-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Parser: simplify an expression to another expression just with undefined variables. #907
Comments
Thanks for sharing your ideas! That would be interesting indeed. |
Paolo, please take a look at the discussion #811 |
Thanks, firepick1. I will try it and after I give some feedback about it. |
I've tried the fastSimplify() from equations. Indeed it's blazingly fast:
However I don't get to reproduce my simplification and replacement idea. Using mathjs syntax, with a hypothetic function simplifyPlus:
|
@paulobuchsbaum thanks for sharing these desired usage examples, that helps getting more clear what we want to be able to solve. Basically it's resolving variable values. This shouldn't be too hard: the simplifier is already resolves constants like |
Thanks for your answer. Exactly! It could be implement like a functionality extension of simplify method. It does not seem to be rocket science for those who participated in the development of the mathjs project, so useful to the community. |
Perhaps we just need a resolve primitive that resolves an expression tree with an object such as |
Such an approach would also resolve the issue raised. I believe that from the standpoint of consistency this would be the best approach because it separates resolution from simplification, but the approach of incorporating simplification into the evolving state of the environment is attractive from the point of view of practicality. It would be great to see the best math library that exists for Javascript even better. |
indeed, though I think in practice you would always use simplify(expr)
simplify(expr, scope) |
@firepick1 would you be interested to see if you can implement this feature? |
Yup. I will try to tackle that next week.
😎Karl
…On Sun, Jul 30, 2017 at 10:54 AM Jos de Jong ***@***.***> wrote:
@firepick1 <https://github.com/firepick1> would you be interested to see
if you can implement this feature?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#907 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADA_gpLDWE1jrSBB6Zvb2qZJ3fjgxzliks5sTMNggaJpZM4Omr5B>
.
|
cool, thanks! |
Turns out simplify already has an optional second arg, so we are looking at: |
heee, really?! that's cool! This hidden feature is missing in the docs. I think that |
I just discovered that mathjs supports typed argument parsing, so it is indeed possible to support both:
Therefore, this need not be a breaking change. Oh. Here are the proposed tests for resolve. @jos, @paulobuchsbaum, (and community) please review for expected behavior: |
I've saw the test.txt. It's perfect.
|
That didn't work, but this did: |
Of course!!! |
Perfect! |
@firepick1, how long do you think this update will be available for "NPM update mathjs" in node.js? |
@paulobuchsbaum timing on master merge for npm is up to Jos. It might be easier to wait for the merge. The simplify2 branch is publicly available directly on GitHub but I think the inconvenience of figuring out how to use that might not be worth your time. I'm also not sure what the mathjs process for documentation is just yet, so we'll need to wait for Jos to let us know how to proceed. |
@firepick1 and @josdejong, I have no words to thank all this. I believe this will be helpful to many people in the community. |
Great, thanks @firepick1! Nice that we don't have breaking changes after all. I can do a next release of math.js this weekend. text.txt is indeed what we're looking for. I'm in doubt though about resolving a variable that is a string: math.simplify('y', {x:2, y:"1+x"}) This is really powerful but a string is also "just" a valid value and might not always contain an expression that needs to be resolved, for example: math.simplify('y', {x:2, y:"1+x", text: "hello world :)"}) // whoops... Thinking aloud: how about an API where we separate expressions from scope (the latter only containing values, no expressions): // math.simplify (expression: string)
// math.simplify (expressions: Object)
// math.simplify (expression: string, scope: Object)
// math.simplify (expressions: Object, scope: Object)
// ...and the variant with rules
// usage:
math.simplify('x + 3', { x: 2 });
math.simplify({ x: 2, y: '1+x', result: 'y' });
math.simplify({ y: '1+x', result: 'y + size(text)[0]' }, { x: 2, text: 'Hello :)' }); The common use case is not using texts, and this way the common use case is very easy (pass a single object with all your expressions and values), and in case you do need to pass special strings or you have all your values in a separate scope, you can easily pass this as the second argument. |
Good catch--I didn't know about string values in mathjs. 😮 On the extension of simplify to allow expression objects as a handy shortcut, this might be a duplication of functionality provided by other well-established existing libraries such as lodash: See http://underscorejs.org/#mapObject |
I don't think passing a map as first argument is really duplicate of underscore functions, this is really about the handiest API for Using |
Simple for now works for me. I am easily confused. :) |
LOL |
The extended |
The mathjs package is very useful and powerful. However, there is a feature that would be awesome if it had: The ability to solve an expression with the variables that already exist, reducing it to a small and simplified expression with fewer variables, performing all operations with variables already defined. It would be like a more advanced simplification. # # #
The text was updated successfully, but these errors were encountered: