Pattern matching on a latex string from the script (not an input)

Can pattern matching operate on a latex string that’s defined as a variable in the script? I’ve created a string called “Combined_Student_Numerators”, which is generated in the script. It pulls apart the student input and multiplies all the quantities that are in the numerator of the student’s expression, allowing me to treat these as equivalent:

(3x^2)/5

(3/5)*x^2

3x^2*(1/5)

etc

(In all three cases above, Combined_Student_Numerators would be 3*x^2, regardless of where the student chose to put the 1/5)

Combined_Student_Numerators = 
  when WhichProduct=1 "${T1_Num}"
  when WhichProduct=2 "${T1_Num}\cdot ${T2_Num}"
  when WhichProduct=3 "`${T1_Num}\cdot ${T2_Num}\cdot ${T3_Num}`"
  when WhichProduct=4 "`${T1_Num}\cdot ${T2_Num}\cdot ${T3_Num}\cdot ${T4_Num}`"
  when WhichProduct=5 "`${T1_Num}\cdot ${T2_Num}\cdot ${T3_Num}\cdot ${T4_Num}\cdot ${T5_Num}`"
  when WhichProduct=6 "`${T1_Num}\cdot ${T2_Num}\cdot ${T3_Num}\cdot ${T4_Num}\cdot ${T5_Num}\cdot ${T6_Num}`"
  when WhichProduct=7 "`${T1_Num}\cdot ${T2_Num}\cdot ${T3_Num}\cdot ${T4_Num}\cdot ${T5_Num}\cdot ${T6_Num}\cdot ${T7_Num}`"
  when WhichProduct=8 "`${T1_Num}\cdot ${T2_Num}\cdot ${T3_Num}\cdot ${T4_Num}\cdot 
  otherwise "Error"

Now I need to run pattern-matching on Combined_Student_Numerators. It doesn’t seem to work. It does work if I make Combined_Student_Numerators the initialLatex of a math input and then parse that input. But then it doesn’t update if the student changes their answer, I guess because initialLatex just defines a starting state but doesn’t update.

If you’re not looking for any particular form (i.e. pattern), you may just want to evaluateAt for a number of values of x:

#student input as a function
f=simpleFunction(input.latex)
#check if function evaluates equivalent to (3x^2)/5
check=f.evaluateAt(0)=0 and f.evaluateAt(1)=0.6 and f.evaluateAt(5)=15

This will accept any equivalent form.

(Can you share your activity?)

Hi Daniel, thank you. These are exponent simplification problems, so I am looking for a particular form. If I just evaluate their expression, they could simply copy and paste the problem as their answer without simplifying anything and get it marked correct.

I will work to put my activity in intelligible form and then will post it here. Right now it probably wouldn’t make any sense to anyone but me. Thanks again.

Might be easier to use countNumberUsage in this case if you can’t figure out how to use patterns.

True, that might work. Thanks for the idea.