Numworks Epsilon  1.4.1
Graphing Calculator Operating System
matrix_dimension.cpp
Go to the documentation of this file.
2 #include <poincare/matrix.h>
3 extern "C" {
4 #include <assert.h>
5 }
6 #include <cmath>
7 
8 namespace Poincare {
9 
11  return Type::MatrixDimension;
12 }
13 
16  return a;
17 }
18 
19 Expression * MatrixDimension::shallowReduce(Context& context, AngleUnit angleUnit) {
20  Expression * e = Expression::shallowReduce(context, angleUnit);
21  if (e != this) {
22  return e;
23  }
24 #if MATRIX_EXACT_REDUCING
25  Expression * op = editableOperand(0);
26  if (op->type() == Type::Matrix) {
27  Matrix * m = static_cast<Matrix *>(op);
28  const Expression * newOperands[2] = {new Rational(m->numberOfRows()), new Rational(m->numberOfColumns())};
29  return replaceWith(new Matrix(newOperands, 1, 2, false), true);
30  }
31  if (!op->recursivelyMatches(Expression::IsMatrix)) {
32  const Expression * newOperands[2] = {new Rational(1), new Rational(1)};
33  return replaceWith(new Matrix(newOperands, 1, 2, false), true);
34  }
35  return this;
36 #else
37  const Expression * newOperands[2] = {new Rational(1), new Rational(1)};
38  return replaceWith(new Matrix(newOperands, 1, 2, false), true);
39 #endif
40 }
41 
42 template<typename T>
43 Expression * MatrixDimension::templatedApproximate(Context& context, AngleUnit angleUnit) const {
44  Expression * input = operand(0)->approximate<T>(context, angleUnit);
45  Expression * operands[2];
46  if (input->type() == Type::Matrix) {
47  operands[0] = new Complex<T>(Complex<T>::Float((T)static_cast<Matrix *>(input)->numberOfRows()));
48  operands[1] = new Complex<T>(Complex<T>::Float((T)static_cast<Matrix *>(input)->numberOfColumns()));
49  } else {
50  operands[0] = new Complex<T>(Complex<T>::Float(1.0));
51  operands[1] = new Complex<T>(Complex<T>::Float(1.0));
52  }
53  delete input;
54  return new Matrix(operands, 1, 2, false);
55 }
56 
57 
58 }
59 
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
const Expression *const * operands() const override
friend class MatrixDimension
Definition: expression.h:56
Expression * editableOperand(int i)
Definition: expression.h:176
friend class Rational
Definition: expression.h:18
Expression * clone() const override
const Expression * m_operands[T]
constexpr uint8_t numberOfColumns
Definition: keyboard.h:39
static Complex< T > Float(T x)
Definition: complex.cpp:23
Type type() const override
friend class Matrix
Definition: expression.h:73
constexpr uint8_t numberOfRows
Definition: keyboard.h:35
const Expression * operand(int i) const
Definition: expression.cpp:78