WeBWorK Main Forum

Webwork with sagecell (almost solved!)

Webwork with sagecell (almost solved!)

by Marc BUFFAT -
Number of replies: 0
Digging into the source of the perl code sage.pl and IO.pl, I was able to write some webwork problems using my own sagecell server.
Before going further, I want to be sure that the way I use sagecell is the right one (i.e. the interface will not change in the near future)

There is 2 ways to use sagecell in a webwork problem

1/ using the Sage function (defined in sage.pl) and described here in the wiki
I use it mainly to plot figures using matplotlib which display nice figure. The problem is however that the figures are not display in the printed version of the problem.
The second problem is that the Sage function is associated a NAMED_ANS question where a sage return value (using record_answer) is checked against a webwork response. I don't understand the usage ?
In the wiki, it is explained that you can disable this behaviour with the option
AnswerReturn => 0
In my source, it is not implemented, and I just modified the sage.pl source in order to used it as in:
SageCode =>$SageCode, AutoEvaluateCell => 'true', AnswerReturn => 0,
CellServer => 'http://sagecellmeca.univ-lyon1.fr:8080',ShowAnswerBlank=> 'input'

2/ the second way to use sagecell is with the AskSage function, described in the wiki:
With AskSage, you can pass values from the sage code to webwork, by using the global dictionary WEBWORK in the sage code as
and by using the perl return value
$reply = AskSage($SageCode1 , {url=>'http://sagecellmeca.univ-lyon1.fr:8080/service',accepted_tos=>true});
the perl dictionary (HASH) is in
$rep0 = $reply->{webwork};
and you can access the element and convert them to MathObject
$rep1 = Compute($rep0->[val});
$rep1a = Formula($rep0->{function});
$rep1b = Matrix($rep0->{diff});
You can also get a variable which indicate the success of the sage code (=1)
$rep2 = $reply->{success};
and the print output of the sage program
$rep3 = $reply->{stdout};
However with AskSage you cannot plot results using sage and matplotlib
(in fact no sagecell is displayed)
Another remark: if I disable the tos in my sagecell server, the AskSage
function does not work any more (it requires that the sagecell server asked for a tos).

Am I correct with these usages?

From my point of view, Webwork with Sagecell is a very useful web 2.0 applications for teaching mathematics and computational science.
Thanks again to Jason for the development of sagecell, and to all the developers of Webwork.