Skip to main content Skip to local navigation

VPL: Using Maple for Math Assignments

VPL: Using Maple for Math Assignments

One of the places that Moodle falls down in is in supporting math assignments. It occurred to me that we could treat math assignments like we do programming assignments by extending the Virtual Programming Lab plugin for Moodle to support Maple. This doesn't replace existing products like the Maple / DigitalEd Möbius platform, nor does it replace a student's existing Maple application. It just allows us to leverage standard Maple within VPL.

Here, we're using Maple within VPL to examine the difference between a student's math equation and the model solution (in "run" mode via the rocket icon)

The student is expected to submit a file with the math solution written in it, formatted as required for Maple. That means using semicolons at the end of commands that are to be displayed and colons for those for which commands are to be hidden. Students don't need to have Maple on their own computers to make this work. If they want to they can, however install it on their own computers, or use the full graphical version of Maple on YorkU's AppAnywhere system through their web browser. Students in the EECS department can access Maple through the remote lab system.

Requirements

You need to have your own VPL server for this and you need to have Maple installed on it. You need to explicitly point any VPL activity you create to your local VPL server. Maple is not installed on the VPL developer's server and so this example will not work in the general case. In our case we're using a positively ancient version of Maple (version 9, from 2003) but it works on our Linux boxes, so it's all good.

Example 1: Test the correctness of an equation.

In this example we're going to test to see if the student's math equation is the same as the teacher's math equation. The equation is

x = 2 + y4

Like with other VPL activities, we typically set up both "run" and "evaluate" sessions using the vpl_run.sh and vpl_evaluate.sh scripts. We don't use the vpl_evaluate.cases file as we build the answers into both the run and evaluate scripts. Note that both the student submission and the teacher solution are written in Maple script but it's the Maple equation output, in ASCII text mode, that is examined, as shown in the figure below.

VPL will display different outputs in evaluation mode based on whether the student's submission is correct or not. The equations displayed are interpretations, by Maple, of what the student and teacher submitted.

Here are the three files that are used in this example. We provide a template file to the student and, in this case, the template is a model solution for the student. We call it studentTemplate.mw, and there's only one line in it:

x:=2+y^4; 

The student does not need to make any changes to it.

This is the vpl_run.sh file. The parts that make processing Maple files different than, say, C or Java or Python, are highlighted below.

#!/bin/bash
#
# vpl_run.sh script (Maple version)
# The output of the student program is tested against the expected output file.
# 
# James Andrew Smith; drsmith@yorku.ca July 2021
# Based on example by D. Thiebaut at Smith College
# http://www.science.smith.edu/dftwiki/index.php/Tutorial:_Moodle_VPL_--_Testing_a_C_Program
# and
# https://www.mapleprimes.com/posts/38232-Scripting-With-Maple
# -----------------------------------------------------------------


cat > vpl_execution <<EEOOFF
#!/bin/bash

# Variables (make changes here)
teacherMapleSolution="x:=2+y^4;"
studentProgram=studentTemplate
maxGrade=100
minGrade=0
consolationGrade=10



# --- create test (Teacher Solution) ---
# Take the teacher's Maple-coded solution and run it through Maple.
# use format echo "x:=1+1;" | maple -q 
# source: https://www.mapleprimes.com/posts/38232-Scripting-With-Maple
echo "\${teacherMapleSolution}" | maple -q &> solution.txt

# Default grade is zero.
grade=\$minGrade

for i in 1 ; do
   echo "TEST \$i"

   # ==============================================
   # TEST i
   # ==============================================
   #--- run program, capture output, display to student ---


#   echo "Running Maple on the student solution..."
   maple -q \${studentProgram}.mw  > user.out
#   echo "... Maple finished."
   
   # all processing of whitespace to remove it has been, itself removed.
   # want to see how that's done?  Go to 
   # http://www.science.smith.edu/dftwiki/index.php/Tutorial:_Moodle_VPL_--_Testing_a_C_Program
   
   #--- compute difference, with exact whitespace --- 
   diff -y -w user.out solution.txt > diff.out
   
   # debug:
   # echo "----- diff.out ------"
   # cat diff.out
   # echo "---------------------"

   
   #--- reject if different ---
   if ((\$? > 0)); then
      echo "Your output is NOT correct."


      echo "---------------"
      echo "Your output:"
      echo "---------------"
      cat user.out
      
      echo ""
      echo "---------------"
      echo "Expected output  "
      echo "---------------"
      cat solution.txt

      grade=\$( expr \$minGrade )
   
      #--- consolation grade ("thanks for coming out")---   
      #grade=\$( expr \$consolationGrade )

      # --------------------- REWARD IF CORRECT OUTPUT -----------------
   else
      #--- good output ---
      echo "Congrats, your output is correct."
      echo " --------------------------------"
      cat user.out
      echo "--------------------------------"
      grade=\$( expr \$maxGrade )
   fi
