Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Symbol evaluate() method #95

Closed
gksander opened this issue May 13, 2017 · 2 comments
Closed

Symbol evaluate() method #95

gksander opened this issue May 13, 2017 · 2 comments

Comments

@gksander
Copy link
Contributor

I see that the Symbol prototype does not have an evaluate method, but the master nerdamer function has an option to evaluate by passing an object. Is there currently a way to evaluate a Symbol object in a similar way, by passing an object with variable-value pairs?

As an explicit example, if I get a Symbol object returned from the integrate function, is there currently a way to evaluate that Symbol at a numerical value?

@jiggzson
Copy link
Owner

The Symbol class is sort of a private class and was never meant to be exposed. The expression class was created for this purpose and is therefore the one that has been documented. If you must interact with the Symbol class directly then I guess core.PARSER.parse is what you'd be looking for. I've found that it's more efficient to convert to string and re-parse then to modify the existing object. So for example:

var core = nerdamer.getCore();
var _ = core.PARSER;
var x = nerdamer('x^2-y+x').symbol;
console.log(_.parse(x, {x: 2}).toString());

Is this what you're looking for?

@gksander
Copy link
Contributor Author

Right -- the Expression is the public interface. Yes, I believe your suggestion works! Actually, that was my first guess (use toString() and reparse) but I didn't know if that was the best option. Thanks!

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

No branches or pull requests

2 participants