diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index fef242492..26a660c36 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -348,8 +348,8 @@ Expression Power::shallowReduce(Context & context, Preferences::ComplexFormat co const Rational b = childAtIndex(1).convert(); // x^0 if (b.isZero()) { - // 0^0 = undef - if (childAtIndex(0).type() == ExpressionNode::Type::Rational && childAtIndex(0).convert().isZero()) { + // 0^0 = undef or (±inf)^0 = undef + if ((childAtIndex(0).type() == ExpressionNode::Type::Rational && childAtIndex(0).convert().isZero()) || childAtIndex(0).type() == ExpressionNode::Type::Infinity) { Expression result = Undefined(); replaceWithInPlace(result); return result; @@ -376,19 +376,21 @@ Expression Power::shallowReduce(Context & context, Preferences::ComplexFormat co Rational a = childAtIndex(0).convert(); // 0^x if (a.isZero()) { + // 0^x with x > 0 = 0 if (childAtIndex(1).sign(&context) == ExpressionNode::Sign::Positive) { Expression result = Rational(0); replaceWithInPlace(result); return result; } + // 0^x with x < 0 = undef if (childAtIndex(1).sign(&context) == ExpressionNode::Sign::Negative) { Expression result = Undefined(); replaceWithInPlace(result); return result; } } - // 1^x - if (a.isOne()) { + // 1^x = 1 if x != ±inf + if (a.isOne() && !childAtIndex(1).recursivelyMatchesInfinity(context)) { Expression result = Rational(1); replaceWithInPlace(result); return result; diff --git a/poincare/test/infinity.cpp b/poincare/test/infinity.cpp index c80735c0e..c84e8765f 100644 --- a/poincare/test/infinity.cpp +++ b/poincare/test/infinity.cpp @@ -24,6 +24,9 @@ QUIZ_CASE(poincare_infinity) { assert_parsed_expression_simplify_to("1E-1000", "0"); assert_parsed_expression_evaluates_to("1*10^1000", "inf"); + assert_parsed_expression_simplify_to("inf^0", "undef"); + assert_parsed_expression_simplify_to("1^inf", "1^inf"); + assert_parsed_expression_simplify_to("1^(X^inf)", "1^(X^inf)"); assert_parsed_expression_simplify_to("inf^(-1)", "0"); assert_parsed_expression_simplify_to("(-inf)^(-1)", "0"); assert_parsed_expression_simplify_to("inf^(-R(2))", "0");