Get slope,xIntercept... from parse function

get slope, xIntercept… from parsedifference

I would like to evaluate the last step of linear equation solution. I’ve constructed the solution’s “Line equation” using the parsedifference (see graph g(x) ).

Now I want to get the slope, xIntercept… of the g(x). How it could be achieved ?


FYI: differenceFunction is lhs-rhs (@Jay there seems to be conflicting info in the documentation i.e. left - right in the Types-equation section, but right-left in the Advanced-Interpreting Math section.)

You don’t need parseEquation to get the slope and intercepts (though you still need if for the graph). Use xyLine:

myLine= xyLine(MathIn.latex)
slope= myLine.slope
xInt= myLine.xIntercept

Mr. Grubbs, hopefully not a bother here, but you were very helpful on another thread and I have another question about “parsing” student input from a math box (and apologies, Itzik, for a question in a slightly different direction; if proper protocol is to start a different topic, either of you feel free to let me know). Anyway, I see that the “xyline” feature allows you to pull out certain features from the line the student entered. I am interested in pulling out certain bits of text from a math input (for example brackets, where the = sign is, etc). Are there any means in the CL to pull out text features of the input similar to excel commands? (for example, the first character like the excel LEFT(cell, # of characters), or say find a certain combination of characters in the middle of the input like the excel FIND(cell, “= x”) or other text search/manipulate functions)

Desmos doesn’t have any string methods or functions. parseEquation and parseInequality allow you to pull the latex for the left and right hand sides, but that’s the extent of it.

Isn’t there a way to get the latex from the graph and use it in the xyLine component


בתאריך שבת, 5 בפבר׳ 2022, 20:00, מאת Daniel_Grubbs via Desmos Activity Builder Support ‏<>:


Thanks for your feedback. I didn’t explain myself good enough. the input is an equation (see screenshot) my question is why I can’t get the slope of the g(x) function (see the screenshot).


‫בתאריך שבת, 5 בפבר׳ 2022 ב-12:42 מאת ‪Daniel_Grubbs via Desmos Activity Builder Support‬‏ <‪‬‏>:‬

I mean technically for your equation the slope is infinite because that equation simplifies to x=-1.5, so xyLine is accurate. The red line is only showing because you’ve defined g(x) from the differenceFunction in terms of x. If you put g(x)=0 in the graph, it will graph the same as f(x). It’s taking the latex of the lhs-rhs and creating a function from that.

That exactly my question. How to process xyLine on g(x). How can I capture the Latex of g(x)?


בתאריך יום א׳, 6 בפבר׳ 2022, 0:53, מאת Daniel_Grubbs via Desmos Activity Builder Support ‏<>:

You can parse the lhs and rhs separately, which are each latex. I guess I don’t understand the purpose of the g(x) function because I don’t see the relevance of it.


Let me explain my motivation. I want to teach linear equation in 7th grade. The student will get an exersice like this:
In the solution I want the student to provide two things.
a) The “Target equation”, i.e - 4x=8 or 4x=-8
b) x=-2

In order to evaluate part (a) of the solution I thought to use g(x).


בתאריך יום א׳, 6 בפבר׳ 2022, 0:53, מאת Daniel_Grubbs via Desmos Activity Builder Support ‏<>:

If you don’t care about specifics, you can generally use:

solution = -2
check = parseEquation(input.latex).differenceFunction(`x`).evaluateAt(solution)=0

That will result in true for either a or b in your example. Some pattern matching may be what you’re looking for if you want to be more specific with a:

checkMonomial= p.product(p.number, p.literal(`x`))
checkA= checkMonomial.matches(lhs) or checkMonomial.matches(rhs)

checkA will just check for the product of a number and x on either side of the equation.


OK, understood. Very elegant solution.

Thanks very much for your attention.

בתאריך יום ב׳, 7 בפבר׳ 2022, 20:18, מאת Daniel_Grubbs via Desmos Activity Builder Support ‏<>: