[poincare] Expression::mapOnMatrixChild -> mapOnMatrixFirstChild

This commit is contained in:
Léa Saviot
2019-07-02 17:48:51 +02:00
committed by Émilie Feral
parent c3d5db42d1
commit 7cf3ce4fee
21 changed files with 25 additions and 23 deletions

View File

@@ -214,7 +214,7 @@ public:
void simplifyAndApproximate(Expression * simplifiedExpression, Expression * approximateExpression, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, bool symbolicComputation = true);
Expression reduce(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
Expression mapOnMatrixChild(ExpressionNode::ReductionContext reductionContext);
Expression mapOnMatrixFirstChild(ExpressionNode::ReductionContext reductionContext);
static Expression ExpressionWithoutSymbols(Expression expressionWithSymbols, Context * context);
Expression radianToDegree();
Expression degreeToRadian();

View File

@@ -37,7 +37,7 @@ Expression AbsoluteValue::shallowReduce(ExpressionNode::ReductionContext reducti
}
Expression c = childAtIndex(0);
if (c.type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
if (c.isReal(reductionContext.context())) {
float app = c.node()->approximate(float(), reductionContext.context(), reductionContext.complexFormat(), reductionContext.angleUnit()).toScalar();

View File

@@ -57,7 +57,7 @@ Expression ArcCosine::shallowReduce(ExpressionNode::ReductionContext reductionCo
}
}
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
return Trigonometry::shallowReduceInverseFunction(*this, reductionContext);
}

View File

@@ -57,7 +57,7 @@ Expression ArcSine::shallowReduce(ExpressionNode::ReductionContext reductionCont
}
}
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
return Trigonometry::shallowReduceInverseFunction(*this, reductionContext);
}

View File

@@ -56,7 +56,7 @@ Expression ArcTangent::shallowReduce(ExpressionNode::ReductionContext reductionC
}
}
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
return Trigonometry::shallowReduceInverseFunction(*this, reductionContext);
}

View File

@@ -45,7 +45,7 @@ Expression Ceiling::shallowReduce(ExpressionNode::ReductionContext reductionCont
}
Expression c = childAtIndex(0);
if (c.type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
if (c.type() == ExpressionNode::Type::Constant) {
Constant s = static_cast<Constant&>(c);

View File

@@ -43,7 +43,7 @@ Expression ComplexArgument::shallowReduce(ExpressionNode::ReductionContext reduc
}
Expression c = childAtIndex(0);
if (c.type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
bool real = c.isReal(reductionContext.context());
if (real) {

View File

@@ -41,7 +41,7 @@ Expression Conjugate::shallowReduce(ExpressionNode::ReductionContext reductionCo
}
Expression c = childAtIndex(0);
if (c.type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
if (c.isReal(reductionContext.context())) {
replaceWithInPlace(c);

View File

@@ -43,7 +43,7 @@ Expression Cosine::shallowReduce(ExpressionNode::ReductionContext reductionConte
}
Expression c = childAtIndex(0);
if (c.type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
return Trigonometry::shallowReduceDirectFunction(*this, reductionContext);
}

View File

@@ -530,8 +530,10 @@ Expression Expression::ExpressionWithoutSymbols(Expression e, Context * context)
return e;
}
Expression Expression::mapOnMatrixChild(ExpressionNode::ReductionContext reductionContext) {
assert(numberOfChildren() == 1 && childAtIndex(0).type() == ExpressionNode::Type::Matrix);
Expression Expression::mapOnMatrixFirstChild(ExpressionNode::ReductionContext reductionContext) {
/* For now, the matrix child on which the mapping must be done is always at
* the index 0. */
assert(childAtIndex(0).type() == ExpressionNode::Type::Matrix);
Expression c = childAtIndex(0);
Matrix matrix = Matrix::Builder();
for (int i = 0; i < c.numberOfChildren(); i++) {

View File

@@ -86,7 +86,7 @@ Expression Factorial::shallowReduce(ExpressionNode::ReductionContext reductionCo
}
Expression c = childAtIndex(0);
if (c.type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
if (c.type() == ExpressionNode::Type::Rational) {
Rational r = c.convert<Rational>();

View File

@@ -44,7 +44,7 @@ Expression Floor::shallowReduce(ExpressionNode::ReductionContext reductionContex
}
Expression c = childAtIndex(0);
if (c.type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
if (c.type() == ExpressionNode::Type::Constant) {
Constant s = static_cast<Constant &>(c);

View File

@@ -41,7 +41,7 @@ Expression FracPart::shallowReduce(ExpressionNode::ReductionContext reductionCon
}
Expression c = childAtIndex(0);
if (c.type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
if (c.type() != ExpressionNode::Type::Rational) {
return *this;

View File

@@ -16,7 +16,7 @@ Expression HyperbolicTrigonometricFunction::shallowReduce(ExpressionNode::Reduct
}
Expression c = childAtIndex(0);
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
return *this;
}

View File

@@ -33,7 +33,7 @@ Expression ImaginaryPart::shallowReduce(ExpressionNode::ReductionContext reducti
}
Expression c = childAtIndex(0);
if (c.type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
if (c.isReal(reductionContext.context())) {
Expression result = Rational::Builder(0);

View File

@@ -95,7 +95,7 @@ Expression CommonLogarithm::shallowReduce(ExpressionNode::ReductionContext reduc
}
Expression c = childAtIndex(0);
if (c.type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
Logarithm log = Logarithm::Builder(childAtIndex(0), Rational::Builder(10));
replaceWithInPlace(log);
@@ -209,7 +209,7 @@ Expression Logarithm::shallowReduce(ExpressionNode::ReductionContext reductionCo
// log(m) with m Matrix
if (c.type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
return *this;

View File

@@ -32,7 +32,7 @@ Expression NaperianLogarithm::shallowReduce(ExpressionNode::ReductionContext red
}
Expression c = childAtIndex(0);
if (c.type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
Logarithm l = Logarithm::Builder(c, Constant::Builder(UCodePointScriptSmallE));
replaceWithInPlace(l);

View File

@@ -33,7 +33,7 @@ Expression RealPart::shallowReduce(ExpressionNode::ReductionContext reductionCon
}
Expression c = childAtIndex(0);
if (c.type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
if (c.isReal(reductionContext.context())) {
replaceWithInPlace(c);

View File

@@ -51,7 +51,7 @@ Expression Round::shallowReduce(ExpressionNode::ReductionContext reductionContex
return result;
}
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
/* We reduce only round(Rational, Rational). We do not reduce
* round(Float, Float) which is equivalent to what is done in approximate. */

View File

@@ -43,7 +43,7 @@ Expression Sine::shallowReduce(ExpressionNode::ReductionContext reductionContext
}
}
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
return Trigonometry::shallowReduceDirectFunction(*this, reductionContext);
}

View File

@@ -47,7 +47,7 @@ Expression Tangent::shallowReduce(ExpressionNode::ReductionContext reductionCont
}
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) {
return mapOnMatrixChild(reductionContext);
return mapOnMatrixFirstChild(reductionContext);
}
Expression newExpression = Trigonometry::shallowReduceDirectFunction(*this, reductionContext);