示例#1
0
 /// <summary>
 /// True if equal to variable represented by the same symbol
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public override bool Equals(SymMathNode node)
 {
     var term = node as Variable;
     if (term != null)
     {
         return string.Equals(Symbol, term.Symbol, StringComparison.OrdinalIgnoreCase);
     }
     return false;
 }
示例#2
0
 /// <summary>
 /// Returns true if this tree is equal to node tree
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public override bool Equals(SymMathNode node)
 {
     var term = node as ConstantInt64;
     if (term != null)
     {
         return m_Value == term.m_Value;
     }
     return false;
 }
示例#3
0
 /// <summary>
 /// Dump node to MathML
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="parent"></param>
 public override void ToMathML(XmlWriter writer, SymMathNode parent)
 {
     writer.WriteStartElement("msup");
     writer.WriteStartElement("mrow");
     A.ToMathML(writer, this);
     writer.WriteEndElement();
     writer.WriteStartElement("mrow");
     B.ToMathML(writer, this);
     writer.WriteEndElement();
     writer.WriteEndElement();
 }
示例#4
0
        /// <summary>
        /// Dump node to MathML
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="parent"></param>
        public override void ToMathML(XmlWriter writer, SymMathNode parent)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            writer.WriteStartElement("msqrt");
            A.ToMathML(writer);
            writer.WriteEndElement();
        }
示例#5
0
 /// <summary>
 /// Returns true if this tree is equal to node tree
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public override bool Equals(SymMathNode node)
 {
     if (this.GetType() == node.GetType())
     {
         var unaryOperation = node as UnaryOperation;
         if (unaryOperation != null)
         {
             return A.Equals(unaryOperation.A);
         }
     }
     return false;
 }
示例#6
0
        /// <summary>
        /// Returns true if this tree is equal to node tree
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public override bool Equals(SymMathNode node)
        {
            if (base.Equals(node))
            {
                return true;
            }

            var add = node as Add;
            if (add != null)
            {
                return A.Equals(add.B) && B.Equals(add.A);
            }

            return false;
        }
示例#7
0
 /// <summary>
 /// Dump node to string
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="parent"></param>
 public override void ToString(StringBuilder builder, SymMathNode parent)
 {
     builder.Append("Sqrt(");
     A.ToString(builder, this);
     builder.Append(")");
 }
示例#8
0
 /// <summary>
 /// Clones current node (deep-copy)
 /// </summary>
 /// <param name="a"></param>
 /// <returns></returns>
 public abstract UnaryOperation Clone(SymMathNode a);
示例#9
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="a"></param>
 public UnaryOperation(SymMathNode a)
 {
     A = a;
 }
示例#10
0
 /// <summary>
 /// Dump node to string
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="parent"></param>
 public override void ToString(StringBuilder builder, SymMathNode parent)
 {
     A.ToString(builder, parent);
     builder.Append("=");
     B.ToString(builder, parent);
 }
示例#11
0
 /// <summary>
 /// Clones current node (deep-copy)
 /// </summary>
 /// <param name="a"></param>
 /// <returns></returns>
 public override UnaryOperation Clone(SymMathNode a)
 {
     return new Minus(a);
 }
示例#12
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 public Power(SymMathNode a, SymMathNode b)
     : base(a, b)
 {
 }
示例#13
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 public Add(SymMathNode a, SymMathNode b)
     : base(a, b)
 {
     A = a;
     B = b;
 }
示例#14
0
 /// <summary>
 /// Clones current node (deep-copy)
 /// </summary>
 /// <param name="a"></param>
 /// <returns></returns>
 public override UnaryOperation Clone(SymMathNode a)
 {
     return new SquareRoot(a);
 }
示例#15
0
 /// <summary>
 /// Dump node to MathML
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="parent"></param>
 public override void ToMathML(XmlWriter writer, SymMathNode parent)
 {
     bool brackets = parent != null && !(parent is Add);
     if (brackets)
     {
         writer.WriteElementString("mo", "(");
     }
     A.ToMathML(writer, this);
     writer.WriteElementString("mo", "+");
     B.ToMathML(writer, this);
     if (brackets)
     {
         writer.WriteElementString("mo", ")");
     }
 }
示例#16
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="a"></param>
 public SquareRoot(SymMathNode a)
     : base(a)
 {
 }
示例#17
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 public Division(SymMathNode a, SymMathNode b)
     : base(a, b)
 {
 }
示例#18
0
 /// <summary>
 /// Clones current node(deep-copy)
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <returns></returns>
 public abstract BinaryOperation Clone(SymMathNode a, SymMathNode b);
