mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/calculation][apps/solver][poincare] Simplify sign =/≈ computation
between outputs in Calculation/Solver
This commit is contained in:
@@ -296,15 +296,9 @@ Calculation::EqualSign Calculation::exactAndApproximateDisplayedOutputsAreEqual(
|
||||
* Store in the exactOutput. */
|
||||
Poincare::ExceptionCheckpoint ecp;
|
||||
if (ExceptionRun(ecp)) {
|
||||
constexpr int bufferSize = Constant::MaxSerializedExpressionSize + 30;
|
||||
char buffer[bufferSize];
|
||||
Preferences * preferences = Preferences::sharedPreferences();
|
||||
Expression exactOutputExpression = PoincareHelpers::ParseAndSimplify(exactOutputText(), context, false);
|
||||
if (exactOutputExpression.isUninitialized()) {
|
||||
exactOutputExpression = Undefined::Builder();
|
||||
}
|
||||
Preferences::ComplexFormat complexFormat = Expression::UpdatedComplexFormatWithTextInput(preferences->complexFormat(), m_inputText);
|
||||
m_equalSign = exactOutputExpression.isEqualToItsApproximationLayout(approximateOutput(context, NumberOfSignificantDigits::UserDefined), buffer, bufferSize, complexFormat, preferences->angleUnit(), preferences->displayMode(), preferences->numberOfSignificantDigits(), context) ? EqualSign::Equal : EqualSign::Approximation;
|
||||
m_equalSign = Expression::ParsedExpressionsAreEqual(exactOutputText(), approximateOutputText(NumberOfSignificantDigits::UserDefined), context, complexFormat, preferences->angleUnit()) ? EqualSign::Equal : EqualSign::Approximation;
|
||||
return m_equalSign;
|
||||
} else {
|
||||
/* Do not override m_equalSign in case there is enough room in the pool
|
||||
|
||||
@@ -218,8 +218,7 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) {
|
||||
* Dutch exam mode to display only the approximate solutions. */
|
||||
m_exactSolutionIdentity[solutionIndex] = forbidExactSolutions || strcmp(exactBuffer, approximateBuffer) == 0;
|
||||
if (!m_exactSolutionIdentity[solutionIndex]) {
|
||||
char buffer[::Constant::MaxSerializedExpressionSize];
|
||||
m_exactSolutionEquality[solutionIndex] = exactSolutions[i].isEqualToItsApproximationLayout(exactSolutionsApproximations[i], buffer, ::Constant::MaxSerializedExpressionSize, preferences->complexFormat(), preferences->angleUnit(), preferences->displayMode(), preferences->numberOfSignificantDigits(), context);
|
||||
m_exactSolutionEquality[solutionIndex] = Expression::ParsedExpressionsAreEqual(exactBuffer, approximateBuffer, context, updatedComplexFormat(context), preferences->angleUnit());
|
||||
}
|
||||
solutionIndex++;
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ public:
|
||||
* same structures and all their nodes have same types and values (ie,
|
||||
* sqrt(pi^2) is NOT identical to pi). */
|
||||
bool isIdenticalTo(const Expression e) const;
|
||||
bool isEqualToItsApproximationLayout(Expression approximation, char * buffer, int bufferSize, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, Context * context);
|
||||
static bool ParsedExpressionsAreEqual(const char * e0, const char * e1, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
|
||||
/* Layout Helper */
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const;
|
||||
|
||||
@@ -522,17 +522,13 @@ bool Expression::isIdenticalTo(const Expression e) const {
|
||||
return ExpressionNode::SimplificationOrder(node(), e.node(), true, true) == 0;
|
||||
}
|
||||
|
||||
bool Expression::isEqualToItsApproximationLayout(Expression approximation, char * buffer, int bufferSize, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, Context * context) {
|
||||
approximation.serialize(buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits);
|
||||
/* Warning: we cannot use directly the the approximate expression but we have
|
||||
* to re-serialize it because the number of stored significative
|
||||
* numbers and the number of displayed significative numbers might not be
|
||||
* identical. (For example, 0.000025 might be displayed "0.00003" and stored
|
||||
* as Decimal(0.000025) and isEqualToItsApproximationLayout should return
|
||||
* false) */
|
||||
Expression approximateOutput = Expression::ParseAndSimplify(buffer, context, complexFormat, angleUnit, true);
|
||||
bool equal = isIdenticalTo(approximateOutput);
|
||||
return equal;
|
||||
bool Expression::ParsedExpressionsAreEqual(const char * e0, const char * e1, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
Expression exp0 = Expression::ParseAndSimplify(e0, context, complexFormat, angleUnit, false);
|
||||
Expression exp1 = Expression::ParseAndSimplify(e1, context, complexFormat, angleUnit, false);
|
||||
if (exp0.isUninitialized() || exp1.isUninitialized()) {
|
||||
return false;
|
||||
}
|
||||
return exp0.isIdenticalTo(exp1);
|
||||
}
|
||||
|
||||
/* Layout Helper */
|
||||
|
||||
Reference in New Issue
Block a user