[poincare] Clean: remove complexCartesian and complexPolar methods

This commit is contained in:
Émilie Feral
2018-12-17 11:38:53 +01:00
committed by Léa Saviot
parent 4a7a95fddf
commit 8a00aa16cc
71 changed files with 8 additions and 728 deletions

View File

@@ -50,7 +50,6 @@ objs += $(addprefix poincare/src/,\
complex.o\
complex_argument.o\
complex_cartesian.o\
complex_helper.o\
confidence_interval.o\
conjugate.o\
constant.o\

View File

@@ -4,7 +4,6 @@
#include <poincare/expression.h>
#include <poincare/rational.h>
#include <poincare/approximation_helper.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -25,7 +24,6 @@ public:
Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit) override;
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
// Approximation

View File

@@ -27,9 +27,6 @@ public:
int polynomialDegree(Context & context, const char * symbolName) const override;
int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const override;
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override;
// Evaluation
template<typename T> static Complex<T> compute(const std::complex<T> c, const std::complex<T> d) { return Complex<T>(c+d); }
template<typename T> static MatrixComplex<T> computeOnMatrices(const MatrixComplex<T> m, const MatrixComplex<T> n) {

View File

@@ -2,7 +2,6 @@
#define POINCARE_ARC_TANGENT_H
#include <poincare/approximation_helper.h>
#include <poincare/complex_helper.h>
#include <poincare/expression.h>
#include <poincare/trigonometry.h>
@@ -24,7 +23,6 @@ public:
Type type() const override { return Type::ArcTangent; }
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianComplexFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return childAtIndex(0)->isReal(context, angleUnit); }
private:

View File

@@ -3,7 +3,6 @@
#include <poincare/approximation_helper.h>
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -20,7 +19,6 @@ public:
#endif
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
// Properties

View File

@@ -3,7 +3,6 @@
#include <poincare/approximation_helper.h>
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -20,7 +19,6 @@ public:
#endif
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
// Properties

View File

@@ -3,7 +3,6 @@
#include <poincare/approximation_helper.h>
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -19,7 +18,6 @@ public:
}
#endif
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
// Properties

View File

@@ -1,24 +0,0 @@
#ifndef POINCARE_COMPLEX_HELPER_H
#define POINCARE_COMPLEX_HELPER_H
#include <poincare/expression.h>
#include <poincare/complex_cartesian.h>
#include <poincare/complex_polar.h>
namespace Poincare {
class ComplexHelper {
public:
static ComplexCartesian complexCartesianComplexFunction(const ExpressionNode * e, Context & context, Preferences::AngleUnit angleUnit);
static ComplexCartesian complexCartesianRealFunction(const ExpressionNode * e, Context & context, Preferences::AngleUnit angleUnit);
// static Expression realPartMatrix(const Expression e, Context & context, Preferences::AngleUnit angleUnit);
static ComplexCartesian complexCartesianFromComplexPolar(const ExpressionNode * node, Context & context, Preferences::AngleUnit angleUnit);
static ComplexPolar complexPolarFromComplexCartesian(const ExpressionNode * node, Context & context, Preferences::AngleUnit angleUnit);
static Expression complexSquareNormComplexCartesian(Expression real, Expression imag, Context & context, Preferences::AngleUnit angleUnit);
private:
static Expression complexCartesianFromComplexPolarHelper(Expression norm, Expression trigo, Context & context, Preferences::AngleUnit angleUnit);
};
}
#endif

View File

@@ -1,47 +0,0 @@
#ifndef POINCARE_COMPLEX_POLAR_H
#define POINCARE_COMPLEX_POLAR_H
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
class ComplexPolarNode : public ExpressionNode {
public:
// TreeNode
size_t size() const override { return sizeof(ComplexPolarNode); }
int numberOfChildren() const override { return 2; }
#if POINCARE_TREE_LOG
virtual void logNodeName(std::ostream & stream) const override {
stream << "ComplexPolar";
}
#endif
// Properties
Type type() const override { return Type::ComplexPolar; }
private:
// Layout
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { assert(false); return Layout(); }
// Evaluation
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { assert(false); return Evaluation<float>(); }
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { assert(false); return Evaluation<double>(); }
};
class ComplexPolar final : public Expression {
public:
ComplexPolar() : Expression() {}
static ComplexPolar Builder(Expression child0, Expression child1) { return ComplexPolar(child0, child1); }
Expression norm() { return childAtIndex(0); }
Expression arg() { return childAtIndex(1); }
private:
ComplexPolar(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<ComplexPolarNode>()) {
replaceChildAtIndexInPlace(0, child0);
replaceChildAtIndexInPlace(1, child1);
}
};
}
#endif

View File

@@ -2,7 +2,6 @@
#define POINCARE_CONFIDENCE_INTERVAL_H
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -20,9 +19,6 @@ public:
// ExpressionNode
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
// Properties
Type type() const override { return Type::ConfidenceInterval; }
int polynomialDegree(Context & context, const char * symbolName) const override { return -1; }

View File

@@ -19,8 +19,6 @@ public:
#endif
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return childAtIndex(0)->isReal(context, angleUnit); }
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override;
ComplexPolar complexPolar(Context & context, Preferences::AngleUnit angleUnit) const override;
// Properties
Type type() const override { return Type::Conjugate; }

View File

@@ -19,7 +19,6 @@ public:
// Complex
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override;
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override;
// Expression Properties
Type type() const override { return Type::Constant; }

View File

@@ -2,7 +2,6 @@
#define POINCARE_COSINE_H
#include <poincare/approximation_helper.h>
#include <poincare/complex_helper.h>
#include <poincare/expression.h>
#include <poincare/trigonometry.h>
@@ -21,7 +20,6 @@ public:
#endif
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianComplexFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return childAtIndex(0)->isReal(context, angleUnit); }
// Properties

