Ask Your Question

jipilab's profile - activity

2020-08-23 19:47:44 -0600 received badge  Nice Answer (source)
2020-08-23 14:57:21 -0600 answered a question Obtaining quotient posets of the Boolean lattice via Sage

Here is a snippet of code that can be used to produce the desired quotient poset. It is not meant to be the most optimal way, but it does return the desired object.

sage: G = PermutationGroup([[(1,2)],[(3,4)]])
sage: S = Set([1,2,3,4])
sage: GroundSet = S.subsets()
sage: Orbits = Set([Set(G.orbit(s, action = "OnSets")) for s in GroundSet])
sage: def quotient_order(a,b):
....:     for s1 in a:
....:         ss1 = set(s1)
....:         for s2 in b:
....:             ss2 = set(s2)
....:             if ss1.issubset(ss2):
....:                 return True
....:     return False
....: 
sage: QuotientPoset = Poset((Orbits,quotient_order))
sage: QuotientPoset.show()

To obtain all of the quotient posets, one should then loop over all permutation subgroups of $S_n$. These subgroups can be obtained this way:

sage: SG = SymmetricGroup(4)
sage: SG.subgroups()
2020-07-28 05:14:55 -0600 answered a question rotating polytope in 4d?

The current default viewer in Sage is now threejs.

To visualize a 4-dimensional polytope, you can do:

sage: hc = polytopes.hypercube(4)
sage: hc.plot()
Launched html viewer for Graphics3d Object

This will open a html page in the default internet browser (this might be a problem, as sometimes if the browser was updated it might not open a new tab). In there, there will be a threejs applet which you can play with with mouse-clicks.

You are probably refering to the pop up menu from the jmol viewer, which is still accessible (though likely is less maintained now as it is not the default viewer anymore):

sage: hc.plot(viewer='jmol')
Launched jmol viewer for Graphics3d Object

There, you may right-click and select "console" where you can then type commands to rotate and change the view.

As far as I know, there was no possibility to change the projection view (from 4d to 3d) once the picture of the Schlegel diagram has been produced.

It is possible to change the projection view, for this, you may proceed to play around as follows:

sage: new_pic = hc.schlegel_projection([1,1,1,2],1.5)
sage: new_pic.plot()
Launched html viewer for Graphics3d Object
2020-07-24 02:41:57 -0600 commented answer Shelling order of a simplicial polytope

Sure! If you want to keep track of the development related to polyhedral geometry in Sage visit the Polyhedral Geometry Trac Wiki. The .boundary_complex method is in Sage since version 9.0.

2020-07-24 02:30:16 -0600 answered a question Shelling order of a simplicial polytope

Dear Guillermo,

The answer to your question is yes. Here is an illustration with the octahedron:

sage: P = polytopes.octahedron()
sage: Facets = {f.ambient_V_indices():f for f in P.faces(P.dimension() - 1)}  # Create the vertices-indices-to-facets dictionary
sage: P.is_simplicial()  # Check that P is simplicial, so we can get the boundary complex
True
sage: C = P.boundary_complex()  # Create the boundary complex
sage: Order = C.is_shellable(True); Order  # Get a shelling order
((0, 1, 2),
 (1, 2, 5),
 (1, 3, 5),
 (0, 2, 4),
 (0, 1, 3),
 (0, 3, 4),
 (2, 4, 5),
 (3, 4, 5))

Finally, we can get the actual sequence of facet using our dictionary.

sage: Facet_shelling = [Facets[indices.tuple()] for indices in Order]; Facet_shelling
[A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices,
 A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices,
 A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices,
 A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices,
 A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices,
 A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices,
 A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices,
 A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices]
2020-07-15 23:11:05 -0600 received badge  Nice Answer (source)
2020-04-26 14:48:43 -0600 marked best answer How to literally print the output of tab completion in the command line?

Some time ago, I realized that pressing tab after a "." in the command line opens a new window where it is possible to scroll through the possible methods to call on this object.

Is it still possible to print inside the terminal all the possibilities?

Even if I modify the preferences of the command line from "readline" to "multicolumns", it still does not show much of the possibilities and sometimes seeing all of them at once is faster than scrolling.

Is it possible to get this feature back as before somehow?

2020-04-26 14:48:43 -0600 received badge  Scholar (source)
2020-04-24 02:39:58 -0600 commented answer Projection along affine hull

Perhaps you could complete this answer with the code to obtain P?

