Pattern Matching for Checking Correctness

My CL is not working, specifically it says equality does not work for “Numerator=72” and “Denominator=13”

p=patterns

Numerator = p.fraction(p.integer,p.integer).parse(this.latex).numerator
Denominator = p.fraction(p.integer,p.integer).parse(this.latex).denominator

isMixedFraction = p.mixedNumber.matches(this.latex)
isFraction = p.fraction(p.integer,p.integer).matches(this.latex)

CoeffMixed = p.mixedNumber.parse(this.latex).whole
NMixed = p.mixedNumber.parse(this.latex).numerator
DMixed = p.mixedNumber.parse(this.latex).denominator

correct: correct
correct = (isMixedFraction and CoeffMixed=5 and NMixed=9 and DMixed=13) or (isFraction and Numerator=72 and Denominator=13)
#this.latex=\frac{72}{13} or this.latex=5\frac{9}{13}
placeholderLatex: ``
suffix: when this.numericValue=1 “hour” otherwise “hours”

Slide 2, Math Response component a1

When you parse those parts, you need to specify whether you want .latex or .numericValue. This is because you can specify different types for parts in a fraction pattern (e.g. expressions or radicals), and you may want to parse the actual latex vs the value.

The mixedNumber pattern, however, requires integers, and so its parts are consistent and its numericValue (within backticks) will be the same as it’s latex.

1 Like