Esempio n. 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);
 }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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();
        }
Esempio n. 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();
 }
Esempio n. 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);
 }
Esempio n. 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);
 }
Esempio n. 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);
 }
Esempio n. 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));
     }
 }
Esempio n. 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);
 }
Esempio n. 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());
     }
 }
Esempio n. 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", ")");
            }
        }
Esempio n. 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);
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 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(")");
            }
        }
Esempio n. 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(")");
 }
Esempio n. 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();
 }
Esempio n. 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));
 }
Esempio n. 20
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="a"></param>
 public Minus(SymMathNode a) : base(a)
 {
 }
Esempio n. 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);
 }
Esempio n. 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);
 }
Esempio n. 23
0
 /// <inheritdoc />
 public override BinaryOperation Clone(SymMathNode a, SymMathNode b)
 {
     return(new Equality(a, b));
 }
Esempio n. 24
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 public Equality(SymMathNode a, SymMathNode b) : base(a, b)
 {
 }
Esempio n. 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));
 }
Esempio n. 26
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 public Division(SymMathNode a, SymMathNode b) : base(a, b)
 {
 }
Esempio n. 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);
 }
Esempio n. 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));
 }
Esempio n. 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);
 }
Esempio n. 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());
 }