From 59a54900aa9eeb2d1878319aba96d530640f573a Mon Sep 17 00:00:00 2001 From: Serg Creevanose Date: Sat, 3 Feb 2024 06:15:59 -0800 Subject: [PATCH] Balance Polynomial Coefficients for grade > 2 --- omnn/math/Sum.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/omnn/math/Sum.cpp b/omnn/math/Sum.cpp index cef25972b..9eaf5fa0e 100644 --- a/omnn/math/Sum.cpp +++ b/omnn/math/Sum.cpp @@ -1361,10 +1361,23 @@ namespace } if (grade > 2) { + auto lcm = constants::one; OptimizeOn oo; for (auto& c : coefficients) { c.optimize(); + if (c.IsFraction()) { + auto& f = c.as(); + auto& dn = f.getDenominator(); + if (dn != constants::one) { + lcm.lcm(dn); + } + } } + if (lcm != constants::one) { + for (auto& c : coefficients) { + c *= lcm; + } + } } return grade; @@ -1874,6 +1887,10 @@ namespace } } + if (lcm != constants::one) { + LOG_AND_IMPLEMENT("Coefficients meant to be balanced before solving"); + } + if(GetView() != View::Solving && GetView() != View::Equation) { // auto }