Ask Your Question
1

Implement Weight Orders

asked 2024-02-05 19:04:12 +0100

Matthias Steiner gravatar image

I am having trouble implementing weight orders in SageMath. Suppose we are given the polynomial ring $K[x, y, z]$, and weight vectors $w_1 = (1, 2, 3), w_2 = (4, 5, 6)$. For exponent vectors $a, b$, I would like to implement a term order that decides $a > b$ according to:

  • $w_1 a > w_1 b$
  • $w_1 a = w_1 b$ and $w_2 a > w_2 b$
  • $w_1 a = w_1 b$ and $w_2 a = w_2 b$ and $a >_{LEX} b$, i.e. in case of two ties $>$ defaults to the standard lexicographic term order.

How can I implement such a term order in SageMath?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2024-02-05 21:12:45 +0100

rburing gravatar image

updated 2024-02-05 21:32:49 +0100

SageMath supports term orders defined by integer matrices (hence all possible term orders).

We want a matrix $W$ such that $a > b$ according to your ordering iff $Wa >_{\text{lex}} Wb$.

The square matrix is specified by the tuple of its integer entries, row-wise:

w1 = (1,2,3)
w2 = (4,5,6)
R.<x,y,z> = PolynomialRing(QQ, order=TermOrder(w1 + w2 + (1, 1, 1)))

Double-check that it's the correct ordering:

def my_order(a,b):
    d1a = tuple(vector(w1).pairwise_product(vector(a)))
    d1b = tuple(vector(w1).pairwise_product(vector(b)))
    if d1a != d1b:
        return d1a > d1b
    d2a = tuple(vector(w2).pairwise_product(vector(a)))
    d2b = tuple(vector(w2).pairwise_product(vector(b)))
    if d2a != d2b:
        return d2a > d2b
    return a > b

from functools import cmp_to_key
my_key = cmp_to_key(lambda a,b: my_order(a.exponents()[0], b.exponents()[0]))

for d in range(1,50):
    print(d)
    M = sum((R.monomials_of_degree(k) for k in range(d)), [])
    M_order1 = sorted(M)
    M_order2 = sorted(M, key=my_key)
    print(M_order1 == M_order2)

Output:

1
True
2
True
3
True
4
True
5
True
6
True
7
True
8
True
9
True
10
...
49
True

So it works.

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: 2024-02-05 19:04:12 +0100

Seen: 123 times

Last updated: Feb 05