# Add early exit in the limit heuristics() for "bad" results with oo #2928

Merged
merged 1 commit into from Mar 22, 2014

## Conversation

Projects
None yet
3 participants
Contributor

### skirpichev commented Feb 18, 2014

 This does limit calculations in this method more fragle, which is good. An example: ``````>>> O(sin(1/x**2).contains(O(cos(1/x**2))) True `````` was wrong, just because of this limit: ``````>>> limit(sin(1/x**2)/cos(1/x**2), x, 0) sin(oo)/cos(oo) `````` PS: This problem appears in this pr #2905.

Merged

Contributor

### avichaldayal commented Feb 18, 2014

 What should be the output for:- ``````sin(x**2)/x**7 in Order((sin(x**2) + cos(x**2))/x**6, (x, oo)) `````` This is giving None now. As a result, `fresnels(z).series(z, oo)` will not stop calculating more terms till order.contains evaluates to True. I tried finding fresnel(z).series(z, oo) and it gives terms till `1/z**23` whereas it should stop after `1/z**6`
Contributor

### skirpichev commented Feb 18, 2014

 This is giving None now. Bad news. But it's better then it was before, for example: ``````In [5]: limit(sin(x**2)/x**7/(cos(x**2)/x**6), x, oo) Out[5]: 0 ``````
Contributor

### avichaldayal commented Feb 18, 2014

 Bad news. But it's better then it was before, for example: Yes but there are cases where limit returns the correct answer while gruntz returns error. ``````In [3]: limit((sin(z**2) + cos(z**2))/z**6, z, oo) Out[3]: 0 `````` but ``````In [4]: gruntz((sin(z**2) + cos(z**2))/z**6, z, oo) --------------------------------------------------------------------------- PoleError `````` as asymptotic series for sin and cos are not implemented around oo Maybe we can try to use limit if gruntz fails(?)
Contributor

### skirpichev commented Feb 18, 2014

 Maybe we can try to use limit if gruntz fails(?) limit was used before :)
Contributor

### avichaldayal commented Feb 18, 2014

 I meant something like:- ``````try: l = gruntz(ratio, s, point) != 0 except (PoleError, ValueError): # try limit as gruntz failed l = None ``````
Owner

### asmeurer commented Feb 19, 2014

 Maybe `limit` should get some kind of strict argument, which avoids returning things like `sin(oo)`.
Contributor

### skirpichev commented Feb 19, 2014

 Maybe limit should get some kind of strict argument, which avoids returning things like sin(oo) This seems to be an unnecessary complication. But at the end of `heuristics()` we can check if `result.has(oo)` and `result not in [oo, -oo]`. Lets raise an error in this case, how it sounds?
Owner

### asmeurer commented Feb 20, 2014

 Well, it could be useful otherwise. Sometimes people complain about "nonsense" answers like sin(oo). But at the end of heuristics() we can check if result.has(oo) and result not in [oo, -oo]. Why the second one?
Contributor

### skirpichev commented Feb 20, 2014

 Why the second one? Because heuristics() can produce "normal" infinite answers...
Owner

### asmeurer commented Feb 23, 2014

 But are those also bad in this case?
Contributor

### skirpichev commented Feb 23, 2014

 No. `bad = (S.NaN, None)`.

### skirpichev added the Series label Mar 3, 2014

 skirpichev ``` Add early exit in the limit heuristics() for "bad" results with oo ``` ``` This does limit calculations in this method more fragle, which is good. An example: >>> O(sin(1/x**2).contains(O(cos(1/x**2))) True was wrong, just because of this limit: >>> limit(sin(1/x**2)/cos(1/x**2), x, 0) sin(oo)/cos(oo)``` `b0c4d41`

Contributor

### skirpichev commented Mar 19, 2014

 @asmeurer, please take look on the new variant

### asmeurer commented on the diff Mar 22, 2014

sympy/series/order.py
 @@ -346,7 +346,10 @@ def contains(self, expr): ratio = self.expr/expr.expr ratio = powsimp(ratio, deep=True, combine='exp') for s in common_symbols: - l = limit(ratio, s, point) != 0 + try: + l = ratio.limit(s, point) != 0

#### asmeurer Mar 22, 2014

Owner

There's no difference between the method and the function, right?

Owner

### asmeurer commented Mar 22, 2014

 Given that this fixes wrong results, I'm going to merge it. I don't really care too strongly either way about things like sin(oo).

### asmeurer added a commit that referenced this pull request Mar 22, 2014

 asmeurer `Merge pull request #2928 from skirpichev/contains-use-gruntz` `Add early exit in the limit heuristics() for "bad" results with oo` `91bcfb6`

### asmeurer merged commit `91bcfb6` into sympy:masterMar 22, 2014 1 check passed

#### 1 check passed

default The Travis CI build passed
Details