[poincare/logarithm] Factor corner case log(x,0) and log(x,1)

This commit is contained in:
Gabriel Ozouf
2020-12-02 15:19:49 +01:00
committed by LeaNumworks
parent f09f06d7ac
commit 48bd7b6a77

View File

@@ -268,21 +268,17 @@ Expression Logarithm::simpleShallowReduce(ExpressionNode::ReductionContext reduc
Expression c = childAtIndex(0);
Expression b = childAtIndex(1);
// log(x,1)->Undefined
if (b.type() == ExpressionNode::Type::Rational && static_cast<Rational &>(b).isOne()) {
return replaceWithUndefinedInPlace();
}
// log(x,0) -> undef
if (b.type() == ExpressionNode::Type::Rational && static_cast<Rational &>(b).isZero()) {
// log(x,0) = log(x,1) = undef
if (b.type() == ExpressionNode::Type::Rational && (static_cast<Rational &>(b).isZero() || static_cast<Rational &>(b).isOne())) {
return replaceWithUndefinedInPlace();
}
if (c.type() == ExpressionNode::Type::Rational) {
const Rational r = static_cast<Rational &>(c);
// log(0, x) = undef
// log(0,x) = undef
if (r.isZero()) {
return replaceWithUndefinedInPlace();
}
// log(1) = 0;
// log(1,x) = 0;
if (r.isOne()) {
Expression result = Rational::Builder(0);
replaceWithInPlace(result);
@@ -290,7 +286,7 @@ Expression Logarithm::simpleShallowReduce(ExpressionNode::ReductionContext reduc
}
}
bool infiniteArg = c.recursivelyMatches(Expression::IsInfinity, reductionContext.context());
// log(x,x)->1 with x != inf and log(inf,inf) = undef
// log(x,x) = 1 with x != inf, and log(inf,inf) = undef
if (c.isIdenticalTo(b)) {
Expression result = infiniteArg ? Undefined::Builder().convert<Expression>() : Rational::Builder(1).convert<Expression>();
replaceWithInPlace(result);