@@ -180,24 +180,48 @@ node is Floorf or Ceilf or Roundf or Signumf
180180 /// <a href="https://github.com/asc-community/AngouriMath/issues/719">#719</a>,
181181 /// <a href="https://github.com/asc-community/AngouriMath/issues/596">#596</a>
182182 /// </remarks>
183- private static Entity ? WhereBothSidesAgree ( Entity expr , Variable x , Entity dest )
183+ private static Entity ? WhereBothSidesAgree ( Entity expr , Variable x , Entity dest , out bool aSideIsUndecided )
184184 {
185+ // Set where no answer came because a side has none yet, rather than because a side
186+ // does not exist or the two differ. Neither side is then known to be NaN, so neither
187+ // is the limit: x floor(2/x) at 0 is 2 from each side, the one-sided paths do not
188+ // decide it, and the two-sided one answered NaN.
189+ aSideIsUndecided = false ;
185190 if ( bothSidesDepth >= MaxBothSidesDepth
186191 || MathS . Settings . Codomain . Value is not AngouriMath . Core . Domain . Real && ! IsRealOnBothSides ( expr , x , dest ) )
187192 return null ;
188193 bothSidesDepth ++ ;
189194 try
190195 {
191- if ( ComputeLimit ( expr , x , dest , ApproachFrom . Left ) is not { } fromLeft
192- || fromLeft . Evaled == MathS . NaN )
196+ var fromLeft = Decided ( ComputeLimit ( expr , x , dest , ApproachFrom . Left ) ) ;
197+ if ( fromLeft ? . Evaled == MathS . NaN )
193198 return null ;
194- if ( ComputeLimit ( expr , x , dest , ApproachFrom . Right ) is not { } fromRight
195- || fromRight . Evaled == MathS . NaN )
199+ // A side that does not exist settles the question whatever the other side does,
200+ // so the right is still asked when the left is undecided.
201+ var fromRight = Decided ( ComputeLimit ( expr , x , dest , ApproachFrom . Right ) ) ;
202+ if ( fromRight ? . Evaled == MathS . NaN )
196203 return null ;
204+ if ( fromLeft is null || fromRight is null )
205+ {
206+ aSideIsUndecided = true ;
207+ return null ;
208+ }
197209 return fromLeft == fromRight || ExpressionNumerical . AreEqual ( fromLeft , fromRight )
198210 ? fromLeft : null ;
199211 }
200212 finally { bothSidesDepth -- ; }
213+
214+ // An indeterminate form a side's own limit could not read is NaN inside the machinery,
215+ // where it stops the search, and withheld at the outermost call, where it is not an
216+ // answer. One with an infinity in it, 0 * floor(-oo) for x floor(2/x), is a product or
217+ // a quotient of parts whose rates were never compared, so that side is undecided rather
218+ // than absent. One of finite parts only stays a side without a limit, as before: 0 / 0
219+ // for (x - x) / (x - x), which has no value anywhere, and ln(-2) / 0 for ln(-2) / ln(x)
220+ // at 1, whose sides are infinities in different directions.
221+ static Entity ? Decided ( Entity ? limit )
222+ => limit is { } && IsAnIndeterminateForm ( limit )
223+ && limit . Nodes . Any ( static node => node is Real { IsFinite : false } )
224+ ? null : limit ;
201225 }
202226
203227 /// <summary>
@@ -719,9 +743,13 @@ node is Derivativef(var expression, Variable variable, var iterations) && iterat
719743 // again: tan(x/2) at pi, +oo and -oo, asked both sides through the whole of the
720744 // machinery each time, and a definite integral over [0, pi] spent its budget of
721745 // limits on that.
722- if ( ( fromLeft . Evaled == MathS . NaN || fromRight . Evaled == MathS . NaN )
723- && WhereBothSidesAgree ( expr , x , dest ) is { } agreed )
724- return agreed ;
746+ if ( fromLeft . Evaled == MathS . NaN || fromRight . Evaled == MathS . NaN )
747+ {
748+ if ( WhereBothSidesAgree ( expr , x , dest , out var aSideIsUndecided ) is { } agreed )
749+ return agreed ;
750+ if ( aSideIsUndecided )
751+ return null ;
752+ }
725753 return MathS . NaN ; // A two-sided limit cannot exist if the limit from left and right don't match.
726754 }
727755 else
@@ -734,7 +762,7 @@ node is Derivativef(var expression, Variable variable, var iterations) && iterat
734762 // something that disagrees -- which is most of what the one-sided
735763 // fallbacks are for, so it is where the promotion is worth the most.
736764 // https://github.com/asc-community/AngouriMath/issues/719
737- return WhereBothSidesAgree ( expr , x , dest ) ;
765+ return WhereBothSidesAgree ( expr , x , dest , out _ ) ;
738766 }
739767 }
740768 throw new AngouriBugException ( $ "Unresolved enum parameter { side } ") ;
0 commit comments