Capture variable is not capturing properly

If you look in the TestNote component I have it printing the first two history points for a capture of “check1”.
I also have it printing the actual variable its supposed to be capturing.

These are not matching up the way they should as it only ever captures zeros even when the variable is 1 and is even printing so.

CheckBtn3 is where the capturing is happening and Input3 is where the variable check1 is being pulled from.

Please help, I know my notes aren’t the best right now so hopefully someone can understand what I’m saying here.

Seems that your likely issue is the misuse of countNumberUsage.
For this form:

countNumberUsage(latex, value)

what countNumberUsage does is count the number of times the value occurs in the latex, so for your code here:


it is trying to see if the decimal equivalent of a/m is literally typed into the input (e.g. if a=6 and m=10, your code would see if a student typed 0.6 once somewhere in their answer). Likely what you want is something more like this:

countNumberUsage(Input3.latex, a) = 1 and countNumberUsage(Input3.latex, m) = 1

which will check if the integers, a and m, each occur once in the latex input.

Hey Daniel, thanks but unfortunately, I don’t think this is what I need. The students are inputting a fraction but I want that fraction to be simplified. m is the variable that the numerator and denominator need to be divided by. So, the student may have entered 6/10 but I’m checking for the 3 and 5 where m would be 2 in this example.

If this were wrong the TestNote component would be printing the wrong value but its not. I set up the TestNote to troubleshoot this and it seems to be telling me a contradiction.

I’m printing Input3.script.check1 in the TestNote
At the same time I’m printing the captured variable which is also supposed to be Input3.script.check1 and they’re showing 2 different things.

I see now your check1 is trying to look for the use of those reduced values.

You’d probably be better off using pattern matching. If you’re looking for the fraction 3/5, for example, the following CL will check this:

p = patterns
targetFraction = p.fraction(p.integer.satisfies(`x=3`), p.integer.satisfies(`x=5`))
check = targetFraction.matches(Input3.latex)

To get your error messaging for a correct but not simplified fraction (also taking into account non-terminating fractions are rounded at some point by the calculator)

targetValue = `\frac{3}{5}`
needToSimplify = not(check) and 
      p.fraction(p.integer, p.integer).matches(Input3.latex) and
      numericValue(`|${Input3.latex}-${targetValue}|)<= 0.0001

You might also consider using the elements of list L, instead of a, b, and c, since they’re already the reduced values you’re looking for.

1 Like

Hey Daniel, I definitely need to look into the patterns thing, I’ve never used them and it definitely works. Thanks for taking the time to look at this. I slimmed down and corrected the needToSimplify part to just numericValue(\abs(${Input3.latex}-${targetValue}))<=0.0001 since the first part of the check will happen first (perhaps this is bad coding practice but this is just for me haha). But this was wonderful, thanks so much!

P.S. still curious why the capture wasn’t working properly…possible bug?

1 Like