Numworks Epsilon  1.4.1
Graphing Calculator Operating System
expression_debug.cpp
Go to the documentation of this file.
2 #include <poincare/expression.h>
3 #include <poincare/symbol.h>
4 #include <poincare/integer.h>
5 #include <poincare/rational.h>
6 #include <poincare/complex.h>
7 #include <ion.h>
8 #include <iostream>
9 
10 namespace Poincare {
11 
12 void print_expression(const Expression * e, int indentationLevel) {
13  if (indentationLevel>0) {
14  for (int i=0; i<indentationLevel-1; i++) {
15  std::cout << " ";
16  }
17  std::cout << "|-";
18  }
19  GlobalContext context;
20  switch (e->type()) {
22  std::cout << "AbsoluteValue";
23  break;
25  std::cout << "Addition";
26  break;
28  std::cout << "ArcCosine";
29  break;
31  std::cout << "ArcSine";
32  break;
34  std::cout << "ArcTangent";
35  break;
37  std::cout << "BinomialCoefficient";
38  break;
40  std::cout << "Ceiling";
41  break;
43  std::cout << "Complex(";
44  std::cout << static_cast<const Complex<double> *>(e)->a();
45  std::cout << ", ";
46  std::cout << static_cast<const Complex<double> *>(e)->b();
47  std::cout << ")";
48  break;
50  std::cout << "ComplexArgument";
51  break;
53  std::cout << "ConfidenceInterval";
54  break;
56  std::cout << "Conjugate";
57  break;
59  std::cout << "Cosine";
60  break;
62  std::cout << "Decimal(";
63  std::cout << e->approximateToScalar<double>(context, Expression::AngleUnit::Radian);
64  std::cout << ")";
65  break;
67  std::cout << "Derivative";
68  break;
70  std::cout << "Determinant";
71  break;
73  std::cout << "Division";
74  break;
76  std::cout << "DivisionQuotient";
77  break;
79  std::cout << "DivisionRemainder";
80  break;
82  std::cout << "Factor";
83  break;
85  std::cout << "Factorial";
86  break;
88  std::cout << "Floor";
89  break;
91  std::cout << "FracPart";
92  break;
94  std::cout << "GreatCommonDivisor";
95  break;
97  std::cout << "HyperbolicArcCosine";
98  break;
100  std::cout << "HyperbolicArcSine";
101  break;
103  std::cout << "HyperbolicArcTangent";
104  break;
106  std::cout << "HyperbolicCosine";
107  break;
109  std::cout << "HyperbolicSine";
110  break;
112  std::cout << "HyperbolicTangent";
113  break;
115  std::cout << "ImaginaryPart";
116  break;
118  std::cout << "Integral";
119  break;
121  std::cout << "LeastCommonMultiple";
122  break;
124  std::cout << "Logarithm";
125  break;
127  std::cout << "Matrix(Rows: ";
128  std::cout << static_cast<const Matrix *>(e)->numberOfRows();
129  std::cout << ", Columns: ";
130  std::cout << static_cast<const Matrix *>(e)->numberOfColumns();
131  std::cout << ")";
132  break;
134  std::cout << "MatrixDimension";
135  break;
137  std::cout << "MatrixInverse";
138  break;
140  std::cout << "MatrixTrace";
141  break;
143  std::cout << "MatrixTranspose";
144  break;
146  std::cout << "Multiplication";
147  break;
149  std::cout << "NaperianLogarithm";
150  break;
152  std::cout << "NthRoot";
153  break;
155  std::cout << "Opposite";
156  break;
158  std::cout << "Parenthesis";
159  break;
161  std::cout << "PermuteCoefficient";
162  break;
164  std::cout << "PredictionInterval";
165  break;
167  std::cout << "Power";
168  break;
170  std::cout << "Product";
171  break;
173  std::cout << "Random";
174  break;
176  std::cout << "Randint";
177  break;
179  std::cout << "Rational(";
180  std::cout << static_cast<const Rational * >(e)->numerator().approximate<double>();
181  std::cout << ", ";
182  std::cout << static_cast<const Rational * >(e)->denominator().approximate<double>();
183  std::cout << ")";
184  break;
186  std::cout << "RealPart";
187  break;
189  std::cout << "Round";
190  break;
192  std::cout << "SimplificationRoot";
193  break;
195  std::cout << "Sine";
196  break;
198  std::cout << "SquareRoot";
199  break;
201  std::cout << "Store";
202  break;
204  std::cout << "Subtraction";
205  break;
207  std::cout << "Sum";
208  break;
210  std::cout << "Symbol(";
211  switch (((Symbol*)e)->name()) {
213  std::cout << "PI";
214  break;
216  std::cout << "i";
217  break;
219  std::cout << "e";
220  break;
221  default:
222  std::cout << ((Symbol*)e)->name();
223  }
224  std::cout << ")";
225  break;
227  std::cout << "Tangent";
228  break;
230  std::cout << "Undefined";
231  break;
232  }
233  std::cout << " at " << (void *)e << " with parent " << (void *)(e->parent()) << std::endl;
234  for (int i=0; i<e->numberOfOperands(); i++) {
235  print_expression(e->operand(i), indentationLevel+1);
236  }
237 }
238 
239 void print_prime_factorization(Integer * outputFactors, Integer * outputCoefficients, int outputLength) {
240  for (int index = 0; index < outputLength; index++) {
241  if (outputCoefficients[index].isEqualTo(Integer(0))) {
242  break;
243  }
244  std::cout << outputFactors[index].approximate<double>();
245  std::cout << "^";
246  std::cout << outputCoefficients[index].approximate<double>();
247  std::cout << "*";
248  }
249  std::cout <<" "<< std::endl;
250 }
251 
252 }
T approximate() const
Definition: integer.cpp:479
Expression * parent() const
Definition: expression.h:185
void print_prime_factorization(Integer *outputFactors, Integer *outputCoefficients, int outputLength)
virtual int numberOfOperands() const =0
void print_expression(const Expression *e, int indentationLevel)
constexpr uint8_t numberOfColumns
Definition: keyboard.h:39
constexpr uint8_t numberOfRows
Definition: keyboard.h:35
T approximateToScalar(Context &context, AngleUnit angleUnit=AngleUnit::Default) const
Definition: expression.cpp:347
const Expression * operand(int i) const
Definition: expression.cpp:78
virtual Type type() const =0