File: universal_polytope.rules

package info (click to toggle)
polymake 4.12-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 35,992 kB
  • sloc: cpp: 168,768; perl: 43,375; javascript: 31,575; ansic: 3,007; java: 2,654; python: 633; sh: 268; xml: 117; makefile: 61
file content (366 lines) | stat: -rw-r--r-- 14,975 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#  Copyright (c) 1997-2024
#  Ewgenij Gawrilow, Michael Joswig, and the polymake team
#  Technische Universität Berlin, Germany
#  https://polymake.org
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-------------------------------------------------------------------------------

object Polytope {

    # @category Combinatorics
    # A lower bound for the minimal number of simplices in a triangulation
    property SIMPLEXITY_LOWER_BOUND : Int;

    # @category Combinatorics
    # An upper bound for the maximal signature of a foldable triangulation of a polytope
    # The signature is the absolute difference of the normalized volumes of black minus white maximal simplices,
    # where only odd normalized volumes are taken into account.
    property FOLDABLE_MAX_SIGNATURE_UPPER_BOUND : Int;

    rule SIMPLEXITY_LOWER_BOUND : COMBINATORIAL_DIM, VERTICES, MAX_INTERIOR_SIMPLICES, VOLUME, COCIRCUIT_EQUATIONS {
        $this->SIMPLEXITY_LOWER_BOUND = simplexity_lower_bound($this->COMBINATORIAL_DIM, $this->VERTICES, $this->MAX_INTERIOR_SIMPLICES, $this->VOLUME, $this->COCIRCUIT_EQUATIONS);
    }

    rule FOLDABLE_MAX_SIGNATURE_UPPER_BOUND : COMBINATORIAL_DIM, VERTICES, MAX_INTERIOR_SIMPLICES, VOLUME, FOLDABLE_COCIRCUIT_EQUATIONS {
        $this->FOLDABLE_MAX_SIGNATURE_UPPER_BOUND = foldable_max_signature_upper_bound($this->COMBINATORIAL_DIM, $this->VERTICES, $this->MAX_INTERIOR_SIMPLICES, $this->VOLUME, $this->FOLDABLE_COCIRCUIT_EQUATIONS);
    }

    # @category Combinatorics
    # The symmetrized version of SIMPLEXITY_LOWER_BOUND
    rule GROUP.SIMPLEXITY_LOWER_BOUND : VOLUME, VERTICES, COMBINATORIAL_DIM, GROUP.REPRESENTATIVE_MAX_INTERIOR_SIMPLICES, GROUP.VERTICES_ACTION.SYMMETRIZED_COCIRCUIT_EQUATIONS.PROJECTED_EQUATIONS {
        $this->GROUP->SIMPLEXITY_LOWER_BOUND = simplexity_lower_bound($this->COMBINATORIAL_DIM, $this->VERTICES, $this->GROUP->REPRESENTATIVE_MAX_INTERIOR_SIMPLICES, $this->VOLUME, $this->GROUP->VERTICES_ACTION->SYMMETRIZED_COCIRCUIT_EQUATIONS->PROJECTED_EQUATIONS);
    }

} # end Polytope

object PointConfiguration {

    # @category Symmetry
    # The symmetrized version of SIMPLEXITY_LOWER_BOUND
    rule GROUP.SIMPLEXITY_LOWER_BOUND : CONVEX_HULL.COMBINATORIAL_DIM, CONVEX_HULL.VOLUME, POINTS, GROUP.REPRESENTATIVE_MAX_INTERIOR_SIMPLICES, GROUP.POINTS_ACTION.SYMMETRIZED_COCIRCUIT_EQUATIONS.ISOTYPIC_COMPONENTS, GROUP.POINTS_ACTION.SYMMETRIZED_COCIRCUIT_EQUATIONS.RIDGES, GROUP.POINTS_ACTION.SYMMETRIZED_COCIRCUIT_EQUATIONS.PROJECTED_EQUATIONS {
        $this->GROUP->SIMPLEXITY_LOWER_BOUND = simplexity_lower_bound($this->CONVEX_HULL->COMBINATORIAL_DIM, $this->POINTS, $this->GROUP->REPRESENTATIVE_MAX_INTERIOR_SIMPLICES, $this->CONVEX_HULL->VOLUME, $this->GROUP->POINTS_ACTION->SYMMETRIZED_COCIRCUIT_EQUATIONS->PROJECTED_EQUATIONS);
    }

    
} # end PointConfiguration