示例#19
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 public BinaryOperation(SymMathNode a, SymMathNode b)
 {
     A = a;
     B = b;
 }
示例#20
0
 /// <summary>
 /// Returns true if A is symbolically equal to node.A and
 /// B is symbolically equal to node.B
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public override bool Equals(SymMathNode node)
 {
     if (GetType() == node.GetType())
     {
         var binaryOperation = node as BinaryOperation;
         if (binaryOperation != null)
         {
             return A.Equals(binaryOperation.A) && B.Equals(binaryOperation.B);
         }
     }
     return false;
 }
示例#21
0
 /// <summary>
 /// Dump node to string
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="parent"></param>
 public override void ToString(StringBuilder builder, SymMathNode parent)
 {
     bool brackets = parent != null && !(parent is Add);
     if (brackets)
     {
         builder.Append("(");
     }
     A.ToString(builder, this);
     if (B is Minus)
     {
         builder.Append("-");
         ((Minus)B).A.ToString(builder, this);
     }
     else
     {
         builder.Append("+");
         B.ToString(builder, this);
     }
     if (brackets)
     {
         builder.Append(")");
     }
 }
示例#22
0
 /// <summary>
 /// Dump node to MathML
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="parent"></param>
 public override void ToMathML(XmlWriter writer, SymMathNode parent)
 {
     writer.WriteElementString("mi", Symbol);
 }
示例#23
0
 /// <summary>
 /// Clones current node (deep-copy)
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <returns></returns>
 public override BinaryOperation Clone(SymMathNode a, SymMathNode b)
 {
     return new Add(a, b);
 }
示例#24
0
 /// <summary>
 /// Dump node to string
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="parent"></param>
 public override void ToString(StringBuilder builder, SymMathNode parent)
 {
     builder.Append(m_Value);
 }
示例#25
0
        public override bool IsApplicable(Division node)
        {
            var         mulA      = node.A as Multiply;
            SymMathNode mulAOther = null;

            Constant termN = node.A as Constant;

            if (mulA != null)
            {
                if (mulA.A is Constant && !(mulA.B is Constant))
                {
                    termN     = (Constant)mulA.A;
                    mulAOther = mulA.B;
                }
                if (mulA.B is Constant && !(mulA.A is Constant))
                {
                    termN     = (Constant)mulA.B;
                    mulAOther = mulA.A;
                }
            }

            Constant    termD     = node.B as Constant;
            var         mulB      = node.B as Multiply;
            SymMathNode mulBOther = null;

            if (mulB != null)
            {
                if (mulB.A is Constant && !(mulB.B is Constant))
                {
                    termD     = (Constant)mulB.A;
                    mulBOther = mulB.B;
                }
                if (mulB.B is Constant && !(mulB.A is Constant))
                {
                    termD     = (Constant)mulB.B;
                    mulBOther = mulB.A;
                }
            }

            if (termN != null && termD != null)
            {
                var gcd = Constant.Gcd(termN, termD);
                if (!gcd.IsOne())
                {
                    termN = (Constant)(termN / gcd);
                    termD = (Constant)(termD / gcd);
                    SymMathNode newA = termN;
                    if (mulAOther != null)
                    {
                        newA = new Multiply(termN, mulAOther);
                    }
                    SymMathNode newB = termD;
                    if (mulBOther != null)
                    {
                        newB = new Multiply(termD, mulBOther);
                    }
                    return(true);
                }
            }
            return(false);
        }
示例#26
0
 /// <summary>
 /// Dump node to MathML
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="parent"></param>
 public override void ToMathML(XmlWriter writer, SymMathNode parent)
 {
     throw new NotImplementedException();
 }
示例#27
0
 /// <summary>
 /// Dump node to MathML
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="parent"></param>
 public override void ToMathML(XmlWriter writer, SymMathNode parent)
 {
     if (m_Value < 0)
     {
         writer.WriteElementString("mo", "-");
         writer.WriteElementString("mn", Convert.ToString(-m_Value));
     }
     else
     {
         writer.WriteElementString("mn", Convert.ToString(m_Value));
     }
 }
示例#28
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 public Equality(SymMathNode a, SymMathNode b)
     : base(a, b)
 {
 }
示例#29
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="parent"></param>
 public override void ToMathML(XmlWriter writer, SymMathNode parent)
 {
     A.ToMathML(writer, this);
     writer.WriteElementString("mo", "=");
     B.ToMathML(writer, this);
 }
示例#30
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="a"></param>
 public Minus(SymMathNode a)
     : base(a)
 {
 }