[poincare] Update matrix transpose, dimension, inverse, trace

This commit is contained in:
Léa Saviot
2018-08-31 17:39:24 +02:00
parent 3eb47d6255
commit 3112d4a130
6 changed files with 30 additions and 14 deletions

View File

@@ -41,6 +41,10 @@ class Expression : public TreeByReference {
friend class Integral;
friend class LeastCommonMultiple;
friend class Logarithm;
friend class MatrixDimension;
friend class MatrixInverse;
friend class MatrixTrace;
friend class MatrixTranspose;
friend class Sine;
friend class Store;

View File

@@ -48,4 +48,3 @@ public:
}
#endif

View File

@@ -40,9 +40,11 @@ Evaluation<T> MatrixDimensionNode::templatedApproximate(Context& context, Prefer
}
Expression MatrixDimension::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
Expression e = Expression::defaultShallowReduce(context, angleUnit);
if (e.isUndefinedOrAllocationFailure()) {
return e;
{
Expression e = Expression::defaultShallowReduce(context, angleUnit);
if (e.isUndefinedOrAllocationFailure()) {
return e;
}
}
Expression c = childAtIndex(0);
#if MATRIX_EXACT_REDUCING
@@ -68,6 +70,7 @@ Expression MatrixDimension::shallowReduce(Context & context, Preferences::AngleU
result.addChildAtIndexInPlace(Rational(1), 0, 0);
result.addChildAtIndexInPlace(Rational(1), 1, 1);
result.setDimensions(1, 2);
replaceWithInPlace(result);
return result;
}
return *this;

View File

@@ -45,9 +45,11 @@ Evaluation<T> MatrixInverseNode::templatedApproximate(Context& context, Preferen
}
Expression MatrixInverse::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
Expression e = Expression::defaultShallowReduce(context, angleUnit);
if (e.isUndefinedOrAllocationFailure()) {
return e;
{
Expression e = Expression::defaultShallowReduce(context, angleUnit);
if (e.isUndefinedOrAllocationFailure()) {
return e;
}
}
Expression c = childAtIndex(0);
#if MATRIX_EXACT_REDUCING
@@ -63,7 +65,9 @@ Expression MatrixInverse::shallowReduce(Context & context, Preferences::AngleUni
return *this;
#else
if (c.type() != ExpressionNode::Type::Matrix) {
return Power(c, Rational(-1)).shallowReduce(context, angleUnit);
Expression result = Power(c, Rational(-1)).shallowReduce(context, angleUnit);
replaceWithInPlace(result);
return result;
}
return *this;
#endif

View File

@@ -35,9 +35,11 @@ Evaluation<T> MatrixTraceNode::templatedApproximate(Context& context, Preference
}
Expression MatrixTrace::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
Expression e = Expression::defaultShallowReduce(context, angleUnit);
if (e.isUndefinedOrAllocationFailure()) {
return e;
{
Expression e = Expression::defaultShallowReduce(context, angleUnit);
if (e.isUndefinedOrAllocationFailure()) {
return e;
}
}
Expression c = childAtIndex(0);
#if MATRIX_EXACT_REDUCING
@@ -59,6 +61,7 @@ Expression MatrixTrace::shallowReduce(Context & context, Preferences::AngleUnit
return *this;
#else
if (c.type() != ExpressionNode::Type::Matrix) {
replaceWithInPlace(c);
return c;
}
return *this;

View File

@@ -39,9 +39,11 @@ Evaluation<T> MatrixTransposeNode::templatedApproximate(Context& context, Prefer
}
Expression MatrixTranspose::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
Expression e = Expression::defaultShallowReduce(context, angleUnit);
if (e.isUndefinedOrAllocationFailure()) {
return e;
{
Expression e = Expression::defaultShallowReduce(context, angleUnit);
if (e.isUndefinedOrAllocationFailure()) {
return e;
}
}
Expression c = childAtIndex(0);
#if MATRIX_EXACT_REDUCING
@@ -55,6 +57,7 @@ Expression MatrixTranspose::shallowReduce(Context & context, Preferences::AngleU
return *this;
#else
if (c.type() != ExpressionNode::Type::Matrix) {
replaceWithInPlace(c);
return c;
}
return *this;