# @category Triangulations, subdivisions and volume
# Calculate the universal polytope //U(P)// of an input polytope //P//. 
# If //P// has //n// vertices and dimension //d//, then //U(P)// is a
# 0/1-polytope in dimension binomial(//n//,//d//+1) whose vertices
# correspond to the full triangulations of //P//. Each coordinate of a
# particular vertex //v// indicates the presence or absence of a
# particular simplex in the triangulation corresponding to //v//, and
# the order of the simplices (and hence the interpretation of each
# coordinate of //v//) is the one given by the property
# MAX_INTERIOR_SIMPLICES. Because the number of triangulations of
# //P// is typically very large, the polytope U(P) is not constructed
# by enumerating triangulations, but instead in the inequality
# description afforded by the cocircuit equations, a volume equality,
# and non-negativity constraints for the coordinates.
# @param Polytope P the input polytope
# @return Polytope
# @example
# Since the 2-dimensional cube (i.e., the square) has just two
# triangulations, its universal polytope is a segment embedded in dimension
# binomial(4,3) = 4. The cocircuit equations read as follows:
# > print universal_polytope(cube(2))->EQUATIONS;
# | -8 4 4 4 4
# | (5) (2 -1) (3 1)
# | (5) (1 -1) (4 1)
user_function universal_polytope<Scalar>(Polytope<Scalar>) {
    my $p = shift;
    return universal_polytope_impl($p->COMBINATORIAL_DIM, $p->VERTICES, $p->MAX_INTERIOR_SIMPLICES, $p->VOLUME, $p->COCIRCUIT_EQUATIONS);
}                      

# @category Triangulations, subdivisions and volume
# Calculate the universal polytope of a polytope, point configuration or quotient manifold
# @param Polytope P the input polytope
# @param Array<Set> reps the representatives of maximal interior simplices 
# @param SparseMatrix cocircuit_equations the matrix of cocircuit equations 
# @return Polytope
user_function universal_polytope<Scalar>(Polytope<Scalar>, Array<Set>, SparseMatrix) {
    my ($p, $simplices, $cocircuit_equations) = @_;
    return universal_polytope_impl($p->COMBINATORIAL_DIM, $p->VERTICES, $simplices, $p->VOLUME, new SparseMatrix<Rational>($cocircuit_equations));
}                      

# @category Optimization
# construct a linear program whose optimal value is a lower bound for the minimal number of simplices
# in a triangulation of P.
# @param Polytope P
# @option String outfile_name. If the string is '-' (as is the default), the linear program is printed to STDOUT.
# @example
# To print the linear program for the 2-dimensional cube, write
# > write_simplexity_ilp(cube(2));
# | MINIMIZE
# |   obj: +1 x1 +1 x2 +1 x3 +1 x4
# | Subject To
# |   ie0: +1 x1 >= 0
# |   ie1: +1 x2 >= 0
# |   ie2: +1 x3 >= 0
# |   ie3: +1 x4 >= 0
# |   eq0: +4 x1 +4 x2 +4 x3 +4 x4 = 8
# |   eq1: -1 x2 +1 x3 = 0
# |   eq2: -1 x1 +1 x4 = 0
# | BOUNDS
# |   x1 free
# |   x2 free
# |   x3 free
# |   x4 free
# | GENERAL
# |   x1
# |   x2
# |   x3
# |   x4
# | END
user_function write_simplexity_ilp<Scalar>(Polytope<Scalar>; $='-') {
    my ($p, $outfilename) = @_;
    my $rmis = new Array<Set>($p->MAX_INTERIOR_SIMPLICES);
    my $q = simplexity_ilp($p->COMBINATORIAL_DIM, $p->VERTICES, $rmis, $p->VOLUME, $p->COCIRCUIT_EQUATIONS);
    poly2lp($q, $q->LP, 0, $outfilename);
}

