Ask Your Question

Revision history [back]

Simple complex definite integral fails

With Sage 10.2 on MacOS, I tried to do

t=var('t')
integral(cos(1+i*t), (t,0,1))

But I get an error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
File /private/var/tmp/sage-10.2-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/interfaces/maxima_lib.py:807, in MaximaLib.sr_integral(self, *args)
    806 try:
--> 807     return max_to_sr(maxima_eval(([max_integrate],[sr_to_max(SR(a)) for a in args])))
    808 except RuntimeError as error:

File /private/var/tmp/sage-10.2-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/libs/ecl.pyx:830, in sage.libs.ecl.EclObject.__call__ (build/cythonized/sage/libs/ecl.c:11677)()
    829 lispargs = EclObject(list(args))
--> 830 return ecl_wrap(ecl_safe_apply(self.obj,(<EclObject>lispargs).obj))
    831 

File /private/var/tmp/sage-10.2-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/libs/ecl.pyx:353, in sage.libs.ecl.ecl_safe_apply (build/cythonized/sage/libs/ecl.c:9184)()
    352     else:
--> 353         raise RuntimeError("ECL says: {}".format(message))
    354 else:

RuntimeError: ECL says: Maxima asks: Is floor((%i+1)/(2*%pi)) positive, negative or zero?

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
Cell In [82], line 1
----> 1 integral(cos(Integer(1)+i*t), (t,Integer(0),Integer(1)))

File /private/var/tmp/sage-10.2-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/misc/functional.py:791, in integral(x, *args, **kwds)
    658 """
    659 Return an indefinite or definite integral of an object ``x``.
    660 
   (...)
    788 
    789 """
    790 if hasattr(x, 'integral'):
--> 791     return x.integral(*args, **kwds)
    792 else:
    793     from sage.symbolic.ring import SR

File /private/var/tmp/sage-10.2-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/symbolic/expression.pyx:13270, in sage.symbolic.expression.Expression.integral (build/cythonized/sage/symbolic/expression.cpp:119603)()
  13268                 R = SR
  13269         return R(integral(f, v, a, b, **kwds))
> 13270     return integral(self, *args, **kwds)
  13271 
  13272 integrate = integral

File /private/var/tmp/sage-10.2-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/symbolic/integration/integral.py:1066, in integrate(expression, v, a, b, algorithm, hold)
   1064     return indefinite_integral(expression, v, hold=hold)
   1065 else:
-> 1066     return definite_integral(expression, v, a, b, hold=hold)

File /private/var/tmp/sage-10.2-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/symbolic/function.pyx:1046, in sage.symbolic.function.BuiltinFunction.__call__ (build/cythonized/sage/symbolic/function.c:15112)()
   1044 res = self._evalf_try_(*args)
   1045 if res is None:
-> 1046     res = super().__call__(
   1047             *args, coerce=coerce, hold=hold)
   1048 

File /private/var/tmp/sage-10.2-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/symbolic/function.pyx:555, in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.c:9795)()
    553             raise TypeError("arguments must be symbolic expressions")
    554 
--> 555 return call_registered_function(self._serial, self._nargs, args, hold,
    556                                 not symbolic_input, SR)
    557 

File /private/var/tmp/sage-10.2-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/symbolic/pynac_function_impl.pxi:1, in sage.symbolic.expression.call_registered_function (build/cythonized/sage/symbolic/expression.cpp:137568)()
----> 1 cpdef call_registered_function(unsigned serial,
      2                                int nargs,
      3                                list args,

File /private/var/tmp/sage-10.2-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/symbolic/pynac_function_impl.pxi:47, in sage.symbolic.expression.call_registered_function (build/cythonized/sage/symbolic/expression.cpp:137103)()
     45     for i in range(len(args)):
     46         vec.push_back((<Expression>args[i])._gobj)
---> 47     res = g_function_evalv(serial, vec, hold)
     48 elif nargs == 1:
     49     res = g_function_eval1(serial,

File /private/var/tmp/sage-10.2-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/symbolic/function.pyx:1136, in sage.symbolic.function.BuiltinFunction._evalf_or_eval_ (build/cythonized/sage/symbolic/function.c:16356)()
   1134 res = self._evalf_try_(*args)
   1135 if res is None:
-> 1136     return self._eval0_(*args)
   1137 else:
   1138     return res

File /private/var/tmp/sage-10.2-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/symbolic/integration/integral.py:254, in DefiniteIntegral._eval_(self, f, x, a, b)
    252 for integrator in self.integrators:
    253     try:
--> 254         A = integrator(*args)
    255     except (NotImplementedError, TypeError,
    256             AttributeError, RuntimeError):
    257         pass

File /private/var/tmp/sage-10.2-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/symbolic/integration/external.py:46, in maxima_integrator(expression, v, a, b)
     44     result = maxima.sr_integral(expression, v)
     45 else:
---> 46     result = maxima.sr_integral(expression, v, a, b)
     47 return result._sage_()

File /private/var/tmp/sage-10.2-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/interfaces/maxima_lib.py:815, in MaximaLib.sr_integral(self, *args)
    813     raise ValueError("Integral is divergent.")
    814 elif "Is" in s: # Maxima asked for a condition
--> 815     self._missing_assumption(s)
    816 else:
    817     raise

File /private/var/tmp/sage-10.2-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/interfaces/maxima_lib.py:1056, in MaximaLib._missing_assumption(self, errstr)
   1053 outstr = "Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume("\
   1054      + errstr[jj+1:k] + ">0)', see `assume?` for more details)\n" + errstr
   1055 outstr = outstr.replace('_SAGE_VAR_','')
-> 1056 raise ValueError(outstr)

ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume(floor((%i+1)/(2*%pi))>0)', see `assume?` for more details)
Is floor((%i+1)/(2*%pi)) positive, negative or zero?

I am not sure what I'm being asked to assume, or how, since there should be complete information here (no unknown variables).

Incidentally, the indefinite integral integral(cos(1+i*t), t) works fine and returns -I*sin(I*t + 1) as expected.