Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
79 lines (54 sloc) 4.79 KB


There are two fields which allow you to define and manipulate computer algebra system variables. These are called the Question Variables and Answer Variables.

The field is a string which contains a list of assignments of the form

key : value

for example

p : (x-1)^3

Each key is the name of a variable local to the question, and value is an expression in Maxima's language. When evaluated this list is passed to the CAS, and evaluated in order. The value obtained for each key will be stored and used later, for example in the question marking routines. The keys need not be unique, although only the last value will be available for use later.

These fields are known as KeyVal fields.

Maxima's assignments a:3

Computer algebra systems each use a different syntax to denote the assignment of a value to a variable. For example, Maple and Derive use :=. Mathematica uses = or :=, depending on when the assignment is to take place. Maxima uses the form key:value, which is unusual and not intuitive. Maxima reserves := to denote function definition, e.g. f(x):=x^2.

STACK 3 now uses Maxima's assignment rules. This is a change from STACK 2. Questions will be imported and quietly changed.


  • Items are separated by either a newline or ;
  • Adding ; at the end of each statement is optional, but makes it easier to cut and paste into a Maxima session.
  • If you type a string not in the form key : value, a variable name such as dumvar3 will be assigned automatically to keep track of the command in the list of question variables.
  • If a student uses a variable longer than one letter in length which has been assigned a value in the question variables then the attempt will be rejected as invalid. Hence, it is a sensible idea to use variable names which are not used as parameters. For example if you set an integration question then you should avoid using the variable c, otherwise students won't be able to write +c in the normal way to indicate a constant of integration.
  • You can include C-style block comments for increased clarity, and these may appear on separate lines e.g. dice : rand(6) + 1 /* roll it! */
  • Avoid using variable names with a single letter, otherwise a student might type this in and it will not automatically be forbidden. You can always forbid them explicitly in the input "forbid" options.
  • Do not define a feedback variable with the same name as an input. For example, if your input is ans1 then do not define a feedback variable ans1:exdowncase(ans1).

Question variables {#Question_variables}

The question variables are evaluated when a version of a question is created. The displayed forms are available to all other CASText fields and the values to other parts of the question, e.g.

If the teacher uses a variable name which is two characters or longer, then students will not be able to use this variable name in their input.
Input from students with two-character variable names which appear in the question variables will be rejected as invalid.
Students can always use single letter variable names.
Teachers are therefore advised to avoid single letter variable names.

Feedback variables {#Feedback_variables}

The feedback variables form one field in the potential response tree.

When using the potential response tree it is often very useful to manipulate the student's answer before applying any of the Answer tests. This gives the opportunity to perform sophisticated mathematical operations.

Before each answer test is applied the following list of variables is assembled and evaluated

  1. The values of the question variables.
  2. The values of each inputs.
  3. The feedback variables.

The values of the evaluated feedback variables can be used as expressions in the answer tests and in the feedback.

Note, you cannot redefine the value of an input as a key in the feedback variables. e.g. you cannot have something like ans1:ans1+1. You must use a new variable name.
When an answer test is evaluated, if the SA or TA field is exactly the name of an input then the raw student's value is used, and not the value from the feedback variables. This is because some of the answer tests require exactly what is typed (e.g. trailing zeros) and not the value through the CAS.
To avoid this problem authors must use new variable names to distinguish between the actual input typed by the student and any calculated value.

You can’t perform that action at this time.