From ec08f027c0cf72a60ccfcf71a64d3156607807eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 18 Dec 2018 09:54:20 +0100 Subject: [PATCH] [poincare] Revert: Use Simplify instead of Reduce II To approximate an expression, it is more precise to approximate its simplified form than its reduced form. Indeed, we want to minimize the number of nodes in the expression before approximating. For instance, a/b has fewer nodes than a*b^-1. --- apps/shared/storage_expression_model.cpp | 7 ++++++- poincare/include/poincare/expression.h | 1 - poincare/src/expression.cpp | 10 +--------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/apps/shared/storage_expression_model.cpp b/apps/shared/storage_expression_model.cpp index 66a143b2b..2f7ac146f 100644 --- a/apps/shared/storage_expression_model.cpp +++ b/apps/shared/storage_expression_model.cpp @@ -39,7 +39,12 @@ Expression StorageExpressionModel::expressionReduced(Poincare::Context * context if (m_expression.isUninitialized()) { assert(!isNull()); Ion::Storage::Record::Data recordData = value(); - m_expression = Expression::ExpressionFromAddress(expressionAddressForValue(recordData), expressionSizeForValue(recordData)).reduce(*context, Preferences::sharedPreferences()->angleUnit()); + m_expression = Expression::ExpressionFromAddress(expressionAddressForValue(recordData), expressionSizeForValue(recordData)); + PoincareHelpers::Simplify(&m_expression, *context); + // simplify might return an uninitialized Expression if interrupted + if (m_expression.isUninitialized()) { + m_expression = Expression::ExpressionFromAddress(expressionAddressForValue(recordData), expressionSizeForValue(recordData)); + } } return m_expression; } diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index aaca8f7bf..f6feb43f4 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -167,7 +167,6 @@ public: int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const; /* Simplification */ - static Expression ParseAndReduce(const char * text, Context & context, Preferences::AngleUnit); static Expression ParseAndSimplify(const char * text, Context & context, Preferences::AngleUnit angleUnit); Expression simplify(Context & context, Preferences::AngleUnit angleUnit); Expression reduce(Context & context, Preferences::AngleUnit angleUnit); diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index 1363d40de..8df1b9a5b 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -312,14 +312,6 @@ int Expression::serialize(char * buffer, int bufferSize, Preferences::PrintFloat /* Simplification */ -Expression Expression::ParseAndReduce(const char * text, Context & context, Preferences::AngleUnit angleUnit) { - Expression exp = Parse(text); - if (exp.isUninitialized()) { - return Undefined(); - } - return exp.reduce(context, angleUnit); -} - Expression Expression::ParseAndSimplify(const char * text, Context & context, Preferences::AngleUnit angleUnit) { Expression exp = Parse(text); if (exp.isUninitialized()) { @@ -423,7 +415,7 @@ U Expression::approximateToScalar(Context& context, Preferences::AngleUnit angle template U Expression::approximateToScalar(const char * text, Context& context, Preferences::AngleUnit angleUnit) { - Expression exp = ParseAndReduce(text, context, angleUnit); + Expression exp = ParseAndSimplify(text, context, angleUnit); return exp.approximateToScalar(context, angleUnit); }