From ae84d8c8c10b68f47df22a080979173826cd9f1a Mon Sep 17 00:00:00 2001 From: Stephen Crowley Date: Sat, 7 Dec 2024 21:31:46 -0600 Subject: [PATCH] https://github.com/crowlogic/arb4j/issues/253 --- src/main/java/arb/expressions/nodes/Node.java | 10 ++++++++++ .../arb/expressions/nodes/unary/FunctionNode.java | 5 +++++ .../arb/expressions/nodes/DerivativeNodeTest.java | 14 ++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/src/main/java/arb/expressions/nodes/Node.java b/src/main/java/arb/expressions/nodes/Node.java index 3a01de648..c1d4af61a 100644 --- a/src/main/java/arb/expressions/nodes/Node.java +++ b/src/main/java/arb/expressions/nodes/Node.java @@ -331,4 +331,14 @@ public Node cot() return apply("cot"); } + public Node sinh() + { + return apply("sinh"); + } + + public Node cosh() + { + return apply("cosh"); + } + } diff --git a/src/main/java/arb/expressions/nodes/unary/FunctionNode.java b/src/main/java/arb/expressions/nodes/unary/FunctionNode.java index e539bc48f..e8ce840cd 100644 --- a/src/main/java/arb/expressions/nodes/unary/FunctionNode.java +++ b/src/main/java/arb/expressions/nodes/unary/FunctionNode.java @@ -160,6 +160,7 @@ public Node differentiate(VariableNode variable) */ private Node differentiateBuiltinFunction() { + switch (functionName) { case "arcsin": @@ -170,6 +171,10 @@ private Node differentiateBuiltinFunction() return arg.cos(); case "cos": return arg.sin().neg(); + case "sinh": + return arg.cosh(); + case "cosh": + return arg.sinh(); case "exp": return this; case "log": diff --git a/src/test/java/arb/expressions/nodes/DerivativeNodeTest.java b/src/test/java/arb/expressions/nodes/DerivativeNodeTest.java index f9cd53e22..07e7eeafc 100644 --- a/src/test/java/arb/expressions/nodes/DerivativeNodeTest.java +++ b/src/test/java/arb/expressions/nodes/DerivativeNodeTest.java @@ -16,6 +16,20 @@ public class DerivativeNodeTest extends TestCase { + public void testHyperbolicSineDerivative() + { + var f = RealFunction.parse("∂sinh(x)/∂x"); + var df = RealFunction.parse("cosh(x)"); + assertEquals(df.rootNode.toString(), f.rootNode.toString()); + } + + public void testHyperbolicCosineDerivative() + { + var f = RealFunction.parse("∂cosh(x)/∂x"); + var df = RealFunction.parse("sinh(x)"); + assertEquals(df.rootNode.toString(), f.rootNode.toString()); + } + public void testCotangentDerivative() { var f = RealFunction.parse("∂cot(x)/∂x");