# @category Optimization
# construct a linear program whose optimal value is a lower bound for the minimal number of simplices
# in a triangulation of P, and that takes into account the angle constraint around codimension 2 faces.
# The first set of variables correspond to possible maximal internal simplices, the second set to the
# simplices of codimension 2. See the source file polytope/src/symmetrized_codim_2_angle_sums.cc for details.
# @param Polytope P
# @param String outfile_name 
# @example
# To print the linear program for the 2-dimensional cube, write
# > write_simplexity_ilp_with_angles(cube(2));
# | MINIMIZE
# |   obj: +1 x1 +1 x2 +1 x3 +1 x4
# | Subject To
# |   ie0: +1 x1 >= 0
# |   ie1: +1 x2 >= 0
# |   ie2: +1 x3 >= 0
# |   ie3: +1 x4 >= 0
# |   ie4: +1 x5 >= 0
# |   ie5: +1 x6 >= 0
# |   ie6: +1 x7 >= 0
# |   ie7: +1 x8 >= 0
# |   eq0: -1 x2 +1 x3 = 0
# |   eq1: -1 x1 +1 x4 = 0
# |   eq2: +0.5 x1 +0.25 x2 +0.2500000000000001 x3 -0.5 x5 = 0
# |   eq3: +0.25 x1 +0.5 x3 +0.2500000000000001 x4 -0.5 x6 = 0
# |   eq4: +0.25 x1 +0.5 x2 +0.2500000000000001 x4 -0.5 x7 = 0
# |   eq5: +0.25 x2 +0.2500000000000001 x3 +0.5 x4 -0.5 x8 = 0
# |   eq6: +1 x5 = 1
# |   eq7: +1 x6 = 1
# |   eq8: +1 x7 = 1
# |   eq9: +1 x8 = 1
# |   eq10: +4 x1 +4 x2 +4 x3 +4 x4 = 8
# | BOUNDS
# |   x1 free
# |   x2 free
# |   x3 free
# |   x4 free
# |   x5 free
# |   x6 free
# |   x7 free
# |   x8 free
# | GENERAL
# |   x1
# |   x2
# |   x3
# |   x4
# |   x5
# |   x6
# |   x7
# |   x8
# | END
# | 
user_function write_simplexity_ilp_with_angles<Scalar>(Polytope<Scalar>; $="-") {
    my ($p, $outfilename) = @_;
    my $rmis = new Array<Set>($p->MAX_INTERIOR_SIMPLICES);
    my $trivial_gens = new Array<Array<Int>>();
    my $V = new Matrix<Scalar>($p->VERTICES);
    my $F = new Matrix<Scalar>($p->FACETS);
    my $q = simplexity_ilp_with_angles($p->COMBINATORIAL_DIM, $V, $F, $p->VERTICES_IN_FACETS, $p->VERTICES_IN_RIDGES, $trivial_gens, $rmis, $p->VOLUME, $p->COCIRCUIT_EQUATIONS);
    poly2lp($q, $q->LP, 0, $outfilename);
}

