Difference between revisions of "User:Malcolm/wip/Sage WW Notes"

From WeBWorK_wiki
Jump to navigation Jump to search
m
Line 26: Line 26:
 
#: <source> $f = Compute($f_raw); </source>
 
#: <source> $f = Compute($f_raw); </source>
 
And use <tt>$f_raw</tt> to pass to Sage and <tt>$f</tt> to work with in WW.
 
And use <tt>$f_raw</tt> to pass to Sage and <tt>$f</tt> to work with in WW.
  +
# TODO investigate using <tt>string()</tt>, but setting some flags noparen ?

Revision as of 15:11, 12 June 2012

Notes on embedding Sage into WW problems using the Sage cell server - May/June 2012

When passing functions to Sage, if the function is defined as a math object problems can occur since it can happen that none of <source lang="perl"> $f $f->string() $f->stringify() $f->TeX() </source> return the orginal string used to define the function.

For example with the set up: <source lang="perl"> Context("Numeric"); $f = Compute("(x-(-2))*(x-2)*(x-4)"); </source> then

  • $f->string() produces [x-(-2)]*(x-2)*(x-4)
  • $f->TeX() produces \left(x-\left(-2\right)\right)\!\left(x-2\right)\!\left(x-4\right)
  • $f->stringify() produces:
    • [x-(-2)]*(x-2)*(x-4) in normalStrings
    • \left(x-\left(-2\right)\right)\!\left(x-2\right)\!\left(x-4\right) in texStrings

Possible solution:

  1. Use a construction like
    <source> $f_raw = "(x-(-2))*(x-2)*(x-4)";</source>
    <source> $f = Compute($f_raw); </source>

And use $f_raw to pass to Sage and $f to work with in WW.

  1. TODO investigate using string(), but setting some flags noparen ?