View File

@@ -3,7 +3,6 @@
#include <poincare/integer.h>
#include <poincare/number.h>
#include <poincare/complex_helper.h>
namespace Poincare {

View File

@@ -2,7 +2,6 @@
#define POINCARE_DERIVATIVE_H
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
#include <poincare/symbol.h>
#include <poincare/variable_context.h>
@@ -21,7 +20,6 @@ public:
#endif
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
// Properties

View File

@@ -22,14 +22,6 @@ public:
}
#endif
/* Property */
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override;
/* If we use the formula arg(a/b) = arg(a)-arg(b), we are likely to end up
* with subtractions of arcTangent. To avoid that, we compute the argument(a/b)
* from the real and imaginary part of a/b.
* TODO: What about norm(a/b)? */
//ComplexPolar complexPolar(Context & context, Preferences::AngleUnit angleUnit) const override;
// Properties
Type type() const override { return Type::Division; }
int polynomialDegree(Context & context, const char * symbolName) const override;

View File

@@ -2,7 +2,6 @@
#define POINCARE_DIVISION_QUOTIENT_H
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -22,7 +21,6 @@ public:
Type type() const override { return Type::DivisionQuotient; }
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
private:

View File

@@ -2,7 +2,6 @@
#define POINCARE_DIVISION_REMAINDER_H
#include <poincare/approximation_helper.h>
#include <poincare/complex_helper.h>
#include <poincare/expression.h>
namespace Poincare {
@@ -23,7 +22,6 @@ public:
Type type() const override { return Type::DivisionRemainder; }
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
private:

View File

@@ -168,9 +168,6 @@ public:
/* Complex */
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const { return node()->isReal(context, angleUnit); }
bool isPureReal(Context & context, Preferences::AngleUnit angleUnit) const;
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const;
ComplexPolar complexPolar(Context & context, Preferences::AngleUnit angleUnit) const;
/* Comparison */
/* isIdenticalTo is the "easy" equality, it returns true if both trees have

View File

@@ -130,8 +130,6 @@ public:
* scan of the tree in ParseAndSimplifyForComplexFormat instead of Simplifying
* and then extracting ComplexCartesian. */
virtual bool isReal(Context & context, Preferences::AngleUnit angleUnit) const { return false; }
virtual ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const;
virtual ComplexPolar complexPolar(Context & context, Preferences::AngleUnit angleUnit) const;
/* Simplification */
/* SimplificationOrder returns:

View File

@@ -3,7 +3,6 @@
#include <poincare/approximation_helper.h>
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -25,7 +24,6 @@ public:
Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit) override;
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
private:

View File

@@ -3,7 +3,6 @@
#include <poincare/approximation_helper.h>
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -24,7 +23,6 @@ public:
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
private:

View File

@@ -3,7 +3,6 @@
#include <poincare/approximation_helper.h>
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -24,7 +23,6 @@ public:
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
private:

View File

@@ -29,8 +29,6 @@ public:
// Complex
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override;
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override;
ComplexPolar complexPolar(Context & context, Preferences::AngleUnit angleUnit) const override;
private:
char m_name[0]; // MUST be the last member variable

View File

@@ -2,7 +2,6 @@
#define POINCARE_GREAT_COMMON_DIVISOR_H
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -21,7 +20,6 @@ public:
// ExpressionNode
Type type() const override { return Type::GreatCommonDivisor; }
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
private:

View File

@@ -2,7 +2,6 @@
#define POINCARE_IMAGINARY_PART_H
#include <poincare/approximation_helper.h>
#include <poincare/complex_helper.h>
#include <poincare/expression.h>
namespace Poincare {
@@ -23,7 +22,6 @@ public:
Type type() const override { return Type::ImaginaryPart; }
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
private:

View File

@@ -3,7 +3,6 @@
#include <poincare/expression.h>
#include <poincare/symbol.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -25,7 +24,6 @@ public:
Expression replaceUnknown(const Symbol & symbol) override;
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
private:

View File

@@ -2,7 +2,6 @@
#define POINCARE_LEAST_COMMON_MULTIPLE_H
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -21,7 +20,6 @@ public:
Type type() const override { return Type::LeastCommonMultiple; }
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
private:

View File

@@ -2,7 +2,6 @@
#define POINCARE_MATRIX_DIMENSION_H
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -21,9 +20,6 @@ public:
// Properties
Type type() const override { return Type::MatrixDimension; }
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
private:
// Layout
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;

View File

@@ -25,15 +25,6 @@ public:
int polynomialDegree(Context & context, const char * symbolName) const override;
int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const override;
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override;
/* If we use the formula arg(a*b) = arg(a)+arg(b), we are likely to end up
* with additions of arcTangent. To avoid that, we compute the argument(a*b)
* from the real and imaginary part of a*b.
* TODO: What about norm(a*b)? */
//ComplexPolar complexPolar(Context & context, Preferences::AngleUnit angleUnit) const override;
//Expression complexArgument(Context & context, Preferences::AngleUnit angleUnit) const override;
// Approximation
template<typename T> static Complex<T> compute(const std::complex<T> c, const std::complex<T> d) { return Complex<T>(c*d); }
template<typename T> static MatrixComplex<T> computeOnComplexAndMatrix(const std::complex<T> c, const MatrixComplex<T> m) {

View File

@@ -2,7 +2,6 @@
#define POINCARE_NTH_ROOT_H
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -20,10 +19,6 @@ public:
}
#endif
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianFromComplexPolar(this, context, angleUnit); }
ComplexPolar complexPolar(Context & context, Preferences::AngleUnit angleUnit) const override;
private:
// Layout
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;

View File

