mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-24 00:00:44 +01:00
[poincare] Use shortcut constructor Rational(Integer())->Rational()
Change-Id: I4af40105e19b3ee94fefd5cdc5dc4d20e76f8f52
This commit is contained in:
@@ -110,7 +110,7 @@ Expression * Logarithm::splitInteger(Integer i, bool isDenominator, Context & co
|
||||
Expression * Logarithm::shallowBeautify(Context & context, AngleUnit angleUnit) {
|
||||
Symbol e = Symbol(Ion::Charset::Exponential);
|
||||
const Expression * op = operand(0);
|
||||
Rational one = Rational(Integer(1));
|
||||
Rational one(1);
|
||||
if (numberOfOperands() == 2 && (operand(1)->isIdenticalTo(&e) || operand(1)->isIdenticalTo(&one))) {
|
||||
detachOperand(op);
|
||||
Expression * nl = operand(1)->isIdenticalTo(&e) ? static_cast<Expression *>(new NaperianLogarithm(op, false)) : static_cast<Expression *> (new Logarithm(op, false));
|
||||
|
||||
@@ -120,7 +120,7 @@ Expression * Multiplication::shallowReduce(Context& context, AngleUnit angleUnit
|
||||
}
|
||||
/* Step 2: If any of the operand is zero, the multiplication result is zero */
|
||||
for (int i = 0; i < numberOfOperands(); i++) {
|
||||
Expression * o = editableOperand(i++);
|
||||
Expression * o = editableOperand(i);
|
||||
if (o->type() == Type::Rational && static_cast<const Rational *>(o)->isZero()) {
|
||||
return replaceWith(new Rational(0), true);
|
||||
}
|
||||
@@ -188,8 +188,8 @@ Expression * Multiplication::resolveSquareRootAtDenominator(Context & context, A
|
||||
if (o->type() == Type::Power && o->operand(0)->type() == Type::Rational && o->operand(1)->type() == Type::Rational && static_cast<const Rational *>(o->operand(1))->isMinusHalf()) {
|
||||
Integer p = static_cast<const Rational *>(o->operand(0))->numerator();
|
||||
Integer q = static_cast<const Rational *>(o->operand(0))->denominator();
|
||||
Power * sqrt = new Power(new Rational(Integer::Multiplication(p, q)), new Rational(Integer(1), Integer(2)), false);
|
||||
replaceOperand(o, new Rational(Integer(1), Integer(p)), true);
|
||||
Power * sqrt = new Power(new Rational(Integer::Multiplication(p, q)), new Rational(1, 2), false);
|
||||
replaceOperand(o, new Rational(Integer(1), p), true);
|
||||
Expression * newExpression = shallowReduce(context, angleUnit);
|
||||
if (newExpression->type() == Type::Multiplication) {
|
||||
static_cast<Multiplication *>(newExpression)->addOperand(sqrt);
|
||||
@@ -223,8 +223,8 @@ Expression * Multiplication::resolveSquareRootAtDenominator(Context & context, A
|
||||
Integer::Power(n2, Integer(2)),
|
||||
Integer::Power(d1, Integer(2))),
|
||||
Integer::Multiplication(p2, q1)));
|
||||
Power * sqrt1 = new Power(new Rational(Integer::Multiplication(p1, q1)), new Rational(Integer(1), Integer(2)), false);
|
||||
Power * sqrt2 = new Power(new Rational(Integer::Multiplication(p2, q2)), new Rational(Integer(1), Integer(2)), false);
|
||||
Power * sqrt1 = new Power(new Rational(Integer::Multiplication(p1, q1)), new Rational(1, 2), false);
|
||||
Power * sqrt2 = new Power(new Rational(Integer::Multiplication(p2, q2)), new Rational(1, 2), false);
|
||||
Integer factor1 = Integer::Multiplication(
|
||||
Integer::Multiplication(n1, d1),
|
||||
Integer::Multiplication(Integer::Power(d2, Integer(2)), q2));
|
||||
|
||||
@@ -131,7 +131,7 @@ int Power::simplificationOrderGreaterType(const Expression * e) const {
|
||||
if (baseComparison != 0) {
|
||||
return baseComparison;
|
||||
}
|
||||
Rational one(Integer(1));
|
||||
Rational one(1);
|
||||
return SimplificationOrder(operand(1), &one);
|
||||
}
|
||||
|
||||
@@ -282,8 +282,8 @@ Expression * Power::CreateSimplifiedIntegerRationalPower(Integer i, Rational * r
|
||||
Integer coefficients[Arithmetic::k_maxNumberOfPrimeFactors];
|
||||
Arithmetic::PrimeFactorization(&i, factors, coefficients, Arithmetic::k_maxNumberOfPrimeFactors);
|
||||
|
||||
Integer r1 = Integer(1);
|
||||
Integer r2 = Integer(1);
|
||||
Integer r1(1);
|
||||
Integer r2(1);
|
||||
int index = 0;
|
||||
while (!coefficients[index].isZero() && index < Arithmetic::k_maxNumberOfPrimeFactors) {
|
||||
Integer n = Integer::Multiplication(coefficients[index], r->numerator());
|
||||
@@ -363,8 +363,8 @@ Expression * Power::resolveSquareRootAtDenominator(Context & context, AngleUnit
|
||||
if (operand(0)->type() == Type::Rational && operand(1)->type() == Type::Rational && static_cast<const Rational *>(operand(1))->isMinusHalf()) {
|
||||
Integer p = static_cast<const Rational *>(operand(0))->numerator();
|
||||
Integer q = static_cast<const Rational *>(operand(0))->denominator();
|
||||
Power * sqrt = new Power(new Rational(Integer::Multiplication(p, q)), new Rational(Integer(1), Integer(2)), false);
|
||||
Expression * newExpression = new Multiplication(new Rational(Integer(1), Integer(p)), sqrt, false);
|
||||
Power * sqrt = new Power(new Rational(Integer::Multiplication(p, q)), new Rational(1, 2), false);
|
||||
Expression * newExpression = new Multiplication(new Rational(Integer(1), p), sqrt, false);
|
||||
sqrt->shallowReduce(context, angleUnit);
|
||||
return replaceWith(newExpression, true);
|
||||
} else if (operand(1)->type() == Type::Rational && static_cast<const Rational *>(operand(1))->isMinusOne() && operand(0)->type() == Type::Addition && operand(0)->numberOfOperands() == 2 && TermIsARationalSquareRootOrRational(operand(0)->operand(0)) && TermIsARationalSquareRootOrRational(operand(0)->operand(1))) {
|
||||
@@ -392,8 +392,8 @@ Expression * Power::resolveSquareRootAtDenominator(Context & context, AngleUnit
|
||||
Integer::Power(n2, Integer(2)),
|
||||
Integer::Power(d1, Integer(2))),
|
||||
Integer::Multiplication(p2, q1)));
|
||||
Power * sqrt1 = new Power(new Rational(Integer::Multiplication(p1, q1)), new Rational(Integer(1), Integer(2)), false);
|
||||
Power * sqrt2 = new Power(new Rational(Integer::Multiplication(p2, q2)), new Rational(Integer(1), Integer(2)), false);
|
||||
Power * sqrt1 = new Power(new Rational(Integer::Multiplication(p1, q1)), new Rational(1, 2), false);
|
||||
Power * sqrt2 = new Power(new Rational(Integer::Multiplication(p2, q2)), new Rational(1, 2), false);
|
||||
Integer factor1 = Integer::Multiplication(
|
||||
Integer::Multiplication(n1, d1),
|
||||
Integer::Multiplication(Integer::Power(d2, Integer(2)), q2));
|
||||
|
||||
@@ -33,7 +33,7 @@ Complex<T> SquareRoot::computeOnComplex(const Complex<T> c, AngleUnit angleUnit)
|
||||
}
|
||||
|
||||
Expression * SquareRoot::shallowReduce(Context& context, AngleUnit angleUnit) {
|
||||
Power * p = new Power(operand(0), new Rational(Integer(1), Integer(2)), false);
|
||||
Power * p = new Power(operand(0), new Rational(1, 2), false);
|
||||
detachOperands();
|
||||
replaceWith(p, true);
|
||||
return p->shallowReduce(context, angleUnit);
|
||||
|
||||
Reference in New Issue
Block a user