mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Move Power vs Unit checks to Power::shallowReduce
This commit is contained in:
committed by
Émilie Feral
parent
fa1235939b
commit
1351babe37
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user