google / mathsteps

Step by step math solutions for everyone
https://socratic.org
Apache License 2.0
2.12k stars 275 forks source link

update equation code to have an equation node #140

Open evykassirer opened 7 years ago

evykassirer commented 7 years ago

blocked on #128 (new parser) because once we have a new tree we can easily add equation nodes to it

--

once it's is done, we can make the equation code a lot nicer

see #126 for some more details, and we can plan this out better once the parser swap is done

hmaurer commented 7 years ago

math-parser will introduce a nice unified system for equations and simplifications. From what I gather there will be relation nodes (equal, less than, etc) which will model equations. There will also be all and any nodes to model a list of equations where all/any must hold. We will then be able to rewrite solveEquations as a function that takes a all node where all members are relations, etc! :)

kevinbarabash commented 7 years ago

There will also be all and any nodes to model a list of equations where all/any must hold.

I ended up making a System node to model systems of equations. This avoids having to check two properties to determine if it's a system of equations (or inequalities).

I'd like to migrate mathsteps to use nodes from math-ast before introducing an equation node (aka Relation).

evykassirer commented 7 years ago

agreed, let's get it working with what we have, then slowly add functionality that math-ast can support :)

hmaurer commented 7 years ago

@kevinbarabash Are you sure that's the way to go? It seems that adding nodes which are just "verified" versions of other nodes generates extra complexity for little benefit. I don't see a problem with a system being represented as

{
  type: 'All',
  args: [
    { type: 'Relation', rel: 'eq', args: ['2x', '3'] },
    { type: 'Relation', rel: 'eq', args: ['x + 1', '0'] }
  ]
}

Is the following what you are proposing?

{
  type: 'System',
  args: [
    { type: 'Relation', rel: 'eq', args: ['2x', '3'] },
    { type: 'Relation', rel: 'eq', args: ['x + 1', '0'] }
  ]
}

In which case we would have both System and All nodes which do similar things?

kevinbarabash commented 7 years ago

@hmaurer I couldn't think of another use for an All node beyond using it for system of equations. If it's only used for system of equations then calling it that makes the intention clear. Also, I found All to a bit ambiguous. Does it mean that all of the equations must be satisfiable? If so, there are systems of equations where that isn't true.

hmaurer commented 7 years ago

@kevinbarabash Mmh I can't think of another use of All within the scope of mathsteps either, but I can think of uses for Any, e.g. when solving equations involving absolute values. I quite like the All - Any pair, but you make a good point.

And yes regarding "all equations must be satisfiable". Isn't that a good semantic for it? Solving a system of equations is then asking "can you find values for these variables such that those equations are all satisfied". It might fail, of course, but it still seems to make sense?