Ask Your Question
0

Simple complex definite integral fails

asked 2024-03-24 22:54:22 +0100

Nate Eldredge gravatar image

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.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2024-03-25 06:49:59 +0100

tolga gravatar image

The default Maxima solver needs assumptions to set floor((%i+1)/(2*%pi)) as shown in the message. You can either give such assumptions or try other algorithms such as:

integral(cos(1+I*t), (t,0,1), algorithm="giac")
edit flag offensive delete link more

Comments

for example

sage: integral(cos(1+i*t), (t,0,1),algorithm='fricas')
1/2*((e^(2*I) - 1)*e^(-I + 1) + e^(-I + 2) - e^I)*e^(-1)
sage: integral(cos(1+i*t), (t,0,1),algorithm='sympy')
1/2*(e - e^(2*I - 1))*e^(-I) + 1/2*(e^(2*I) - 1)*e^(-I)
sage: integral(cos(1+i*t), (t,0,1),algorithm='giac')
-I*sin(I + 1) + I*sin(1)
FrédéricC gravatar imageFrédéricC ( 2024-03-25 10:12:51 +0100 )edit

What would those assumptions look like?

Nate Eldredge gravatar imageNate Eldredge ( 2024-03-25 18:55:58 +0100 )edit
0

answered 2024-03-28 21:53:36 +0100

Emmanuel Charpentier gravatar image

FWIW, the question Is floor((%i+1)/(2*%pi)) positive, negative or zero? is nonsensical : $\displaystyle{\frac{i+1}{2\pi}}$ is not real and therefore has no sign. Maxima was out for a short beer, but can be hand-guided.

BTW :

sage: cos(1+I*t).trig_expand().integrate(t,0,1) # Hand-guide Maxima
-I*cosh(1)*sin(1) + cos(1)*sinh(1) + I*sin(1)
sage: cos(1+I*t).integrate(t,0,1, algorithm="giac")
-I*sin(I + 1) + I*sin(1)
sage: cos(1+I*t).integrate(t,0,1, algorithm="fricas")
1/2*((e^(2*I) - 1)*e^(-I + 1) + e^(-I + 2) - e^I)*e^(-1) # Exponentialized...
sage: cos(1+I*t).integrate(t,0,1, algorithm="sympy")
1/2*(e - e^(2*I - 1))*e^(-I) + 1/2*(e^(2*I) - 1)*e^(-I) # Same as fricas
sage: cos(1+I*t).integrate(t,0,1, algorithm="mathematica_free")
0.634964000000000 - 0.456987000000000*I # Numerical result, correct but nonsensical here...
sage: cos(1+I*t)._mathematica_().Integrate((t, 0, 1)).sage()
-I*sin(I + 1) + I*sin(1) # Same as giac
sage: cos(1+I*t)._mathematica_().Integrate((t, 0, 1)).sage().trig_expand()
-I*cosh(1)*sin(1) + cos(1)*sinh(1) + I*sin(1) # Same as hand-guided Maxima

And, BTW :

sage: bool(cos(1+I*t).integrate(t,0,1, algorithm="fricas")==cos(1+I*t).trig_expand().integrate(t,0,1).exponentialize())
True

All these expressions are therefore equal.

HTH,

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2024-03-24 22:54:22 +0100

Seen: 209 times

Last updated: Mar 28