Single Expression Answer Questions

Single expression answer questions are those in which the reader supplies a single algebraic expression as the answer to the question. A browser with forms capability is required for this type of question. For an example, select here.

The three sections of a single expression question are shown here:

	<ANSWER ... >

	<RESPONSES>
	...
	</RESPONSES>

	<HINTS>
	...
	</HINTS>

The structure of each of these sections is shown here. See below for explanation of expression syntax and testing equality.

ANSWER

The form of the <ANSWER...> element is as follows:
	<ANSWER ANS=l TOL=t HELP=url>

The <ANSWER...> element automatically generates the proper HTML for the form used by the reader to supply her answer. Only the ANS= attribute is required; the others are optional.

The ANS=l attribute specifies that l is the correct answer for the question.

The tolerance, t, is the relative amount that the supplied answer can be different from the correct one and still be judged correct. By default, TOL=0.0001. See below for an explanation of equality testing.

The HELP="url" attribute is optional. If given, it specifies the URL of a help document, and a link to that is automatically included after the answer form..

RESPONSES

The <RESPONSES> section is optional; it provides the responses that should be displayed after an answer has been given. The format of the <RESPONSES> section is shown here:
	<RESPONSES>
	<WHEN ANS=x> . . .
	. . .
	<WHEN CORRECT> . . .
	. . .
	<WHEN INCORRECT> . . .
	. . .
	</RESPONSES>
The <WHEN...> elements specify the conditions under which the following text is to be displayed as a response to a supplied answer.

<WHEN ANS=x> specifies that the following text is to be displayed whenever the reader supplies value x as an answer.

<WHEN CORRECT> specifies that the following text is to be displayed whenever the user selects the correct answer, and no other WHEN clause has been printed.

<WHEN INCORRECT> specifies that the following text is to be displayed whenever the user selects an incorrect answer, and no other WHEN clause has been printed.

All WHEN elements are optional; if none are given then the RESPONSES section need not be given either. In either case, a suitable default response is provided, giving feedback as to whether the selected answer was correct or not.

HINTS

See the hints section in the general document.

Expression Syntax

The allowable syntax of expressions is much like that of the "C" language (actually, it is almost identical to that of the "Perl" language, except that variables do not start with a '$'). Expressions must have numeric results.

The following arithmetic functions are available:

Trigonometric functions express angles in radians.

Extensions to the Syntax

In order to make things like vector expressions a bit more usual, we have implemented the following extension.

A number followed immediately by a variable is taken to mean multiplication. In other words, the expression:

	5i + 3j
is legal and is equivalent to:
	5*i + 3*j

Judging Equality of Expressions

The tutorial gateway does not have access to a symbolic algebra program, so to compare algebraic expressions for equality takes some guess work.

Basically, we just substitute random numbers between 0 and 1 for the variables in the expressions, numerically evaluate them, and compare results, using the tolerance specified in the <ANSWER...> element. Of course, we first ensure that the expressions have exactly the same set of variables.

This method has lots of problems, but it works for simple things.