Checking for number not expression

The activity I am working has one slide where I ask for the cosine, sine, and tangent of an angle (slide 8). I DON’T want them just entering cos(pi/2) here. I want them to give me an approximation or an exact value. I am wondering how I can build a check for that.

Do you know how to use patterns? You could use a simple one, like:

p = patterns
valid = p.number
check = valid.parse(this.latex)

If you want to allow fractions also, you’d need to use
valid = p.anyof(p.number, p.fraction(p.number,p.number))

Let me know if you want to see an example worked out in activity builder (I’m on my phone right now and can do it later).

I can use patterns to a limited degree. I got it mostly figured out using patterns but then got stuck with including negatives. The answers I want to accept include exact values-- hence radicals, fractions, and integers. My attempt at getting this to work via patterns is in the CL on that slide but I got stuck!

Give this a look. Let me know if it does what you want. I realized I misread, because before I thought you said that you only wanted a decimal approximation, not an exact answer. cos(π/2) pattern • Activity Builder by Desmos

1 Like

Yea! Putting it to work. Needed to add in some more checks b/c my S’s do weird stuff! I am sure with more skill at patterns this could be simplified, but here is what I have now:

radFrac = p.radical(p.fraction(p.number,p.number))
fracRad = p.fraction(p.radical(p.number),p.radical(p.number))
fracRadnegNum = p.fraction(p.negative(p.radical(p.number)),p.radical(p.number))
fracRadnegDen = p.fraction(p.radical(p.number),p.negative(p.radical(p.number)))
fracRadnegBoth = p.fraction(p.negative(p.radical(p.number)),p.negative(p.radical(p.number)))

I believe you can use p.negative with the overall fraction rather than needing separate ones for numerator and denominator… p.negative(p.fraction(…

In the CL for the math input, you could also use
disableEvaluation: true