Example #1
0
 /// <summary>
 /// ctor. Term.Factory has to be set otherwise exception is thrown
 /// </summary>
 /// <param name="a"></param>
 public UnaryOperation(long a)
 {
     if (Constant.Factory == null)
     {
         throw new Exception("Please set Term.Factory first (you can set it to TermBigInteger.Factory or to TermInt64.Factory).");
     }
     A = Constant.Factory.Create(a);
 }
Example #2
0
        /// <summary>
        /// Returns ture if node is of type T and condition evaluate is satisfied
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="node"></param>
        /// <param name="evaluate"></param>
        /// <returns></returns>
        public static bool IfType <T>(this SymMathNode node, Func <T, bool> evaluate) where T : class
        {
            var t = node as T;

            if (t != null)
            {
                return(evaluate.Invoke(t));
            }
            return(false);
        }
Example #3
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 ConstantBigInteger;

            if (term != null)
            {
                return(m_Value == term.m_Value);
            }
            return(false);
        }
Example #4
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);
        }
Example #5
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();
        }
Example #6
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("mfrac");
     writer.WriteStartElement("mrow");
     A.ToMathML(writer, this);
     writer.WriteEndElement();
     writer.WriteStartElement("mrow");
     B.ToMathML(writer, this);
     writer.WriteEndElement();
     writer.WriteEndElement();
 }
Example #7
0
 /// <summary>
 /// If any simplification rule exits, simplify given node
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public static SymMathNode Simplify(this SymMathNode node)
 {
     foreach (var rule in node.GetSimplificationRules())
     {
         if (rule.IsApplicable(node))
         {
             return(rule.Apply(node));
         }
     }
     return(node);
 }
Example #8
0
 /// <summary>
 /// If any simplification rule exits, simplify given node
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public static bool CanSimplify(this SymMathNode node)
 {
     foreach (var rule in node.GetSimplificationRules())
     {
         if (rule.IsApplicable(node))
         {
             return(true);
         }
     }
     return(false);
 }
Example #9
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);
 }
Example #10
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));
     }
 }
Example #11
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);
 }
Example #12
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", BigInteger.Abs(m_Value).ToString());
     }
     else
     {
         writer.WriteElementString("mn", m_Value.ToString());
     }
 }
Example #13
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", ")");
            }
        }
Example #14
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 Multiply;

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

            return(false);
        }
Example #15
0
        /// <summary>
        /// Applies all simplification rules, until none is applicable
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public static SymMathNode GetBaseForm(this SymMathNode node)
        {
            var result = node;

            while (true)
            {
                bool ruleFound = false;
                foreach (var rule in result.GetSimplificationRules())
                {
                    if (rule.IsApplicable(result))
                    {
                        result    = rule.Apply(result);
                        ruleFound = true;
                        break;
                    }
                }
                if (!ruleFound)
                {
                    return(result);
                }
            }
        }
Example #16
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(")");
            }
        }
Example #17
0
 /// <summary>
 /// Dump node to string
 /// </summary>
 /// <returns></returns>
 public override void ToString(StringBuilder builder, SymMathNode parent)
 {
     builder.Append("-(");
     A.ToString(builder, this);
     builder.Append(")");
 }
Example #18
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();
 }
Example #19
0
 /// <summary>
 /// Clones current node (deep-copy)
 /// </summary>
 /// <param name="a"></param>
 /// <returns></returns>
 public override UnaryOperation Clone(SymMathNode a)
 {
     return(new Minus(a));
 }
Example #20
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="a"></param>
 public Minus(SymMathNode a) : base(a)
 {
 }
Example #21
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);
 }
Example #22
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);
 }
Example #23
0
 /// <inheritdoc />
 public override BinaryOperation Clone(SymMathNode a, SymMathNode b)
 {
     return(new Equality(a, b));
 }
Example #24
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 public Equality(SymMathNode a, SymMathNode b) : base(a, b)
 {
 }
Example #25
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 Division(a, b));
 }
Example #26
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 public Division(SymMathNode a, SymMathNode b) : base(a, b)
 {
 }
Example #27
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);
 }
Example #28
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 Multiply(a, b));
 }
Example #29
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(Symbol);
 }
Example #30
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.ToString());
 }