mathjs-simple-integral icon indicating copy to clipboard operation
mathjs-simple-integral copied to clipboard

Can't compile the resulting expression

Open bgirschig opened this issue 7 years ago • 2 comments
trafficstars

Hello!

I'm very new to mathjs, but this looks like an amazing library I need to compute and use an integral for one of my projects, but it looks to me like there is a small bug with this lib:

Doing this:

math.integral('x^2', 'x').compile();

raises a arg._compile is not a function exception

But this:

math.parse(math.format(math.integral('x^2', 'x'))).compile();

works fine

I've tried tracking the problem down, and by comparing the json representations of these two:

math.integral('x^2', 'x')
math.parse(math.format(math.integral('x^2', 'x')))

I can only find one difference:

// math.integral output
{"name":"x"}

// serialized then parsed output
{"mathjs":"SymbolNode","name":"x"}

I hope that was clear, and that I'm not missing something obvious (as I said, this is the first time I use both your lib and mathjs)

Cheers!

bgirschig avatar Nov 07 '18 14:11 bgirschig

I think this is happening because you are using a recent version of Math.js (version >=5.0.0), whereas this extension internally links against version 3.18.1 (released in December 2017). If you ensure that you are using a compatible version, this plugin should work. Just to double check, I created a npm project that uses the old version of Math.js, and the following ran flawlessly in Node:

const math = require('mathjs');
math.import(require('mathjs-simple-integral'));

console.log(math.integral('x^2', 'x').compile().eval({x:1}));

That said, I should warn against using this extension, as it is unmaintained (hence why it doesn't work with recent versions), and has some pretty severe limitations on the types of functions it can integrate. If you are fine with these limitations, I can look into putting in an hour or two to upgrade this to the latest Mathjs version, which should fix your issue.

joelahoover avatar Nov 09 '18 16:11 joelahoover

Thanks for your answer, and sorry for replying so late (I though I'd had enabled email notifications). I'll check using v3.18.1 Thanks for the heads up about the extension being unmaintained. I don't think I'll have the time to make a fix: I needed the lib for a small side project that I had to cancel because of lack of time

Thanks again, and sorry for not helping (at least for now)

bgirschig avatar Nov 24 '18 17:11 bgirschig