Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I think this is it:

def sym_reduce(f):
    Sym = SymmetricFunctions(f.base_ring())
    m = Sym.m()
    e = Sym.e()
    v = f.variables()
    s = 0
    while True:
        t = max((t for t in f if t[1] and (d:=t[1].degrees())==tuple(sorted(d,reverse=True))), key=lambda t: t[1], default=0)
        if t==0:
            return sum(c*e[d] for d,c in e.from_polynomial(s) if max(d)<=len(v)), f
        g = t[0] * m[t[1].degrees()].expand(len(v),v)
        s += g
        f -= g

For example,

R.<x,y,z> = PolynomialRing(QQ, order='lex')
sym_reduce((x-y)^2 * (x-z)^2 * (y-z)^2)

gives

(e[2, 2, 1, 1] - 4*e[2, 2, 2] - 4*e[3, 1, 1, 1] + 18*e[3, 2, 1] - 27*e[3, 3], 
 0)

PS. Note that the result depends on the monomial order.

I think this is it:

def sym_reduce(f):
    Sym = SymmetricFunctions(f.base_ring())
    m = Sym.m()
    e = Sym.e()
    v = f.variables()
    s = 0
    while True:
        try:
            t = max((t next( t for t in f if t[1] and (d:=t[1].degrees())==tuple(sorted(d,reverse=True))), key=lambda t: t[1], default=0)
        if t==0:
(d:=t[1].degrees())==tuple(sorted(d,reverse=True)) )
        except StopIteration:
            return sum(c*e[d] for d,c in e.from_polynomial(s) if max(d)<=len(v)), f
        g = t[0] * m[t[1].degrees()].expand(len(v),v)
        s += g
        f -= g

For example,

R.<x,y,z> = PolynomialRing(QQ, order='lex')
sym_reduce((x-y)^2 * (x-z)^2 * (y-z)^2)

gives

(e[2, 2, 1, 1] - 4*e[2, 2, 2] - 4*e[3, 1, 1, 1] + 18*e[3, 2, 1] - 27*e[3, 3], 
 0)

PS. Note that the result depends on the monomial order.

I think this is it:

def sym_reduce(f):
    Sym = SymmetricFunctions(f.base_ring())
    m = Sym.m()
    e = Sym.e()
    v = f.variables()
    s = 0
    while True:
        try:
            t = next( t for t in f if t[1] and (d:=t[1].degrees())==tuple(sorted(d,reverse=True)) )
        except StopIteration:
            return sum(c*e[d] for d,c in e.from_polynomial(s) if max(d)<=len(v)), len(d)=0 or d[0]<=len(v)), f
        g = t[0] * m[t[1].degrees()].expand(len(v),v)
        s += g
        f -= g

For example,

R.<x,y,z> = PolynomialRing(QQ, order='lex')
sym_reduce((x-y)^2 * (x-z)^2 * (y-z)^2)

gives

(e[2, 2, 1, 1] - 4*e[2, 2, 2] - 4*e[3, 1, 1, 1] + 18*e[3, 2, 1] - 27*e[3, 3], 
 0)

PS. Note that the result depends on the monomial order.

I think this is it:

def sym_reduce(f):
    Sym = SymmetricFunctions(f.base_ring())
    m = Sym.m()
    e = Sym.e()
    v = f.variables()
    s = 0
    while True:
        try:
            t = next( t for t in f if t[1] and (d:=t[1].degrees())==tuple(sorted(d,reverse=True)) )
        except StopIteration:
            return sum(c*e[d] for d,c in e.from_polynomial(s) if len(d)=0 len(d)==0 or d[0]<=len(v)), f
        g = t[0] * m[t[1].degrees()].expand(len(v),v)
        s += g
        f -= g

For example,

R.<x,y,z> = PolynomialRing(QQ, order='lex')
sym_reduce((x-y)^2 * (x-z)^2 * (y-z)^2)

gives

(e[2, 2, 1, 1] - 4*e[2, 2, 2] - 4*e[3, 1, 1, 1] + 18*e[3, 2, 1] - 27*e[3, 3], 
 0)

PS. Note that the result depends on the monomial order.

I think this is it:

def sym_reduce(f):
    Sym = SymmetricFunctions(f.base_ring())
    m = Sym.m()
    e = Sym.e()
    v = f.variables()
    s = 0
    while True:
        try:
            t = next( t for t in f if t[1] and (d:=t[1].degrees())==tuple(sorted(d,reverse=True)) )
        except StopIteration:
            return sum(c*e[d] for d,c in e.from_polynomial(s) if len(d)==0 or d[0]<=len(v)), f
        g = t[0] * m[t[1].degrees()].expand(len(v),v)
        s += g
        f -= g

For example,

R.<x,y,z> = PolynomialRing(QQ, order='lex')
PolynomialRing(QQ)
sym_reduce((x-y)^2 * (x-z)^2 * (y-z)^2)

gives

