How can I parse fractions in student input?

I would like to write some activities where students need to enter fractions.

I would like to be able to extract the numerator and denominator separately.

Is there any way that I can do this with a function like parseEquation(…) and parseOrderedPair(…) but for fractions?

(I can see from the documentation that there seems to be a large parsing library in the works but I’m assured that it’s not ready for prime time; in the meanwhile could perhaps a parseFraction emerge?)

add a table , you can ask your students to enter numerator and denominator separately. you will be able to see a fraction generated from Num and denominator.

CL to add on Note: content:"\\frac{${table.cellContent(2,1)}}{${table.cellContent(2,2)}}"

1 Like

What is the purpose? If it’s for correction, you can use countNumberUsage().

2 Likes

Yep at the moment this is my best option, just as with coordinates before they added the option to parse.

Agree that for one off questions this is the best way.

The problem is that I want to have generalizable screens, where I can either randomly generate fractions or to specify the numerators and denominators in computation layer. But countNumberUsage only checks for constant numbers, so I don’t think you could code a general checker.

Just to bring this up again in the hope Desmos will offer it.

I’d like to play around with Dan Meyer’s ideas about interpreting students’ answers, in the context of fractions. But can’t really do that without being able to parse the fraction.

1 Like

I wrote a short example to separate a numerator from a denominator in a fraction. You can find it here:

Separating Fractions into Num and Den

1 Like

I extended the fraction parse, and added a screen with components to simplify radicals (pulling out perfect squares). I saw several questions about this in other posts, too.

Screen 2 is simplifying a radical

1 Like

I like this workaround. You have a little bit of unnecessary code. In the graph CL, you don’t need:

number("n_{um}"): this.number(`N_{um}`) # the numerator
number("d_{en}"): this.number(`D_{en}`)

You can just use g1.number(`N_{um}`) in your note. Just a little redundant.

1 Like

Thanks for the heads up here! Now it feels very obvious.

Since I like to keep track of what’s in the graph component, I’ll start putting more comments in the graph CL about available variables when there’s no need to redefine.

1 Like

Missed this a long time ago, but you can use variables in countNumberUsage(). So if you set “num” and “den”, you could use:
countNumberUsage(input.latex, num)=1 and countNumberUsage(input.latex, den)=1

1 Like

I don’t have a computer handy to check but I thought the second argument to countNumberUsage couldn’t be a variable. (I am imagining a scenario in which these are randomly generated, not something where I’ve hardcoded a specific value). Has this changed?

Maybe it changed. Pretty sure I’ve used this before. Here’s an example:

1 Like

Thanks - you are correct!

I am not sure when they changed that but I have a distinct memory of that not working back at some stage in 2020.

But in conclusion, it seems as though we can now do countNumberUsage with variables in the second argument.

Here is an update on fraction parsing using the new Patterns feature:

On slide 8 of this activity (8.27 Calculating rates from a graph • Activity Builder by Desmos )

I am trying to take the numerator and denominator that students enter in the table t1 row 1 column 1 and place it into the first 3 options of the multiple choice question. I have set those choices to update with the fraction only when table 1 is correct. However, once table 1 is correct, you can only see the first choice in the multiple choice update with the proper numerator and denominator, while choices 2 and 3 become blank. Is there a way to get choices 2 and 3 to update properly with the correct numerator and denominator?

The problem has something to do with the formatting of the latex. I don’t really understand what’s causing the issue, but if you add a space between the backslash and the word marshmallows, it works. Same thing goes for choice 3, add a space between the backslash and the word units.

Thank you so much! That’s awesome.