Ask Your Question

JTS's profile - activity

2025-02-17 17:41:19 +0100 marked best answer 0/1-equivalence for polytopes

Dear all, for polytopes there is a method P.is_combinatorially_isomorphic(Q) which tests if two polytopes are combinatorially equivalent, i.e. if their face lattices are isomorphic.

I would like to test two 0/1-polytopes, i.e. polytopes which are the convex hull of a subset of the vertices of a (canonically embedded) hypercube $Q_n \subset [0,1]^n$, for 0/1-equivalence. This means that there is an automorphism of $Q_n$ that maps $P$ to $Q$. Explicitly, the automorphism should be a combination of permuting the variables and flipping $x_i \to 1 - x_i$.

A reference is Ziegler, Lectures on 0/1-polytopes. He also mentions:

The full-dimensional 0/1-polytopes of dimension d = 4 were first enumerated by Alexx Below: There are 349 different 0/1-equivalence classes. In dimension 5 there are exactly 1226525 different 0/1-equivalence classes of 5-dimensional 0/1-polytopes. This classification was done by Oswin Aichholzer [2]: a considerable achievement, which was possible only by systematic use of all the symmetry that is in- herent in the problem.

It would be great to have access to a database of 0/1-polytopes, and be able to compare all facets of dimension at most 4 of some polytope P to candidates in the database, and classify them, something similar to

G.structure_description()

but for 0/1-polytopes.

Of secondary importance (to me) would be checking two polytopes for for affine equivalence and congruence.

Is this implemented i Sagemath?

Edit: the answer by Max Alekseyev points me in the right direction. I will investigate the polydb and polymake docs. Thanks for the help!

2025-02-17 17:40:55 +0100 marked best answer How to inherit from polytopes

Dear all, I want to write a very simple class that inherits from existing polytopes functionality, creates one particular type of polytopes, and adds some functionality which is only relevant for this type of polytopes.

However, I am a python beginner, and am having a hard time navigating the sagemath src directory to find exactly from which class (Polyhedron or Polyhedra) that I should inherit, and how to do this.

Here is a toy example: suppose I want to investigate "depleted cubes", ie polytopes combinatorially equivalent with hypercubes with one corner neatly sliced off. I also want to easily retrieve the cut-off facet.

This works:

def depleted_cube(n: Integer) -> Polyhedron:
       """Returns the n-dimensional hypercube minus one vertex"""
       H = polytopes.hypercube(n)
       Verts = [v for v in H.vertices_list() if add(v) < n]
       C = Polyhedron(vertices=Verts)
       return C

def _strange_facet(P: Polyhedron):
      """Returns the strange facet of P, but only of P depleted cube"""
      n = P.dimension()
      L = [F for F in P.facets() if len(F.vertices()) == n]
      return L[0]

I can now go

sage: _strange_facet(depleted_cube(6)).vertices()
(A vertex at (-1, 1, 1, 1, 1, 1),
A vertex at (1, -1, 1, 1, 1, 1),
A vertex at (1, 1, -1, 1, 1, 1),
A vertex at (1, 1, 1, -1, 1, 1),
A vertex at (1, 1, 1, 1, -1, 1),
A vertex at (1, 1, 1, 1, 1, -1))

but I would like to be able to do

polytopes.depleted_cube(6).strange_facet().vertices()

so as not to dilute the precious namespace! I.e., the function should be a "method" to some "class" that inherits from, either Polyhedron or Polyhedra or polyhedron_base_with_backend_cpp or ... Can someone provide an example, skeleton implementation of a polytope class that inherits from somewhere? As I mentioned, I tried looking at the src directory, but the relevant files are extremely long and littered with docstrings and doctests and cruft; I can make neither head nor tails of them.

Edit: As per the answer by dan_fulea, it is not worthwhile to try to turn the functions into a method. I will undogmatically refrain from doing so, then. Thank you for the tour through the internals of sagemath; I was not aware of the f.?? method of getting the code of a function/object.

2025-02-17 16:44:00 +0100 received badge  Famous Question (source)
2025-02-17 16:39:00 +0100 edited question How to inherit from polytopes

How to inherit from polytopes Dear all, I want to write a very simple class that inherits from existing polytopes functi

2025-02-13 14:09:46 +0100 edited question 0/1-equivalence for polytopes

0/1-equivalence for polytopes Dear all, for polytopes there is a method P.is_combinatorially_isomorphic(Q) which tests

2025-02-13 14:00:04 +0100 received badge  Famous Question (source)
2025-02-13 14:00:04 +0100 received badge  Notable Question (source)
2025-02-13 14:00:04 +0100 received badge  Popular Question (source)
2025-02-13 11:23:53 +0100 commented answer 0/1-equivalence for polytopes

This looks promising, thanks! Many useful refeernces indeed. Poking around, I found clear instructions for accessing po

2025-02-12 16:04:35 +0100 asked a question 0/1-equivalence for polytopes

0/1-equivalence for polytopes Dear all, for polytopes there is a method P.is_combinatorially_isomorphic(Q) which tests

2025-02-05 21:50:46 +0100 answered a question Lattice of maximum-length antichains in sage

Here is my attempt: def smallerB(a,B,P): if len([b for b in B if P.is_lequal(a,b)]) > 0: return true else: r

2025-02-04 19:48:19 +0100 received badge  Enthusiast
2025-02-03 21:38:12 +0100 asked a question How to inherit from polytopes

How to inherit from polytopes Dear all, I want to write a very simple class that inherits from existing polytopes functi

2024-11-20 08:26:24 +0100 received badge  Notable Question (source)
2023-10-20 13:29:38 +0100 edited question Multivariate Pade approximation, recognizing rational function

Multivariate Pade approximation, recognizing rational function (Question edited) Suppose that I have a taylor polynomia

2023-10-19 13:30:14 +0100 commented question Multivariate Pade approximation, recognizing rational function

Let me show my work so far. S.<y> = QQ[] R.<x> = S[] T.<y,x> = PowerSeriesRing(QQ,default_prec=8) U.&

2023-10-18 17:09:03 +0100 edited question Multivariate Pade approximation, recognizing rational function

Multivariate Pade approximation, recognizing rational function Suppose that I have a taylor polynomial approximation of

2023-10-18 17:06:56 +0100 edited question Multivariate Pade approximation, recognizing rational function

Multivariate Pade approximation, recognizing rational function Suppose that I have a taylor polynomial approximation of

2023-10-18 17:05:41 +0100 edited question Multivariate Pade approximation, recognizing rational function

Multivariate Pade approximation, recognizing rational function Suppose that I have a taylor polynomial approximation of

2023-10-18 17:05:22 +0100 edited question Multivariate Pade approximation, recognizing rational function

Multivariate Pade approximation, recognizing rational function Suppose that I have a taylor polynomial approximation of

2023-10-18 17:04:20 +0100 asked a question Multivariate Pade approximation, recognizing rational function

Multivariate Pade approximation, recognizing rational function Suppose that I have a taylor polynomial approximation of

2023-10-02 19:56:14 +0100 received badge  Popular Question (source)
2023-09-01 00:16:43 +0100 received badge  Nice Answer (source)
2023-08-31 12:50:40 +0100 answered a question Diagonalisability check Malfunctioning

Your matrix is not symmetric: A = matrix(QQbar, [[2,-1,0],[-1,2,1],[0,-1,2]]) A.is_symmetric()

2023-06-13 15:57:01 +0100 received badge  Notable Question (source)
2023-06-13 15:57:01 +0100 received badge  Popular Question (source)
2022-07-16 18:31:41 +0100 received badge  Nice Answer (source)
2022-07-16 18:14:58 +0100 received badge  Self-Learner (source)
2022-07-16 16:39:16 +0100 answered a question latex for Hasse diagram of poset not properly laid out

Adding dot2tex to the Sage installation, as suggested by FrédéricC and John Palmieri, did work for me and produces Hass

2022-07-10 21:37:58 +0100 edited question latex for Hasse diagram of poset not properly laid out

latex for Hasse diagram of poset not properly laid out The plot method on a poset displays the Hasse diagram in a satisf

2022-07-10 15:03:53 +0100 asked a question latex for Hasse diagram of poset not properly laid out

latex for Hasse diagram of poset not properly laid out The plot method on a poset displays the Hasse diagram in a satisf

2022-06-23 16:03:18 +0100 edited answer taylor series of expression involving modulus of a complex expression

You could expand around t=0 instead, for t = w + 0.1 var('t') bmac = b.substitute(w=t-0.1).taylor(t,0,3) cmac = c.subst

2022-06-23 16:03:01 +0100 answered a question taylor series of expression involving modulus of a complex expression

You could expand around t=0 instead, for t = w + 0. var('t') bmac = b.substitute(w=t-0.1).taylor(t,0,3) cmac = c.substi

2022-06-22 20:25:29 +0100 asked a question Displaying and typesetting partitions

Displaying and typesetting partitions A partition can be viewed as a list or pretty-printed using ascii art. This works

2022-06-21 19:47:32 +0100 received badge  Supporter (source)
2022-06-21 19:44:15 +0100 marked best answer Simplifying factorials, limits, Maxima crash

I am trying to simplify some binomial expressions using Sage.

var('a,n,c,m')
H = binomial(2*m-c,m-c)-binomial(2*m-c,m+1)
Cn = binomial(2*n,n)/(n+1)
Uan = (H.substitute(m=n,c=a+1) + a*H.substitute(m=n-1,c=a))/Cn 
assume(a>0)
assume(n>0)
assume(n,'integer')
assume(a,'integer')
UUan=Uan.full_simplify()
UUan

