/// <summary>
 /// Calculates derivation tree
 /// </summary>
 /// <param name="tree">Tree to calculate</param>
 /// <param name="variableName">Name of variable</param>
 /// <returns>Tree of derivation</returns>
 static public ObjectFormulaTree Derivation(this ObjectFormulaTree tree, string variableName)
 {
     if (tree.Operation is IDerivationOperation)
     {
         IDerivationOperation op = tree.Operation as IDerivationOperation;
         return(op.Derivation(tree, variableName));
     }
     if (ElementaryBinaryOperation.IsInteger(tree.Operation.ReturnType))
     {
         ElementaryRealConstant op = new ElementaryRealConstant(0);
         return(new ObjectFormulaTree(op, new List <ObjectFormulaTree>()));
     }
     if (tree.Operation is OptionalOperation)
     {
         OptionalOperation op = tree.Operation as OptionalOperation;
         op = op.Clone() as OptionalOperation;
         List <ObjectFormulaTree> list = new List <ObjectFormulaTree>();
         list.Add(tree[0]);
         for (int i = 1; i < 3; i++)
         {
             list.Add(tree[i].Derivation(variableName));
         }
         return(new ObjectFormulaTree(op, list));
     }
     return(null);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Accepts operation
 /// </summary>
 /// <param name="type">Argument type</param>
 /// <returns>The operation</returns>
 public IObjectOperation Accept(object type)
 {
     if (!ElementaryBinaryOperation.IsInteger(type))
     {
         return(null);
     }
     this.type = type;
     return(this);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Acceptor of binary operation
 /// </summary>
 /// <param name="typeA">Type of left part</param>
 /// <param name="typeB">Type of right part</param>
 /// <returns>Accepted operation</returns>
 public IObjectOperation Accept(object typeA, object typeB)
 {
     if (!ElementaryBinaryOperation.IsInteger(typeA))
     {
         throw new Exception("Illegal integer argument");
     }
     if ((symbol == '\u2266') | (symbol == '\u2267'))
     {
         if (!ElementaryBinaryOperation.IsNumber(typeB))
         {
             throw new Exception("Illegal integer argument");
         }
         type = typeA;
         return(this);
     }
     if (!typeA.Equals(typeB))
     {
         throw new Exception("Different types of integer");
     }
     type = typeA;
     return(this);
 }