Open nasser1 opened 2 years ago
Description changed:
---
+++
@@ -1,10 +1,10 @@
-This seems like a new problem I have no seen before. If already known or reported, please delete this ticket.
+This seems like a new problem I have not seen before. If already known or reported, please delete this ticket.
-I also asked about it here
+fyi, I also asked about it here
https://ask.sagemath.org/question/61120/latex-command-makes-sage-95-coredump-any-workaround/
-This seems to happen on some output and so far see it from maxima only but could also when using other algorithms. I need to check more. Here is an example
+This seems to happen on some output and so far see it happen when trying to convert maxima output to Latex on some results. But could also when using other algorithms. I need to check more. Here is an example
It doesn't work for me on OS X, either. I see:
sage: s = latex(anti)
Help file /Applications/usr/share/giac/doc/fr/aide_cas not found
Added 0 synonyms
and then it hangs. If I hit ctrl-C to interrupt it, it kicks me out to the shell, not to the Sage prompt. This is with Sage 9.6.beta1.
I'm guessing that's it's a giac bug, trying to convert a symbolic expression to LaTeX.
Changed keywords from latex maxima to latex maxima giac
Testing on Ubuntu 20.04 (CoCalc
) reproduces the bug on 9.4, but not on 9.3. With 9.3, it takes about 15 seconds to produce the latex. On 9.4, it usually crashed, but once it ran for more than 5 minutes until I stopped it, with memory usage over 4GB.
Here's what I think is happening. If you look at anti
, you will see it is an expression that contains an unevaluated integral, and this integral is much worse than the one we started with. Calling latex(anti)
means "evaluate/simplify anti
, and then return latex code of the result". So sagemath
tries to evaluate the integral. In 9.3 (and earlier), sagemath
realizes this is hopeless, and produces latex that includes an unevaluated integral. In 9.4 (and later), giac
(or some other backend) does not give up, so keeps trying to evaluate the integral until it runs out of memory.
To more-or-less confirm this diagnosis, I asked sagemath
to evaluate the unevaluated integral. In 9.3, it returns after about 15 seconds, with essentially the same integral that we started with. In 9.4, it hangs or crashes.
I don't know what we should do to fix this.
Yes, this is a problem if latex() command tries to evaluate the math it is trying to convert to Latex. In this case I will modify my code to avoid calling latex() on result which contains integrate in it to bypass this problem.
But does not sagemath has a way to prevent evaluation? For example, in Mathematica one can do the following
TeXForm[HoldForm[Integrate[Sin[x], x]]]
\int \sin (x) \, dx
The command HoldForm
tells it not to evaluate what is inside. Without this, it will evaluate first.
TeXForm[Integrate[Sin[x], x]]
-\cos (x)
To prevent evaluation of an integral, use the keyword argument hold=True
:
sage: integral(sin(x), x)
-cos(x)
sage: integral(sin(x), x, hold=True)
integrate(sin(x), x)
sage: latex(integral(sin(x), x, hold=True))
\int \sin\left(x\right)\,{d x}
It should also be possible to use a hold context
, but that doesn't seem to work for the complicated integral, though I don't know why.
Yes, this is not the same as Mathematica's HoldForm
. The result returned is from maxima with integrate
already in it without hold=True
.
So one would then need to first parse the input first, look for any integrate
and modify the integrate
command to add hold=true
into it at the correct position, and only then try latex()
command again on the updated result.
There should be a way to tell sage not to evaluate any expression regardless what it is.
Similar to Mathematica's Hold
commands. But for now, I will bypass calling latex()
in sage on any result that contains integrate
in it. This is much easier solution for me at this moment.
A hold context
is supposed to prevent evaluation, but it is buggy (see #31607, for example) and it does not seem to work for your example.
This no longer coredumps in sage-10.2. But as discussed above, the output of latex
is different than its input -- the argument anti
is evaluated.
This seems like a new problem I have not seen before. If already known or reported, please delete this ticket.
fyi, I also asked about it here
https://ask.sagemath.org/question/61120/latex-command-makes-sage-95-coredump-any-workaround/
This seems to happen on some output and so far see it happen when trying to convert maxima output to Latex on some results. But could also when using other algorithms. I need to check more. Here is an example
Doing the same, but using "fricas" instead of "maxima" shows no issues and the latex is generated with no problem. This is on Arch Linux running inside Virtual box.
Thanks. --Nasser
Component: symbolics
Keywords: latex maxima giac
Issue created by migration from https://trac.sagemath.org/ticket/33356