Difference between revisions of "AskSage"
Line 96: | Line 96: | ||
<td style="background-color:#ffdddd;border:black 1px dashed;"> |
<td style="background-color:#ffdddd;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
− | $sageReply1 = AskSage($SageCode1,{seed=>$problemSeed}); |
+ | $sageReply1 = AskSage($SageCode1,{accept_tos=true,seed=>$problemSeed}); |
$M = Matrix($sageReply1); |
$M = Matrix($sageReply1); |
||
− | $sageReply2 = AskSage($SageCode2); |
+ | $sageReply2 = AskSage($SageCode2,{accept_tos=true}); |
$ans = Matrix($sageReply2); |
$ans = Matrix($sageReply2); |
||
Line 110: | Line 110: | ||
</p> |
</p> |
||
<p> |
<p> |
||
− | The first argument to AskSage() must be sage code. After that, you may optionally send a <code>seed</code> value to sage's <code>set_random_seed()</code> function and/or send a <code>url</code> pointing to a sage cell web-service handler. If no |
+ | The first argument to AskSage() must be sage code. After that, you must send your acceptance of the [http://sagecell.sagemath.org/tos.html Sage Cell Terms of Service]. Please do read the Sage Cell TOS and think about it quietly for a moment before proceeding. If you accept the TOS, you may also optionally send along with your acceptance a <code>seed</code> value to sage's <code>set_random_seed()</code> function and/or send a <code>url</code> pointing to a sage cell web-service handler. If no |
<code>url</code> is sent, then <code>AskSage()</code> uses as a default <code>url => 'https://sagecell.sagemath.org/service'</code>. |
<code>url</code> is sent, then <code>AskSage()</code> uses as a default <code>url => 'https://sagecell.sagemath.org/service'</code>. |
||
</p> |
</p> |
Revision as of 12:08, 10 January 2014
Using the Sage Cell Server
This PG code shows how to embed a call to the Sage Cell Server from within a problem.
PG problem file | Explanation |
---|---|
loadMacros( "PGstandard.pl", "MathObjects.pl", ); |
No additional macros are needed to use the |
############################################### ## ## pg initializations and regular WeBWorK code Context("Matrix"); my $rows = random(3,4); my $columns = random(4,5); my $rank = random(2,3); |
The WeBWorK set up for the problem is the same. |
$SageCode1=<<END; print random_matrix(QQ,$rows,$columns,algorithm='echelonizable',rank=$rank).rows() END $SageCode2 =<<END; print matrix(QQ,$sageReply1).rref().rows() END |
$SageCode = <<END;
denotes the beginning of a block of Sage python code. This will be paired at the end with and ending END which must be left-justified. This portion will create a perl scalar variable |
$sageReply1 = AskSage($SageCode1,{accept_tos=true,seed=>$problemSeed}); $M = Matrix($sageReply1); $sageReply2 = AskSage($SageCode2,{accept_tos=true}); $ans = Matrix($sageReply2); |
Calling
The first argument to AskSage() must be sage code. After that, you must send your acceptance of the Sage Cell Terms of Service. Please do read the Sage Cell TOS and think about it quietly for a moment before proceeding. If you accept the TOS, you may also optionally send along with your acceptance a Notice that we convert sage's replies to a MathObjects so that we can take advantage of WeBWorK's built in answer checking, display capbilities, etc. |
Context()->texStrings; BEGIN_TEXT Row reduce \( $M \) $BR \{ $ans->ans_array\} END_TEXT Context()->normalStrings; ANS($ans->cmp()); ENDDOCUMENT(); |
Now we display the problem and check the answer as in a typical WeBWorK problem. |