[GiNaC-list] GiNaC on the web

Dani Biró danipro93 at gmail.com
Tue Nov 2 20:57:21 CET 2021

Hey GiNaC people!

First of all, thank you for this great library!

I'm working on a web-based interface for GiNaC as a hobby project and I
wanted to share it with you.

You can try a demo frontend here: https://daninet.github.io/ginac-wasm/
Source code: https://github.com/Daninet/ginac-wasm

There is no operator overloading in JavaScript, so I had to implement
functions like add(), mul() for the different operations. The GiNaC
commands are batched for faster processing because WASM <=> JavaScript
calls are too expensive.  The demo frontend includes a PEG-based parser
written in JavaScript, but the embedded parser is also exposed through the
parse() function.

At this moment, the JavaScript/TypeScript API looks like this:
const GiNaC = await initGiNaC('./dist/ginac.wasm');
const g = getFactory();
GiNaC(g.mul(g.numeric('2'), g.pow(g.symbol('x'), g.numeric('2'))));
GiNaC(g.series(g.atan(g.symbol('x')), g.symbol('x'), g.numeric('5')));

On my computer, the native ginsh is about 10x faster in estimating Pi with
Machin’s formula compared to my WebAssembly port. That's because of the
expensive C++ exception mocks generated by Emscripten, which compensate for
the lack of native browser support for exceptions in WebAssembly. I
estimate that the performance gap can be brought down to about 1/2 of
native performance once the native exception instructions are getting
wildly available in browsers.

I plan to publish it on NPM (the JavaScript package library) when I manage
to stabilize the API and implement the remaining features.

What do you think? Do you have any suggestions or ideas?

Best regards,
Dani Biró
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.ginac.de/pipermail/ginac-list/attachments/20211102/3e1821bc/attachment.htm>

More information about the GiNaC-list mailing list