Numworks Epsilon  1.4.1
Graphing Calculator Operating System
determinant.cpp
Go to the documentation of this file.
1 #include <poincare/determinant.h>
2 #include <poincare/matrix.h>
3 extern "C" {
4 #include <assert.h>
5 }
6 #include <cmath>
7 
8 namespace Poincare {
9 
11  return Type::Determinant;
12 }
13 
15  Determinant * a = new Determinant(m_operands, true);
16  return a;
17 }
18 
19 Expression * Determinant::shallowReduce(Context& context, AngleUnit angleUnit) {
20  Expression * e = Expression::shallowReduce(context, angleUnit);
21  if (e != this) {
22  return e;
23  }
24  Expression * op = editableOperand(0);
25 #if MATRIX_EXACT_REDUCING
26  if (!op->recursivelyMatches(Expression::IsMatrix)) {
27  return replaceWith(op, true);
28  }
29  return this;
30 #else
31  return replaceWith(op, true);
32 #endif
33 }
34 
35 // TODO: handle this exactly in shallowReduce for small dimensions.
36 template<typename T>
37 Expression * Determinant::templatedApproximate(Context& context, AngleUnit angleUnit) const {
38  Expression * input = operand(0)->approximate<T>(context, angleUnit);
39  Expression * result = nullptr;
40  if (input->type() == Type::Complex) {
41  result = input->clone();
42  } else {
43  assert(input->type() == Type::Matrix);
44  result = static_cast<Matrix *>(input)->createDeterminant<T>();
45  }
46  delete input;
47  return result;
48 }
49 
50 }
51 
friend class Determinant
Definition: expression.h:40
#define assert(e)
Definition: assert.h:9
Expression * replaceWith(Expression *newOperand, bool deleteAfterReplace=true)
Definition: expression.cpp:85
Expression * approximate(Context &context, AngleUnit angleUnit=AngleUnit::Default) const
Definition: expression.cpp:338
static bool IsMatrix(const Expression *e, Context &context)
Definition: expression.cpp:198
#define T(x)
Definition: events.cpp:26
Type type() const override
Definition: determinant.cpp:10
Expression * clone() const override
Definition: determinant.cpp:14
Expression * editableOperand(int i)
Definition: expression.h:176
const Expression * m_operands[T]
friend class Matrix
Definition: expression.h:73
const Expression * operand(int i) const
Definition: expression.cpp:78