Skip to content

Commit

Permalink
#253 fix derivative of
Browse files Browse the repository at this point in the history
exponentiation
  • Loading branch information
crowlogic committed Nov 27, 2024
1 parent 8bcb756 commit 41524eb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/main/java/arb/expressions/nodes/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import arb.expressions.Compiler;
import arb.expressions.Expression;
import arb.expressions.nodes.binary.AdditionNode;
import arb.expressions.nodes.binary.DivisionNode;
import arb.expressions.nodes.binary.ExponentiationNode;
import arb.expressions.nodes.binary.MultiplicationNode;
import arb.expressions.nodes.binary.SubtractionNode;
import arb.functions.Function;

/**
Expand Down Expand Up @@ -210,13 +213,34 @@ public boolean isPossiblyNegative()
return false;
}

public Node<D, R, F> pow(Node<D, R, F> exponent)
{
return new ExponentiationNode<>(expression,
this,
exponent);
}

public Node<D, R, F> sub(Node<D, R, F> subtrahend)
{
return new SubtractionNode<>(expression,
this,
subtrahend);
}

public Node<D, R, F> add(Node<D, R, F> addend)
{
return new AdditionNode<>(expression,
this,
addend);
}

public Node<D, R, F> div(Node<D, R, F> divisor)
{
return new DivisionNode<>(expression,
this,
divisor);
}

public Node<D, R, F> mul(Node<D, R, F> multiplicand)
{
return new MultiplicationNode<>(expression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import arb.documentation.BusinessSourceLicenseVersionOnePointOne;
import arb.documentation.TheArb4jLibrary;
import arb.expressions.Expression;
import arb.expressions.nodes.LiteralConstantNode;
import arb.expressions.nodes.Node;
import arb.expressions.nodes.VariableNode;
import arb.functions.Function;
Expand Down Expand Up @@ -65,7 +66,8 @@ public Node<D, R, F> integral(VariableNode<D, R, F> variable)
@Override
public Node<D, R, F> differentiate(VariableNode<D, R, F> variable)
{
return this;
return right.mul(left.pow(right.sub(new LiteralConstantNode<>(expression,
"1"))));
}

@Override
Expand Down

0 comments on commit 41524eb

Please sign in to comment.