mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-24 08:10:50 +01:00
[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.
This commit is contained in:
committed by
LeaNumworks
parent
78e4c9066f
commit
ec08f027c0
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<typename U>
|
||||
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<U>(context, angleUnit);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user