"HeldExpression" (Comparison Method)
Details
- The "HeldExpression" comparison method considers two expressions to be equivalent if they are the same within any holding wrappers.
- Both answer key values and submitted answers are typically provided with a holding wrapper such as Hold, HoldPattern or HoldComplete.
- Answer key values containing patterns must be given using HoldPattern[expr] to support standard pattern matching. Using HoldComplete or Hold requires literal matching of expressions.
Examples
open allclose allBasic Examples (2)
Create an AssessmentFunction for an unevaluated expression:
The submitted answer must exactly match:
The evaluated result is not marked as correct:
Create an AssessmentFunction for an unevaluated mathematical expression:
The submitted answer must be identical:
Mathematically equivalent submissions that are not identical are marked incorrect:
Scope (1)
Create an assessment function for a code question:
Use it in a QuestionObject:
Attempting to submit the output will be marked as incorrect:
Properties & Relations (4)
Assessment functions using Hold will treat patterns literally:
Submissions that match the pattern will be marked as incorrect:
Exact literal matches are marked as correct:
Use HoldPattern instead to support pattern matching:
Matching held expressions are marked as correct:
The evaluated result is not accepted:
The "Expression" comparison method compares the full expression, including holding wrappers when they exist:
Different holding wrappers will not be marked as correct:
Use "HeldExpression" to compare the expression within the holding wrapper:
The same answer is marked correct:
Create assessment for a held mathematical expression:
Create another assessment for treating the same answer as an "ArithmeticResult":
"HeldExpression" does not allow even basic equivalences like reordering terms in addition, but "ArithmeticResult" does:
Create assessment for a held code expression:
Create another assessment for treating the same answer as a "CodeEquivalence" solution:
"HeldExpression" does not attempt to find equivalences between non-identical answers, but "CodeEquivalence" does:
Possible Issues (1)
QuestionObject allows formatting of values even when given in Hold wrappers:
Use DisableFormatting to prevent formatting in QuestionObject: