I would like the correct: 1/3 But fractions have to be typed a certain way. How can I have the fraction be the correct answer?
There are a variety of ways to check, each with their own pros and cons. (Samples are assuming an input, and would vary slightly if using a table.)
- Latex matching is not recommended, though it’s much more stable than it used to be. If you’re not sure the way latex should be typed, put it in the calculator and copy/paste it into your CL. It will auto-format it. The following will only accept the fraction as written. Pro: it’s not too complicated to write. Con: for things like expressions, all variations would need to be defined
correct: this.latex = `\frac{1}{3}`
- Evaluation. Non-terminating decimals can be an issue, so using a tolerance may be needed. This would accept any equivalent, not just the explicit “1/3”. Pro and con: any equivalent is accepted
correct: this.numericValue = numericValue(`\frac{1}{3}`)
or with a tolerance
correct: numericValue(`\abs(${this.latex}-\frac{1}{3})`) <= 0.01
- Pattern matching can be used alone or along with evaluation. The following pattern is specifically for “1/3”, but could be a generic fraction pattern by removing
.satisfies( )
and then using evaluation as well. Pro: there is soooo much you can do with patterns to allow or restrict different forms. Cons: not the lowest entry point to learn
p = patterns
correct: p.fraction(p.integer.satisfies(`x=1`), p.integer.satisfies(`x=3`) ).matches(this.latex)
1 Like
Pattern matching sounds interesting. I have yet to play around with it. Any good example activities that I can view that you have stored around?
Jay Chow has an article here with some resources to start with. Definitely need to play with it a bit to get the hang of it, and there’s some nuance to how a few of them work.
1 Like