Ask Your Question
1

How to use faces of a polytope as variables?

asked 2021-05-08 21:44:28 +0200

Polydarya gravatar image

Hello, I am very new to using computer algebras system, and I can't figure out the following: I need to create a 3D polytope (in fact, an associahedron) and then do some computations in the algebra of rational functions in variables that correspond to faces of associahedron. How do I do that? I know writing something like Frac(ZZ['x,y,z']) creates the algebra that I need, but how do I make formal symbols x,y,z remember that they once were faces of a polytope (so that I could check if one was a subface of another, or something like that...)?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-05-09 11:29:12 +0200

tmonteil gravatar image

Here is how i would do from scratch, without looking whether there is already some tools to do that.

First, define the associahedron :

sage: A = polytopes.associahedron(['A',3])
sage: A
Generalized associahedron of type ['A', 3] with 14 vertices

Then, the list of faces :

sage: F = list(A.face_generator())
sage: F
[A 3-dimensional face of a Polyhedron in QQ^3 defined as the convex hull of 14 vertices,
 A -1-dimensional face of a Polyhedron in QQ^3,
 A 2-dimensional face of a Polyhedron in QQ^3 defined as the convex hull of 5 vertices,
 A 2-dimensional face of a Polyhedron in QQ^3 defined as the convex hull of 4 vertices,
...

Then, you can define your fraction field:

sage: R = Frac(PolynomialRing(QQ,x,len(F)+1))
sage: R
Fraction Field of Multivariate Polynomial Ring in x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, x29, x30, x31, x32, x33, x34, x35, x36, x37, x38, x39, x40, x41, x42, x43, x44, x45, x46 over Rational Field
sage: R.inject_varibles()
sage: R.inject_variables()
Defining x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, x29, x30, x31, x32, x33, x34, x35, x36, x37, x38, x39, x40, x41, x42, x43, x44, x45, x46

At this point, you can do:

sage: P = 3*x6*x7 + x2 ; P
3*x6*x7 + x2

Now, we can define a bridge between both worlds in both ways:

sage: face = {x:f for x,f in list(zip(R.gens(),F))}  
sage: x = {f:x for x,f in list(zip(R.gens(),F))}
sage: face[x3]                                                                                                                                                                                               
A 2-dimensional face of a Polyhedron in QQ^3 defined as the convex hull of 4 vertices
sage: x[face[x3]]                                                                                                                                                                                            
x3

Now, you can play:

For example, you can define the polynomial that corresponds to facets (faces of codimension 1):

sage: sum([x[id[f]] for f in A.facets()]) ;
x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10

If you have a fraction, you can get the set the vertices involved in it

sage: p = (x11 + x12) / (x9 + x10)
sage: set(flatten([face[a].vertices() for a in p.numerator().variables() + p.denominator().variables()]))
{A vertex at (-3/2, 0, -1/2),
 A vertex at (-3/2, 1, -3/2),
 A vertex at (-3/2, 2, -3/2),
 A vertex at (-3/2, 2, 3/2),
 A vertex at (3/2, -2, 1/2),
 A vertex at (3/2, -2, 3/2),
 A vertex at (3/2, 0, -3/2),
 A vertex at (3/2, 2, -3/2),
 A vertex at (3/2, 2, 3/2)}
edit flag offensive delete link more

Comments

Thank you so so much! You are my saviour. One little detail I can't understand: what is this "-1-dimensional" face x1?

Polydarya gravatar imagePolydarya ( 2021-05-09 19:27:54 +0200 )edit

It seems to be the empty set:

sage: f = F[1]
sage: f
A -1-dimensional face of a Polyhedron in QQ^3
sage: f.dim()
-1
sage: f.vertices()
()
tmonteil gravatar imagetmonteil ( 2021-05-09 21:13:14 +0200 )edit

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: 2021-05-08 21:44:28 +0200

Seen: 50 times

Last updated: May 09