Esempio n. 1
0
        public override bool Matches(Expression E, MatchContext Matched)
        {
            Expression matched;

            if (Matched.TryGetValue(Right, out matched))
            {
                if (Left.Matches(E ^ Binary.Divide(1, matched), Matched))
                {
                    return(true);
                }
            }

            // x^0 = 1.
            if (E.EqualsOne() && Right.Matches(0, Matched))
            {
                return(true);
            }
            // 0^x = 0.
            if (E.EqualsZero() && Left.Matches(0, Matched))
            {
                return(true);
            }

            Binary PE = E as Power;

            if (!ReferenceEquals(PE, null) && Matched.TryMatch(() => Left.Matches(PE.Left, Matched) && Right.Matches(PE.Right, Matched)))
            {
                return(true);
            }

            // If the exponent matches 1, E can match left.
            if (Matched.TryMatch(() => Right.Matches(1, Matched) && Left.Matches(E, Matched)))
            {
                return(true);
            }

            if (Right.IsInteger() && Left.Matches(ComputerAlgebra.Power.New(E, Binary.Divide(1, Right)).Evaluate(), Matched))
            {
                return(true);
            }

            return(false);
        }