mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[poincare] Rename isRationalZero to isNumberZero
Change-Id: I554dd5e9b9ab3af4364ca23cde590f9e0a458ef8
This commit is contained in:
committed by
Émilie Feral
parent
58114255e5
commit
98499f6c9f
@@ -51,7 +51,7 @@ void MatrixListController::setExpression(Poincare::Expression e) {
|
||||
m_layouts[index++] = getLayoutFromExpression(determinant, context, preferences);
|
||||
// 2. Matrix inverse if invertible matrix
|
||||
// A squared matrix is invertible if and only if determinant is non null
|
||||
if (!determinant.isUndefined() && !determinant.isRationalZero()) {
|
||||
if (!determinant.isUndefined() && !determinant.isNumberZero()) {
|
||||
m_indexMessageMap[index] = messageIndex++;
|
||||
m_layouts[index++] = getLayoutFromExpression(MatrixInverse::Builder(m_expression.clone()), context, preferences);
|
||||
}
|
||||
|
||||
@@ -316,12 +316,12 @@ EquationStore::Error EquationStore::resolveLinearSystem(Expression exactSolution
|
||||
for (int j = m-1; j >= 0; j--) {
|
||||
bool rowWithNullCoefficients = true;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (!Ab.matrixChild(j, i).isRationalZero()) {
|
||||
if (!Ab.matrixChild(j, i).isNumberZero()) {
|
||||
rowWithNullCoefficients = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rowWithNullCoefficients && !Ab.matrixChild(j, n).isRationalZero()) {
|
||||
if (rowWithNullCoefficients && !Ab.matrixChild(j, n).isNumberZero()) {
|
||||
m_numberOfSolutions = 0;
|
||||
}
|
||||
}
|
||||
@@ -348,7 +348,7 @@ EquationStore::Error EquationStore::oneDimensialPolynomialSolve(Expression exact
|
||||
if (delta.isUninitialized()) {
|
||||
delta = Poincare::Undefined::Builder();
|
||||
}
|
||||
if (delta.isRationalZero()) {
|
||||
if (delta.isNumberZero()) {
|
||||
// if delta = 0, x0=x1= -b/(2a)
|
||||
exactSolutions[0] = Division::Builder(Opposite::Builder(coefficients[1]), Multiplication::Builder(Rational::Builder(2), coefficients[2]));
|
||||
m_numberOfSolutions = 2;
|
||||
@@ -383,8 +383,8 @@ EquationStore::Error EquationStore::oneDimensialPolynomialSolve(Expression exact
|
||||
Expression * mult5Operands[3] = {new Rational::Builder(3), a->clone(), c->clone()};
|
||||
Expression * delta0 = new Subtraction::Builder(new Power::Builder(b->clone(), new Rational::Builder(2), false), new Multiplication::Builder(mult5Operands, 3, false), false);
|
||||
Reduce(&delta0, *context);
|
||||
if (delta->isRationalZero()) {
|
||||
if (delta0->isRationalZero()) {
|
||||
if (delta->isNumberZero()) {
|
||||
if (delta0->isNumberZero()) {
|
||||
// delta0 = 0 && delta = 0 --> x0 = -b/(3a)
|
||||
delete delta0;
|
||||
m_exactSolutions[0] = new Opposite::Builder(new Division::Builder(b, new Multiplication::Builder(new Rational::Builder(3), a, false), false), false);
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
// Expression subclassing
|
||||
Type type() const override { return Type::BasedInteger; }
|
||||
Sign sign(Context * context) const override { return Sign::Positive; }
|
||||
bool isRationalZero() const override { return integer().isZero(); }
|
||||
bool isNumberZero() const override { return integer().isZero(); }
|
||||
|
||||
// Layout
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
Type type() const override { return Type::Decimal; }
|
||||
Sign sign(Context * context) const override { return m_negative ? Sign::Negative : Sign::Positive; }
|
||||
Expression setSign(Sign s, ReductionContext reductionContext) override;
|
||||
bool isRationalZero() const override { return unsignedMantissa().isZero(); }
|
||||
bool isNumberZero() const override { return unsignedMantissa().isZero(); }
|
||||
|
||||
// Approximation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -153,7 +153,7 @@ public:
|
||||
ExpressionNode::Sign sign(Context * context) const { return node()->sign(context); }
|
||||
bool isUndefined() const { return node()->type() == ExpressionNode::Type::Undefined || node()->type() == ExpressionNode::Type::Unreal; }
|
||||
bool isNumber() const { return node()->isNumber(); }
|
||||
bool isRationalZero() const { return node()->isRationalZero(); }
|
||||
bool isNumberZero() const { return node()->isNumberZero(); }
|
||||
bool isRationalOne() const;
|
||||
bool isRandom() const { return node()->isRandom(); }
|
||||
bool isParameteredExpression() const { return node()->isParameteredExpression(); }
|
||||
|
||||
@@ -187,7 +187,7 @@ public:
|
||||
|
||||
virtual Sign sign(Context * context) const { return Sign::Unknown; }
|
||||
virtual bool isNumber() const { return false; }
|
||||
virtual bool isRationalZero() const { return false; }
|
||||
virtual bool isNumberZero() const { return false; }
|
||||
virtual bool isRandom() const { return false; }
|
||||
virtual bool isParameteredExpression() const { return false; }
|
||||
/* childAtIndexNeedsUserParentheses checks if parentheses are required by mathematical rules:
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
Sign sign(Context * context) const override { return m_value < 0 ? Sign::Negative : Sign::Positive; }
|
||||
Expression setSign(Sign s, ReductionContext reductionContext) override;
|
||||
int simplificationOrderSameType(const ExpressionNode * e, bool ascending, bool canBeInterrupted, bool ignoreParentheses) const override;
|
||||
bool isRationalZero() const override { return m_value == 0.0; }
|
||||
bool isNumberZero() const override { return m_value == 0.0; }
|
||||
|
||||
// Layout
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
@@ -17,7 +17,7 @@ private:
|
||||
LayoutShape leftLayoutShape() const override { return LayoutShape::MoreLetters; };
|
||||
LayoutShape rightLayoutShape() const override { return LayoutShape::BoundaryPunctuation; }
|
||||
Expression shallowReduce(ReductionContext reductionContext) override;
|
||||
virtual bool isNotableValue(Expression e) const { return e.isRationalZero(); }
|
||||
virtual bool isNotableValue(Expression e) const { return e.isNumberZero(); }
|
||||
virtual Expression imageOfNotableValue() const { return Rational::Builder(0); }
|
||||
};
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
bool isNegative() const { return m_negative; }
|
||||
void setNegative(bool negative) { m_negative = negative; }
|
||||
bool isInteger() const { return denominator().isOne(); }
|
||||
bool isRationalZero() const override { return isZero(); }
|
||||
bool isNumberZero() const override { return isZero(); }
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override;
|
||||
|
||||
@@ -60,7 +60,7 @@ Expression ComplexCartesian::shallowReduce() {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
if (imag().isRationalZero()) {
|
||||
if (imag().isNumberZero()) {
|
||||
Expression r = real();
|
||||
replaceWithInPlace(r);
|
||||
return r;
|
||||
@@ -128,9 +128,9 @@ Expression ComplexCartesian::squareNorm(ExpressionNode::ReductionContext reducti
|
||||
Expression ComplexCartesian::norm(ExpressionNode::ReductionContext reductionContext) {
|
||||
Expression a;
|
||||
// Special case for pure real or pure imaginary cartesian
|
||||
if (imag().isRationalZero()) {
|
||||
if (imag().isNumberZero()) {
|
||||
a = real();
|
||||
} else if (real().isRationalZero()) {
|
||||
} else if (real().isNumberZero()) {
|
||||
a = imag();
|
||||
}
|
||||
if (!a.isUninitialized()) {
|
||||
@@ -149,7 +149,7 @@ Expression ComplexCartesian::norm(ExpressionNode::ReductionContext reductionCont
|
||||
Expression ComplexCartesian::argument(ExpressionNode::ReductionContext reductionContext) {
|
||||
Expression a = real();
|
||||
Expression b = imag();
|
||||
if (!b.isRationalZero()) {
|
||||
if (!b.isNumberZero()) {
|
||||
// if b != 0, argument = sign(b) * π/2 - atan(a/b)
|
||||
// First, compute atan(a/b) or (π/180)*atan(a/b)
|
||||
Expression divab = Division::Builder(a, b.clone());
|
||||
@@ -242,11 +242,11 @@ ComplexCartesian ComplexCartesian::powerInteger(int n, ExpressionNode::Reduction
|
||||
Expression a = real();
|
||||
Expression b = imag();
|
||||
assert(n > 0);
|
||||
assert(!b.isRationalZero());
|
||||
assert(!b.isNumberZero());
|
||||
|
||||
// Special case: a == 0 (otherwise, we are going to introduce undefined expressions - a^0 = NAN)
|
||||
// (b*i)^n = b^n*i^n with i^n == i, -i, 1 or -1
|
||||
if (a.isRationalZero()) {
|
||||
if (a.isNumberZero()) {
|
||||
ComplexCartesian result;
|
||||
Expression bpow = Power::Builder(b, Rational::Builder(n));
|
||||
if (n/2%2 == 1) {
|
||||
|
||||
@@ -136,7 +136,7 @@ int Matrix::rank(Context * context, Preferences::ComplexFormat complexFormat, Pr
|
||||
int i = rank-1;
|
||||
while (i >= 0) {
|
||||
int j = m.numberOfColumns()-1;
|
||||
while (j >= i && matrixChild(i,j).isRationalZero()) {
|
||||
while (j >= i && matrixChild(i,j).isNumberZero()) {
|
||||
j--;
|
||||
}
|
||||
if (j == i-1) {
|
||||
@@ -225,7 +225,7 @@ Matrix Matrix::rowCanonize(ExpressionNode::ReductionContext reductionContext, Ex
|
||||
// Using float to find the biggest pivot is sufficient.
|
||||
float pivot = AbsoluteValue::Builder(matrixChild(iPivot_temp, k).clone()).approximateToScalar<float>(reductionContext.context(), reductionContext.complexFormat(), reductionContext.angleUnit());
|
||||
// Handle very low pivots
|
||||
if (pivot == 0.0f && !matrixChild(iPivot_temp, k).isRationalZero()) {
|
||||
if (pivot == 0.0f && !matrixChild(iPivot_temp, k).isNumberZero()) {
|
||||
pivot = FLT_MIN;
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ Matrix Matrix::rowCanonize(ExpressionNode::ReductionContext reductionContext, Ex
|
||||
}
|
||||
iPivot_temp++;
|
||||
}
|
||||
if (matrixChild(iPivot, k).isRationalZero()) {
|
||||
if (matrixChild(iPivot, k).isNumberZero()) {
|
||||
// No non-null coefficient in this column, skip
|
||||
k++;
|
||||
if (determinant) {
|
||||
|
||||
@@ -1123,7 +1123,7 @@ bool Multiplication::TermsCanSafelyCombineExponents(const Expression & e1, const
|
||||
Expression base = Base(e1);
|
||||
ExpressionNode::Sign baseSign = base.sign(reductionContext.context());
|
||||
|
||||
if (baseSign != ExpressionNode::Sign::Unknown && !base.isRationalZero()) {
|
||||
if (baseSign != ExpressionNode::Sign::Unknown && !base.isNumberZero()) {
|
||||
// x cannot be null
|
||||
return true;
|
||||
}
|
||||
@@ -1133,8 +1133,8 @@ bool Multiplication::TermsCanSafelyCombineExponents(const Expression & e1, const
|
||||
Expression exponent2 = CreateExponent(e2);
|
||||
ExpressionNode::Sign exponentSign2 = exponent2.sign(reductionContext.context());
|
||||
|
||||
if (exponentSign1 == ExpressionNode::Sign::Positive && !exponent1.isRationalZero()
|
||||
&& exponentSign2 == ExpressionNode::Sign::Positive && !exponent2.isRationalZero()) {
|
||||
if (exponentSign1 == ExpressionNode::Sign::Positive && !exponent1.isNumberZero()
|
||||
&& exponentSign2 == ExpressionNode::Sign::Positive && !exponent2.isNumberZero()) {
|
||||
// a and b are strictly positive
|
||||
return true;
|
||||
}
|
||||
@@ -1142,7 +1142,7 @@ bool Multiplication::TermsCanSafelyCombineExponents(const Expression & e1, const
|
||||
Expression sum = Addition::Builder(exponent1, exponent2).shallowReduce(reductionContext);
|
||||
ExpressionNode::Sign sumSign = sum.sign(reductionContext.context());
|
||||
|
||||
if (sumSign == ExpressionNode::Sign::Negative || sum.isRationalZero()) {
|
||||
if (sumSign == ExpressionNode::Sign::Negative || sum.isNumberZero()) {
|
||||
// a+b is negative or null
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -501,7 +501,7 @@ Expression Power::shallowReduce(ExpressionNode::ReductionContext reductionContex
|
||||
// x^0
|
||||
if (rationalIndex.isZero()) {
|
||||
// 0^0 = undef or (±inf)^0 = undef
|
||||
if (base.isRationalZero() || baseType == ExpressionNode::Type::Infinity) {
|
||||
if (base.isNumberZero() || baseType == ExpressionNode::Type::Infinity) {
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
// x^0
|
||||
|
||||
Reference in New Issue
Block a user