@@ -2,7 +2,6 @@
#define POINCARE_NUMBER_H
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -24,7 +23,6 @@ public:
double doubleApproximation() const;
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
};

View File

@@ -27,10 +27,6 @@ public:
int polynomialDegree(Context & context, const char * symbolName) const override;
Sign sign(Context * context, Preferences::AngleUnit angleUnit) const override;
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override;
ComplexPolar complexPolar(Context & context, Preferences::AngleUnit angleUnit) const override;
// Approximation
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
return ApproximationHelper::Map<float>(this, context, angleUnit, compute<float>);

View File

@@ -3,7 +3,6 @@
#include <poincare/expression.h>
#include <poincare/complex_cartesian.h>
#include <poincare/complex_polar.h>
namespace Poincare {
@@ -23,10 +22,6 @@ public:
Type type() const override { return Type::Parenthesis; }
int polynomialDegree(Context & context, const char * symbolName) const override;
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return childAtIndex(0)->complexCartesian(context, angleUnit); }
ComplexPolar complexPolar(Context & context, Preferences::AngleUnit angleUnit) const override { return childAtIndex(0)->complexPolar(context, angleUnit); }
// Layout
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;

View File

@@ -3,7 +3,6 @@
#include <poincare/expression.h>
#include <poincare/evaluation.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -24,9 +23,7 @@ public:
// Properties
Type type() const override{ return Type::PermuteCoefficient; }
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
private:

View File

@@ -23,8 +23,6 @@ public:
// Complex
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override;
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override;
ComplexPolar complexPolar(Context & context, Preferences::AngleUnit angleUnit) const override;
// Properties
Type type() const override { return Type::Power; }

View File

@@ -2,7 +2,6 @@
#define POINCARE_PREDICTION_INTERVAL_H
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -20,9 +19,6 @@ public:
// ExpressionNode
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
// Properties
Type type() const override { return Type::PredictionInterval; }
int polynomialDegree(Context & context, const char * symbolName) const override { return -1; }

View File

@@ -2,7 +2,6 @@
#define POINCARE_RANDINT_H
#include <poincare/expression.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -22,7 +21,6 @@ public:
Type type() const override { return Type::Randint; }
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
private:

View File

@@ -3,7 +3,6 @@
#include <poincare/expression.h>
#include <poincare/evaluation.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -20,7 +19,6 @@ public:
#endif
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
// Properties

View File

@@ -3,7 +3,6 @@
#include <poincare/expression.h>
#include <poincare/approximation_helper.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -23,7 +22,6 @@ public:
Type type() const override { return Type::RealPart; }
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
private:

View File

@@ -3,7 +3,6 @@
#include <poincare/expression.h>
#include <poincare/evaluation.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -20,7 +19,6 @@ public:
#endif
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
// Properties

View File

@@ -2,7 +2,6 @@
#define POINCARE_SIGN_FUNCTION_H
#include <poincare/approximation_helper.h>
#include <poincare/complex_helper.h>
#include <poincare/expression.h>
namespace Poincare {
@@ -25,7 +24,6 @@ public:
Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit) override;
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianRealFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return true; }
private:

View File

@@ -4,7 +4,6 @@
#include <poincare/approximation_helper.h>
#include <poincare/expression.h>
#include <poincare/trigonometry.h>
#include <poincare/complex_helper.h>
namespace Poincare {
@@ -21,7 +20,6 @@ public:
#endif
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianComplexFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return childAtIndex(0)->isReal(context, angleUnit); }
// Properties

View File

@@ -22,17 +22,7 @@ public:
}
#endif
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override;
/* If we use the formula arg(sqrt(a)) = arg(a)/2, we are likely to end up
* with half arcTangent. To avoid that, we compute the argument(sqrt(a))
* from the real and imaginary part of sqrt(a).
* TODO: What about norm(sqrt(a))? */
//ComplexPolar complexPolar(Context & context, Preferences::AngleUnit angleUnit) const override;
private:
//Complex
static Multiplication complexCartesianHelper(Expression e, Context & context, Preferences::AngleUnit angleUnit);
// Layout
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;

View File

@@ -24,9 +24,6 @@ public:
Type type() const override { return Type::Subtraction; }
int polynomialDegree(Context & context, const char * symbolName) const override;
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override;
// Approximation
template<typename T> static Complex<T> compute(const std::complex<T> c, const std::complex<T> d) { return Complex<T>(c - d); }
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {

View File

@@ -28,8 +28,6 @@ public:
// Complex
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override;
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override;
ComplexPolar complexPolar(Context & context, Preferences::AngleUnit angleUnit) const override;
/* Layout */
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;

View File

@@ -81,8 +81,6 @@ protected:
private:
static Expression Expand(const SymbolAbstract & symbol, Context & context, bool clone);
static bool isReal(const SymbolAbstract & symbol, Context & context, Preferences::AngleUnit angleUnit);
static ComplexCartesian complexCartesian(const SymbolAbstract & symbol, Context & context, Preferences::AngleUnit angleUnit);
static ComplexPolar complexPolar(const SymbolAbstract & symbol, Context & context, Preferences::AngleUnit angleUnit);
static size_t AlignedNodeSize(size_t nameLength, size_t nodeSize);
};

View File

