Ask Your Question
1

possible invalid latex translation from fricas result

asked 2019-10-18 14:30:12 -0600

Nasser gravatar image

updated 2019-10-18 15:04:20 -0600

Using 8.9 sagemath on Linux. Where Fricas 1.5 is installed.

After calling fricas for integration from inside sagemath, and then translating the result to latex, the latex do not compile. I get syntax error compiling the latex with latest texlive TL 2019.

   >sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.9, Release Date: 2019-09-29                     │
│ Using Python 2.7.16. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: var('b c x n a e')
sage: anti=integrate((b*log(c*x^n) + a)*x^2*polylog(3, e*x),x, algorithm="fricas")
sage: anti_in_latex=latex(anti)
sage: anti_in_latex

sage: anti_in_latex
-\frac{4 \, {\left(4 \, b e^{3} n - 3 \, a e^{3}\right)} x^{3} + 9 \, {\left(3 \, b e^{2} n - 2 \, a e^{2}\right)} x^{2} + 36 \, {\left(2 \, b e n - a e\right)} x + 36 \, {\left(3 \, b e^{3} n x^{3} \log\left(x\right) + 3 \, b e^{3} x^{3} \log\left(c\right) - {\left(2 \, b e^{3} n - 3 \, a e^{3}\right)} x^{3} - b n\right)} {\rm %iint}\left(e, x, -\frac{\log\left(-e x + 1\right)}{e}, -\frac{\log\left(-e x + 1\right)}{x}\right) - 36 \, {\left({\left(b e^{3} n - a e^{3}\right)} x^{3} - b n + a\right)} \log\left(-e x + 1\right) - 6 \, {\left(2 \, b e^{3} x^{3} + 3 \, b e^{2} x^{2} + 6 \, b e x - 6 \, {\left(b e^{3} x^{3} - b\right)} \log\left(-e x + 1\right)\right)} \log\left(c\right) - 6 \, {\left(2 \, b e^{3} n x^{3} + 3 \, b e^{2} n x^{2} + 6 \, b e n x - 6 \, {\left(b e^{3} n x^{3} - b n\right)} \log\left(-e x + 1\right)\right)} \log\left(x\right) - 108 \, {\left(3 \, b e^{3} n x^{3} \log\left(x\right) + 3 \, b e^{3} x^{3} \log\left(c\right) - {\left(b e^{3} n - 3 \, a e^{3}\right)} x^{3}\right)} {\rm polylog}\left(3, e x\right)}{972 \, e^{3}}
sage:

Now when compiling the above, here is the error

>cat foo1.tex
\documentclass[12pt]{article}%
\usepackage{amsmath}
\begin{document}

\[
-\frac{4 \, {\left(4 \, b e^{3} n - 3 \, a e^{3}\right)} x^{3} + 9 \, {\left(3 \, b e^{2} n - 2 \, a e^{2}\right)} x^{2} + 36 \, {\left(2 \, b e n - a e\right)} x + 36 \, {\left(3 \, b e^{3} n x^{3} \log\left(x\right) + 3 \, b e^{3} x^{3} \log\left(c\right) - {\left(2 \, b e^{3} n - 3 \, a e^{3}\right)} x^{3} - b n\right)} {\rm %iint}\left(e, x, -\frac{\log\left(-e x + 1\right)}{e}, -\frac{\log\left(-e x + 1\right)}{x}\right) - 36 \, {\left({\left(b e^{3} n - a e^{3}\right)} x^{3} - b n + a\right)} \log\left(-e x + 1\right) - 6 \, {\left(2 \, b e^{3} x^{3} + 3 \, b e^{2} x^{2} + 6 \, b e x - 6 \, {\left(b e^{3} x^{3} - b\right)} \log\left(-e x + 1\right)\right)} \log\left(c\right) - 6 \, {\left(2 \, b e^{3} n x^{3} + 3 \, b e^{2} n x^{2} + 6 \, b e n x - 6 \, {\left(b e^{3} n x^{3} - b n\right)} \log\left(-e x + 1\right)\right)} \log\left(x\right) - 108 \, {\left(3 \, b e^{3} n x^{3} \log\left(x\right) + 3 \, b e^{3} x^{3} \log\left(c\right) - {\left(b e^{3} n - 3 \, a e^{3}\right)} x^{3}\right)} {\rm polylog}\left(3, e x\right)}{972 \, e^{3}}
\]
\end{document}

