Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
1

Implement Weight Orders

asked 1 year ago

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 w1=(1,2,3),w2=(4,5,6). For exponent vectors a,b, I would like to implement a term order that decides a>b according to:

  • w1a>w1b
  • w1a=w1b and w2a>w2b
  • w1a=w1b and w2a=w2b and a>LEXb, i.e. in case of two ties > defaults to the standard lexicographic term order.

How can I implement such a term order in SageMath?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 1 year ago

rburing gravatar image

updated 1 year ago

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>lexWb.

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.

Preview: (hide)
link

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: 1 year ago

Seen: 150 times

Last updated: Feb 05 '24