Difference between revisions of "DraggableProofs"

From WeBWorK_wiki
Jump to navigation Jump to search
(Created page with "<h2>Using the Sage Cell Server</h2> <!-- Header for these sections -- no modification needed --> <!-- 300px|thumb|right|Click to enlarge -->...")
 
Line 5: Line 5:
 
[[File:GraphicsFilename1.png|300px|thumb|right|Click to enlarge]]
 
[[File:GraphicsFilename1.png|300px|thumb|right|Click to enlarge]]
 
-->
 
-->
UNDER CONSTRUCTION!!!
 
  +
 
<p style="background-color:#f9f9f9;border:black solid 1px;padding:3px;">
 
<p style="background-color:#f9f9f9;border:black solid 1px;padding:3px;">
This PG code shows how to embed a call to the Sage Cell Server from within a problem.
+
This PG code shows how to apply a javascript-enabled collection of drag and drop statements.
 
</p>
 
</p>
   
Line 30: Line 30:
 
loadMacros(
 
loadMacros(
 
"PGstandard.pl",
 
"PGstandard.pl",
"MathObjects.pl",
+
"draggableProof.pl",
"sage.pl",
 
 
);
 
);
  +
 
</pre>
 
</pre>
   
Line 37: Line 38:
   
 
<td style="background-color:#ccffcc;padding:7px;">
 
