X

Sundararajan's Weblog

Playing with Nerdamer symbolic math JS library with Nashorn jjs

I was searching for a self-contained, simple JS library for symbolic math to check homework solutions of my son. On googling "symbolic math javascript", the first hit I got was http://www.nerdamer.com/


I git cloned the source from the git repo:
$ cd ~/src
$ git clone https://github.com/jiggzson/nerdamer
$ cd nerdamer

There is a nice documentation for nerdamer @ http://www.nerdamer.com/documentation


I started Nashorn jjs shell. The following is from my jjs session with nerdamer.


$ ls
Algebra.js changelog.md nerdamer.core.js Solve.js
Calculus.js license.txt README.md

Note: I used rlwrap - http://freecode.com/projects/rlwrap - for better line editing support. Note that rlwrap is not needed for jdk9 builds.
jjs in jdk9 build has integrated better line editing support, tab-completion etc using "jline". "rlwrap" is suggested only for jdk8u builds.


$ rlwrap jjs -scripting
jjs> load("nerdamer.core.js")
jjs> load("Algebra.js")
jjs> load("Calculus.js")
jjs> load("Solve.js")
jjs> nerdamer('sqrt(x)*sqrt(x)-2').evaluate({x:2})
0
jjs> nerdamer("diff(tan(x), x)")
sec(x)^2
jjs> nerdamer.solveEquations("x^2 + 1 = 0", "x")
i,-i
var f = nerdamer("x^3 + sin(x)").buildFunction()
jjs> f
function (x) {
return (Math.pow(x,3)+Math.sin(x));
}
jjs> f(Math.PI)
31.006276680299816

I really like this self-contained JS library. No browser specific stuff (window.call_crap_function() --
so that I didn't have to introduce fake helper functions! And no "require('foo.js')" module stuff -- so that I didn't have to fake
a require using nashorn's "load" function. Nerdamer works as advertised and runs smooth on Nashorn!

Join the discussion

Comments ( 2 )
  • guest Sunday, September 27, 2015

    Nerdamer is to be used as a node module(server side) as well as on the browser(client side).


  • guest Sunday, September 27, 2015

    nerdamer is a node module as well as a browser library. It is meant to be used as both.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.