-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
SymPy translation to JavaScript #165
Comments
I would like to point out that this is already sort of a thing using pyodide, which fully supports sympy! 🎉 |
@Kreijstal isn't it easier to extend an existed lib than create a new one? It might be faster to add set theory, simplify boolean expressions, solve inequalities to Math.JS. What do you think? |
I think currently, it really makes little difference. Since the amount of effort to make an alternative to sympy is around the same, but of course, if you decide to update existing math libraries, then, by all means. Please do so. Also it doesn't mean we cannot use their functions that they define if it saves time. |
@Kreijstal do you know if someone worked on this feature? I would like to learn more about these algorithms by doing tools. |
In order to do inequalities you need to have a way of using operation on sets of numbers see this for example |
I mean, sure I've done this and it's pretty nice, but of course it's a bit heavy since it has to use nasm, and painfully slow, on phones, for example, would be nice native javascript but of course, its still an option. just timed it |
Yes, the size of pyodide is definitely a big issue. It should be possible to slash the size at least in half, as documented here pyodide/pyodide#646 If you look at the network tab, you can see that it transfers multiple megabytes of data (especially on first load, on subsequent loads most of it should be cached) Though, for development purposes, this is actually not an issue. If you use a shared worker and make sure to keep one tab open, you can keep the worker alive instead of reloading it every time. Regarding a native Javascript version, yes, that would be quite interesting indeed. The main issue is obviously finding someone who would put in the time and effort to make sure that the CAS really does end up being a top-notch CAS. Currently, projects like Giac/Xcas seem like the closest thing to a proper web-based CAS. |
sorry, I am not sure that I understand your message. Do you know if we have something that is similar to SymPy? If not. Should we start creating this? |
If we want to implement some features like python's |
What do you mean? If you're referring to Javascript operator overloading, then no, that's not necessary at all. |
Regarding point 4, the Brython developer has attempted that and ran into a few blocking issues that would have to be sorted out on the Sympy side |
If there isn't operator overloading, some arithmetic operation like the following python code would implement and write using a complicate and indirectly method. # this is a sample python sympy code
x = symbols('x')
expr = x**2 + 2*x + 1 The correspond js code maybe like this import symbols, {add, multiply, exp} from 'symbols';
const x = symbols('x')
const expr = add(add(exp(x, 2), multiply(x, 2)), 1) The form of |
@liudonghua123 As far as I know, you would need more than just operator overloading. You would need something closer to expression trees. For example, take the following expression (Javascript) const expr = 3/7; Since it's a fraction that can't be represented in base 2 nor in base 10, you would want to store the actual fraction To do that with operator overloading, you have to overload the division operator for the built-in number type. Javascript might never get the ability to do that. A more doable approach right now would be parsing string-expressions and turning them into sympy code. Something like const expr = sympy("3/7"); // Generates an expression tree |
I guess another way to achieve it is to compile https://github.com/symengine/symengine into WASM. |
Project description
As far as I know there are only three JavaScript CASes with various issues, these are
However none of those are at the level of sympy. They can't do set theory, simplify boolean expressions, solve inequalities, etc. So I figured out there could be a translation of sympy into JavaScript and there are many paths to realize this.
Edit: Because of Built in function 'super' with arguments not supported TranscryptOrg/Transcrypt#598 got stuck, because Transcrypt doesn't support super with arguments.
Just compile Python into JavaScript with emscripten.This would mean that you wouldn't have to spend so much time mantaining your port of Sympy, but depending on how you compiled it, it will take a really long time to load your libraries and might not work on all browsers (This one is what pyodide has done but currently there is no module on npm available, also pyodide seems to be dependent on the browser considering wasm support for node)Edit: Done, it works, but I get out of memory exceptions on some computers, it is extremely slow to load, it takes around 30 seconds to download a huge javascript python "binary", it doesn't work in mobile either, but, it works, yes, it does, it works, sympy in JavaScript. See also this project: https://minireference.com/static/tmp/pypyjs_sympy_demo/
[Write what technology is relevant. What language, what platform, any particular library/framework/existing project it is based on?]
Convert sympy to javascript
Pyodide
Complexity and required time
[Please only tick off one box in each category by changing
[ ]
to[x]
. The labels on the project will then be updated by the maintainers as soon as possible.]Complexity
Required time (ETA)
The text was updated successfully, but these errors were encountered: