mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Factorize troigonometry mapping on matrices
This commit is contained in:
@@ -24,6 +24,7 @@ public:
|
||||
template <typename T> static std::complex<T> ConvertRadianToAngleUnit(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
template <typename T> static std::complex<T> RoundToMeaningfulDigits(const std::complex<T> result, const std::complex<T> input);
|
||||
private:
|
||||
static Expression mapIfPossible(Expression & e, ExpressionNode::ReductionContext reductionContext);
|
||||
template <typename T> static T RoundToMeaningfulDigits(T result, T input);
|
||||
};
|
||||
|
||||
|
||||
@@ -56,9 +56,6 @@ Expression ArcCosine::shallowReduce(ExpressionNode::ReductionContext reductionCo
|
||||
return e;
|
||||
}
|
||||
}
|
||||
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) {
|
||||
return mapOnMatrixFirstChild(reductionContext);
|
||||
}
|
||||
return Trigonometry::shallowReduceInverseFunction(*this, reductionContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,9 +56,6 @@ Expression ArcSine::shallowReduce(ExpressionNode::ReductionContext reductionCont
|
||||
return e;
|
||||
}
|
||||
}
|
||||
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) {
|
||||
return mapOnMatrixFirstChild(reductionContext);
|
||||
}
|
||||
return Trigonometry::shallowReduceInverseFunction(*this, reductionContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,9 +55,6 @@ Expression ArcTangent::shallowReduce(ExpressionNode::ReductionContext reductionC
|
||||
return e;
|
||||
}
|
||||
}
|
||||
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) {
|
||||
return mapOnMatrixFirstChild(reductionContext);
|
||||
}
|
||||
return Trigonometry::shallowReduceInverseFunction(*this, reductionContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,10 +41,6 @@ Expression Cosine::shallowReduce(ExpressionNode::ReductionContext reductionConte
|
||||
return e;
|
||||
}
|
||||
}
|
||||
Expression c = childAtIndex(0);
|
||||
if (c.type() == ExpressionNode::Type::Matrix) {
|
||||
return mapOnMatrixFirstChild(reductionContext);
|
||||
}
|
||||
return Trigonometry::shallowReduceDirectFunction(*this, reductionContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,9 +42,6 @@ Expression Sine::shallowReduce(ExpressionNode::ReductionContext reductionContext
|
||||
return e;
|
||||
}
|
||||
}
|
||||
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) {
|
||||
return mapOnMatrixFirstChild(reductionContext);
|
||||
}
|
||||
return Trigonometry::shallowReduceDirectFunction(*this, reductionContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,10 +46,6 @@ Expression Tangent::shallowReduce(ExpressionNode::ReductionContext reductionCont
|
||||
}
|
||||
}
|
||||
|
||||
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) {
|
||||
return mapOnMatrixFirstChild(reductionContext);
|
||||
}
|
||||
|
||||
Expression newExpression = Trigonometry::shallowReduceDirectFunction(*this, reductionContext);
|
||||
if (newExpression.type() == ExpressionNode::Type::Tangent) {
|
||||
Sine s = Sine::Builder(newExpression.childAtIndex(0).clone());
|
||||
|
||||
@@ -96,6 +96,14 @@ bool Trigonometry::ExpressionIsEquivalentToTangent(const Expression & e) {
|
||||
Expression Trigonometry::shallowReduceDirectFunction(Expression & e, ExpressionNode::ReductionContext reductionContext) {
|
||||
assert(isDirectTrigonometryFunction(e));
|
||||
|
||||
// Step 0. Map on matrix child if possible
|
||||
{
|
||||
Expression mapped = mapIfPossible(e, reductionContext);
|
||||
if (!mapped.isUninitialized()) {
|
||||
return mapped;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 1. Try finding an easy standard calculation reduction
|
||||
Expression lookup = TrigonometryCheatTable::Table()->simplify(e.childAtIndex(0), e.type(), reductionContext);
|
||||
if (!lookup.isUninitialized()) {
|
||||
@@ -254,6 +262,14 @@ Expression Trigonometry::shallowReduceDirectFunction(Expression & e, ExpressionN
|
||||
|
||||
Expression Trigonometry::shallowReduceInverseFunction(Expression & e, ExpressionNode::ReductionContext reductionContext) {
|
||||
assert(isInverseTrigonometryFunction(e));
|
||||
// Step 0. Map on matrix child if possible
|
||||
{
|
||||
Expression mapped = mapIfPossible(e, reductionContext);
|
||||
if (!mapped.isUninitialized()) {
|
||||
return mapped;
|
||||
}
|
||||
}
|
||||
|
||||
float pi = reductionContext.angleUnit() == Preferences::AngleUnit::Radian ? M_PI : 180;
|
||||
|
||||
// Step 1. Look for an expression of type "acos(cos(x))", return x
|
||||
@@ -360,6 +376,13 @@ std::complex<T> Trigonometry::ConvertRadianToAngleUnit(const std::complex<T> c,
|
||||
return c;
|
||||
}
|
||||
|
||||
Expression Trigonometry::mapIfPossible(Expression & e, ExpressionNode::ReductionContext reductionContext) {
|
||||
if (e.childAtIndex(0).type() == ExpressionNode::Type::Matrix) {
|
||||
return e.mapOnMatrixFirstChild(reductionContext);
|
||||
}
|
||||
return Expression();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T Trigonometry::RoundToMeaningfulDigits(T result, T input) {
|
||||
/* Cheat: openbsd trigonometric functions are numerical implementation and
|
||||
|
||||
Reference in New Issue
Block a user