@@ -2,7 +2,6 @@
#define POINCARE_TANGENT_H
#include <poincare/approximation_helper.h>
#include <poincare/complex_helper.h>
#include <poincare/expression.h>
namespace Poincare {
@@ -24,7 +23,6 @@ public:
float characteristicXRange(Context & context, Preferences::AngleUnit angleUnit) const override;
// Complex
ComplexCartesian complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const override { return ComplexHelper::complexCartesianComplexFunction(this, context, angleUnit); }
bool isReal(Context & context, Preferences::AngleUnit angleUnit) const override { return childAtIndex(0)->isReal(context, angleUnit); }
private:

View File

@@ -17,7 +17,7 @@ public:
#endif
// Complex
using ExpressionNode::complexCartesian;
using ExpressionNode::isReal;
// Properties
Type type() const override { return Type::Undefined; }

View File

@@ -3,6 +3,7 @@
#include <poincare/serialization_helper.h>
#include <poincare/simplification_helper.h>
#include <poincare/absolute_value_layout.h>
#include <poincare/complex_cartesian.h>
#include <poincare/multiplication.h>
#include <assert.h>
#include <cmath>

View File

@@ -1,4 +1,5 @@
#include <poincare/addition.h>
#include <poincare/complex_cartesian.h>
#include <poincare/multiplication.h>
#include <poincare/subtraction.h>
#include <poincare/power.h>
@@ -27,30 +28,6 @@ int AdditionNode::getPolynomialCoefficients(Context & context, const char * symb
return Addition(this).getPolynomialCoefficients(context, symbolName, coefficients);
}
// Private
ComplexCartesian AdditionNode::complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const {
Expression e(this);
Addition real;
Addition imag;
int nbOfChildren = e.numberOfChildren();
for (int i = 0; i < nbOfChildren; i++) {
ComplexCartesian cartesianParts = e.childAtIndex(i).complexCartesian(context, angleUnit);
if (cartesianParts.isUninitialized()) {
return ComplexCartesian();
}
Expression a = cartesianParts.real();
Expression b = cartesianParts.imag();
assert(!a.isUninitialized() && !b.isUninitialized());
real.addChildAtIndexInPlace(a, real.numberOfChildren(), real.numberOfChildren());
imag.addChildAtIndexInPlace(b, imag.numberOfChildren(), imag.numberOfChildren());
}
return ComplexCartesian::Builder(
real.shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
imag.shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
);
}
// Layout
bool AdditionNode::childNeedsParenthesis(const TreeNode * child) const {
if (((static_cast<const ExpressionNode *>(child)->isNumber()

View File

@@ -1,4 +1,5 @@
#include <poincare/complex_argument.h>
#include <poincare/complex_cartesian.h>
#include <poincare/layout_helper.h>
#include <poincare/serialization_helper.h>
#include <poincare/simplification_helper.h>

View File

@@ -1,132 +0,0 @@
#include <poincare/complex_helper.h>
#include <poincare/addition.h>
#include <poincare/arc_tangent.h>
#include <poincare/cosine.h>
#include <poincare/constant.h>
#include <poincare/division.h>
#include <poincare/multiplication.h>
#include <poincare/rational.h>
#include <poincare/square_root.h>
#include <poincare/sine.h>
#include <poincare/sign_function.h>
#include <poincare/subtraction.h>
#include <poincare/power.h>
namespace Poincare {
ComplexCartesian ComplexHelper::complexCartesianComplexFunction(const ExpressionNode * node, Context & context, Preferences::AngleUnit angleUnit) {
Expression e(node);
ComplexCartesian complexChild = e.childAtIndex(0).complexCartesian(context, angleUnit);
if (complexChild.isUninitialized()) {
return ComplexCartesian();
}
Expression childImaginaryPart = complexChild.imag();
assert(!childImaginaryPart.isUninitialized());
if (childImaginaryPart.type() != ExpressionNode::Type::Rational || !static_cast<Rational &>(childImaginaryPart).isZero()) {
return ComplexCartesian();
}
return ComplexCartesian::Builder(
e.clone(),
Rational(0)
);
}
ComplexCartesian ComplexHelper::complexCartesianRealFunction(const ExpressionNode * e, Context & context, Preferences::AngleUnit angleUnit) {
return ComplexCartesian::Builder(
Expression(e).clone(),
Rational(0)
);
}
Expression ComplexHelper::complexCartesianFromComplexPolarHelper(Expression norm, Expression trigo, Context & context, Preferences::AngleUnit angleUnit) {
return Multiplication(norm, trigo.shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation)).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation);
}
ComplexCartesian ComplexHelper::complexCartesianFromComplexPolar(const ExpressionNode * node, Context & context, Preferences::AngleUnit angleUnit) {
Expression e(node);
ComplexPolar polar = e.complexPolar(context, angleUnit);
if (polar.isUninitialized()) {
return ComplexCartesian();
}
Expression r = polar.norm();
Expression th = polar.arg();
assert(!r.isUninitialized() && !th.isUninitialized());
Expression argument = th;
return ComplexCartesian::Builder(
complexCartesianFromComplexPolarHelper(r.clone(), Cosine::Builder(argument.clone()), context, angleUnit),
complexCartesianFromComplexPolarHelper(r, Sine::Builder(argument), context, angleUnit)
);
}
ComplexPolar ComplexHelper::complexPolarFromComplexCartesian(const ExpressionNode * node, Context & context, Preferences::AngleUnit angleUnit) {
Expression e(node);
ComplexCartesian cartesian = e.complexCartesian(context, angleUnit);
if (cartesian.isUninitialized()) {
return ComplexPolar();
}
Expression a = cartesian.real();
Expression b = cartesian.imag();
assert(!a.isUninitialized() && !b.isUninitialized());
// Step 1: find norm
Expression norm;
ExpressionNode::Sign s = e.sign(&context, angleUnit);
if (s == ExpressionNode::Sign::Positive) {
// Case 1: the expression is positive real
norm = e.clone();
} else if (s == ExpressionNode::Sign::Negative) {
// Case 2: the argument is negative real
norm = e.clone().setSign(ExpressionNode::Sign::Positive, &context, angleUnit);
} else {
// Case 3: the argument is complex or of unknown approximation
// sqrt(a^2+b^2)
norm = SquareRoot::Builder(
Addition(
Power(a.clone(), Rational(2)).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation),
Power(b.clone(), Rational(2)).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation);
}
// Step 2: find the argument
Expression argument;
float bApprox = b.approximateToScalar<float>(context, angleUnit);
if (bApprox != 0.0f) {
// if b != 0, argument = sign(b) * Pi/2 - arctan(a/b)
// First, compute arctan(a/b) or (Pi/180)*arctan(a/b)
Expression arcTangent = ArcTangent::Builder(Division(a, b.clone()).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation)).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation);
// Then, compute sign(b) * Pi/2 - arctan(a/b)
argument = Subtraction(
Multiplication(
SignFunction::Builder(b).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation),
Division(Constant(Ion::Charset::SmallPi), Rational(2)).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation),
arcTangent
).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation);
} else {
// if b == 0, argument = (1-sign(a))*Pi/2
argument = Multiplication(
Subtraction(
Rational(1),
SignFunction::Builder(a).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation),
Division(Constant(Ion::Charset::SmallPi), Rational(2)).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation);
}
return ComplexPolar::Builder(norm, argument);
}
Expression ComplexHelper::complexSquareNormComplexCartesian(Expression real, Expression imag, Context & context, Preferences::AngleUnit angleUnit) {
assert(!real.isUninitialized() && !imag.isUninitialized());
return Addition(
Power(
real,
Rational(2)
).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation),
Power(
imag,
Rational(2)
).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation);
}
}

