Documente Academic
Documente Profesional
Documente Cultură
Our mission at Socratic is to make learning easy. Our app lets you
take a picture of a homework question, and we teach you how to
answer itmagic!
Millions of students use our app and website to learn, and math
(especially algebra) is consistently the top subject, for good reason:
everyone has to take math, they take it for years, concepts build on
each other, and many find it hard to understand.
steps.forEach(step => {
console.log(step.oldNode.toString()); // "2 x + 2 x + x
+ x"
console.log(step.changeType); //
"ADD_POLYNOMIAL_TERMS"
console.log(step.newNode.toString()); // "6 x"
console.log(step.substeps.length); // 3
});
1. Parsing mathinput
Math expressions aretrees
As humans, we read and write math as a line of text. If you were to
type a math expression, it would probably look something like this:
(1 + 2) - abs(-3) * x
You could also just look at that math expression and use your intuition
to prioritize where to start simplifying. But a computer will understand
the expression best when its stored in a tree. These trees can be
surprisingly complicatedeven a short expression like (1 + 2) - abs
There are many existing open source projects that parse strings of
math and create trees like this one. Several of these projects are also
full Computer Algebra Systems (CAS) which can provide answers to
math problems, though not with step-by-step explanations.
4) . This means math.js has to make a choice about which two things
are being added together. It implicitly adds parenthesis when
constructing its tree to make the operations binary.
But heres the issue: the binary tree that math.js generates for 2 + x +
The transformed tree is a lot closer to the way we all intuitively view
addition. We can then look at the children of (+), see that two of them
are x and two of them are numbers, and collect those like terms to get
(x + x) + (2 + 2) . Flattening multiplication works in the same way.
Notice that even though we change the tree, we still preserve the users
input and therefore our ability to teach what the student is asking.
There is exactly one situation where how we store the tree is a bit
different from what the student gave as input: subtraction. When you
see the expression 2 - x - 2 - x you probably still see -x and -x
to get 2 - x - 2 - x .
Each of these simplifying rules are tree searches that traverse through
the whole math expression tree to see if we can perform that
simplification anywhere. For example, searching for the rule => 1
During the tree search, the algorithm checks nodes one at a time
(shown in red in the gif) to see if they match a rule. For the => 1
3. If it is, then this node has matched the rule. Replace the node with
the constant node 1, to be recorded as the next step.
Every tree search in mathsteps finds one place in the tree to apply a
simplification, then returns from the search with that simplification.
We keep looking for simplifications, starting at the very top of the tree
each time, until no more simplifications can be applied. As we go, we
keep a list of each simplification that is applied, which then make up
the final step-by-step solution.
In this example, the best solution is more steps, and also requires more
code. Having pedagogical opinions makes the math solver more
complex, but these extra details create a more intuitive learning
experience because were explaining things more thoroughly.
Note how the first step makes the expression more complicated! But
then, if the tree search only does one change at a time without any
context, this could happen:
If youre curious, you can see the code for adding fractions here.
3 first, so its more efficient for the tree search to start by attempting
to perform simplifications lower in the tree.
Here are some ideas weve had about great teaching experiences built
off of mathsteps:
Keep track of the types of problems a student asks and when they
look at substeps, and use this information to customize the detail
of their future step-by-step solutions
and there are many more possibilities! If you have ideas, wed love
to hear them.
Were excited about mathsteps and hope it will improve the world of
math educational tech for both engineers and students. If youd like to
chat, work with us to create your first PR, or get some help using
mathsteps in your projects, please reach outwed love to hear from
you!