[GiNaC-list] lsolve() fails with "system is not linear"
Vitaly Magerya
vmagerya at gmail.com
Mon Aug 6 18:20:58 CEST 2018
Here's what I get with the latest GiNaC release, as well as the
latest commit:
$ ginsh
ginsh - GiNaC Interactive Shell (GiNaC V1.7.3)
[...]
> lsolve({(1+c)^(-1)*(1+x+x*c)==0},{x});
lsolve: system is not linear
The problem is that the linearity of the system is tested in
lsolve() by subtracting 'x' times it's coefficient from the
equation, and seeing if there are any more 'x' remaining. In this
case such subtraction results in '-(1+c)^(-1)-(1+c)^(-1)*c*x-
(1+c)^(-1)*x+x', where 'x' is not explicitly canceled, thus the
error.
One workaround that solves this particular case is using 'numer()'
on each equation, like so:
diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp
index db40dba6..b83b2548 100644
--- a/ginac/inifcns.cpp
+++ b/ginac/inifcns.cpp
@@ -1094,7 +1094,7 @@ ex lsolve(const ex &eqns, const ex &symbols, unsigned options)
matrix vars(symbols.nops(),1);
for (size_t r=0; r<eqns.nops(); r++) {
- const ex eq = eqns.op(r).op(0)-eqns.op(r).op(1); // lhs-rhs==0
+ const ex eq = numer(eqns.op(r).op(0)-eqns.op(r).op(1)); // lhs-rhs==0
const exset syms = symbolset(eq);
ex linpart = eq;
for (size_t c=0; c<symbols.nops(); c++) {
... this doesn't look performant to me though, and doesn't
obviously solve the general case. Any alternative ideas?
More information about the GiNaC-list
mailing list