(e[2, 2, 1, 1] - 4*e[2, 2, 2] - 4*e[3, 1, 1, 1] + 18*e[3, 2, 1] - 27*e[3, 3], 
 0)

PS. Note that the result depends on the monomial variables order.

I think this is it:

def sym_reduce(f):
    Sym = SymmetricFunctions(f.base_ring())
    m = Sym.m()
    e = Sym.e()
    v = f.variables()
    s = 0
    while True:
        try:
            t = next( t for t in f if t[1] and (d:=t[1].degrees())==tuple(sorted(d,reverse=True)) )
        except StopIteration:
            return sum(c*e[d] for d,c in e.from_polynomial(s) if len(d)==0 or d[0]<=len(v)), f
        g = t[0] * m[t[1].degrees()].expand(len(v),v)
        s += g
        f -= g

For example,

R.<x,y,z> = PolynomialRing(QQ)
sym_reduce((x-y)^2 * (x-z)^2 * (y-z)^2)

gives

(e[2, 2, 1, 1] - 4*e[2, 2, 2] - 4*e[3, 1, 1, 1] + 18*e[3, 2, 1] - 27*e[3, 3], 
 0)

PS. Note that the result depends on the variables order.

order when given polynomial f is not symmetric.

First off, if a given polynomial f is symmetric, then the following conversion

SymmetricFunctions(f.base_ring()).e().from_polynomial(f)

will do the job.

For a non-symmetric polynomial, I think this the following function is it:equivalent to the one in Mathematica:

def sym_reduce(f):
    Sym = SymmetricFunctions(f.base_ring())
    m = Sym.m()
    e = Sym.e()
    v = f.variables()
    s = 0
    while True:
        try:
            t = next( t for t in f if t[1] and (d:=t[1].degrees())==tuple(sorted(d,reverse=True)) )
        except StopIteration:
            return sum(c*e[d] for d,c in e.from_polynomial(s) if len(d)==0 or d[0]<=len(v)), f
        g = t[0] * m[t[1].degrees()].expand(len(v),v)
        s += g
        f -= g

For example,

R.<x,y,z> = PolynomialRing(QQ)
sym_reduce((x-y)^2 * (x-z)^2 * (y-z)^2)

gives

(e[2, 2, 1, 1] - 4*e[2, 2, 2] - 4*e[3, 1, 1, 1] + 18*e[3, 2, 1] - 27*e[3, 3], 
 0)

PS. Note that the result depends on the variables order when given polynomial f is not symmetric.

First off, if a given polynomial f is symmetric, then the following conversion

SymmetricFunctions(f.base_ring()).e().from_polynomial(f)

will do the job.

For a non-symmetric polynomial, I think the following function is equivalent to the one in Mathematica:

def sym_reduce(f):
    Sym = SymmetricFunctions(f.base_ring())
    m = Sym.m()
    e = Sym.e()
    v = f.variables()
    s = 0
    while True:
        try:
            t = next( t sum( t[0] * m[t[1].degrees()].expand(len(v),v) for t in f if t[1] and (d:=t[1].degrees())==tuple(sorted(d,reverse=True)) )
        except StopIteration:
            return sum(c*e[d] for d,c in e.from_polynomial(s) if len(d)==0 or d[0]<=len(v)), f
        g = t[0] * m[t[1].degrees()].expand(len(v),v)
        s += g
        f -= g
f-s

For example,

R.<x,y,z> = PolynomialRing(QQ)
sym_reduce((x-y)^2 * (x-z)^2 * (y-z)^2)

gives

(e[2, 2, 1, 1] - 4*e[2, 2, 2] - 4*e[3, 1, 1, 1] + 18*e[3, 2, 1] - 27*e[3, 3], 
 0)

PS. Note that the result depends on the variables order when given polynomial f is not symmetric.

First off, if a given polynomial f is symmetric, then the following conversion

SymmetricFunctions(f.base_ring()).e().from_polynomial(f)

will do the job.

For a non-symmetric polynomial, I think the following function is equivalent to the one in Mathematica:

def sym_reduce(f):
    Sym = SymmetricFunctions(f.base_ring())
    m = Sym.m()
    e = Sym.e()
    v = f.variables()
    s = sum( t[0] * m[t[1].degrees()].expand(len(v),v) m[d].expand(len(v),v) for t in f if (d:=t[1].degrees())==tuple(sorted(d,reverse=True)) )
    return sum(c*e[d] for d,c in e.from_polynomial(s) if len(d)==0 or d[0]<=len(v)), f-s

For example,

R.<x,y,z> = PolynomialRing(QQ)
sym_reduce((x-y)^2 * (x-z)^2 * (y-z)^2)

gives

(e[2, 2, 1, 1] - 4*e[2, 2, 2] - 4*e[3, 1, 1, 1] + 18*e[3, 2, 1] - 27*e[3, 3], 
 0)

PS. Note that the result depends on the variables order when given polynomial f is not symmetric.