Skip to content

Commit 286f66d

Browse files
committed
WIP #930 iterative functions for TrigExpand
1 parent e9188ef commit 286f66d

File tree

3 files changed

+16
-29
lines changed

3 files changed

+16
-29
lines changed

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/TrigExpand.java

+5-24
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.matheclipse.core.expression.ImplementationStatus;
2020
import org.matheclipse.core.expression.S;
2121
import org.matheclipse.core.interfaces.IAST;
22-
import org.matheclipse.core.interfaces.IASTAppendable;
2322
import org.matheclipse.core.interfaces.IExpr;
2423
import org.matheclipse.core.interfaces.IInteger;
2524
import org.matheclipse.core.visit.VisitorPlusTimesPowerReplaceAll;
@@ -109,8 +108,12 @@ private IExpr expandPlus(IAST ast, IAST plusAST) {
109108
return expandCoshSinhPlus(plusAST, true);
110109
} else if (ast.isAST(S.Csch, 2)) {
111110
return expandCschPlus(plusAST, 1);
111+
} else if (ast.isAST(S.Coth, 2)) {
112+
// Cosh(x) / Sinh(x)
113+
return F.Divide(expandCoshSinhPlus(plusAST, true), expandCoshSinhPlus(plusAST, false));
112114
} else if (ast.isTanh()) {
113-
return expandTanhPlus(plusAST, 1);
115+
// Sinh(x) / Cosh(x)
116+
return F.Divide(expandCoshSinhPlus(plusAST, false), expandCoshSinhPlus(plusAST, true));
114117
}
115118
return F.NIL;
116119
}
@@ -298,28 +301,6 @@ private static IExpr expandSechPlus(IAST plusAST, int startPosition) {
298301
F.Power(F.Plus(F.Times(F.Cosh(b), F.Cosh(a)), F.Times(F.Sinh(a), F.Sinh(b))), F.CN1)));
299302
}
300303

301-
/**
302-
* <code>Tanh(a+b+c+...)</code>
303-
*
304-
* @param plusAST
305-
* @param startPosition
306-
* @return
307-
*/
308-
private static IExpr expandTanhPlus(IAST plusAST, int startPosition) {
309-
IASTAppendable result = F.TimesAlloc(2);
310-
IExpr lhs = plusAST.get(startPosition);
311-
if (startPosition == plusAST.size() - 2) {
312-
// (Tanh(x)+Tanh(y)) / (1+Tanh(x)*Tanh(y))
313-
IExpr rhs = plusAST.get(startPosition + 1);
314-
result.append(Plus(F.Tanh(lhs), F.Tanh(rhs)));
315-
result.append(F.Power(Plus(F.C1, Times(F.Tanh(lhs), F.Tanh(rhs))), F.CN1));
316-
} else {
317-
result.append(Plus(F.Tanh(lhs), expandTanhPlus(plusAST, startPosition + 1)));
318-
result.append(F.Power(
319-
Plus(F.C1, Times(F.Tanh(lhs), expandTanhPlus(plusAST, startPosition + 1))), F.CN1));
320-
}
321-
return result;
322-
}
323304
}
324305

325306
public TrigExpand() {}

symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -25704,12 +25704,18 @@ public void testTrigExpand() {
2570425704
check("TrigExpand(Sinh(a+b+c))", //
2570525705
"Cosh(b)*Cosh(c)*Sinh(a)+Cosh(a)*Cosh(c)*Sinh(b)+Cosh(a)*Cosh(b)*Sinh(c)+Sinh(a)*Sinh(b)*Sinh(c)");
2570625706

25707+
check("TrigExpand(Coth(a+b))", //
25708+
"(Cosh(a)*Cosh(b))/(Cosh(b)*Sinh(a)+Cosh(a)*Sinh(b))+" //
25709+
+ "(Sinh(a)*Sinh(b))/(Cosh(b)*Sinh(a)+Cosh(a)*Sinh(b))");
25710+
2570725711
check("TrigExpand(Tanh(a+b))", //
25708-
"Tanh(a)/(1+Tanh(a)*Tanh(b))+Tanh(b)/(1+Tanh(a)*Tanh(b))");
25712+
"(Cosh(b)*Sinh(a))/(Cosh(a)*Cosh(b)+Sinh(a)*Sinh(b))+" //
25713+
+ "(Cosh(a)*Sinh(b))/(Cosh(a)*Cosh(b)+Sinh(a)*Sinh(b))");
2570925714
check("TrigExpand(Tanh(a+b+c))", //
25710-
"Tanh(a)/(1+(Tanh(a)*Tanh(b))/(1+Tanh(b)*Tanh(c))+(Tanh(a)*Tanh(c))/(1+Tanh(b)*Tanh(c)))+Tanh(b)/((\n"
25711-
+ "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"
25712-
+ "1+Tanh(b)*Tanh(c))*(1+(Tanh(a)*Tanh(b))/(1+Tanh(b)*Tanh(c))+(Tanh(a)*Tanh(c))/(1+Tanh(b)*Tanh(c))))");
25715+
"(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))+"//
25716+
+ "(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))+"//
25717+
+ "(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))+"//
25718+
+ "(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))");
2571325719

2571425720
check("TrigExpand(Csc(a+b+c))", //
2571525721
"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))");

symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/SimplifyTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ public void testTrigSimplifyTR10() {
757757

758758
tr10 = TrigSimplifyFu.tr10(F.Sin(F.Plus(F.a, F.b, F.c)));
759759
assertEquals(tr10.toString(), //
760-
"Sin(a)*Cos(b)*Cos(c)+Sin(a)*-Sin(b)*Sin(c)+Cos(a)*Cos(c)*Sin(b)+Cos(a)*Cos(b)*Sin(c)");
760+
"Cos(c)*Cos(b)*Sin(a)+Cos(c)*Cos(a)*Sin(b)+Cos(a)*Cos(b)*Sin(c)+-Sin(a)*Sin(b)*Sin(c)");
761761
}
762762

763763
@Test

0 commit comments

Comments
 (0)