2020-04-23 02:57:24 -0600 commented question Memory leak in Polyhedron?

This memory leak in Polyhedron is fixed in this ticket.

2020-04-23 02:48:39 -0600 commented answer Compute the centroid of a polytope

... which will be accessible with the command

sage: q = polytopes.permutahedron(4)
sage: q.centroid()
2020-04-23 02:43:49 -0600 commented answer plotting 5,8,16,24,120 and 600-cells

The 120-cell is now available in the library. The 'normaliz' backend is currently the fastest way to get it.

sage: otc = polytopes.one_hundred_twenty_cell() # slow...
sage: otc = polytopes.one_hundred_twenty_cell(backend='normaliz')
sage: otc.plot()
2020-04-09 02:02:16 -0600 received badge  Good Answer (source)
2020-04-08 12:20:21 -0600 received badge  Nice Answer (source)
2020-04-08 10:08:58 -0600 answered a question PolyhedronFace

In sage 9.0, I can execute:

sage: square = polytopes.hypercube(2)
sage: fl = square.face_lattice();
sage: list(f.ambient_V_indices() for f in fl)
[(), (0,), (1,), (2,), (3,), (0, 1), (0, 2), (2, 3), (1, 3), (0, 1, 2, 3)]

Which version of sage are you using? That might be a problem as the function ambient_V_indices is available since version 8.8.

2020-03-01 04:43:48 -0600 commented answer Find sphere points in a lattice

I see. If it is in Sage I would suspect that it is closer to the number theory and quadratic forms code, but I am not aware of it...

2020-02-13 03:30:16 -0600 answered a question looping of equality function

Defining x,y,z to be variables and then using them as integers is not really appropriate. The indentation was also missing, along with an if.

You do not need to declare the variables if you use them in a range:

sage: for x in range(-100,101):
....:     for y in range(-100,101):
....:         for z in range(-100,101):
....:             if x^4+y^4 == z^3:
....:                 print(x,y,z)

You can also use more advanced iterators and shorten the code:

sage: import itertools
sage: for x,y,z in itertools.product(srange(-100,101),repeat=3):
....:     if x^4 + y^4 == z^3:
....:         print(x,y,z)
2020-02-11 01:35:23 -0600 received badge  Good Answer (source)
2020-02-10 15:30:56 -0600 received badge  Nice Answer (source)
2020-02-10 12:00:08 -0600 answered a question Find sphere points in a lattice

Here is a snippet of code that should do:

sage: Q = RootSystem('E8').weight_lattice()
sage: B = Q.basis()
sage: the_set = set()
sage: finished = False
sage: i = 1
sage: value = 4
sage: while not finished:
....:     smaller_or_eq_values = False
....:     int_vectors = IntegerVectors(n=i,k=8)
....:     for vect in int_vectors:
....:         weight = sum(vect[j]*B[j+1] for j in range(8)) # Create the weight
....:         wns = weight.norm_squared()
....:         if wns <= value:
....:             smaller_or_eq_values = True
....:             if wns == value:
....:                 print(weight)
....:                 the_set.add(weight)
....:     if not smaller_or_eq_values:
....:         finished = True
....:     i += 1

You will get a set the_set which above contains all the (positive) weights that have the norm squared to be equal to value=4.

The norm squared seem to deliver the same as the symmetric form:

sage: B[1]+B[2]
Lambda[1] + Lambda[2]
sage: a_weight = B[1]+B[2]
sage: a_weight.symmetric_form(a_weight)
22
sage: a_weight.norm_squared()
22
2020-02-10 06:47:43 -0600 answered a question VoronoiDiagram returns empty regions

This looks like a bug. I have reported it on trac: ticket 29176

Thanks for reporting this!

2020-02-10 06:41:12 -0600 answered a question Typo in Sage documentation (no. 2)

This is now a ticket: ticket 29175

2020-02-07 12:08:19 -0600 commented answer Intersection of a Cube with two planes and resulting polyhedron

In a more recent version you can do:

sage: cube = polytopes.cube()
sage: plane1 = Polyhedron(eqns=[(0,1,0,0)])
sage: plane2 = Polyhedron(eqns=[(1,0,0,-1)])
sage: intersec = cube & plane1 & plane2
2020-02-07 11:59:29 -0600 commented question hyperplane arrangements raises error on regions

I would also try to use rational numbers instead of floats, this might facilitate the computations. You probably do not need floats, as the size of the input is reasonable.

