[poincare] Static Expression methods start with uppercase

This commit is contained in:
Léa Saviot
2019-01-03 16:39:12 +01:00
parent 271e22628b
commit e5f0959239
17 changed files with 48 additions and 48 deletions

View File

@@ -84,7 +84,7 @@ AppsContainer::AppsContainer() :
* We just remove the circuit breaker for now.
* TODO: Put the Poincare circuit breaker back on epsilon's web emulator */
#else
Poincare::Expression::setCircuitBreaker(AppsContainer::poincareCircuitBreaker);
Poincare::Expression::SetCircuitBreaker(AppsContainer::poincareCircuitBreaker);
#endif
Ion::Storage::sharedStorage()->setDelegate(this);
}

View File

@@ -128,8 +128,8 @@ double Model::alphaPrimeCoefficient(Store * store, int series, double * modelCoe
* a'(k,k) = 2*epsilon so that the inversion method does not detect a'(k,k)
* as a zero. */
result = alphaCoefficient(store, series, modelCoefficients, k, l)*(1.0+lambda);
if (std::fabs(result) < Expression::epsilon<double>()) {
result = 2*Expression::epsilon<double>();
if (std::fabs(result) < Expression::Epsilon<double>()) {
result = 2*Expression::Epsilon<double>();
}
} else {
result = alphaCoefficient(store, series, modelCoefficients, l, k);

View File

@@ -48,7 +48,7 @@ template <class T>
inline T ApproximateToScalar(const char * text, Poincare::Context & context) {
Poincare::Preferences * preferences = Poincare::Preferences::sharedPreferences();
Poincare::Preferences::ComplexFormat complexFormat = Poincare::Expression::UpdatedComplexFormatWithTextInput(preferences->complexFormat(), text);
return Poincare::Expression::approximateToScalar<T>(text, context, complexFormat, preferences->angleUnit());
return Poincare::Expression::ApproximateToScalar<T>(text, context, complexFormat, preferences->angleUnit());
}
inline Poincare::Expression ParseAndSimplify(const char * text, Poincare::Context & context) {

View File

@@ -99,7 +99,7 @@ class Expression : public TreeHandle {
friend class SymbolNode;
public:
static bool isExpression() { return true; }
static bool IsExpression() { return true; }
/* Constructor & Destructor */
Expression() : TreeHandle() {}
@@ -109,9 +109,9 @@ public:
/* Circuit breaker */
typedef bool (*CircuitBreaker)();
static void setCircuitBreaker(CircuitBreaker cb);
static bool shouldStopProcessing();
static void setInterruption(bool interrupt);
static void SetCircuitBreaker(CircuitBreaker cb);
static bool ShouldStopProcessing();
static void SetInterruption(bool interrupt);
/* Hierarchy */
Expression childAtIndex(int i) const;
@@ -196,10 +196,10 @@ public:
/* Approximation Helper */
// These methods reset the sApproximationEncounteredComplex flag. They should not be use to implement node approximation
template<typename U> static U epsilon();
template<typename U> static U Epsilon();
template<typename U> Expression approximate(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
template<typename U> U approximateToScalar(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
template<typename U> static U approximateToScalar(const char * text, Context & context, Preferences::ComplexFormat complexFormat, 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::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
/* Expression roots/extrema solver */
struct Coordinate2D {
@@ -247,7 +247,7 @@ protected:
* ie, you can write: 'Rational a(2); AbsoluteValue b(a);'
* */
assert(T::isExpression());
assert(T::IsExpression());
static_assert(sizeof(T) == sizeof(Expression), "Size mismatch");
return *reinterpret_cast<T *>(const_cast<Expression *>(this));
}
@@ -309,9 +309,9 @@ private:
int defaultGetPolynomialCoefficients(Context & context, const char * symbol, Expression expression[]) const;
/* Builder */
static bool isZero(const Expression e);
static bool isOne(const Expression e);
static bool isMinusOne(const Expression e);
static bool IsZero(const Expression e);
static bool IsOne(const Expression e);
static bool IsMinusOne(const Expression e);
static Expression CreateComplexExpression(Expression ra, Expression tb, Preferences::ComplexFormat complexFormat, bool undefined, bool isZeroRa, bool isOneRa, bool isZeroTb, bool isOneTb, bool isNegativeRa, bool isNegativeTb);
/* Expression roots/extrema solver*/

View File

@@ -50,11 +50,11 @@ Expression AbsoluteValue::shallowReduce(Context & context, Preferences::ComplexF
Expression c = childAtIndex(0);
if (c.isReal(context)) {
float app = c.node()->approximate(float(), context, angleUnit).toScalar();
if (!std::isnan(app) && app >= Expression::epsilon<float>()) {
if (!std::isnan(app) && app >= Expression::Epsilon<float>()) {
// abs(a) = a with a > 0
replaceWithInPlace(c);
return c;
} else if (!std::isnan(app) && app <= -Expression::epsilon<float>()) {
} else if (!std::isnan(app) && app <= -Expression::Epsilon<float>()) {
// abs(a) = -a with a < 0
Multiplication m(Rational(-1), c);
replaceWithInPlace(m);

View File

@@ -16,7 +16,7 @@ template <typename T> T absMod(T a, T b) {
template <typename T> std::complex<T> ApproximationHelper::TruncateRealOrImaginaryPartAccordingToArgument(std::complex<T> c) {
T arg = std::arg(c);
T precision = 10*Expression::epsilon<T>();
T precision = 10*Expression::Epsilon<T>();
if (absMod<T>(arg, (T)M_PI) <= precision) {
c.imag(0);
}

View File

@@ -49,12 +49,12 @@ Expression ComplexArgument::shallowReduce(Context & context, Preferences::Comple
bool real = c.isReal(context);
if (real) {
float app = c.node()->approximate(float(), context, angleUnit).toScalar();
if (!std::isnan(app) && app >= Expression::epsilon<float>()) {
if (!std::isnan(app) && app >= Expression::Epsilon<float>()) {
// arg(x) = 0 if x > 0
Expression result = Rational(0);
replaceWithInPlace(result);
return result;
} else if (!std::isnan(app) && app <= -Expression::epsilon<float>()) {
} else if (!std::isnan(app) && app <= -Expression::Epsilon<float>()) {
// arg(x) = Pi if x < 0
Expression result = Constant(Ion::Charset::SmallPi);
replaceWithInPlace(result);

View File

@@ -58,7 +58,7 @@ Expression ComplexCartesian::shallowBeautify(Context & context, Preferences::Com
b = oppositeB.isUninitialized() ? b : oppositeB;
Expression e = Expression::CreateComplexExpression(a, b, Preferences::ComplexFormat::Cartesian,
a.isUndefined() || b.isUndefined(),
Expression::isZero(a), Expression::isOne(a), Expression::isZero(b), Expression::isOne(b),
Expression::IsZero(a), Expression::IsOne(a), Expression::IsZero(b), Expression::IsOne(b),
!oppositeA.isUninitialized(),
!oppositeB.isUninitialized()
);
@@ -357,7 +357,7 @@ ComplexCartesian ComplexCartesian::power(ComplexCartesian & other, Context & con
ComplexCartesian ComplexCartesian::interruptComputationIfManyNodes() {
if (numberOfDescendants(true) > k_maxNumberOfNodesBeforeInterrupting) {
Expression::setInterruption(true);
Expression::SetInterruption(true);
return ComplexCartesian(Undefined(), Undefined());
}
return *this;

View File

@@ -45,11 +45,11 @@ Expression Expression::ExpressionFromAddress(const void * address, size_t size)
static Expression::CircuitBreaker sCircuitBreaker = nullptr;
static bool sSimplificationHasBeenInterrupted = false;
void Expression::setCircuitBreaker(CircuitBreaker cb) {
void Expression::SetCircuitBreaker(CircuitBreaker cb) {
sCircuitBreaker = cb;
}
bool Expression::shouldStopProcessing() {
bool Expression::ShouldStopProcessing() {
if (sCircuitBreaker == nullptr) {
return false;
}
@@ -60,7 +60,7 @@ bool Expression::shouldStopProcessing() {
return false;
}
void Expression::setInterruption(bool interrupt) {
void Expression::SetInterruption(bool interrupt) {
sSimplificationHasBeenInterrupted = interrupt;
}
@@ -474,7 +474,7 @@ void Expression::simplifyAndApproximate(Expression * simplifiedExpression, Expre
bool tbIsNegative = false;
makePositive(&ra, &raIsNegative);
makePositive(&tb, &tbIsNegative);
*simplifiedExpression = CreateComplexExpression(ra, tb, complexFormat, ra.isUndefined() || tb.isUndefined(), isZero(ra), isOne(ra), isZero(tb), isOne(tb), raIsNegative, tbIsNegative);
*simplifiedExpression = CreateComplexExpression(ra, tb, complexFormat, ra.isUndefined() || tb.isUndefined(), IsZero(ra), IsOne(ra), IsZero(tb), IsOne(tb), raIsNegative, tbIsNegative);
} else {
/* Case 2: The reduced expression has a complex component that could not
* be bubbled up. */
@@ -575,7 +575,7 @@ U Expression::approximateToScalar(Context& context, Preferences::ComplexFormat c
}
template<typename U>
U Expression::approximateToScalar(const char * text, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
U Expression::ApproximateToScalar(const char * text, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
Expression exp = ParseAndSimplify(text, context, complexFormat, angleUnit);
assert(!exp.isUninitialized());
return exp.approximateToScalar<U>(context, complexFormat, angleUnit);
@@ -589,20 +589,20 @@ U Expression::approximateWithValueForSymbol(const char * symbol, U x, Context &
}
template<typename U>
U Expression::epsilon() {
U Expression::Epsilon() {
static U epsilon = sizeof(U) == sizeof(double) ? 1E-15 : 1E-7f;
return epsilon;
}
/* Builder */
bool Expression::isZero(const Expression e) {
bool Expression::IsZero(const Expression e) {
return e.type() == ExpressionNode::Type::Rational && static_cast<const Rational &>(e).isZero();
}
bool Expression::isOne(const Expression e) {
bool Expression::IsOne(const Expression e) {
return e.type() == ExpressionNode::Type::Rational && static_cast<const Rational &>(e).isOne();
}
bool Expression::isMinusOne(const Expression e) {
bool Expression::IsMinusOne(const Expression e) {
return e.type() == ExpressionNode::Type::Rational && static_cast<const Rational &>(e).isMinusOne();
}
@@ -996,8 +996,8 @@ double Expression::brentRoot(const char * symbol, double ax, double bx, double p
return NAN;
}
template float Expression::epsilon<float>();
template double Expression::epsilon<double>();
template float Expression::Epsilon<float>();
template double Expression::Epsilon<double>();
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;
@@ -1005,8 +1005,8 @@ template Expression Expression::approximate<double>(Context& context, Preference
template float Expression::approximateToScalar(Context& context, Preferences::ComplexFormat, Preferences::AngleUnit angleUnit) const;
template double Expression::approximateToScalar(Context& context, Preferences::ComplexFormat, Preferences::AngleUnit angleUnit) const;
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 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::ComplexFormat, Preferences::AngleUnit angleUnit) const;
template Evaluation<double> Expression::approximateToEvaluation(Context& context, Preferences::ComplexFormat, Preferences::AngleUnit angleUnit) const;

View File

@@ -74,14 +74,14 @@ float ExpressionNode::characteristicXRange(Context & context, Preferences::Angle
int ExpressionNode::SimplificationOrder(const ExpressionNode * e1, const ExpressionNode * e2, bool ascending, bool canBeInterrupted) {
if (e1->type() > e2->type()) {
if (canBeInterrupted && Expression::shouldStopProcessing()) {
if (canBeInterrupted && Expression::ShouldStopProcessing()) {
return 1;
}
return -(e2->simplificationOrderGreaterType(e1, ascending, canBeInterrupted));
} else if (e1->type() == e2->type()) {
return e1->simplificationOrderSameType(e2, ascending, canBeInterrupted);
} else {
if (canBeInterrupted && Expression::shouldStopProcessing()) {
if (canBeInterrupted && Expression::ShouldStopProcessing()) {
return -1;
}
return e1->simplificationOrderGreaterType(e2, ascending, canBeInterrupted);

View File

@@ -184,7 +184,7 @@ IntegralNode::DetailedResult<T> IntegralNode::kronrodGaussQuadrature(T a, T b, C
template<typename T>
T IntegralNode::adaptiveQuadrature(T a, T b, T eps, int numberOfIterations, Context & context, Preferences::AngleUnit angleUnit) const {
if (Integral::shouldStopProcessing()) {
if (Expression::ShouldStopProcessing()) {
return NAN;
}
DetailedResult<T> quadKG = kronrodGaussQuadrature(a, b, context, angleUnit);

View File

@@ -147,7 +147,7 @@ int Matrix::ArrayInverse(T * array, int numberOfRows, int numberOfColumns) {
ArrayRowCanonize(operands, dim, 2*dim);
// Check inversibility
for (int i = 0; i < dim; i++) {
if (std::abs(operands[i*2*dim+i] - (T)1.0) > Expression::epsilon<float>()) {
if (std::abs(operands[i*2*dim+i] - (T)1.0) > Expression::Epsilon<float>()) {
return -2;
}
}
@@ -160,7 +160,7 @@ int Matrix::ArrayInverse(T * array, int numberOfRows, int numberOfColumns) {
}
Matrix Matrix::rowCanonize(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, Multiplication determinant) {
Expression::setInterruption(false);
Expression::SetInterruption(false);
// The matrix children have to be reduced to be able to spot 0
deepReduceChildren(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation);
@@ -230,7 +230,7 @@ void Matrix::ArrayRowCanonize(T * array, int numberOfRows, int numberOfColumns,
while (h < numberOfRows && k < numberOfColumns) {
// Find the first non-null pivot
int iPivot = h;
while (iPivot < numberOfRows && std::abs(array[iPivot*numberOfColumns+k]) < Expression::epsilon<double>()) {
while (iPivot < numberOfRows && std::abs(array[iPivot*numberOfColumns+k]) < Expression::Epsilon<double>()) {
iPivot++;
}
if (iPivot == numberOfRows) {

View File

@@ -28,7 +28,7 @@ namespace Poincare {
// Properties
ExpressionNode::Sign PowerNode::sign(Context * context) const {
if (Expression::shouldStopProcessing()) {
if (Expression::ShouldStopProcessing()) {
return Sign::Unknown;
}
if (childAtIndex(0)->sign(context) == Sign::Positive && childAtIndex(1)->sign(context) != Sign::Unknown) {
@@ -221,7 +221,7 @@ template<typename T> MatrixComplex<T> PowerNode::computeOnMatrixAndComplex(const
MatrixComplex<T> result = MatrixComplex<T>::createIdentity(m.numberOfRows());
// TODO: implement a quick exponentiation
for (int k = 0; k < (int)power; k++) {
if (Expression::shouldStopProcessing()) {
if (Expression::ShouldStopProcessing()) {
return MatrixComplex<T>::Undefined();
}
result = MultiplicationNode::computeOnMatrices<T>(result, m);

View File

@@ -31,7 +31,7 @@ Evaluation<T> SequenceNode::templatedApproximate(Context& context, Preferences::
VariableContext nContext = VariableContext(static_cast<SymbolNode *>(childAtIndex(1))->name(), &context);
Evaluation<T> result = Complex<T>((T)emptySequenceValue());
for (int i = (int)start; i <= (int)end; i++) {
if (Expression::shouldStopProcessing()) {
if (Expression::ShouldStopProcessing()) {
return Complex<T>::Undefined();
}
nContext.setApproximationForVariable<T>((T)i);

View File

@@ -87,7 +87,7 @@ Expression Store::shallowReduce(Context & context, Preferences::ComplexFormat co
e = reducedE;
}
// Restore the previous interruption flag
setInterruption(interruptedSimplification);
SetInterruption(interruptedSimplification);
replaceWithInPlace(e);
return e;

View File

@@ -455,7 +455,7 @@ Expression Trigonometry::table(const Expression e, ExpressionNode::Type type, Co
}
for (int i = 0; i < k_numberOfEntries; i++) {
float inputValue = cheatTable[i][inputIndex].value;
if (std::isnan(inputValue) || std::fabs(inputValue-eValue) > Expression::epsilon<float>()) {
if (std::isnan(inputValue) || std::fabs(inputValue-eValue) > Expression::Epsilon<float>()) {
continue;
}
// Our given expression approximation matches a table entry, we check that both expressions are identical
@@ -502,8 +502,8 @@ T Trigonometry::RoundToMeaningfulDigits(T result, T input) {
* have sin(pi) ~ 0 and sin(1E-15)=1E-15.
* We can't do that for all evaluation as the user can operate on values as
* small as 1E-308 (in double) and most results still be correct. */
if (input == 0.0 || std::fabs(result/input) <= Expression::epsilon<T>()) {
T precision = 10*Expression::epsilon<T>();
if (input == 0.0 || std::fabs(result/input) <= Expression::Epsilon<T>()) {
T precision = 10*Expression::Epsilon<T>();
result = std::round(result/precision)*precision;
}
return result;

View File

@@ -166,7 +166,7 @@ template<typename T>
void assert_parsed_expression_approximates_with_value_for_symbol(Expression expression, const char * symbol, T value, T approximation, Poincare::Preferences::ComplexFormat complexFormat, Poincare::Preferences::AngleUnit angleUnit) {
Shared::GlobalContext globalContext;
T result = expression.approximateWithValueForSymbol(symbol, value, globalContext, complexFormat, angleUnit);
quiz_assert((std::isnan(result) && std::isnan(approximation)) || std::fabs(result - approximation) < 10.0*Expression::epsilon<T>());
quiz_assert((std::isnan(result) && std::isnan(approximation)) || std::fabs(result - approximation) < 10.0*Expression::Epsilon<T>());
}
void assert_parsed_expression_simplify_to(const char * expression, const char * simplifiedExpression, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) {