From 4cc3542a99249c5650253cb0b54bdfd5558e21f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 3 Nov 2020 17:40:16 +0100 Subject: [PATCH] [poincare] Sequence: when approximating within a reduce routine, escape to avoid infinite loop --- poincare/src/sequence.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/poincare/src/sequence.cpp b/poincare/src/sequence.cpp index 82f2023aa..a86ed08ea 100644 --- a/poincare/src/sequence.cpp +++ b/poincare/src/sequence.cpp @@ -63,7 +63,16 @@ Evaluation SequenceNode::approximate(DoublePrecision p, ApproximationCon template Evaluation SequenceNode::templatedApproximate(ApproximationContext approximationContext) const { - if (childAtIndex(0)->approximate((T)1, approximationContext).isUndefined()) { + if (childAtIndex(0)->approximate((T)1, approximationContext).isUndefined() || approximationContext.withinReduce()) { + /* If we're inside a reducing routine, we want to escape the sequence + * approximation. Indeed, in order to know that the sequence is well defined + * (especially for self-referencing or inter-dependently defined sequences), + * we need to reduce the sequence definition (done by calling + * 'expressionForSymbolAbstract'); if we're within a reduce routine, we + * would create an infinite loop. Returning a NAN approximation for + * sequences within reduce routine does not really matter: we just have + * access to less information in order to simplify (abs(u(n)) might not be + * reduced for instance). */ return Complex::Undefined(); } Expression e = approximationContext.context()->expressionForSymbolAbstract(this, false);