[poincare/trigonometry] Fix wrong use of pi

In Trigonometry::shallowReduceInverseFunction, the reduction of
atan(1/x) used the hard value of pi instead of its equivalent in the
selected angle unit.
This fixes a bug causing atan(1/tan(40°)) to be equal to π/2-40 instead
of 50.

Change-Id: Ifd7df5cd168fadf3146eee168c0bc2136ea15a7b
This commit is contained in:
Gabriel Ozouf
2020-09-29 11:21:11 +02:00
committed by Émilie Feral
parent 91d9438421
commit 857ca4eecd
2 changed files with 6 additions and 2 deletions

View File

@@ -331,14 +331,16 @@ Expression Trigonometry::shallowReduceInverseFunction(Expression & e, Expression
* reduced to undef) */
if (reductionContext.target() == ExpressionNode::ReductionTarget::User || x.isNumber()) {
Expression sign = SignFunction::Builder(x.clone());
Multiplication m0 = Multiplication::Builder(Rational::Builder(1,2), sign, Constant::Builder(UCodePointGreekSmallLetterPi));
Multiplication m0 = Multiplication::Builder(Rational::Builder(1,2), sign, piExpression(angleUnit));
sign.shallowReduce(reductionContext);
e.replaceChildAtIndexInPlace(0, x);
Addition a = Addition::Builder(m0);
m0.shallowReduce(reductionContext);
e.replaceWithInPlace(a);
Multiplication m1 = Multiplication::Builder(Rational::Builder(-1), e);
e.shallowReduce(reductionContext);
a.addChildAtIndexInPlace(m1, 1, 1);
m1.shallowReduce(reductionContext);
return a.shallowReduce(reductionContext);
}
}

View File

@@ -948,7 +948,9 @@ QUIZ_CASE(poincare_simplification_trigonometry_functions) {
assert_parsed_expression_simplify_to("atan(tan(1808))", "8", User, Degree);
assert_parsed_expression_simplify_to("atan(tan(-180/7))", "-180/7", User, Degree);
assert_parsed_expression_simplify_to("atan(√(3))", "60", User, Degree);
assert_parsed_expression_simplify_to("atan(1/x)", "\u0012π×sign(x)-2×atan(x)\u0013/2", User, Degree);
assert_parsed_expression_simplify_to("atan(1/x)", "\u0012π×sign(x)-2×atan(x)\u0013/2");
assert_parsed_expression_simplify_to("atan(1/x)", "90×sign(x)-atan(x)", User, Degree);
assert_parsed_expression_simplify_to("atan(1/x)", "100×sign(x)-atan(x)", User, Gradian);
// cos(asin)
assert_parsed_expression_simplify_to("cos(asin(x))", "√(-x^2+1)", User, Degree);