mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Fix trigonometric inverse functions' names in comments
This commit is contained in:
committed by
Léa Saviot
parent
baf067f20d
commit
19356c4a4e
@@ -39,7 +39,7 @@ Complex<T> ArcCosineNode::computeOnComplex(const std::complex<T> c, Preferences:
|
||||
* this cut. We followed the convention chosen by the lib c++ of llvm on
|
||||
* ]-inf+0i, -1+0i[ (warning: acos takes the other side of the cut values on
|
||||
* ]-inf-0i, -1-0i[) and choose the values on ]1+0i, +inf+0i[ to comply with
|
||||
* acos(-x) = Pi - acos(x) and tan(arccos(x)) = sqrt(1-x^2)/x. */
|
||||
* acos(-x) = π - acos(x) and tan(acos(x)) = sqrt(1-x^2)/x. */
|
||||
if (c.imag() == 0 && c.real() > 1) {
|
||||
result.imag(-result.imag()); // other side of the cut
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ Complex<T> ArcSineNode::computeOnComplex(const std::complex<T> c, Preferences::C
|
||||
* this cut. We followed the convention chosen by the lib c++ of llvm on
|
||||
* ]-inf+0i, -1+0i[ (warning: asin takes the other side of the cut values on
|
||||
* ]-inf-0i, -1-0i[) and choose the values on ]1+0i, +inf+0i[ to comply with
|
||||
* asin(-x) = -asin(x) and tan(arcsin(x)) = x/sqrt(1-x^2). */
|
||||
* asin(-x) = -asin(x) and tan(asin(x)) = x/sqrt(1-x^2). */
|
||||
if (c.imag() == 0 && c.real() > 1) {
|
||||
result.imag(-result.imag()); // other side of the cut
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ Complex<T> ArcTangentNode::computeOnComplex(const std::complex<T> c, Preferences
|
||||
* on this cut. We followed the convention chosen by the lib c++ of llvm on
|
||||
* ]-i+0, -i*inf+0[ (warning: atan takes the other side of the cut values on
|
||||
* ]-i+0, -i*inf+0[) and choose the values on ]-inf*i, -i[ to comply with
|
||||
* atan(-x) = -atan(x) and sin(arctan(x)) = x/sqrt(1+x^2). */
|
||||
* atan(-x) = -atan(x) and sin(atan(x)) = x/sqrt(1+x^2). */
|
||||
if (c.real() == 0 && c.imag() < -1) {
|
||||
result.real(-result.real()); // other side of the cut
|
||||
}
|
||||
|
||||
@@ -140,8 +140,8 @@ Expression ComplexCartesian::argument(Context & context, Preferences::ComplexFor
|
||||
Expression a = real();
|
||||
Expression b = imag();
|
||||
if (!b.isRationalZero()) {
|
||||
// if b != 0, argument = sign(b) * Pi/2 - arctan(a/b)
|
||||
// First, compute arctan(a/b) or (Pi/180)*arctan(a/b)
|
||||
// if b != 0, argument = sign(b) * π/2 - atan(a/b)
|
||||
// First, compute atan(a/b) or (π/180)*atan(a/b)
|
||||
Expression divab = Division::Builder(a, b.clone());
|
||||
Expression arcTangent = ArcTangent::Builder(divab);
|
||||
divab.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
@@ -150,7 +150,7 @@ Expression ComplexCartesian::argument(Context & context, Preferences::ComplexFor
|
||||
arcTangent.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
arcTangent = temp;
|
||||
}
|
||||
// Then, compute sign(b) * Pi/2 - arctan(a/b)
|
||||
// Then, compute sign(b) * π/2 - atan(a/b)
|
||||
Expression signb = SignFunction::Builder(b);
|
||||
Expression signbPi2 = Multiplication::Builder(Rational::Builder(1,2), signb, Constant::Builder(UCodePointGreekSmallLetterPi));
|
||||
signb.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
@@ -159,7 +159,7 @@ Expression ComplexCartesian::argument(Context & context, Preferences::ComplexFor
|
||||
arcTangent.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return sub;
|
||||
} else {
|
||||
// if b == 0, argument = (1-sign(a))*Pi/2
|
||||
// if b == 0, argument = (1-sign(a))*π/2
|
||||
Expression signa = SignFunction::Builder(a).shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Subtraction sub = Subtraction::Builder(Rational::Builder(1), signa);
|
||||
signa.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
|
||||
@@ -446,7 +446,7 @@ void Expression::simplifyAndApproximate(Expression * simplifiedExpression, Expre
|
||||
/* Step 2: Approximation
|
||||
* We compute the approximate expression from the Cartesian form to avoid
|
||||
* unprecision. For example, if the result is the ComplexCartesian(a,b),
|
||||
* the final expression is goind to be sqrt(a^2+b^2)*exp(i*arctan(b/a)...
|
||||
* the final expression is going to be sqrt(a^2+b^2)*exp(i*atan(b/a)...
|
||||
* in Polar ComplexFormat. If we approximate this expression instead of
|
||||
* ComplexCartesian(a,b), we are going to loose precision on the resulting
|
||||
* complex.*/
|
||||
|
||||
@@ -99,14 +99,14 @@ Expression Trigonometry::shallowReduceDirectFunction(Expression & e, Context& co
|
||||
return lookup;
|
||||
}
|
||||
|
||||
// Step 2. Look for an expression of type "cos(arccos(x))", return x
|
||||
// Step 2. Look for an expression of type "cos(acos(x))", return x
|
||||
if (AreInverseFunctions(e, e.childAtIndex(0))) {
|
||||
Expression result = e.childAtIndex(0).childAtIndex(0);
|
||||
e.replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Step 3. Look for an expression of type "cos(arcsin(x))" or "sin(arccos(x)), return sqrt(1-x^2)
|
||||
// Step 3. Look for an expression of type "cos(asin(x))" or "sin(acos(x)), return sqrt(1-x^2)
|
||||
// These equalities are true on complexes
|
||||
if ((e.type() == ExpressionNode::Type::Cosine && e.childAtIndex(0).type() == ExpressionNode::Type::ArcSine) || (e.type() == ExpressionNode::Type::Sine && e.childAtIndex(0).type() == ExpressionNode::Type::ArcCosine)) {
|
||||
Expression sqrt =
|
||||
@@ -131,9 +131,9 @@ Expression Trigonometry::shallowReduceDirectFunction(Expression & e, Context& co
|
||||
return sqrt.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
// Step 4. Look for an expression of type "cos(arctan(x))" or "sin(arctan(x))"
|
||||
// cos(arctan(x)) --> 1/sqrt(1+x^2)
|
||||
// sin(arctan(x)) --> x/sqrt(1+x^2)
|
||||
// Step 4. Look for an expression of type "cos(atan(x))" or "sin(atan(x))"
|
||||
// cos(atan(x)) --> 1/sqrt(1+x^2)
|
||||
// sin(atan(x)) --> x/sqrt(1+x^2)
|
||||
// These equalities are true on complexes
|
||||
if ((e.type() == ExpressionNode::Type::Cosine || e.type() == ExpressionNode::Type::Sine) && e.childAtIndex(0).type() == ExpressionNode::Type::ArcTangent) {
|
||||
Expression x = e.childAtIndex(0).childAtIndex(0);
|
||||
@@ -252,7 +252,7 @@ Expression Trigonometry::shallowReduceInverseFunction(Expression & e, Context& c
|
||||
assert(isInverseTrigonometryFunction(e));
|
||||
float pi = angleUnit == Preferences::AngleUnit::Radian ? M_PI : 180;
|
||||
|
||||
// Step 1. Look for an expression of type "arccos(cos(x))", return x
|
||||
// Step 1. Look for an expression of type "acos(cos(x))", return x
|
||||
if (AreInverseFunctions(e.childAtIndex(0), e)) {
|
||||
float trigoOp = e.childAtIndex(0).childAtIndex(0).node()->approximate(float(), context, complexFormat, angleUnit).toScalar();
|
||||
if ((e.type() == ExpressionNode::Type::ArcCosine && trigoOp >= 0.0f && trigoOp <= pi) ||
|
||||
@@ -264,7 +264,7 @@ Expression Trigonometry::shallowReduceInverseFunction(Expression & e, Context& c
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2. Special case for arctan(sin(x)/cos(x))
|
||||
// Step 2. Special case for atan(sin(x)/cos(x))
|
||||
if (e.type() == ExpressionNode::Type::ArcTangent && ExpressionIsEquivalentToTangent(e.childAtIndex(0))) {
|
||||
float trigoOp = e.childAtIndex(0).childAtIndex(1).childAtIndex(0).node()->approximate(float(), context, complexFormat, angleUnit).toScalar();
|
||||
if (trigoOp >= -pi/2.0f && trigoOp <= pi/2.0f) {
|
||||
@@ -274,7 +274,7 @@ Expression Trigonometry::shallowReduceInverseFunction(Expression & e, Context& c
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3. Look for an expression of type "arctan(1/x), return sign(x)*π/2-arctan(x)
|
||||
// Step 3. Look for an expression of type "atan(1/x), return sign(x)*π/2-atan(x)
|
||||
if (e.type() == ExpressionNode::Type::ArcTangent && e.childAtIndex(0).type() == ExpressionNode::Type::Power && e.childAtIndex(0).childAtIndex(1).type() == ExpressionNode::Type::Rational && e.childAtIndex(0).childAtIndex(1).convert<Rational>().isMinusOne()) {
|
||||
Expression x = e.childAtIndex(0).childAtIndex(0);
|
||||
/* This equality is not true if x = 0. We apply it under certain conditions:
|
||||
@@ -310,8 +310,8 @@ Expression Trigonometry::shallowReduceInverseFunction(Expression & e, Context& c
|
||||
*/
|
||||
Expression p = e.parent();
|
||||
bool letArcFunctionAtRoot = !p.isUninitialized() && isDirectTrigonometryFunction(p);
|
||||
/* Step 5. Handle opposite argument: arccos(-x) = π-arcos(x),
|
||||
* arcsin(-x) = -arcsin(x), arctan(-x)= -arctan(x) *
|
||||
/* Step 5. Handle opposite argument: acos(-x) = π-acos(x),
|
||||
* asin(-x) = -asin(x), atan(-x)= -atan(x) *
|
||||
*/
|
||||
if (!letArcFunctionAtRoot) {
|
||||
Expression positiveArg = e.childAtIndex(0).makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, target);
|
||||
|
||||
@@ -513,22 +513,22 @@ QUIZ_CASE(poincare_trigo_simplify) {
|
||||
assert_parsed_expression_simplify_to("atan(√(3))", "60", User, Degree);
|
||||
assert_parsed_expression_simplify_to("atan(1/x)", "(π×sign(x)-2×atan(x))/2", User, Degree);
|
||||
|
||||
// cos(arcsin)
|
||||
// cos(asin)
|
||||
assert_parsed_expression_simplify_to("cos(asin(x))", "√(-x^2+1)", User, Degree);
|
||||
assert_parsed_expression_simplify_to("cos(asin(-x))", "√(-x^2+1)", User, Degree);
|
||||
// cos(arctan)
|
||||
// cos(atan)
|
||||
assert_parsed_expression_simplify_to("cos(atan(x))", "1/√(x^2+1)", User, Degree);
|
||||
assert_parsed_expression_simplify_to("cos(atan(-x))", "1/√(x^2+1)", User, Degree);
|
||||
// sin(arccos)
|
||||
// sin(acos)
|
||||
assert_parsed_expression_simplify_to("sin(acos(x))", "√(-x^2+1)", User, Degree);
|
||||
assert_parsed_expression_simplify_to("sin(acos(-x))", "√(-x^2+1)", User, Degree);
|
||||
// sin(arctan)
|
||||
// sin(atan)
|
||||
assert_parsed_expression_simplify_to("sin(atan(x))", "x/√(x^2+1)", User, Degree);
|
||||
assert_parsed_expression_simplify_to("sin(atan(-x))", "-x/√(x^2+1)", User, Degree);
|
||||
// tan(arccos)
|
||||
// tan(acos)
|
||||
assert_parsed_expression_simplify_to("tan(acos(x))", "√(-x^2+1)/x", User, Degree);
|
||||
assert_parsed_expression_simplify_to("tan(acos(-x))", "-√(-x^2+1)/x", User, Degree);
|
||||
// tan(arcsin)
|
||||
// tan(asin)
|
||||
assert_parsed_expression_simplify_to("tan(asin(x))", "x/√(-x^2+1)", User, Degree);
|
||||
assert_parsed_expression_simplify_to("tan(asin(-x))", "-x/√(-x^2+1)", User, Degree);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user