Now I want the limit of this expression as n -> +Infininty. Maple can do it, it correctly returns

                                                             2                  (-a)
                                                          (a  + 3 a + 4) 2
                                                          --------------------
                                                                   4

I can get Sage to calculate the limit for specific values of a:

limit(UUan.substitute(a=5),n=+Infinity)

However, when I try

limit(UUan,n=+Infinity)

I get an error from the underlying Maxima engine:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-70-59aa81a6cc92> in <module>
----> 1 limit(UUan,n=+Infinity)

~/sage/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/sage/calculus/calculus.py in limit(ex, dir, taylor, algorithm, **argv)
   1415     if algorithm == 'maxima':
   1416         if dir is None:
-> 1417             l = maxima.sr_limit(ex, v, a)
   1418         elif dir in dir_plus:
   1419             l = maxima.sr_limit(ex, v, a, 'plus')

~/sage/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/sage/interfaces/maxima_lib.py in sr_limit(self, expr, v, a, dir)
    985             elif dir == "minus":
    986                 L.append(max_minus)
--> 987             return max_to_sr(maxima_eval(([max_limit], L)))
    988         except RuntimeError as error:
    989             s = str(error)

~/sage/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.EclObject.__call__ (build/cythonized/sage/libs/ecl.c:8511)()
    836         """
    837         lispargs = EclObject(list(args))
--> 838         return ecl_wrap(ecl_safe_apply(self.obj,(<EclObject>lispargs).obj))
    839 
    840     def __richcmp__(left, right, int op):

~/sage/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.ecl_safe_apply (build/cythonized/sage/libs/ecl.c:6053)()
    357             raise KeyboardInterrupt("ECL says: {}".format(message))
    358         else:
--> 359             raise RuntimeError("ECL says: {}".format(message))
    360     else:
    361         return ret

RuntimeError: ECL says: BINDING-STACK overflow at size 10240. Stack can probably be resized.
Proceed with caution.

---------------------------------------------------------------------------------------------------------------------------------------------

Is SAGE able to compute this limit? Should i provide other provisos? Is there another approach I should try?

Edit: The following works:

Uan.limit(n=Infinity,dir='+',taylor=True)

so I guess all is well. I do not know if the fact that Maxima throws an exception when the taylor keyword is ommitted is a bug or not. The documentation for limit says

  • "taylor" - (default: False); if True, use Taylor series, which allows more limits to be computed (but may also crash in some obscure cases due to bugs in Maxima).

Maybe this should be amended to indicate that in some cases, taylor=False causes crashes.

2022-06-21 19:44:15 +0100 received badge  Scholar (source)
2022-06-21 15:53:39 +0100 edited answer Simplifying factorials, limits, Maxima crash

The function limit() has a keyword taylor, which might help or hinder. In this case, Uan.limit(n=Infinity,dir='+',taylo

2022-06-21 15:52:32 +0100 answered a question Simplifying factorials, limits, Maxima crash

The function limit() has a keyword taylor, which might help or hinder. In this case, Uan.limit(n=Infinity,dir='+'

2022-06-21 15:47:55 +0100 commented question Simplifying factorials, limits, Maxima crash

++++++++++

2022-06-21 15:37:15 +0100 commented question Simplifying factorials, limits, Maxima crash

Uan.limit(n=Infinity,dir='+',taylor=True) works in this case, in other cases it is better to use taylor=False.

2022-06-21 15:37:02 +0100 commented question Simplifying factorials, limits, Maxima crash

Uan.limit(n=Infinity,dir='+',taylor=True) works in this case, in other cases it is better to use taylor=False.

2022-06-21 15:30:59 +0100 edited question Simplifying factorials, limits, Maxima crash

Simplifying factorials, limits, Maxima crash I am trying to simplify some binomial expressions using Sage. var('a,n,c,m

2022-06-21 09:11:05 +0100 edited question Simplifying factorials, limits, Maxima crash

Simplifying factorials, limits, Maxima crash I am trying to simplify some binomial expressions using Sage. var('a,n,c,m

2022-06-21 09:11:02 +0100 edited question Simplifying factorials, limits, Maxima crash

Simplifying factorials, limits, Maxima crash I am trying to simplify some binomial expressions using Sage. var('a,n,c,m

2022-06-21 08:01:24 +0100 edited question Simplifying factorials, limits, Maxima crash

Simplifying factorials, limits, Maxima crash I am trying to simplify some binomial expressions using Sage. var('a,n,c,m

2022-06-21 08:01:05 +0100 edited question Simplifying factorials, limits, Maxima crash

Simplifying factorials, limits, Maxima crash I am trying to simplify some binomial expressions using Sage. var('a,n,c,m

2022-06-21 07:33:00 +0100 asked a question Simplifying factorials, limits, Maxima crash

Simplifying factorials, limits, Maxima crash I am trying to simplify some binomial expressions using Sage. var('a,n,c,m

2022-06-15 07:08:13 +0100 received badge  Nice Answer (source)