done

echo "Possible Grade : \$grade (you need to evaluate for official grade)"

exit 0
EEOOFF

 
chmod +x vpl_execution
exit 0

This is the vpl_evaluate.sh file. It is similar to the vpl_run.sh file, with a few notable differences, mostly related to the way that text is displayed or results sent back to Moodle during evaluation. First, the grade and comments that are sent back to Moodle at the evaluation stage are formatted with :=>>. Second, a prefix of '>' is added to the student's submission and the teacher result. This is accomplished with thee sed lines, found below:

#!/bin/bash
#
# vpl_evaluate.sh script (Maple version)
# The output of the student program is tested against the expected output file.
# 
# James Andrew Smith; drsmith@yorku.ca July 2021
#
# Based on example by D. Thiebaut at Smith College
# http://www.science.smith.edu/dftwiki/index.php/Tutorial:_Moodle_VPL_--_Testing_a_C_Program
# and
# https://www.mapleprimes.com/posts/38232-Scripting-With-Maple
# -----------------------------------------------------------------


cat > vpl_execution <<EEOOFF
#!/bin/bash

# Variables (make changes here)
# ----------------------------------------------
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
# ----------------------------------------------
teacherMapleSolution="x:=2+y^4;"
studentProgram=studentTemplate
maxGrade=100
minGrade=0
consolationGrade=10
# ----------------------------------------------
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# ----------------------------------------------

# --- create test (Teacher Solution) ---
# Take the teacher's Maple-coded solution and run it through Maple.
# use format echo "x:=1+1;" | maple -q 
# source: https://www.mapleprimes.com/posts/38232-Scripting-With-Maple
echo "\${teacherMapleSolution}" | maple -q &> solution.txt


# Default grade is zero.
grade=\$minGrade


for i in 1 ; do
   echo "Comment :=>>-TEST \$i"

   # ==============================================
   # TEST i
   # ==============================================
   #--- run program, capture output, display to student ---

   echo "Running Maple on the student solution..."
   maple -q \${studentProgram}.mw  > user.out
   echo "... Maple finished."
   
    # add a '>' prefix to student and teacher files
    # sed -i -e 's/^/>/' myfile.txt 
    cp user.out modifiedUser.out
    cp solution.txt modifiedSolution.txt
    sed -i -e 's/^/>/' modifiedUser.out
    sed -i -e 's/^/>/' modifiedSolution.txt
    echo "> Modified Student and Teacher variations:"
    cat modifiedUser.out
    cat modifiedSolution.txt

   
   # all processing of whitespace to remove it has been, itself removed.
   # want to see how that's done?  Go to 
   # http://www.science.smith.edu/dftwiki/index.php/Tutorial:_Moodle_VPL_--_Testing_a_C_Program
   
   #--- compute difference, with exact whitespace --- 
   diff -y -w user.out solution.txt > diff.out
   
   #--- compute difference --- 
   diff -y -w --ignore-all-space user.out solution.txt > diff.out
   #echo "----- diff.out ------"
   #cat diff.out
   #echo "---------------------"
   diff -y -w --ignore-all-space user.out solution.txt > diff.out

   
   #--- reject if different ---
   if ((\$? > 0)); then
      echo "Comment :=>>- Your output is incorrect."


      echo "Comment :=>> ---------------"
      echo "Comment :=>>- Your output:"
      echo "Comment :=>> ---------------"
      echo "<|--"
      cat modifiedUser.out
      echo "--|>"
      echo ""
      echo "Comment :=>> ---------------"
      echo "Comment :=>>- Expected output: "
      echo "Comment :=>> ---------------"
      echo "<|--"
      cat modifiedSolution.txt
      echo "--|>"
   
      grade=\$( expr \$minGrade )
   
      #--- consolation grade ("thanks for coming out")---   
      #grade=\$( expr \$consolationGrade )

      # --------------------- REWARD IF CORRECT OUTPUT -----------------
   else
      #--- good output ---
      echo "Comment :=>>- Congrats, your output is correct."
      echo "Comment :=>> --------------------------------."
      echo "<|--"
      cat modifiedUser.out
      echo "--|>"
      grade=\$( expr \$maxGrade )
   fi
done
      

echo "Grade :=>> \$grade"
exit 0
EEOOFF

 
chmod +x vpl_execution
exit 0

The teacher solution, teacherMapleSolution="x:=2+y^4;", is highlighted in the code above. You can also modify the maximum grade and file name for the student submission in there.

The vpl_evaluate.cases file is blank because the model solutions are integrated in vpl_run.sh and vpl_evaluate.sh.

Example 2: Graphs in Maple

Graphical assignments are hard to do in VPL. In that respect, Maple's Möbius and Matlab Grader have a distinct advantage. That said, we can use Maple's admittedly old-fashioned ASCII-drawing approach to graphs to get something reasonable with little effort:

The run and evaluate output for the correct graphing solution in VPL with Maple.
The incorrect solution for the Maple graphs, shown for both run and evaluate modes of VPL.

Here is the student model solution, studentTemplate.mw, provided to the student in the requested files:

plot( sin(x), x = 0..2*Pi);

Here is the vpl_run.sh file for this example

#!/bin/bash
#
# vpl_run.sh script (Maple version)
# The output of the student program is tested against the expected output file.
# 
# James Andrew Smith; drsmith@yorku.ca July 2021
# Based on example by D. Thiebaut at Smith College
# http://www.science.smith.edu/dftwiki/index.php/Tutorial:_Moodle_VPL_--_Testing_a_C_Program
# and
# https://www.mapleprimes.com/posts/38232-Scripting-With-Maple
# -----------------------------------------------------------------


cat > vpl_execution <<EEOOFF
#!/bin/bash

# Variables (make changes here)
teacherMapleSolution="plot( sin(x), x = 0..2*Pi);"
studentProgram=studentTemplate
maxGrade=100
minGrade=0
consolationGrade=10



# --- create test (Teacher Solution) ---
# Take the teacher's Maple-coded solution and run it through Maple.
# use format echo "x:=1+1;" | maple -q 
# source: https://www.mapleprimes.com/posts/38232-Scripting-With-Maple
echo "\${teacherMapleSolution}" | maple -q &> solution.txt

# Default grade is zero.
grade=\$minGrade

for i in 1 ; do
   echo "TEST \$i"

   # ==============================================
   # TEST i
   # ==============================================
   #--- run program, capture output, display to student ---

#   ./\${studentProgram}  &> user.out
#   echo "Running Maple on the student solution..."
   maple -q \${studentProgram}.mw  > user.out
#   echo "... Maple finished."
   
   # all processing of whitespace to remove it has been, itself removed.
   # want to see how that's done?  Go to 
   # http://www.science.smith.edu/dftwiki/index.php/Tutorial:_Moodle_VPL_--_Testing_a_C_Program
   
   #--- compute difference, with exact whitespace --- 
   diff -y -w user.out solution.txt > diff.out
   
   # debug:
   # echo "----- diff.out ------"
   # cat diff.out
   # echo "---------------------"

   
   #--- reject if different ---
   if ((\$? > 0)); then
      echo "Your output is NOT correct."


      echo "---------------"
      echo "Your output:"
      echo "---------------"
      cat user.out
      
      echo ""
      echo "---------------"
      echo "Expected output  "
      echo "---------------"
      cat solution.txt

      grade=\$( expr \$minGrade )
   
      #--- consolation grade ("thanks for coming out")---   
      #grade=\$( expr \$consolationGrade )

      # --------------------- REWARD IF CORRECT OUTPUT -----------------
   else
      #--- good output ---
      echo "Congrats, your output is correct."
      echo " --------------------------------"
      cat user.out
      echo "--------------------------------"
      grade=\$( expr \$maxGrade )
   fi
done

echo "Possible Grade : \$grade (you need to evaluate for official grade)"

exit 0
EEOOFF

 
chmod +x vpl_execution
exit 0

Hhere is the vpl_evaluate.sh file for this example

#!/bin/bash
#
# vpl_evaluate.sh script (Maple version)
# The output of the student program is tested against the expected output file.
# 
# James Andrew Smith; drsmith@yorku.ca July 2021
#
# Based on example by D. Thiebaut at Smith College
# http://www.science.smith.edu/dftwiki/index.php/Tutorial:_Moodle_VPL_--_Testing_a_C_Program
# and
# https://www.mapleprimes.com/posts/38232-Scripting-With-Maple
# -----------------------------------------------------------------


cat > vpl_execution <<EEOOFF
#!/bin/bash

# Variables (make changes here)
# ----------------------------------------------
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
# ----------------------------------------------
teacherMapleSolution="plot( sin(x), x = 0..2*Pi);"
studentProgram=studentTemplate
maxGrade=100
minGrade=0
consolationGrade=10
# ----------------------------------------------
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# ----------------------------------------------

# --- create test (Teacher Solution) ---
# Take the teacher's Maple-coded solution and run it through Maple.
# use format echo "x:=1+1;" | maple -q 
# source: https://www.mapleprimes.com/posts/38232-Scripting-With-Maple
echo "\${teacherMapleSolution}" | maple -q &> solution.txt


# Default grade is zero.
grade=\$minGrade