# @category Optimization
# construct a linear program whose optimal value is a lower bound for
# the minimal number of simplices in a triangulation of P.
# The symmetry group of P is taken into account, in that the
# variables in the linear program are projections of the indicator
# variables of the maximal interior simplices to a given direct sum of
# isotypic components of the symmetry group of P acting on these simplices.
# @param Polytope P
# @param Set<Int> isotypic_components the set of indices of isotypic components to project to; default [0]
# @param String outfile_name. Setting this to '-' (as is the default) prints the LP to stdout.
# @example
# For the 3-cube, the symmetrized LP for isotypic component 0 reads as follows:
# > write_symmetrized_simplexity_ilp(cube(3,group=>1));
# | MINIMIZE
# |   obj: +1 x1 +1 x2 +1 x3 +1 x4
# | Subject To
# |   ie0: +1 x1 >= 0
# |   ie1: +1 x2 >= 0
# |   ie2: +1 x3 >= 0
# |   ie3: +1 x4 >= 0
# |   eq0: +8 x1 +8 x2 +8 x3 +16 x4 = 48
# |   eq1: -6 x1 +6 x3 +24 x4 = 0
# | BOUNDS
# |   x1 free
# |   x2 free
# |   x3 free
# |   x4 free
# | GENERAL
# |   x1
# |   x2
# |   x3
# |   x4
# | END
# The interpretation is as follows: The variables x1,...,x4 correspond to the representatives of interior simplices:
# > print cube(3,group=>1)->GROUP->REPRESENTATIVE_MAX_INTERIOR_SIMPLICES;
# | {0 1 2 4}
# | {0 1 2 5}
# | {0 1 2 7}
# | {0 3 5 6}
# The solution (x1,x2,x3,x4) = (4,0,0,1) of the LP says that in a minimal triangulation of the 3-cube, 
# there are 4 simplices in the same symmetry class as {0,1,2,4}, and one in the class of {0,3,5,6}.

user_function write_symmetrized_simplexity_ilp<Scalar>(Polytope<Scalar>; $=[0], $="-") {
    my ($p, $isotypic_components_ref, $outfilename) = @_;
    my $isotypic_components = new Set<Int>($isotypic_components_ref);
    my $q = simplexity_ilp($p->COMBINATORIAL_DIM, $p->VERTICES, $p->GROUP->REPRESENTATIVE_MAX_INTERIOR_SIMPLICES, $p->VOLUME, symmetrized_cocircuit_equations($p, $isotypic_components)->PROJECTED_EQUATIONS);
    poly2lp($q, $q->LP, 0, $outfilename);
}


