Changeset 17780


Ignore:
Timestamp:
11/02/20 16:27:25 (3 weeks ago)
Author:
gkronber
Message:

#3073 added (limited) support for power symbol (only for integer exponents)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/DerivativeCalculator.cs

    r17650 r17780  
    149149        return Product(Product(CreateConstant(3.0), Square(f)), Derive(f, variableName));
    150150      }
     151      if (branch.Symbol is Power) {
     152        // HL evaluators handle power strangely (exponent is rounded to an integer)
     153        // here we only support the case when the exponent is a constant integer and
     154        var exponent = branch.GetSubtree(1) as ConstantTreeNode;
     155        if (exponent != null && Math.Truncate(exponent.Value) == exponent.Value) {
     156          var newPower = (ISymbolicExpressionTreeNode)branch.Clone();
     157          var newExponent = (ConstantTreeNode)newPower.GetSubtree(1);
     158          newExponent.Value -= 1;
     159          return Product(CreateConstant(exponent.Value), newPower);
     160        } else throw new NotSupportedException("Cannot derive non-integer powers");
     161      }
    151162      if (branch.Symbol is Absolute) {
    152163        var f = (ISymbolicExpressionTreeNode)branch.GetSubtree(0).Clone();
     
    263274          !(n.Symbol is Cube) &&
    264275          !(n.Symbol is CubeRoot) &&
     276          !(n.Symbol is Power) &&
    265277          !(n.Symbol is Absolute) &&
    266278          !(n.Symbol is AnalyticQuotient) &&
Note: See TracChangeset for help on using the changeset viewer.