[poincare] In Multiplication::shallowBeautify, when extracting the unit,

reduce without changing the unit in order to extract the right unit.

This fixes the following bug: simplify "πππ23*_cK"
This commit is contained in:
Émilie Feral
2020-11-05 17:24:13 +01:00
committed by LeaNumworks
parent 50bc31fcfa
commit d789e8da97
2 changed files with 14 additions and 1 deletions

View File

@@ -191,6 +191,17 @@ public:
m_symbolicComputation(symbolicComputation),
m_unitConversion(unitConversion)
{}
static ReductionContext NonInvasiveReductionContext(ReductionContext reductionContext) {
return ReductionContext(
reductionContext.context(),
reductionContext.complexFormat(),
reductionContext.angleUnit(),
reductionContext.unitFormat(),
reductionContext.target(),
SymbolicComputation::DoNotReplaceAnySymbol,
UnitConversion::None
);
}
Preferences::UnitFormat unitFormat() const { return m_unitFormat; }
ReductionTarget target() const { return m_target; }
SymbolicComputation symbolicComputation() const { return m_symbolicComputation; }

View File

@@ -423,7 +423,9 @@ Expression Multiplication::shallowBeautify(ExpressionNode::ReductionContext redu
// Step 2: Handle the units
if (hasUnit()) {
Expression units;
self = deepReduce(reductionContext); // removeUnit has to be called on reduced expression
/* removeUnit has to be called on reduced expression but we want to modify
* the least the expression so we use the uninvasive reduction context. */
self = deepReduce(ExpressionNode::ReductionContext::NonInvasiveReductionContext(reductionContext));
self = removeUnit(&units);
if (self.isUndefined() || units.isUninitialized()) {