Difference between revisions of "User:Malcolm/wip/Sage WW Notes"
< User:Malcolm | wip
Jump to navigation
Jump to search
m |
|||
Line 2: | Line 2: | ||
When passing functions to Sage, if the function is defined as a math object problems can occur since it can happen that none of |
When passing functions to Sage, if the function is defined as a math object problems can occur since it can happen that none of |
||
− | <pre> |
||
+ | <source lang="perl"> |
||
$f |
$f |
||
$f->string() |
$f->string() |
||
$f->stringify() |
$f->stringify() |
||
$f->TeX() |
$f->TeX() |
||
− | </pre>return the orginal string used to define the function. |
||
+ | </source> |
||
+ | return the orginal string used to define the function. |
||
For example with the set up: |
For example with the set up: |
||
− | <pre> |
||
+ | <source lang="perl"> |
||
Context("Numeric"); |
Context("Numeric"); |
||
$f = Compute("(x-(-2))*(x-2)*(x-4)"); |
$f = Compute("(x-(-2))*(x-2)*(x-4)"); |
||
− | </ |
+ | </source> |
then |
then |
||
− | < |
+ | *<tt>$f->string()</tt> produces <tt>[x-(-2)]*(x-2)*(x-4)</tt> |
− | $f->TeX() produces\left(x-\left(-2\right)\right)\!\left(x-2\right)\!\left(x-4\right) |
+ | * <tt>$f->TeX()</tt> produces <tt>\left(x-\left(-2\right)\right)\!\left(x-2\right)\!\left(x-4\right)</tt> |
− | $f->stringify() produces: |
+ | * <tt>$f->stringify()</tt> produces: |
− | [x-(-2)]*(x-2)*(x-4) in normalStrings |
+ | ** <tt>[x-(-2)]*(x-2)*(x-4)</tt> in <tt>normalStrings</tt> |
− | \left(x-\left(-2\right)\right)\!\left(x-2\right)\!\left(x-4\right) in texStrings |
+ | ** <tt>\left(x-\left(-2\right)\right)\!\left(x-2\right)\!\left(x-4\right)</tt> in <tt>texStrings</tt> |
Possible solution: |
Possible solution: |
||
− | Use a construction like |
+ | # Use a construction like |
− | < |
+ | #: <source> $f_raw = "(x-(-2))*(x-2)*(x-4)";</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. |
|
− | </pre> |
Revision as of 14:09, 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:
- 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.