google / mathsteps

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

Distribute exponent #197

Closed aliang8 closed 7 years ago

aliang8 commented 7 years ago

1) Given an expression in the form (base)^exponent, where base is a multiplication node and the exponent is any term, we want to distribute the exponent over each term.

e.g. (x^2 y^2)^(2) -> x^4 y^4 e.g. ((x + 1) (x + 2))^2 -> (x + 1)^2 (x + 2)^2

2) Given a node raised to a negative power, negate the exponent and reciprocate the node. Returns a nodeChanged Status object.

e.g. (x y)^-1 -> 1/(x y) e.g. (2x^2)^-1 -> 1/(2x^2)

TODO: I will be adding support for distributing exponents over nthRoots soon. There is quite a few things going on in this PR and it would be better for you to start reviewing as I add more support.

ldworkin commented 7 years ago

This is awesome! I have one question above about your logic for exponent distribution. Also, wondering if the negative exponent business ever gets us into trouble. Are there ever times where we don't want to do this? I might need to think about this more to come up with a possible example ...

aliang8 commented 7 years ago

This is officially ready for review :D

ldworkin commented 7 years ago

Wondering, what was the motivation for the negative exponent change? Was it this Asana task: "x/x^2 -> x^-1, but should be 1/x"?

ldworkin commented 7 years ago

Also you say in the description "I will be adding support for distributing exponents over nthRoots soon." but from the test cases it looks like that works fine? e.g. ['(nthRoot(x, 2) * nthRoot(x, 3))^2', 'nthRoot(x, 2)^2 * nthRoot(x, 3)^2'

Edit: I see, it looks like you just added support for this! 🎉

ldworkin commented 7 years ago

I think this PR also fixes this Asana task, right?! https://app.asana.com/0/329831092427581/385493588159834 - "Make (nthRoot(x, 2))^2 one step"

evykassirer commented 7 years ago

I think I'll wait for you to address Lili's comments before I take a look :) Then hopefully it'll be a quick review!