张麟 2010年11月03日 星期三 09:19 | 2147次浏览 | 1条评论
it is from http://stochastix.wordpress.com/2008/07/05/playing-with-sympy/#comment-70270
An example
Let’s consider the system of
polynomial equations
in
,
where
is a known vector (whose entries are distinct). We will denote
. Let function
be defined as
.
The system of polynomial equations can thus be rewritten as
where
for all
. According to
my conjecture
, this system of
equations
should have exactly
solutions. Solving the system is not very easy because the equations
are nonlinear in variables
. A
CAS
would be useful.
For example, we could implement function
with the following
Python
script:
def g(z,k):
We could then compute the
Gröbner basis
of the set of polynomials
, and the solutions of the system of polynomial equations for a given
, say,
:
The output is:
.
.
As expected, the solutions of the system of polynomial equations are the
permutations of the elements of
. Of course, this does not prove the
conjecture
. All it proves is that my conjecture works for the particular case where
and
.
"""Computes g_k(z), where z is a list of reals and k is a positive integer"""
# checks function arguments for errors
if len(z)==0:
return "ERROR: First argument must be a non-empty list of symbols!"
if (type(k) != int) or (k < 1):
return "ERROR: Second argument must be a positive integer!"
# computes g_k(z) and returns it
acc = 0
for i in range(0,len(z)):
acc += (z[i])**k
return acc
from sympy import *
# number of equations and symbolic variables
n = 3
# defines set S = {1, 2,..., n}
S = range(1,n+1)
# declares symbolic variables
x = [Symbol('x%d' % i) for i in S]
# initializes y vector
#y = [Symbol('y%d' % i) for i in S]
y = S
# defines system of polynomial equations in variables [x1, x2, x3]
P = [g(x,k) - g(y,k) for k in S]
# computes Groebner basis and solutions of the system of polynomials
GB = groebner(P,x, order='lex')
Sols = solve_system(P,x)
# prints results
print "Groebner basis: %s" % GB
print "Solutions: %s" % Sols
print "There are %d solutions." % len(Sols)
Zeuux © 2024
京ICP备05028076号
回复 张麟 2010年11月03日 星期三 10:38