View File

@@ -1,7 +1,6 @@
#include <poincare/conjugate.h>
#include <poincare/conjugate_layout.h>
#include <poincare/complex_cartesian.h>
#include <poincare/complex_polar.h>
#include <poincare/multiplication.h>
#include <poincare/rational.h>
#include <poincare/serialization_helper.h>
@@ -16,28 +15,6 @@ constexpr Expression::FunctionHelper Conjugate::s_functionHelper;
int ConjugateNode::numberOfChildren() const { return Conjugate::s_functionHelper.numberOfChildren(); }
ComplexCartesian ConjugateNode::complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const {
ComplexCartesian childCartesian = childAtIndex(0)->complexCartesian(context, angleUnit);
if (childCartesian.isUninitialized()) {
return ComplexCartesian();
}
return ComplexCartesian::Builder(
childCartesian.real(),
Multiplication(Rational(-1), childCartesian.imag()).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
);
}
ComplexPolar ConjugateNode::complexPolar(Context & context, Preferences::AngleUnit angleUnit) const {
ComplexPolar childPolar = childAtIndex(0)->complexPolar(context, angleUnit);
if (childPolar.isUninitialized()) {
return ComplexPolar();
}
return ComplexPolar::Builder(
childPolar.norm(),
Multiplication(Rational(-1), childPolar.arg()).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
);
}
Layout ConjugateNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
return ConjugateLayout(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits));
}

View File

@@ -2,6 +2,7 @@
#include <poincare/char_layout.h>
#include <poincare/horizontal_layout.h>
#include <poincare/layout_helper.h>
#include <poincare/complex_cartesian.h>
#include <poincare/rational.h>
#include <ion.h>
#include <cmath>
@@ -20,13 +21,6 @@ bool ConstantNode::isReal(Context & context, Preferences::AngleUnit angleUnit) c
return !isIComplex();
}
ComplexCartesian ConstantNode::complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const {
if (isIComplex()) {
return ComplexCartesian::Builder(Rational(0), Rational(1));
}
return ComplexCartesian::Builder(Constant(this).clone(), Rational(0));
}
Layout ConstantNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
return LayoutHelper::String(m_name, strlen(m_name));
}

View File

