CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual use to large groups and classes! Also, H100 GPUs starting at $2/hour.

| Download
Views: 8
Visibility: Unlisted (only visible to those who know the link)
Image: ubuntu2204

Posets in Sage - An Introduction

Math 737 - Lab 1

First define a poset.

Make a list of the elements of your poset, then a list of the covering relations between poset element.

Evaluate the cell below by putting your cursor in the block and then pressing shift + enter

elem = [1,2,3,4,5,6] rels = [[1,2],[2,3],[4,5],[5,6],[1,4],[2,5],[3,6]] Q = Poset((elem,rels)) Q.plot()

You can also make a random poset.

Evaluate the cell below multiple times to see multiple random posets of 7 elements.

myposet = Posets(7).random_element() plot(myposet)

Exercise 1: Make some of the example posets P, Q, R, S, T, N, from our last class. We already made Q above.

Let's see what Sage can do with a poset.

Type the name of your poset, then type . and shift+enter. Scroll through the commands until you find one you recognize. Run a command; you likely need to add () at the end to make it work.

To access the documentation for a function, type the function with no () and put ? to see the documentation, and ?? to see the documentation and code

Exercise 2: Use Sage to verify your answers from yesterday's class. You may need to access the documentation to see what the function is actually doing.

The following function is code for the rank generating function of a poset P. It will not work if your poset does not have a rank function.

def rank_generating_function(P): f = P.rank_function() rk = P.rank() list_of_ranks = [f(i) for i in P] R.<x> = PolynomialRing(QQ) rgf = 0 for elem in list_of_ranks: rgf += x^elem return rgf

An order ideal is a subset of poset elements that is closed downward.

Let's make a random order ideal, using the code below. The green elements are the order ideal. The red elements are an order filter.

oi = P.random_order_ideal() list(oi) P.order_ideal_plot(oi)
Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python3.11/site-packages/smc_sagews/sage_server.py", line 1244, in execute exec( File "", line 1, in <module> NameError: name 'P' is not defined

Here is one of my favorite posets: the triangle

Evaluate the following cells to see some ways to plot posets

elemP7 = [11, 12, 13, 14, 15, 16, 17, 21, 22, 23, 24, 25, 26, 31, 32, 33, 34, 35, 41, 42, 43, 44, 51, 52, 53, 61, 62, 71] relP7 = [[11,21],[12, 21],[12, 22],[13, 22],[13, 23],[14, 23],[14, 24],[15,24],[15,25],[16,25],[16,26],[17,26],[21,31],[22,31],[22,32],[23,32],[23,33],[24,33],[24,34],[25,34],[25,35],[26,35],[31,41],[32,41],[32,42],[33,42],[33,43],[34,43],[34,44],[35,44],[41,51],[42,51],[42,52],[43,52],[43,53],[44,53],[51,61],[52,61],[52,62],[52,62],[53,62],[61,71],[62,71]] P7 = Poset((elemP7,relP7))

Evaluate the following cells to see some ways to plot posets

The normal way

plot(P7)

The pretty way

show(P7)

Latex code for putting in your paper

latex(P7)

The boingy way

H7 = P7.hasse_diagram() show(H7)

The sticky way

H7.plot(save_pos=True) show(H7)

Exercise 3: Use these various plot methods on our example posets. Which plot method is your favorite?

The reason the triangle poset is one of my favorite posets is that order ideals of the triangle poset are Dyck paths!

P7oi = P7.random_order_ideal() P7.order_ideal_plot(P7oi)
d = DyckWords(8).random_element() plot(d)

We can use Sage to construct new posets from old

Exercise 4: Using our example posets P,Q,R,S,T,N, construct new posets as examples of the disjoint sum, ordinal sum, and direct (cartesian) product. Plot the new posets you create.

︠5e6b4a4d-f744-47d4-82f1-eefff11d1975︠ ︠ff20ba09-9bff-46a9-95c8-04d852790865︠ ︠5ce45d38-e915-4a4b-b1b0-b5a6d7abcdf1︠