say 83/100 instead of 0.83 ...

2020-02-07 11:52:55 -0600 commented question Find sphere points in a lattice

Could you explain what is meant by "canonical bilinear form", the one coming from the geometric representation?

This will affect how to give you a better answer.

2020-02-07 11:44:42 -0600 commented question Sage notebook only runs when a browser is already open

With the notebook, it is also useful to restart the browser once in a while if an update was made (I rarely restart my browser and I was getting similar problems with start-up, restarting the browser did the thing...)

Maybe try with have a freshly updated firefox, that does not run, and moving the .sage folder to another location and then so what happens?

2020-01-09 15:33:56 -0600 received badge  Nice Answer (source)
2020-01-08 10:41:03 -0600 answered a question Lattices via sage

Here is a first attempt to answer your questions.

1) The comment should be addressed in order to give an instructive answer.

2) Assuming you want to consider only _linear_ subspace, the following code does the thing:

sage: dim = 2
sage: FF = FiniteField(3)
sage: VS = VectorSpace(FF,2)
sage: SS = {}
sage: SS[0] = set([VS.subspace([])])
sage: for dim in range(1,dim+1):
....:     new_subspaces = set()
....:     for v in VS:
....:         for ss in SS[dim-1]:
....:             new_ss = ss + VS.subspace([v])
....:             if new_ss.dimension() == dim:
....:                 new_subspaces.add(new_ss)
....:     SS[dim] = new_subspaces
....:     
sage: ground_set = reduce(lambda x,y:x.union(y),SS.values())
sage: the_lattice = LatticePoset((ground_set,lambda x,y: x.is_subspace(y)))

3) See https://ask.sagemath.org/question/389... and https://ask.sagemath.org/question/389...

2020-01-08 06:53:33 -0600 commented question Lattices via sage

Could you clarify which lattice you mean? A lattice can be a subgroup of the additive group R^n which is isomorphic to Z^n or a poset with a join and meet operations.

2019-10-26 04:49:16 -0600 commented question LattE problem: Executable 'count' not found on PATH.

I also get 39 for the command q1.integral_points_count() on sage 8.9.

As mentioned in the documentation obtained by typing q1.integral_points_count?, there is a threshold for when sage will use latte for the computations. The import statement from sage.interfaces.latte import * does not affect anything here. As tmonteil said, it requires that either you have latte integrale installed on your system of you install it via sage -i latte_int.

I suspect that you are interested in the Ehrhart polynomial. It is important to know that counting the lattice points in a lattice polytope and obtaining the Ehrhart polynomial are two completely different tasks, although they are obviously related.

2019-10-25 17:19:36 -0600 commented answer How to find the vertices a a polyhedron define by inequalities ,

It is also possible to get the full V-representation using the Vrepresentation method.

2019-10-25 17:17:43 -0600 answered a question Computing projection of a polyhedron

One possibility is the following.

First create the desired transformation as a matrix.

sage: nf = QuadraticField(2)
sage: sqrt2 = nf.gen()
sage: proj_mat = matrix(nf,[[sqrt2/2,sqrt2/2],[sqrt2/2,sqrt2/2]])

Then, create your polyhedron

sage: P = Polyhedron(vertices=[(-1,-1), (1,3), (5,-2)])

One then just need to apply the transformation on each vertices of the polyhedron and take the result back to a polyhedron.

sage: Pproj = Polyhedron(vertices = (proj_mat*P.vertices_matrix()).columns())
sage: Pproj
A 1-dimensional polyhedron in (Number Field in a with defining polynomial x^2 - 2)^2 defined as the convex hull of 2 vertices
sage: Pproj.vertices_list()
[[-a, -a], [2*a, 2*a]]

Currently, projections (or other linear transformations) are not implemented better than as above...

2019-10-25 13:12:07 -0600 answered a question About algorithm for testing whether a point is in a V-polyhedron

You can access the algorithm for containment by doing the following:

sage: p = polytopes.cube()
sage: p.contains??

This will show you the source code for this function. The containment check is independent of the backend. Currently, when you create a polyhedron object in Sage, it computes the other representation (H- to V-, or V- to H-) automatically (this may change in the future, but for now, it is so). Then, checking containment is obtained directly from the H-representation by matrix multiplication and checking the equality or inequality of Ax<=B. This is then done in the arithmetic of the appropriate ring (ZZ, QQ, RDF, NumberField, etc).

