/// <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);
 }
Esempio n. 2
0
        /// <summary>
        /// Calculates derivation
        /// </summary>
        /// <param name="tree">The function for derivation calculation</param>
        /// <param name="variableName">Name of variable</param>
        /// <returns>The derivation</returns>
        public ObjectFormulaTree Derivation(ObjectFormulaTree tree, string variableName)
        {
            if (arity == 1)
            {
                return(tree[0].Derivation(variableName));
            }
            IDerivationOperation pow =
                ElementaryFunctionsCreator.Object.GetPowerOperation(tree[0].ReturnType, tree[1].ReturnType)
                as IDerivationOperation;

            return(pow.Derivation(tree, variableName));
        }