[poincare] Update ComplexArgument and ConfidenceInterval

This commit is contained in:
Léa Saviot
2018-08-31 15:25:05 +02:00
parent 8e264e72d8
commit a46d7c0869
4 changed files with 22 additions and 13 deletions

View File

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

View File

@@ -22,6 +22,7 @@ class Expression : public TreeByReference {
friend class Arithmetic;
friend class BinomialCoefficient;
friend class Ceiling;
friend class ComplexArgument;
friend class CosineNode;
friend class SineNode;
friend class ExpressionNode;

View File

@@ -16,7 +16,7 @@ ComplexArgumentNode * ComplexArgumentNode::FailedAllocationStaticNode() {
}
LayoutReference ComplexArgumentNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
return LayoutHelper::Prefix(ComplexArgument(this), floatDisplayMode, numberOfSignificantDigits, name());
return LayoutHelper::Prefix(ComplexArgument(this), floatDisplayMode, numberOfSignificantDigits, name());
}
int ComplexArgumentNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
@@ -33,9 +33,11 @@ Complex<T> ComplexArgumentNode::computeOnComplex(const std::complex<T> c, Prefer
}
Expression ComplexArgument::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;
}
}
#if MATRIX_EXACT_REDUCING
Expression c = childAtIndex(0);

View File

@@ -51,9 +51,11 @@ SimplePredictionIntervalNode * SimplePredictionIntervalNode::FailedAllocationSta
}
Expression ConfidenceInterval::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 c0 = childAtIndex(0);
Expression c1 = childAtIndex(1);
@@ -65,13 +67,17 @@ Expression ConfidenceInterval::shallowReduce(Context & context, Preferences::Ang
if (c0.type() == ExpressionNode::Type::Rational) {
Rational r0 = static_cast<Rational&>(c0);
if (r0.signedIntegerNumerator().isNegative() || Integer::NaturalOrder(r0.signedIntegerNumerator(), r0.integerDenominator()) > 0) {
return Undefined();
Expression result = Undefined();
replaceWithInPlace(result);
return result;
}
}
if (c1.type() == ExpressionNode::Type::Rational) {
Rational r1 = static_cast<Rational&>(c1);
if (!r1.integerDenominator().isOne() || r1.signedIntegerNumerator().isNegative()) {
return Undefined();
Expression result = Undefined();
replaceWithInPlace(result);
return result;
}
}
if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) {
@@ -82,11 +88,12 @@ Expression ConfidenceInterval::shallowReduce(Context & context, Preferences::Ang
// Compute [r0-1/sqr(r1), r0+1/sqr(r1)]
Expression sqr = Power(r1, Rational(-1, 2));
Matrix matrix;
matrix.addChildAtIndexInPlace(Addition(r0, Multiplication(Rational(-1), sqr)), 0, 0);
matrix.addChildAtIndexInPlace(Addition(r0.clone(), Multiplication(Rational(-1), sqr.clone())), 0, 0);
matrix.addChildAtIndexInPlace(Addition(r0, sqr), 1, 1);
matrix.setDimensions(1, 2);
return matrix.deepReduce(context, angleUnit);
replaceWithInPlace(matrix);
Expression result = matrix.deepReduce(context, angleUnit);
return result;
}
}