From 41524ebe4c975fa0b383cb485ad650879cb4260f Mon Sep 17 00:00:00 2001 From: Stephen Crowley Date: Wed, 27 Nov 2024 16:29:08 -0600 Subject: [PATCH] https://github.com/crowlogic/arb4j/issues/253 fix derivative of exponentiation --- src/main/java/arb/expressions/nodes/Node.java | 24 +++++++++++++++++++ .../nodes/binary/ExponentiationNode.java | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/arb/expressions/nodes/Node.java b/src/main/java/arb/expressions/nodes/Node.java index ea286bc15..02bcf0e5a 100644 --- a/src/main/java/arb/expressions/nodes/Node.java +++ b/src/main/java/arb/expressions/nodes/Node.java @@ -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; /** @@ -210,6 +213,20 @@ public boolean isPossiblyNegative() return false; } + public Node pow(Node exponent) + { + return new ExponentiationNode<>(expression, + this, + exponent); + } + + public Node sub(Node subtrahend) + { + return new SubtractionNode<>(expression, + this, + subtrahend); + } + public Node add(Node addend) { return new AdditionNode<>(expression, @@ -217,6 +234,13 @@ public Node add(Node addend) addend); } + public Node div(Node divisor) + { + return new DivisionNode<>(expression, + this, + divisor); + } + public Node mul(Node multiplicand) { return new MultiplicationNode<>(expression, diff --git a/src/main/java/arb/expressions/nodes/binary/ExponentiationNode.java b/src/main/java/arb/expressions/nodes/binary/ExponentiationNode.java index 86a485ca3..addea57ae 100644 --- a/src/main/java/arb/expressions/nodes/binary/ExponentiationNode.java +++ b/src/main/java/arb/expressions/nodes/binary/ExponentiationNode.java @@ -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; @@ -65,7 +66,8 @@ public Node integral(VariableNode variable) @Override public Node differentiate(VariableNode variable) { - return this; + return right.mul(left.pow(right.sub(new LiteralConstantNode<>(expression, + "1")))); } @Override