mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Add complex format as an argument of simplification
This commit is contained in:
@@ -186,7 +186,7 @@ Calculation::EqualSign Calculation::exactAndApproximateDisplayedOutputsAreEqual(
|
||||
if (exactOutputExpression.isUninitialized()) {
|
||||
exactOutputExpression = Undefined();
|
||||
}
|
||||
m_equalSign = exactOutputExpression.isEqualToItsApproximationLayout(approximateOutput(context), buffer, bufferSize, preferences->angleUnit(), preferences->displayMode(), preferences->numberOfSignificantDigits(), *context) ? EqualSign::Equal : EqualSign::Approximation;
|
||||
m_equalSign = exactOutputExpression.isEqualToItsApproximationLayout(approximateOutput(context), buffer, bufferSize, preferences->complexFormat(), preferences->angleUnit(), preferences->displayMode(), preferences->numberOfSignificantDigits(), *context) ? EqualSign::Equal : EqualSign::Approximation;
|
||||
return m_equalSign;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,9 @@ inline int Serialize(const Poincare::Expression e, char * buffer, int bufferSize
|
||||
|
||||
template <class T>
|
||||
inline Poincare::Expression Approximate(const Poincare::Expression e, Poincare::Context & context) {
|
||||
return e.approximate<T>(context, Poincare::Preferences::sharedPreferences()->angleUnit(), Poincare::Preferences::sharedPreferences()->complexFormat());
|
||||
Poincare::Preferences::ComplexFormat complexFormat = Poincare::Preferences::sharedPreferences()->complexFormat();
|
||||
complexFormat = Poincare::Expression::UpdatedComplexFormatWithExpressionInput(complexFormat, e, context);
|
||||
return e.approximate<T>(context, complexFormat, Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@@ -34,23 +36,27 @@ inline T ApproximateToScalar(const Poincare::Expression e, Poincare::Context & c
|
||||
|
||||
template <class T>
|
||||
inline T ApproximateToScalar(const char * text, Poincare::Context & context) {
|
||||
return Poincare::Expression::approximateToScalar<T>(text, context, Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
Poincare::Preferences::ComplexFormat complexFormat = Poincare::Preferences::sharedPreferences()->complexFormat();
|
||||
complexFormat = Poincare::Expression::UpdatedComplexFormatWithTextInput(complexFormat, text);
|
||||
return Poincare::Expression::approximateToScalar<T>(text, context, complexFormat, Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
}
|
||||
|
||||
inline Poincare::Expression ParseAndSimplify(const char * text, Poincare::Context & context) {
|
||||
return Poincare::Expression::ParseAndSimplify(text, context, Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
return Poincare::Expression::ParseAndSimplify(text, context, Poincare::Preferences::sharedPreferences()->complexFormat(), Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
}
|
||||
|
||||
inline void Simplify(Poincare::Expression * e, Poincare::Context & context) {
|
||||
*e = e->simplify(context, Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
inline void Simplify(Poincare::Expression * e, Poincare::Context & context, Poincare::Preferences::ComplexFormat complexFormat = Poincare::Preferences::sharedPreferences()->complexFormat()) {
|
||||
complexFormat = Poincare::Expression::UpdatedComplexFormatWithExpressionInput(complexFormat, *e, context);
|
||||
*e = e->simplify(context, complexFormat, Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
}
|
||||
|
||||
inline void ParseAndSimplifyAndApproximate(const char * text, Poincare::Expression * simplifiedExpression, Poincare::Expression * approximateExpression, Poincare::Context & context) {
|
||||
Poincare::Expression::ParseAndSimplifyAndApproximate(text, simplifiedExpression, approximateExpression, context, Poincare::Preferences::sharedPreferences()->angleUnit(), Poincare::Preferences::sharedPreferences()->complexFormat());
|
||||
Poincare::Expression::ParseAndSimplifyAndApproximate(text, simplifiedExpression, approximateExpression, context, Poincare::Preferences::sharedPreferences()->complexFormat(), Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
}
|
||||
|
||||
inline void SimplifyAndApproximate(Poincare::Expression * e, Poincare::Expression * approximate, Poincare::Context & context) {
|
||||
e->simplifyAndApproximate(e, approximate, context, Poincare::Preferences::sharedPreferences()->angleUnit(), Poincare::Preferences::sharedPreferences()->complexFormat());
|
||||
inline void SimplifyAndApproximate(Poincare::Expression * e, Poincare::Expression * approximate, Poincare::Context & context, Poincare::Preferences::ComplexFormat complexFormat = Poincare::Preferences::sharedPreferences()->complexFormat()) {
|
||||
complexFormat = Poincare::Expression::UpdatedComplexFormatWithExpressionInput(complexFormat, *e, context);
|
||||
e->simplifyAndApproximate(e, approximate, context, complexFormat, Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ Expression Equation::standardForm(Context * context) const {
|
||||
return m_standardForm;
|
||||
}
|
||||
if (e.type() == ExpressionNode::Type::Equal) {
|
||||
m_standardForm = static_cast<const Equal&>(e).standardEquation(*context, Preferences::sharedPreferences()->angleUnit());
|
||||
Preferences * preferences = Preferences::sharedPreferences();
|
||||
m_standardForm = static_cast<const Equal&>(e).standardEquation(*context, Expression::UpdatedComplexFormatWithTextInput(preferences->complexFormat(), text()), preferences->angleUnit());
|
||||
} else {
|
||||
assert(e.type() == ExpressionNode::Type::Rational && static_cast<const Rational&>(e).isOne());
|
||||
// The equality was reduced which means the equality was always true.
|
||||
|
||||
@@ -126,7 +126,7 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) {
|
||||
bool isLinear = true; // Invalid the linear system if one equation is non-linear
|
||||
Preferences * preferences = Preferences::sharedPreferences();
|
||||
for (int i = 0; i < numberOfDefinedModels(); i++) {
|
||||
isLinear = isLinear && definedModelAtIndex(i)->standardForm(context).getLinearCoefficients((char *)m_variables, Poincare::SymbolAbstract::k_maxNameSize, coefficients[i], &constants[i], *context, preferences->angleUnit());
|
||||
isLinear = isLinear && definedModelAtIndex(i)->standardForm(context).getLinearCoefficients((char *)m_variables, Poincare::SymbolAbstract::k_maxNameSize, coefficients[i], &constants[i], *context, updatedComplexFormat(), preferences->angleUnit());
|
||||
if (!isLinear) {
|
||||
// TODO: should we clean pool allocated memory if the system is not linear
|
||||
#if 0
|
||||
@@ -157,7 +157,7 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) {
|
||||
/* 2- Polynomial & Monovariable? */
|
||||
assert(numberOfVariables == 1 && numberOfDefinedModels() == 1);
|
||||
Expression polynomialCoefficients[Expression::k_maxNumberOfPolynomialCoefficients];
|
||||
int degree = definedModelAtIndex(0)->standardForm(context).getPolynomialReducedCoefficients(m_variables[0], polynomialCoefficients, *context, preferences->angleUnit());
|
||||
int degree = definedModelAtIndex(0)->standardForm(context).getPolynomialReducedCoefficients(m_variables[0], polynomialCoefficients, *context, updatedComplexFormat(), preferences->angleUnit());
|
||||
if (degree == 2) {
|
||||
/* Polynomial degree <= 2*/
|
||||
m_type = Type::PolynomialMonovariable;
|
||||
@@ -201,7 +201,7 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) {
|
||||
/* Check for equality between exact and approximate layouts */
|
||||
if (!m_exactSolutionIdentity[solutionIndex]) {
|
||||
char buffer[Shared::ExpressionModel::k_expressionBufferSize];
|
||||
m_exactSolutionEquality[solutionIndex] = exactSolutions[i].isEqualToItsApproximationLayout(exactSolutionsApproximations[i], buffer, Shared::ExpressionModel::k_expressionBufferSize, preferences->angleUnit(), preferences->displayMode(), preferences->numberOfSignificantDigits(), *context);
|
||||
m_exactSolutionEquality[solutionIndex] = exactSolutions[i].isEqualToItsApproximationLayout(exactSolutionsApproximations[i], buffer, Shared::ExpressionModel::k_expressionBufferSize, preferences->complexFormat(), preferences->angleUnit(), preferences->displayMode(), preferences->numberOfSignificantDigits(), *context);
|
||||
}
|
||||
solutionIndex++;
|
||||
}
|
||||
@@ -226,7 +226,7 @@ EquationStore::Error EquationStore::resolveLinearSystem(Expression exactSolution
|
||||
Ab.setDimensions(m, n+1);
|
||||
|
||||
// Compute the rank of (A | b)
|
||||
int rankAb = Ab.rank(*context, angleUnit, true);
|
||||
int rankAb = Ab.rank(*context, updatedComplexFormat(), angleUnit, true);
|
||||
|
||||
// Initialize the number of solutions
|
||||
m_numberOfSolutions = INT_MAX;
|
||||
@@ -251,7 +251,7 @@ EquationStore::Error EquationStore::resolveLinearSystem(Expression exactSolution
|
||||
m_numberOfSolutions = n;
|
||||
for (int i = 0; i < m_numberOfSolutions; i++) {
|
||||
exactSolutions[i] = Ab.matrixChild(i,n);
|
||||
PoincareHelpers::SimplifyAndApproximate(&exactSolutions[i], &exactSolutionsApproximations[i], *context);
|
||||
PoincareHelpers::SimplifyAndApproximate(&exactSolutions[i], &exactSolutionsApproximations[i], *context, updatedComplexFormat());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -263,7 +263,7 @@ EquationStore::Error EquationStore::oneDimensialPolynomialSolve(Expression exact
|
||||
assert(degree == 2);
|
||||
// Compute delta = b*b-4ac
|
||||
Expression delta = Subtraction(Power(coefficients[1].clone(), Rational(2)), Multiplication(Rational(4), coefficients[0].clone(), coefficients[2].clone()));
|
||||
PoincareHelpers::Simplify(&delta, *context);
|
||||
PoincareHelpers::Simplify(&delta, *context, updatedComplexFormat());
|
||||
if (delta.isUninitialized()) {
|
||||
delta = Poincare::Undefined();
|
||||
}
|
||||
@@ -280,7 +280,7 @@ EquationStore::Error EquationStore::oneDimensialPolynomialSolve(Expression exact
|
||||
}
|
||||
exactSolutions[m_numberOfSolutions] = delta;
|
||||
for (int i = 0; i <= m_numberOfSolutions; i++) {
|
||||
PoincareHelpers::SimplifyAndApproximate(&exactSolutions[i], &exactSolutionsApproximations[i], *context);
|
||||
PoincareHelpers::SimplifyAndApproximate(&exactSolutions[i], &exactSolutionsApproximations[i], *context, updatedComplexFormat());
|
||||
}
|
||||
return Error::NoError;
|
||||
#if 0
|
||||
@@ -356,6 +356,14 @@ void EquationStore::tidySolution() {
|
||||
}
|
||||
}
|
||||
|
||||
Preferences::ComplexFormat EquationStore::updatedComplexFormat() {
|
||||
Preferences::ComplexFormat complexFormat = Preferences::sharedPreferences()->complexFormat();
|
||||
if (complexFormat == Preferences::ComplexFormat::Real && isExplictlyComplex()) {
|
||||
return Preferences::ComplexFormat::Cartesian;
|
||||
}
|
||||
return complexFormat;
|
||||
}
|
||||
|
||||
bool EquationStore::isExplictlyComplex() {
|
||||
for (int i = 0; i < numberOfDefinedModels(); i++) {
|
||||
if (definedModelAtIndex(i)->containsIComplex()) {
|
||||
|
||||
@@ -83,6 +83,7 @@ private:
|
||||
Error oneDimensialPolynomialSolve(Poincare::Expression solutions[k_maxNumberOfExactSolutions], Poincare::Expression solutionApproximations[k_maxNumberOfExactSolutions], Poincare::Expression polynomialCoefficients[Poincare::Expression::k_maxNumberOfPolynomialCoefficients], int degree, Poincare::Context * context);
|
||||
void tidySolution();
|
||||
bool isExplictlyComplex();
|
||||
Poincare::Preferences::ComplexFormat updatedComplexFormat();
|
||||
|
||||
Equation m_equations[k_maxNumberOfEquations];
|
||||
Type m_type;
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
// Properties
|
||||
Type type() const override { return Type::AbsoluteValue; }
|
||||
Sign sign(Context * context) const override { return Sign::Positive; }
|
||||
Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
// Complex
|
||||
bool isReal(Context & context) const override { return true; }
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
};
|
||||
|
||||
class AbsoluteValue final : public Expression {
|
||||
@@ -53,12 +53,12 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("abs", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit AbsoluteValue(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<AbsoluteValueNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit);
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ private:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override;
|
||||
|
||||
/* Evaluation */
|
||||
template<typename T> static MatrixComplex<T> computeOnMatrixAndComplex(const MatrixComplex<T> m, const std::complex<T> c) {
|
||||
@@ -74,8 +74,8 @@ public:
|
||||
}
|
||||
}
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const;
|
||||
private:
|
||||
static const Number NumeralFactor(const Expression & e);
|
||||
@@ -83,8 +83,8 @@ private:
|
||||
static inline const Expression FirstNonNumeralFactor(const Expression & e);
|
||||
|
||||
static bool TermsHaveIdenticalNonNumeralFactors(const Expression & e1, const Expression & e2);
|
||||
Expression factorizeOnCommonDenominator(Context & context, Preferences::AngleUnit angleUnit);
|
||||
void factorizeChildrenAtIndexesInPlace(int index1, int index2, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression factorizeOnCommonDenominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
void factorizeChildrenAtIndexesInPlace(int index1, int index2, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
AdditionNode * node() const { return static_cast<AdditionNode *>(Expression::node()); }
|
||||
};
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ private:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
//Evaluation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("acos", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit ArcCosine(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<ArcCosineNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -26,7 +26,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
//Evaluation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("asin", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit ArcSine(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<ArcSineNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -30,7 +30,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
//Evaluation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("atan", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit ArcTangent(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<ArcTangentNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -29,7 +29,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("binomial", 2, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
BinomialCoefficient(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<BinomialCoefficientNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
|
||||
@@ -28,7 +28,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("ceil", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
explicit Ceiling(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<CeilingNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -27,7 +27,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("arg", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit ComplexArgument(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<ComplexArgumentNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -27,8 +27,8 @@ private:
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override;
|
||||
|
||||
private:
|
||||
template<typename T> Complex<T> templatedApproximate(Context& context, Preferences::AngleUnit angleUnit) const;
|
||||
@@ -46,28 +46,28 @@ public:
|
||||
Expression imag() { return childAtIndex(1); }
|
||||
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
|
||||
// Common operations (done in-place)
|
||||
Expression squareNorm(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression norm(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression argument(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
ComplexCartesian inverse(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
ComplexCartesian squareRoot(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
ComplexCartesian powerInteger(int n, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
ComplexCartesian multiply(ComplexCartesian & other, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
ComplexCartesian power(ComplexCartesian & other, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression squareNorm(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression norm(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression argument(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
ComplexCartesian inverse(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
ComplexCartesian squareRoot(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
ComplexCartesian powerInteger(int n, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
ComplexCartesian multiply(ComplexCartesian & other, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
ComplexCartesian power(ComplexCartesian & other, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
static constexpr int k_maxNumberOfNodesBeforeInterrupting = 50;
|
||||
ComplexCartesian(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<ComplexCartesianNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
}
|
||||
void factorAndArgumentOfFunction(Expression e, ExpressionNode::Type searchedType, Expression * factor, Expression * argument, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
void factorAndArgumentOfFunction(Expression e, ExpressionNode::Type searchedType, Expression * factor, Expression * argument, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
ComplexCartesian interruptComputationIfManyNodes();
|
||||
static Multiplication squareRootHelper(Expression e, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
static Expression powerHelper(Expression norm, Expression trigo, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
static Multiplication squareRootHelper(Expression e, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
static Expression powerHelper(Expression norm, Expression trigo, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("confidence", 2, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
ConfidenceInterval(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<ConfidenceIntervalNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
|
||||
@@ -27,7 +27,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("conj", 1, &UntypedBuilder);;
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit Conjugate(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<ConjugateNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
bool isIComplex() const { return isConstantChar(Ion::Charset::IComplex); }
|
||||
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
private:
|
||||
char m_name[0]; // MUST be the last member variable
|
||||
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
bool isIComplex() const { return node()->isIComplex(); }
|
||||
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
|
||||
private:
|
||||
ConstantNode * node() const { return static_cast<ConstantNode *>(Expression::node()); }
|
||||
|
||||
@@ -33,7 +33,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplication
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
return ApproximationHelper::Map<float>(this, context, angleUnit,computeOnComplex<float>);
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("cos", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit Cosine(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<CosineNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
// Properties
|
||||
Type type() const override { return Type::Decimal; }
|
||||
Sign sign(Context * context) const override { return m_negative ? Sign::Negative : Sign::Positive; }
|
||||
Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
// Approximation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
@@ -62,8 +62,8 @@ public:
|
||||
int simplificationOrderSameType(const ExpressionNode * e, bool canBeInterrupted) const override;
|
||||
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override;
|
||||
|
||||
// Serialization
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = 0) const override;
|
||||
@@ -104,8 +104,8 @@ private:
|
||||
Decimal(size_t size, const Integer & m, int e);
|
||||
Expression setSign(ExpressionNode::Sign s);
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ private:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
}
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("diff", 3, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
Derivative(Expression child0, Expression child1, Expression child2) : Expression(TreePool::sharedPool()->createTreeNode<DerivativeNode>()) {
|
||||
assert(child1.type() == ExpressionNode::Type::Symbol);
|
||||
|
||||
@@ -24,7 +24,7 @@ private:
|
||||
/* Serialization */
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
/* Simplification */
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
/* Approximation */
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("det", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
explicit Determinant(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<DeterminantNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
private:
|
||||
// Approximation
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
}
|
||||
Division(const DivisionNode * n) : Expression(n) {}
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("quo", 2, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
DivisionQuotient(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<DivisionQuotientNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
|
||||
@@ -29,7 +29,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("rem", 2, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
DivisionRemainder(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<DivisionRemainderNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
int polynomialDegree(Context & context, const char * symbolName) const override { return -1; }
|
||||
private:
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Layout
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
@@ -41,9 +41,9 @@ public:
|
||||
}
|
||||
|
||||
// For the equation A = B, create the reduced expression A-B
|
||||
Expression standardEquation(Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
Expression standardEquation(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -154,19 +154,21 @@ public:
|
||||
* the variables hold in 'variables'. Otherwise, it fills 'coefficients' with
|
||||
* the coefficients of the variables hold in 'variables' (following the same
|
||||
* order) and 'constant' with the constant of the expression. */
|
||||
bool getLinearCoefficients(char * variables, int maxVariableLength, Expression coefficients[], Expression constant[], Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
bool getLinearCoefficients(char * variables, int maxVariableLength, Expression coefficients[], Expression constant[], Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
/* getPolynomialCoefficients fills the table coefficients with the expressions
|
||||
* of the first 3 polynomial coefficients and returns the polynomial degree.
|
||||
* It is supposed to be called on a reduced expression.
|
||||
* coefficients has up to 3 entries. */
|
||||
static constexpr int k_maxPolynomialDegree = 2;
|
||||
static constexpr int k_maxNumberOfPolynomialCoefficients = k_maxPolynomialDegree+1;
|
||||
int getPolynomialReducedCoefficients(const char * symbolName, Expression coefficients[], Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
int getPolynomialReducedCoefficients(const char * symbolName, Expression coefficients[], Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
Expression replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression) { return node()->replaceSymbolWithExpression(symbol, expression); }
|
||||
Expression replaceUnknown(const Symbol & symbol);
|
||||
Expression defaultReplaceUnknown(const Symbol & symbol);
|
||||
|
||||
/* Complex */
|
||||
static Preferences::ComplexFormat UpdatedComplexFormatWithTextInput(Preferences::ComplexFormat complexFormat, const char * textInput);
|
||||
static Preferences::ComplexFormat UpdatedComplexFormatWithExpressionInput(Preferences::ComplexFormat complexFormat, const Expression & e, Context & context);
|
||||
bool isReal(Context & context) const { return node()->isReal(context); }
|
||||
|
||||
/* Comparison */
|
||||
@@ -174,27 +176,27 @@ public:
|
||||
* same structures and all their nodes have same types and values (ie,
|
||||
* sqrt(pi^2) is NOT identical to pi). */
|
||||
bool isIdenticalTo(const Expression e) const;
|
||||
bool isEqualToItsApproximationLayout(Expression approximation, char * buffer, int bufferSize, Preferences::AngleUnit angleUnit, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, Context & context);
|
||||
bool isEqualToItsApproximationLayout(Expression approximation, char * buffer, int bufferSize, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, Context & context);
|
||||
|
||||
/* Layout Helper */
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const;
|
||||
|
||||
/* Simplification */
|
||||
static Expression ParseAndSimplify(const char * text, Context & context, Preferences::AngleUnit angleUnit);
|
||||
static void ParseAndSimplifyAndApproximate(const char * text, Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat);
|
||||
Expression simplify(Context & context, Preferences::AngleUnit angleUnit);
|
||||
void simplifyAndApproximate(Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat);
|
||||
Expression reduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
static Expression ParseAndSimplify(const char * text, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
static void ParseAndSimplifyAndApproximate(const char * text, Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
Expression simplify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
void simplifyAndApproximate(Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
Expression reduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
static Expression ExpressionWithoutSymbols(Expression expressionWithSymbols, Context & context);
|
||||
Expression radianToDegree();
|
||||
Expression degreeToRadian();
|
||||
|
||||
/* Approximation Helper */
|
||||
template<typename U> static U epsilon();
|
||||
template<typename U> Expression approximate(Context& context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) const;
|
||||
template<typename U> Expression approximate(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
template<typename U> U approximateToScalar(Context& context, Preferences::AngleUnit angleUnit) const;
|
||||
template<typename U> static U approximateToScalar(const char * text, Context& context, Preferences::AngleUnit angleUnit);
|
||||
template<typename U> static U approximateToScalar(const char * text, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
template<typename U> U approximateWithValueForSymbol(const char * symbol, U x, Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
/* Expression roots/extrema solver */
|
||||
struct Coordinate2D {
|
||||
@@ -276,24 +278,24 @@ protected:
|
||||
* is reduced (only a numeral factor was potentially made positive, and if it
|
||||
* was -1, it was removed from the multiplication).
|
||||
*/
|
||||
Expression makePositiveAnyNegativeNumeralFactor(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const { return node()->denominator(context, angleUnit); }
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { return node()->shallowReduce(context, angleUnit, target); }
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { return node()->shallowBeautify(context, angleUnit); }
|
||||
Expression deepBeautify(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression makePositiveAnyNegativeNumeralFactor(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { return node()->denominator(context, complexFormat, angleUnit); }
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { return node()->shallowReduce(context, complexFormat, angleUnit, target); }
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { return node()->shallowBeautify(context, complexFormat, angleUnit); }
|
||||
Expression deepBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
|
||||
private:
|
||||
static constexpr int k_maxSymbolReplacementsCount = 10;
|
||||
static bool sSymbolReplacementsCountLock;
|
||||
/* Simplification */
|
||||
Expression deepReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
void deepReduceChildren(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
return node()->deepReduceChildren(context, angleUnit, target);
|
||||
Expression deepReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
void deepReduceChildren(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
return node()->deepReduceChildren(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
void defaultDeepReduceChildren(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression defaultShallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression defaultShallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { return *this; }
|
||||
void defaultDeepReduceChildren(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression defaultShallowReduce();
|
||||
Expression defaultShallowBeautify() { return *this; }
|
||||
|
||||
/* Approximation */
|
||||
template<typename U> Evaluation<U> approximateToEvaluation(Context& context, Preferences::AngleUnit angleUnit) const;
|
||||
|
||||
@@ -116,7 +116,7 @@ public:
|
||||
virtual bool isNumber() const { return false; }
|
||||
/*!*/ virtual Expression replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression);
|
||||
/*!*/ virtual Expression replaceUnknown(const Symbol & symbol);
|
||||
/*!*/ virtual Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target);
|
||||
/*!*/ virtual Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target);
|
||||
virtual int polynomialDegree(Context & context, const char * symbolName) const;
|
||||
/*!*/ virtual int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const;
|
||||
/*!*/ virtual Expression shallowReplaceReplaceableSymbols(Context & context);
|
||||
@@ -160,11 +160,11 @@ public:
|
||||
virtual Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const = 0;
|
||||
|
||||
/* Simplification */
|
||||
/*!*/ virtual void deepReduceChildren(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target);
|
||||
/*!*/ virtual Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target);
|
||||
/*!*/ virtual Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit);
|
||||
/*!*/ virtual void deepReduceChildren(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target);
|
||||
/*!*/ virtual Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target);
|
||||
/*!*/ virtual Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
/* Return a clone of the denominator part of the expression */
|
||||
/*!*/ virtual Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
/*!*/ virtual Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
|
||||
/* Hierarchy */
|
||||
ExpressionNode * childAtIndex(int i) const override { return static_cast<ExpressionNode *>(TreeNode::childAtIndex(i)); }
|
||||
|
||||
@@ -25,7 +25,7 @@ private:
|
||||
/* Serialization */
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
/* Simplification */
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override;
|
||||
/* Evaluation */
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -41,8 +41,8 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("factor", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Multiplication createMultiplicationOfIntegerPrimeDecomposition(Integer i, Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
Multiplication createMultiplicationOfIntegerPrimeDecomposition(Integer i, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
private:
|
||||
explicit Factor(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<FactorNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
// Properties
|
||||
Type type() const override { return Type::Factorial; }
|
||||
Sign sign(Context * context) const override { return Sign::Positive; }
|
||||
Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
// Complex
|
||||
bool isReal(Context & context) const override { return true; }
|
||||
@@ -32,8 +32,8 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplication
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override;
|
||||
// Evaluation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
@@ -57,8 +57,8 @@ public:
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
constexpr static int k_maxOperandValue = 100;
|
||||
};
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
// Properties
|
||||
Type type() const override { return Type::Float; }
|
||||
Sign sign(Context * context) const override { return m_value < 0 ? Sign::Negative : Sign::Positive; }
|
||||
Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
int simplificationOrderSameType(const ExpressionNode * e, bool canBeInterrupted) const override;
|
||||
|
||||
// Layout
|
||||
|
||||
@@ -30,7 +30,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("floor", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
explicit Floor(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<FloorNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -30,7 +30,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("frac", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
explicit FracPart(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<FracPartNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -38,7 +38,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReplaceReplaceableSymbols(Context & context) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override;
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
|
||||
// Simplification
|
||||
Expression replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression);
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReplaceReplaceableSymbols(Context & context);
|
||||
private:
|
||||
//VariableContext unknownXContext(Context & parentContext) const;
|
||||
|
||||
@@ -27,7 +27,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("gcd", 2, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
GreatCommonDivisor(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<GreatCommonDivisorNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
|
||||
@@ -12,13 +12,13 @@ public:
|
||||
int numberOfChildren() const override { return 1; }
|
||||
private:
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
};
|
||||
|
||||
class HyperbolicTrigonometricFunction : public Expression {
|
||||
public:
|
||||
HyperbolicTrigonometricFunction(const HyperbolicTrigonometricFunctionNode * n) : Expression(n) {}
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit) {
|
||||
return Complex<T>(std::imag(c));
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("im", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit ImaginaryPart(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<ImaginaryPartNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -9,7 +9,7 @@ class InfinityNode final : public NumberNode {
|
||||
public:
|
||||
|
||||
void setNegative(bool negative) { m_negative = negative; }
|
||||
Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(InfinityNode); }
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
Infinity(bool negative) : Number(TreePool::sharedPool()->createTreeNode<InfinityNode>()) {
|
||||
node()->setNegative(negative);
|
||||
}
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit);
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
static const char * Name() {
|
||||
return "inf";
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("int", 4, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
Integral(Expression child0, Expression child1, Expression child2, Expression child3) : Expression(TreePool::sharedPool()->createTreeNode<IntegralNode>()) {
|
||||
assert(child1.type() == ExpressionNode::Type::Symbol);
|
||||
|
||||
@@ -27,7 +27,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
/* Simplification */
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
/* Evaluation */
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("lcm", 2, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
LeastCommonMultiple(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<LeastCommonMultipleNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
|
||||
@@ -27,8 +27,8 @@ public:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override;
|
||||
// Evaluation
|
||||
template<typename U> static Complex<U> computeOnComplex(const std::complex<U> c, Preferences::AngleUnit angleUnit) {
|
||||
/* log has a branch cut on ]-inf, 0]: it is then multivalued on this cut. We
|
||||
@@ -48,17 +48,17 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("log", 2, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
|
||||
private:
|
||||
Logarithm(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<LogarithmNode<2> >()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
}
|
||||
Expression simpleShallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression simpleShallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
Integer simplifyLogarithmIntegerBaseInteger(Integer i, Integer & base, Addition & a, bool isDenominator);
|
||||
Expression splitLogarithmInteger(Integer i, bool isDenominator, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression splitLogarithmInteger(Integer i, bool isDenominator, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
bool parentIsAPowerOfSameBase() const;
|
||||
};
|
||||
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("log", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit CommonLogarithm(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<LogarithmNode<1> >()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
Expression matrixChild(int i, int j) { return childAtIndex(i*numberOfColumns()+j); }
|
||||
|
||||
/* Operation on matrix */
|
||||
int rank(Context & context, Preferences::AngleUnit angleUnit, bool inPlace = false);
|
||||
int rank(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, bool inPlace = false);
|
||||
// Inverse the array in-place. Array has to be given in the form array[row_index][column_index]
|
||||
template<typename T> static int ArrayInverse(T * array, int numberOfRows, int numberOfColumns);
|
||||
#if MATRIX_EXACT_REDUCING
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
Matrix transpose() const;
|
||||
static Matrix createIdentity(int dim);
|
||||
/* createInverse can be called on any matrix reduce or not, approximate or not. */
|
||||
Expression inverse(Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
Expression inverse(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
#endif
|
||||
private:
|
||||
// TODO: find another solution for inverse and determinant (avoid capping the matrix)
|
||||
@@ -98,7 +98,7 @@ private:
|
||||
void setNumberOfRows(int rows) { assert(rows >= 0); node()->setNumberOfRows(rows); }
|
||||
void setNumberOfColumns(int columns) { assert(columns >= 0); node()->setNumberOfColumns(columns); }
|
||||
/* rowCanonize turns a matrix in its reduced row echelon form. */
|
||||
Matrix rowCanonize(Context & context, Preferences::AngleUnit angleUnit, Multiplication m = Multiplication());
|
||||
Matrix rowCanonize(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, Multiplication m = Multiplication());
|
||||
// Row canonize the array in place
|
||||
template<typename T> static void ArrayRowCanonize(T * array, int numberOfRows, int numberOfColumns, T * c = nullptr);
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("dim", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
explicit MatrixDimension(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<MatrixDimensionNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -24,7 +24,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("inverse", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit MatrixInverse(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<MatrixInverseNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -24,7 +24,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("trace", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
explicit MatrixTrace(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<MatrixTraceNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -24,7 +24,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("transpose", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
explicit MatrixTranspose(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<MatrixTransposeNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
|
||||
private:
|
||||
// Property
|
||||
Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
// Layout
|
||||
bool childNeedsParenthesis(const TreeNode * child) const override;
|
||||
@@ -44,9 +44,9 @@ private:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override;
|
||||
Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override;
|
||||
Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override;
|
||||
|
||||
/* Approximation */
|
||||
template<typename T> static MatrixComplex<T> computeOnMatrixAndComplex(const MatrixComplex<T> m, const std::complex<T> c) {
|
||||
@@ -80,21 +80,21 @@ public:
|
||||
|
||||
template<typename T> static void computeOnArrays(T * m, T * n, T * result, int mNumberOfColumns, int mNumberOfRows, int nNumberOfColumns);
|
||||
// Expression
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const;
|
||||
Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
private:
|
||||
// Simplification
|
||||
Expression privateShallowReduce(Context& context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool expand, bool canBeInterrupted);
|
||||
Expression privateShallowReduce(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool expand, bool canBeInterrupted);
|
||||
void mergeMultiplicationChildrenInPlace();
|
||||
void factorizeBase(int i, int j, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
void mergeInChildByFactorizingBase(int i, Expression e, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
void factorizeExponent(int i, int j, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression distributeOnOperandAtIndex(int index, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
void addMissingFactors(Expression factor, Context & context, Preferences::AngleUnit angleUnit);
|
||||
void factorizeSineAndCosine(int i, int j, Context & context, Preferences::AngleUnit angleUnit);
|
||||
void factorizeBase(int i, int j, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
void mergeInChildByFactorizingBase(int i, Expression e, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
void factorizeExponent(int i, int j, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression distributeOnOperandAtIndex(int index, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
void addMissingFactors(Expression factor, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
void factorizeSineAndCosine(int i, int j, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
static bool HaveSameNonNumeralFactors(const Expression & e1, const Expression & e2);
|
||||
static bool TermsHaveIdenticalBase(const Expression & e1, const Expression & e2);
|
||||
static bool TermsHaveIdenticalExponent(const Expression & e1, const Expression & e2);
|
||||
@@ -103,7 +103,7 @@ private:
|
||||
static const Expression CreateExponent(Expression e);
|
||||
/* Warning: mergeNegativePower doesnot always return a multiplication:
|
||||
* *(b^-1,c^-1) -> (bc)^-1 */
|
||||
Expression mergeNegativePower(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression mergeNegativePower(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
static inline const Expression Base(const Expression e);
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
/* Evaluation */
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit) {
|
||||
/* ln has a branch cut on ]-inf, 0]: it is then multivalued on this cut. We
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("ln", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit NaperianLogarithm(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<NaperianLogarithmNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -24,7 +24,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("root", 2, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
NthRoot(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<NthRootNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
/* Number::sign() or Number::setSign does not need a context or an angle unit
|
||||
* (a number can be Infinity, Undefined, Float, Decimal, Rational). */
|
||||
ExpressionNode::Sign sign() { return Expression::sign(nullptr); }
|
||||
Number setSign(ExpressionNode::Sign s) { return Expression::setSign(s, nullptr, Preferences::AngleUnit::Degree, ExpressionNode::ReductionTarget::User).convert<Number>(); }
|
||||
Number setSign(ExpressionNode::Sign s) { return Expression::setSign(s, nullptr, Preferences::ComplexFormat::Real, Preferences::AngleUnit::Degree, ExpressionNode::ReductionTarget::User).convert<Number>(); }
|
||||
protected:
|
||||
Number() : Expression() {}
|
||||
NumberNode * node() const { return static_cast<NumberNode *>(Expression::node()); }
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = 0) const override;
|
||||
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
};
|
||||
|
||||
class Opposite final : public Expression {
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
// Approximation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
replaceChildAtIndexInPlace(0, exp);
|
||||
}
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("permute", 2, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
PermuteCoefficient(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<PermuteCoefficientNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
// Properties
|
||||
Type type() const override { return Type::Power; }
|
||||
Sign sign(Context * context) const override;
|
||||
Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
int polynomialDegree(Context & context, const char * symbolName) const override;
|
||||
int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const override;
|
||||
@@ -45,11 +45,11 @@ private:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
// Simplify
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override;
|
||||
int simplificationOrderGreaterType(const ExpressionNode * e, bool canBeInterrupted) const override;
|
||||
int simplificationOrderSameType(const ExpressionNode * e, bool canBeInterrupted) const override;
|
||||
Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const override;
|
||||
Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override;
|
||||
// Evaluation
|
||||
template<typename T> static MatrixComplex<T> computeOnComplexAndMatrix(const std::complex<T> c, const MatrixComplex<T> n);
|
||||
template<typename T> static MatrixComplex<T> computeOnMatrixAndComplex(const MatrixComplex<T> m, const std::complex<T> d);
|
||||
@@ -68,28 +68,28 @@ class Power final : public Expression {
|
||||
public:
|
||||
Power(Expression base, Expression exponent);
|
||||
Power(const PowerNode * n) : Expression(n) {}
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const;
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
|
||||
private:
|
||||
constexpr static int k_maxExactPowerMatrix = 100;
|
||||
constexpr static int k_maxNumberOfTermsInExpandedMultinome = 25;
|
||||
|
||||
// Simplification
|
||||
Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
|
||||
Expression simplifyPowerPower(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression simplifyPowerMultiplication(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression simplifyRationalRationalPower(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression simplifyPowerPower(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression simplifyPowerMultiplication(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression simplifyRationalRationalPower(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
|
||||
static Expression CreateSimplifiedIntegerRationalPower(Integer i, Rational r, bool isDenominator, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression removeSquareRootsFromDenominator(Context & context, Preferences::AngleUnit angleUnit);
|
||||
static Expression CreateSimplifiedIntegerRationalPower(Integer i, Rational r, bool isDenominator, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression removeSquareRootsFromDenominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
bool parentIsALogarithmOfSameBase() const;
|
||||
bool isNthRootOfUnity() const;
|
||||
Expression equivalentExpressionUsingStandardExpression() const;
|
||||
static Expression CreateComplexExponent(const Expression & r, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); // Returns e^(i*pi*r)
|
||||
static Expression CreateComplexExponent(const Expression & r, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); // Returns e^(i*pi*r)
|
||||
static bool TermIsARationalSquareRootOrRational(const Expression& e);
|
||||
static const Rational RadicandInExpression(const Expression & e);
|
||||
static const Rational RationalFactorInExpression(const Expression & e);
|
||||
|
||||
@@ -27,7 +27,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("prediction95", 2, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
PredictionInterval(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<PredictionIntervalNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
// Properties
|
||||
Type type() const override { return Type::Random; }
|
||||
Sign sign(Context * context) const override { return Sign::Positive; }
|
||||
Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
private:
|
||||
// Layout
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
template<typename T> static T random();
|
||||
private:
|
||||
Random() : Expression(TreePool::sharedPool()->createTreeNode<RandomNode>()) {}
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit);
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -57,10 +57,10 @@ public:
|
||||
static int NaturalOrder(const RationalNode * i, const RationalNode * j);
|
||||
private:
|
||||
int simplificationOrderSameType(const ExpressionNode * e, bool canBeInterrupted) const override;
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override;
|
||||
Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override;
|
||||
Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override;
|
||||
bool m_negative;
|
||||
uint8_t m_numberOfDigitsNumerator;
|
||||
uint8_t m_numberOfDigitsDenominator;
|
||||
@@ -108,15 +108,15 @@ public:
|
||||
static int NaturalOrder(const Rational & i, const Rational & j) { return RationalNode::NaturalOrder(i.node(), j.node()); }
|
||||
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
|
||||
private:
|
||||
Rational(const native_uint_t * i, uint8_t numeratorSize, const native_uint_t * j, uint8_t denominatorSize, bool negative);
|
||||
RationalNode * node() { return static_cast<RationalNode *>(Number::node()); }
|
||||
|
||||
/* Simplification */
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
Expression setSign(ExpressionNode::Sign s);
|
||||
};
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit) {
|
||||
return Complex<T>(std::real(c));
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("re", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit RealPart(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<RealPartNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -28,7 +28,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("round", 2, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
private:
|
||||
Round(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<RoundNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
// Properties
|
||||
Type type() const override { return Type::SignFunction; }
|
||||
Sign sign(Context * context) const override;
|
||||
Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
// Complex
|
||||
bool isReal(Context & context) const override { return true; }
|
||||
@@ -31,7 +31,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("sign", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit SignFunction(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<SignFunctionNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -34,7 +34,7 @@ private:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
// Simplication
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("sin", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit Sine(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<SineNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -27,7 +27,7 @@ private:
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
static_assert('\x91' == Ion::Charset::Root, "Charset error");
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("\x91", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit SquareRoot(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<SquareRootNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -25,8 +25,8 @@ public:
|
||||
|
||||
private:
|
||||
// Simplification
|
||||
void deepReduceChildren(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
void deepReduceChildren(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Layout
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
}
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
/* Simplification */
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
private:
|
||||
/* Evaluation */
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
}
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
/* Simplification */
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReplaceReplaceableSymbols(Context & context) override;
|
||||
|
||||
/* Approximation */
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
static bool isRegressionSymbol(const char * c);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression);
|
||||
Expression replaceUnknown(const Symbol & symbol);
|
||||
int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const;
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
|
||||
// Property
|
||||
Sign sign(Context * context) const override;
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
// TreeNode
|
||||
#if POINCARE_TREE_LOG
|
||||
|
||||
@@ -31,7 +31,7 @@ private:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
// Simplication
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
// Evaluation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit = Preferences::AngleUnit::Radian);
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("tan", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit Tangent(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<TangentNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
|
||||
@@ -17,10 +17,10 @@ public:
|
||||
static bool isInverseTrigonometryFunction(const Expression & e);
|
||||
static bool AreInverseFunctions(const Expression & directFunction, const Expression & inverseFunction);
|
||||
static bool ExpressionIsEquivalentToTangent(const Expression & e);
|
||||
static Expression shallowReduceDirectFunction(Expression & e, Context& context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
static Expression shallowReduceInverseFunction(Expression & e, Context& context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
static Expression shallowReduceDirectFunction(Expression & e, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
static Expression shallowReduceInverseFunction(Expression & e, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
constexpr static int k_numberOfEntries = 37;
|
||||
static Expression table(const Expression e, ExpressionNode::Type type, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); // , Function f, bool inverse
|
||||
static Expression table(const Expression e, ExpressionNode::Type type, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); // , Function f, bool inverse
|
||||
template <typename T> static std::complex<T> ConvertToRadian(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
template <typename T> static std::complex<T> ConvertRadianToAngleUnit(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
template <typename T> static std::complex<T> RoundToMeaningfulDigits(const std::complex<T> result, const std::complex<T> input);
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
// Properties
|
||||
Type type() const override { return Type::Undefined; }
|
||||
int polynomialDegree(Context & context, const char * symbolName) const override;
|
||||
Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
// Approximation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -14,8 +14,8 @@ constexpr Expression::FunctionHelper AbsoluteValue::s_functionHelper;
|
||||
|
||||
int AbsoluteValueNode::numberOfChildren() const { return AbsoluteValue::s_functionHelper.numberOfChildren(); }
|
||||
|
||||
Expression AbsoluteValueNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return AbsoluteValue(this).setSign(s, context, angleUnit);
|
||||
Expression AbsoluteValueNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return AbsoluteValue(this).setSign(s, context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
Layout AbsoluteValueNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
@@ -26,17 +26,17 @@ int AbsoluteValueNode::serialize(char * buffer, int bufferSize, Preferences::Pri
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, AbsoluteValue::s_functionHelper.name());
|
||||
}
|
||||
|
||||
Expression AbsoluteValueNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return AbsoluteValue(this).shallowReduce(context, angleUnit, target);
|
||||
Expression AbsoluteValueNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return AbsoluteValue(this).shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
Expression AbsoluteValue::setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit) {
|
||||
Expression AbsoluteValue::setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
assert(s == ExpressionNode::Sign::Positive);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Expression AbsoluteValue::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression AbsoluteValue::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
@@ -58,17 +58,17 @@ Expression AbsoluteValue::shallowReduce(Context & context, Preferences::AngleUni
|
||||
// abs(a) = -a with a < 0
|
||||
Multiplication m(Rational(-1), c);
|
||||
replaceWithInPlace(m);
|
||||
return m.shallowReduce(context, angleUnit, target);
|
||||
return m.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
}
|
||||
if (c.type() == ExpressionNode::Type::ComplexCartesian) {
|
||||
ComplexCartesian complexChild = static_cast<ComplexCartesian &>(c);
|
||||
Expression childNorm = complexChild.norm(context, angleUnit, target);
|
||||
Expression childNorm = complexChild.norm(context, complexFormat, angleUnit, target);
|
||||
replaceWithInPlace(childNorm);
|
||||
return childNorm.shallowReduce(context, angleUnit, target);
|
||||
return childNorm.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
// abs(-x) = abs(x)
|
||||
c.makePositiveAnyNegativeNumeralFactor(context, angleUnit, target);
|
||||
c.makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, target);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,12 +50,12 @@ int AdditionNode::serialize(char * buffer, int bufferSize, Preferences::PrintFlo
|
||||
|
||||
// Simplication
|
||||
|
||||
Expression AdditionNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Addition(this).shallowReduce(context, angleUnit, target);
|
||||
Expression AdditionNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Addition(this).shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
Expression AdditionNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
return Addition(this).shallowBeautify(context, angleUnit);
|
||||
Expression AdditionNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
return Addition(this).shallowBeautify(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
// Addition
|
||||
@@ -88,7 +88,7 @@ int Addition::getPolynomialCoefficients(Context & context, const char * symbolNa
|
||||
return deg;
|
||||
}
|
||||
|
||||
Expression Addition::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Addition::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
/* Beautifying AdditionNode essentially consists in adding Subtractions if
|
||||
* needed.
|
||||
* In practice, we want to turn "a+(-1)*b" into "a-b". Or, more precisely, any
|
||||
@@ -101,7 +101,7 @@ Expression Addition::shallowBeautify(Context & context, Preferences::AngleUnit a
|
||||
|
||||
for (int i = 0; i < numberOfChildren(); i++) {
|
||||
// Try to make the child i positive if any negative numeral factor is found
|
||||
Expression subtractant = childAtIndex(i).makePositiveAnyNegativeNumeralFactor(context, angleUnit, ExpressionNode::ReductionTarget::User);
|
||||
Expression subtractant = childAtIndex(i).makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User);
|
||||
if (subtractant.isUninitialized())
|
||||
{
|
||||
// if subtractant is not initialized, it means the child i had no negative numeral factor
|
||||
@@ -131,9 +131,9 @@ Expression Addition::shallowBeautify(Context & context, Preferences::AngleUnit a
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression Addition::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression Addition::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
@@ -187,7 +187,7 @@ Expression Addition::shallowReduce(Context & context, Preferences::AngleUnit ang
|
||||
resultMatrix->replaceOperand(resultMatrixEntryJ, a, false);
|
||||
a->addOperand(currentMatrix->childAtIndex(j));
|
||||
a->addOperand(resultMatrixEntryJ);
|
||||
a->shallowReduce(context, angleUnit);
|
||||
a->shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
currentMatrix->detachOperands();
|
||||
removeOperand(currentMatrix, true);
|
||||
@@ -199,9 +199,9 @@ Expression Addition::shallowReduce(Context & context, Preferences::AngleUnit ang
|
||||
Expression * entryI = resultMatrix->childAtIndex(i);
|
||||
resultMatrix->replaceOperand(entryI, a, false);
|
||||
a->addOperand(entryI);
|
||||
a->shallowReduce(context, angleUnit);
|
||||
a->shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
return replaceWith(resultMatrix, true)->shallowReduce(context, angleUnit);
|
||||
return replaceWith(resultMatrix, true)->shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -221,7 +221,7 @@ Expression Addition::shallowReduce(Context & context, Preferences::AngleUnit ang
|
||||
continue;
|
||||
}
|
||||
if (TermsHaveIdenticalNonNumeralFactors(e1, e2)) {
|
||||
factorizeChildrenAtIndexesInPlace(i, i+1, context, angleUnit, target);
|
||||
factorizeChildrenAtIndexesInPlace(i, i+1, context, complexFormat, angleUnit, target);
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
@@ -275,9 +275,9 @@ Expression Addition::shallowReduce(Context & context, Preferences::AngleUnit ang
|
||||
replaceWithInPlace(newComplexCartesian);
|
||||
newComplexCartesian.replaceChildAtIndexInPlace(0, real);
|
||||
newComplexCartesian.replaceChildAtIndexInPlace(1, imag);
|
||||
real.shallowReduce(context, angleUnit, target);
|
||||
imag.shallowReduce(context, angleUnit, target);
|
||||
return newComplexCartesian.shallowReduce(context, angleUnit);
|
||||
real.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
imag.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return newComplexCartesian.shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
/* Step 7: Let's put everything under a common denominator.
|
||||
@@ -286,7 +286,7 @@ Expression Addition::shallowReduce(Context & context, Preferences::AngleUnit ang
|
||||
Expression p = result.parent();
|
||||
if (target == ExpressionNode::ReductionTarget::User && result == *this && (p.isUninitialized() || p.type() != ExpressionNode::Type::Addition)) {
|
||||
// squashUnaryHierarchy didn't do anything: we're not an unary hierarchy
|
||||
result = factorizeOnCommonDenominator(context, angleUnit);
|
||||
result = factorizeOnCommonDenominator(context, complexFormat, angleUnit);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -332,16 +332,16 @@ bool Addition::TermsHaveIdenticalNonNumeralFactors(const Expression & e1, const
|
||||
}
|
||||
}
|
||||
|
||||
Expression Addition::factorizeOnCommonDenominator(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Addition::factorizeOnCommonDenominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
// We want to turn (a/b+c/d+e/b) into (a*d+b*c+e*d)/(b*d)
|
||||
|
||||
// Step 1: We want to compute the common denominator, b*d
|
||||
Multiplication commonDenominator = Multiplication();
|
||||
for (int i = 0; i < numberOfChildren(); i++) {
|
||||
Expression currentDenominator = childAtIndex(i).denominator(context, angleUnit);
|
||||
Expression currentDenominator = childAtIndex(i).denominator(context, complexFormat, angleUnit);
|
||||
if (!currentDenominator.isUninitialized()) {
|
||||
// Make commonDenominator = LeastCommonMultiple(commonDenominator, denominator);
|
||||
commonDenominator.addMissingFactors(currentDenominator, context, angleUnit);
|
||||
commonDenominator.addMissingFactors(currentDenominator, context, complexFormat, angleUnit);
|
||||
}
|
||||
}
|
||||
if (commonDenominator.numberOfChildren() == 0) {
|
||||
@@ -355,7 +355,7 @@ Expression Addition::factorizeOnCommonDenominator(Context & context, Preferences
|
||||
for (int i = 0; i < numberOfChildren(); i++) {
|
||||
Multiplication m = Multiplication(childAtIndex(i), commonDenominator.clone());
|
||||
numerator.addChildAtIndexInPlace(m, numerator.numberOfChildren(), numerator.numberOfChildren());
|
||||
m.privateShallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User, true, false);
|
||||
m.privateShallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User, true, false);
|
||||
}
|
||||
|
||||
// Step 3: Add the denominator
|
||||
@@ -363,18 +363,18 @@ Expression Addition::factorizeOnCommonDenominator(Context & context, Preferences
|
||||
Multiplication result = Multiplication(numerator, inverseDenominator);
|
||||
|
||||
// Step 4: Simplify the numerator
|
||||
numerator.shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User);
|
||||
numerator.shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User);
|
||||
|
||||
// Step 5: Simplify the denominator (in case it's a rational number)
|
||||
inverseDenominator.deepReduce(context, angleUnit, ExpressionNode::ReductionTarget::User);
|
||||
inverseDenominator.deepReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User);
|
||||
|
||||
/* Step 6: We simplify the resulting multiplication forbidding any
|
||||
* distribution of multiplication on additions (to avoid an infinite loop). */
|
||||
replaceWithInPlace(result);
|
||||
return result.privateShallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User, false, true);
|
||||
return result.privateShallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User, false, true);
|
||||
}
|
||||
|
||||
void Addition::factorizeChildrenAtIndexesInPlace(int index1, int index2, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
void Addition::factorizeChildrenAtIndexesInPlace(int index1, int index2, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
/* This function factorizes two children which only differ by a rational
|
||||
* factor. For example, if this is AdditionNode(2*pi, 3*pi), then 2*pi and 3*pi
|
||||
* could be merged, and this turned into AdditionNode(5*pi). */
|
||||
@@ -410,7 +410,7 @@ void Addition::factorizeChildrenAtIndexesInPlace(int index1, int index2, Context
|
||||
}
|
||||
|
||||
// Step 5: Reduce the multiplication (in case the new rational factor is zero)
|
||||
m.shallowReduce(context, angleUnit, target);
|
||||
m.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
template Complex<float> Poincare::AdditionNode::compute<float>(std::complex<float>, std::complex<float>);
|
||||
|
||||
@@ -19,8 +19,8 @@ int ArcCosineNode::serialize(char * buffer, int bufferSize, Preferences::PrintFl
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, ArcCosine::s_functionHelper.name());
|
||||
}
|
||||
|
||||
Expression ArcCosineNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return ArcCosine(this).shallowReduce(context, angleUnit, target);
|
||||
Expression ArcCosineNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return ArcCosine(this).shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -48,9 +48,9 @@ Complex<T> ArcCosineNode::computeOnComplex(const std::complex<T> c, Preferences:
|
||||
return Complex<T>(Trigonometry::ConvertRadianToAngleUnit(result, angleUnit));
|
||||
}
|
||||
|
||||
Expression ArcCosine::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression ArcCosine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
@@ -60,7 +60,7 @@ Expression ArcCosine::shallowReduce(Context & context, Preferences::AngleUnit an
|
||||
return SimplificationHelper::Map(*this, context, angleUnit);
|
||||
}
|
||||
#endif
|
||||
return Trigonometry::shallowReduceInverseFunction(*this, context, angleUnit, target);
|
||||
return Trigonometry::shallowReduceInverseFunction(*this, context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ int ArcSineNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloa
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, ArcSine::s_functionHelper.name());
|
||||
}
|
||||
|
||||
Expression ArcSineNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return ArcSine(this).shallowReduce(context, angleUnit, target);
|
||||
Expression ArcSineNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return ArcSine(this).shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -48,9 +48,9 @@ Complex<T> ArcSineNode::computeOnComplex(const std::complex<T> c, Preferences::A
|
||||
return Complex<T>(Trigonometry::ConvertRadianToAngleUnit(result, angleUnit));
|
||||
}
|
||||
|
||||
Expression ArcSine::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression ArcSine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
@@ -60,7 +60,7 @@ Expression ArcSine::shallowReduce(Context & context, Preferences::AngleUnit angl
|
||||
return SimplificationHelper::Map(*this, context, angleUnit);
|
||||
}
|
||||
#endif
|
||||
return Trigonometry::shallowReduceInverseFunction(*this, context, angleUnit, target);
|
||||
return Trigonometry::shallowReduceInverseFunction(*this, context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,13 +44,13 @@ Complex<T> ArcTangentNode::computeOnComplex(const std::complex<T> c, Preferences
|
||||
return Complex<T>(Trigonometry::ConvertRadianToAngleUnit(result, angleUnit));
|
||||
}
|
||||
|
||||
Expression ArcTangentNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return ArcTangent(this).shallowReduce(context, angleUnit, target);
|
||||
Expression ArcTangentNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return ArcTangent(this).shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
Expression ArcTangent::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression ArcTangent::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
@@ -60,7 +60,7 @@ Expression ArcTangent::shallowReduce(Context & context, Preferences::AngleUnit a
|
||||
return SimplificationHelper::Map(*this, context, angleUnit);
|
||||
}
|
||||
#endif
|
||||
return Trigonometry::shallowReduceInverseFunction(*this, context, angleUnit, target);
|
||||
return Trigonometry::shallowReduceInverseFunction(*this, context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ constexpr Expression::FunctionHelper BinomialCoefficient::s_functionHelper;
|
||||
|
||||
int BinomialCoefficientNode::numberOfChildren() const { return BinomialCoefficient::s_functionHelper.numberOfChildren(); }
|
||||
|
||||
Expression BinomialCoefficientNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return BinomialCoefficient(this).shallowReduce(context, angleUnit);
|
||||
Expression BinomialCoefficientNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return BinomialCoefficient(this).shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
Layout BinomialCoefficientNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
@@ -53,9 +53,9 @@ T BinomialCoefficientNode::compute(T k, T n) {
|
||||
return std::round(result);
|
||||
}
|
||||
|
||||
Expression BinomialCoefficient::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression BinomialCoefficient::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -31,13 +31,13 @@ Complex<T> CeilingNode::computeOnComplex(const std::complex<T> c, Preferences::A
|
||||
return Complex<T>(std::ceil(c.real()));
|
||||
}
|
||||
|
||||
Expression CeilingNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Ceiling(this).shallowReduce(context, angleUnit);
|
||||
Expression CeilingNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Ceiling(this).shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
Expression Ceiling::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Ceiling::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ int ComplexArgumentNode::serialize(char * buffer, int bufferSize, Preferences::P
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, ComplexArgument::s_functionHelper.name());
|
||||
}
|
||||
|
||||
Expression ComplexArgumentNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return ComplexArgument(this).shallowReduce(context, angleUnit, target);
|
||||
Expression ComplexArgumentNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return ComplexArgument(this).shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -33,9 +33,9 @@ Complex<T> ComplexArgumentNode::computeOnComplex(const std::complex<T> c, Prefer
|
||||
return Complex<T>(std::arg(c));
|
||||
}
|
||||
|
||||
Expression ComplexArgument::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression ComplexArgument::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
@@ -63,9 +63,9 @@ Expression ComplexArgument::shallowReduce(Context & context, Preferences::AngleU
|
||||
}
|
||||
if (real || c.type() == ExpressionNode::Type::ComplexCartesian) {
|
||||
ComplexCartesian complexChild = real ? ComplexCartesian::Builder(c, Rational(0)) : static_cast<ComplexCartesian &>(c);
|
||||
Expression childArg = complexChild.argument(context, angleUnit, target);
|
||||
Expression childArg = complexChild.argument(context, complexFormat, angleUnit, target);
|
||||
replaceWithInPlace(childArg);
|
||||
return childArg.shallowReduce(context, angleUnit, target);
|
||||
return childArg.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
Expression ComplexCartesianNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return ComplexCartesian(this).shallowReduce(context, angleUnit);
|
||||
Expression ComplexCartesianNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return ComplexCartesian(this).shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
Expression ComplexCartesianNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
return ComplexCartesian(this).shallowBeautify(context, angleUnit);
|
||||
Expression ComplexCartesianNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
return ComplexCartesian(this).shallowBeautify(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -40,7 +40,7 @@ Complex<T> ComplexCartesianNode::templatedApproximate(Context& context, Preferen
|
||||
return Complex<T>(a.real(), b.real());
|
||||
}
|
||||
|
||||
Expression ComplexCartesian::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression ComplexCartesian::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
if (imag().isRationalZero()) {
|
||||
Expression r = real();
|
||||
replaceWithInPlace(r);
|
||||
@@ -49,11 +49,11 @@ Expression ComplexCartesian::shallowReduce(Context & context, Preferences::Angle
|
||||
return *this;
|
||||
}
|
||||
|
||||
Expression ComplexCartesian::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression ComplexCartesian::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
Expression a = real();
|
||||
Expression b = imag();
|
||||
Expression oppositeA = a.makePositiveAnyNegativeNumeralFactor(context, angleUnit, ExpressionNode::ReductionTarget::User);
|
||||
Expression oppositeB = b.makePositiveAnyNegativeNumeralFactor(context, angleUnit, ExpressionNode::ReductionTarget::User);
|
||||
Expression oppositeA = a.makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User);
|
||||
Expression oppositeB = b.makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User);
|
||||
a = oppositeA.isUninitialized() ? a : oppositeA;
|
||||
b = oppositeB.isUninitialized() ? b : oppositeB;
|
||||
Expression e = Expression::CreateComplexExpression(a, b, Preferences::ComplexFormat::Cartesian,
|
||||
@@ -66,7 +66,7 @@ Expression ComplexCartesian::shallowBeautify(Context & context, Preferences::Ang
|
||||
return e;
|
||||
}
|
||||
|
||||
void ComplexCartesian::factorAndArgumentOfFunction(Expression e, ExpressionNode::Type searchedType, Expression * factor, Expression * argument, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
void ComplexCartesian::factorAndArgumentOfFunction(Expression e, ExpressionNode::Type searchedType, Expression * factor, Expression * argument, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
if (e.type() == searchedType) {
|
||||
*factor = Rational(1);
|
||||
*argument = e.childAtIndex(0);
|
||||
@@ -78,8 +78,8 @@ void ComplexCartesian::factorAndArgumentOfFunction(Expression e, ExpressionNode:
|
||||
*argument = e.childAtIndex(i).childAtIndex(0);
|
||||
*factor = e.clone();
|
||||
static_cast<Multiplication *>(factor)->removeChildAtIndexInPlace(i);
|
||||
*factor = factor->shallowReduce(context, angleUnit, target);
|
||||
Expression positiveFactor = factor->makePositiveAnyNegativeNumeralFactor(context, angleUnit, target);
|
||||
*factor = factor->shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Expression positiveFactor = factor->makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, target);
|
||||
*factor = positiveFactor.isUninitialized() ? *factor : positiveFactor;
|
||||
return;
|
||||
}
|
||||
@@ -87,26 +87,26 @@ void ComplexCartesian::factorAndArgumentOfFunction(Expression e, ExpressionNode:
|
||||
}
|
||||
}
|
||||
|
||||
Expression ComplexCartesian::squareNorm(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression ComplexCartesian::squareNorm(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression a = real();
|
||||
Expression b = imag();
|
||||
Expression aFactor, bFactor, aArgument, bArgument;
|
||||
factorAndArgumentOfFunction(a, ExpressionNode::Type::Cosine, &aFactor, &aArgument, context, angleUnit, target);
|
||||
factorAndArgumentOfFunction(b, ExpressionNode::Type::Sine, &bFactor, &bArgument, context, angleUnit, target);
|
||||
factorAndArgumentOfFunction(a, ExpressionNode::Type::Cosine, &aFactor, &aArgument, context, complexFormat, angleUnit, target);
|
||||
factorAndArgumentOfFunction(b, ExpressionNode::Type::Sine, &bFactor, &bArgument, context, complexFormat, angleUnit, target);
|
||||
if (!aFactor.isUninitialized() && !aArgument.isUninitialized() && !bFactor.isUninitialized() && !bArgument.isUninitialized() && aFactor.isIdenticalTo(bFactor) && aArgument.isIdenticalTo(bArgument)) {
|
||||
Power result(aFactor, Rational(2));
|
||||
aFactor.shallowReduce(context, angleUnit, target);
|
||||
aFactor.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return result;
|
||||
}
|
||||
Expression a2 = Power(a, Rational(2));
|
||||
Expression b2 = Power(b, Rational(2));
|
||||
Addition add(a2, b2);
|
||||
a2.shallowReduce(context, angleUnit, target);
|
||||
b2.shallowReduce(context, angleUnit, target);
|
||||
a2.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
b2.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return add;
|
||||
}
|
||||
|
||||
Expression ComplexCartesian::norm(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression ComplexCartesian::norm(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
if (imag().isRationalZero()) {
|
||||
Expression a = real();
|
||||
ExpressionNode::Sign s = a.sign(&context);
|
||||
@@ -115,16 +115,16 @@ Expression ComplexCartesian::norm(Context & context, Preferences::AngleUnit angl
|
||||
return a;;
|
||||
} else if (s == ExpressionNode::Sign::Negative) {
|
||||
// Case 2: the argument is negative real
|
||||
return a.setSign(ExpressionNode::Sign::Positive, &context, angleUnit, target);
|
||||
return a.setSign(ExpressionNode::Sign::Positive, &context, complexFormat, angleUnit, target);
|
||||
}
|
||||
}
|
||||
Expression n2 = squareNorm(context, angleUnit, target);
|
||||
Expression n2 = squareNorm(context, complexFormat, angleUnit, target);
|
||||
Expression n = SquareRoot::Builder(n2);
|
||||
n2.shallowReduce(context, angleUnit, target);
|
||||
n2.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return n;
|
||||
}
|
||||
|
||||
Expression ComplexCartesian::argument(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression ComplexCartesian::argument(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression a = real();
|
||||
Expression b = imag();
|
||||
if (!b.isRationalZero()) {
|
||||
@@ -132,91 +132,91 @@ Expression ComplexCartesian::argument(Context & context, Preferences::AngleUnit
|
||||
// First, compute arctan(a/b) or (Pi/180)*arctan(a/b)
|
||||
Expression divab = Division(a, b.clone());
|
||||
Expression arcTangent = ArcTangent::Builder(divab);
|
||||
divab.shallowReduce(context, angleUnit, target);
|
||||
divab.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
if (angleUnit == Preferences::AngleUnit::Degree) {
|
||||
Expression temp = arcTangent.degreeToRadian();
|
||||
arcTangent.shallowReduce(context, angleUnit, target);
|
||||
arcTangent.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
arcTangent = temp;
|
||||
}
|
||||
// Then, compute sign(b) * Pi/2 - arctan(a/b)
|
||||
Expression signb = SignFunction::Builder(b);
|
||||
Expression signbPi2 = Multiplication(Rational(1,2), signb, Constant(Ion::Charset::SmallPi));
|
||||
signb.shallowReduce(context, angleUnit, target);
|
||||
signb.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Expression sub = Subtraction(signbPi2, arcTangent);
|
||||
signbPi2.shallowReduce(context, angleUnit, target);
|
||||
arcTangent.shallowReduce(context, angleUnit, target);
|
||||
signbPi2.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
arcTangent.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return sub;
|
||||
} else {
|
||||
// if b == 0, argument = (1-sign(a))*Pi/2
|
||||
Expression signa = SignFunction::Builder(a).shallowReduce(context, angleUnit, target);
|
||||
Expression signa = SignFunction::Builder(a).shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Subtraction sub(Rational(1), signa);
|
||||
signa.shallowReduce(context, angleUnit, target);
|
||||
signa.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Multiplication mul(Rational(1,2), Constant(Ion::Charset::SmallPi), sub);
|
||||
sub.shallowReduce(context, angleUnit, target);
|
||||
sub.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return mul;
|
||||
}
|
||||
}
|
||||
|
||||
ComplexCartesian ComplexCartesian::inverse(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
ComplexCartesian ComplexCartesian::inverse(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression a = real();
|
||||
Expression b = imag();
|
||||
// 1/(a+ib) = a/(a^2+b^2)+i*(-b/(a^2+b^2))
|
||||
Expression denominatorReal = clone().convert<ComplexCartesian>().squareNorm(context, angleUnit, target);
|
||||
Expression denominatorReal = clone().convert<ComplexCartesian>().squareNorm(context, complexFormat, angleUnit, target);
|
||||
Expression denominatorImag = denominatorReal.clone();
|
||||
Expression denominatorRealInv = Power(denominatorReal, Rational(-1));
|
||||
denominatorReal.shallowReduce(context, angleUnit, target);
|
||||
denominatorReal.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Expression denominatorImagInv = Power(denominatorImag, Rational(-1));
|
||||
denominatorImag.shallowReduce(context, angleUnit, target);
|
||||
denominatorImag.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Multiplication A(a, denominatorRealInv);
|
||||
denominatorRealInv.shallowReduce(context, angleUnit, target);
|
||||
denominatorRealInv.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Expression numeratorImag = Multiplication(Rational(-1), b);
|
||||
Multiplication B(numeratorImag, denominatorImagInv);
|
||||
numeratorImag.shallowReduce(context, angleUnit, target);
|
||||
denominatorImagInv.shallowReduce(context, angleUnit, target);
|
||||
numeratorImag.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
denominatorImagInv.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
ComplexCartesian result(A,B);
|
||||
A.shallowReduce(context, angleUnit, target);
|
||||
B.shallowReduce(context, angleUnit, target);
|
||||
A.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
B.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return result.interruptComputationIfManyNodes();
|
||||
}
|
||||
|
||||
Multiplication ComplexCartesian::squareRootHelper(Expression e, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Multiplication ComplexCartesian::squareRootHelper(Expression e, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
//(1/2)*sqrt(2*e)
|
||||
Multiplication doubleE(Rational(2), e);
|
||||
e.shallowReduce(context, angleUnit, target);
|
||||
e.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Expression sqrt = SquareRoot::Builder(doubleE);
|
||||
doubleE.shallowReduce(context, angleUnit, target);
|
||||
doubleE.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Multiplication result(Rational(1,2), sqrt);
|
||||
sqrt.shallowReduce(context, angleUnit, target);
|
||||
sqrt.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return result;
|
||||
}
|
||||
|
||||
ComplexCartesian ComplexCartesian::squareRoot(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
ComplexCartesian ComplexCartesian::squareRoot(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression a = real();
|
||||
Expression b = imag();
|
||||
// A: (1/2)*sqrt(2*(sqrt(a^2+b^2)+a))
|
||||
// B: (1/2)*sqrt(2*(sqrt(a^2+b^2)-a))*sign(b)
|
||||
Expression normA = clone().convert<ComplexCartesian>().norm(context, angleUnit, target);
|
||||
Expression normA = clone().convert<ComplexCartesian>().norm(context, complexFormat, angleUnit, target);
|
||||
Expression normB = normA.clone();
|
||||
// A = (1/2)*sqrt(2*(sqrt(a^2+b^2)+a))
|
||||
Addition normAdda(normA, a.clone());
|
||||
normA.shallowReduce(context, angleUnit, target);
|
||||
Multiplication A = squareRootHelper(normAdda, context, angleUnit, target);
|
||||
normA.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Multiplication A = squareRootHelper(normAdda, context, complexFormat, angleUnit, target);
|
||||
// B = B: (1/2)*sqrt(2*(sqrt(a^2+b^2)-a))
|
||||
Subtraction normSuba(normB, a);
|
||||
normB.shallowReduce(context, angleUnit, target);
|
||||
Multiplication B = squareRootHelper(normSuba, context, angleUnit, target);
|
||||
normB.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Multiplication B = squareRootHelper(normSuba, context, complexFormat, angleUnit, target);
|
||||
// B = B: (1/2)*sqrt(2*(sqrt(a^2+b^2)-a))*sign(b)
|
||||
Expression signb = SignFunction::Builder(b);
|
||||
B.addChildAtIndexInPlace(signb, B.numberOfChildren(), B.numberOfChildren());
|
||||
signb.shallowReduce(context, angleUnit, target);
|
||||
signb.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
ComplexCartesian result = ComplexCartesian::Builder(A, B);
|
||||
A.shallowReduce(context, angleUnit, target);
|
||||
B.shallowReduce(context, angleUnit, target);
|
||||
A.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
B.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return result.interruptComputationIfManyNodes();
|
||||
}
|
||||
|
||||
|
||||
ComplexCartesian ComplexCartesian::powerInteger(int n, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
ComplexCartesian ComplexCartesian::powerInteger(int n, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression a = real();
|
||||
Expression b = imag();
|
||||
assert(n > 0);
|
||||
@@ -229,7 +229,7 @@ ComplexCartesian ComplexCartesian::powerInteger(int n, Context & context, Prefer
|
||||
Expression bpow = Power(b, Rational(n));
|
||||
if (n/2%2 == 1) {
|
||||
Expression temp = Multiplication(Rational(-1), bpow);
|
||||
bpow.shallowReduce(context, angleUnit, target);
|
||||
bpow.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
bpow = temp;
|
||||
}
|
||||
if (n%2 == 0) {
|
||||
@@ -237,7 +237,7 @@ ComplexCartesian ComplexCartesian::powerInteger(int n, Context & context, Prefer
|
||||
} else {
|
||||
result = ComplexCartesian(Rational(0), bpow);
|
||||
}
|
||||
bpow.shallowReduce(context, angleUnit, target);
|
||||
bpow.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return result;
|
||||
}
|
||||
// (a+ib) = a^n+i*b*a^(n-1)+(-1)*b^2*a^(n-2)+(-i)*b^3*a^(n-3)+b^3*a^(n-4)+...
|
||||
@@ -253,9 +253,9 @@ ComplexCartesian ComplexCartesian::powerInteger(int n, Context & context, Prefer
|
||||
Power apow(aclone, Rational(n-i));
|
||||
Power bpow(bclone, Rational(i));
|
||||
Multiplication m(binom, apow, bpow);
|
||||
binom.shallowReduce(context, angleUnit);
|
||||
apow.shallowReduce(context, angleUnit, target);
|
||||
bpow.shallowReduce(context, angleUnit, target);
|
||||
binom.shallowReduce(context, complexFormat, angleUnit);
|
||||
apow.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
bpow.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
if (i/2%2 == 1) {
|
||||
m.addChildAtIndexInPlace(Rational(-1), 0, m.numberOfChildren());
|
||||
}
|
||||
@@ -264,18 +264,18 @@ ComplexCartesian ComplexCartesian::powerInteger(int n, Context & context, Prefer
|
||||
} else {
|
||||
B.addChildAtIndexInPlace(m, B.numberOfChildren(), B.numberOfChildren());
|
||||
}
|
||||
m.shallowReduce(context, angleUnit, target);
|
||||
m.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
result = result.interruptComputationIfManyNodes();
|
||||
if (result.real().isUndefined()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
A.shallowReduce(context, angleUnit, target);
|
||||
B.shallowReduce(context, angleUnit, target);
|
||||
A.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
B.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return result;
|
||||
}
|
||||
|
||||
ComplexCartesian ComplexCartesian::multiply(ComplexCartesian & other, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
ComplexCartesian ComplexCartesian::multiply(ComplexCartesian & other, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression a = real();
|
||||
Expression b = imag();
|
||||
Expression c = other.real();
|
||||
@@ -285,73 +285,73 @@ ComplexCartesian ComplexCartesian::multiply(ComplexCartesian & other, Context &
|
||||
Expression ac = Multiplication(a.clone(), c.clone());
|
||||
Expression bd = Multiplication(b.clone(), d.clone());
|
||||
Subtraction A(ac, bd);
|
||||
ac.shallowReduce(context, angleUnit, target);
|
||||
bd.shallowReduce(context, angleUnit, target);
|
||||
ac.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
bd.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
// Compute ad+bc
|
||||
Expression ad = Multiplication(a, d);
|
||||
Expression bc = Multiplication(b, c);
|
||||
Addition B(ad, bc);
|
||||
ad.shallowReduce(context, angleUnit, target);
|
||||
bc.shallowReduce(context, angleUnit, target);
|
||||
ad.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
bc.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
ComplexCartesian result = ComplexCartesian::Builder(A, B);
|
||||
A.shallowReduce(context, angleUnit, target);
|
||||
B.shallowReduce(context, angleUnit, target);
|
||||
A.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
B.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return result.interruptComputationIfManyNodes();
|
||||
}
|
||||
|
||||
Expression ComplexCartesian::powerHelper(Expression norm, Expression trigo, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression ComplexCartesian::powerHelper(Expression norm, Expression trigo, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Multiplication m(norm, trigo);
|
||||
norm.shallowReduce(context, angleUnit, target);
|
||||
trigo.shallowReduce(context, angleUnit, target);
|
||||
norm.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
trigo.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return m;
|
||||
}
|
||||
|
||||
ComplexCartesian ComplexCartesian::power(ComplexCartesian & other, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression r = clone().convert<ComplexCartesian>().norm(context, angleUnit, target);
|
||||
ComplexCartesian ComplexCartesian::power(ComplexCartesian & other, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression r = clone().convert<ComplexCartesian>().norm(context, complexFormat, angleUnit, target);
|
||||
Expression rclone = r.clone();
|
||||
Expression th = argument(context, angleUnit, target);
|
||||
Expression th = argument(context, complexFormat, angleUnit, target);
|
||||
Expression thclone = th.clone();
|
||||
Expression c = other.real();
|
||||
Expression d = other.imag();
|
||||
// R = r^c*e^(-th*d)
|
||||
Expression rpowc = Power(rclone, c.clone());
|
||||
rclone.shallowReduce(context, angleUnit, target);
|
||||
rclone.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Expression thmuld = Multiplication(Rational(-1), thclone, d.clone());
|
||||
thclone.shallowReduce(context, angleUnit, target);
|
||||
thclone.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Expression exp = Power(Constant(Ion::Charset::Exponential), thmuld);
|
||||
thmuld.shallowReduce(context, angleUnit, target);
|
||||
thmuld.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Multiplication norm(rpowc, exp);
|
||||
rpowc.shallowReduce(context, angleUnit, target);
|
||||
exp.shallowReduce(context, angleUnit, target);
|
||||
rpowc.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
exp.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
|
||||
// TH = d*ln(r)+c*th
|
||||
Expression lnr = NaperianLogarithm::Builder(r);
|
||||
r.shallowReduce(context, angleUnit, target);
|
||||
r.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Multiplication dlnr(d, lnr);
|
||||
lnr.shallowReduce(context, angleUnit, target);
|
||||
lnr.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Multiplication thc(th, c);
|
||||
th.shallowReduce(context, angleUnit, target);
|
||||
th.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Expression argument = Addition(thc, dlnr);
|
||||
thc.shallowReduce(context, angleUnit, target);
|
||||
dlnr.shallowReduce(context, angleUnit, target);
|
||||
thc.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
dlnr.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
|
||||
if (angleUnit == Preferences::AngleUnit::Degree) {
|
||||
Expression temp = argument.radianToDegree();
|
||||
argument.shallowReduce(context, angleUnit, target);
|
||||
argument.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
argument = temp;
|
||||
}
|
||||
// Result = (norm*cos(argument), norm*sin(argument))
|
||||
Expression normClone = norm.clone();
|
||||
Expression argClone = argument.clone();
|
||||
Expression cos = Cosine::Builder(argClone);
|
||||
argClone.shallowReduce(context, angleUnit, target);
|
||||
Expression normcosarg = powerHelper(normClone, cos, context, angleUnit, target);
|
||||
argClone.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Expression normcosarg = powerHelper(normClone, cos, context, complexFormat, angleUnit, target);
|
||||
Expression sin = Sine::Builder(argument);
|
||||
argument.shallowReduce(context, angleUnit, target);
|
||||
Expression normsinarg = powerHelper(norm, sin, context, angleUnit, target);
|
||||
argument.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Expression normsinarg = powerHelper(norm, sin, context, complexFormat, angleUnit, target);
|
||||
ComplexCartesian result = ComplexCartesian::Builder(normcosarg, normsinarg);
|
||||
normcosarg.shallowReduce(context, angleUnit, target);
|
||||
normsinarg.shallowReduce(context, angleUnit, target);
|
||||
normcosarg.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
normsinarg.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return result.interruptComputationIfManyNodes();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ int ConfidenceIntervalNode::serialize(char * buffer, int bufferSize, Preferences
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, ConfidenceInterval::s_functionHelper.name());
|
||||
}
|
||||
|
||||
Expression ConfidenceIntervalNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return ConfidenceInterval(this).shallowReduce(context, angleUnit, target);
|
||||
Expression ConfidenceIntervalNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return ConfidenceInterval(this).shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -52,9 +52,9 @@ int SimplePredictionIntervalNode::serialize(char * buffer, int bufferSize, Prefe
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, SimplePredictionInterval::s_functionHelper.name());
|
||||
}
|
||||
|
||||
Expression ConfidenceInterval::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression ConfidenceInterval::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ Expression ConfidenceInterval::shallowReduce(Context & context, Preferences::Ang
|
||||
matrix.addChildAtIndexInPlace(Addition(r0, sqr), 1, 1);
|
||||
matrix.setDimensions(1, 2);
|
||||
replaceWithInPlace(matrix);
|
||||
matrix.deepReduceChildren(context, angleUnit, target);
|
||||
matrix.deepReduceChildren(context, complexFormat, angleUnit, target);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ int ConjugateNode::serialize(char * buffer, int bufferSize, Preferences::PrintFl
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, Conjugate::s_functionHelper.name());
|
||||
}
|
||||
|
||||
Expression ConjugateNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Conjugate(this).shallowReduce(context, angleUnit, target);
|
||||
Expression ConjugateNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Conjugate(this).shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -32,9 +32,9 @@ Complex<T> ConjugateNode::computeOnComplex(const std::complex<T> c, Preferences:
|
||||
return Complex<T>(std::conj(c));
|
||||
}
|
||||
|
||||
Expression Conjugate::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression Conjugate::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
@@ -53,7 +53,7 @@ Expression Conjugate::shallowReduce(Context & context, Preferences::AngleUnit an
|
||||
ComplexCartesian complexChild = static_cast<ComplexCartesian &>(c);
|
||||
Multiplication m(Rational(-1), complexChild.imag());
|
||||
complexChild.replaceChildAtIndexInPlace(1, m);
|
||||
m.shallowReduce(context, angleUnit, target);
|
||||
m.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
replaceWithInPlace(complexChild);
|
||||
return complexChild;
|
||||
}
|
||||
|
||||
@@ -45,15 +45,15 @@ Evaluation<T> ConstantNode::templatedApproximate(Context& context, Preferences::
|
||||
return Complex<T>(M_E);
|
||||
}
|
||||
|
||||
Expression ConstantNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Constant(this).shallowReduce(context, angleUnit, target);
|
||||
Expression ConstantNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Constant(this).shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
Constant::Constant(char name) : SymbolAbstract(TreePool::sharedPool()->createTreeNode<ConstantNode>(SymbolAbstract::AlignedNodeSize(1, sizeof(ConstantNode)))) {
|
||||
node()->setName(&name, 1);
|
||||
}
|
||||
|
||||
Expression Constant::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression Constant::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
if (target == ExpressionNode::ReductionTarget::User && isIComplex()) {
|
||||
ComplexCartesian c = ComplexCartesian::Builder(Rational(0), Rational(1));
|
||||
replaceWithInPlace(c);
|
||||
|
||||
@@ -30,13 +30,13 @@ int CosineNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloat
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, Cosine::s_functionHelper.name());
|
||||
}
|
||||
|
||||
Expression CosineNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Cosine(this).shallowReduce(context, angleUnit, target);
|
||||
Expression CosineNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Cosine(this).shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
Expression Cosine::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression Cosine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ Expression Cosine::shallowReduce(Context & context, Preferences::AngleUnit angle
|
||||
return SimplificationHelper::Map(*this, context, angleUnit);
|
||||
}
|
||||
#endif
|
||||
return Trigonometry::shallowReduceDirectFunction(*this, context, angleUnit, target);
|
||||
return Trigonometry::shallowReduceDirectFunction(*this, context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ size_t DecimalNode::size() const {
|
||||
return DecimalSize(m_numberOfDigitsInMantissa);
|
||||
}
|
||||
|
||||
Expression DecimalNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
Expression DecimalNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Decimal(this).setSign(s);
|
||||
}
|
||||
|
||||
@@ -85,12 +85,12 @@ int DecimalNode::simplificationOrderSameType(const ExpressionNode * e, bool canB
|
||||
return ((int)Number(this).sign())*unsignedComparison;
|
||||
}
|
||||
|
||||
Expression DecimalNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Decimal(this).shallowReduce(context, angleUnit);
|
||||
Expression DecimalNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Decimal(this).shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
Expression DecimalNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
return Decimal(this).shallowBeautify(context, angleUnit);
|
||||
Expression DecimalNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
return Decimal(this).shallowBeautify(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
Layout DecimalNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
@@ -342,8 +342,8 @@ Expression Decimal::setSign(ExpressionNode::Sign s) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression Decimal::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression Decimal::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
@@ -370,7 +370,7 @@ Expression Decimal::shallowReduce(Context & context, Preferences::AngleUnit angl
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression Decimal::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Decimal::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
if (sign() == ExpressionNode::Sign::Negative) {
|
||||
Expression abs = setSign(ExpressionNode::Sign::Positive);
|
||||
Opposite o;
|
||||
|
||||
@@ -39,8 +39,8 @@ int DerivativeNode::serialize(char * buffer, int bufferSize, Preferences::PrintF
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, Derivative::s_functionHelper.name());
|
||||
}
|
||||
|
||||
Expression DerivativeNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Derivative(this).shallowReduce(context, angleUnit);
|
||||
Expression DerivativeNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Derivative(this).shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -137,9 +137,9 @@ T DerivativeNode::riddersApproximation(Context & context, Preferences::AngleUnit
|
||||
return ans;
|
||||
}
|
||||
|
||||
Expression Derivative::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Derivative::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -28,13 +28,13 @@ Evaluation<T> DeterminantNode::templatedApproximate(Context& context, Preference
|
||||
return Complex<T>(input.determinant());
|
||||
}
|
||||
|
||||
Expression DeterminantNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Determinant(this).shallowReduce(context, angleUnit);
|
||||
Expression DeterminantNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Determinant(this).shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
Expression Determinant::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Determinant::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ int DivisionNode::serialize(char * buffer, int bufferSize, Preferences::PrintFlo
|
||||
return SerializationHelper::Infix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "/");
|
||||
}
|
||||
|
||||
Expression DivisionNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Division(this).shallowReduce(context, angleUnit, target);
|
||||
Expression DivisionNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Division(this).shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
template<typename T> Complex<T> DivisionNode::compute(const std::complex<T> c, const std::complex<T> d) {
|
||||
@@ -72,18 +72,18 @@ template<typename T> MatrixComplex<T> DivisionNode::computeOnMatrices(const Matr
|
||||
|
||||
Division::Division() : Expression(TreePool::sharedPool()->createTreeNode<DivisionNode>()) {}
|
||||
|
||||
Expression Division::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression Division::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
Expression p = Power(childAtIndex(1), Rational(-1));
|
||||
Multiplication m = Multiplication(childAtIndex(0), p);
|
||||
p.shallowReduce(context, angleUnit, target); // Imagine Division(2,1). p would be 1^(-1) which can be simplified
|
||||
p.shallowReduce(context, complexFormat, angleUnit, target); // Imagine Division(2,1). p would be 1^(-1) which can be simplified
|
||||
replaceWithInPlace(m);
|
||||
return m.shallowReduce(context, angleUnit, target);
|
||||
return m.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ constexpr Expression::FunctionHelper DivisionQuotient::s_functionHelper;
|
||||
|
||||
int DivisionQuotientNode::numberOfChildren() const { return DivisionQuotient::s_functionHelper.numberOfChildren(); }
|
||||
|
||||
Expression DivisionQuotientNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return DivisionQuotient(this).shallowReduce(context, angleUnit);
|
||||
Expression DivisionQuotientNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return DivisionQuotient(this).shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
Layout DivisionQuotientNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
@@ -35,9 +35,9 @@ Evaluation<T> DivisionQuotientNode::templatedApproximate(Context& context, Prefe
|
||||
return Complex<T>(std::floor(f1/f2));
|
||||
}
|
||||
|
||||
Expression DivisionQuotient::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression DivisionQuotient::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ int DivisionRemainderNode::serialize(char * buffer, int bufferSize, Preferences:
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, DivisionRemainder::s_functionHelper.name());
|
||||
}
|
||||
|
||||
Expression DivisionRemainderNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return DivisionRemainder(this).shallowReduce(context, angleUnit);
|
||||
Expression DivisionRemainderNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return DivisionRemainder(this).shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -36,9 +36,9 @@ Evaluation<T> DivisionRemainderNode::templatedApproximate(Context& context, Pref
|
||||
return Complex<T>(std::round(f1-f2*std::floor(f1/f2)));
|
||||
}
|
||||
|
||||
Expression DivisionRemainder::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression DivisionRemainder::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ extern "C" {
|
||||
}
|
||||
namespace Poincare {
|
||||
|
||||
Expression EqualNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Equal(this).shallowReduce(context, angleUnit);
|
||||
Expression EqualNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Equal(this).shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
Layout EqualNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
@@ -41,14 +41,14 @@ Evaluation<T> EqualNode::templatedApproximate(Context& context, Preferences::Ang
|
||||
return Complex<T>::Undefined();
|
||||
}
|
||||
|
||||
Expression Equal::standardEquation(Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
Expression Equal::standardEquation(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
|
||||
Expression sub = Subtraction(childAtIndex(0).clone(), childAtIndex(1).clone());
|
||||
return sub.reduce(context, angleUnit);
|
||||
return sub.reduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
Expression Equal::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Equal::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ bool containsVariables(const Expression e, char * variables, int maxVariableSize
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Expression::getLinearCoefficients(char * variables, int maxVariableSize, Expression coefficients[], Expression constant[], Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
bool Expression::getLinearCoefficients(char * variables, int maxVariableSize, Expression coefficients[], Expression constant[], Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
|
||||
assert(!recursivelyMatches(IsMatrix, context, true));
|
||||
// variables is in fact of type char[k_maxNumberOfVariables][maxVariableSize]
|
||||
int index = 0;
|
||||
@@ -162,7 +162,7 @@ bool Expression::getLinearCoefficients(char * variables, int maxVariableSize, Ex
|
||||
index = 0;
|
||||
Expression polynomialCoefficients[k_maxNumberOfPolynomialCoefficients];
|
||||
while (variables[index*maxVariableSize] != 0) {
|
||||
int degree = equation.getPolynomialReducedCoefficients(&variables[index*maxVariableSize], polynomialCoefficients, context, angleUnit);
|
||||
int degree = equation.getPolynomialReducedCoefficients(&variables[index*maxVariableSize], polynomialCoefficients, context, complexFormat, angleUnit);
|
||||
switch (degree) {
|
||||
case 0:
|
||||
coefficients[index] = Rational(0);
|
||||
@@ -183,7 +183,7 @@ bool Expression::getLinearCoefficients(char * variables, int maxVariableSize, Ex
|
||||
equation = polynomialCoefficients[0];
|
||||
index++;
|
||||
}
|
||||
constant[0] = Opposite(equation.clone()).reduce(context, angleUnit);
|
||||
constant[0] = Opposite(equation.clone()).reduce(context, complexFormat, angleUnit);
|
||||
/* The expression can be linear on all coefficients taken one by one but
|
||||
* non-linear (ex: xy = 2). We delete the results and return false if one of
|
||||
* the coefficients contains a variable. */
|
||||
@@ -199,13 +199,13 @@ bool Expression::getLinearCoefficients(char * variables, int maxVariableSize, Ex
|
||||
|
||||
// Private
|
||||
|
||||
void Expression::defaultDeepReduceChildren(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
void Expression::defaultDeepReduceChildren(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
for (int i = 0; i < numberOfChildren(); i++) {
|
||||
childAtIndex(i).deepReduce(context, angleUnit, target);
|
||||
childAtIndex(i).deepReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
}
|
||||
|
||||
Expression Expression::defaultShallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Expression::defaultShallowReduce() {
|
||||
for (int i = 0; i < numberOfChildren(); i++) {
|
||||
if (childAtIndex(i).type() == ExpressionNode::Type::Undefined) {
|
||||
Expression result = Undefined();
|
||||
@@ -246,10 +246,10 @@ Expression Expression::defaultReplaceReplaceableSymbols(Context & context) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Expression Expression::makePositiveAnyNegativeNumeralFactor(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression Expression::makePositiveAnyNegativeNumeralFactor(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
// The expression is a negative number
|
||||
if (isNumber() && sign(&context) == ExpressionNode::Sign::Negative) {
|
||||
return setSign(ExpressionNode::Sign::Positive, &context, angleUnit, target);
|
||||
return setSign(ExpressionNode::Sign::Positive, &context, complexFormat, angleUnit, target);
|
||||
}
|
||||
// The expression is a multiplication whose numeral factor is negative
|
||||
if (type() == ExpressionNode::Type::Multiplication && numberOfChildren() > 0 && childAtIndex(0).isNumber() && childAtIndex(0).sign(&context) == ExpressionNode::Sign::Negative) {
|
||||
@@ -261,7 +261,7 @@ Expression Expression::makePositiveAnyNegativeNumeralFactor(Context & context, P
|
||||
return m.squashUnaryHierarchyInPlace();
|
||||
} else {
|
||||
// Otherwise, we make it positive
|
||||
m.childAtIndex(0).setSign(ExpressionNode::Sign::Positive, &context, angleUnit, target);
|
||||
m.childAtIndex(0).setSign(ExpressionNode::Sign::Positive, &context, complexFormat, angleUnit, target);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
@@ -291,11 +291,11 @@ int Expression::defaultGetPolynomialCoefficients(Context & context, const char *
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Expression::getPolynomialReducedCoefficients(const char * symbolName, Expression coefficients[], Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
int Expression::getPolynomialReducedCoefficients(const char * symbolName, Expression coefficients[], Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
|
||||
// Reset interrupting flag because we use deepReduce
|
||||
int degree = getPolynomialCoefficients(context, symbolName, coefficients);
|
||||
for (int i = 0; i <= degree; i++) {
|
||||
coefficients[i] = coefficients[i].reduce(context, angleUnit);
|
||||
coefficients[i] = coefficients[i].reduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
return degree;
|
||||
}
|
||||
@@ -312,6 +312,22 @@ Expression Expression::defaultReplaceUnknown(const Symbol & symbol) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* Complex */
|
||||
|
||||
Preferences::ComplexFormat Expression::UpdatedComplexFormatWithTextInput(Preferences::ComplexFormat complexFormat, const char * textInput) {
|
||||
if (complexFormat == Preferences::ComplexFormat::Real && strchr(textInput, Ion::Charset::IComplex) != nullptr) {
|
||||
return Preferences::ComplexFormat::Cartesian;
|
||||
}
|
||||
return complexFormat;
|
||||
}
|
||||
|
||||
Preferences::ComplexFormat Expression::UpdatedComplexFormatWithExpressionInput(Preferences::ComplexFormat complexFormat, const Expression & exp, Context & context) {
|
||||
if (complexFormat == Preferences::ComplexFormat::Real && exp.recursivelyMatches([](const Expression e, Context & context, bool replaceSymbols) { return e.type() == ExpressionNode::Type::Constant && static_cast<const Constant &>(e).isIComplex(); }, context, true)) {
|
||||
return Preferences::ComplexFormat::Cartesian;
|
||||
}
|
||||
return complexFormat;
|
||||
}
|
||||
|
||||
/* Comparison */
|
||||
|
||||
bool Expression::isIdenticalTo(const Expression e) const {
|
||||
@@ -320,7 +336,7 @@ bool Expression::isIdenticalTo(const Expression e) const {
|
||||
return ExpressionNode::SimplificationOrder(node(), e.node(), true) == 0;
|
||||
}
|
||||
|
||||
bool Expression::isEqualToItsApproximationLayout(Expression approximation, char * buffer, int bufferSize, Preferences::AngleUnit angleUnit, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, Context & context) {
|
||||
bool Expression::isEqualToItsApproximationLayout(Expression approximation, char * buffer, int bufferSize, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, Context & context) {
|
||||
approximation.serialize(buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits);
|
||||
/* Warning: we cannot use directly the the approximate expression but we have
|
||||
* to re-serialize it because the number of stored significative
|
||||
@@ -328,7 +344,7 @@ bool Expression::isEqualToItsApproximationLayout(Expression approximation, char
|
||||
* identical. (For example, 0.000025 might be displayed "0.00003" and stored
|
||||
* as Decimal(0.000025) and isEqualToItsApproximationLayout should return
|
||||
* false) */
|
||||
Expression approximateOutput = Expression::ParseAndSimplify(buffer, context, angleUnit);
|
||||
Expression approximateOutput = Expression::ParseAndSimplify(buffer, context, complexFormat, angleUnit);
|
||||
bool equal = isIdenticalTo(approximateOutput);
|
||||
return equal;
|
||||
}
|
||||
@@ -343,12 +359,12 @@ int Expression::serialize(char * buffer, int bufferSize, Preferences::PrintFloat
|
||||
|
||||
/* Simplification */
|
||||
|
||||
Expression Expression::ParseAndSimplify(const char * text, Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Expression::ParseAndSimplify(const char * text, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
Expression exp = Parse(text);
|
||||
if (exp.isUninitialized()) {
|
||||
return Undefined();
|
||||
}
|
||||
exp = exp.simplify(context, angleUnit);
|
||||
exp = exp.simplify(context, UpdatedComplexFormatWithTextInput(complexFormat, text), angleUnit);
|
||||
/* simplify might have been interrupted, in which case the resulting
|
||||
* expression is uninitialized, so we need to check that. */
|
||||
if (exp.isUninitialized()) {
|
||||
@@ -357,7 +373,7 @@ Expression Expression::ParseAndSimplify(const char * text, Context & context, Pr
|
||||
return exp;
|
||||
}
|
||||
|
||||
void Expression::ParseAndSimplifyAndApproximate(const char * text, Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) {
|
||||
void Expression::ParseAndSimplifyAndApproximate(const char * text, Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
assert(simplifiedExpression);
|
||||
Expression exp = Parse(text);
|
||||
if (exp.isUninitialized()) {
|
||||
@@ -365,22 +381,22 @@ void Expression::ParseAndSimplifyAndApproximate(const char * text, Expression *
|
||||
*approximateExpression = Undefined();
|
||||
return;
|
||||
}
|
||||
exp.simplifyAndApproximate(simplifiedExpression, approximateExpression, context, angleUnit, complexFormat);
|
||||
exp.simplifyAndApproximate(simplifiedExpression, approximateExpression, context, UpdatedComplexFormatWithTextInput(complexFormat, text), angleUnit);
|
||||
/* simplify might have been interrupted, in which case the resulting
|
||||
* expression is uninitialized, so we need to check that. */
|
||||
if (simplifiedExpression->isUninitialized()) {
|
||||
*simplifiedExpression = Parse(text);
|
||||
if (approximateExpression) {
|
||||
*approximateExpression = simplifiedExpression->approximate<double>(context, angleUnit, complexFormat);
|
||||
*approximateExpression = simplifiedExpression->approximate<double>(context, complexFormat, angleUnit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Expression Expression::simplify(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Expression::simplify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
sSimplificationHasBeenInterrupted = false;
|
||||
Expression e = deepReduce(context, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation);
|
||||
Expression e = deepReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation);
|
||||
if (!sSimplificationHasBeenInterrupted) {
|
||||
e = e.deepBeautify(context, angleUnit);
|
||||
e = e.deepBeautify(context, complexFormat, angleUnit);
|
||||
}
|
||||
return sSimplificationHasBeenInterrupted ? Expression() : e;
|
||||
}
|
||||
@@ -392,14 +408,14 @@ void makePositive(Expression * e, bool * isNegative) {
|
||||
}
|
||||
}
|
||||
|
||||
void Expression::simplifyAndApproximate(Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) {
|
||||
void Expression::simplifyAndApproximate(Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
assert(simplifiedExpression);
|
||||
sSimplificationHasBeenInterrupted = false;
|
||||
// Step 1: we reduce the expression
|
||||
Expression e = clone().deepReduce(context, angleUnit, ExpressionNode::ReductionTarget::User);
|
||||
Expression e = clone().deepReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User);
|
||||
if (sSimplificationHasBeenInterrupted) {
|
||||
sSimplificationHasBeenInterrupted = false;
|
||||
e = deepReduce(context, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation);
|
||||
e = deepReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation);
|
||||
}
|
||||
*simplifiedExpression = Expression();
|
||||
if (!sSimplificationHasBeenInterrupted) {
|
||||
@@ -418,15 +434,15 @@ void Expression::simplifyAndApproximate(Expression * simplifiedExpression, Expre
|
||||
// Clone the ComplexCartesian to use it to compute the approximation
|
||||
ComplexCartesian ecomplexClone = ecomplex.clone().convert<ComplexCartesian>();
|
||||
// To minimize the error on the approximation, we reduce the number of nodes in the expression by beautifying
|
||||
ecomplexClone.real().deepBeautify(context, angleUnit);
|
||||
ecomplexClone.imag().deepBeautify(context, angleUnit);
|
||||
*approximateExpression = ecomplexClone.approximate<double>(context, angleUnit, complexFormat);
|
||||
ecomplexClone.real().deepBeautify(context, complexFormat, angleUnit);
|
||||
ecomplexClone.imag().deepBeautify(context, complexFormat, angleUnit);
|
||||
*approximateExpression = ecomplexClone.approximate<double>(context, complexFormat, angleUnit);
|
||||
}
|
||||
// Step 3: create the simplied expression with the required complex format
|
||||
Expression ra = complexFormat == Preferences::ComplexFormat::Polar ? ecomplex.clone().convert<ComplexCartesian>().norm(context, angleUnit, ExpressionNode::ReductionTarget::User).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User) : ecomplex.real();
|
||||
Expression tb = complexFormat == Preferences::ComplexFormat::Polar ? ecomplex.argument(context, angleUnit, ExpressionNode::ReductionTarget::User).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User) : ecomplex.imag();
|
||||
ra = ra.deepBeautify(context, angleUnit);
|
||||
tb = tb.deepBeautify(context, angleUnit);
|
||||
Expression ra = complexFormat == Preferences::ComplexFormat::Polar ? ecomplex.clone().convert<ComplexCartesian>().norm(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User).shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User) : ecomplex.real();
|
||||
Expression tb = complexFormat == Preferences::ComplexFormat::Polar ? ecomplex.argument(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User).shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User) : ecomplex.imag();
|
||||
ra = ra.deepBeautify(context, complexFormat, angleUnit);
|
||||
tb = tb.deepBeautify(context, complexFormat, angleUnit);
|
||||
bool raIsNegative = false;
|
||||
bool tbIsNegative = false;
|
||||
makePositive(&ra, &raIsNegative);
|
||||
@@ -435,9 +451,9 @@ void Expression::simplifyAndApproximate(Expression * simplifiedExpression, Expre
|
||||
} else {
|
||||
/* Case 2: The reduced expression has a complex component that could not
|
||||
* be bubbled up. */
|
||||
*simplifiedExpression = e.deepBeautify(context, angleUnit);
|
||||
*simplifiedExpression = e.deepBeautify(context, complexFormat, angleUnit);
|
||||
if (approximateExpression) {
|
||||
*approximateExpression = simplifiedExpression->approximate<double>(context, angleUnit, complexFormat);
|
||||
*approximateExpression = simplifiedExpression->approximate<double>(context, complexFormat, angleUnit);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -484,12 +500,12 @@ Expression Expression::degreeToRadian() {
|
||||
return Multiplication(*this, Rational(1, 180), Constant(Ion::Charset::SmallPi));
|
||||
}
|
||||
|
||||
Expression Expression::reduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Expression::reduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
sSimplificationHasBeenInterrupted = false;
|
||||
return deepReduce(context, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation);
|
||||
return deepReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation);
|
||||
}
|
||||
|
||||
Expression Expression::deepReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression Expression::deepReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
#if MATRIX_EXACT_REDUCING
|
||||
#else
|
||||
if (IsMatrix(*this, context, true)) {
|
||||
@@ -498,30 +514,30 @@ Expression Expression::deepReduce(Context & context, Preferences::AngleUnit angl
|
||||
}
|
||||
#endif
|
||||
|
||||
deepReduceChildren(context, angleUnit, target);
|
||||
deepReduceChildren(context, complexFormat, angleUnit, target);
|
||||
if (sSimplificationHasBeenInterrupted) {
|
||||
return *this;
|
||||
}
|
||||
return shallowReduce(context, angleUnit, target);
|
||||
return shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
Expression Expression::deepBeautify(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression e = shallowBeautify(context, angleUnit);
|
||||
Expression Expression::deepBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
Expression e = shallowBeautify(context, complexFormat, angleUnit);
|
||||
int nbChildren = e.numberOfChildren();
|
||||
for (int i = 0; i < nbChildren; i++) {
|
||||
e.childAtIndex(i).deepBeautify(context, angleUnit);
|
||||
e.childAtIndex(i).deepBeautify(context, complexFormat, angleUnit);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
Expression Expression::setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
return node()->setSign(s, context, angleUnit, target);
|
||||
Expression Expression::setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
return node()->setSign(s, context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
/* Evaluation */
|
||||
|
||||
template<typename U>
|
||||
Expression Expression::approximate(Context& context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) const {
|
||||
Expression Expression::approximate(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
|
||||
return isUninitialized() ? Undefined() : approximateToEvaluation<U>(context, angleUnit).complexToExpression(complexFormat);
|
||||
}
|
||||
|
||||
@@ -532,11 +548,9 @@ U Expression::approximateToScalar(Context& context, Preferences::AngleUnit angle
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
U Expression::approximateToScalar(const char * text, Context& context, Preferences::AngleUnit angleUnit) {
|
||||
Expression exp = ParseAndSimplify(text, context, angleUnit);
|
||||
if (exp.isUninitialized()) {
|
||||
return NAN;
|
||||
}
|
||||
U Expression::approximateToScalar(const char * text, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
Expression exp = ParseAndSimplify(text, context, UpdatedComplexFormatWithTextInput(complexFormat, text), angleUnit);
|
||||
assert(!exp.isUninitialized());
|
||||
return exp.approximateToScalar<U>(context, angleUnit);
|
||||
}
|
||||
|
||||
@@ -958,14 +972,14 @@ double Expression::brentRoot(const char * symbol, double ax, double bx, double p
|
||||
template float Expression::epsilon<float>();
|
||||
template double Expression::epsilon<double>();
|
||||
|
||||
template Expression Expression::approximate<float>(Context& context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) const;
|
||||
template Expression Expression::approximate<double>(Context& context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) const;
|
||||
template Expression Expression::approximate<float>(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
template Expression Expression::approximate<double>(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
|
||||
template float Expression::approximateToScalar(Context& context, Preferences::AngleUnit angleUnit) const;
|
||||
template double Expression::approximateToScalar(Context& context, Preferences::AngleUnit angleUnit) const;
|
||||
|
||||
template float Expression::approximateToScalar<float>(const char * text, Context& context, Preferences::AngleUnit angleUnit);
|
||||
template double Expression::approximateToScalar<double>(const char * text, Context& context, Preferences::AngleUnit angleUnit);
|
||||
template float Expression::approximateToScalar<float>(const char * text, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
template double Expression::approximateToScalar<double>(const char * text, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
|
||||
template Evaluation<float> Expression::approximateToEvaluation(Context& context, Preferences::AngleUnit angleUnit) const;
|
||||
template Evaluation<double> Expression::approximateToEvaluation(Context& context, Preferences::AngleUnit angleUnit) const;
|
||||
|
||||
@@ -22,7 +22,7 @@ Expression ExpressionNode::replaceUnknown(const Symbol & symbol) {
|
||||
return Expression(this).defaultReplaceUnknown(symbol);
|
||||
}
|
||||
|
||||
Expression ExpressionNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
Expression ExpressionNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
assert(false);
|
||||
return Expression();
|
||||
}
|
||||
@@ -108,16 +108,16 @@ int ExpressionNode::simplificationOrderSameType(const ExpressionNode * e, bool c
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ExpressionNode::deepReduceChildren(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression(this).defaultDeepReduceChildren(context, angleUnit, target);
|
||||
void ExpressionNode::deepReduceChildren(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression(this).defaultDeepReduceChildren(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
Expression ExpressionNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Expression(this).defaultShallowReduce(context, angleUnit);
|
||||
Expression ExpressionNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Expression(this).defaultShallowReduce();
|
||||
}
|
||||
|
||||
Expression ExpressionNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
return Expression(this).defaultShallowBeautify(context, angleUnit);
|
||||
Expression ExpressionNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
return Expression(this).defaultShallowBeautify();
|
||||
}
|
||||
|
||||
bool ExpressionNode::isOfType(Type * types, int length) const {
|
||||
@@ -133,7 +133,7 @@ void ExpressionNode::setChildrenInPlace(Expression other) {
|
||||
Expression(this).defaultSetChildrenInPlace(other);
|
||||
}
|
||||
|
||||
Expression ExpressionNode::denominator(Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
Expression ExpressionNode::denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
|
||||
return Expression();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@ int FactorNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloat
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, Factor::s_functionHelper.name());
|
||||
}
|
||||
|
||||
Expression FactorNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
return Factor(this).shallowBeautify(context, angleUnit);
|
||||
Expression FactorNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
return Factor(this).shallowBeautify(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
Expression Factor::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Factor::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
Expression c = childAtIndex(0);
|
||||
if (c.type() != ExpressionNode::Type::Rational) {
|
||||
Expression result = Undefined();
|
||||
@@ -42,7 +42,7 @@ Expression Factor::shallowBeautify(Context & context, Preferences::AngleUnit ang
|
||||
replaceWithInPlace(r);
|
||||
return r;
|
||||
}
|
||||
Multiplication numeratorDecomp = createMultiplicationOfIntegerPrimeDecomposition(r.unsignedIntegerNumerator(), context, angleUnit);
|
||||
Multiplication numeratorDecomp = createMultiplicationOfIntegerPrimeDecomposition(r.unsignedIntegerNumerator(), context, complexFormat, angleUnit);
|
||||
if (numeratorDecomp.numberOfChildren() == 0) {
|
||||
Expression result = Undefined();
|
||||
replaceWithInPlace(result);
|
||||
@@ -50,7 +50,7 @@ Expression Factor::shallowBeautify(Context & context, Preferences::AngleUnit ang
|
||||
}
|
||||
Expression result = numeratorDecomp.squashUnaryHierarchyInPlace();
|
||||
if (!r.integerDenominator().isOne()) {
|
||||
Multiplication denominatorDecomp = createMultiplicationOfIntegerPrimeDecomposition(r.integerDenominator(), context, angleUnit);
|
||||
Multiplication denominatorDecomp = createMultiplicationOfIntegerPrimeDecomposition(r.integerDenominator(), context, complexFormat, angleUnit);
|
||||
if (denominatorDecomp.numberOfChildren() == 0) {
|
||||
Expression result = Undefined();
|
||||
replaceWithInPlace(result);
|
||||
@@ -65,7 +65,7 @@ Expression Factor::shallowBeautify(Context & context, Preferences::AngleUnit ang
|
||||
return result;
|
||||
}
|
||||
|
||||
Multiplication Factor::createMultiplicationOfIntegerPrimeDecomposition(Integer i, Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
Multiplication Factor::createMultiplicationOfIntegerPrimeDecomposition(Integer i, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
|
||||
assert(!i.isZero());
|
||||
assert(!i.isNegative());
|
||||
Multiplication m;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Poincare {
|
||||
|
||||
// Property
|
||||
|
||||
Expression FactorialNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
Expression FactorialNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
assert(s == Sign::Positive);
|
||||
return Factorial(this);
|
||||
}
|
||||
@@ -34,12 +34,12 @@ bool FactorialNode::childNeedsParenthesis(const TreeNode * child) const {
|
||||
|
||||
// Simplification
|
||||
|
||||
Expression FactorialNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Factorial(this).shallowReduce(context, angleUnit);
|
||||
Expression FactorialNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Factorial(this).shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
Expression FactorialNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
return Factorial(this).shallowBeautify(context, angleUnit);
|
||||
Expression FactorialNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
return Factorial(this).shallowBeautify(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -91,9 +91,9 @@ int FactorialNode::serialize(char * buffer, int bufferSize, Preferences::PrintFl
|
||||
|
||||
Factorial::Factorial() : Expression(TreePool::sharedPool()->createTreeNode<FactorialNode>()) {}
|
||||
|
||||
Expression Factorial::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Factorial::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ Expression Factorial::shallowReduce(Context & context, Preferences::AngleUnit an
|
||||
return *this;
|
||||
}
|
||||
|
||||
Expression Factorial::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Factorial::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
// +(a,b)! ->(+(a,b))!
|
||||
if (childAtIndex(0).type() == ExpressionNode::Type::Addition
|
||||
|| childAtIndex(0).type() == ExpressionNode::Type::Multiplication
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
namespace Poincare {
|
||||
|
||||
template<typename T>
|
||||
Expression FloatNode<T>::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
Expression FloatNode<T>::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
assert(s != Sign::Unknown);
|
||||
Sign currentSign = m_value < 0 ? Sign::Negative : Sign::Positive;
|
||||
Expression thisExpr = Number(this);
|
||||
|
||||
@@ -31,13 +31,13 @@ Complex<T> FloorNode::computeOnComplex(const std::complex<T> c, Preferences::Ang
|
||||
return Complex<T>(std::floor(c.real()));
|
||||
}
|
||||
|
||||
Expression FloorNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Floor(this).shallowReduce(context, angleUnit);
|
||||
Expression FloorNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Floor(this).shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
Expression Floor::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Floor::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ int FracPartNode::serialize(char * buffer, int bufferSize, Preferences::PrintFlo
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, FracPart::s_functionHelper.name());
|
||||
}
|
||||
|
||||
Expression FracPartNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return FracPart(this).shallowReduce(context, angleUnit);
|
||||
Expression FracPartNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return FracPart(this).shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -31,9 +31,9 @@ Complex<T> FracPartNode::computeOnComplex(const std::complex<T> c, Preferences::
|
||||
return Complex<T>(c.real()-std::floor(c.real()));
|
||||
}
|
||||
|
||||
Expression FracPart::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression FracPart::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -62,8 +62,8 @@ int FunctionNode::serialize(char * buffer, int bufferSize, Preferences::PrintFlo
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name());
|
||||
}
|
||||
|
||||
Expression FunctionNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Function(this).shallowReduce(context, angleUnit, target); // This uses Symbol::shallowReduce
|
||||
Expression FunctionNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Function(this).shallowReduce(context, complexFormat, angleUnit, target); // This uses Symbol::shallowReduce
|
||||
}
|
||||
|
||||
Expression FunctionNode::shallowReplaceReplaceableSymbols(Context & context) {
|
||||
@@ -113,12 +113,12 @@ Expression Function::replaceSymbolWithExpression(const SymbolAbstract & symbol,
|
||||
return *this;
|
||||
}
|
||||
|
||||
Expression Function::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression Function::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Function f(*this);
|
||||
Expression e = SymbolAbstract::Expand(f, context, true);
|
||||
if (!e.isUninitialized()) {
|
||||
replaceWithInPlace(e);
|
||||
return e.deepReduce(context, angleUnit, target);
|
||||
return e.deepReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ int GreatCommonDivisorNode::serialize(char * buffer, int bufferSize, Preferences
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, GreatCommonDivisor::s_functionHelper.name());
|
||||
}
|
||||
|
||||
Expression GreatCommonDivisorNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return GreatCommonDivisor(this).shallowReduce(context, angleUnit);
|
||||
Expression GreatCommonDivisorNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return GreatCommonDivisor(this).shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -48,9 +48,9 @@ Evaluation<T> GreatCommonDivisorNode::templatedApproximate(Context& context, Pre
|
||||
return Complex<T>(std::round((T)a));
|
||||
}
|
||||
|
||||
Expression GreatCommonDivisor::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression GreatCommonDivisor::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
Expression HyperbolicTrigonometricFunctionNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return HyperbolicTrigonometricFunction(this).shallowReduce(context, angleUnit);
|
||||
Expression HyperbolicTrigonometricFunctionNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return HyperbolicTrigonometricFunction(this).shallowReduce(context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
Expression HyperbolicTrigonometricFunction::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression HyperbolicTrigonometricFunction::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ int ImaginaryPartNode::serialize(char * buffer, int bufferSize, Preferences::Pri
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, ImaginaryPart::s_functionHelper.name());
|
||||
}
|
||||
|
||||
Expression ImaginaryPartNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return ImaginaryPart(this).shallowReduce(context, angleUnit, target);
|
||||
Expression ImaginaryPartNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return ImaginaryPart(this).shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
Expression ImaginaryPart::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
Expression ImaginaryPart::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
@@ -46,7 +46,7 @@ Expression ImaginaryPart::shallowReduce(Context & context, Preferences::AngleUni
|
||||
ComplexCartesian complexChild = static_cast<ComplexCartesian &>(c);
|
||||
Expression i = complexChild.imag();
|
||||
replaceWithInPlace(i);
|
||||
return i.shallowReduce(context, angleUnit, target);
|
||||
return i.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ extern "C" {
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
Expression InfinityNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Infinity(this).setSign(s, context, angleUnit);
|
||||
Expression InfinityNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) {
|
||||
return Infinity(this).setSign(s, context, complexFormat, angleUnit);
|
||||
}
|
||||
|
||||
Layout InfinityNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
@@ -30,7 +30,7 @@ template<typename T> Evaluation<T> InfinityNode::templatedApproximate() const {
|
||||
return Complex<T>(m_negative ? -INFINITY : INFINITY);
|
||||
}
|
||||
|
||||
Expression Infinity::setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit) {
|
||||
Expression Infinity::setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
Expression result = Infinity(s == ExpressionNode::Sign::Negative);
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user