There is absolutely no difference between bounded vs unbounded polyhedron.

To know if the function depends on the backend, you can look next to the 1-to-last line in the output of p.contains?? it will mention the file in which this function is. If this file contains ppl, normaliz, polymake, cdd, field, then this function is implemented specifically for that backend. Otherwise, if it is in say base.py, it is a generic function that is used in general...

2019-09-14 00:56:10 -0600 commented answer jmol stuck at "Initializing 3D display"

Thanks! That explains why it was stuck indeed. I did create a dummy worksheet to execute my snippet of code and jsmol does work inside jupyter notebooks.

2019-09-12 03:49:13 -0600 asked a question jmol stuck at "Initializing 3D display"

I have a freshly compiled version of sage 8.9.rc0. jmol used to work fine until I got it stuck at "Initializing 3D display"

sage: h = polytopes.regular_polygon(6)
sage: w = h.wedge(h.facets()[0])
sage: w.plot()
Launched jmol viewer for Graphics3d Object

The pop out window opens and then is stuck for eternity. This is annoying. I know that I could use a different viewer like threejs but it does not open a window in my browser (which is another unrelated issue). So I would really like jmol to just work as I expect it to...

(I also upgraded my debian from stretch to buster, but I do not think it is the problem since jmol starts fine outside of sage)

How to fix this?

2019-08-29 03:29:23 -0600 received badge  Good Answer (source)
2019-08-29 03:28:22 -0600 received badge  Nice Answer (source)
2019-08-28 05:48:19 -0600 received badge  Nice Answer (source)
2019-08-28 05:47:55 -0600 received badge  Necromancer (source)
2019-08-27 15:45:10 -0600 received badge  Nice Answer (source)
2019-08-27 15:31:06 -0600 received badge  Necromancer (source)
2019-08-27 15:29:02 -0600 received badge  Necromancer (source)
2019-08-27 15:24:47 -0600 answered a question Computing the volume of a polytope that is not full-dimensional

There is a simple way to do so directly in Sage:

sage: p = polytopes.permutahedron(4); p
A 3-dimensional polyhedron in ZZ^4 defined as the convex hull of 24 vertices

Naturally, it is lower dimensional, so its volume is zero:

sage: p.volume()
0

But, changing the measure to 'induced', we can directly compute the Lebesgue measure inside of the affine hull, without doing any transformation:

sage: p.volume(measure='induced')
32

The .volume method can use different algorithms and other measures (for example for lattice polytopes) whose performance may vary, you can check the accessible algorithms by typing p.volume? and read the documentation for more details.

2019-08-27 15:04:46 -0600 answered a question Is it possible to compute the face lattice of a polytope from its vertex-facet incidences?

From Sage version 8.9+, on, the class CombinatorialPolyhedron can do just that.

Here is an example with your suggested Egyptian pyramid:

sage: ep = CombinatorialPolyhedron([[4,3,2,1],[4,3,0],[4,2,0],[3,1,0],[2,1,0]]); ep
A 3-dimensional combinatorial polyhedron with 5 facets
sage: fl_ep = ep.face_lattice(); fl_ep
Finite lattice containing 20 elements
sage: ep.f_vector()
(1, 5, 8, 5, 1)
sage: ep_poly = polytopes.regular_polygon(4).pyramid()
sage: fl_ep_poly = ep_poly.face_lattice()
sage: fl_ep_poly.is_isomorphic(fl_ep)
True

So far, there are a few things you can call on ep like edge graph, and ridges, and a fast iterator on the faces.

2019-08-27 09:21:01 -0600 edited answer Can sage compute the h* vector of a polytope?

You can use the normaliz backend (requires Normaliz 3.5.4) and its python interface pynormaliz (requires PyNormaliz 1.16).

You can install them by typing:

sage -i normaliz
sage -i pynormaliz

Then, in a terminal with Sage 8.9 or more recent, you can get the h^*-vector by typing:

sage: C = polytopes.hypercube(3, backend="normaliz")
sage: C.ehrhart_series().numerator().coefficients()
[1, 23, 23, 1]

This hypercube is the ±1 cube, so its volume is 8*factorial(3)=48, which is 1+23+23+1.

Eventually, once this ticket is merged, it will be possible to call it directly on the polytope like so:

sage: C.h_star_vector()
[1, 23, 23, 1]
2019-08-27 06:10:47 -0600 received badge  Necromancer (source)