google / mathsteps

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

Solve/simplify using scope (a la math.js' eval) #209

Open Ephs05msm opened 7 years ago

Ephs05msm commented 7 years ago

Hello,

Thanks so much for your work on this project. Super interesting and the mission is such a worthy one. I found you all via the math.js site -- then read the blog post -- and am curious whether mathsteps can use an array of symbols (e.g., { x: 10, foo: 20, bar: "foo + x", baz: "bar^2" }) passed in as a scope. In math.js this can be done in math.eval(expr, scope). But math.js returns just the solution and not the steps. I imagine this boils down to (at least) a "change type" of substituting symbols for their respective values. Given the potentially recursive nature of traversing the symbols (e.g., baz in the example above), this may not be a simple thing ... but that's also a bit of what mathsteps is doing I believe.

I poked around the codebase and don't see an obvious way to accomplish this so I thought I would ask.

Thanks again, Matt

tkosan commented 7 years ago

Substitution of symbols is a capability of computer algebra systems (CAS), and MathSteps is slowly accumulating CAS capabilities. MathSteps is able to perform symbol substitutions, but I don't think support has been included yet for the example you provided. However, I don't think it would be difficult to implement. I created the following solution to the problem you posted using the MathPiper CAS:

Evaluate a list using substitution

Is this approach similar to the one you have in mind?

Also, what are you interested in using this kind of capability for?

Ephs05msm commented 7 years ago

Thanks for the reply and MathPiper example. Yes, that approach works well.

My interest in this capability is in the context of how spreadsheets are sometimes used: one might build up a range of inputs and then reference those inputs in formulas elsewhere. Evaluating the formulas requires substituting cell addresses (e.g., A1, B2, etc.) with the values. I'd like to explore an expanded way of auditing formulas that shows the steps. Excel includes a built-in tool to evaluate formulas that does the substitution and can step through the calculation, but it will not display more than one step at a time.

I'm interested in trying to use MathSteps to display many/all of the calculation steps (including the substitution step) to see if it helps with understanding more complex formulas.

Is there something that I can do to help add this capability to MathSteps? I'm somewhere between beginner and intermediate in terms of experience. With some guidance/oversight, I believe I can be helpful.

Thanks again.

tkosan commented 7 years ago

MathSteps is currently undergoing a bug fixing phase to get it ready for a release that will be used to help with Socratic's upcoming fundraising event. After that the plan is to heavily modify the codebase to switch it to a rules-based design. Experimenting with enhancing MathSteps to support step-by-step spreadsheet evaluation would probably best be done after the switch to a rule-based design has been completed.

If you would like to experiment with this idea sooner rather than later, an option would be to prototype it in MathPiper (which is rule-based), and then convert the prototype into MathSteps after the conversion to a rule-based design has been completed. If you are interested in pursuing this option, I would be willing to help you. I could also teach you how rule-based programming works, which would be helpful for working on MathSteps in the future.

evykassirer commented 7 years ago

Hi Matt!

Thanks for reaching out. I'm glad you think the project and mission is interesting - I do too :D

I think that traversing the tree and subbing stuff in probably won't be too tricky - the main thing that'd be blocking for implementing this is around design and how the user would provide this and how we'd store it and all that. I think for now it'd make more sense if I helped you write some code (we could even keep it in mathsteps in a file that's not used yet, but is tested?) that:

  1. on input with an expression and an array of symbol/value pairs
  2. replaced every instance of symbol with value in the expression, recursively (I could see this looping with something like x = y and y = x but we can just try to detect that and then throw an error or something)
  3. take the resulting expression and pass that through mathsteps as it currently works

That would help you for now, would be a fun problem for me to work on with you if you want (algorithms!), and would pave the way for it to be used in mathsteps eventually

So let me know if you'd like help getting that set up - happy to chat!


Separately (thanks for the context so far Ted), there's actually an update on our end that I've been meaning to share on gitter. (no pressure to read this Matt - it's not totally relevant to your question xD)

I'd gotten a bit burned out from reviewing Socratic's PRs (which is why I haven't shared yet haha, taking it easy) and they want to do a 'move fast and break things' approach for fundraising which has led us to decide that the best solution for them while they're in startup mode (for now) is to make a private version of this repo that they'll keep working on in whatever fast (and maybe not pretty) ways they want. It kinda sucks because this version of the code won't be used in their app for a bit, but I think it's better for building the community and cleaning up the code because they can't prioritize that right now.

Next step for me is planning the semantic-math porting process (the huge refactor to clean stuff up and switch how rules are described so it's easier to add new ones!) - scoping out what needs to be done to get it completed, what functionality we still need to add into the parser and rule creator, etc. I'm hoping Kevin will be down to help but I'm not sure what he's up to these days so this is all tbd. If you're down to help with that Ted let me know!

Once that's done, we'll probably dive into ways to change the way we store step changes to add more functionality for what Matt is suggesting as well as systems of equations and all that fun stuff.

Anyways - excited to have more control going forward, but also not gonna rush this because I don't wanna burn out - I want this project to keep getting more and more awesome for a long time 😊

evykassirer commented 7 years ago

oh also @Ephs05msm neat use case! It's so neat to see how different folks are using mathsteps :D

Ephs05msm commented 7 years ago

Ted, thanks again for the explanation, context, and offer to help. I've interpreted Evy's follow up as being the preferred approach, but your helpfulness is not lost on me!

Evy, hi and thanks so much for the thoughtful reply! I'd love to team up with you on this if you don't mind guiding me a bit. I've never contributed to a repository with more than just me in it, so I'm a bit apprehensive (simply from lack of experience) that I'll mess something up for you. If you can school me on some best practices I'm happy to dive in alongside you.

Bit of background on me: I've been in real estate finance for the last seven years (hence the Excel use case) but have loved technology forever and have spent the last 18 months self-educating to move into software/web development. Took CS50 through Harvard's EDx offering last fall and have been focused on Javascript since then. Currently working on a project in Elm ... using ports to talk to MathJS. And that brings me to you all!

When you're in a good spot to take a run at this, please let me know how you like to chat/coordinate.

Thanks again and enjoy your weekend, Matt

evykassirer commented 7 years ago

omg Elm! I actually want to learn Elm because I'm giving a talk on mathsteps in September at StrangeLoop and decided to attend Elm-Conf the day before (gotta learn some Elm first though!) Maybe we can teach each other some stuff haha

I think this would be a pretty safe contribution to a bigger project because your code won't be used by anyone except you for a while! It's also a nice project in that there's little setup, it's easy to write tests for (so you know if you broke something 😂), and there's a linter that'll complain if you write code that's not in the style guide. I'm also happy to help with whatever!

I'm travelling to Canada today ✈️ 🇨🇦 but we can start chatting more about options for this! Either here on gitter https://gitter.im/mathsteps-chat/Lobby both works for me. Even happy to call if that's easier, but probably not in this next week.

My thoughts starting out:

Let me know if you want me to clarify anything - I think it's really cool that you're learning coding on your own and even after doing it for a little while now am often asking questions about things people say/talk about/code I read that I don't understand so I love questions - just lemme know if I can provide any more info to get you started (here on gitter)

tkosan commented 7 years ago

@Ephs05msm since the MathSteps project has moved back to a less rushed mode of development, I think taking Evy up on her offer to help you implement your feature in MathSteps is a good way to go. Also, concepts such as parsing code into abstract syntax trees is often not covered until towards the end of a CS degree. If you need some help learning these concepts, feel free to ask.

@evykassirer yes, I would like to assist with the semantic-math port. My thought is to go ahead and create an issue for the porting process so we can start discussing it. Sometime soon I would also like to discuss the users that MathSteps is initially targeting. In this project I have noticed it is very challenging to develop for users (currently K-12 students) who can't be communicated with directly. Being able to talk to a user (in this case Matt) directly has been refreshing, and I would like to do more of it. A huge group of potential MathSteps users are average computer programmers who received an inadequate mathematics education and who would like to fix this deficiency. I think a good case could be made for shifting MathStep's emphasis from K-12 students to these average programmers.

Ephs05msm commented 7 years ago

@evykassirer this is super helpful; thanks! I'll plan to get the library working locally today and then dig into TreeSearch.js in the context of your suggested approach. If I get stuck/confused and can't research my way out of it I'll come back for help. Will also get setup with gitter and look for you there if the question seems like a good fit for IM. Happy to chat by phone at some point as well, especially if I submit something that you'd like to review together. Thanks so much again for the offer to help. I'll do my best to be productive and respectful of your time.

@tkosan thanks for the context/forewarning on abstract syntax trees. The concept was introduced in the CS50 course but I'm sure many of the critical implementation details were omitted given the audience. I'll revisit the course materials, attempt to self-educate a bit when needed, and then come back here with informed questions if I'm still not understanding. Thanks again.

Ephs05msm commented 7 years ago

Also, happy to chat about Elm anytime. I know just enough to be dangerous. For someone very much still trying to get my bearings in development, I appreciate the strong guarantees that Elm provides/enforces.

Ephs05msm commented 7 years ago

@evykassirer @tkosan Just submitted a first pass for review. Look forward to discussing with you at your convenience. Thanks again for the help.

evykassirer commented 7 years ago

@tkosan

re: creating an issue to discuss - sounds good. I'll probably open it after I get back from Canada, and will also do a bit of playing around to see what kinds of things break if I just replace the bodies of the Node.Creator and Node.Type functions with calling math-parser's equivalents

re: changing the user: I really want to keep this for students. That was the goal all along and I think it's a neat teaching problem and the motivation behind this project. I agree reaching students is important, and @nitin42 's demo is gonna be great for that - hopefully eventually students will be using our website for their math homework and we can ask for feedback there! But learning about other use cases and making it easy for them to also use mathsteps if possible is definitely something I'd support :)

@Ephs05msm woo! I'll take a look