What library can parse & solve a simple math expression in C++ [closed]
Asked Answered
F

1

15

I have an arbitrary expression in a string. Let's say: y=12*x+34 I will have x or y and I need to solve for the other. muParser does a brilliant job of solving the first form given x but it and all the other math parsers I've found cannot perform any sort of manipulation to turn the expression into: x=(y-34)/12 so the other could be solved if I had y instead of x.

Is there a C/C++ library out there that isn't GNU encumbered that can be used to solve this?

Fi answered 24/2, 2012 at 13:57 Comment(1)
You can check the tutorial on how to create an own compiler with LLVM. It basically does just this, iirc. You probably have to extend it a lot, though. See here: llvm.org/docs/tutorial/LangImpl1.htmlVassell
P
0

It looks like you want to embed a proper CAS. Try GiNaC, if it is not powerful enough, think of embedding Maxima or Axiom (both are very heavyweight and runs on top of Common Lisp).

Preponderate answered 24/2, 2012 at 15:55 Comment(4)
Unfortunately GiNaC is GNU encumbered.Fi
@hsikcah, then probably your best bet is to use a heavyweight CAS (license does not matter) spawned in a separate process, and communicate with it via a socket or a pipe.Preponderate
I hope to find some simple lightweight CAS to do the job. In my case it's fairly simple algebra - the need for a 100mb math processing package capable of putting a man on Mars sounds like a bit of overkill.Fi
@hsikcah, GiNaC was the smallest I've ever met. Chances are you've got to write your own library. It is not that complicated.Preponderate

© 2022 - 2024 — McMap. All rights reserved.