Skip to content

Commit

Permalink
public void testDerivativeOfLogarithm()
Browse files Browse the repository at this point in the history
  {
    var x = RealFunction.parse("∂ln(x)/∂x");
    assertEquals("1/x", x.rootNode.toString());
  } #253
  • Loading branch information
crowlogic committed Dec 2, 2024
1 parent 6191770 commit 6a93d0b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/arb/expressions/nodes/unary/FunctionNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import arb.expressions.Expression;
import arb.expressions.FunctionMapping;
import arb.expressions.Parser;
import arb.expressions.nodes.LiteralConstantNode;
import arb.expressions.nodes.Node;
import arb.expressions.nodes.VariableNode;
import arb.functions.Function;
Expand Down Expand Up @@ -473,6 +474,9 @@ private Node<D, R, F> differentiateBuiltinFunction()
expression).neg(); // derivative of cos is -sin
case "exp":
return this; // derivative of exp is exp
case "log":
return new LiteralConstantNode<>(expression,
"1").div(arg);
// Add other built-in function derivatives
default:
throw new UnsupportedOperationException("Derivative not implemented for function: " + functionName);
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/arb/expressions/ExpressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
public class ExpressionTest extends
TestCase
{
public void testDerivativeOfLogarithm()
{
var x = RealFunction.parse("∂ln(x)/∂x");
assertEquals("1/x", x.rootNode.toString());
}


public void testDerivativeOfExponentialFunction()
{
var x = RealFunction.parse("∂exp(x)/∂x");
Expand Down

0 comments on commit 6a93d0b

Please sign in to comment.