@@ -46,47 +46,6 @@ Expression DivisionNode::shallowReduce(Context & context, Preferences::AngleUnit
return Division(this).shallowReduce(context, angleUnit, target);
}
ComplexCartesian DivisionNode::complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const {
Division e(this);
ComplexCartesian cartesianChild0 = e.childAtIndex(0).complexCartesian(context, angleUnit);
ComplexCartesian cartesianChild1 = e.childAtIndex(1).complexCartesian(context, angleUnit);
if (cartesianChild0.isUninitialized() || cartesianChild1.isUninitialized()) {
return ComplexCartesian();
}
Expression a = cartesianChild0.real();
Expression b = cartesianChild0.imag();
Expression c = cartesianChild1.real();
Expression d = cartesianChild1.imag();
assert(!a.isUninitialized() && !b.isUninitialized() && !c.isUninitialized() && !d.isUninitialized());
Expression denominator = ComplexHelper::complexSquareNormComplexCartesian(c.clone(), d.clone(), context, angleUnit);
return ComplexCartesian::Builder(
Division(
Addition(
Multiplication(a.clone(), c.clone()).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
Multiplication(b.clone(), d.clone()).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
denominator.clone()
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
Division(
Subtraction(
Multiplication(b, c).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
Multiplication(a, d).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
denominator
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
);
}
/*ComplexPolar DivisionNode::complexPolar(Context & context, Preferences::AngleUnit angleUnit) const {
Division d(this);
Expression r0 = d.childAtIndex(0).complexNorm(context, angleUnit);
Expression r1 = d.childAtIndex(1).complexNorm(context, angleUnit);
if (r0.isUninitialized() || r1.isUninitialized()) {
return Expression();
}
return Division(r0,r1).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation);
}*/
template<typename T> Complex<T> DivisionNode::compute(const std::complex<T> c, const std::complex<T> d) {
return Complex<T>(c/d);
}

View File

@@ -199,26 +199,6 @@ bool Expression::getLinearCoefficients(char * variables, int maxVariableSize, Ex
return !isMultivariablePolynomial;
}
/* Complex */
bool Expression::isPureReal(Context & context, Preferences::AngleUnit angleUnit) const {
Evaluation<float> approx = approximateToEvaluation<float>(context, angleUnit);
if (approx.type() == EvaluationNode<float>::Type::Complex) {
Complex<float> approxComplex = static_cast<Complex<float>&>(approx);
return approxComplex.imag() == 0.0f;
}
// TODO: matrix are not reduced yet so isPureReal is dummy if the approximation is a matrix
return true;
}
ComplexCartesian Expression::complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const {
return node()->complexCartesian(context, angleUnit);
}
ComplexPolar Expression::complexPolar(Context & context, Preferences::AngleUnit angleUnit) const {
return node()->complexPolar(context, angleUnit);
}
// Private
void Expression::defaultDeepReduceChildren(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {

View File

@@ -3,8 +3,6 @@
#include <poincare/addition.h>
#include <poincare/arc_tangent.h>
#include <poincare/complex_cartesian.h>
#include <poincare/complex_helper.h>
#include <poincare/complex_polar.h>
#include <poincare/division.h>
#include <poincare/power.h>
#include <poincare/rational.h>
@@ -74,14 +72,6 @@ float ExpressionNode::characteristicXRange(Context & context, Preferences::Angle
return range;
}
ComplexCartesian ExpressionNode::complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const {
return ComplexCartesian();
}
ComplexPolar ExpressionNode::complexPolar(Context & context, Preferences::AngleUnit angleUnit) const {
return ComplexHelper::complexPolarFromComplexCartesian(this, context, angleUnit);
}
int ExpressionNode::SimplificationOrder(const ExpressionNode * e1, const ExpressionNode * e2, bool canBeInterrupted) {
if (e1->type() > e2->type()) {
if (canBeInterrupted && Expression::shouldStopProcessing()) {

View File

@@ -9,21 +9,11 @@
namespace Poincare {
ComplexCartesian FunctionNode::complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const {
Function f(this);
return SymbolAbstract::complexCartesian(f, context, angleUnit);
}
bool FunctionNode::isReal(Context & context, Preferences::AngleUnit angleUnit) const {
Function f(this);
return SymbolAbstract::isReal(f, context, angleUnit);
}
ComplexPolar FunctionNode::complexPolar(Context & context, Preferences::AngleUnit angleUnit) const {
Function f(this);
return SymbolAbstract::complexPolar(f, context, angleUnit);
}
Expression FunctionNode::replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression) {
return Function(this).replaceSymbolWithExpression(symbol, expression);
}

View File

@@ -2,6 +2,7 @@
#include <poincare/layout_helper.h>
#include <poincare/serialization_helper.h>
#include <poincare/simplification_helper.h>
#include <poincare/complex_cartesian.h>
#include <poincare/rational.h>
#include <cmath>

View File

@@ -31,67 +31,6 @@ ExpressionNode::Sign MultiplicationNode::sign(Context * context, Preferences::An
return (Sign)sign;
}
ComplexCartesian MultiplicationNode::complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const {
Multiplication m(this);
int nbChildren = m.numberOfChildren();
assert(nbChildren > 0);
ComplexCartesian cartesian = m.childAtIndex(0).complexCartesian(context, angleUnit);
if (cartesian.isUninitialized()) {
return ComplexCartesian();
}
Expression real = cartesian.real();
Expression imag = cartesian.imag();
assert(!real.isUninitialized() && !imag.isUninitialized());
for (int i = 1; i < nbChildren; i++) {
ComplexCartesian childCartesian = m.childAtIndex(i).complexCartesian(context, angleUnit);
if (childCartesian.isUninitialized()) {
return ComplexCartesian();
}
Expression childReal = childCartesian.real();
Expression childImag = childCartesian.imag();
assert(!real.isUninitialized() && !imag.isUninitialized());
Expression newReal =
Subtraction(
Multiplication(real.clone(), childReal.clone()).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
Multiplication(imag.clone(), childImag.clone()).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation);
Expression newImag =
Addition(
Multiplication(real, childImag).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
Multiplication(imag, childReal).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation);
real = newReal;
imag = newImag;
}
return ComplexCartesian::Builder(real, imag);
}
/*Expression MultiplicationNode::complexNorm(Context & context, Preferences::AngleUnit angleUnit) const {
Multiplication m(this);
Multiplication norm;
for (int i = 0; i < m.numberOfChildren(); i++) {
Expression r = m.childAtIndex(i).complexNorm(context, angleUnit);
if (r.isUninitialized()) {
return Expression();
}
norm.addChildAtIndexInPlace(r, norm.numberOfChildren(), norm.numberOfChildren());
}
return norm.shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation);
}
Expression MultiplicationNode::complexArgument(Context & context, Preferences::AngleUnit angleUnit) const {
Multiplication m(this);
Addition arg;
for (int i = 0; i < m.numberOfChildren(); i++) {
Expression r = m.childAtIndex(i).complexArgument(context, angleUnit);
if (r.isUninitialized()) {
return Expression();
}
arg.addChildAtIndexInPlace(r, arg.numberOfChildren(), arg.numberOfChildren());
}
return arg;
}
*/
int MultiplicationNode::polynomialDegree(Context & context, const char * symbolName) const {
int degree = 0;
for (ExpressionNode * c : children()) {

View File

@@ -18,47 +18,6 @@ constexpr Expression::FunctionHelper NthRoot::s_functionHelper;
int NthRootNode::numberOfChildren() const { return NthRoot::s_functionHelper.numberOfChildren(); }
ComplexPolar NthRootNode::complexPolar(Context & context, Preferences::AngleUnit angleUnit) const {
NthRoot e(this);
ComplexPolar polarChild0 = e.childAtIndex(0).complexPolar(context, angleUnit);
ComplexCartesian cartesianChild1 = e.childAtIndex(0).complexCartesian(context, angleUnit);
if (polarChild0.isUninitialized() || cartesianChild1.isUninitialized()) {
return ComplexPolar();
}
// NthRoot(r*e^(i*th), c+id)
Expression r = polarChild0.norm();
Expression th = polarChild0.arg();
Expression c = cartesianChild1.real();
Expression d = cartesianChild1.imag();
assert(!r.isUninitialized() && !th.isUninitialized() && !c.isUninitialized() && !d.isUninitialized());
Expression denominator = ComplexHelper::complexSquareNormComplexCartesian(c.clone(), d.clone(), context, angleUnit);
// R = r^(c/(c^2+d^2))*e^(th*d/(c^2+d^2))
Expression norm = Multiplication(
Power(
r.clone(),
Division(c.clone(), denominator.clone()).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
Power(
Constant(Ion::Charset::Exponential),
Division(
Multiplication(d.clone(), th.clone()).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
denominator.clone())
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation);
// TH = (th*c-d*ln(r))/(c^2+d^2)
Expression argument = Division(
Subtraction(
Multiplication(th, c).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
Multiplication(
d,
NaperianLogarithm::Builder(r).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
denominator
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation);
return ComplexPolar::Builder(norm, argument);
}
Layout NthRootNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
return NthRootLayout(
childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits),

View File

@@ -29,28 +29,6 @@ ExpressionNode::Sign OppositeNode::sign(Context * context, Preferences::AngleUni
return ExpressionNode::sign(context,angleUnit);
}
ComplexCartesian OppositeNode::complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const {
ComplexCartesian childCartesian = childAtIndex(0)->complexCartesian(context, angleUnit);
if (childCartesian.isUninitialized()) {
return ComplexCartesian();
}
return ComplexCartesian::Builder(
Multiplication(Rational(-1), childCartesian.real()).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
Multiplication(Rational(-1), childCartesian.imag()).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
);
}
ComplexPolar OppositeNode::complexPolar(Context & context, Preferences::AngleUnit angleUnit) const {
ComplexPolar childPolar = childAtIndex(0)->complexPolar(context, angleUnit);
if (childPolar.isUninitialized()) {
return ComplexPolar();
}
return ComplexPolar::Builder(
childPolar.norm(),
Addition(childPolar.arg(), Constant(Ion::Charset::SmallPi)).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
);
}
/* Layout */
bool OppositeNode::childNeedsParenthesis(const TreeNode * child) const {

View File

@@ -94,50 +94,6 @@ bool PowerNode::isReal(Context & context, Preferences::AngleUnit angleUnit) cons
return false;
}
ComplexCartesian PowerNode::complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const {
Power p(this);
Expression e = p.equivalentExpressionUsingStandardExpression();
if (!e.isUninitialized()) {
return e.complexCartesian(context, angleUnit);
}
return ComplexHelper::complexCartesianFromComplexPolar(this, context, angleUnit);
}
ComplexPolar PowerNode::complexPolar(Context & context, Preferences::AngleUnit angleUnit) const {
Power p(this);
Expression e = p.equivalentExpressionUsingStandardExpression();
if (!e.isUninitialized()) {
return e.complexPolar(context, angleUnit);
}
ComplexPolar polarChild0 = p.childAtIndex(0).complexPolar(context, angleUnit);
ComplexCartesian cartesianChild1 = p.childAtIndex(1).complexCartesian(context, angleUnit);
if (polarChild0.isUninitialized() || cartesianChild1.isUninitialized()) {
return ComplexPolar();
}
// Power(r*e^(i*th), c+id)
Expression r = polarChild0.norm();
Expression th = polarChild0.arg();
Expression c = cartesianChild1.real();
Expression d = cartesianChild1.imag();
// R = r^c*e^(-th*d)
Expression norm = Multiplication(
Power(r.clone(), c.clone()).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
Power(
Constant(Ion::Charset::Exponential),
Multiplication(Rational(-1), th.clone(), d.clone()).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation);
// TH = d*ln(r)+c*th
Expression argument = Addition(
Multiplication(th, c).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
Multiplication(
d,
NaperianLogarithm::Builder(r).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation);
return ComplexPolar::Builder(norm, argument);
}
// Private
template<typename T>

View File

@@ -1,4 +1,5 @@
#include <poincare/real_part.h>
#include <poincare/complex_cartesian.h>
#include <poincare/layout_helper.h>
#include <poincare/serialization_helper.h>
#include <poincare/simplification_helper.h>

View File

@@ -1,4 +1,5 @@
#include <poincare/sign_function.h>
#include <poincare/complex_cartesian.h>
#include <poincare/rational.h>
#include <poincare/layout_helper.h>
#include <poincare/serialization_helper.h>

View File

@@ -18,57 +18,6 @@ constexpr Expression::FunctionHelper SquareRoot::s_functionHelper;
int SquareRootNode::numberOfChildren() const { return SquareRoot::s_functionHelper.numberOfChildren(); }
/*Expression SquareRootNode::complexNorm(Context & context, Preferences::AngleUnit angleUnit) const {
Expression r = childAtIndex(0)->complexNorm(context, angleUnit);
if (r.isUninitialized()) {
return Expression();
}
// R = sqrt(r)
return SquareRoot::Builder(r).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation);
}*/
/*Expression SquareRootNode::complexArgument(Context & context, Preferences::AngleUnit angleUnit) const {
Expression th = childAtIndex(0)->complexArgument(context, angleUnit);
if (th.isUninitialized()) {
return Expression();
}
// TH = th/2
return Division(th, Rational(2)).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation);
}*/
Multiplication SquareRootNode::complexCartesianHelper(Expression e, Context & context, Preferences::AngleUnit angleUnit) {
return Multiplication(
Rational(1,2),
SquareRoot::Builder(
Multiplication(
Rational(2),
e.shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
);
}
ComplexCartesian SquareRootNode::complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const {
// real: (1/2)*sqrt(2*(sqrt(x^2+y^2)+x))
// imag: (1/2)*sqrt(2*(sqrt(x^2+y^2)-x)*sign(y))
SquareRoot e(this);
ComplexCartesian cartesian = e.childAtIndex(0).complexCartesian(context, angleUnit);
if (cartesian.isUninitialized()) {
return ComplexCartesian();
}
Expression x = cartesian.real();
Expression y = cartesian.imag();
assert(!x.isUninitialized() && !y.isUninitialized());
Expression norm = SquareRoot::Builder(ComplexHelper::complexSquareNormComplexCartesian(x.clone(), y.clone(), context, angleUnit)).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation);
// a = sqrt(x^2+y^2)+x
Multiplication real = complexCartesianHelper(Addition(norm.clone(), x.clone()), context, angleUnit);
Multiplication imag = complexCartesianHelper(Subtraction(norm, x), context, angleUnit);
imag.addChildAtIndexInPlace(SignFunction::Builder(y).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::BottomUpComputation), imag.numberOfChildren(), imag.numberOfChildren());
return ComplexCartesian::Builder(
real.shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
imag.shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
);
}
Layout SquareRootNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
return NthRootLayout(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits));
}

View File

@@ -23,19 +23,6 @@ int SubtractionNode::polynomialDegree(Context & context, const char * symbolName
// Private
ComplexCartesian SubtractionNode::complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const {
Subtraction e(this);
ComplexCartesian cartesian0 = e.childAtIndex(0).complexCartesian(context, angleUnit);
ComplexCartesian cartesian1 = e.childAtIndex(1).complexCartesian(context, angleUnit);
if (cartesian0.isUninitialized() || cartesian1.isUninitialized()) {
return ComplexCartesian();
}
return ComplexCartesian::Builder(
Subtraction(cartesian0.real(), cartesian1.real()).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation),
Subtraction(cartesian0.imag(), cartesian1.imag()).shallowReduce(context, angleUnit, ReductionTarget::BottomUpComputation)
);
}
bool SubtractionNode::childNeedsParenthesis(const TreeNode * child) const {
if (child == childAtIndex(0)) {
return false;

View File

@@ -82,16 +82,6 @@ bool SymbolNode::isReal(Context & context, Preferences::AngleUnit angleUnit) con
return SymbolAbstract::isReal(s, context, angleUnit);
}
ComplexCartesian SymbolNode::complexCartesian(Context & context, Preferences::AngleUnit angleUnit) const {
Symbol s(this);
return SymbolAbstract::complexCartesian(s, context, angleUnit);
}
ComplexPolar SymbolNode::complexPolar(Context & context, Preferences::AngleUnit angleUnit) const {
Symbol f(this);
return SymbolAbstract::complexPolar(f, context, angleUnit);
}
Layout SymbolNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
if (m_name[0] == Symbol::SpecialSymbols::UnknownX) {
assert(m_name[1] == 0);

View File

@@ -1,6 +1,5 @@
#include <poincare/symbol_abstract.h>
#include <poincare/complex_cartesian.h>
#include <poincare/complex_polar.h>
#include <poincare/rational.h>
#include <poincare/symbol.h>
#include <poincare/expression.h>
@@ -88,23 +87,6 @@ bool SymbolAbstract::isReal(const SymbolAbstract & symbol, Context & context, Pr
return e.isReal(context, angleUnit);
}
ComplexCartesian SymbolAbstract::complexCartesian(const SymbolAbstract & symbol, Context & context, Preferences::AngleUnit angleUnit) {
Expression e = SymbolAbstract::Expand(symbol, context, true);
if (e.isUninitialized()) {
return ComplexCartesian::Builder(symbol.clone(), Rational(0));
}
return e.complexCartesian(context, angleUnit);
}
ComplexPolar SymbolAbstract::complexPolar(const SymbolAbstract & symbol, Context & context, Preferences::AngleUnit angleUnit) {
Expression e = SymbolAbstract::Expand(symbol, context, true);
if (e.isUninitialized()) {
// sqrt(f(x)^2)*exp((1-sign(f(x))*Pi/2)
return ComplexHelper::complexPolarFromComplexCartesian(symbol.node(), context, angleUnit);
}
return e.complexPolar(context, angleUnit);
}
/* TreePool uses adresses and sizes that are multiples of 4 in order to make
* node moves faster.*/
size_t SymbolAbstract::AlignedNodeSize(size_t nameLength, size_t nodeSize) {

View File

@@ -222,7 +222,6 @@ template OppositeNode * Poincare::TreePool::createTreeNode<OppositeNode>(size_t
template PowerNode * Poincare::TreePool::createTreeNode<PowerNode>(size_t size);
template ComplexArgumentNode * Poincare::TreePool::createTreeNode<ComplexArgumentNode>(size_t size);
template ComplexCartesianNode * Poincare::TreePool::createTreeNode<ComplexCartesianNode>(size_t size);
template ComplexPolarNode * Poincare::TreePool::createTreeNode<ComplexPolarNode>(size_t size);
template ConfidenceIntervalNode * Poincare::TreePool::createTreeNode<ConfidenceIntervalNode>(size_t size);
template ConjugateNode * Poincare::TreePool::createTreeNode<ConjugateNode>(size_t size);
template ConstantNode * Poincare::TreePool::createTreeNode<ConstantNode>(size_t size);