mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
[poincare] Expression:replaceWithUndefinedInPlace
This commit is contained in:
@@ -297,6 +297,7 @@ protected:
|
||||
|
||||
/* Hierarchy */
|
||||
Expression parent() const; // TODO try to inline
|
||||
Expression replaceWithUndefinedInPlace();
|
||||
void defaultSetChildrenInPlace(Expression other);
|
||||
void addChildAtIndexInPlace(TreeHandle t, int index, int currentNumberOfChildren) = delete;
|
||||
void removeChildAtIndexInPlace(int i) = delete;
|
||||
|
||||
@@ -175,9 +175,7 @@ Expression Addition::shallowReduce(ExpressionNode::ReductionContext reductionCon
|
||||
/* If there is a matrix in the children, the last child is a matrix. If
|
||||
* there is a ascalar, the first child is a scalar.
|
||||
* We forbid the addition of a matrix and a scalar. */
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
// Create the addition matrix (in place of the first child)
|
||||
Matrix resultMatrix = static_cast<Matrix &>(firstChild);
|
||||
@@ -191,9 +189,7 @@ Expression Addition::shallowReduce(ExpressionNode::ReductionContext reductionCon
|
||||
int currentM = currentMatrix.numberOfColumns();
|
||||
if (currentN != n || currentM != m) {
|
||||
// Addition of matrices of different dimensions -> undef
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
// Dispatch the current matrix children in the created addition matrix
|
||||
for (int j = 0; j < n*m; j++) {
|
||||
|
||||
@@ -65,25 +65,19 @@ Expression BinomialCoefficient::shallowReduce(Context * context) {
|
||||
Expression c1 = childAtIndex(1);
|
||||
|
||||
if (SortedIsMatrix(c0, context) || SortedIsMatrix(c1, context)) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
|
||||
if (c0.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r0 = static_cast<Rational&>(c0);
|
||||
if (!r0.integerDenominator().isOne() || r0.isNegative()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c1.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r1 = static_cast<Rational&>(c1);
|
||||
if (!r1.integerDenominator().isOne() || r1.isNegative()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) {
|
||||
@@ -95,9 +89,7 @@ Expression BinomialCoefficient::shallowReduce(Context * context) {
|
||||
Integer n = r0.signedIntegerNumerator();
|
||||
Integer k = r1.signedIntegerNumerator();
|
||||
if (n.isLowerThan(k)) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
/* If n is too big, we do not reduce in order to avoid too long computation.
|
||||
* The binomial coefficient will be approximatively evaluated later. */
|
||||
|
||||
@@ -62,24 +62,18 @@ Expression ConfidenceInterval::shallowReduce(ExpressionNode::ReductionContext re
|
||||
Expression c0 = childAtIndex(0);
|
||||
Expression c1 = childAtIndex(1);
|
||||
if (SortedIsMatrix(c0, reductionContext.context()) || SortedIsMatrix(c1, reductionContext.context())) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
if (c0.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r0 = static_cast<Rational&>(c0);
|
||||
if (r0.signedIntegerNumerator().isNegative() || Integer::NaturalOrder(r0.signedIntegerNumerator(), r0.integerDenominator()) > 0) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c1.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r1 = static_cast<Rational&>(c1);
|
||||
if (!r1.integerDenominator().isOne() || r1.signedIntegerNumerator().isNegative()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) {
|
||||
|
||||
@@ -146,9 +146,7 @@ Expression Derivative::shallowReduce(Context * context) {
|
||||
|| SortedIsMatrix(childAtIndex(1), context)
|
||||
|| SortedIsMatrix(childAtIndex(2), context))
|
||||
{
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
// TODO: to be implemented diff(+) -> +diff() etc
|
||||
return *this;
|
||||
|
||||
@@ -46,24 +46,18 @@ Expression DivisionQuotient::shallowReduce() {
|
||||
Expression c0 = childAtIndex(0);
|
||||
Expression c1 = childAtIndex(1);
|
||||
if (c0.type() == ExpressionNode::Type::Matrix || c1.type() == ExpressionNode::Type::Matrix) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
if (c0.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r0 = static_cast<Rational &>(c0);
|
||||
if (!r0.integerDenominator().isOne()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c1.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r1 = static_cast<Rational &>(c1);
|
||||
if (!r1.integerDenominator().isOne()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) {
|
||||
|
||||
@@ -47,24 +47,18 @@ Expression DivisionRemainder::shallowReduce() {
|
||||
Expression c0 = childAtIndex(0);
|
||||
Expression c1 = childAtIndex(1);
|
||||
if (c0.type() == ExpressionNode::Type::Matrix || c1.type() == ExpressionNode::Type::Matrix) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
if (c0.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r0 = static_cast<Rational &>(c0);
|
||||
if (!r0.integerDenominator().isOne()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c1.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r1 = static_cast<Rational &>(c1);
|
||||
if (!r1.integerDenominator().isOne()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/expression_node.h>
|
||||
#include <poincare/rational.h>
|
||||
#include <poincare/opposite.h>
|
||||
#include <poincare/undefined.h>
|
||||
#include <poincare/rational.h>
|
||||
#include <poincare/symbol.h>
|
||||
#include <poincare/undefined.h>
|
||||
#include <poincare/variable_context.h>
|
||||
#include <ion.h>
|
||||
#include <ion/unicode/utf8_helper.h>
|
||||
@@ -240,6 +240,12 @@ Expression Expression::parent() const {
|
||||
return static_cast<Expression &>(p);
|
||||
}
|
||||
|
||||
Expression Expression::replaceWithUndefinedInPlace() {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Expression::defaultSetChildrenInPlace(Expression other) {
|
||||
assert(numberOfChildren() == other.numberOfChildren());
|
||||
for (int i = 0; i < numberOfChildren(); i++) {
|
||||
|
||||
@@ -67,9 +67,7 @@ Expression Factor::shallowReduce() {
|
||||
}
|
||||
}
|
||||
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { // TODO LEA SortedIsMatrix?
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -77,9 +75,7 @@ Expression Factor::shallowReduce() {
|
||||
Expression Factor::shallowBeautify(ExpressionNode::ReductionContext reductionContext) {
|
||||
Expression c = childAtIndex(0);
|
||||
if (c.type() != ExpressionNode::Type::Rational) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
Rational r = static_cast<Rational &>(c);
|
||||
if (r.isZero()) {
|
||||
@@ -88,17 +84,13 @@ Expression Factor::shallowBeautify(ExpressionNode::ReductionContext reductionCon
|
||||
}
|
||||
Multiplication numeratorDecomp = createMultiplicationOfIntegerPrimeDecomposition(r.unsignedIntegerNumerator(), reductionContext.context(), reductionContext.complexFormat(), reductionContext.angleUnit());
|
||||
if (numeratorDecomp.numberOfChildren() == 0) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
Expression result = numeratorDecomp.squashUnaryHierarchyInPlace();
|
||||
if (!r.integerDenominator().isOne()) {
|
||||
Multiplication denominatorDecomp = createMultiplicationOfIntegerPrimeDecomposition(r.integerDenominator(), reductionContext.context(), reductionContext.complexFormat(), reductionContext.angleUnit());
|
||||
if (denominatorDecomp.numberOfChildren() == 0) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
result = Division::Builder(result, denominatorDecomp.squashUnaryHierarchyInPlace());
|
||||
}
|
||||
|
||||
@@ -91,9 +91,7 @@ Expression Factorial::shallowReduce(ExpressionNode::ReductionContext reductionCo
|
||||
if (c.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r = c.convert<Rational>();
|
||||
if (!r.integerDenominator().isOne() || r.sign() == ExpressionNode::Sign::Negative) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
if (Integer(k_maxOperandValue).isLowerThan(r.unsignedIntegerNumerator())) {
|
||||
return *this;
|
||||
@@ -105,9 +103,7 @@ Expression Factorial::shallowReduce(ExpressionNode::ReductionContext reductionCo
|
||||
}
|
||||
if (c.type() == ExpressionNode::Type::Constant) {
|
||||
// e! = undef, i! = undef, pi! = undef
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -138,9 +138,7 @@ Expression Function::shallowReduce(ExpressionNode::ReductionContext reductionCon
|
||||
return e.deepReduce(reductionContext);
|
||||
}
|
||||
if (!reductionContext.symbolicComputation()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -60,24 +60,18 @@ Expression GreatCommonDivisor::shallowReduce() {
|
||||
Expression c0 = childAtIndex(0);
|
||||
Expression c1 = childAtIndex(1);
|
||||
if (c0.type() == ExpressionNode::Type::Matrix || c1.type() == ExpressionNode::Type::Matrix) { //TODO LEA SortedIsMatrix ?
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
if (c0.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r0 = static_cast<Rational &>(c0);
|
||||
if (!r0.integerDenominator().isOne()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c1.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r1 = static_cast<Rational&>(c1);
|
||||
if (!r1.integerDenominator().isOne()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) {
|
||||
|
||||
@@ -225,9 +225,7 @@ Expression Integral::shallowReduce(Context * context) {
|
||||
|| SortedIsMatrix(childAtIndex(2), context)
|
||||
|| SortedIsMatrix(childAtIndex(3), context))
|
||||
{
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -64,24 +64,18 @@ Expression LeastCommonMultiple::shallowReduce() {
|
||||
Expression c0 = childAtIndex(0);
|
||||
Expression c1 = childAtIndex(1);
|
||||
if (c0.type() == ExpressionNode::Type::Matrix || c1.type() == ExpressionNode::Type::Matrix) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
if (c0.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r0 = static_cast<Rational &>(c0);
|
||||
if (!r0.integerDenominator().isOne()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c1.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r1 = static_cast<Rational &>(c1);
|
||||
if (!r1.integerDenominator().isOne()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) {
|
||||
|
||||
@@ -111,9 +111,7 @@ Expression Logarithm::shallowReduce(ExpressionNode::ReductionContext reductionCo
|
||||
}
|
||||
|
||||
if (SortedIsMatrix(childAtIndex(1), reductionContext.context())) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
|
||||
Expression c = childAtIndex(0);
|
||||
@@ -220,15 +218,11 @@ Expression Logarithm::simpleShallowReduce(Context * context, Preferences::Comple
|
||||
Expression b = childAtIndex(1);
|
||||
// log(0,0)->Undefined
|
||||
if (c.type() == ExpressionNode::Type::Rational && b.type() == ExpressionNode::Type::Rational && static_cast<Rational &>(b).isZero() && static_cast<Rational &>(c).isZero()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
// log(x,1)->Undefined
|
||||
if (b.type() == ExpressionNode::Type::Rational && static_cast<Rational &>(b).isOne()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
bool infiniteArg = c.recursivelyMatches(Expression::IsInfinity, context);
|
||||
// log(x,x)->1 with x != inf and log(inf,inf) = undef
|
||||
@@ -251,9 +245,7 @@ Expression Logarithm::simpleShallowReduce(Context * context, Preferences::Comple
|
||||
bool infiniteBase = b.recursivelyMatches(Expression::IsInfinity, context);
|
||||
// Special case: log(0,inf) -> undef
|
||||
if (infiniteBase) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
bool isNegative = true;
|
||||
Expression result;
|
||||
|
||||
@@ -47,22 +47,19 @@ Expression MatrixIdentity::shallowReduce(ExpressionNode::ReductionContext reduct
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
|
||||
Expression c = childAtIndex(0);
|
||||
if (!c.isRationalOne()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
Integer dimension = static_cast<Rational &>(c).signedIntegerNumerator();
|
||||
if (Integer::NaturalOrder(dimension, Integer(Integer::k_maxExtractableInteger)) > 0) {
|
||||
return *this;
|
||||
}
|
||||
int dim = dimension.extractedInt();
|
||||
Expression result = Matrix::CreateIdentity(dim);
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
Expression c = childAtIndex(0);
|
||||
if (!c.isRationalOne()) {
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
Integer dimension = static_cast<Rational &>(c).signedIntegerNumerator();
|
||||
if (Integer::NaturalOrder(dimension, Integer(Integer::k_maxExtractableInteger)) > 0) {
|
||||
return *this;
|
||||
}
|
||||
int dim = dimension.extractedInt();
|
||||
Expression result = Matrix::CreateIdentity(dim);
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -297,9 +297,7 @@ Expression Multiplication::privateShallowReduce(ExpressionNode::ReductionContext
|
||||
int currentM = currentMatrix.numberOfColumns();
|
||||
if (currentM != n) {
|
||||
// Matrices dimensions do not match for multiplication
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
/* Create the matrix resulting of the multiplication of the current matrix
|
||||
* and the result matrix
|
||||
|
||||
@@ -72,9 +72,7 @@ Expression NthRoot::shallowReduce(ExpressionNode::ReductionContext reductionCont
|
||||
}
|
||||
}
|
||||
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix || childAtIndex(1).type() == ExpressionNode::Type::Matrix) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
Expression invIndex = Power::Builder(childAtIndex(1), Rational::Builder(-1));
|
||||
Power p = Power::Builder(childAtIndex(0), invIndex);
|
||||
|
||||
@@ -60,24 +60,18 @@ Expression PermuteCoefficient::shallowReduce() {
|
||||
Expression c0 = childAtIndex(0);
|
||||
Expression c1 = childAtIndex(1);
|
||||
if (c0.type() == ExpressionNode::Type::Matrix || c1.type() == ExpressionNode::Type::Matrix) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
if (c0.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r0 = static_cast<Rational &>(c0);
|
||||
if (!r0.integerDenominator().isOne() || r0.sign() == ExpressionNode::Sign::Negative) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c1.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r1 = static_cast<Rational &>(c1);
|
||||
if (!r1.integerDenominator().isOne() || r1.sign() == ExpressionNode::Sign::Negative) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) {
|
||||
|
||||
@@ -292,9 +292,7 @@ Expression Power::shallowReduce(ExpressionNode::ReductionContext reductionContex
|
||||
|
||||
// Step 0: Handle matrices
|
||||
if (index.type() == ExpressionNode::Type::Matrix) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
if (base.type() == ExpressionNode::Type::Matrix) {
|
||||
Matrix matrixBase = static_cast<Matrix &>(base);
|
||||
@@ -302,9 +300,7 @@ Expression Power::shallowReduce(ExpressionNode::ReductionContext reductionContex
|
||||
|| !static_cast<Rational &>(index).integerDenominator().isOne()
|
||||
|| matrixBase.numberOfRows() != matrixBase.numberOfColumns())
|
||||
{
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
Integer exponent = static_cast<Rational &>(index).signedIntegerNumerator();
|
||||
if (exponent.isNegative()) {
|
||||
@@ -359,9 +355,7 @@ Expression Power::shallowReduce(ExpressionNode::ReductionContext reductionContex
|
||||
if (b.isZero()) {
|
||||
// 0^0 = undef or (±inf)^0 = undef
|
||||
if ((childAtIndex(0).type() == ExpressionNode::Type::Rational && childAtIndex(0).convert<Rational>().isZero()) || childAtIndex(0).type() == ExpressionNode::Type::Infinity) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
// x^0
|
||||
if (reductionContext.target() == ExpressionNode::ReductionTarget::User || childAtIndex(0).isNumber()) {
|
||||
@@ -393,9 +387,7 @@ Expression Power::shallowReduce(ExpressionNode::ReductionContext reductionContex
|
||||
}
|
||||
// 0^x with x < 0 = undef
|
||||
if (childAtIndex(1).sign(reductionContext.context()) == ExpressionNode::Sign::Negative) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
// 1^x = 1 if x != ±inf
|
||||
|
||||
@@ -57,24 +57,18 @@ Expression PredictionInterval::shallowReduce(ExpressionNode::ReductionContext re
|
||||
Expression c0 = childAtIndex(0);
|
||||
Expression c1 = childAtIndex(1);
|
||||
if (c0.type() == ExpressionNode::Type::Matrix || c1.type() == ExpressionNode::Type::Matrix) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
if (c0.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r0 = static_cast<Rational &>(c0);
|
||||
if (r0.sign() == ExpressionNode::Sign::Negative || Integer::NaturalOrder(r0.unsignedIntegerNumerator(), r0.integerDenominator()) > 0) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c1.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r1 = static_cast<Rational &>(c1);
|
||||
if (!r1.integerDenominator().isOne() || r1.sign() == ExpressionNode::Sign::Negative) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) {
|
||||
@@ -83,9 +77,7 @@ Expression PredictionInterval::shallowReduce(ExpressionNode::ReductionContext re
|
||||
Rational r0 = static_cast<Rational &>(c0);
|
||||
Rational r1 = static_cast<Rational &>(c1);
|
||||
if (!r1.integerDenominator().isOne() || r1.sign() == ExpressionNode::Sign::Negative || r0.sign() == ExpressionNode::Sign::Negative || Integer::NaturalOrder(r0.unsignedIntegerNumerator(), r0.integerDenominator()) > 0) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
/* [r0-1.96*sqrt(r0*(1-r0)/r1), r0+1.96*sqrt(r0*(1-r0)/r1)]*/
|
||||
// Compute numerator = r0*(1-r0)
|
||||
|
||||
@@ -46,9 +46,7 @@ Expression Round::shallowReduce(ExpressionNode::ReductionContext reductionContex
|
||||
}
|
||||
}
|
||||
if (childAtIndex(1).type() == ExpressionNode::Type::Matrix) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) {
|
||||
return mapOnMatrixFirstChild(reductionContext);
|
||||
@@ -59,9 +57,7 @@ Expression Round::shallowReduce(ExpressionNode::ReductionContext reductionContex
|
||||
Rational r1 = childAtIndex(0).convert<Rational>();
|
||||
Rational r2 = childAtIndex(1).convert<Rational>();
|
||||
if (!r2.integerDenominator().isOne()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
const Rational ten = Rational::Builder(10);
|
||||
if (Power::RationalExponentShouldNotBeReduced(ten, r2)) {
|
||||
|
||||
@@ -56,9 +56,7 @@ Expression Sequence::shallowReduce() {
|
||||
}
|
||||
assert(childAtIndex(1).type() != ExpressionNode::Type::Matrix);
|
||||
if (childAtIndex(2).type() == ExpressionNode::Type::Matrix || childAtIndex(3).type() == ExpressionNode::Type::Matrix) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -63,9 +63,7 @@ Expression SignFunction::shallowReduce(ExpressionNode::ReductionContext reductio
|
||||
}
|
||||
Expression child = childAtIndex(0);
|
||||
if (child.type() == ExpressionNode::Type::Matrix) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
Rational resultSign = Rational::Builder(1);
|
||||
ExpressionNode::Sign s = child.sign(reductionContext.context());
|
||||
|
||||
@@ -52,9 +52,7 @@ Expression SquareRoot::shallowReduce(ExpressionNode::ReductionContext reductionC
|
||||
}
|
||||
Expression c = childAtIndex(0);
|
||||
if (c.type() == ExpressionNode::Type::Matrix) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
Power p = Power::Builder(c, Rational::Builder(1, 2));
|
||||
replaceWithInPlace(p);
|
||||
|
||||
Reference in New Issue
Block a user