Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Changing one letter in integrand causes sagemath/giac crash

I've been trying for a while to find why some integrals cause giac to crash. This is different from earlier question I asked.

This seem to be an interface issue between sagemath and giac.

Here is an integrand which causes giac to crash according to sagemath. Ok, may be due sagemath changing the form of the integrand. I do not know. (this takes about almost 10 minutes to crash, which I do not know why so long).

btw, is there a way to see what exactly sagemath sends to giac in the call if sagemath changes the form of the integrand? Is there a way to trace the call?

sage: var("x f e a b z")
sage: integrand = cot(f * x + e) * (a + b * sin(f * x + e) ^ 2) ^ (1 / 2)
sage: integrand
        sqrt(b*sin(f*x + e)^2 + a)*cot(f*x + e)
sage: integrate(integrand, x, algorithm="giac")
Giac crashed -- automatically restarting.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File /usr/lib/python3.10/site-packages/sage/interfaces/interface.py:1216, in InterfaceElement.__getattr__(self, attrname)
   1215 try:
-> 1216     P = self._check_valid()
   1217 except ValueError:

File /usr/lib/python3.10/site-packages/sage/interfaces/expect.py:1500, in ExpectElement._check_valid(self)
   1498     if P is None or P._session_number == BAD_SESSION or self._session_number == -1 or \
   1499                   P._session_number != self._session_number:
-> 1500         raise ValueError("The %s session in which this object was defined is no longer running."%P.name())
   1501 except AttributeError:

ValueError: The giac session in which this object was defined is no longer running.

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
Input In [9], in <module>
----> 1 integrate(integrand, x, algorithm="giac")

File /usr/lib/python3.10/site-packages/sage/misc/functional.py:764, in integral(x, *args, **kwds)
    639 """
    640 Return an indefinite or definite integral of an object ``x``.
    641 
   (...)
    761 
    762 """
    763 if hasattr(x, 'integral'):
--> 764     return x.integral(*args, **kwds)
    765 else:
    766     from sage.symbolic.ring import SR

File /usr/lib/python3.10/site-packages/sage/symbolic/expression.pyx:13138, in sage.symbolic.expression.Expression.integral (build/cythonized/sage/symbolic/expression.cpp:95254)()
  13136                 R = SR
  13137         return R(integral(f, v, a, b, **kwds))
> 13138     return integral(self, *args, **kwds)
  13139 
  13140 integrate = integral

File /usr/lib/python3.10/site-packages/sage/symbolic/integration/integral.py:1047, in integrate(expression, v, a, b, algorithm, hold)
   1045     if not integrator:
   1046         raise ValueError("Unknown algorithm: %s" % algorithm)
-> 1047     return integrator(expression, v, a, b)
   1048 if a is None:
   1049     return indefinite_integral(expression, v, hold=hold)

File /usr/lib/python3.10/site-packages/sage/symbolic/integration/external.py:258, in giac_integrator(expression, v, a, b)
    256     return expression.integrate(v, a, b, hold=True)
    257 else:
--> 258     return result._sage_()

File /usr/lib/python3.10/site-packages/sage/interfaces/giac.py:1135, in GiacElement._sage_(self, locals)
   1131 from sage.calculus.calculus import symbolic_expression_from_string, SR_parser_giac
   1133 result = repr(self) # string representation
-> 1135 if str(self.type()) not in ['DOM_LIST', 'vector', 'vecteur']:
   1136 
   1137     # Merge the user-specified locals dictionary and the symbol_table
   1138     # (locals takes priority)
   1139     lsymbols = symbol_table['giac'].copy()
   1140     lsymbols.update(locals)

File /usr/lib/python3.10/site-packages/sage/interfaces/interface.py:1218, in InterfaceElement.__getattr__(self, attrname)
   1216     P = self._check_valid()
   1217 except ValueError:
-> 1218     raise AttributeError(attrname)
   1219 if attrname[:1] == "_":
   1220     raise AttributeError

AttributeError: type
sage:

When I change e to say z the crash goes away! This answer returns immediately also.

sage: integrand = cot(f * x + z) * (a + b * sin(f * x + z) ^ 2) ^ (1 / 2)
sage: integrand
     sqrt(b*sin(f*x + z)^2 + a)*cot(f*x + z)

sage: integrate(integrand, x, algorithm="giac")
   (a*arctan(sqrt(b*sin(f*x + z)^2 + a)/sqrt(-a))/sqrt(-a) + sqrt(b*sin(f*x + z)^2 + a))/f

