From 48bd7b6a770cfdea8dd86ac85495036bf73f7f5c Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Wed, 2 Dec 2020 15:19:49 +0100 Subject: [PATCH] [poincare/logarithm] Factor corner case log(x,0) and log(x,1) --- poincare/src/logarithm.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/poincare/src/logarithm.cpp b/poincare/src/logarithm.cpp index c38076685..a9faf8020 100644 --- a/poincare/src/logarithm.cpp +++ b/poincare/src/logarithm.cpp @@ -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(b).isOne()) { - return replaceWithUndefinedInPlace(); - } - // log(x,0) -> undef - if (b.type() == ExpressionNode::Type::Rational && static_cast(b).isZero()) { + // log(x,0) = log(x,1) = undef + if (b.type() == ExpressionNode::Type::Rational && (static_cast(b).isZero() || static_cast(b).isOne())) { return replaceWithUndefinedInPlace(); } if (c.type() == ExpressionNode::Type::Rational) { const Rational r = static_cast(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() : Rational::Builder(1).convert(); replaceWithInPlace(result);