for i in 1 ; do
   echo "Comment :=>>-TEST \$i"

   # ==============================================
   # TEST i
   # ==============================================
   #--- run program, capture output, display to student ---

   echo "Running Maple on the student solution..."
   maple -q \${studentProgram}.mw  > user.out
   echo "... Maple finished."
   
    # add a '>' prefix to student and teacher files
    # sed -i -e 's/^/>/' myfile.txt 
    cp user.out modifiedUser.out
    cp solution.txt modifiedSolution.txt
    sed -i -e 's/^/>/' modifiedUser.out
    sed -i -e 's/^/>/' modifiedSolution.txt
    echo "> Modified Student and Teacher variations:"
    cat modifiedUser.out
    cat modifiedSolution.txt

   
   # all processing of whitespace to remove it has been, itself removed.
   # want to see how that's done?  Go to 
   # http://www.science.smith.edu/dftwiki/index.php/Tutorial:_Moodle_VPL_--_Testing_a_C_Program
   
   #--- compute difference, with exact whitespace --- 
   diff -y -w user.out solution.txt > diff.out
   
   #--- compute difference --- 
   diff -y -w --ignore-all-space user.out solution.txt > diff.out
   #echo "----- diff.out ------"
   #cat diff.out
   #echo "---------------------"
   diff -y -w --ignore-all-space user.out solution.txt > diff.out

   
   #--- reject if different ---
   if ((\$? > 0)); then
      echo "Comment :=>>- Your output is incorrect."


      echo "Comment :=>> ---------------"
      echo "Comment :=>>- Your output:"
      echo "Comment :=>> ---------------"
      echo "<|--"
      cat modifiedUser.out
      echo "--|>"
      echo ""
      echo "Comment :=>> ---------------"
      echo "Comment :=>>- Expected output: "
      echo "Comment :=>> ---------------"
      echo "<|--"
      cat modifiedSolution.txt
      echo "--|>"
   
      grade=\$( expr \$minGrade )
   
      #--- consolation grade ("thanks for coming out")---   
      #grade=\$( expr \$consolationGrade )

      # --------------------- REWARD IF CORRECT OUTPUT -----------------
   else
      #--- good output ---
      echo "Comment :=>>- Congrats, your output is correct."
      echo "Comment :=>> --------------------------------."
      echo "<|--"
      cat modifiedUser.out
      echo "--|>"
      grade=\$( expr \$maxGrade )
   fi
done

# echo "<|--"
# echo ">                      1234"
# echo "--|>"
      
      

echo "Grade :=>> \$grade"
exit 0
EEOOFF

 
chmod +x vpl_execution
exit 0

Printing in Evaluation Mode: Some "gotchas"

Make visible by using "<|--" and "--|>"

it's important to note that if you don't begin and end print statements a particular way, they won't show up when it's time to evaluate, even if they show up during a run. You need to start with <|-- and end with --|> For example:

echo "<|--"
echo "1234"
echo "--|>"

will print 1234 to the screen during evaluations, whereas you simply would have used echo "1234" in run mode.

Maintain white-space formatting by using ">" at the beginning of a line

In certain types of assignments, it's important to show student submissions and teacher solutions with white-space. This is the case with the equations that are displayed in ASCII text in Maple. They will display fine in run mode, but won't in evaluation mode. In order to display Maple equations correctly in evaluation mode, it's important to add a > prefix to each line of the Maple interpretation of both the student's solution or in the teacher's answer.

The > prefix needs to be added after Maple has processed the commands from either the student or teacher. Here it is:

   #--- run program, capture output, display to student ---
   echo "Running Maple on the student solution..."
   maple -q \${studentProgram}.mw  > user.out
   echo "... Maple finished."
   
   # ---- add a '>' prefix --------------------------------
   # add a '>' prefix to student and teacher files
   # form: sed -i -e 's/^/>/' myfile.txt 
   cp user.out modifiedUser.out
   cp solution.txt modifiedSolution.txt
   sed -i -e 's/^/>/' modifiedUser.out
   sed -i -e 's/^/>/' modifiedSolution.txt
   # ------------------------------------------------------

Conclusion

This is a proof of concept for creating automatically-graded math assignments using Maple within the VPL framework in Moodle. We can verify a student's equation or her graph against a teacher's model answer. It's not as feature-rich or refined as Matlab Grader or Maple's Möbius, but if you've already got Maple set up on your VPL server and you've already got VPL running on Moodle, then it might be worth a shot.

Don't forget!

When setting up the activity, don't forget to include the local VPL server location


don't forget to add in the location of your local VPL ("jail") server.

and don't forget to turn on "run", "evaluate" and "autograde" execution options:

Don't forget to set your execution options whens setting up your VPL assignment.

James Andrew Smith is an associate professor in Electrical Engineering and Computer Science Department in York University's Lassonde School.  He lived in Strasbourg, France and taught at the INSA Strasbourg and Hochschule Karlsruhe while on sabbatical in 2018-19 with his wife and kids. Some of his other blog posts discuss the family's sabbatical year, from both personal and professional perspectives.