Skip to content

Commit

Permalink
Remove unused code from TrigExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Sep 20, 2023
1 parent 72cc9fb commit def1c2f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 64 deletions.
63 changes: 7 additions & 56 deletions src/fintamath/expressions/unary/TrigExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,14 @@ ArgumentPtr TrigExpression::trigTableSimplify(const IFunction &func, const Ratio
static const TrigonometryFunctionsTable trigTable = {
{Sin().toString(), &trigTableSinSimplify},
{Cos().toString(), &trigTableCosSimplify},
{Tan().toString(), &trigTableTanSimplify},
{Cot().toString(), &trigTableCotSimplify},
};
Rational rhsShifted = phaseShiftPeriod(rhs);
return trigTable.at(func.toString())(rhsShifted);

if (auto iter = trigTable.find(func.toString()); iter != trigTable.end()) {
Rational rhsShifted = phaseShiftPeriod(rhs);
return iter->second(rhsShifted);
}

return {};
}

ArgumentPtr TrigExpression::trigTableSinSimplify(const Rational &rhs) {
Expand Down Expand Up @@ -142,38 +145,6 @@ ArgumentPtr TrigExpression::trigTableCosSimplify(const Rational &rhs) {
return findValue(trigTable, rhsShifted, isNegated);
}

ArgumentPtr TrigExpression::trigTableTanSimplify(const Rational &rhs) {
static const TrigonometryTable trigTable = {
{Rational(0), Integer(0).clone()}, // 0 | 0
{Rational(1, 6), mulExpr(Rational(1, 3).clone(), sqrtExpr(Integer(3)))}, // π/6 | √3/3
{Rational(1, 4), Integer(1).clone()}, // π/4 | 1
{Rational(1, 3), sqrtExpr(Integer(3))}, // π/3 | √3
{Rational(1, 2), ComplexInf().clone()}, // π/2 | ComplexInf
{Rational(2, 3), negExpr(sqrtExpr(Integer(3)))}, // 2π/3 | -√3
{Rational(3, 4), Integer(-1).clone()}, // 3π/4 | -1
{Rational(5, 6), mulExpr(Rational(-1, 3).clone(), sqrtExpr(Integer(3)))}, // 5π/6 | -√3/3
{Rational(1), Integer(0).clone()}, // π | 0
};
auto [rhsShifted, isNegated] = phaseShiftTan(rhs);
return findValue(trigTable, rhsShifted, isNegated);
}

ArgumentPtr TrigExpression::trigTableCotSimplify(const Rational &rhs) {
static const TrigonometryTable trigTable = {
{Rational(0), ComplexInf().clone()}, // 0 | ComplexInf
{Rational(1, 6), sqrtExpr(Integer(3))}, // π/6 | √3
{Rational(1, 4), Integer(1).clone()}, // π/4 | 1
{Rational(1, 3), mulExpr(Rational(1, 3).clone(), sqrtExpr(Integer(3)))}, // π/3 | √3/3
{Rational(1, 2), Integer(0).clone()}, // π/2 | 0
{Rational(2, 3), mulExpr(Rational(-1, 3).clone(), sqrtExpr(Integer(3)))}, // 2π/3 | -√3/3
{Rational(3, 4), Integer(-1).clone()}, // 3π/4 | -1
{Rational(5, 6), negExpr(sqrtExpr(Integer(3)))}, // 5π/6 | -√3
{Rational(1), ComplexInf().clone()}, // π | ComplexInf
};
auto [rhsShifted, isNegated] = phaseShiftCot(rhs);
return findValue(trigTable, rhsShifted, isNegated);
}

std::tuple<Rational, bool> TrigExpression::phaseShiftSin(const Rational &rhs) {
Rational rhsShifted = rhs;
bool isNegated = false;
Expand Down Expand Up @@ -207,26 +178,6 @@ std::tuple<Rational, bool> TrigExpression::phaseShiftCos(const Rational &rhs) {
return {rhsShifted, isNegated};
}

std::tuple<Rational, bool> TrigExpression::phaseShiftTan(const Rational &rhs) {
Rational rhsShifted = rhs;
bool isNegated = false;

if (rhsShifted < 0) {
rhsShifted = -rhsShifted;
isNegated = !isNegated;
}

if (rhsShifted.numerator() > rhsShifted.denominator()) {
rhsShifted = Rational(rhsShifted.numerator() % rhsShifted.denominator(), rhsShifted.denominator());
}

return {rhsShifted, isNegated};
}

std::tuple<Rational, bool> TrigExpression::phaseShiftCot(const Rational &rhs) {
return phaseShiftTan(rhs);
}

Rational TrigExpression::phaseShiftPeriod(const Rational &rhs) {
return Rational(rhs.numerator() % (rhs.denominator() * 2), rhs.denominator());
}
Expand Down
8 changes: 0 additions & 8 deletions src/fintamath/expressions/unary/TrigExpression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,10 @@ class TrigExpression : public IUnaryExpressionCRTP<TrigExpression, true> {

static ArgumentPtr trigTableCosSimplify(const Rational &rhs);

static ArgumentPtr trigTableTanSimplify(const Rational &rhs);

static ArgumentPtr trigTableCotSimplify(const Rational &rhs);

static std::tuple<Rational, bool> phaseShiftSin(const Rational &rhs);

static std::tuple<Rational, bool> phaseShiftCos(const Rational &rhs);

static std::tuple<Rational, bool> phaseShiftTan(const Rational &rhs);

static std::tuple<Rational, bool> phaseShiftCot(const Rational &rhs);

static Rational phaseShiftPeriod(const Rational &rhs);

static std::shared_ptr<IFunction> getOppositeFunction(const IFunction &function);
Expand Down

0 comments on commit def1c2f

Please sign in to comment.