mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-24 16:20:49 +01:00
[poincare] Fix PredictionInterval::shallowReduce
Change-Id: Id0e3677c78e2925834027be43080df9bcb951d6b
This commit is contained in:
@@ -34,7 +34,7 @@ Expression * PredictionInterval::shallowReduce(Context& context, AngleUnit angle
|
||||
}
|
||||
Rational * r0 = static_cast<Rational *>(op0);
|
||||
Rational * r1 = static_cast<Rational *>(op1);
|
||||
if (!r1->denominator().isOne() || r1->numerator().isNegative() || r0->numerator().isNegative() || Integer::NaturalOrder(r0->numerator(), r0->denominator()) <= 0) {
|
||||
if (!r1->denominator().isOne() || r1->numerator().isNegative() || r0->numerator().isNegative() || Integer::NaturalOrder(r0->numerator(), r0->denominator()) > 0) {
|
||||
return replaceWith(new Undefined(), true);
|
||||
}
|
||||
detachOperand(r0);
|
||||
@@ -43,10 +43,9 @@ Expression * PredictionInterval::shallowReduce(Context& context, AngleUnit angle
|
||||
// Compute numerator = r0*(1-r0)
|
||||
Rational * numerator = new Rational(Rational::Multiplication(*r0, Rational(Integer::Subtraction(r0->denominator(), r0->numerator()), r0->denominator())));
|
||||
// Compute sqr = sqrt(r0*(1-r0)/r1)
|
||||
Expression * sqr = new Power(new Division(numerator, r1, false), new Rational(-1, 2), false);
|
||||
Expression * sqr = new Power(new Division(numerator, r1, false), new Rational(1, 2), false);
|
||||
Expression * m = new Multiplication(new Rational(196, 100), sqr, false);
|
||||
const Expression * newOperands[2] = {new Addition(r0, m, true),
|
||||
new Addition(r0, new Multiplication(new Rational(-1), m, false), false)};
|
||||
const Expression * newOperands[2] = {new Addition(r0, new Multiplication(new Rational(-1), m, false), false), new Addition(r0, m, true),};
|
||||
Expression * matrix = replaceWith(new Matrix(newOperands, 1, 2, false), true);
|
||||
return matrix->deepReduce(context, angleUnit);
|
||||
}
|
||||
|
||||
@@ -66,6 +66,8 @@ QUIZ_CASE(poincare_simplify_easy) {
|
||||
assert_parsed_expression_simplify_to("binomial(20,10)", "184756");
|
||||
assert_parsed_expression_simplify_to("ceil([[1/R(2),1/2][1,-1.3]])", "[[ceil(R(2)/2),1][1,-1]]");
|
||||
assert_parsed_expression_simplify_to("confidence(1/3, 25)", "[[2/15,8/15]]");
|
||||
assert_parsed_expression_simplify_to("confidence(45, 25)", "undef");
|
||||
assert_parsed_expression_simplify_to("confidence(1/3, -34)", "undef");
|
||||
assert_parsed_expression_simplify_to("conj([[1/R(2),1/2][1,-1]])", "[[conj(1/R(2)),1/2][1,-1]]");
|
||||
assert_parsed_expression_simplify_to("cos([[P/3,0][P/7,P/2]])", "[[1/2,1][cos(P/7),0]]");
|
||||
assert_parsed_expression_simplify_to("diff([[P/3,0][P/7,P/2]],3)", "undef");
|
||||
@@ -115,6 +117,9 @@ QUIZ_CASE(poincare_simplify_easy) {
|
||||
assert_parsed_expression_simplify_to("permute([[1,-2][3,4]], 2)", "undef");
|
||||
assert_parsed_expression_simplify_to("permute(102,4)", "101989800");
|
||||
assert_parsed_expression_simplify_to("permute(20,-10)", "undef");
|
||||
assert_parsed_expression_simplify_to("prediction95(1/3, 25)", "[[1/3-49R(2)/375,1/3+49R(2)/375]]");
|
||||
assert_parsed_expression_simplify_to("prediction95(45, 25)", "undef");
|
||||
assert_parsed_expression_simplify_to("prediction95(1/3, -34)", "undef");
|
||||
|
||||
assert_parsed_expression_simplify_to("1*tan(2)*tan(5)", "tan(2)*tan(5)");
|
||||
assert_parsed_expression_simplify_to("P+(3R(2)-2R(3))/25", "(3R(2)-2R(3)+25P)/25");
|
||||
|
||||
Reference in New Issue
Block a user