Repository: sympy/sympy

Issue:
Type error in evaluating Fresnel-like integral
### Error

When evaluating a [Fresnel-like](https://en.wikipedia.org/wiki/Fresnel_integral) integral, a type error occurs when some code attempts to iterate over an `Interval`.

The integral is a slight generalization of the Fresnel integral. Specifically, it is `exp(-x^2 * cos(2 * theta)) * cos(x^2 * sin(2 * theta))` from `x = 0` to `x = oo`. The correct result, for appropriate values of `theta`, is `sqrt(pi) / 2 * cos(theta)`. I didn't expect the correct result to be returned, but I at least expected an unevaluated integral.

### Traceback

```python
>>> from sympy import cos, sin, exp, integrate, oo
>>> from sympy.abc import x, theta
>>> integrate(exp(-x**2 * cos(2 * theta)) * cos(x**2 * sin(2 * theta)), (x, 0, oo))
Traceback (most recent call last):
  File "<ipython-input-14-5b088a60a3a5>", line 1, in <module>
    integrate(exp(-x**2 * cos(2 * theta)) * cos(x**2 * sin(2 * theta)), (x, 0, oo))
  File "/home/rwb/Dropbox/sympy/sympy/integrals/integrals.py", line 1465, in integrate
    risch=risch, manual=manual)
  File "/home/rwb/Dropbox/sympy/sympy/integrals/integrals.py", line 521, in doit
    ret = try_meijerg(function, xab)
  File "/home/rwb/Dropbox/sympy/sympy/integrals/integrals.py", line 505, in try_meijerg
    function, (x, a, b)), True))
  File "/home/rwb/Dropbox/sympy/sympy/functions/elementary/piecewise.py", line 138, in __new__
    r = cls.eval(*newargs)
  File "/home/rwb/Dropbox/sympy/sympy/functions/elementary/piecewise.py", line 187, in eval
    c = c.as_set().as_relational(x)
  File "/home/rwb/Dropbox/sympy/sympy/logic/boolalg.py", line 147, in as_set
    s = r._eval_as_set()
  File "/home/rwb/Dropbox/sympy/sympy/core/relational.py", line 239, in _eval_as_set
    return solve_univariate_inequality(self, x, relational=False)
  File "/home/rwb/Dropbox/sympy/sympy/solvers/inequalities.py", line 492, in solve_univariate_inequality
    frange = function_range(e, gen, domain)
  File "/home/rwb/Dropbox/sympy/sympy/calculus/util.py", line 175, in function_range
    for critical_point in critical_points:
TypeError: 'Interval' object is not iterable
```



Discussion:

Patch:
diff --git a/sympy/calculus/util.py b/sympy/calculus/util.py
index 3019a2a8ca..37f7781acd 100644
--- a/sympy/calculus/util.py
+++ b/sympy/calculus/util.py
@@ -12,6 +12,7 @@
 from sympy.utilities import filldedent
 from sympy.simplify.radsimp import denom
 from sympy.polys.rationaltools import together
+from sympy.core.compatibility import iterable
 
 def continuous_domain(f, symbol, domain):
     """
@@ -167,7 +168,7 @@ def function_range(f, symbol, domain):
 
             solution = solveset(f.diff(symbol), symbol, interval)
 
-            if isinstance(solution, ConditionSet):
+            if not iterable(solution):
                 raise NotImplementedError('Unable to find critical points for {}'.format(f))
 
             critical_points += solution


Test patch:
diff --git a/sympy/integrals/tests/test_integrals.py b/sympy/integrals/tests/test_integrals.py
index 8432db5172..b186c30dc6 100644
--- a/sympy/integrals/tests/test_integrals.py
+++ b/sympy/integrals/tests/test_integrals.py
@@ -1,8 +1,8 @@
 from sympy import (
     Abs, acos, acosh, Add, And, asin, asinh, atan, Ci, cos, sinh, cosh,
     tanh, Derivative, diff, DiracDelta, E, Ei, Eq, exp, erf, erfi,
-    EulerGamma, Expr, factor, Function, gamma, I, Idx, im, IndexedBase, Integral, integrate,
-    Interval, Lambda, LambertW, log, Matrix, Max, meijerg, Min, nan,
+    EulerGamma, Expr, factor, Function, gamma, gammasimp, I, Idx, im, IndexedBase,
+    Integral, integrate, Interval, Lambda, LambertW, log, Matrix, Max, meijerg, Min, nan,
     Ne, O, oo, pi, Piecewise, polar_lift, Poly, polygamma, Rational, re, S, Si, sign,
     simplify, sin, sinc, SingularityFunction, sqrt, sstr, Sum, Symbol,
     symbols, sympify, tan, trigsimp, Tuple
@@ -1408,3 +1408,9 @@ def test_issue_15124():
     m, p = symbols('m p', cls=Idx)
     assert integrate(exp(x*I*(omega[m] + omega[p])), x, conds='none') == \
         -I*exp(I*x*omega[m])*exp(I*x*omega[p])/(omega[m] + omega[p])
+
+
+def test_issue_15292():
+    res = integrate(exp(-x**2*cos(2*t)) * cos(x**2*sin(2*t)), (x, 0, oo))
+    assert isinstance(res, Piecewise)
+    assert gammasimp((res - sqrt(pi)/2 * cos(t)).subs(t, pi/6)) == 0