Advanced Mathematical Questions
Writing Mathematical Questions covers the everyday math <answer> — equivalent forms, partial credit, tolerances, and lists — where the response is matched against a correct value. This guide steps up to the <award> + <when> construction, which grades a condition on the response instead of matching a fixed value: accepting any value that fits a rule, combining several inputs, checking that an expression is factored, comparing sets and intervals, and handling a question whose number of blanks depends on the reader.
It assumes you’ve read the basics guide. As before, every example is live: edit the source on the left and the result updates on the right.
Accept any answer that fits a condition
Sometimes there is no single right answer — any value with a certain property will do. Validate the response with an <award> whose <when> child states the condition. Name the <mathInput> so the <when> can refer to it.
The condition inside <when> can use any math operators. For example, use <mod> to test divisibility:
Because the input is written out explicitly here, the <label> goes on the <mathInput>, not on the <answer>.
Use several input boxes for one answer
Put more than one <mathInput> inside the <answer> and validate them together with an <award> whose <when> condition refers to each one.
The <when> refers to each input by name. Give each one a <shortDescription> so a screen reader can tell the boxes apart.
What counts as a “response”? A <when> can reference any named component — an input, a point, a computed value — whether or not it is marked as a response, so the examples here work as written. A response is a separate idea: the value Doenet records as what the student submitted, so an instructor can later review what each student tried (it does not affect grading). Inputs inside the <answer> are recorded as responses automatically; to record an input or value that lives elsewhere, link it with forAnswer="$ans", or flag it with referencesAreResponses on the <award> or a <considerAsResponses> child. For the details, see the advanced answer examples.
Check that an expression is factored
Asking the reader to factor is tricky, because the unfactored form is mathematically equal to the factored one — a plain answer would accept either. <hasSameFactoring> returns true only when the response is equivalent and broken into the same factors.
The label shows the expanded form (x^2 + 3x + 2) via <math extend="$expr" expand />, and the <award> fires only for a genuinely factored response such as (x+1)(x+2) — the expanded form is rejected even though it’s equal. Attributes on <hasSameFactoring> can tighten this further (for example, requiring matching monomial factors).
Accept any form of an interval or set
A reader might describe the same set of numbers as an interval, a chained inequality, or set notation. Wrap both the response and the expected answer in <subsetOfReals> and the = comparison checks whether they’re the same set, regardless of how it’s written.
All of these responses are accepted:
To have the reader build the set on a number line instead of typing it, use the <subsetOfRealsInput> widget and compare its value the same way.
A varying number of answer blanks
Sometimes you don’t want to reveal how many answers there should be — you want the student to determine that. Accomplishing this effect currently requires a combination of DoenetML components. Use a <mathInput> to ask “how many?”, a <repeatForSequence> to produce that many answer boxes, and <collect> to gather their values into a <mathList> for grading.
Typing a number into the first input creates that many solution boxes. <collect> gathers them, and the <mathList> of their values is compared — unorderedCompare so order doesn’t matter, matchPartial so a partly-right set earns partial credit — against the expected solutions 2 and -5.
Where to go next
- Writing Mathematical Questions — the basics this guide builds on.
<award>and<when>reference — the building blocks of every example here.<answer>reference — every<answer>attribute and property, plus the advanced answer examples on designating responses.<hasSameFactoring>,<subsetOfReals>, and<subsetOfRealsInput>reference pages.- Writing Accessible Activities — labeling inputs so every reader can use your questions.