Skip to content

Commit

Permalink
Simplify inverse trigonometric constants
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Aug 10, 2023
1 parent 91959d4 commit 2185b53
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
46 changes: 44 additions & 2 deletions src/fintamath/expressions/unary/InvTrigExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,50 @@ InvTrigExpression::SimplifyFunctionsVector InvTrigExpression::getFunctionsForPos
}

ArgumentPtr InvTrigExpression::constantsSimplify(const IFunction & /*func*/, const ArgumentPtr & /*rhs*/) {
// TODO! implement
return {};
if (*rhs == Pi()) {
return trigTableSimplify(func, 1);
}

if (*rhs == *makeExpr(Neg(), Pi())) {
return trigTableSimplify(func, -1);
}

const auto rhsExpr = cast<IExpression>(rhs);
if (!rhsExpr || !is<Mul>(rhsExpr->getFunction())) {
return {};
}

const auto rhsChildren = rhsExpr->getChildren();
if (rhsChildren.size() != 2 || !is<Pi>(rhsChildren.back())) {
return {};
}

const auto rhsChildRat = cast<Rational>(convert(Rational(), *rhsChildren.front()));
if (!rhsChildRat) {
return {};
}

return trigTableSimplify(func, *rhsChildRat);
}

ArgumentPtr InvTrigExpression::invTrigTableSimplify(const IFunction &func, const Rational &rhs) {

}

ArgumentPtr InvTrigExpression::invTrigTableAsinSimplify(const Rational &rhs) {

}

ArgumentPtr InvTrigExpression::invTrigTableAcosSimplify(const Rational &rhs) {

}

ArgumentPtr InvTrigExpression::invTrigTableAtanSimplify(const Rational &rhs) {

}

ArgumentPtr InvTrigExpression::invTrigTableAcotSimplify(const Rational &rhs) {

}

}
12 changes: 12 additions & 0 deletions src/fintamath/expressions/unary/InvTrigExpression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace fintamath {

class Rational;

class InvTrigExpression : public IUnaryExpressionCRTP<InvTrigExpression, true> {
public:
explicit InvTrigExpression(const IFunction &inFunc, const ArgumentPtr &inChild);
Expand All @@ -17,6 +19,16 @@ class InvTrigExpression : public IUnaryExpressionCRTP<InvTrigExpression, true> {

private:
static ArgumentPtr constantsSimplify(const IFunction &func, const ArgumentPtr &rhs);

static ArgumentPtr invTrigTableSimplify(const IFunction &func, const Rational &rhs);

static ArgumentPtr invTrigTableAsinSimplify(const Rational &rhs);

static ArgumentPtr invTrigTableAcosSimplify(const Rational &rhs);

static ArgumentPtr invTrigTableAtanSimplify(const Rational &rhs);

static ArgumentPtr invTrigTableAcotSimplify(const Rational &rhs);
};

}
1 change: 1 addition & 0 deletions src/fintamath/expressions/unary/TrigExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ ArgumentPtr TrigExpression::constantsSimplify(const IFunction &func, const Argum
if (!rhsChildRat) {
return {};
}

return trigTableSimplify(func, *rhsChildRat);
}

Expand Down

0 comments on commit 2185b53

Please sign in to comment.