Ask Your Question
1

Solving symbolic polynomials in terms of alternate variables (+ bug?)

asked 2016-05-25 23:08:22 +0100

EvanBalster gravatar image

I've been struggling for a few days to convert get sage making inferences like the following, where I convert a (multivariate polynomial) function in terms of one set of variables (roots) into a function in terms of another (coefficients). For my use cases the conversions are always "clean", producing simpler formulas than the original:

F == p^2+pq+q^2
a == -p-q
b == pq
>> F == a^2+b  (which expands to p^2-2pq+q^2 + pq)

I'm hoping for a general solution which will work with considerably more complicated root formulas. The required math is simple algebra, so I shouldn't need anything so extravagant as solving for p and q in terms of a and b (which becomes prohibitively complex).

After some other failed experiments, I'm currently trying to use the solve() function to navigate the problem. This hasn't gone so well. My approach is to reformulate the problem in terms of an equation multiplying unknown variables by combinations of A and B which I know might show up in the particular permutation of the equation.

var("k j a x", domain='real')

#Solver can't handle these pseudo-overdetermined systems, and returns nothing
show(solve([a==-x, k*a^2==x^2], k))  # Expected k == 1
show(solve([a==-x, k*a  ==x  ], k))  # Expected k == -1
show(solve([a== x, k    ==x  ], k))  # Expected k == x

#If we substitute the known value of a, it works...
show(solve([k*(-x)^2==x^2], k))      # Yields k == 1

#...But not if solving for multiple variables --- is this a bug?
#show(solve([k*(-x)^2+j*(-x)==x^2-x], [k, j]))
#>> AttributeError: 'list' object has no attribute 'lhs'

#We can work around the bug by solving one variable at a time
show(solve([k*(-x)^2+j*(-x)==x^2-x], j))    #Yields j=(k-1)x+1 ... scalar part 1 is correct
show(solve([k*(-x)^2+j*(-x)==x^2-x], k))    #Yields (j+x-1)/x  ... scalar part 1 is correct

With my "cheat" I may be able to repeatedly solve the formula and get this just barely working... But this requires some difficult equation mangling and promises to be super inefficient. All of this has me thinking that I'm using the wrong approach to solve this relatively simple algebraic problem. Help?

edit retag flag offensive close merge delete

Comments

I am not an expert on this part of Sage, but just as a comment, note that you don't have the bug if you don't define your variables as real:

sage: var("k j a x")
(k, j, a, x)
sage: solve([k*(-x)^2+j*(-x)==x^2-x], [k, j])
[[k == (r2 + x - 1)/x, j == r2]]

I have the same result as yours for your first three examples.

B r u n o gravatar imageB r u n o ( 2016-05-26 14:13:25 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-05-26 21:12:03 +0100

For overdetermined systems, you can get solutions by explicitly specifying all variables:

var('k a x')
show(solve([a==-x, k*a^2==x^2], [k, a, x]))

The result is

[[k == 1, a == r1, x == -r1], [k == r2, a == 0, x == 0]]

where r1 and r2 are arbitrary parameters.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-05-25 22:39:15 +0100

Seen: 567 times

Last updated: May 26 '16