And

>lualatex foo1.tex
This is LuaTeX, Version 1.10.0 (TeX Live 2019)
 restricted system commands enabled.
(./foo1.tex
LaTeX2e <2018-12-01>

luaotfload | main : initialization completed in 0.144 seconds
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsopn.sty)) (./foo1.aux)
)
Runaway argument?
{4 \, {\left (4 \, b e^{3} n - 3 \, a e^{3}\right )} x^{3} + 9 \, {\left \ETC.
! File ended while scanning use of \frac .
<inserted text>
\par
<*> foo1.tex

?

This is the first time I see latex generated by sagemath not compile OK. I am usin

Any one knows what is going on and why this error is generated?

Update Fyi, when running the above directly in Fricas, this is what I get

  ii:=integrate((b*log(c*x^n) + a)*x^2*polylog(3, e*x),x);
  unparse(ii::InputForm) 

 "(((-108)*b*e^3*n*x^3*log(x)+((-108)*b*e^3*x^3*log(c)+((72*b*e^3*n+(-108)*a*e
  ^3)*x^3+36*b*n)))*%iint(e,x,((-1)*log((-1)*e*x+1))/e,((-1)*log((-1)*e*x+1))/x
  )+((324*b*e^3*n*x^3*log(x)+(324*b*e^3*x^3*log(c)+((-108)*b*e^3*n+324*a*e^3)*x
  ^3))*polylog(3,e*x)+((((-36)*b*e^3*n*x^3+36*b*n)*log((-1)*e*x+1)+(12*b*e^3*n*
  x^3+18*b*e^2*n*x^2+36*b*e*n*x))*log(x)+((((-36)*b*e^3*x^3+36*b)*log((-1)*e*x+
  1)+(12*b*e^3*x^3+18*b*e^2*x^2+36*b*e*x))*log(c)+(((36*b*e^3*n+(-36)*a*e^3)*x^
  3+((-36)*b*n+36*a))*log((-1)*e*x+1)+(((-16)*b*e^3*n+12*a*e^3)*x^3+((-27)*b*e^
  2*n+18*a*e^2)*x^2+((-72)*b*e*n+36*a*e)*x))))))/(972*e^3)"

But Fricas Latex is VALID, since it add \ around %

