From aa2166ed9939ff9f306bd54802a87794140a9f8e Mon Sep 17 00:00:00 2001 From: axexlck Date: Sun, 12 Nov 2023 03:25:15 +0100 Subject: [PATCH] WIP #856 improve Together - handle "inverse denominator number" >> 1/(sqrt[7] - 2 sqrt[2]) + 1/(sqrt[7] + 2 sqrt[2]) // Together -2*Sqrt(7) --- .../src/main/java/org/matheclipse/core/builtin/Algebra.java | 6 +++--- .../org/matheclipse/core/system/LinearAlgebraTestCase.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Algebra.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Algebra.java index 59717f50d1..dd3f4a3d08 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Algebra.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Algebra.java @@ -4365,9 +4365,6 @@ private static IExpr togetherPlus(IAST plusAST) { return F.C0; } if (!exprDenominator.isOne()) { - if (exprDenominator.isMinusOne()) { - return exprNumerator.negate(); - } try { IExpr[] result = cancelGCD(exprNumerator, exprDenominator); if (result != null) { @@ -4380,6 +4377,9 @@ private static IExpr togetherPlus(IAST plusAST) { } catch (JASConversionException jce) { LOGGER.debug("Together.togetherPlus()", jce); } + if (exprDenominator.isNumber()) { + return exprDenominator.inverse().times(exprNumerator); + } return F.Times(exprNumerator, F.Power(denom, -1)); } return exprNumerator; diff --git a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LinearAlgebraTestCase.java b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LinearAlgebraTestCase.java index 563182f05e..459a400ea3 100644 --- a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LinearAlgebraTestCase.java +++ b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LinearAlgebraTestCase.java @@ -17,7 +17,7 @@ public LinearAlgebraTestCase(String name) { public void testAdjugate() { check("Adjugate({{E^5, 1, 3 - 2*I}, {1 + I, Pi/2, 5}, {0, 1, -4}})", // - "{{2*(-5/2-Pi),7-I*2,(3/2-I)*(30/13+I*20/13-Pi)},\n" // + "{{-2*(5/2+Pi),7-I*2,(3/2-I)*(30/13+I*20/13-Pi)},\n" // + " {4+I*4,-4*E^5,5*(1+I*1/5-E^5)},\n" // + " {1+I,-E^5,1/2*(-2-I*2+E^5*Pi)}}"); // https://en.wikipedia.org/wiki/Adjugate_matrix