Numworks Epsilon  1.4.1
Graphing Calculator Operating System
power.h
Go to the documentation of this file.
1 #ifndef POINCARE_POWER_H
2 #define POINCARE_POWER_H
3 
6 #include <poincare/rational.h>
8 
9 namespace Poincare {
10 
11 class Power : public StaticHierarchy<2> {
13  friend class Multiplication;
14  friend class NthRoot;
15  friend class SquareRoot;
16  friend class Addition;
17  friend class Division;
18  friend class Round;
19  friend class Symbol;
20 public:
21  Type type() const override;
22  Expression * clone() const override;
23  Sign sign() const override;
24  int polynomialDegree(char symbolName) const override;
25  template<typename T> static Complex<T> compute(const Complex<T> c, const Complex<T> d);
26 private:
27  constexpr static int k_maxNumberOfTermsInExpandedMultinome = 25;
28  constexpr static int k_maxIntegerPower = 100;
29  /* Property */
30  Expression * setSign(Sign s, Context & context, AngleUnit angleUnit) override;
31  /* Layout */
32  ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
33  bool needParenthesisWithParent(const Expression * e) const override;
34  int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {
35  return LayoutEngine::writeInfixExpressionTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, name());
36  }
37  static const char * name() { return "^"; }
38  /* Simplify */
39  Expression * shallowReduce(Context& context, AngleUnit angleUnit) override;
40  Expression * shallowBeautify(Context & context, AngleUnit angleUnit) override;
41  int simplificationOrderGreaterType(const Expression * e, bool canBeInterrupted) const override;
42  int simplificationOrderSameType(const Expression * e, bool canBeInterrupted) const override;
43  Expression * simplifyPowerPower(Power * p, Expression * r, Context & context, AngleUnit angleUnit);
44  Expression * cloneDenominator(Context & context, AngleUnit angleUnit) const override;
45  Expression * simplifyPowerMultiplication(Multiplication * m, Expression * r, Context & context, AngleUnit angleUnit);
46  Expression * simplifyRationalRationalPower(Expression * result, Rational * a, Rational * b, Context & context, AngleUnit angleUnit);
47  Expression * removeSquareRootsFromDenominator(Context & context, AngleUnit angleUnit);
48  bool parentIsALogarithmOfSameBase() const;
49  bool isNthRootOfUnity() const;
50  static Expression * CreateSimplifiedIntegerRationalPower(Integer i, Rational * r, bool isDenominator, Context & context, AngleUnit angleUnit);
51  static Expression * CreateNthRootOfUnity(const Rational r);
52  static bool TermIsARationalSquareRootOrRational(const Expression * e);
53  static const Rational * RadicandInExpression(const Expression * e);
54  static const Rational * RationalFactorInExpression(const Expression * e);
55  static bool RationalExponentShouldNotBeReduced(const Rational * r);
56  /* Evaluation */
57  constexpr static int k_maxApproximatePowerMatrix = 1000;
58  constexpr static int k_maxExactPowerMatrix = 100;
59  template<typename T> static Matrix * computeOnComplexAndMatrix(const Complex<T> * c, const Matrix * n) { return nullptr; }
60  template<typename T> static Matrix * computeOnMatrixAndComplex(const Matrix * m, const Complex<T> * d);
61  template<typename T> static Matrix * computeOnMatrices(const Matrix * m, const Matrix * n) { return nullptr; }
62  Expression * privateApproximate(SinglePrecision p, Context& context, AngleUnit angleUnit) const override {
63  return ApproximationEngine::mapReduce<float>(this, context, angleUnit, compute<float>, computeOnComplexAndMatrix<float>, computeOnMatrixAndComplex<float>, computeOnMatrices<float>);
64  }
65  Expression * privateApproximate(DoublePrecision p, Context& context, AngleUnit angleUnit) const override {
66  return ApproximationEngine::mapReduce<double>(this, context, angleUnit, compute<double>, computeOnComplexAndMatrix<double>, computeOnMatrixAndComplex<double>, computeOnMatrices<double>);
67  }
68 };
69 
70 }
71 
72 #endif
static int writeInfixExpressionTextInBuffer(const Expression *expression, char *buffer, int bufferSize, int numberOfDigits, const char *operatorName)
Sign sign() const override
Definition: power.cpp:38
friend class Multiplication
Definition: power.h:13
int polynomialDegree(char symbolName) const override
Definition: power.cpp:58
c(generic_all_nodes)
friend class Rational
Definition: expression.h:18
friend class Power
Definition: expression.h:21
Expression * clone() const override
Definition: power.cpp:34
friend class Matrix
Definition: expression.h:73
static Complex< T > compute(const Complex< T > c, const Complex< T > d)
Definition: power.cpp:84
Type type() const override
Definition: power.cpp:30