r85804306610 2 days ago

because 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 and the op announcement is here 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]);
  • seanhunter 2 days ago

    One 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.

    • seanhunter 2 days ago

      Some other useful things:

      1)solve to solve a system and “variable: expression” will assign that expression to that variable. You can then substitute the results into a later expression using a “,”. So you might do

         solns:solve([x+3*y=5,5*x-2*y=4],[x,y]);
         z:%e^(x,y),solns;
      
      That will solve the system and then substitute those solutions into the expression for z.

      2)pi, e, and the imaginary unit are called %pi, %e and %i respectively.

      3)The symbolic solver is a lot less powerful than mathematica but you can do

         load(“to_poly_solve”);
      
      To get a polynomial solver that will at least get you all the roots of polynomials and does better on most trigonometric equations.

         load(“drawdf”);
      
      Is useful for drawing vector fields, phase portraits and that type of thing.

      4) you can use a single quote to delay evaluation of something. Like say you want to write a differential equation and you don’t want it to actually try to evaluate the derivative inline, you can write something like

         osc:‘diff(x,t,2) + r*’diff(x,t) + k*x = p*cos(omega\*t);
      
      …for a forced harmonic oscilator. Or whatever. This is useful if you want to mess with the expression a bit before you try to solve the expression (eg doing substitutions or whatnot).*
  • michaelsbradley 2 days ago

    Thank 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.

    • r85804306610 2 days ago

      you probably didn't define the function, f(x,y), which is the line before plot3d. it's a slightly buggy behavior

    • williamstein 2 days ago

      plot3d did work for me (on Chrome). Impressive.

unusual-name 2 days ago

We 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

  • forgotpwd16 2 days 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 2 days 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)

veryveryold 2 days 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 that is using webassembly

It seems to work very well locally without connection to the web.

  • disentanglement 2 days ago

    Apart 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.

  • jackdaniel 2 days ago

    Web version of ecl when compiler is invoked at runtime, uses one-pass bytecodes compiler, so things tend to lack optimization unless compiled beforehand.

  • ted_dunning 2 days ago

    It feels faster than the other web-hosted maxima instances out there and if you take into account the cost of installing common lisp and maxima (I only need to use this about twice a year so I don't keep them live), it can be much faster than a local instance.

vindarel 2 days ago

I'll add options to run Maxima:

* [Maxima on Android](https://play.google.com/store/apps/details?id=jp.yhonda), built with ECL.

* [Maxima on Jupyter](https://github.com/robert-dodier/maxima-jupyter)

* Maxima can be used via [SageMath](https://www.sagemath.org/) and [KDE Cantor](https://apps.kde.org/cantor/).

* Of course, with Emacs: [maxima-mode](https://gitlab.com/sasanidas/maxima) ([screenshot](https://community.linuxmint.com/img/screenshots/maxima-emacs...))

and [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...).

(and [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)

trott 2 days ago

How do Maxima and SymPy compare in terms of capability, features and speed (native, not WASM)?

fsckboy 2 days ago

tangential: 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 2 days ago

    maxima 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
azakai 2 days ago

It 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 2 days ago

    It'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 a day ago

      Interesting, 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 a day ago

        As 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 a day ago

          Hey! 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_reques... 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) ```

gtpedrosa 2 days ago

This 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.

phkahler 2 days ago

Is there a place to get a wxmaxima installer for Windows other than SourceForge? I no longer trust stuff from there.

soegaard 2 days ago

This is great?

Feature request: A way to easily copy old expressions into the current input field (to fix mistakes).

dartos 2 days ago

How did you get Common Lisp running on wasm? I thought wasm didn’t support tail call recursive

  • jackdaniel 2 days ago

    Common 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 2 days ago

      Oh wow.

      I always thought TCO was part of the spec itself.

      • jackdaniel 2 days ago

        Scheme requires TCO. It is a different Lisp (it also has standard[s]).

      • JoelMcCracken a day ago

        CL is not particularly functionally oriented. Many things like this are absent (or present, in some cases).

  • aidenn0 2 days ago

    The 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 a day ago

      Nitpick: JVM supports recursive tail calls, but doesn't have the "tail call elimination" optimization that would make tail calls consume 0 stack.

      • aidenn0 a day ago

        That's a reasonable nitpick; tail-recursion is just a special case of tail-calls, and you can do tail-calls without TCE, just not unboundedly.

  • p_l 2 days ago

    WASM supports tail calls and multiple return values now

fud101 2 days ago

I love Maxima, i don't really need a CAS much these days but whenever I do, I will turn to Maxima.

openrisk 2 days ago

omg, macsyma is still alive and I can now manipulate real tensors in the browser?