Note that the above used to work OK in 9.3. i.e. when using e, it used to work and return the same antiderivative shown above but with z replaced by e. I have report showing this worked before with giac. so something changed.

Notice that giac, e is the Euler constant. And I assume sagemath knows this ofcourse and it changes internally e to some made up VAR symbol before calling giac and in return reverse this back to e in sagemath space.

Here is the same thing inside giac, both complete immeadility.

2>> integrand:=sqrt(b*sin(f*x + e)^2 + a)*cot(f*x + e)
3>> integrate(integrand,x)
1/b/f*b*(sqrt(a+b*sin(f*x+exp(1))^2)+2*a/2/sqrt(-a)*atan(sqrt(a+b*sin(f*x+exp(1))^2)/sqrt(-a)))

4>> integrand:=sqrt(b*sin(f*x + z)^2 + a)*cot(f*x + z)
5>> integrate(integrand,x)
1/b/f*b*(sqrt(a+b*sin(f*x+z)^2)+2*a/2/sqrt(-a)*atan(sqrt(a+b*sin(f*x+z)^2)/sqrt(-a)))

No crash inside giac for same integrand using e or z

my question is: Why giac crashes when using e but not when using z? Surely the letter should not have made a difference? Is this a new interface problem? Why this same integral worked in 9.3 but not in 9.5? I am running the same test.

Is this new issue? Maybe I should make a ticket on it?

Changing one letter in integrand causes sagemath/giac crash

I've been trying for a while to find why some integrals cause giac to crash. This is different from earlier question I asked.

This seem to be an interface issue between sagemath and giac.

Here is an integrand which causes giac to crash according to sagemath. Ok, may be due sagemath changing the form of the integrand. I do not know. (this takes about almost 10 minutes to crash, which I do not know why so long).

btw, is there a way to see what exactly sagemath sends to giac in the call if sagemath changes the form of the integrand? Is there a way to trace the call?

sage: var("x f e a b z")
sage: integrand = cot(f * x + e) * (a + b * sin(f * x + e) ^ 2) ^ (1 / 2)
sage: integrand
        sqrt(b*sin(f*x + e)^2 + a)*cot(f*x + e)
sage: integrate(integrand, x, algorithm="giac")
Giac crashed -- automatically restarting.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File /usr/lib/python3.10/site-packages/sage/interfaces/interface.py:1216, in InterfaceElement.__getattr__(self, attrname)
   1215 try:
-> 1216     P = self._check_valid()
   1217 except ValueError:

File /usr/lib/python3.10/site-packages/sage/interfaces/expect.py:1500, in ExpectElement._check_valid(self)
   1498     if P is None or P._session_number == BAD_SESSION or self._session_number == -1 or \
   1499                   P._session_number != self._session_number:
-> 1500         raise ValueError("The %s session in which this object was defined is no longer running."%P.name())
   1501 except AttributeError:

ValueError: The giac session in which this object was defined is no longer running.

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
Input In [9], in <module>
----> 1 integrate(integrand, x, algorithm="giac")

File /usr/lib/python3.10/site-packages/sage/misc/functional.py:764, in integral(x, *args, **kwds)
    639 """
    640 Return an indefinite or definite integral of an object ``x``.
    641 
   (...)
    761 
    762 """
    763 if hasattr(x, 'integral'):
--> 764     return x.integral(*args, **kwds)
    765 else:
    766     from sage.symbolic.ring import SR

File /usr/lib/python3.10/site-packages/sage/symbolic/expression.pyx:13138, in sage.symbolic.expression.Expression.integral (build/cythonized/sage/symbolic/expression.cpp:95254)()
  13136                 R = SR
  13137         return R(integral(f, v, a, b, **kwds))
> 13138     return integral(self, *args, **kwds)
  13139 
  13140 integrate = integral

File /usr/lib/python3.10/site-packages/sage/symbolic/integration/integral.py:1047, in integrate(expression, v, a, b, algorithm, hold)
   1045     if not integrator:
   1046         raise ValueError("Unknown algorithm: %s" % algorithm)
-> 1047     return integrator(expression, v, a, b)
   1048 if a is None:
   1049     return indefinite_integral(expression, v, hold=hold)

File /usr/lib/python3.10/site-packages/sage/symbolic/integration/external.py:258, in giac_integrator(expression, v, a, b)
    256     return expression.integrate(v, a, b, hold=True)
    257 else:
--> 258     return result._sage_()

File /usr/lib/python3.10/site-packages/sage/interfaces/giac.py:1135, in GiacElement._sage_(self, locals)
   1131 from sage.calculus.calculus import symbolic_expression_from_string, SR_parser_giac
   1133 result = repr(self) # string representation
-> 1135 if str(self.type()) not in ['DOM_LIST', 'vector', 'vecteur']:
   1136 
   1137     # Merge the user-specified locals dictionary and the symbol_table
   1138     # (locals takes priority)
   1139     lsymbols = symbol_table['giac'].copy()
   1140     lsymbols.update(locals)

File /usr/lib/python3.10/site-packages/sage/interfaces/interface.py:1218, in InterfaceElement.__getattr__(self, attrname)
   1216     P = self._check_valid()
   1217 except ValueError:
-> 1218     raise AttributeError(attrname)
   1219 if attrname[:1] == "_":
   1220     raise AttributeError

AttributeError: type
sage:

When I change e to say z the crash goes away! This answer returns immediately also.

sage: integrand = cot(f * x + z) * (a + b * sin(f * x + z) ^ 2) ^ (1 / 2)
sage: integrand
     sqrt(b*sin(f*x + z)^2 + a)*cot(f*x + z)

sage: integrate(integrand, x, algorithm="giac")
   (a*arctan(sqrt(b*sin(f*x + z)^2 + a)/sqrt(-a))/sqrt(-a) + sqrt(b*sin(f*x + z)^2 + a))/f

Note that the above used to work OK in 9.3. i.e. when using e, it used to work and return the same antiderivative shown above but with z replaced by e. I have report showing this worked before with giac. so something changed.

Notice that giac, e is the Euler constant. And I assume sagemath knows this ofcourse and it changes internally e to some made up VAR symbol before calling giac and in return reverse this back to e in sagemath space.

Here is the same thing inside giac, both complete immeadility.immediately.

2>> integrand:=sqrt(b*sin(f*x + e)^2 + a)*cot(f*x + e)
3>> integrate(integrand,x)
1/b/f*b*(sqrt(a+b*sin(f*x+exp(1))^2)+2*a/2/sqrt(-a)*atan(sqrt(a+b*sin(f*x+exp(1))^2)/sqrt(-a)))

4>> integrand:=sqrt(b*sin(f*x + z)^2 + a)*cot(f*x + z)
5>> integrate(integrand,x)
1/b/f*b*(sqrt(a+b*sin(f*x+z)^2)+2*a/2/sqrt(-a)*atan(sqrt(a+b*sin(f*x+z)^2)/sqrt(-a)))

No crash inside giac for same integrand using e or z

my question is: Why giac crashes when using e but not when using z? Surely the letter should not have made a difference? Is this a new interface problem? Why this same integral worked in 9.3 but not in 9.5? I am running the same test.

Is this new issue? Maybe Just in case, I should make also created a ticket on it? https://trac.sagemath.org/ticket/33379#ticket

Changing one letter in integrand causes sagemath/giac crash

I've been trying for a while to find why some integrals cause giac to crash. This is different from earlier question I asked.

This seem to be an interface issue between sagemath and giac.

Here is an integrand which causes giac to crash according to sagemath. Ok, may be due sagemath changing the form of the integrand. I do not know. (this takes about almost 10 minutes to crash, which I do not know why so long).

btw, is there a way to see what exactly sagemath sends to giac in the call if sagemath changes the form of the integrand? Is there a way to trace the call?

sage: var("x f e a b z")
sage: integrand = cot(f * x + e) * (a + b * sin(f * x + e) ^ 2) ^ (1 / 2)
sage: integrand
        sqrt(b*sin(f*x + e)^2 + a)*cot(f*x + e)
sage: integrate(integrand, x, algorithm="giac")
Giac crashed -- automatically restarting.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File /usr/lib/python3.10/site-packages/sage/interfaces/interface.py:1216, in InterfaceElement.__getattr__(self, attrname)
   1215 try:
-> 1216     P = self._check_valid()
   1217 except ValueError:

File /usr/lib/python3.10/site-packages/sage/interfaces/expect.py:1500, in ExpectElement._check_valid(self)
   1498     if P is None or P._session_number == BAD_SESSION or self._session_number == -1 or \
   1499                   P._session_number != self._session_number:
-> 1500         raise ValueError("The %s session in which this object was defined is no longer running."%P.name())
   1501 except AttributeError:

