Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

should a b be implicit? #133

Closed
kevinbarabash opened this issue Feb 19, 2017 · 13 comments
Closed

should a b be implicit? #133

kevinbarabash opened this issue Feb 19, 2017 · 13 comments

Comments

@kevinbarabash
Copy link
Contributor

It seems weird to treat 2 a as implicit but not a b or 2 a b.

const steps = mathsteps.simplifyExpression('a b * 1');
console.log(steps[0].newNode);

Node {
  implicit: false,
  op: '*',
  fn: 'multiply',
  args:
   [ Node { name: 'a', changeGroup: undefined },
     Node { name: 'b', changeGroup: undefined } ] }
const steps = mathsteps.simplifyExpression('2 a b * 1');
console.log(steps[0].newNode);

Node {
  implicit: false,
  op: '*',
  fn: 'multiply',
  args:
   [ Node {
       implicit: true,
       op: '*',
       fn: 'multiply',
       args: [Object],
       changeGroup: undefined },
     Node { name: 'b', changeGroup: undefined } ] }

I would expect 2 a b to be parsed as a single implicit: true, op: "*" node. As we start to support multivariate equations as proposed in #130, we'll probably want to differentiate 2 a b from 2 a * b.

@evykassirer
Copy link
Contributor

oo yeah. mathsteps doesn't really consider multivariable things very well

One issue is that mathjs parses 2ab with "ab" as a single symbol (pretty sure) --- but if we start using math-parser I guess we can fix that :D

And flattenOperands doesn't have great logic for multivariable implicit multiplication. As we start to support multivariable, I would definitely like to fix this. And in general, be better about when to make things implicit and when not.

Thanks for opening this!

@kevinbarabash
Copy link
Contributor Author

Does it make sense to parse 2xy * xy as:

{ 
    op: "*", 
    implicit: false, 
    args: [
       {
           op: "*",
           implicit: true,
           args: [2, "x", "y"],
       },
       {
           op: "*",
           implicit: true,
           args: ["x", "y"],
       }
    ]
}

@evykassirer
Copy link
Contributor

evykassirer commented Feb 19, 2017

yeah, I think it makes sense to parse it like that (though "2" would a number node and "x" a symbol node, and stuff)

but eventually, as we're solving, I think the tree should look like

{ 
    op: "*", 
    implicit: ???, 
    args: [2, "x", "y", "x", "y"],
}

so that we can group similar terms together to get 2 * x^2 * y^2 (or `2 x^2 y^2 depending on how we use implicit)

if you were to teach this, when would you use implicit vs explicit notation (after parsing the original input as whatever they wrote)

@kevinbarabash
Copy link
Contributor Author

Given the equation 2xy = 1/(xy) I might multiply both sides by xy and would probably want to show that as:

   2xy = 1/(xy)
=> 2xy * xy = 1/(xy) * xy
=> 2x^2y^2 = (xy)/(xy)
=> 2x^2y^2 = 1

@hmaurer
Copy link
Contributor

hmaurer commented Feb 25, 2017

What about functions? For a built-in function like "sin" it is easy to parse sin(x) properly, but what about non built-in functions? Should f(x) parse asf * (x) or f applied to x? Also what if the student makes a typo, e.g. si(x)? Should that parse as s * i * (x)?

Edit: Mathematica, for example, seems to interpret spaces as implicit multiplication. So ab would parse as a single identifier ab, but a b would parse as a * b.

@evykassirer
Copy link
Contributor

mathjs parses any string followed by a ( as a function call, so x(y + 5) treats x as a function name. for multiplication you'd have to do x*(y+5).

not sure what we want to do for our parser - probably the same? ideally we could parse from latex

@hmaurer
Copy link
Contributor

hmaurer commented Feb 25, 2017

@evykassirer Mmh yeah that makes sense I think! What about "numbered" variables? e.g. x1, x2, etc. Would we also special-case this so that it parses as a single identifier? I think I like was @kevinbarabash in the original post better, where you need to add spaces explicitly for implicit multiplication.

@evykassirer
Copy link
Contributor

yeah, any numbers following a letter would be included in the symbol name

(I believe mathjs does this as well)

@kevinbarabash
Copy link
Contributor Author

math-parser parses multiple character identifiers include those containing digits. We may also want to support variables with subscripts, e.g. x_1, x_2, ... x_n. I've accounted for subscripts in Identifier nodes, but haven't implemented the parsing yet.

@evykassirer
Copy link
Contributor

cool stuff!

@aelnaiem
Copy link
Collaborator

Going to close this issue because it seems resolved :)

@evykassirer
Copy link
Contributor

(resolved as in it'll be eventually handled in math-parser?

@aelnaiem
Copy link
Collaborator

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants