Using SymbolicC++ to solve systems of equations symbolically

4

I am looking for a way to programmatically solve systems of (not necessarily linear) equations, symbolically. My main focus has been on SymbolicC++, but I was unable to find much documentation, and I am unable to get it working.

The code below yields a == 1/2*(-4*b^(2)+4*c^(2))^(1/2), which is clearly not simplified properly (I even explicitly call simplify.) :

#include <symbolicc++.h>
#include <iostream>

int main()
{
    Symbolic a("a");
    Symbolic b("b");
    Symbolic c("c");

    auto eq1 = (a^2) + (b^2) == (c^2);
    auto solutions = solve(eq1, a);

    for (auto i = solutions.begin(); i != solutions.end(); i++)
        std::cout << (*i).simplify() << std::endl;
}

The code below is supposed to yield among many solutions a==2, b==2, c==2, d==2 and a == 5-2*sqrt(6), b == 5+2*sqrt(6), c == 5-2*sqrt(6), d == 5+2*sqrt(6) but instead encounters the following exception after executing for about 10 seconds:

Unhandled exception at 0x73203D5C (vcruntime140.dll) in test.exe: 0xC0000005: Access violation reading location 0x00000018.

#include <symbolicc++.h>
#include <iostream>

int main()
{
    Symbolic a("a");
    Symbolic b("b");
    Symbolic c("c");
    Symbolic d("d");

    auto eq1 = a + b*c*d == 10;
    auto eq2 = b + a*c*d == 10;
    auto eq3 = c + a*b*d == 10;
    auto eq4 = d + a*b*c == 10;
    auto eq = (eq1, eq2, eq3, eq4);
    auto solutions = solve(eq, (a, b, c, d));

    for (auto i = solutions.begin(); i != solutions.end(); i++)
        std::cout << *i << std::endl;
}

(I used Visual Studio to compile the library.)

My test equations seem to be solvable, since WolframAlpha solves them with ease. (I just used solve a^2+b^2 = c^2 for a and solve a+bcd=10, b+acd=10, c+abd=10, d+abc=10.)

Am I doing something wrong? What do I need to get these examples to work correctly?

Notes about other libraries:
If possible, I would like to compile the library to ARM systems (Windows Phone). As far as I can tell, only C++ and .NET libraries come into play. Since currently I use MSVC to compile SymbolicC++ anyway, I think cross-compiling it to WP won't be a problem.

Notes about sympy:
The code below throws ZeroDivisionError with the message polynomial division. Since it does not really fit my portability needs anyway, I just gave up on it.

import sympy.solvers
from sympy import Equality
from sympy.abc import a, b, c, d
equations = [ Equality(a + b*c*d, 10), Equality(b + a*c*d, 10), Equality(c + a*b*d, 10), Equality(d + a*b*c, 10) ]
print sympy.solvers.solve(equations, [a, b, c, d])
c++
symbolic-math
asked on Stack Overflow May 14, 2016 by kuruczgyurci • edited May 18, 2016 by Captain Obvlious

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0