ValueError: The giac session in which this object was defined is no longer running.

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
Input In [9], in <module>
----> 1 integrate(integrand, x, algorithm="giac")

File /usr/lib/python3.10/site-packages/sage/misc/functional.py:764, in integral(x, *args, **kwds)
    639 """
    640 Return an indefinite or definite integral of an object ``x``.
    641 
   (...)
    761 
    762 """
    763 if hasattr(x, 'integral'):
--> 764     return x.integral(*args, **kwds)
    765 else:
    766     from sage.symbolic.ring import SR

File /usr/lib/python3.10/site-packages/sage/symbolic/expression.pyx:13138, in sage.symbolic.expression.Expression.integral (build/cythonized/sage/symbolic/expression.cpp:95254)()
  13136                 R = SR
  13137         return R(integral(f, v, a, b, **kwds))
> 13138     return integral(self, *args, **kwds)
  13139 
  13140 integrate = integral

File /usr/lib/python3.10/site-packages/sage/symbolic/integration/integral.py:1047, in integrate(expression, v, a, b, algorithm, hold)
   1045     if not integrator:
   1046         raise ValueError("Unknown algorithm: %s" % algorithm)
-> 1047     return integrator(expression, v, a, b)
   1048 if a is None:
   1049     return indefinite_integral(expression, v, hold=hold)

File /usr/lib/python3.10/site-packages/sage/symbolic/integration/external.py:258, in giac_integrator(expression, v, a, b)
    256     return expression.integrate(v, a, b, hold=True)
    257 else:
--> 258     return result._sage_()

File /usr/lib/python3.10/site-packages/sage/interfaces/giac.py:1135, in GiacElement._sage_(self, locals)
   1131 from sage.calculus.calculus import symbolic_expression_from_string, SR_parser_giac
   1133 result = repr(self) # string representation
-> 1135 if str(self.type()) not in ['DOM_LIST', 'vector', 'vecteur']:
   1136 
   1137     # Merge the user-specified locals dictionary and the symbol_table
   1138     # (locals takes priority)
   1139     lsymbols = symbol_table['giac'].copy()
   1140     lsymbols.update(locals)

File /usr/lib/python3.10/site-packages/sage/interfaces/interface.py:1218, in InterfaceElement.__getattr__(self, attrname)
   1216     P = self._check_valid()
   1217 except ValueError:
-> 1218     raise AttributeError(attrname)
   1219 if attrname[:1] == "_":
   1220     raise AttributeError

AttributeError: type
sage:

When I change e to say z the crash goes away! This answer returns immediately also.

sage: integrand = cot(f * x + z) * (a + b * sin(f * x + z) ^ 2) ^ (1 / 2)
sage: integrand
     sqrt(b*sin(f*x + z)^2 + a)*cot(f*x + z)

sage: integrate(integrand, x, algorithm="giac")
   (a*arctan(sqrt(b*sin(f*x + z)^2 + a)/sqrt(-a))/sqrt(-a) + sqrt(b*sin(f*x + z)^2 + a))/f

Note that the above used to work OK in 9.3. i.e. when using e, it used to work and return the same antiderivative shown above but with z replaced by e. I have report showing this worked before with giac. so something changed.

Notice that inside giac, e is the Euler constant. And I assume sagemath knows this ofcourse of course and it changes internally e to some made up VAR VAR symbol before calling giac and in return reverse this back to e in sagemath space.

Here is the same thing inside giac, both complete immediately.

2>> integrand:=sqrt(b*sin(f*x + e)^2 + a)*cot(f*x + e)
3>> integrate(integrand,x)
1/b/f*b*(sqrt(a+b*sin(f*x+exp(1))^2)+2*a/2/sqrt(-a)*atan(sqrt(a+b*sin(f*x+exp(1))^2)/sqrt(-a)))

4>> integrand:=sqrt(b*sin(f*x + z)^2 + a)*cot(f*x + z)
5>> integrate(integrand,x)
1/b/f*b*(sqrt(a+b*sin(f*x+z)^2)+2*a/2/sqrt(-a)*atan(sqrt(a+b*sin(f*x+z)^2)/sqrt(-a)))

No crash inside giac for same integrand using e or z

my question is: Why giac crashes when using e but not when using z? Surely the letter should not have made a difference? Is this a new interface problem? Why this same integral worked in 9.3 but not in 9.5? I am running the same test.

Just in case, I also created a ticket https://trac.sagemath.org/ticket/33379#ticket