# Solve for variable in equation

Hello, I need a computer aided algebra system. I don’t know that I have one. I bet there might be a way to use APIs to re-arrange an equation for one variable to be isolated on the side But it isn’t apparent from the API documentation of OWL or z3. I see OCamlCAS out there but I wonder if perhaps there isn’t something like an ocaml interface to octave or something. I really just need to balance an equation in terms of a variable on one side. If I can do that, that would really help me a lot.

I’m sorry, but what do you want to solve? Linear equations? And in which form are they - strings to be parsed, some sort of tree, …?

I would just like to be able to algebraically rewrite equations of multiple variables. Suppose I would like to express something that starts out as y= … x…, but I would like to have x = … y …, for whatever the equations need to be on the right. I need to do this in an automated fashion.

Some eigensolver of the same sort would be good too.

Just to clarify (I don’t have any answers, but figure it’s worth clarifying your question for other readers): you want an OCaml interface to

1. a computer algebra system
2. a linear algebra/matrix math system (for the eigensolver)
?

It’s been a real gap in OCaml for a long time.

ETA: I’ve used Maxima in the past, and wondered if it was written in LISP. As it turns out, it is. I wonder how difficult interfacing that to OCaml would be …

So far what I have identified is that I will use octave and swig bindings to generate some ocaml interface to the internals of octave. This way, I can write an AST manipulator and explorer that revolves around the octave syntax. I need to be able to map the languages across one another at both input and output. I think this will provide for what you’re looking for.

2 is satisfied by OWL actually I think. But I don’t think that octave is the only way to go, there is also FriCaS and Axiom that each look good. I just don’t know what method to use to allow access by ocaml. I don’t want to write a parser, but serialization might suffice.

Also, to be more clear, computer algebra systems is a broad category of computational algorithms for algebra, which span a lot of different use case applications. I just want an algebra manipulation system.

It might be worth considering interfacing to these systems via Python (that is OCaml->Python->{Axiom,Octave,etc}) if only because it might reduce the effort, at the price of a certain amount of inefficiency.

As you didn’t tell us about the size of your problems, I’m assuming toy/learning/example numbers of equations: I would just write an Octave (or whatever you end up using in the end) source file in OCaml (if you know it is able to rewrite your equations) that outputs the results in a file, in a format that you can directly read, for example JSON or S-expressions of the generated AST, and run that in a process. No need to do any FFI to C++ or to parse the output.
As said, I don’t know what you are doing or your performance requirements, but I’d guess that it would be way easier to write a bigger part of your program in Octave than just the equation rewriter and eigenvalue solving.

octave can output to json? I didn’t know that! Let me go check

Octave is a programming language, but the Interpreter is quite slow (Matlab is way faster).