# @category Optimization
# construct a linear program whose optimal value is an upper bound for the algebraic signature of 
# a triangulation of P. This is the absolute value of the difference of normalized volumes of black
# minus white simplices (counting only those with odd normalized volume) in a triangulation of P
# whose dual graph is bipartite.
# If P has a GROUP, it will be used to construct the linear program.
# @param Polytope P
# @param String outfile_name
# @example
# For the 0/1 2-cube without a GROUP, the foldable max signature lp is computed as follows:
# > write_foldable_max_signature_ilp(cube(2,0));
# | MINIMIZE
# |   obj: +1 x1 -1 x2 +1 x3 -1 x4 +1 x5 -1 x6 +1 x7 -1 x8
# | Subject To
# |   ie0: +1 x1 >= 0
# |   ie1: +1 x2 >= 0
# |   ie2: +1 x3 >= 0
# |   ie3: +1 x4 >= 0
# |   ie4: +1 x5 >= 0
# |   ie5: +1 x6 >= 0
# |   ie6: +1 x7 >= 0
# |   ie7: +1 x8 >= 0
# |   ie8: -1 x1 -1 x2 >= -1
# |   ie9: -1 x3 -1 x4 >= -1
# |   ie10: -1 x5 -1 x6 >= -1
# |   ie11: -1 x7 -1 x8 >= -1
# |   eq0: -1 x4 +1 x5 = 0
# |   eq1: +1 x3 -1 x6 = 0
# |   eq2: -1 x2 +1 x7 = 0
# |   eq3: +1 x1 -1 x8 = 0
# |   eq4: +1 x1 +1 x2 +1 x3 +1 x4 +1 x5 +1 x6 +1 x7 +1 x8 = 2
# | BOUNDS
# |   x1 free
# |   x2 free
# |   x3 free
# |   x4 free
# |   x5 free
# |   x6 free
# |   x7 free
# |   x8 free
# | GENERAL
# |   x1
# |   x2
# |   x3
# |   x4
# |   x5
# |   x6
# |   x7
# |   x8
# | END
# There are eight variables, one for each possible black or white maximal interior simplex. The optimal value of this LP is zero, because any triangulation
# has exactly one black and one white simplex of odd normalized volume. Notice that the objective function becomes empty for cube(2), because in the +1/-1 cube,
# each simplex has even volume.
# @example
# For the 0/1 3-cube, we use a GROUP property:
# > write_foldable_max_signature_ilp(cube(3,0,group=>1));
# | MINIMIZE
# |   obj: +1 x1 -1 x2 +1 x3 -1 x4 +1 x5 -1 x6
# | Subject To
# |   ie0: +1 x1 >= 0
# |   ie1: +1 x2 >= 0
# |   ie2: +1 x3 >= 0
# |   ie3: +1 x4 >= 0
# |   ie4: +1 x5 >= 0
# |   ie5: +1 x6 >= 0
# |   ie6: +1 x7 >= 0
# |   ie7: +1 x8 >= 0
# |   ie8: -1 x1 -1 x2 >= -8
# |   ie9: -1 x3 -1 x4 >= -24
# |   ie10: -1 x5 -1 x6 >= -24
# |   ie11: -1 x7 -1 x8 >= -2
# |   eq0: +2 x3 -2 x4 +2 x5 -2 x6 = 0
# |   eq1: -2 x3 +2 x4 -2 x5 +2 x6 = 0
# |   eq2: -6 x2 +6 x5 +24 x7 = 0
# |   eq3: -6 x1 +6 x6 +24 x8 = 0
# |   eq4: +1 x1 +1 x2 +1 x3 +1 x4 +1 x5 +1 x6 +2 x7 +2 x8 = 6
# | BOUNDS
# |   x1 free
# |   x2 free
# |   x3 free
# |   x4 free
# |   x5 free
# |   x6 free
# |   x7 free
# |   x8 free
# | GENERAL
# |   x1
# |   x2
# |   x3
# |   x4
# |   x5
# |   x6
# |   x7
# |   x8
# | END
# There are again 8 variables, but now they correspond to the black and white representatives of the four symmetry classes of maximal interior simplices.
# The optimal value of this linear program is 4, because the most imbalanced triangulation is the one with 5 simplices, in which the volume of the big interior
# simplex is even and doesn't get counted in the objective function.
user_function write_foldable_max_signature_ilp<Scalar>(Polytope<Scalar>; $="-") {
    my $p = shift;
    my $outfilename = shift;
    if (!$p->LATTICE) {
        die "need the polytope to be a lattice polytope, ie, all vertices must be integral";
    }
    my $q;
    if ($p->lookup("GROUP")) {
        my $max_simplices = $p->GROUP->REPRESENTATIVE_MAX_INTERIOR_SIMPLICES;
        my $foldable_cocircuit_equations = symmetrized_foldable_cocircuit_equations_0($p->COMBINATORIAL_DIM, $p->VERTICES, $p->VERTICES_IN_FACETS, $p->GROUP->VERTICES_ACTION->GENERATORS, $p->GROUP->REPRESENTATIVE_INTERIOR_RIDGE_SIMPLICES, $max_simplices);
        $q = symmetrized_foldable_max_signature_ilp($p->COMBINATORIAL_DIM, $p->VERTICES, $max_simplices, $p->VOLUME, $p->GROUP->VERTICES_ACTION->GENERATORS, $foldable_cocircuit_equations);
    } else {
        my $max_simplices = $p->MAX_INTERIOR_SIMPLICES;
        my $foldable_cocircuit_equations = $p->FOLDABLE_COCIRCUIT_EQUATIONS;
        $q = foldable_max_signature_ilp($p->COMBINATORIAL_DIM, $p->VERTICES, $max_simplices, $p->VOLUME, $foldable_cocircuit_equations);
    }
    poly2lp($q, $q->LP, 0, $outfilename);    
}
    
# Local Variables:
# mode: perl
# cperl-indent-level:3
# indent-tabs-mode:nil
# End: