[poincare] Move Power vs Unit checks to Power::shallowReduce

This commit is contained in:
Ruben Dashyan
2020-03-20 10:25:16 +01:00
committed by Émilie Feral
parent fa1235939b
commit 1351babe37
2 changed files with 12 additions and 9 deletions

View File

@@ -387,9 +387,18 @@ Expression Power::shallowReduce(ExpressionNode::ReductionContext reductionContex
Expression base = childAtIndex(0);
Expression index = childAtIndex(1);
// Step 1: There should be no unit in the index!
if (index.hasUnit()) {
return replaceWithUndefinedInPlace();
// Step 1: Handle the units
{
if (index.hasUnit()) {
// There must be no unit in the exponent
return replaceWithUndefinedInPlace();
}
if (base.hasUnit()) {
if (index.type() != ExpressionNode::Type::Rational || !static_cast<Rational &>(index).isInteger()) {
// The exponent must be an Integer
return replaceWithUndefinedInPlace();
}
}
}
// Step 2: Handle matrices

View File

@@ -323,12 +323,7 @@ Expression Unit::shallowBeautify(ExpressionNode::ReductionContext reductionConte
m.addChildAtIndexInPlace(*this, 1, 1);
return std::move(m);
}
// Check that the exponent, if any, of a Unit is an integer
if (!ancestor.isUninitialized() && ancestor.type() == ExpressionNode::Type::Power) {
Expression exponent = ancestor.childAtIndex(1);
if (!(exponent.type() == ExpressionNode::Type::Rational && static_cast<Rational &>(exponent).isInteger())) {
goto UnitCheckUnsuccessful;
}
ancestor = ancestor.parent();
}
/* Check homogeneity: at this point, ancestor must be
@@ -344,7 +339,6 @@ Expression Unit::shallowBeautify(ExpressionNode::ReductionContext reductionConte
if (ancestor.isUninitialized()) {
return *this;
}
UnitCheckUnsuccessful:
/* If the latter checks are not successfully passed, then the function
* returns replaceWithUndefinedInPlace.
* TODO Something else should be returned in order to report a more