19

I am looking for a simple computer algebra system (cas) for JavaScript but I can't find anything with google. I only need basic functionality:

  • simplify expressions to some canonic form. Ability to check if two expressions are the same, i.e., a(x+y) == ax+ay
  • parse mathematical formulas. I want it to be able to read expressions like ax²+4x.
  • solve simple equations etc.

Do you know of such a library?

SJuan76
  • 24,532
  • 6
  • 47
  • 87
Jonas
  • 19,422
  • 10
  • 54
  • 67
  • Solve simple equation: How simple? Simple operations can build unsolvable equations e.g. `x^x = 3` or `x^5 + x^3 - 6*x^2 + 3 = 0`. – kennytm May 02 '10 at 12:56
  • BTW, try to Google for "Symbolic math". – kennytm May 02 '10 at 12:57
  • 4
    @KennyTM Those equations aren’t unsolveable, unless you’re talking about how they have multiple solutions. Solutions: [`x^x = 3`](http://www.wolframalpha.com/input/?i=x^x+%3D+3%3B+solve+for+x), [`x^5 + x^3 - 6*x^2 + 3 = 0`](http://www.wolframalpha.com/input/?i=x^5+%2B+x^3+-+6*x^2+%2B+3+%3D+0%3B+solve+for+x) – Rory O'Kane Oct 27 '12 at 12:57
  • Bountying, as I'm really interested in this. – Giulio Muscarello Dec 10 '12 at 15:22

8 Answers8

6

(I'm answering myself, as the bounty failed to bring attention on this.)

You might want to try this CAS, which has some good functions (although some parts are broken, use the older versions).

Giulio Muscarello
  • 1,312
  • 2
  • 12
  • 33
5

You can try nerdamer

  • simplification
  • factoring
  • expanding
  • custom functions
  • vectors
  • matrices
  • integration
  • differentiation
  • root solver
  • interpolation

//Expanding
var result = nerdamer('a*(x+y)',null,'expand');
document.getElementById('text').innerHTML = '<p>'+result.text()+'</p>';
//Solving equation
var sol = nerdamer.solveEquations('0=x^2+x+a','x');
document.getElementById('text').innerHTML += '<p>'+sol.toString()+'</p>';
<script src="http://nerdamer.com/js/nerdamer.core.js"></script>
<script src="http://nerdamer.com/js/Algebra.js"></script>
<script src="http://nerdamer.com/js/Solve.js"></script>
<div id="text"></div>
ArchHaskeller
  • 1,270
  • 1
  • 12
  • 28
  • It's just a coincidence that it shows `0.5` for `1/2` in this example, so that it doesn't seem to be a numeric solver. Try something that should return `1/3` or `sqrt(2)` instead. – polkovnikov.ph Oct 08 '15 at 19:50
  • @polkovnikov.ph Please give an example of such an equation. – ArchHaskeller Oct 08 '15 at 22:20
  • I kind of understand what polkovnikov.ph is saying. At the time of his comment coefficients were represented as decimals so in reality they were approximations when used in the solver. In newer versions however this is no longer the case. 1/3 is a real ratio and sqrt(2) is no longer converted to a decimal until instructed. – jiggzson Sep 19 '16 at 00:11
2

You might also look at JSolve: http://www.movss.com/~rich/jsolve/

It's written in Java and compiled to JavaScript using the GWT framework.

1

I found another one that looks decent, Coffeequate.

Keavon
  • 6,837
  • 9
  • 51
  • 79
0

You could try Wolframalpha API. http://products.wolframalpha.com/api/documentation.html

Ivan Solntsev
  • 2,081
  • 2
  • 31
  • 40
  • First, Javascript cannot access external web sites. Second, W|A is not properly a CAS. Third, its ToS forbide the access by automated means. – Giulio Muscarello Dec 17 '12 at 11:55
  • First, XMLHttpRequest on Samsung can access external web sites. Second part is true, but you can extract symbolic interpretaton from response. Third, what part of http://products.wolframalpha.com/api/termsofuse.html prohibit automated access? – Ivan Solntsev Dec 17 '12 at 11:59
  • Sorry, about XMLHttpRequest you right. I confuse this question with about SmarTV. Yes, you need to proxy requests to wolfram API to get results in JavaScript. This can be done by setting up ReverseProxy on site where your project is hosted. – Ivan Solntsev Dec 18 '12 at 06:47
  • You're right about the automated access part - I confused the W|A ToS with its API ToS. – Giulio Muscarello Dec 18 '12 at 10:05
0

To add a solid library to the list: http://mathjs.org/

It even helped to solve a problem with complex calculations.

Community
  • 1
  • 1
Avatar
  • 14,622
  • 9
  • 119
  • 198
0

To parse mathematical formula's you might give jscc a try. Solving them is left as an exercise for the reader...

Bitsplitter
  • 980
  • 7
  • 17
0

Algebrite seems to be a very good one: http://algebrite.org

There is a list of more than 7 other CAS libraries for JS at the bottom of their website.

Samer Alkhabbaz
  • 507
  • 5
  • 7