Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Best way to use mathics inside sagemath. Latex issues

I just started to learn how to use mathics from sagemath. I am not sure if I am doing it correctly. I just need to use mathics for integration.

Sometimes mathics return result from integration which I need to obtain its Latex. but it seems sagemath command does not know what to do in some cases and return result which does not compile. Here is an example

>sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.6, Release Date: 2022-05-15                     │
│ Using Python 3.10.4. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: from sage.interfaces.mathics import mathics
sage: res=mathics('Integrate[Sin[x]/(3 + Cos[x])^2,x]')

sage: res
ConditionalExpression[3 + Cos[x], {3 + Cos[x] != 0}]

sage: latex(res)
}0\right\}\right]

Is there a better way to handle such cases? Am I doing something wrong here?

Best way to use mathics inside sagemath. Latex issues

I just started to learn how to use mathics from sagemath. I am not sure if I am doing it correctly. I just need to use mathics for integration.

Sometimes mathics return result from integration which I need to obtain its Latex. but it seems sagemath command does not know what to do in some cases and return result which does not compile. Here is an example

>sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.6, Release Date: 2022-05-15                     │
│ Using Python 3.10.4. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: from sage.interfaces.mathics import mathics
sage: res=mathics('Integrate[Sin[x]/(3 + Cos[x])^2,x]')

sage: res
ConditionalExpression[3 + Cos[x], {3 + Cos[x] != 0}]

sage: latex(res)
}0\right\}\right]

Is there a better way to handle such cases? Am I doing something wrong here?

Can I add a code to check on result before calling latex on it? This is all done in a script which runs over 10's of thousands of integrals. So need a way to automate this checking in code. Not by looking at output and deciding what to do.

Best way to use mathics inside sagemath. Latex issues

I just started to learn how to use mathics from sagemath. I am not sure if I am doing it correctly. I just need to use mathics for integration.

Sometimes mathics return result from integration which I need to obtain its Latex. but it seems sagemath command does not know what to do in some cases and return result which does not compile. Here is an example

>sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.6, Release Date: 2022-05-15                     │
│ Using Python 3.10.4. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: from sage.interfaces.mathics import mathics
sage: res=mathics('Integrate[Sin[x]/(3 + Cos[x])^2,x]')

sage: res
ConditionalExpression[3 + Cos[x], {3 + Cos[x] != 0}]

sage: latex(res)
}0\right\}\right]

Is there a better way to handle such cases? Am I doing something wrong here?

Here is another example

sage: res=mathics('Integrate[x^n*Log[a*x],x]')

sage: res
Piecewise[{{(-1 + n Log[a x] + Log[a x]) x ^ (1 + n) / (1 + 2 n + n ^ 2), n != -1}}, Log[a x] ^ 2 / 2]

sage: latex(res)
}-1\right\}\right\},\frac{\text{Log}\left[a x\right]^2}{2}\right]

Can I add a code to check on result before calling latex on it? This is all done in a script which runs over 10's of thousands of integrals. So need a way to automate this checking in code. Not by looking at output and deciding what to do.

I found the following workaround which I am now using

sage: res=mathics('Integrate[x^n*Log[a*x],x]')
sage: the_latex=mathics('TeXForm['+str(res)+']')

sage: the_latex
\text{Piecewise}\left[\left\{\left\{\frac{\left(-1+n \text{Log}\left[a x\right]+\text{Log}\left[a x\right]\right) x^{1+n}}{1+2 n+n^2},n\text{!=}-1\right\}\right\},\frac{\text{Log}\left[a x\right]^2}{2}\right]

I thought sagemath latex() command will know how to do this directly. Will sage latex() fully support mathics output conversion in the future?