8 ms·
Maxima in the browser using Embedded Common Lisp on WASM
- v9v 2y agoRaymond Toy posted this on the ECL mailing list: https://mailman3.common-lisp.net/hyperkitty/list/ecl-devel@common-lisp.net/thread/T64S5EMVV6WHDPKWZ3AQHEPO3EQE2K5M/ https://mailman3.common-lisp.net/hyperkitty/list/ecl-devel@c...
- deleted 2y ago[deleted]
- magicalhippo 2y agoI've tried Maxima on a few occasions but the syntax somehow fails to agree with me. Been looking for a self-hosted alternative to Wolfram Alpha, and just stumbled over Mathics, which has a Django front-end[1]. Rough but usable Mathematica alternative, at least for basic use. [1]: https://github.com/Mathics3/mathics-django https://github.com/Mathics3/mathics-django
- pkaye 2y agoThere is also Expreduce which is a CAS written in Go that follows Mathematica syntax. https://corywalker.github.io/expreduce-docs/ https://corywalker.github.io/expreduce-docs/
- rockybernstein 2y agoVery recent is david a roberts work to get this running on Pyodide, marimo and Observable. See https://mathics3.github.io/Mathics3-live/ https://mathics3.github.io/Mathics3-live/ and https://github.com/Mathics3/Mathics3-notebook-frontends https://github.com/Mathics3/Mathics3-notebook-frontends All of this is a little new and wobbly, but I expect things to stabilize in a month or so. (And sooner or better if more people get involved).
- magicalhippo 2y agoThat looks very interesting, thanks for the pointer!
- r85804306610 2y agobecause nobody knows maxima, some things to try. also plot2d/plot3d work, so that's pretty neat. the whole thing is powered by https://ecl.common-lisp.dev https://ecl.common-lisp.dev and the op announcement is here https://mailman3.common-lisp.net/hyperkitty/list/ecl-devel@common-lisp.net/thread/T64S5EMVV6WHDPKWZ3AQHEPO3EQE2K5M/ https://mailman3.common-lisp.net/hyperkitty/list/ecl-devel@c... :lisp (+ 2 2) solve(f(x)^2-1,x); integrate(x^2,x); 2^1024; factor(30!); a:1 b:2 a+b; sqrt(a^2+b^2); expr: log((x+2)*(x-2))+log(x); ratsimp(expr); fullratsimp(expr); trigsimp(2*cos(x)^2 + sin(x)^2); solve(x^3=1,x); diff(sin(x), x); float([%e,%pi,%phi,%gamma]); f(x):=x^2; f(10); taylor(sin(x),x,0,5); plot2d(x^2-x+3,[x,-10,10]); plot2d([x^2, x^3, x^4 -x +1] ,[x,-10,10]); f(x,y):= sin(x) + cos(y); plot3d(f(x,y), [x,-5,5], [y,-5,5]);
- michaelsbradley 2y agoThank you! As someone with no prior Maxima experience, those were some great starting points for me to learn and explore! Note `plot3d(...);` doesn't seem to work: the output image is missing/broken.
- williamstein 2y agoplot3d did work for me (on Chrome). Impressive.
- r85804306610 2y agoyou probably didn't define the function, f(x,y), which is the line before plot3d. it's a slightly buggy behavior
- michaelsbradley 2y agoAh, yes, can reproduce the problem if f(x,y) isn't defined. Also, if f(x,y) is "broken" (e.g. by a typo like syn instead of sin) then the effect is the same.
- seanhunter 2y agoOne thing I would add for people who are new to this is you can do ??something; to get the internal help. So say I want to know how to solve ODEs in maxima, do ??ode; …and you’ll get help. It generally does a search and presents a numbered list of options and you’ll want to type a number and a semicolon.
- hackernj 2y agoNice. I've been using this Maxima interpreter: http://www.dma.ufv.br/maxima/index.php http://www.dma.ufv.br/maxima/index.php
- veryveryold 2y ago(to_lisp); (loop for i below 1000000 count t) takes 0.34 seconds on my system with vanilla maxima (on gcl). In the browser it takes about 7 seconds, so it must be a factor of 21 in computer time. Using sbcl outside maxima it takes 0.002 seconds. So one can get some idea about performance. Perhaps it could be combined with J (array language), like in the playground https://code.jsoftware.com/wiki/Playground https://code.jsoftware.com/wiki/Playground that is using webassembly It seems to work very well locally without connection to the web.
- jackdaniel 2y agoWeb version of ecl when compiler is invoked at runtime, uses one-pass bytecodes compiler, so things tend to lack optimization unless compiled beforehand.
- disentanglement 2y agoApart from the restriction to bytecode interpretation already mentioned, one reason for the slowness is that the sort of C with garbage collection that ECL needs is quite difficult to do in Webassembly. There is no way to scan previous stack frames for pointers in wasm, so all pointers to heap objects (or everything that looks like it might be one) have to be kept around somewhere in the heap where the GC can find them. This is really expensive and slows down the code a lot. Of course, another approach would be to use the new wasm GC interface. But that requires defining a new ABI for garbage collected C, writing a new backend for LLVM, etc. So that would also be a lot of work to implement. Right now, there just is no efficient way to run programs that depend on bdwgc on wasm.
- unusual-name 2y agoWe used maxima extensively in high school. I remember that I forgot to bring my laptop when we had our first maxima lesson. My teachers understandably scolded me for not bringing my laptop to school, but to their surprise I found an online version of maxima. [1] While it was good enough for this period, in contrast to this implementation it was truly awful. I just think it's kinda sad that a lot of people never heard of maxima, as it is a pretty decent tool once you learn how to use it. [1] http://www.dma.ufv.br/maxima/index.php http://www.dma.ufv.br/maxima/index.php
- forgotpwd16 2y ago>scolded me for not bringing my laptop to school That sounds stupid. What if someone doesn't have a laptop? Even if do, cannot see why one's obligated to bring it along. >in contrast to this implementation it was truly awful It surely has the advantage of interactivity. The version you linked seems to restart the session in every query. On the other hand, seems more stable. Both `invert(matrix([2,3,1], [a,0,0], [1,4,8]));` and `draw3d(explicit(x^2+y^2,x,-1,1,y,-1,1));` that run fine in UFV's DMa version fail to run in the submitted one.
- aidenn0 2y ago> That sounds stupid. What if someone doesn't have a laptop? Even if do, cannot see why one's obligated to bring it along. Where I live, the school issues laptops to students, so not bringing the laptop is today's not bringing your textbook. (As a point of fact, my daughter is in 10th grade and has had exactly one physical textbook so far; the rest have been digital)
- dartos 2y agoHow did you get Common Lisp running on wasm? I thought wasm didn’t support tail call recursive
- jackdaniel 2y agoCommon Lisp does not require TCO. This runs on emscripten port of Embeddable Common Lisp - this platform support is relatively new. I'm also working on WASI port and an optimizing compiler at runtime (currently we use bytecodes compiler when running).
- dartos 2y agoOh wow. I always thought TCO was part of the spec itself.
- jackdaniel 2y agoScheme requires TCO. It is a different Lisp (it also has standard[s]).
- ted_dunning 2y agoAnd revisions[n].
- JoelMcCracken 2y agoCL is not particularly functionally oriented. Many things like this are absent (or present, in some cases).
- aidenn0 2y agoThe platform supporting tail-recursion is irrelevant to hosting languages that support it; e.g. the JVM does (or at least did) not support tail recursion, but kawa scheme (which does) runs just fine on the JVM.
- fulafel 2y ago
- openrisk 2y agoomg, macsyma is still alive and I can now manipulate real tensors in the browser?
- dreamcompiler 2y agoThis is maxima, not macsyma. https://en.m.wikipedia.org/wiki/Maxima_(software) https://en.m.wikipedia.org/wiki/Maxima_(software)
- openrisk 2y agoHow different is it? > While this has resulted in some incompatibilities between Macsyma and Maxima, programs written in the Macsyma algebraic language can often be run, with only minor changes, in either system. Symbolic tensor manipulation is still supported https://maxima-on-wasm.pages.dev/doc/html/Package-itensor#Package-itensor https://maxima-on-wasm.pages.dev/doc/html/Package-itensor#Pa...
- dokyun 2y agoIt's the only Macsyma anyone's running these days, so maybe if Symbolics hadn't killed it off there'd be another version more deserving of the title.
- fsckboy 2y agotangential: can Macsyma/Maxima do symbolic boolean algebra, reducing formulae to bog standard "OR of ANDs" form? (I've tried looking at the doc, and it's clearly not a feature they showcase, and as others have said, the way it works is not intuitive to me. I really need this, but trying to do it in lisp is becoming its own project and I want to get back to my project. I found some really nice online reducers, but the UIs are not conducive to pasting/putting in simultaneous equations, and using those outputs as inputs again)
- r85804306610 2y agomaxima has logic package, written in 2009 by alexey beshenov. it lives in share/logic which is also where the texi docs are. it's included with the op version, load(logic); logic_simp (a or (b or false or (a or b))); characteristic_vector (a xor b); zhegalkin_form ((a implies b) or c); e : ((a or b) xor c) and d$ logic_equiv (e, zhegalkin_form (e)); logic_diff (a or b or c, a); demorgan (boolean_form (a nor b nor c)); etc. there's more stuff in docs
- maple3142 2y agoSimilar project: PARI/GP on WASM https://pari.math.u-bordeaux.fr/gpexpwasm.html https://pari.math.u-bordeaux.fr/gpexpwasm.html
- azakai 2y agoIt looks like the wasm file here is not fully optimized. Reading the wasm and JS, I'd guess -O1 perhaps? Linking with -O3 would make it smaller and possibly faster (10% smaller binary in a quick local test, and it removes 90% of locals, which should speed things up too) But it is possible that it's already fast enough for the purposes here, and this doesn't matter.
- jackdaniel 2y agoIt's worse, it is -O0 -- this is because of the GC and binaryen/llvm interaction. For GC to work we need to spill stack call pointers (and binaryen has such a flag!), but for the optimization level 1 and above said pointers are sometimes optimized away :3 I'm experimenting with WASI and the GC extension for WASM, but that's months from today if we speak about complete port (given my time capacity at the moment).
- azakai 2y agoInteresting, thanks for the details! WasmGC would be the best solution here, yeah, then the VM handles pointers for you. Otherwise, I could look into the SpillPointers issue for you if you want - optimizations should not remove GC pointers, so that sounds like a bug. If so feel free to file an issue with a testcase. (But WasmGC would be best, avoiding all that.)
- disentanglement 2y agoAs far as I know, optimization levels higher than -O0 work fine with SpillPointers. But at least in a cursory first look I had a while ago, the optimizations made things slower overall. I guess they might lead actually to more "moving pointers in and out of the heap" since the SpillPointers pass is done at the very end. But this should all be investigated more thoroughly.
- jackdaniel 2y agoHey! Thanks for the offer and thanks for the correction. I've revisited relevant threads and it seems that it is indeed -O0 because things are slower with higher optimization levels (I must have misremembered). Relevant links: https://gitlab.com/embeddable-common-lisp/ecl/-/merge_requests/331/diffs https://gitlab.com/embeddable-common-lisp/ecl/-/merge_reques... https://github.com/ivmai/bdwgc/issues/650 https://github.com/ivmai/bdwgc/issues/650 Most notably an entry in the INSTALL file: ``` the optimization level -O0 is used because higher optimization levels seem to interfere with the binaryen options needed to get the garbage collector to work correctly and tend slow down the program (might be worth experimenting with the optimization options) ```
- phkahler 2y agoIs there a place to get a wxmaxima installer for Windows other than SourceForge? I no longer trust stuff from there.
- v9v 2y agoThere seems to be a github repo here with binaries (but you need to get maxima separately, probably from sourceforge): https://github.com/wxMaxima-developers/wxmaxima https://github.com/wxMaxima-developers/wxmaxima
- gtpedrosa 2y agoThis brings back memories. We used this in my mechanical engineering mechanisms class. It was cool to have the (simplified!) symbolic formulas describing the movements we were designing.
- soegaard 2y agoThis is great? Feature request: A way to easily copy old expressions into the current input field (to fix mistakes).
- deleted 2y ago[deleted]
- phoe-krk 2y agoIt's called "Embeddable Common Lisp", not "Embedded Common Lisp". https://ecl.common-lisp.dev/ https://ecl.common-lisp.dev/
- vindarel 2y agoI'll add options to run Maxima: * [Maxima on Android](https://play.google.com/store/apps/details?id=jp.yhonda https://play.google.com/store/apps/details?id=jp.yhonda), built with ECL. * [Maxima on Jupyter](https://github.com/robert-dodier/maxima-jupyter https://github.com/robert-dodier/maxima-jupyter) * Maxima can be used via [SageMath](https://www.sagemath.org/ https://www.sagemath.org/) and [KDE Cantor](https://apps.kde.org/cantor/ https://apps.kde.org/cantor/). * Of course, with Emacs: [maxima-mode](https://gitlab.com/sasanidas/maxima https://gitlab.com/sasanidas/maxima) ([screenshot](https://community.linuxmint.com/img/screenshots/maxima-emacs.png https://community.linuxmint.com/img/screenshots/maxima-emacs...)) and [maxima-interface](https://github.com/jmbr/maxima-interface https://github.com/jmbr/maxima-interface) to ease the interface between Maxima and Common Lisp. * it can be used [from a Lisp REPL](https://mahmoodsheikh36.github.io/post/20230510181916-maxima_in_lisp/ https://mahmoodsheikh36.github.io/post/20230510181916-maxima...). (and [wxMaxima](https://wxmaxima-developers.github.io/wxmaxima/ https://wxmaxima-developers.github.io/wxmaxima/): a graphical frontend as mentioned earlier) (find the links and more scientific libraries for CL on https://github.com/CodyReichert/awesome-cl https://github.com/CodyReichert/awesome-cl)
- trott 2y agoHow do Maxima and SymPy compare in terms of capability, features and speed (native, not WASM)?
- rockybernstein 2y agoIn terms of features, I imagine they are about the same. Here is why I think this. Maxima's function organization seems to follow and refers to the NIST Digital Library of Mathematical Functions https://dlmf.nist.gov/ https://dlmf.nist.gov/ Mathematica and Sympy also seem to follow this organization. My take: I blame compatibility on the NIST Digital Library of Mathematical Functions.
- fud101 2y agoI love Maxima, i don't really need a CAS much these days but whenever I do, I will turn to Maxima.