Skip to content

Commit

Permalink
https://github.com/crowlogic/arb4j/issues/253
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlogic committed Nov 28, 2024
1 parent f3b7c86 commit 627e42d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/arb/expressions/nodes/DerivativeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class DerivativeNode<D, R, F extends Function<? extends D, ? extends R>>
@Override
public String toString()
{
return String.format("DerivativeNode[operand=%s, variable=%s, derivative=%s]", operand, variable, derivative);
return derivative.toString();
}

public Node<D, R, F> operand;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/arb/expressions/nodes/binary/AdditionNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public boolean isCommutative()
Node<E, S, G>
spliceInto(Expression<E, S, G> newExpression)
{
return new AdditionNode<E, S, G>(newExpression,
left.spliceInto(newExpression),
right.spliceInto(newExpression));
return left.spliceInto(newExpression).add(right.spliceInto(newExpression));
}

@Override
Expand Down
14 changes: 10 additions & 4 deletions src/test/java/arb/expressions/ExpressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import arb.RationalFunction;
import arb.Real;
import arb.RealConstants;
import arb.RoundingMode;
import arb.documentation.BusinessSourceLicenseVersionOnePointOne;
import arb.documentation.TheArb4jLibrary;
import arb.exceptions.CompilerException;
Expand Down Expand Up @@ -121,11 +122,16 @@ public void testDerivativeToo()

public void testRealPolynomialDerivative()
{
var context = new Context(Real.named("a"),
Real.named("b"),
Real.named("c"));
var context = new Context(Real.named("a").set(2),
Real.named("b").set(4),
Real.named("c").set(6));
var x = RealPolynomialNullaryFunction.express("x->∂a*x+b*x²+c*x³/∂x", context);
assertEquals("a+2*b*x+3*c*x^2", x.typeset());
assertEquals("x➔∂a*x+b*x²+c*x³/∂x", x.toString());
var poly = x.evaluate(128);
assertEquals("18*x² + 8*x + 2", poly.toString());
var y = poly.evaluate(new Real("2.3", 128), 1, 128, new Real() );
y.printPrecision = false;
assertEquals( "115.62", y.toString() );
}

/**
Expand Down

0 comments on commit 627e42d

Please sign in to comment.