<td style="background-color:#ccffcc;padding:7px;">
<p> The sage.pl macro is not yet part of the standard WeBWorK distribution. You will need to download the macro file [[https://github.com/drjt/pg/blob/feature/SageMacro/macros/sage.pl sage.pl ]] and place it in your local macros directory for this to work.
+
<p> The draggableProof.pl macro is not yet part of the standard WeBWorK distribution. You will need to download the macro file [[https://github.com/drjt/pg/blob/feature/SageMacro/macros/sage.pl sage.pl ]] FIX THIS LINK and place it in your local macros directory for this to work.
 
</p>
 
</p>
 
</td>
 
</td>
 
</tr>
 
</tr>
   
<!-- Setup section -->
+
<!-- Create the lists -->
   
 
<tr valign="top">
 
<tr valign="top">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
###############################################
 
  +
TEXT(beginproblem());
##
 
## pg initializations and regular WeBWorK code
 
   
$a = random(2,5,1);
 
  +
$CorrectProof = DraggableProof([
  +
"Jason Aubrey",
  +
"Someone better than Jason but less than everyone else",
  +
"John Travis"
  +
],
   
$ansList = List("(-cos(pi*$a)/$a + 1/$a)");
 
  +
[
  +
"Don't complain about it",
  +
"\(x^2\)"
  +
],
   
</pre>
 
  +
SourceLabel => "Choose from these",
</td>
 
  +
TargetLabel => "Place the people in order of increasing usefulness.",
<td style="background-color:#ffffcc;padding:7px;">
 
The WeBWorK set up for the problem is the same, but in addition you have
 
to consider how you will pass the problem parameters into Sage. For example,
 
if you want to pass
 
<code>$f = (x-(-2))(x+2)(x+4)</code> it may be best to create two versions of <code>f</code>:
 
<code>$f_raw = (x-(-2))*(x+2)*(x+4);</code> to pass to Sage and the math object
 
<code>$f = Compute("$f_raw");</code> to use in WeBWorK.
 
<p>
 
Also, you will need to store the list of correct answers in a variable named $ansList (which is also customizable).
 
</p>
 
<p>
 
Finally, if your final answer is a matrix converted to a list, then do not use extra parenthesis here. Otherwise $ansList will be a List of Lists which is probably a bad thing.
 
</p>
 
</td>
 
</tr>
 
 
<!-- Initialize the Sage embedding -->
 
 
<tr valign="top">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
 
$SageCode = <<SAGE_CODE;
 
 
Area = integrate(sin($a*x),x,0,pi)
 
 
record_answer((Area)) # leave out if you return no answer
 
 
SAGE_CODE
 
</pre>
 
</td>
 
 
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
$SageCode = <<SAGE_CODE;
 
</p>
 
<p>
 
denotes the beginning of the Sage Python code to be inserted into the WeBWorK problem. This will be paired at the end with and ending SAGE_CODE which must be left-justified. This portion will create a perl variable $SageCode which is the complete Python text.
 
</p>
 
<p>To share values computed inside the Sage cell back to the WeBWorK problem, create a single Sage list named "sageAnswer" (which is configurable).</p>
 
</td>
 
</tr>
 
 
<!-- Sage macro and options section -->
 
 
<tr valign="top">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
 
Sage(
 
SageCode=>$SageCode,
 
 
);
 
);
 
 
</pre>
 
</pre>
 
</td>
 
</td>
   
 
<td style="background-color:#ffcccc;padding:7px;">
 
<td style="background-color:#ffcccc;padding:7px;">
  +
Notice the format is:
 
<p>
 
<p>
<b>Main sage script:</b>
 
  +
[ list of correct statement in order],
</p>
+
<br>
<p>
+
[ list of incorrect statements in order],
Working Sage code will work verbatim except for a couple of notational changes caused by conflicting syntax between perl and sage. In particular, since "@" is used for tables in perl and for interacts in sage, one will need to replace "@" with "~~@".
+
options
   
Further, WeBWorK uses <code>\( and \)</code> to delimit latex and "$" for variables while Sage uses "$' to delimit latex. Therefore, converting each pair of Sage's latex $ delimiters averts any conflict.
 
</p>
 
<p>
 
The defaults for several of the customizable options:
 
<pre>
 
SageCode => 'print 1+2', # This is the default code if none given.
 
ButtonText => 'Start/Restart the Interactive Cell',
 
CellServer => 'http://sagecell.sagemath.org',
 
SageAnswerName => 'sageAnswer', # not used yet
 
SageAnswerValue => 'ansList', # not used yet
 
AutoEvaluateCell => 'true', # 'false' requires student to activate cell
 
ShowAnswerBlank => 'hidden', # Set to 'input' to see Sage answer
 
AnswerReturn => 1, # Set to 0 if Sage returns nothing
 
HideElements => [''], # List of items to hide in cell
 
LinkedCells => 'false', # To allow for sharing between multiple cells
 
</pre>
 
</p>
 
<p>
 
You can hide various elements of the sage cell by listing them in the HideElements flag. Some options:
 
<pre>
 
Input Elements:
 
Editor (editor)
 
Editor type toggle (editorToggle)
 
Language selection box (language)
 
Evaluate button (evalButton)
 
Output Elements:
 
Permalinks (permalinks)
 
Session output (output)
 
Session end message (done)
 
Session files (sessionFiles)
 
</pre>
 
</p>
 
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 170: Line 93:
   
 
BEGIN_TEXT
 
BEGIN_TEXT
Determine the definite integral of
 
  +
\( \sin(${a}x) \) from \(a=0\) to \(b=\pi\).
 
  +
Select \{ $CorrectProof->numNeeded \} of the following.
  +
  +
$PAR
  +
\{ $CorrectProof->Print \}
   
 
END_TEXT
 
END_TEXT
 
 
Context()->normalStrings;
 
Context()->normalStrings;
   
 
# Answer Evaluation
 
# Answer Evaluation
   
$showPartialCorrectAnswers = 1;
 
  +
ANS($CorrectProof->cmp);
NAMED_ANS( sageAnswer => $ansList->cmp ); # Leave out if no Sage answer.
 
   
   
Line 186: Line 110:
 
</pre>
 
</pre>
 
<td style="background-color:#ddddff;padding:7px;">
 
<td style="background-color:#ddddff;padding:7px;">
<p> ${a}x allows you to place the value of $a adjacent to x without a space. $ax would be interpreted as the value of
 
  +
Notice, $CorrectProof->numNeeded returns the actual number of correct statements provided in the first list from above.
a variable called ax while $a x would produce a space between the number and x.
 
</p>
 
<p>
 
The list of values computed inside the Sage cell are sageAnswer => $ansList.
 
</p>
 
 
</td>
 
</td>
 
</tr>
 
</tr>

Revision as of 17:39, 20 November 2013

Using the Sage Cell Server


This PG code shows how to apply a javascript-enabled collection of drag and drop statements.

Problem Techniques Index

PG problem file Explanation
DOCUMENT();
loadMacros(
"PGstandard.pl",
"draggableProof.pl",
);

The draggableProof.pl macro is not yet part of the standard WeBWorK distribution. You will need to download the macro file [sage.pl ] FIX THIS LINK and place it in your local macros directory for this to work.

TEXT(beginproblem());

$CorrectProof = DraggableProof([
"Jason Aubrey",
"Someone better than Jason but less than everyone else",
"John Travis"
],

[
"Don't complain about it",
"\(x^2\)"
],

SourceLabel => "Choose from these",
TargetLabel =>  "Place the people in order of increasing usefulness.",
);

Notice the format is:

[ list of correct statement in order],
[ list of incorrect statements in order], options

## Lower WeBWorK text
##
## Problem display following the Sage cell
##

Context()->texStrings;

BEGIN_TEXT

Select \{ $CorrectProof->numNeeded \} of the following.

$PAR
\{ $CorrectProof->Print \}

END_TEXT
Context()->normalStrings;

# Answer Evaluation

ANS($CorrectProof->cmp);


ENDDOCUMENT();

Notice, $CorrectProof->numNeeded returns the actual number of correct statements provided in the first list from above.

Templates by Subject Area


Problem Techniques Index