mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Evaluation return numerical matrix
Change-Id: I58dbc93ad22a086580a77318b2524db9c70e47d2
This commit is contained in:
@@ -76,7 +76,7 @@ ExpressionLayout * Calculation::inputLayout() {
|
||||
return m_inputLayout;
|
||||
}
|
||||
|
||||
Expression * Calculation::output(Context * context) {
|
||||
Evaluation * Calculation::output(Context * context) {
|
||||
if (m_output == nullptr) {
|
||||
/* To ensure that the expression 'm_output' is a matrix or a complex, we
|
||||
* call 'evaluate'. */
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
const char * outputText();
|
||||
Poincare::Expression * input();
|
||||
Poincare::ExpressionLayout * inputLayout();
|
||||
Poincare::Expression * output(Poincare::Context * context);
|
||||
Poincare::Evaluation * output(Poincare::Context * context);
|
||||
Poincare::ExpressionLayout * outputLayout(Poincare::Context * context);
|
||||
void setContent(const char * c, Poincare::Context * context);
|
||||
bool isEmpty();
|
||||
@@ -30,7 +30,7 @@ private:
|
||||
char m_outputText[2*::TextField::maxBufferSize()];
|
||||
Poincare::Expression * m_input;
|
||||
Poincare::ExpressionLayout * m_inputLayout;
|
||||
Poincare::Expression * m_output;
|
||||
Poincare::Evaluation * m_output;
|
||||
Poincare::ExpressionLayout * m_outputLayout;
|
||||
};
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ LocalContext::LocalContext(GlobalContext * parentContext, CalculationStore * cal
|
||||
{
|
||||
}
|
||||
|
||||
Expression * LocalContext::ansValue() {
|
||||
Evaluation * LocalContext::ansValue() {
|
||||
if (m_calculationStore->numberOfCalculations() == 0) {
|
||||
return m_parentContext->defaultExpression();
|
||||
}
|
||||
@@ -18,13 +18,13 @@ Expression * LocalContext::ansValue() {
|
||||
return lastCalculation->output(m_parentContext);
|
||||
}
|
||||
|
||||
void LocalContext::setExpressionForSymbolName(Expression * expression, const Symbol * symbol) {
|
||||
void LocalContext::setExpressionForSymbolName(Evaluation * expression, const Symbol * symbol) {
|
||||
if (symbol->name() != Symbol::SpecialSymbols::Ans) {
|
||||
m_parentContext->setExpressionForSymbolName(expression, symbol);
|
||||
}
|
||||
}
|
||||
|
||||
const Expression * LocalContext::expressionForSymbol(const Symbol * symbol) {
|
||||
const Evaluation * LocalContext::expressionForSymbol(const Symbol * symbol) {
|
||||
if (symbol->name() == Symbol::SpecialSymbols::Ans) {
|
||||
return ansValue();
|
||||
} else {
|
||||
|
||||
@@ -9,10 +9,10 @@ namespace Calculation {
|
||||
class LocalContext : public Poincare::Context {
|
||||
public:
|
||||
LocalContext(Poincare::GlobalContext * parentContext, CalculationStore * calculationStore);
|
||||
void setExpressionForSymbolName(Poincare::Expression * expression, const Poincare::Symbol * symbol) override;
|
||||
const Poincare::Expression * expressionForSymbol(const Poincare::Symbol * symbol) override;
|
||||
void setExpressionForSymbolName(Poincare::Evaluation * expression, const Poincare::Symbol * symbol) override;
|
||||
const Poincare::Evaluation * expressionForSymbol(const Poincare::Symbol * symbol) override;
|
||||
private:
|
||||
Poincare::Expression * ansValue();
|
||||
Poincare::Evaluation * ansValue();
|
||||
CalculationStore * m_calculationStore;
|
||||
Poincare::GlobalContext * m_parentContext;
|
||||
};
|
||||
|
||||
@@ -6,13 +6,14 @@ namespace Sequence {
|
||||
|
||||
LocalContext::LocalContext(Context * parentContext) :
|
||||
VariableContext('n', parentContext),
|
||||
m_values{{Complex::Float(NAN), Complex::Float(NAN)}, {Complex::Float(NAN), Complex::Float(NAN)}
|
||||
m_values{{Complex::Float(NAN), Complex::Float(NAN)},
|
||||
{Complex::Float(NAN), Complex::Float(NAN)}
|
||||
//, {Complex::Float(NAN), Complex::Float(NAN)}
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
const Expression * LocalContext::expressionForSymbol(const Symbol * symbol) {
|
||||
const Evaluation * LocalContext::expressionForSymbol(const Symbol * symbol) {
|
||||
if (symbol->name() == Symbol::SpecialSymbols::un || symbol->name() == Symbol::SpecialSymbols::un1 ||
|
||||
symbol->name() == Symbol::SpecialSymbols::vn || symbol->name() == Symbol::SpecialSymbols::vn1 ||
|
||||
symbol->name() == Symbol::SpecialSymbols::wn || symbol->name() == Symbol::SpecialSymbols::wn1) {
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Sequence {
|
||||
class LocalContext : public Poincare::VariableContext {
|
||||
public:
|
||||
LocalContext(Poincare::Context * parentContext);
|
||||
const Poincare::Expression * expressionForSymbol(const Poincare::Symbol * symbol) override;
|
||||
const Poincare::Evaluation * expressionForSymbol(const Poincare::Symbol * symbol) override;
|
||||
void setValueForSequenceRank(float value, const char * sequenceName, int rank);
|
||||
private:
|
||||
constexpr static int k_depth = 2;
|
||||
|
||||
@@ -137,24 +137,22 @@ void VariableBoxController::ContentViewController::willDisplayCellForIndex(Highl
|
||||
char label[3];
|
||||
putLabelAtIndexInBuffer(index, label);
|
||||
myCell->setLabel(label);
|
||||
const Expression * expression = expressionForIndex(index);
|
||||
const Evaluation * evaluation = expressionForIndex(index);
|
||||
if (m_currentPage == Page::Scalar) {
|
||||
myCell->displayExpression(false);
|
||||
char buffer[Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
|
||||
((Complex *)expression)->writeTextInBuffer(buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits));
|
||||
evaluation->writeTextInBuffer(buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits));
|
||||
myCell->setSubtitle(buffer);
|
||||
return;
|
||||
}
|
||||
myCell->displayExpression(true);
|
||||
if (expression) {
|
||||
assert(expression->type() == Expression::Type::Matrix);
|
||||
Matrix * m = (Matrix *)expression;
|
||||
if (evaluation) {
|
||||
/* TODO: implement list contexts */
|
||||
myCell->setExpression((Expression *)expression);
|
||||
myCell->setExpression(evaluation);
|
||||
char buffer[2*Complex::bufferSizeForFloatsWithPrecision(2)+1];
|
||||
int numberOfChars = Complex::convertFloatToText(m->numberOfRows(), buffer, Complex::bufferSizeForFloatsWithPrecision(2), 2, Expression::FloatDisplayMode::Decimal);
|
||||
int numberOfChars = Complex::convertFloatToText(evaluation->numberOfRows(), buffer, Complex::bufferSizeForFloatsWithPrecision(2), 2, Expression::FloatDisplayMode::Decimal);
|
||||
buffer[numberOfChars++] = 'x';
|
||||
Complex::convertFloatToText(m->numberOfColumns(), buffer+numberOfChars, Complex::bufferSizeForFloatsWithPrecision(2), 2, Expression::FloatDisplayMode::Decimal);
|
||||
Complex::convertFloatToText(evaluation->numberOfColumns(), buffer+numberOfChars, Complex::bufferSizeForFloatsWithPrecision(2), 2, Expression::FloatDisplayMode::Decimal);
|
||||
myCell->setSubtitle(buffer);
|
||||
} else {
|
||||
myCell->setExpression(nullptr);
|
||||
@@ -203,7 +201,7 @@ int VariableBoxController::ContentViewController::typeAtLocation(int i, int j) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const Expression * VariableBoxController::ContentViewController::expressionForIndex(int index) {
|
||||
const Evaluation * VariableBoxController::ContentViewController::expressionForIndex(int index) {
|
||||
if (m_currentPage == Page::Scalar) {
|
||||
const Symbol symbol = Symbol('A'+index);
|
||||
return m_context->expressionForSymbol(&symbol);
|
||||
|
||||
@@ -56,7 +56,7 @@ private:
|
||||
Page pageAtIndex(int index);
|
||||
void putLabelAtIndexInBuffer(int index, char * buffer);
|
||||
I18n::Message nodeLabelAtIndex(int index);
|
||||
const Poincare::Expression * expressionForIndex(int index);
|
||||
const Poincare::Evaluation * expressionForIndex(int index);
|
||||
|
||||
Poincare::Context * m_context;
|
||||
TextField * m_textFieldCaller;
|
||||
|
||||
@@ -83,7 +83,7 @@ void VariableBoxLeafCell::setSubtitle(const char * text) {
|
||||
layoutSubviews();
|
||||
}
|
||||
|
||||
void VariableBoxLeafCell::setExpression(Expression * expression) {
|
||||
void VariableBoxLeafCell::setExpression(const Expression * expression) {
|
||||
if(m_expressionLayout != nullptr) {
|
||||
delete m_expressionLayout;
|
||||
m_expressionLayout = nullptr;
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
void reloadCell() override;
|
||||
void setLabel(const char * text);
|
||||
void setSubtitle(const char * text);
|
||||
void setExpression(Poincare::Expression * expression);
|
||||
void setExpression(const Poincare::Expression * expression);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
private:
|
||||
constexpr static KDCoordinate k_separatorThickness = 1;
|
||||
|
||||
@@ -13,6 +13,7 @@ objs += $(addprefix poincare/src/,\
|
||||
ceiling.o\
|
||||
complex.o\
|
||||
complex_argument.o\
|
||||
complex_matrix.o\
|
||||
confidence_interval.o\
|
||||
conjugate.o\
|
||||
cosine.o\
|
||||
@@ -20,6 +21,7 @@ objs += $(addprefix poincare/src/,\
|
||||
determinant.o\
|
||||
division_quotient.o\
|
||||
division_remainder.o\
|
||||
evaluation.o\
|
||||
expression.o\
|
||||
expression_lexer.o\
|
||||
expression_parser.o\
|
||||
@@ -28,6 +30,7 @@ objs += $(addprefix poincare/src/,\
|
||||
frac_part.o\
|
||||
fraction.o\
|
||||
function.o\
|
||||
expression_matrix.o\
|
||||
global_context.o\
|
||||
great_common_divisor.o\
|
||||
hyperbolic_arc_cosine.o\
|
||||
@@ -96,6 +99,7 @@ tests += $(addprefix poincare/test/,\
|
||||
complex.cpp\
|
||||
fraction.cpp\
|
||||
function.cpp\
|
||||
helper.cpp\
|
||||
identity.cpp\
|
||||
integer.cpp\
|
||||
matrix.cpp\
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <poincare/ceiling.h>
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/complex_argument.h>
|
||||
#include <poincare/complex_matrix.h>
|
||||
#include <poincare/confidence_interval.h>
|
||||
#include <poincare/conjugate.h>
|
||||
#include <poincare/context.h>
|
||||
@@ -20,12 +21,15 @@
|
||||
#include <poincare/determinant.h>
|
||||
#include <poincare/division_quotient.h>
|
||||
#include <poincare/division_remainder.h>
|
||||
#include <poincare/evaluation.h>
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/expression_layout.h>
|
||||
#include <poincare/factorial.h>
|
||||
#include <poincare/floor.h>
|
||||
#include <poincare/frac_part.h>
|
||||
#include <poincare/fraction.h>
|
||||
#include <poincare/function.h>
|
||||
#include <poincare/expression_matrix.h>
|
||||
#include <poincare/global_context.h>
|
||||
#include <poincare/great_common_divisor.h>
|
||||
#include <poincare/hyperbolic_arc_cosine.h>
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,9 +12,13 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
bool isCommutative() const override;
|
||||
static Complex compute(const Complex c, const Complex d);
|
||||
static Evaluation * computeOnMatrices(Evaluation * m, Evaluation * n);
|
||||
static Evaluation * computeOnComplexAndMatrix(const Complex * c, Evaluation * m);
|
||||
private:
|
||||
Expression * evaluateOnComplex(Complex * c, Complex * d, Context& context, AngleUnit angleUnit) const override;
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex privateCompute(const Complex c, const Complex d) const override {
|
||||
return compute(c, d);
|
||||
}
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/matrix.h>
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/complex_matrix.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class BinaryOperation : public Expression {
|
||||
public:
|
||||
BinaryOperation();
|
||||
BinaryOperation(Expression ** operands, bool cloneOperands = true);
|
||||
~BinaryOperation();
|
||||
BinaryOperation(const BinaryOperation& other) = delete;
|
||||
@@ -21,11 +23,14 @@ public:
|
||||
Expression * clone() const override;
|
||||
protected:
|
||||
Expression * m_operands[2];
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
virtual Expression * evaluateOnComplex(Complex * c, Complex * d, Context& context, AngleUnit angleUnit) const = 0;
|
||||
virtual Expression * evaluateOnMatrixAndComplex(Matrix * m, Complex * c, Context& context, AngleUnit angleUnit) const;
|
||||
virtual Expression * evaluateOnComplexAndMatrix(Complex * c, Matrix * m, Context& context, AngleUnit angleUnit) const;
|
||||
virtual Expression * evaluateOnMatrices(Matrix * m, Matrix * n, Context& context, AngleUnit angleUnit) const;
|
||||
Evaluation * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
virtual Evaluation * computeOnComplexAndComplexMatrix(const Complex * c, Evaluation * n) const;
|
||||
virtual Evaluation * computeOnComplexMatrixAndComplex(Evaluation * m, const Complex * d) const;
|
||||
virtual Evaluation * computeOnNumericalMatrices(Evaluation * m, Evaluation * n) const;
|
||||
Evaluation * computeOnComplexes(const Complex * c, const Complex * d) const {
|
||||
return new Complex(privateCompute(*c, *d));
|
||||
}
|
||||
virtual Complex privateCompute(const Complex c, const Complex d) const = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,28 +1,44 @@
|
||||
#ifndef POINCARE_COMPLEX_H
|
||||
#define POINCARE_COMPLEX_H
|
||||
|
||||
#include <poincare/leaf_expression.h>
|
||||
#include <poincare/evaluation.h>
|
||||
#include <poincare/preferences.h>
|
||||
#include <math.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class Complex : public LeafExpression {
|
||||
class Complex : public Evaluation {
|
||||
public:
|
||||
Complex() : m_a(0.0f), m_b(0.0f) {}
|
||||
static Complex Float(float x);
|
||||
static Complex Cartesian(float a, float b);
|
||||
static Complex Polar(float r, float theta);
|
||||
Complex(const char * integralPart, int integralPartLength, bool integralNegative,
|
||||
const char * fractionalPart, int fractionalPartLength,
|
||||
const char * exponent, int exponentLength, bool exponentNegative);
|
||||
float toFloat() const override;
|
||||
const Complex * operand(int i) const override {
|
||||
return complexOperand(i);
|
||||
}
|
||||
int numberOfRows() const override;
|
||||
int numberOfColumns() const override;
|
||||
Type type() const override;
|
||||
Expression * clone() const override;
|
||||
int writeTextInBuffer(char * buffer, int bufferSize) override;
|
||||
float a();
|
||||
float b();
|
||||
Complex * clone() const override;
|
||||
Evaluation * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
int writeTextInBuffer(char * buffer, int bufferSize) const override;
|
||||
Evaluation * createDeterminant() const override {
|
||||
return clone();
|
||||
}
|
||||
Evaluation * createInverse() const override;
|
||||
Evaluation * createTrace() const override {
|
||||
return clone();
|
||||
}
|
||||
float a() const;
|
||||
float b() const;
|
||||
float r() const;
|
||||
float th() const;
|
||||
Complex * createConjugate();
|
||||
Complex conjugate() const;
|
||||
/* The parameter 'DisplayMode' refers to the way to display float 'scientific'
|
||||
* or 'auto'. The scientific mode returns float with style -1.2E2 whereas
|
||||
* the auto mode tries to return 'natural' float like (0.021) and switches
|
||||
@@ -41,10 +57,10 @@ public:
|
||||
}
|
||||
private:
|
||||
Complex(float a, float b);
|
||||
const Complex * complexOperand(int i) const override;
|
||||
constexpr static int k_numberOfSignificantDigits = 7;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
/* We here define the buffer size to write the lengthest float possible.
|
||||
* At maximum, the number has 7 significant digits so, in the worst case it
|
||||
* has the form -1.999999e-38 (7+6+1 char) (the auto mode is always
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
33
poincare/include/poincare/complex_matrix.h
Normal file
33
poincare/include/poincare/complex_matrix.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef POINCARE_COMPLEX_MATRIX_H
|
||||
#define POINCARE_COMPLEX_MATRIX_H
|
||||
|
||||
#include <poincare/evaluation.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class ComplexMatrix : public Evaluation {
|
||||
public:
|
||||
ComplexMatrix(const Complex * complexes, int numberOfRows, int numberOfColumns);
|
||||
~ComplexMatrix();
|
||||
ComplexMatrix(const ComplexMatrix& other) = delete;
|
||||
ComplexMatrix(ComplexMatrix&& other) = delete;
|
||||
ComplexMatrix& operator=(const ComplexMatrix& other) = delete;
|
||||
ComplexMatrix& operator=(ComplexMatrix&& other) = delete;
|
||||
float toFloat() const override;
|
||||
const Complex * complexOperand(int i) const override;
|
||||
int numberOfRows() const override;
|
||||
int numberOfColumns() const override;
|
||||
ComplexMatrix * clone() const override;
|
||||
ComplexMatrix * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
static Evaluation * createIdentity(int dim);
|
||||
private:
|
||||
Complex * m_values;
|
||||
int m_numberOfRows;
|
||||
int m_numberOfColumns;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,8 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,8 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#ifndef POINCARE_CONTEXT_H
|
||||
#define POINCARE_CONTEXT_H
|
||||
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/evaluation.h>
|
||||
#include <poincare/symbol.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class Context {
|
||||
public:
|
||||
virtual const Expression * expressionForSymbol(const Symbol * symbol) = 0;
|
||||
virtual void setExpressionForSymbolName(Expression * expression, const Symbol * symbol) = 0;
|
||||
virtual const Evaluation * expressionForSymbol(const Symbol * symbol) = 0;
|
||||
virtual void setExpressionForSymbolName(Evaluation * expression, const Symbol * symbol) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,9 +11,12 @@ public:
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
static Complex compute(const Complex c);
|
||||
private:
|
||||
float trigonometricApproximation(float x) const override;
|
||||
Expression * createComplexEvaluation(Expression * arg, Context & context, AngleUnit angleUnit) const override;
|
||||
Complex privateCompute(const Complex c, AngleUnit angleUnit) const override {
|
||||
return compute(c);
|
||||
}
|
||||
float computeForRadianReal(float x) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
float growthRateAroundAbscissa(float x, float h, VariableContext variableContext, AngleUnit angleUnit) const;
|
||||
float approximateDerivate2(float x, float h, VariableContext xContext, AngleUnit angleUnit) const;
|
||||
constexpr static float k_maxErrorRateOnApproximation = 0.001f;
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
28
poincare/include/poincare/evaluation.h
Normal file
28
poincare/include/poincare/evaluation.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef POINCARE_EVALUATION_H
|
||||
#define POINCARE_EVALUATION_H
|
||||
|
||||
#include <poincare/matrix.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class Complex;
|
||||
|
||||
class Evaluation : public Matrix {
|
||||
public:
|
||||
virtual float toFloat() const = 0;
|
||||
Type type() const override;
|
||||
bool hasValidNumberOfArguments() const override;
|
||||
virtual const Expression * operand(int i) const override;
|
||||
virtual const Complex * complexOperand(int i) const = 0;
|
||||
virtual Evaluation * clone() const override = 0;
|
||||
virtual Evaluation * createTrace() const;
|
||||
virtual Evaluation * createDeterminant() const;
|
||||
virtual Evaluation * createInverse() const;
|
||||
Evaluation * createTranspose() const;
|
||||
private:
|
||||
Evaluation * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -7,6 +7,7 @@
|
||||
namespace Poincare {
|
||||
|
||||
class Context;
|
||||
class Evaluation;
|
||||
|
||||
class Expression {
|
||||
public:
|
||||
@@ -31,6 +32,7 @@ public:
|
||||
Float,
|
||||
Floor,
|
||||
FracPart,
|
||||
ExpressionMatrix,
|
||||
GreatCommonDivisor,
|
||||
HyperbolicArcCosine,
|
||||
HyperbolicArcSine,
|
||||
@@ -43,7 +45,6 @@ public:
|
||||
Integral,
|
||||
Logarithm,
|
||||
LeastCommonMultiple,
|
||||
Matrix,
|
||||
MatrixDimension,
|
||||
MatrixInverse,
|
||||
MatrixTrace,
|
||||
@@ -51,6 +52,7 @@ public:
|
||||
Multiplication,
|
||||
NaperianLogarithm,
|
||||
NthRoot,
|
||||
Evaluation,
|
||||
Opposite,
|
||||
PredictionInterval,
|
||||
Fraction,
|
||||
@@ -131,14 +133,13 @@ public:
|
||||
|
||||
/* The function evaluate creates a new expression and thus mallocs memory.
|
||||
* Do not forget to delete the new expression to avoid leaking. */
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Default) const;
|
||||
Evaluation * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Default) const;
|
||||
float approximate(Context& context, AngleUnit angleUnit = AngleUnit::Default) const;
|
||||
static float approximate(const char * text, Context& context, AngleUnit angleUnit = AngleUnit::Default);
|
||||
virtual int writeTextInBuffer(char * buffer, int bufferSize);
|
||||
virtual int writeTextInBuffer(char * buffer, int bufferSize) const;
|
||||
private:
|
||||
virtual ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const = 0;
|
||||
virtual Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const = 0;
|
||||
virtual float privateApproximate(Context& context, AngleUnit angleUnit) const = 0;
|
||||
virtual Evaluation * privateEvaluate(Context& context, AngleUnit angleUnit) const = 0;
|
||||
bool sequentialOperandsIdentity(const Expression * e) const;
|
||||
bool commutativeOperandsIdentity(const Expression * e) const;
|
||||
bool combinatoryCommutativeOperandsIdentity(const Expression * e,
|
||||
|
||||
33
poincare/include/poincare/expression_matrix.h
Normal file
33
poincare/include/poincare/expression_matrix.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef POINCARE_EXPRESSION_MATRIX_H
|
||||
#define POINCARE_EXPRESSION_MATRIX_H
|
||||
|
||||
#include <poincare/matrix.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class ExpressionMatrix : public Matrix {
|
||||
public:
|
||||
ExpressionMatrix(MatrixData * matrixData);
|
||||
ExpressionMatrix(Expression ** newOperands, int numberOfOperands, int m_numberOfColumns, int m_numberOfRows, bool cloneOperands);
|
||||
~ExpressionMatrix();
|
||||
ExpressionMatrix(const Matrix& other) = delete;
|
||||
ExpressionMatrix(Matrix&& other) = delete;
|
||||
ExpressionMatrix& operator=(const ExpressionMatrix& other) = delete;
|
||||
ExpressionMatrix& operator=(ExpressionMatrix&& other) = delete;
|
||||
bool hasValidNumberOfArguments() const override;
|
||||
int numberOfRows() const override;
|
||||
int numberOfColumns() const override;
|
||||
const Expression * operand(int i) const override;
|
||||
Expression * clone() const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
Evaluation * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
static Complex * defaultExpression();
|
||||
MatrixData * m_matrixData;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,12 +11,14 @@ public:
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
static Complex compute(const Complex c, const Complex d);
|
||||
private:
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnComplex(Complex * c, Complex * d, Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnComplexAndMatrix(Complex * c, Matrix * m, Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnMatrices(Matrix * m, Matrix * n, Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * computeOnComplexAndComplexMatrix(const Complex * c, Evaluation * n) const override;
|
||||
Evaluation * computeOnNumericalMatrices(Evaluation * m, Evaluation * n) const override;
|
||||
Complex privateCompute(const Complex c, const Complex d) const override {
|
||||
return compute(c, d);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/list_data.h>
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/complex_matrix.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -24,8 +26,11 @@ public:
|
||||
int numberOfOperands() const override;
|
||||
Expression * clone() const override;
|
||||
protected:
|
||||
virtual Complex computeComplex(const Complex c, AngleUnit angleUnit) const;
|
||||
virtual Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
void build(Expression ** args, int numberOfArguments, bool clone);
|
||||
void clean();
|
||||
Expression ** m_args;
|
||||
int m_numberOfArguments;
|
||||
int m_requiredNumberOfArguments;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <poincare/context.h>
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/complex_matrix.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -20,16 +21,16 @@ public:
|
||||
GlobalContext& operator=(GlobalContext&& other) = delete;
|
||||
/* The expression recorded in global context is already a final expression.
|
||||
* Otherwise, we would need the context and the angle unit to evaluate it */
|
||||
const Expression * expressionForSymbol(const Symbol * symbol) override;
|
||||
void setExpressionForSymbolName(Expression * expression, const Symbol * symbol) override;
|
||||
const Evaluation * expressionForSymbol(const Symbol * symbol) override;
|
||||
void setExpressionForSymbolName(Evaluation * expression, const Symbol * symbol) override;
|
||||
static constexpr uint16_t k_maxNumberOfScalarExpressions = 26;
|
||||
static constexpr uint16_t k_maxNumberOfListExpressions = 10;
|
||||
static constexpr uint16_t k_maxNumberOfMatrixExpressions = 10;
|
||||
static Complex * defaultExpression();
|
||||
static Evaluation * defaultExpression();
|
||||
private:
|
||||
int symbolIndex(const Symbol * symbol) const;
|
||||
Expression * m_expressions[k_maxNumberOfScalarExpressions];
|
||||
Expression * m_matrixExpressions[k_maxNumberOfMatrixExpressions];
|
||||
Evaluation * m_expressions[k_maxNumberOfScalarExpressions];
|
||||
Evaluation * m_matrixExpressions[k_maxNumberOfMatrixExpressions];
|
||||
Complex m_pi;
|
||||
Complex m_e;
|
||||
};
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,9 +11,11 @@ public:
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
static Complex compute(const Complex c);
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override {
|
||||
return compute(c);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,9 +11,11 @@ public:
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
static Complex compute(const Complex c);
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override {
|
||||
return compute(c);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,9 +11,11 @@ public:
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
static Complex compute(const Complex c);
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override {
|
||||
return compute(c);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -36,8 +36,7 @@ public:
|
||||
Expression * clone() const override;
|
||||
private:
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Integer add(const Integer &other, bool inverse_other_negative) const;
|
||||
int8_t ucmp(const Integer &other) const; // -1, 0, or 1
|
||||
Integer usum(const Integer &other, bool subtract, bool output_negative) const;
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
struct DetailedResult
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ public:
|
||||
ListData& operator=(const ListData& other) = delete;
|
||||
ListData& operator=(ListData&& other) = delete;
|
||||
int numberOfOperands() const;
|
||||
Expression ** operands() const;
|
||||
const Expression * operand(int i) const;
|
||||
void pushExpression(Expression * operand);
|
||||
private:
|
||||
|
||||
@@ -13,8 +13,9 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,44 +2,21 @@
|
||||
#define POINCARE_MATRIX_H
|
||||
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/matrix_data.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class Matrix : public Expression {
|
||||
public:
|
||||
Matrix(MatrixData * matrixData);
|
||||
Matrix(Expression ** newOperands, int numberOfOperands, int m_numberOfColumns, int m_numberOfRows, bool cloneOperands);
|
||||
~Matrix();
|
||||
Matrix(const Matrix& other) = delete;
|
||||
Matrix(Matrix&& other) = delete;
|
||||
Matrix& operator=(const Matrix& other) = delete;
|
||||
Matrix& operator=(Matrix&& other) = delete;
|
||||
bool hasValidNumberOfArguments() const override;
|
||||
const Expression * operand(int i) const override;
|
||||
virtual const Expression * operand(int i) const override = 0;
|
||||
int numberOfOperands() const override;
|
||||
Expression * clone() const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
int numberOfRows() const;
|
||||
int numberOfColumns() const;
|
||||
virtual int numberOfRows() const = 0;
|
||||
virtual int numberOfColumns() const = 0;
|
||||
/* If the buffer is too small, the function fills the buffer until reaching
|
||||
* buffer size */
|
||||
int writeTextInBuffer(char * buffer, int bufferSize) override;
|
||||
Expression * createDimensionMatrix(Context& context, AngleUnit angleUnit) const;
|
||||
float trace(Context& context, AngleUnit angleUnit) const;
|
||||
float determinant(Context& context, AngleUnit angleUnit) const;
|
||||
Expression * createInverse(Context& context, AngleUnit angleUnit) const;
|
||||
Expression * createTranspose(Context& context, AngleUnit angleUnit) const;
|
||||
static Expression * createIdentity(int dim);
|
||||
int writeTextInBuffer(char * buffer, int bufferSize) const override;
|
||||
private:
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
MatrixData * m_matrixData;
|
||||
static Complex * defaultExpression();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
#define POINCARE_MATRIX_DATA_H
|
||||
|
||||
#include <poincare/list_data.h>
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/expression.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class Complex;
|
||||
|
||||
class MatrixData {
|
||||
public:
|
||||
MatrixData(ListData * listData, bool clone);
|
||||
|
||||
@@ -12,8 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,8 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,8 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,11 +11,17 @@ public:
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
static Evaluation * computeOnMatrices(Evaluation * m, Evaluation * n);
|
||||
static Evaluation * computeOnComplexAndMatrix(const Complex * c, Evaluation * m);
|
||||
static Complex compute(const Complex c, const Complex d);
|
||||
private:
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnComplex(Complex * c, Complex * d, Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnMatrices(Matrix * m, Matrix * n, Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * computeOnNumericalMatrices(Evaluation * m, Evaluation * n) const override {
|
||||
return computeOnMatrices(m, n);
|
||||
}
|
||||
Complex privateCompute(const Complex c, const Complex d) const override {
|
||||
return compute(c, d);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Complex compute(const Complex c, const Complex d) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ public:
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
static Complex compute(const Complex c);
|
||||
static Evaluation * computeOnMatrix(Evaluation * m);
|
||||
private:
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
Expression * m_operand;
|
||||
Expression * evaluateOnMatrix(Matrix * m, Context& context, AngleUnit angleUnit) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@ public:
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * m_operand;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,14 +11,16 @@ public:
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
static Complex compute(const Complex c, const Complex d);
|
||||
private:
|
||||
constexpr static float k_maxNumberOfSteps = 10000.0f;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnComplex(Complex * c, Complex * d, Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnMatrixAndComplex(Matrix * m, Complex * c, Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnComplexAndMatrix(Complex * c, Matrix * m, Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnMatrices(Matrix * m, Matrix * n, Context& context, AngleUnit angleUnit) const override;
|
||||
Complex privateCompute(const Complex c, const Complex d) const override {
|
||||
return compute(c, d);
|
||||
}
|
||||
Evaluation * computeOnComplexAndComplexMatrix(const Complex * c, Evaluation * n) const override;
|
||||
Evaluation * computeOnComplexMatrixAndComplex(Evaluation * m, const Complex * d) const override;
|
||||
Evaluation * computeOnNumericalMatrices(Evaluation * m, Evaluation * n) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,8 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -13,9 +13,8 @@ public:
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float emptySequenceValue() const override;
|
||||
float approximateWithNextTerm(float sequence, float newTerm) const override;
|
||||
ExpressionLayout * createSequenceLayoutWithArgumentLayouts(ExpressionLayout * subscriptLayout, ExpressionLayout * superscriptLayout, ExpressionLayout * argumentLayout) const override;
|
||||
Expression * evaluateWithNextTerm(Expression ** args, Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * evaluateWithNextTerm(Evaluation * a, Evaluation * b) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -10,13 +10,11 @@ public:
|
||||
Sequence(const char * name);
|
||||
private:
|
||||
constexpr static float k_maxNumberOfSteps = 10000.0f;
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
virtual float emptySequenceValue() const = 0;
|
||||
virtual float approximateWithNextTerm(float sequence, float newTerm) const = 0;
|
||||
virtual ExpressionLayout * createSequenceLayoutWithArgumentLayouts(ExpressionLayout * subscriptLayout, ExpressionLayout * superscriptLayout, ExpressionLayout * argumentLayout) const = 0;
|
||||
virtual Expression * evaluateWithNextTerm(Expression ** args, Context& context, AngleUnit angleUnit) const = 0;
|
||||
virtual Evaluation * evaluateWithNextTerm(Evaluation * a, Evaluation * b) const = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,9 +11,12 @@ public:
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
static Complex compute(const Complex c);
|
||||
private:
|
||||
float trigonometricApproximation(float x) const override;
|
||||
Expression * createComplexEvaluation(Expression * arg, Context & context, AngleUnit angleUnit) const override;
|
||||
Complex privateCompute(const Complex c, AngleUnit angleUnit) const override {
|
||||
return compute(c);
|
||||
}
|
||||
float computeForRadianReal(float x) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,9 +12,8 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,7 @@ public:
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context & context, AngleUnit angleUnit) const override;
|
||||
Symbol * m_symbol;
|
||||
Expression * m_value;
|
||||
};
|
||||
|
||||
@@ -11,11 +11,13 @@ public:
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
static Complex compute(const Complex c, const Complex d);
|
||||
private:
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
Expression * evaluateOnComplex(Complex * c, Complex * d, Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnComplexAndMatrix(Complex * c, Matrix * m, Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * computeOnComplexAndComplexMatrix(const Complex * c, Evaluation * m) const override;
|
||||
Complex privateCompute(const Complex c, const Complex d) const override {
|
||||
return compute(c, d);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -13,9 +13,8 @@ public:
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float emptySequenceValue() const override;
|
||||
float approximateWithNextTerm(float sequence, float newTerm) const override;
|
||||
ExpressionLayout * createSequenceLayoutWithArgumentLayouts(ExpressionLayout * subscriptLayout, ExpressionLayout * superscriptLayout, ExpressionLayout * argumentLayout) const override;
|
||||
Expression * evaluateWithNextTerm(Expression ** args, Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * evaluateWithNextTerm(Evaluation * a, Evaluation * b) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -36,8 +36,7 @@ public:
|
||||
bool valueEquals(const Expression * e) const override;
|
||||
bool isMatrixSymbol() const;
|
||||
private:
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
const char m_name;
|
||||
};
|
||||
|
||||
@@ -12,8 +12,8 @@ public:
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float trigonometricApproximation(float x) const override;
|
||||
Expression * createComplexEvaluation(Expression * arg, Context & context, AngleUnit angleUnit) const override;
|
||||
Complex privateCompute(const Complex c, AngleUnit angleUnit) const override;
|
||||
float computeForRadianReal(float x) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -9,10 +9,9 @@ class TrigonometricFunction : public Function {
|
||||
public:
|
||||
TrigonometricFunction(const char * name);
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
virtual float trigonometricApproximation(float x) const = 0;
|
||||
virtual Expression * createComplexEvaluation(Expression * arg, Context & context, AngleUnit angleUnit) const = 0;
|
||||
Complex computeComplex(const Complex c, AngleUnit angleUnit) const override;
|
||||
virtual float computeForRadianReal(float x) const = 0;
|
||||
virtual Complex privateCompute(const Complex c, AngleUnit angleUnit) const = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ namespace Poincare {
|
||||
class VariableContext : public Context {
|
||||
public:
|
||||
VariableContext(char name, Context * parentContext = nullptr);
|
||||
void setExpressionForSymbolName(Expression * expression, const Symbol * symbol) override;
|
||||
const Expression * expressionForSymbol(const Symbol * symbol) override;
|
||||
void setExpressionForSymbolName(Evaluation * expression, const Symbol * symbol) override;
|
||||
const Evaluation * expressionForSymbol(const Symbol * symbol) override;
|
||||
private:
|
||||
char m_name;
|
||||
Complex m_value;
|
||||
|
||||
@@ -26,18 +26,8 @@ Expression * AbsoluteValue::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return a;
|
||||
}
|
||||
|
||||
float AbsoluteValue::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Expression * evaluation = m_args[0]->evaluate(context, angleUnit);
|
||||
assert(evaluation->type() == Type::Matrix || evaluation->type() == Type::Complex);
|
||||
float result = 0.0f;
|
||||
if (evaluation->type() == Type::Matrix) {
|
||||
result = NAN;
|
||||
} else {
|
||||
result = ((Complex *)evaluation)->r();
|
||||
}
|
||||
delete evaluation;
|
||||
return result;
|
||||
Complex AbsoluteValue::computeComplex(const Complex c, AngleUnit angleUnit) const {
|
||||
return Complex::Float(c.r());
|
||||
}
|
||||
|
||||
ExpressionLayout * AbsoluteValue::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <poincare/addition.h>
|
||||
#include <poincare/complex_matrix.h>
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
@@ -16,22 +17,31 @@ Expression::Type Addition::type() const {
|
||||
ExpressionLayout * Addition::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
assert(complexFormat != ComplexFormat::Default);
|
||||
ExpressionLayout** children_layouts = (ExpressionLayout **)malloc(3*sizeof(ExpressionLayout *));
|
||||
ExpressionLayout** children_layouts = new ExpressionLayout * [3];
|
||||
children_layouts[0] = m_operands[0]->createLayout(floatDisplayMode, complexFormat);
|
||||
children_layouts[1] = new StringLayout("+", 1);
|
||||
children_layouts[2] = m_operands[1]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[1]->createLayout(floatDisplayMode, complexFormat)) : m_operands[1]->createLayout(floatDisplayMode, complexFormat);
|
||||
ExpressionLayout * layout = new HorizontalLayout(children_layouts, 3);
|
||||
free(children_layouts);
|
||||
delete[] children_layouts;
|
||||
return layout;
|
||||
}
|
||||
|
||||
float Addition::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
return m_operands[0]->approximate(context, angleUnit)+m_operands[1]->approximate(context, angleUnit);;
|
||||
Complex Addition::compute(const Complex c, const Complex d) {
|
||||
return Complex::Cartesian(c.a()+d.a(), c.b()+d.b());
|
||||
}
|
||||
|
||||
Evaluation * Addition::computeOnMatrices(Evaluation * m, Evaluation * n) {
|
||||
Addition a;
|
||||
return a.computeOnNumericalMatrices(m,n);
|
||||
}
|
||||
|
||||
Evaluation * Addition::computeOnComplexAndMatrix(const Complex * c, Evaluation * m) {
|
||||
Addition a;
|
||||
return a.computeOnComplexAndComplexMatrix(c,m);
|
||||
}
|
||||
|
||||
Expression * Addition::cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands) const {
|
||||
int numberOfOperands, bool cloneOperands) const {
|
||||
return new Addition(newOperands, cloneOperands);
|
||||
}
|
||||
|
||||
@@ -39,8 +49,4 @@ bool Addition::isCommutative() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
Expression * Addition::evaluateOnComplex(Complex * c, Complex * d, Context& context, AngleUnit angleUnit) const {
|
||||
return new Complex(Complex::Cartesian(c->a()+ d->a(), c->b() + d->b()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,12 +23,16 @@ Expression * ArcCosine::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return c;
|
||||
}
|
||||
|
||||
float ArcCosine::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
Complex ArcCosine::computeComplex(const Complex c, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
if (angleUnit == AngleUnit::Degree) {
|
||||
return acosf(m_args[0]->approximate(context, angleUnit))*180.0f/M_PI;
|
||||
if (c.b() != 0.0f) {
|
||||
return Complex::Float(NAN);
|
||||
}
|
||||
return acosf(m_args[0]->approximate(context, angleUnit));
|
||||
float result = acosf(c.a());
|
||||
if (angleUnit == AngleUnit::Degree) {
|
||||
return Complex::Float(result*180.0f/M_PI);
|
||||
}
|
||||
return Complex::Float(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,12 +23,16 @@ Expression * ArcSine::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return s;
|
||||
}
|
||||
|
||||
float ArcSine::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
Complex ArcSine::computeComplex(const Complex c, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
if (angleUnit == AngleUnit::Degree) {
|
||||
return asinf(m_args[0]->approximate(context, angleUnit))*180.0f/M_PI;
|
||||
if (c.b() != 0.0f) {
|
||||
return Complex::Float(NAN);
|
||||
}
|
||||
return asinf(m_args[0]->approximate(context, angleUnit));
|
||||
float result = asinf(c.a());
|
||||
if (angleUnit == AngleUnit::Degree) {
|
||||
return Complex::Float(result*180.0f/M_PI);
|
||||
}
|
||||
return Complex::Float(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,12 +23,16 @@ Expression * ArcTangent::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return t;
|
||||
}
|
||||
|
||||
float ArcTangent::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
Complex ArcTangent::computeComplex(const Complex c, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
if (angleUnit == AngleUnit::Degree) {
|
||||
return atanf(m_args[0]->approximate(context, angleUnit))*180.0f/M_PI;
|
||||
if (c.b() != 0.0f) {
|
||||
return Complex::Float(NAN);
|
||||
}
|
||||
return atanf(m_args[0]->approximate(context, angleUnit));
|
||||
float result = atanf(c.a());
|
||||
if (angleUnit == AngleUnit::Degree) {
|
||||
return Complex::Float(result*180.0f/M_PI);
|
||||
}
|
||||
return Complex::Float(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <poincare/binary_operation.h>
|
||||
#include <poincare/complex_matrix.h>
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
@@ -7,6 +8,12 @@ extern "C" {
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
BinaryOperation::BinaryOperation()
|
||||
{
|
||||
m_operands[0] = nullptr;
|
||||
m_operands[1] = nullptr;
|
||||
}
|
||||
|
||||
BinaryOperation::BinaryOperation(Expression ** operands, bool cloneOperands) {
|
||||
assert(operands != nullptr);
|
||||
assert(operands[0] != nullptr);
|
||||
@@ -21,8 +28,12 @@ BinaryOperation::BinaryOperation(Expression ** operands, bool cloneOperands) {
|
||||
}
|
||||
|
||||
BinaryOperation::~BinaryOperation() {
|
||||
delete m_operands[1];
|
||||
delete m_operands[0];
|
||||
if (m_operands[1] != nullptr) {
|
||||
delete m_operands[1];
|
||||
}
|
||||
if (m_operands[0] != nullptr) {
|
||||
delete m_operands[0];
|
||||
}
|
||||
}
|
||||
|
||||
bool BinaryOperation::hasValidNumberOfArguments() const {
|
||||
@@ -43,95 +54,51 @@ Expression * BinaryOperation::clone() const {
|
||||
return this->cloneWithDifferentOperands((Expression**) m_operands, 2, true);
|
||||
}
|
||||
|
||||
Expression * BinaryOperation::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Expression * leftOperandEvalutation = m_operands[0]->evaluate(context, angleUnit);
|
||||
Expression * rightOperandEvalutation = m_operands[1]->evaluate(context, angleUnit);
|
||||
Expression * result = nullptr;
|
||||
switch (leftOperandEvalutation->type()) {
|
||||
case Type::Complex:
|
||||
{
|
||||
switch (rightOperandEvalutation->type()) {
|
||||
case Type::Complex:
|
||||
result = evaluateOnComplex((Complex *)leftOperandEvalutation, (Complex *)rightOperandEvalutation, context, angleUnit);
|
||||
break;
|
||||
case Type::Matrix:
|
||||
result = evaluateOnComplexAndMatrix((Complex *)leftOperandEvalutation, (Matrix *)rightOperandEvalutation, context, angleUnit);
|
||||
break;
|
||||
default:
|
||||
result = new Complex(Complex::Float(NAN));
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Type::Matrix:
|
||||
{
|
||||
switch (rightOperandEvalutation->type()) {
|
||||
case Type::Complex:
|
||||
result = evaluateOnMatrixAndComplex((Matrix *)leftOperandEvalutation, (Complex *)rightOperandEvalutation, context, angleUnit);
|
||||
break;
|
||||
case Type::Matrix:
|
||||
result = evaluateOnMatrices((Matrix *)leftOperandEvalutation, (Matrix *)rightOperandEvalutation, context, angleUnit);
|
||||
break;
|
||||
default:
|
||||
result = new Complex(Complex::Float(NAN));
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
result = new Complex(Complex::Float(NAN));
|
||||
break;
|
||||
Evaluation * BinaryOperation::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Evaluation * leftOperandEvalutation = m_operands[0]->evaluate(context, angleUnit);
|
||||
Evaluation * rightOperandEvalutation = m_operands[1]->evaluate(context, angleUnit);
|
||||
Evaluation * result = nullptr;
|
||||
if (leftOperandEvalutation->numberOfRows() == 1 && leftOperandEvalutation->numberOfColumns() == 1 && rightOperandEvalutation->numberOfRows() == 1 && rightOperandEvalutation->numberOfColumns() == 1) {
|
||||
result = computeOnComplexes(leftOperandEvalutation->complexOperand(0), rightOperandEvalutation->complexOperand(0));
|
||||
} else if (leftOperandEvalutation->numberOfRows() == 1 && leftOperandEvalutation->numberOfColumns() == 1) {
|
||||
result = computeOnComplexAndComplexMatrix(leftOperandEvalutation->complexOperand(0), rightOperandEvalutation);
|
||||
} else if (rightOperandEvalutation->numberOfRows() == 1 && rightOperandEvalutation->numberOfColumns() == 1) {
|
||||
result = computeOnComplexMatrixAndComplex(leftOperandEvalutation, rightOperandEvalutation->complexOperand(0));
|
||||
} else {
|
||||
result = computeOnNumericalMatrices(leftOperandEvalutation, rightOperandEvalutation);
|
||||
}
|
||||
delete leftOperandEvalutation;
|
||||
delete rightOperandEvalutation;
|
||||
if (result == nullptr) {
|
||||
result = new Complex(Complex::Float(NAN));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression * BinaryOperation::evaluateOnMatrixAndComplex(Matrix * m, Complex * c, Context& context, AngleUnit angleUnit) const {
|
||||
Expression ** operands = (Expression **)malloc(m->numberOfRows() * m->numberOfColumns()*sizeof(Expression *));
|
||||
for (int i = 0; i < m->numberOfRows() * m->numberOfColumns(); i++) {
|
||||
Expression * evaluation = m->operand(i)->evaluate(context, angleUnit);
|
||||
assert(evaluation->type() == Type::Matrix || evaluation->type() == Type::Complex);
|
||||
if (evaluation->type() == Type::Matrix) {
|
||||
operands[i] = new Complex(Complex::Float(NAN));
|
||||
delete evaluation;
|
||||
continue;
|
||||
}
|
||||
operands[i] = evaluateOnComplex((Complex *)evaluation, c, context, angleUnit);
|
||||
delete evaluation;
|
||||
Evaluation * BinaryOperation::computeOnComplexAndComplexMatrix(const Complex * c, Evaluation * n) const {
|
||||
return computeOnComplexMatrixAndComplex(n, c);
|
||||
}
|
||||
|
||||
Evaluation * BinaryOperation::computeOnComplexMatrixAndComplex(Evaluation * m, const Complex * d) const {
|
||||
Complex * operands = new Complex[m->numberOfRows()*m->numberOfColumns()];
|
||||
for (int i = 0; i < m->numberOfOperands(); i++) {
|
||||
operands[i] = privateCompute(*(m->complexOperand(i)), *d);
|
||||
}
|
||||
Expression * result = new Matrix(operands, m->numberOfRows() * m->numberOfColumns(), m->numberOfColumns(), m->numberOfRows(), false);
|
||||
free(operands);
|
||||
Evaluation * result = new ComplexMatrix(operands, m->numberOfRows(), m->numberOfColumns());
|
||||
delete[] operands;
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression * BinaryOperation::evaluateOnComplexAndMatrix(Complex * c, Matrix * m, Context& context, AngleUnit angleUnit) const {
|
||||
return evaluateOnMatrixAndComplex(m, c, context, angleUnit);
|
||||
}
|
||||
|
||||
Expression * BinaryOperation::evaluateOnMatrices(Matrix * m, Matrix * n, Context& context, AngleUnit angleUnit) const {
|
||||
if (m->numberOfColumns() != n->numberOfColumns() || m->numberOfRows() != n->numberOfRows()) {
|
||||
return new Complex(Complex::Float(NAN));
|
||||
Evaluation * BinaryOperation::computeOnNumericalMatrices(Evaluation * m, Evaluation * n) const {
|
||||
if (m->numberOfRows() != n->numberOfRows() && m->numberOfColumns() != n->numberOfColumns()) {
|
||||
return nullptr;
|
||||
}
|
||||
Expression ** operands = (Expression **)malloc(m->numberOfRows() * m->numberOfColumns()*sizeof(Expression *));
|
||||
for (int i = 0; i < m->numberOfRows() * m->numberOfColumns(); i++) {
|
||||
Expression * mEvaluation = m->operand(i)->evaluate(context, angleUnit);
|
||||
Expression * nEvaluation = n->operand(i)->evaluate(context, angleUnit);
|
||||
assert(mEvaluation->type() == Type::Matrix || mEvaluation->type() == Type::Complex);
|
||||
assert(nEvaluation->type() == Type::Matrix || nEvaluation->type() == Type::Complex);
|
||||
if (mEvaluation->type() == Type::Matrix ||nEvaluation->type() == Type::Matrix) {
|
||||
operands[i] = new Complex(Complex::Float(NAN));
|
||||
delete mEvaluation;
|
||||
delete nEvaluation;
|
||||
continue;
|
||||
}
|
||||
operands[i] = evaluateOnComplex((Complex *)mEvaluation, (Complex *)nEvaluation, context, angleUnit);
|
||||
delete mEvaluation;
|
||||
delete nEvaluation;
|
||||
Complex * operands = new Complex[m->numberOfRows()*m->numberOfColumns()];
|
||||
for (int i = 0; i < m->numberOfOperands(); i++) {
|
||||
operands[i] = privateCompute(*(m->complexOperand(i)), *(n->complexOperand(i)));
|
||||
}
|
||||
Expression * result = new Matrix(operands, m->numberOfRows() * m->numberOfColumns(), m->numberOfColumns(), m->numberOfRows(), false);
|
||||
free(operands);
|
||||
Evaluation * result = new ComplexMatrix(operands, m->numberOfRows(), m->numberOfColumns());
|
||||
delete[] operands;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <poincare/binomial_coefficient.h>
|
||||
#include <poincare/evaluation.h>
|
||||
#include <poincare/complex.h>
|
||||
#include "layout/parenthesis_layout.h"
|
||||
#include "layout/grid_layout.h"
|
||||
@@ -28,18 +29,21 @@ Expression * BinomialCoefficient::cloneWithDifferentOperands(Expression** newOpe
|
||||
return bc;
|
||||
}
|
||||
|
||||
float BinomialCoefficient::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
float n = m_args[0]->approximate(context, angleUnit);
|
||||
float k = m_args[1]->approximate(context, angleUnit);
|
||||
Evaluation * BinomialCoefficient::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Evaluation * nInput = m_args[0]->evaluate(context, angleUnit);
|
||||
Evaluation * kInput = m_args[1]->evaluate(context, angleUnit);
|
||||
float n = nInput->toFloat();
|
||||
float k = kInput->toFloat();
|
||||
delete nInput;
|
||||
delete kInput;
|
||||
if (isnan(n) || isnan(k) || n != (int)n || k != (int)k || k > n || k < 0.0f || n < 0.0f) {
|
||||
return NAN;
|
||||
return new Complex(Complex::Float(NAN));
|
||||
}
|
||||
float result = 1.0f;
|
||||
for (int i = 0; i < (int)k; i++) {
|
||||
result *= (n-(float)i)/(k-(float)i);
|
||||
}
|
||||
return roundf(result);
|
||||
return new Complex(Complex::Float(roundf(result)));
|
||||
}
|
||||
|
||||
ExpressionLayout * BinomialCoefficient::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
|
||||
|
||||
@@ -24,10 +24,11 @@ Expression * Ceiling::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return c;
|
||||
}
|
||||
|
||||
float Ceiling::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
float f = m_args[0]->approximate(context, angleUnit);
|
||||
return ceilf(f);
|
||||
Complex Ceiling::computeComplex(const Complex c, AngleUnit angleUnit) const {
|
||||
if (c.b() != 0.0f) {
|
||||
return Complex::Float(NAN);
|
||||
}
|
||||
return Complex::Float(ceilf(c.a()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ extern "C" {
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
}
|
||||
#include <poincare/complex_matrix.h>
|
||||
#include "layout/string_layout.h"
|
||||
#include "layout/baseline_relative_layout.h"
|
||||
#include <ion.h>
|
||||
@@ -56,44 +57,47 @@ Complex::Complex(const char * integralPart, int integralPartLength, bool integra
|
||||
m_b = 0.0f;
|
||||
}
|
||||
|
||||
Expression * Complex::clone() const {
|
||||
return new Complex(Cartesian(m_a, m_b));
|
||||
}
|
||||
|
||||
float Complex::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
if (m_b == 0.0f) {
|
||||
return m_a;
|
||||
float Complex::toFloat() const {
|
||||
if (m_b != 0.0f) {
|
||||
return NAN;
|
||||
}
|
||||
return NAN;
|
||||
return m_a;
|
||||
}
|
||||
|
||||
Expression * Complex::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
return clone();
|
||||
int Complex::numberOfRows() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Complex::numberOfColumns() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Expression::Type Complex::type() const {
|
||||
return Type::Complex;
|
||||
}
|
||||
|
||||
ExpressionLayout * Complex::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
if (complexFormat == ComplexFormat::Polar) {
|
||||
return createPolarLayout(floatDisplayMode);
|
||||
}
|
||||
return createCartesianLayout(floatDisplayMode);
|
||||
Complex * Complex::clone() const {
|
||||
return new Complex(Cartesian(m_a, m_b));
|
||||
}
|
||||
|
||||
int Complex::writeTextInBuffer(char * buffer, int bufferSize) {
|
||||
Evaluation * Complex::cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands) const {
|
||||
return this->clone();
|
||||
}
|
||||
|
||||
int Complex::writeTextInBuffer(char * buffer, int bufferSize) const {
|
||||
return convertComplexToText(buffer, bufferSize, Preferences::sharedPreferences()->displayMode(), Preferences::sharedPreferences()->complexFormat());
|
||||
}
|
||||
|
||||
float Complex::a() {
|
||||
Evaluation * Complex::createInverse() const {
|
||||
return new Complex(Cartesian(1.0f/m_a, -1.0f/m_b));
|
||||
}
|
||||
|
||||
float Complex::a() const {
|
||||
return m_a;
|
||||
}
|
||||
|
||||
float Complex::b() {
|
||||
float Complex::b() const {
|
||||
return m_b;
|
||||
}
|
||||
|
||||
@@ -116,8 +120,8 @@ float Complex::th() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
Complex * Complex::createConjugate() {
|
||||
return new Complex(Complex::Cartesian(m_a, -m_b));
|
||||
Complex Complex::conjugate() const {
|
||||
return Complex::Cartesian(m_a, -m_b);
|
||||
}
|
||||
|
||||
int Complex::convertFloatToText(float f, char * buffer, int bufferSize,
|
||||
@@ -152,6 +156,22 @@ Complex::Complex(float a, float b) :
|
||||
{
|
||||
}
|
||||
|
||||
const Complex * Complex::complexOperand(int i) const {
|
||||
return this;
|
||||
}
|
||||
|
||||
Evaluation * Complex::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
return this->clone();
|
||||
}
|
||||
|
||||
ExpressionLayout * Complex::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
if (complexFormat == ComplexFormat::Polar) {
|
||||
return createPolarLayout(floatDisplayMode);
|
||||
}
|
||||
return createCartesianLayout(floatDisplayMode);
|
||||
}
|
||||
|
||||
int Complex::convertComplexToText(char * buffer, int bufferSize, FloatDisplayMode displayMode, ComplexFormat complexFormat) const {
|
||||
assert(displayMode != FloatDisplayMode::Default);
|
||||
int numberOfChars = 0;
|
||||
|
||||
@@ -25,18 +25,8 @@ Expression * ComplexArgument::cloneWithDifferentOperands(Expression** newOperand
|
||||
return ca;
|
||||
}
|
||||
|
||||
float ComplexArgument::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Expression * evaluation = m_args[0]->evaluate(context, angleUnit);
|
||||
assert(evaluation->type() == Type::Matrix || evaluation->type() == Type::Complex);
|
||||
float result = 0.0f;
|
||||
if (evaluation->type() == Type::Matrix) {
|
||||
result = NAN;
|
||||
} else {
|
||||
result = ((Complex *)evaluation)->th();
|
||||
}
|
||||
delete evaluation;
|
||||
return result;
|
||||
Complex ComplexArgument::computeComplex(const Complex c, AngleUnit angleUnit) const {
|
||||
return Complex::Float(c.th());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
78
poincare/src/complex_matrix.cpp
Normal file
78
poincare/src/complex_matrix.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
}
|
||||
#include <poincare/complex_matrix.h>
|
||||
#include <poincare/complex.h>
|
||||
#include "layout/grid_layout.h"
|
||||
#include "layout/bracket_layout.h"
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
ComplexMatrix::ComplexMatrix(const Complex * complexes, int numberOfRows, int numberOfColumns) :
|
||||
m_numberOfRows(numberOfRows),
|
||||
m_numberOfColumns(numberOfColumns)
|
||||
{
|
||||
assert(complexes != nullptr);
|
||||
m_values = new Complex[numberOfColumns*numberOfRows];
|
||||
for (int i = 0; i < numberOfColumns*numberOfRows; i++) {
|
||||
m_values[i] = complexes[i];
|
||||
}
|
||||
}
|
||||
|
||||
ComplexMatrix::~ComplexMatrix() {
|
||||
delete[] m_values;
|
||||
}
|
||||
|
||||
float ComplexMatrix::toFloat() const {
|
||||
if (m_numberOfColumns != 1 || m_numberOfRows != 1) {
|
||||
return NAN;
|
||||
}
|
||||
if (m_values[0].b() != 0.0f) {
|
||||
return NAN;
|
||||
}
|
||||
return m_values[0].a();
|
||||
}
|
||||
|
||||
int ComplexMatrix::numberOfRows() const {
|
||||
return m_numberOfRows;
|
||||
}
|
||||
|
||||
int ComplexMatrix::numberOfColumns() const {
|
||||
return m_numberOfColumns;
|
||||
}
|
||||
|
||||
const Complex * ComplexMatrix::complexOperand(int i) const {
|
||||
return &m_values[i];
|
||||
}
|
||||
|
||||
ComplexMatrix * ComplexMatrix::clone() const {
|
||||
return this->cloneWithDifferentOperands((Expression **)&m_values, m_numberOfRows*m_numberOfColumns);
|
||||
}
|
||||
|
||||
ComplexMatrix * ComplexMatrix::cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands) const {
|
||||
assert(newOperands != nullptr);
|
||||
return new ComplexMatrix((Complex *)newOperands[0], m_numberOfColumns, m_numberOfRows);
|
||||
}
|
||||
|
||||
Evaluation * ComplexMatrix::createIdentity(int dim) {
|
||||
Complex * operands = new Complex [dim*dim];
|
||||
for (int i = 0; i < dim; i++) {
|
||||
for (int j = 0; j < dim; j++) {
|
||||
if (i == j) {
|
||||
operands[i*dim+j] = Complex(Complex::Float(1.0));
|
||||
} else {
|
||||
operands[i*dim+j] = Complex(Complex::Float(0.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
Evaluation * matrix = new ComplexMatrix(operands, dim, dim);
|
||||
delete [] operands;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <poincare/confidence_interval.h>
|
||||
#include <poincare/matrix.h>
|
||||
#include <poincare/evaluation.h>
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
@@ -24,19 +25,20 @@ Expression * ConfidenceInterval::cloneWithDifferentOperands(Expression** newOper
|
||||
return ci;
|
||||
}
|
||||
|
||||
float ConfidenceInterval::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
return NAN;
|
||||
}
|
||||
|
||||
Expression * ConfidenceInterval::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
float f = m_args[0]->approximate(context, angleUnit);
|
||||
float n = m_args[1]->approximate(context, angleUnit);
|
||||
Expression * operands[2];
|
||||
operands[0] = new Complex(Complex::Float(f - 1.0f/sqrtf(n)));
|
||||
operands[1] = new Complex(Complex::Float(f + 1.0f/sqrtf(n)));
|
||||
return new Matrix(new MatrixData(operands, 2, 2, 1, false));
|
||||
Evaluation * ConfidenceInterval::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Evaluation * fInput = m_args[0]->evaluate(context, angleUnit);
|
||||
Evaluation * nInput = m_args[1]->evaluate(context, angleUnit);
|
||||
float f = fInput->toFloat();
|
||||
float n = nInput->toFloat();
|
||||
delete fInput;
|
||||
delete nInput;
|
||||
if (isnan(f) || isnan(n) || n != (int)n || n < 0.0f || f < 0.0f || f > 1.0f) {
|
||||
return new Complex(Complex::Float(NAN));
|
||||
}
|
||||
Complex operands[2];
|
||||
operands[0] = Complex::Float(f - 1.0f/sqrtf(n));
|
||||
operands[1] = Complex::Float(f + 1.0f/sqrtf(n));
|
||||
return new ComplexMatrix(operands, 2, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,22 +26,8 @@ Expression * Conjugate::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return c;
|
||||
}
|
||||
|
||||
float Conjugate::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
return m_args[0]->approximate(context, angleUnit);
|
||||
}
|
||||
|
||||
Expression * Conjugate::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Expression * evaluation = m_args[0]->evaluate(context, angleUnit);
|
||||
assert(evaluation->type() == Type::Matrix || evaluation->type() == Type::Complex);
|
||||
if (evaluation->type() == Type::Matrix) {
|
||||
delete evaluation;
|
||||
return new Complex(Complex::Float(NAN));
|
||||
}
|
||||
Expression * result = ((Complex *)evaluation)->createConjugate();
|
||||
delete evaluation;
|
||||
return result;
|
||||
Complex Conjugate::computeComplex(const Complex c, AngleUnit angleUnit) const {
|
||||
return c.conjugate();
|
||||
}
|
||||
|
||||
ExpressionLayout * Conjugate::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
|
||||
|
||||
@@ -25,19 +25,13 @@ Expression * Cosine::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return c;
|
||||
}
|
||||
|
||||
float Cosine::trigonometricApproximation(float x) const {
|
||||
Complex Cosine::compute(const Complex c) {
|
||||
Complex arg = Complex::Cartesian(-c.b(), c.a());
|
||||
return HyperbolicCosine::compute(arg);
|
||||
}
|
||||
|
||||
float Cosine::computeForRadianReal(float x) const {
|
||||
return cosf(x);
|
||||
}
|
||||
|
||||
Expression * Cosine::createComplexEvaluation(Expression * exp, Context & context, AngleUnit angleUnit) const {
|
||||
assert(exp->type() == Type::Complex);
|
||||
Expression * arg = new Complex(Complex::Cartesian(-((Complex *)exp)->b(), ((Complex *)exp)->a()));
|
||||
Function * cosh = new HyperbolicCosine();
|
||||
cosh->setArgument(&arg, 1, true);
|
||||
delete arg;
|
||||
Expression * resultEvaluation = cosh->evaluate(context, angleUnit);
|
||||
delete cosh;
|
||||
return resultEvaluation;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,18 +27,21 @@ Expression * Derivative::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return d;
|
||||
}
|
||||
|
||||
float Derivative::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Evaluation * Derivative::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
VariableContext xContext = VariableContext('x', &context);
|
||||
Symbol xSymbol = Symbol('x');
|
||||
float x = m_args[1]->approximate(context, angleUnit);
|
||||
Evaluation * xInput = m_args[1]->evaluate(context, angleUnit);
|
||||
float x = xInput->toFloat();
|
||||
delete xInput;
|
||||
Complex e = Complex::Float(x);
|
||||
xContext.setExpressionForSymbolName(&e, &xSymbol);
|
||||
float functionValue = m_args[0]->approximate(xContext, angleUnit);
|
||||
Evaluation * fInput = m_args[1]->evaluate(xContext, angleUnit);
|
||||
float functionValue = fInput->toFloat();
|
||||
delete fInput;
|
||||
|
||||
// No complex/matrix version of Derivative
|
||||
if (isnan(x) || isnan(functionValue)) {
|
||||
return NAN;
|
||||
return new Complex(Complex::Float(NAN));
|
||||
}
|
||||
|
||||
/* Ridders' Algorithm
|
||||
@@ -96,23 +99,27 @@ float Derivative::privateApproximate(Context& context, AngleUnit angleUnit) cons
|
||||
}
|
||||
/* if the error is too big regarding the value, do not return the answer */
|
||||
if (err/ans > k_maxErrorRateOnApproximation || isnan(err)) {
|
||||
return NAN;
|
||||
return new Complex(Complex::Float(NAN));
|
||||
}
|
||||
if (err < FLT_MIN) {
|
||||
return ans;
|
||||
return new Complex(Complex::Float(ans));
|
||||
}
|
||||
err = powf(10.0f, (int)log10f(fabsf(err))+2.0f);
|
||||
return roundf(ans/err)*err;
|
||||
return new Complex(Complex::Float(roundf(ans/err)*err));
|
||||
}
|
||||
|
||||
float Derivative::growthRateAroundAbscissa(float x, float h, VariableContext xContext, AngleUnit angleUnit) const {
|
||||
Symbol xSymbol = Symbol('x');
|
||||
Complex e = Complex::Float(x + h);
|
||||
xContext.setExpressionForSymbolName(&e, &xSymbol);
|
||||
float expressionPlus = m_args[0]->approximate(xContext, angleUnit);
|
||||
Evaluation * fInput = m_args[0]->evaluate(xContext, angleUnit);
|
||||
float expressionPlus = fInput->toFloat();
|
||||
delete fInput;
|
||||
e = Complex::Float(x-h);
|
||||
xContext.setExpressionForSymbolName(&e, &xSymbol);
|
||||
float expressionMinus = m_args[0]->approximate(xContext, angleUnit);
|
||||
fInput = m_args[0]->evaluate(xContext, angleUnit);
|
||||
float expressionMinus = fInput->toFloat();
|
||||
delete fInput;
|
||||
return (expressionPlus - expressionMinus)/(2*h);
|
||||
}
|
||||
|
||||
@@ -120,13 +127,19 @@ float Derivative::approximateDerivate2(float x, float h, VariableContext xContex
|
||||
Symbol xSymbol = Symbol('x');
|
||||
Complex e = Complex::Float(x + h);
|
||||
xContext.setExpressionForSymbolName(&e, &xSymbol);
|
||||
float expressionPlus = m_args[0]->approximate(xContext, angleUnit);
|
||||
Evaluation * fInput = m_args[0]->evaluate(xContext, angleUnit);
|
||||
float expressionPlus = fInput->toFloat();
|
||||
delete fInput;
|
||||
e = Complex::Float(x);
|
||||
xContext.setExpressionForSymbolName(&e, &xSymbol);
|
||||
float expression = m_args[0]->approximate(xContext, angleUnit);
|
||||
fInput = m_args[0]->evaluate(xContext, angleUnit);
|
||||
float expression = fInput->toFloat();
|
||||
delete fInput;
|
||||
e = Complex::Float(x-h);
|
||||
xContext.setExpressionForSymbolName(&e, &xSymbol);
|
||||
float expressionMinus = m_args[0]->approximate(xContext, angleUnit);
|
||||
fInput = m_args[0]->evaluate(xContext, angleUnit);
|
||||
float expressionMinus = fInput->toFloat();
|
||||
delete fInput;
|
||||
return expressionPlus - 2.0f*expression + expressionMinus;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,18 +24,11 @@ Expression * Determinant::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return d;
|
||||
}
|
||||
|
||||
float Determinant::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Expression * evaluation = m_args[0]->evaluate(context, angleUnit);
|
||||
assert(evaluation->type() == Type::Matrix || evaluation->type() == Type::Complex);
|
||||
if (evaluation->type() == Type::Complex) {
|
||||
float result = evaluation->approximate(context, angleUnit);
|
||||
delete evaluation;
|
||||
return result;
|
||||
}
|
||||
float det = ((Matrix *)evaluation)->determinant(context, angleUnit);
|
||||
delete evaluation;
|
||||
return det;
|
||||
Evaluation * Determinant::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Evaluation * input = m_args[0]->evaluate(context, angleUnit);
|
||||
Evaluation * result = input->createDeterminant();
|
||||
delete input;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,14 +24,17 @@ Expression * DivisionQuotient::cloneWithDifferentOperands(Expression** newOperan
|
||||
return dq;
|
||||
}
|
||||
|
||||
float DivisionQuotient::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
float f1 = m_args[0]->approximate(context, angleUnit);
|
||||
float f2 = m_args[1]->approximate(context, angleUnit);
|
||||
Evaluation * DivisionQuotient::privateEvaluate(Context & context, AngleUnit angleUnit) const {
|
||||
Evaluation * f1Input = m_args[0]->evaluate(context, angleUnit);
|
||||
Evaluation * f2Input = m_args[1]->evaluate(context, angleUnit);
|
||||
float f1 = f1Input->toFloat();
|
||||
float f2 = f2Input->toFloat();
|
||||
delete f1Input;
|
||||
delete f2Input;
|
||||
if (isnan(f1) || isnan(f2) || f1 != (int)f1 || f2 != (int)f2) {
|
||||
return NAN;
|
||||
return new Complex(Complex::Float(NAN));
|
||||
}
|
||||
return floorf(f1/f2);
|
||||
return new Complex(Complex::Float(floorf(f1/f2)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,14 +24,17 @@ Expression * DivisionRemainder::cloneWithDifferentOperands(Expression** newOpera
|
||||
return dr;
|
||||
}
|
||||
|
||||
float DivisionRemainder::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
float f1 = m_args[0]->approximate(context, angleUnit);
|
||||
float f2 = m_args[1]->approximate(context, angleUnit);
|
||||
Evaluation * DivisionRemainder::privateEvaluate(Context & context, AngleUnit angleUnit) const {
|
||||
Evaluation * f1Input = m_args[0]->evaluate(context, angleUnit);
|
||||
Evaluation * f2Input = m_args[1]->evaluate(context, angleUnit);
|
||||
float f1 = f1Input->toFloat();
|
||||
float f2 = f2Input->toFloat();
|
||||
delete f1Input;
|
||||
delete f2Input;
|
||||
if (isnan(f1) || isnan(f2) || f1 != (int)f1 || f2 != (int)f2) {
|
||||
return NAN;
|
||||
return new Complex(Complex::Float(NAN));
|
||||
}
|
||||
return roundf(f1-f2*floorf(f1/f2));
|
||||
return new Complex(Complex::Float(roundf(f1-f2*floorf(f1/f2))));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
194
poincare/src/evaluation.cpp
Normal file
194
poincare/src/evaluation.cpp
Normal file
@@ -0,0 +1,194 @@
|
||||
#include <poincare/evaluation.h>
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
}
|
||||
#include <poincare/complex_matrix.h>
|
||||
#include <poincare/addition.h>
|
||||
#include <poincare/complex.h>
|
||||
#include "layout/grid_layout.h"
|
||||
#include "layout/bracket_layout.h"
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
Expression::Type Evaluation::type() const {
|
||||
return Type::Evaluation;
|
||||
}
|
||||
|
||||
bool Evaluation::hasValidNumberOfArguments() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
const Expression * Evaluation::operand(int i) const {
|
||||
return complexOperand(i);
|
||||
}
|
||||
|
||||
Evaluation * Evaluation::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(false);
|
||||
return this->clone();
|
||||
}
|
||||
|
||||
Evaluation * Evaluation::createTrace() const {
|
||||
if (numberOfColumns() != numberOfRows()) {
|
||||
return new Complex(Complex::Float(NAN));
|
||||
}
|
||||
int dim = numberOfRows();
|
||||
Complex c = Complex::Float(0.0f);
|
||||
for (int i = 0; i < dim; i++) {
|
||||
c = Addition::compute(c, *complexOperand(i*dim+i));
|
||||
}
|
||||
return new Complex(c);
|
||||
}
|
||||
|
||||
// TODO: implement determinant for complex matrix?
|
||||
Evaluation * Evaluation::createDeterminant() const {
|
||||
if (numberOfColumns() != numberOfRows()) {
|
||||
return new Complex(Complex::Float(NAN));
|
||||
}
|
||||
int dim = numberOfRows();
|
||||
float ** tempMat = new float*[dim];
|
||||
for (int i = 0; i < dim; i++) {
|
||||
tempMat[i] = new float[dim];
|
||||
}
|
||||
float det = 1.0f;
|
||||
/* Copy the matrix */
|
||||
for (int i = 0; i < dim; i++) {
|
||||
for (int j = 0; j < dim; j++) {
|
||||
tempMat[i][j] = complexOperand(i*dim+ j)->toFloat();
|
||||
}
|
||||
}
|
||||
|
||||
/* Main Loop: Gauss pivot */
|
||||
for (int i = 0; i < dim-1; i++) {
|
||||
/* Search for pivot */
|
||||
int rowWithPivot = i;
|
||||
for (int row = i+1; row < dim; row++) {
|
||||
if (fabsf(tempMat[rowWithPivot][i]) < fabsf(tempMat[row][i])) {
|
||||
rowWithPivot = row;
|
||||
}
|
||||
}
|
||||
float valuePivot = tempMat[rowWithPivot][i];
|
||||
/* if the pivot is null, det = 0. */
|
||||
if (fabsf(valuePivot) <= FLT_EPSILON) {
|
||||
for (int i = 0; i < dim; i++) {
|
||||
free(tempMat[i]);
|
||||
}
|
||||
free(tempMat);
|
||||
return new Complex(Complex::Float(0.0f));
|
||||
}
|
||||
/* Switch rows to have the pivot row as first row */
|
||||
if (rowWithPivot != i) {
|
||||
for (int col = i; col < dim; col++) {
|
||||
float temp = tempMat[i][col];
|
||||
tempMat[i][col] = tempMat[rowWithPivot][col];
|
||||
tempMat[rowWithPivot][col] = temp;
|
||||
}
|
||||
det *= -1;
|
||||
}
|
||||
det *= valuePivot;
|
||||
/* Set to 0 all A[][i] by linear combination */
|
||||
for (int row = i+1; row < dim; row++) {
|
||||
float factor = tempMat[row][i]/valuePivot;
|
||||
for (int col = i; col < dim; col++) {
|
||||
tempMat[row][col] -= factor*tempMat[i][col];
|
||||
}
|
||||
}
|
||||
}
|
||||
det *= tempMat[dim-1][dim-1];
|
||||
for (int i = 0; i < dim; i++) {
|
||||
delete[] tempMat[i];
|
||||
}
|
||||
delete[] tempMat;
|
||||
return new Complex(Complex::Float(det));
|
||||
}
|
||||
|
||||
Evaluation * Evaluation::createInverse() const {
|
||||
if (numberOfColumns() != numberOfRows()) {
|
||||
return new Complex(Complex::Float(NAN));
|
||||
}
|
||||
int dim = numberOfRows();
|
||||
/* Create the matrix inv = (A|I) with A the input matrix and I the dim identity matrix */
|
||||
float ** inv = new float*[dim];
|
||||
for (int i = 0; i < dim; i++) {
|
||||
inv[i] = new float [2*dim];
|
||||
}
|
||||
for (int i = 0; i < dim; i++) {
|
||||
for (int j = 0; j < dim; j++) {
|
||||
inv[i][j] = complexOperand(i*dim+j)->toFloat();
|
||||
}
|
||||
for (int j = dim; j < 2*dim; j++) {
|
||||
inv[i][j] = (i+dim == j);
|
||||
}
|
||||
}
|
||||
/* Main Loop: Gauss pivot */
|
||||
for (int i = 0; i < dim; i++) {
|
||||
/* Search for pivot */
|
||||
int rowWithPivot = i;
|
||||
for (int row = i+1; row < dim; row++) {
|
||||
if (fabsf(inv[rowWithPivot][i]) < fabsf(inv[row][i])) {
|
||||
rowWithPivot = row;
|
||||
}
|
||||
}
|
||||
float valuePivot = inv[rowWithPivot][i];
|
||||
/* if the pivot is null, the matrix in not invertible. */
|
||||
if (fabsf(valuePivot) <= FLT_EPSILON) {
|
||||
for (int i = 0; i < dim; i++) {
|
||||
free(inv[i]);
|
||||
}
|
||||
free(inv);
|
||||
return new Complex(Complex::Float(NAN));
|
||||
}
|
||||
/* Switch rows to have the pivot row as first row */
|
||||
if (rowWithPivot != i) {
|
||||
for (int col = i; col < 2*dim; col++) {
|
||||
float temp = inv[i][col];
|
||||
inv[i][col] = inv[rowWithPivot][col];
|
||||
inv[rowWithPivot][col] = temp;
|
||||
}
|
||||
}
|
||||
/* A[pivot][] = A[pivot][]/valuePivot */
|
||||
for (int col = 0; col < 2*dim; col++) {
|
||||
inv[i][col] /= valuePivot;
|
||||
}
|
||||
/* Set to 0 all A[][row] by linear combination */
|
||||
for (int row = 0; row < dim; row++) {
|
||||
if (row == i) {
|
||||
continue;
|
||||
}
|
||||
float factor = inv[row][i];
|
||||
for (int col = 0; col < 2*dim; col++) {
|
||||
inv[row][col] -= factor*inv[i][col];
|
||||
}
|
||||
}
|
||||
}
|
||||
Complex * operands = new Complex[numberOfOperands()];
|
||||
for (int i = 0; i < dim; i++) {
|
||||
for (int j = 0; j < dim; j++) {
|
||||
operands[i*dim+j] = Complex(Complex::Float(inv[i][j+dim]));
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < dim; i++) {
|
||||
delete[] inv[i];
|
||||
}
|
||||
delete[] inv;
|
||||
Evaluation * matrix = new ComplexMatrix(operands, numberOfColumns(), numberOfRows());
|
||||
delete[] operands;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
Evaluation * Evaluation::createTranspose() const {
|
||||
Complex * operands = new Complex[numberOfOperands()];
|
||||
for (int i = 0; i < numberOfRows(); i++) {
|
||||
for (int j = 0; j < numberOfColumns(); j++) {
|
||||
operands[j*numberOfRows()+i] = *(complexOperand(i*numberOfColumns()+j));
|
||||
}
|
||||
}
|
||||
Evaluation * matrix = new ComplexMatrix(operands, numberOfRows(), numberOfColumns());
|
||||
delete[] operands;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <poincare/symbol.h>
|
||||
#include <poincare/list_data.h>
|
||||
#include <poincare/matrix_data.h>
|
||||
#include <poincare/evaluation.h>
|
||||
#include "expression_parser.hpp"
|
||||
#include "expression_lexer.hpp"
|
||||
extern "C" {
|
||||
@@ -57,7 +58,7 @@ ExpressionLayout * Expression::createLayout(FloatDisplayMode floatDisplayMode, C
|
||||
}
|
||||
}
|
||||
|
||||
Expression * Expression::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Evaluation * Expression::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
switch (angleUnit) {
|
||||
case AngleUnit::Default:
|
||||
return privateEvaluate(context, Preferences::sharedPreferences()->angleUnit());
|
||||
@@ -67,21 +68,21 @@ Expression * Expression::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
}
|
||||
|
||||
float Expression::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
switch (angleUnit) {
|
||||
case AngleUnit::Default:
|
||||
return privateApproximate(context, Preferences::sharedPreferences()->angleUnit());
|
||||
default:
|
||||
return privateApproximate(context, angleUnit);
|
||||
}
|
||||
Evaluation * evaluation = evaluate(context, angleUnit);
|
||||
float result = evaluation->toFloat();
|
||||
delete evaluation;
|
||||
return result;
|
||||
}
|
||||
|
||||
float Expression::approximate(const char * text, Context& context, AngleUnit angleUnit) {
|
||||
Expression * exp = parse(text);
|
||||
float result = NAN;
|
||||
if (exp != nullptr) {
|
||||
result = exp->approximate(context, angleUnit);
|
||||
delete exp;
|
||||
if (exp == nullptr) {
|
||||
return NAN;
|
||||
}
|
||||
Evaluation * evaluation = exp->evaluate(context, angleUnit);
|
||||
delete exp;
|
||||
float result = evaluation->toFloat();
|
||||
delete evaluation;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -103,7 +104,7 @@ Expression * Expression::simplify() const {
|
||||
/* We recursively simplify the children expressions.
|
||||
* Note that we are sure to get the samne number of children as we had before
|
||||
*/
|
||||
Expression ** simplifiedOperands = (Expression**) malloc(result->numberOfOperands() * sizeof(Expression*));
|
||||
Expression ** simplifiedOperands = new Expression * [result->numberOfOperands()];
|
||||
for (int i = 0; i < result->numberOfOperands(); i++) {
|
||||
simplifiedOperands[i] = result->operand(i)->simplify();
|
||||
}
|
||||
@@ -115,7 +116,7 @@ Expression * Expression::simplify() const {
|
||||
result = tmp;
|
||||
|
||||
// The table is no longer needed.
|
||||
free(simplifiedOperands);
|
||||
delete [] simplifiedOperands;
|
||||
|
||||
simplification_pass_was_useful = false;
|
||||
for (int i=0; i<knumberOfSimplifications; i++) {
|
||||
@@ -180,7 +181,7 @@ bool Expression::commutativeOperandsIdentity(const Expression * e) const {
|
||||
/* We create a table allowing us to know which operands of the second
|
||||
* expression have been associated with one of the operands of the first
|
||||
* expression */
|
||||
bool * operandMatched = (bool *) malloc (this->numberOfOperands() * sizeof(bool));
|
||||
bool * operandMatched = new bool [this->numberOfOperands()];
|
||||
for (int i(0); i<this->numberOfOperands(); i++) {
|
||||
operandMatched[i] = false;
|
||||
}
|
||||
@@ -188,7 +189,7 @@ bool Expression::commutativeOperandsIdentity(const Expression * e) const {
|
||||
// We call our recursive helper.
|
||||
bool commutativelyIdentical = this->combinatoryCommutativeOperandsIdentity(e, operandMatched, leftToMatch);
|
||||
|
||||
free(operandMatched);
|
||||
delete [] operandMatched;
|
||||
return commutativelyIdentical;
|
||||
}
|
||||
|
||||
@@ -229,7 +230,7 @@ bool Expression::isCommutative() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
int Expression::writeTextInBuffer(char * buffer, int bufferSize) {
|
||||
int Expression::writeTextInBuffer(char * buffer, int bufferSize) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user