(11) -> latex(ii)

   (11)
  "{{{\left( -{{108} \  b \  {{e} \sp {3}} \  n \  {{x} \sp {3}} \  {\log \left
  ( {x} \right)}} -{{108} \  b \  {{e} \sp {3}} \  {{x} \sp {3}} \  {\log \left
  ( {c} \right)}}+{{\left( {{72} \  b \  {{e} \sp {3}} \  n} -{{108} \  a \  {{
  e} \sp {3}}} \right)} \  {{x} \sp {3}}}+{{36} \  b \  n} \right)} \  { \%iint
   \left( {e, \: x, \: -{{\log \left( {{-{e \  x}+1}} \right)} \over e}, \: -{{
  \log \left( {{-{e \  x}+1}} \right)} \over x}} \right)}}+{{\left( {{324} \  b
   \  {{e} \sp {3}} \  n \  {{x} \sp {3}} \  {\log \left( {x} \right)}}+{{324} 
  \  b \  {{e} \sp {3}} \  {{x} \sp {3}} \  {\log \left( {c} \right)}}+{{\left(
   -{{108} \  b \  {{e} \sp {3}} \  n}+{{324} \  a \  {{e} \sp {3}}} \right)} \
    {{x} \sp {3}}} \right)} \  {polylog \left( {3, \: {e \  x}} \right)}}+{{\le
  ft( {{\left( -{{36} \  b \  {{e} \sp {3}} \  n \  {{x} \sp {3}}}+{{36} \  b \
    n} \right)} \  {\log \left( {{-{e \  x}+1}} \right)}}+{{12} \  b \  {{e} \s
  p {3}} \  n \  {{x} \sp {3}}}+{{18} \  b \  {{e} \sp {2}} \  n \  {{x} \sp {2
  }}}+{{36} \  b \  e \  n \  x} \right)} \  {\log \left( {x} \right)}}+{{\left
  ( {{\left( -{{36} \  b \  {{e} \sp {3}} \  {{x} \sp {3}}}+{{36} \  b} \right)
  } \  {\log \left( {{-{e \  x}+1}} \right)}}+{{12} \  b \  {{e} \sp {3}} \  {{
  x} \sp {3}}}+{{18} \  b \  {{e} \sp {2}} \  {{x} \sp {2}}}+{{36} \  b \  e \ 
   x} \right)} \  {\log \left( {c} \right)}}+{{\left( {{\left( {{36} \  b \  {{
  e} \sp {3}} \  n} -{{36} \  a \  {{e} \sp {3}}} \right)} \  {{x} \sp {3}}} -{
  {36} \  b \  n}+{{36} \  a} \right)} \  {\log \left( {{-{e \  x}+1}} \right)}
  }+{{\left( -{{16} \  b \  {{e} \sp {3}} \  n}+{{12} \  a \  {{e} \sp {3}}} \r
  ight)} \  {{x} \sp {3}}}+{{\left( -{{27} \  b \  {{e} \sp {2}} \  n}+{{18} \ 
   a \  {{e} \sp {2}}} \right)} \  {{x} \sp {2}}}+{{\left( -{{72} \  b \  e \  
  n}+{{36} \  a \  e} \right)} \  x}} \over {{972} \  {{e} \sp {3}}}"

So it looks like sagemath needs to do the same. Look into the result returned by Fricas, and replace %iint by \%iint in the Latex?

Thanks --Nasser

edit retag flag offensive close merge delete

Comments

I tend not to agree with your last statement, if such a weird %iint appears in Sage, it means that there is a missing corresponding Sage function. It is better not to hide the problem, and instead definite such missing function correctly, and it will come with its own latex representation (e.g. dilog(x) is transformed into {\rm Li}_2\left(x\right), not just \dilog(x)).

tmonteil gravatar imagetmonteil ( 2019-10-18 17:25:41 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2019-10-18 14:45:47 -0600

tmonteil gravatar image

updated 2019-10-18 14:55:11 -0600

The culprit is %iint that let the rest of the formula appear as a comment.

Here is a smaller example:

sage: f = polylog(3, x)
sage: f.integral(x)
-x*dilog(x) - (x - 1)*log(-x + 1) + x*polylog(3, x) + x
sage: f.integral(x, algorithm='fricas')
-x*%iint(x, -log(-x + 1)/x) - (x - 1)*log(-x + 1) + x*polylog(3, x) + x

Thanks for reporting, this is now trac ticket 28630.

edit flag offensive delete link more

Comments

Thanks. What should be the fix for this? Is it fricas fault or should Sagemath handle this? Running automated large script which takes the latex from Sagemath to process and this causes the script to stop.

Nasser gravatar imageNasser ( 2019-10-18 14:53:38 -0600 )edit

I guess this is an interface problem between Sage and fricas. Note that fricas is optional, hence much less user and developers use it, so the errors are less likely to be catched.

tmonteil gravatar imagetmonteil ( 2019-10-18 14:56:55 -0600 )edit

At least this is my superficial interpretation, this is why i put it in https://trac.sagemath.org/wiki/symbol...

tmonteil gravatar imagetmonteil ( 2019-10-18 15:00:16 -0600 )edit

I am not an expert of that part of Sage, but other devs will know more.

tmonteil gravatar imagetmonteil ( 2019-10-18 15:04:49 -0600 )edit

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: 2019-10-18 14:30:12 -0600

Seen: 26 times

Last updated: Oct 18