From 286f66d7a5217ec67e933af62b74cde5fabf765e Mon Sep 17 00:00:00 2001 From: axexlck Date: Sun, 10 Mar 2024 19:39:35 +0100 Subject: [PATCH] WIP #930 iterative functions for TrigExpand --- .../core/reflection/system/TrigExpand.java | 29 ++++--------------- .../core/system/LowercaseTestCase.java | 14 ++++++--- .../matheclipse/core/system/SimplifyTest.java | 2 +- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/TrigExpand.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/TrigExpand.java index 657b41c5f2..f282e437a2 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/TrigExpand.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/TrigExpand.java @@ -19,7 +19,6 @@ import org.matheclipse.core.expression.ImplementationStatus; import org.matheclipse.core.expression.S; import org.matheclipse.core.interfaces.IAST; -import org.matheclipse.core.interfaces.IASTAppendable; import org.matheclipse.core.interfaces.IExpr; import org.matheclipse.core.interfaces.IInteger; import org.matheclipse.core.visit.VisitorPlusTimesPowerReplaceAll; @@ -109,8 +108,12 @@ private IExpr expandPlus(IAST ast, IAST plusAST) { return expandCoshSinhPlus(plusAST, true); } else if (ast.isAST(S.Csch, 2)) { return expandCschPlus(plusAST, 1); + } else if (ast.isAST(S.Coth, 2)) { + // Cosh(x) / Sinh(x) + return F.Divide(expandCoshSinhPlus(plusAST, true), expandCoshSinhPlus(plusAST, false)); } else if (ast.isTanh()) { - return expandTanhPlus(plusAST, 1); + // Sinh(x) / Cosh(x) + return F.Divide(expandCoshSinhPlus(plusAST, false), expandCoshSinhPlus(plusAST, true)); } return F.NIL; } @@ -298,28 +301,6 @@ private static IExpr expandSechPlus(IAST plusAST, int startPosition) { F.Power(F.Plus(F.Times(F.Cosh(b), F.Cosh(a)), F.Times(F.Sinh(a), F.Sinh(b))), F.CN1))); } - /** - * Tanh(a+b+c+...) - * - * @param plusAST - * @param startPosition - * @return - */ - private static IExpr expandTanhPlus(IAST plusAST, int startPosition) { - IASTAppendable result = F.TimesAlloc(2); - IExpr lhs = plusAST.get(startPosition); - if (startPosition == plusAST.size() - 2) { - // (Tanh(x)+Tanh(y)) / (1+Tanh(x)*Tanh(y)) - IExpr rhs = plusAST.get(startPosition + 1); - result.append(Plus(F.Tanh(lhs), F.Tanh(rhs))); - result.append(F.Power(Plus(F.C1, Times(F.Tanh(lhs), F.Tanh(rhs))), F.CN1)); - } else { - result.append(Plus(F.Tanh(lhs), expandTanhPlus(plusAST, startPosition + 1))); - result.append(F.Power( - Plus(F.C1, Times(F.Tanh(lhs), expandTanhPlus(plusAST, startPosition + 1))), F.CN1)); - } - return result; - } } public TrigExpand() {} diff --git a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java index c36b04cb58..b18f8e23ac 100644 --- a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java +++ b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java @@ -25704,12 +25704,18 @@ public void testTrigExpand() { check("TrigExpand(Sinh(a+b+c))", // "Cosh(b)*Cosh(c)*Sinh(a)+Cosh(a)*Cosh(c)*Sinh(b)+Cosh(a)*Cosh(b)*Sinh(c)+Sinh(a)*Sinh(b)*Sinh(c)"); + check("TrigExpand(Coth(a+b))", // + "(Cosh(a)*Cosh(b))/(Cosh(b)*Sinh(a)+Cosh(a)*Sinh(b))+" // + + "(Sinh(a)*Sinh(b))/(Cosh(b)*Sinh(a)+Cosh(a)*Sinh(b))"); + check("TrigExpand(Tanh(a+b))", // - "Tanh(a)/(1+Tanh(a)*Tanh(b))+Tanh(b)/(1+Tanh(a)*Tanh(b))"); + "(Cosh(b)*Sinh(a))/(Cosh(a)*Cosh(b)+Sinh(a)*Sinh(b))+" // + + "(Cosh(a)*Sinh(b))/(Cosh(a)*Cosh(b)+Sinh(a)*Sinh(b))"); check("TrigExpand(Tanh(a+b+c))", // - "Tanh(a)/(1+(Tanh(a)*Tanh(b))/(1+Tanh(b)*Tanh(c))+(Tanh(a)*Tanh(c))/(1+Tanh(b)*Tanh(c)))+Tanh(b)/((\n" - + "1+Tanh(b)*Tanh(c))*(1+(Tanh(a)*Tanh(b))/(1+Tanh(b)*Tanh(c))+(Tanh(a)*Tanh(c))/(1+Tanh(b)*Tanh(c))))+Tanh(c)/((\n" - + "1+Tanh(b)*Tanh(c))*(1+(Tanh(a)*Tanh(b))/(1+Tanh(b)*Tanh(c))+(Tanh(a)*Tanh(c))/(1+Tanh(b)*Tanh(c))))"); + "(Cosh(b)*Cosh(c)*Sinh(a))/(Cosh(a)*Cosh(b)*Cosh(c)+Cosh(c)*Sinh(a)*Sinh(b)+Cosh(b)*Sinh(a)*Sinh(c)+Cosh(a)*Sinh(b)*Sinh(c))+"// + + "(Cosh(a)*Cosh(c)*Sinh(b))/(Cosh(a)*Cosh(b)*Cosh(c)+Cosh(c)*Sinh(a)*Sinh(b)+Cosh(b)*Sinh(a)*Sinh(c)+Cosh(a)*Sinh(b)*Sinh(c))+"// + + "(Cosh(a)*Cosh(b)*Sinh(c))/(Cosh(a)*Cosh(b)*Cosh(c)+Cosh(c)*Sinh(a)*Sinh(b)+Cosh(b)*Sinh(a)*Sinh(c)+Cosh(a)*Sinh(b)*Sinh(c))+"// + + "(Sinh(a)*Sinh(b)*Sinh(c))/(Cosh(a)*Cosh(b)*Cosh(c)+Cosh(c)*Sinh(a)*Sinh(b)+Cosh(b)*Sinh(a)*Sinh(c)+Cosh(a)*Sinh(b)*Sinh(c))"); check("TrigExpand(Csc(a+b+c))", // "1/(Cos(b)*Cos(c)*Sin(a)+Cos(a)*Cos(c)*Sin(b)+Cos(a)*Cos(b)*Sin(c)-Sin(a)*Sin(b)*Sin(c))"); diff --git a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/SimplifyTest.java b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/SimplifyTest.java index f2aa662861..dad89e4415 100644 --- a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/SimplifyTest.java +++ b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/SimplifyTest.java @@ -757,7 +757,7 @@ public void testTrigSimplifyTR10() { tr10 = TrigSimplifyFu.tr10(F.Sin(F.Plus(F.a, F.b, F.c))); assertEquals(tr10.toString(), // - "Sin(a)*Cos(b)*Cos(c)+Sin(a)*-Sin(b)*Sin(c)+Cos(a)*Cos(c)*Sin(b)+Cos(a)*Cos(b)*Sin(c)"); + "Cos(c)*Cos(b)*Sin(a)+Cos(c)*Cos(a)*Sin(b)+Cos(a)*Cos(b)*Sin(c)+-Sin(a)*Sin(b)*Sin(c)"); } @Test