Ask Your Question
1

Obtaining a poset from a list of vectors in Sage

asked 2025-02-03 18:05:03 +0100

sagequstions gravatar image

I have a list of vectors (coming from GAP) as follows:

U=[ [ 1, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 1 ], [ 1, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0 ], [ 0, 0, 0, 1, 0 ], [ 0, 1, 0, 0, 1 ], [ 1, 0, 1, 0, 0 ], 
  [ 0, 0, 0, 0, 1 ], [ 1, 0, 1, 1, 0 ], [ 0, 1, 0, 0, 0 ], [ 0, 0, 1, 1, 1 ], [ 1, 1, 1, 1, 1 ] ]

I want to define a poset using this list of vector via sage by saying that for two vectors v and w in this list U, we have v<=w if w-v in in the list U. Is there an easy way to obtain this poset directly in Sage?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2025-02-03 18:55:20 +0100

FrédéricC gravatar image

updated 2025-02-03 18:56:01 +0100

Like this

sage: V = [vector(v,immutable=True) for v in U]
sage: Poset([V,lambda v,w:bool(w-v in V)])
Finite poset containing 12 elements
edit flag offensive delete link more

Comments

Mwarf, parallel answer with the exact same notations !

tmonteil gravatar imagetmonteil ( 2025-02-03 19:01:08 +0100 )edit

Note that w-v in V is a bool already.

tmonteil gravatar imagetmonteil ( 2025-02-03 21:18:46 +0100 )edit
3

answered 2025-02-03 19:00:14 +0100

tmonteil gravatar image

updated 2025-02-03 19:22:59 +0100

First, note that your list U is not a list of vectors but a list of lists. So, the first thing to do is to transform it into a list of vectors (forget about the immutable=True for now):

sage: V = [vector(u, immutable=True) for u in U]
sage: V
[(1, 0, 0, 0, 0),
 (0, 0, 0, 1, 1),
 (1, 1, 0, 0, 0),
 (0, 0, 1, 0, 0),
 (0, 0, 0, 1, 0),
 (0, 1, 0, 0, 1),
 (1, 0, 1, 0, 0),
 (0, 0, 0, 0, 1),
 (1, 0, 1, 1, 0),
 (0, 1, 0, 0, 0),
 (0, 0, 1, 1, 1),
 (1, 1, 1, 1, 1)]

Now, if you look at the Poset constructor documentation:

sage: Poset?

you will see that the second way to build a poset is to provide a pair (E,f) where E are the elements of the poset and f(x,y) is a function that returns True when x<=y in the poset. This corresponds to your description.

So we can do:

sage: P = Poset((V, lambda v,w: w-v in V))

where lambda v,w: w-v in V is a Python way to describe "the map that, given v and w, returns whether w-v belongs to V".

You can check that you have the expected poset by drawing it:

sage: P.show()

Remark: everything seems to be very natural (we just translated your question into Sage/Python), except perhaps the immutable=True. This is due to the fact that, if the elements of V are mutable, you will get the following error:

sage: V = [vector(u) for u in U]
sage: P = Poset((V, lambda v,w: w-v in V))
TypeError: mutable vectors are unhashable
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: 2025-02-03 18:05:03 +0100

Seen: 47 times

Last updated: Feb 03