mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[poincare/src] Use reduce before removeUnit
With deepReduce(), when a simplifiaction was interrupted, expression could contain Undefined children, which would trigger the assert in removeUnit(). With reduce(), if a simplification is interrupted, the entire expression becomes Undefined, which is handled by removeUnits().
This commit is contained in:
committed by
EmilieNumworks
parent
5bc9579db6
commit
7146eff7ee
@@ -425,8 +425,8 @@ Expression Multiplication::shallowBeautify(ExpressionNode::ReductionContext * re
|
||||
Expression units;
|
||||
/* 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);
|
||||
self = self.reduce(ExpressionNode::ReductionContext::NonInvasiveReductionContext(*reductionContext));
|
||||
self = self.removeUnit(&units);
|
||||
|
||||
if (self.isUndefined() || units.isUninitialized()) {
|
||||
// TODO: handle error "Invalid unit"
|
||||
@@ -501,7 +501,7 @@ Expression Multiplication::shallowBeautify(ExpressionNode::ReductionContext * re
|
||||
// Apply simplifications
|
||||
if (unitsAccu.numberOfChildren() > 0) {
|
||||
// Divide by derived units
|
||||
units = Division::Builder(units, unitsAccu.clone()).deepReduce(*reductionContext);
|
||||
units = Division::Builder(units, unitsAccu.clone()).reduce(*reductionContext);
|
||||
Expression newUnits;
|
||||
// Separate units and generated values
|
||||
units = units.removeUnit(&newUnits);
|
||||
|
||||
@@ -50,7 +50,7 @@ void UnitConvert::deepReduceChildren(ExpressionNode::ReductionContext reductionC
|
||||
reductionContext.target(),
|
||||
ExpressionNode::SymbolicComputation::ReplaceAllSymbolsWithUndefined,
|
||||
ExpressionNode::UnitConversion::None);
|
||||
// Don't transform the targetted unit
|
||||
// Don't transform the targeted unit
|
||||
childAtIndex(1).deepReduce(reductionContextKeepUnitAsIs);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ Expression UnitConvert::shallowBeautify(ExpressionNode::ReductionContext * reduc
|
||||
reductionContext->target(),
|
||||
ExpressionNode::SymbolicComputation::ReplaceAllSymbolsWithUndefined);
|
||||
Expression unit;
|
||||
Expression childWithoutUnit = childAtIndex(1).clone().deepReduce(reductionContextWithUnits).removeUnit(&unit);
|
||||
Expression childWithoutUnit = childAtIndex(1).clone().reduce(reductionContextWithUnits).removeUnit(&unit);
|
||||
if (childWithoutUnit.isUndefined() || unit.isUninitialized()) {
|
||||
// There is no unit on the right
|
||||
return replaceWithUndefinedInPlace();
|
||||
@@ -104,7 +104,7 @@ Expression UnitConvert::shallowBeautify(ExpressionNode::ReductionContext * reduc
|
||||
|
||||
// Divide the left member by the new unit
|
||||
Expression division = Division::Builder(childAtIndex(0), unit.clone());
|
||||
division = division.deepReduce(*reductionContext);
|
||||
division = division.reduce(*reductionContext);
|
||||
Expression divisionUnit;
|
||||
division = division.removeUnit(&divisionUnit);
|
||||
if (!divisionUnit.isUninitialized()) {
|
||||
|
||||
Reference in New Issue
Block a user