AMC with sagetex

Added by Juani Mela about 4 years ago

Does anyone have experience with AMC and sagetex [1]?

This could really expand the possibilities of package fp.

With sage, it is possible to do symbolic derivation, plotting a computed function, or solving a linear system of equations, to name a few.


Replies (3)

RE: AMC with sagetex - Added by Pablo UPM about 4 years ago

A small inconvenience is that in order to use sagetex you have to:

  1. run pdflatex sagetex_example
  2. run sage sagetex_example.sagetex.sage
  3. run pdflatex sagetex_example again

RE: AMC with sagetex - Added by Pablo UPM about 4 years ago

Running sage in between is only a small inconvenience. The problems with the sage verbatim environments are more serious:

  • Inline environments can not be used to assign to variables
  • Multiline environments are equivalent to verbatim environments, which mess up with AMC seriously
  • It is crucial to define variables to do really meaningful examples

Partial+inconvenient workaround: combine latex variables and sage commands. Example:

\FPeval\a{trunc(6 + random * 3,0)}


  Statement of the question:

\a, $\a$, \sage{2+3}, \sage{\a}, \sage{\b}, \sage{2+\a}

  \AMCOpen{lines=2, dots=False}{
Solution is

\sageplot[width=10cm]{plot(sin(x), 0, pi)}

\sageplot[width=10cm]{plot(\a*sin(x), 0, pi)}

I guess I should be happy, since this is better than fpeval alone, but it is not possible to store a polynomial, matrix, function, etc in an fpeval variable.

RE: AMC with sagetex - Added by Pablo UPM about 4 years ago

Much better, I added a sageraw environment to sagetex.sty

 _st_.current_tex_line = \the\inputlineno^^J

(note: the \% go without a backslash, but this forum complains if I leave the percentage sign alone)

and now I can define variables within latex


Then make computations and plots

My limited knowledge of latex does not allow me to do multiline sage raw input without relying on verbatim. I understand the problem is not easy even for the latex masters.

My sagerawline also breaks sageplot in DOC-corrige (although it works in DOC-sujet), but this can be done in other ways.

Not perfect, but this will suffice: each student gets a different question, but we are not limited to basic arithmetic.

This could be done with any other script language (at least haskell and R had latex extensions before Sage did).