1 | /////////////////////////////////////////////////////////////////////////////// |
---|
2 | version="version gfan.lib 4.1.2.0 Feb_2019 "; // $Id$ |
---|
3 | category = "Convex Geometry"; |
---|
4 | info=" |
---|
5 | LIBRARY: gfan.lib Interface to gfan and gfanlib for computations in convex geometry |
---|
6 | AUTHORS: Anders N. Jensen, email: jensen@imf.au.dk |
---|
7 | Yue Ren, email: ren@mathematik.uni-kl.de |
---|
8 | Frank Seelisch |
---|
9 | |
---|
10 | PROCEDURES: |
---|
11 | fullSpace(n); cone, the ambient space of dimension n |
---|
12 | origin(n); cone, the origin in an ambient space of dimension n |
---|
13 | positiveOrthant(n); cone, the positive orthant of dimension n |
---|
14 | ambientDimension(c); the dimension of the ambient space the input lives in |
---|
15 | canonicalizeCone(c); a unique representation of the cone c |
---|
16 | codimension(c); the codimension of the input |
---|
17 | coneViaPoints(); define a cone |
---|
18 | coneViaInequalities(); define a cone |
---|
19 | coneLink(c,w); the link of c around w |
---|
20 | containsAsFace(c,d); is d a face of c |
---|
21 | containsInSupport(c,d); is d contained in c |
---|
22 | containsPositiveVector(c); contains a vector with only positive entries? |
---|
23 | containsRelatively(c,p); p in c? |
---|
24 | convexHull(c1,c2); convex hull |
---|
25 | convexIntersection(c1,c2); convex hull |
---|
26 | dimension(c); dimension of c |
---|
27 | dualCone(c); the dual of c |
---|
28 | equations(c); defining equations of c |
---|
29 | faceContaining(c,w); the face of c containing w in its relative interior |
---|
30 | facets(c); the facets of c |
---|
31 | generatorsOfLinealitySpace(c); generators of the lineality space of c |
---|
32 | generatorsOfSpan(c); generators of the span of c |
---|
33 | getLinearForms(c); linear forms previously stored in c |
---|
34 | getMultiplicity(c); multiplicity previously stored in c |
---|
35 | inequalities(c); inequalities of c |
---|
36 | isFullSpace(c); is the entire ambient space? |
---|
37 | isOrigin(c); is the origin? |
---|
38 | isSimplicial(c); is simplicial? |
---|
39 | linealityDimension(c); the dimension of the lineality space of c |
---|
40 | linealitySpace(c); the lineality space of c |
---|
41 | negatedCone(c); the negative of c |
---|
42 | polytopeViaInequalities(); |
---|
43 | polytopeViaPoints(); |
---|
44 | quotientLatticeBasis(c); basis of Z^n intersected with the span of c modulo Z^n intersected with the lineality space of c |
---|
45 | randomPoint(c); a random point in the relative interior of c |
---|
46 | rays(c); generators of the rays of c |
---|
47 | relativeInteriorPoint(c); point in the relative interior of c |
---|
48 | semigroupGenerator(c); generator of Z^n intersected with c modulo Z^n intersected with the lineality space of c |
---|
49 | setLinearForms(c); stores linear forms in c |
---|
50 | setMultiplicity(c); stores a multiplicity in c |
---|
51 | span(c); unique irredundant equations of c |
---|
52 | uniquePoint(c); a unique point in c stable under reflections at coordinate hyperplanes |
---|
53 | containsInCollection(f,c); f contains c? |
---|
54 | emptyFan(n); empty fan in ambient dimension n |
---|
55 | fanViaCones(L); fan generated by the cones in L |
---|
56 | fullFan(n); full fan in ambient dimension n |
---|
57 | fVector(f); the f-Vector of f |
---|
58 | getCone(f,d,i[,m]); the i-th cone of dimension d in f |
---|
59 | insertCone(f,c[,b]); inserts the cone c into f |
---|
60 | isCompatible(f,c); f and c live in the same ambient space |
---|
61 | isPure(f); all maximal cones of f are of the same dimension |
---|
62 | nmaxcones(f); number of maximal cones in f |
---|
63 | ncones(f); number of cones in f |
---|
64 | numberOfConesOfDimension(f,d[,m]); the number of cones in dimension d |
---|
65 | removeCone(f,c[,b]); removes the cone c |
---|
66 | dualPolytope(p); the dual of p |
---|
67 | newtonPolytope(f); convex hull of all exponent vectors of f |
---|
68 | vertices(p); vertices of p |
---|
69 | onesVector(n); intvec of length n with all entries 1 |
---|
70 | "; |
---|
71 | |
---|
72 | /////////////////////////////////////////////////////////////////////////////// |
---|
73 | |
---|
74 | ///// |
---|
75 | // non gfanlib.so functions |
---|
76 | ///// |
---|
77 | |
---|
78 | proc fullSpace(int n) |
---|
79 | "USAGE: fullSpace(n); n int |
---|
80 | RETURN: cone, the ambient space of dimension n |
---|
81 | EXAMPLE: example positiveOrthant; shows an example |
---|
82 | " |
---|
83 | { |
---|
84 | cone c = n; |
---|
85 | return (c); |
---|
86 | } |
---|
87 | example |
---|
88 | { |
---|
89 | "EXAMPLE:"; echo = 2; |
---|
90 | cone c = fullSpace(2); |
---|
91 | generatorsOfLinealitySpace(c); |
---|
92 | } |
---|
93 | |
---|
94 | proc origin(int n) |
---|
95 | "USAGE: origin(n); n int |
---|
96 | RETURN: cone, the origin in an ambient space of dimension n |
---|
97 | EXAMPLE: example origin; shows an example |
---|
98 | " |
---|
99 | { |
---|
100 | bigintmat ineq[0][n]; |
---|
101 | bigintmat eq[n][n]; |
---|
102 | for (int i=1; i<=n; i++) |
---|
103 | { |
---|
104 | eq[i,i]=1; |
---|
105 | } |
---|
106 | cone o = coneViaInequalities(ineq,eq); |
---|
107 | return (o); |
---|
108 | } |
---|
109 | example |
---|
110 | { |
---|
111 | "EXAMPLE:"; echo = 2; |
---|
112 | cone c = origin(2); |
---|
113 | equations(c); |
---|
114 | } |
---|
115 | |
---|
116 | proc positiveOrthant(int n) |
---|
117 | "USAGE: positiveOrthant(n); n int |
---|
118 | RETURN: cone, the positive orthant of dimension n |
---|
119 | EXAMPLE: example positiveOrthant; shows an example |
---|
120 | " |
---|
121 | { |
---|
122 | bigintmat ineq[n][n]; |
---|
123 | for (int i=1; i<=n; i++) |
---|
124 | { |
---|
125 | ineq[i,i]=1; |
---|
126 | } |
---|
127 | cone posOrthant = coneViaInequalities(ineq); |
---|
128 | return (posOrthant); |
---|
129 | } |
---|
130 | example |
---|
131 | { |
---|
132 | "EXAMPLE:"; echo = 2; |
---|
133 | cone c = positiveOrthant(2); |
---|
134 | rays(c); |
---|
135 | } |
---|
136 | |
---|
137 | ///// |
---|
138 | // gfan interface functions |
---|
139 | ///// |
---|
140 | |
---|
141 | static proc intmatToGfanVectorConfiguration(intmat P) |
---|
142 | { |
---|
143 | string gfanVectorConfiguration = "{"; |
---|
144 | int c = ncols(P); |
---|
145 | for (int i=1; i<=nrows(P); i++) |
---|
146 | { |
---|
147 | gfanVectorConfiguration = gfanVectorConfiguration |
---|
148 | +"("+string(intvec(P[i,1..c]))+"),"; |
---|
149 | } |
---|
150 | int k = size(gfanVectorConfiguration); |
---|
151 | gfanVectorConfiguration = gfanVectorConfiguration[1..k-1]; |
---|
152 | gfanVectorConfiguration = gfanVectorConfiguration+"}"; |
---|
153 | return (gfanVectorConfiguration); |
---|
154 | } |
---|
155 | |
---|
156 | proc secondaryFan(intmat P, def #) |
---|
157 | "USAGE: secondaryFan(P); P intmat |
---|
158 | secondaryFan(P,s); P intmat, s string |
---|
159 | RETURN: fan, the secondary fan of the vector configuration P |
---|
160 | NOTE: s is a option string that is passed to gfan, possible options are |
---|
161 | '--log1' to '--log3' for output during the computation |
---|
162 | EXAMPLE: example secondaryFan; shows an examplex |
---|
163 | " |
---|
164 | { |
---|
165 | string filename = "/tmp/gfanlib_secondaryFan_"+string(random(1,2147483647)); |
---|
166 | string filenameIn = filename+".in.gfan"; |
---|
167 | string filenameOut = filename+".out.gfan"; |
---|
168 | |
---|
169 | string filestring = intmatToGfanVectorConfiguration(P); |
---|
170 | filestring; |
---|
171 | write(":w "+filenameIn,filestring); |
---|
172 | int dummy = system("sh","gfan_secondaryfan "+string(#)+" < "+filenameIn+" > "+filenameOut); |
---|
173 | string fanString = read(filenameOut); |
---|
174 | |
---|
175 | dummy = system("sh","rm "+filenameIn+" "+filenameOut); |
---|
176 | return (fanFromString(fanString)); |
---|
177 | } |
---|
178 | example |
---|
179 | { |
---|
180 | "EXAMPLE:"; echo = 2; |
---|
181 | intmat P[4][3] = |
---|
182 | 1,0,0, |
---|
183 | 1,1,0, |
---|
184 | 1,0,1, |
---|
185 | 1,1,1; |
---|
186 | fan F = secondaryFan(P); |
---|
187 | F; |
---|
188 | } |
---|
189 | |
---|
190 | ///// |
---|
191 | // cone related functions |
---|
192 | ///// |
---|
193 | |
---|
194 | proc ambientDimension() |
---|
195 | "USAGE: ambientDimension(c); c cone |
---|
196 | ambientDimension(f); f fan |
---|
197 | ambientDimension(p); p polytope |
---|
198 | RETURN: int, the dimension of the ambient space the input lives in |
---|
199 | EXAMPLE: example ambientDimension; shows an example |
---|
200 | " |
---|
201 | { |
---|
202 | |
---|
203 | } |
---|
204 | example |
---|
205 | { |
---|
206 | "EXAMPLE:"; echo = 2; |
---|
207 | intmat M1[2][2]= |
---|
208 | 1,0, |
---|
209 | 0,1; |
---|
210 | cone c1=coneViaPoints(M1); |
---|
211 | ambientDimension(c1); |
---|
212 | intmat M2[2][3]= |
---|
213 | 1,0,0, |
---|
214 | 0,1,0; |
---|
215 | cone c2=coneViaPoints(M2); |
---|
216 | ambientDimension(c2); |
---|
217 | |
---|
218 | fan f = emptyFan(3); |
---|
219 | ambientDimension(f); |
---|
220 | } |
---|
221 | |
---|
222 | proc canonicalizeCone() |
---|
223 | "USAGE: canonicalizeCone(c); c cone |
---|
224 | RETURN: cone, a unique representation of the cone c |
---|
225 | EXAMPLE: example canonicalizeCone; shows an example |
---|
226 | " |
---|
227 | { |
---|
228 | } |
---|
229 | example |
---|
230 | { |
---|
231 | "EXAMPLE:"; echo = 2; |
---|
232 | intmat M[5][3]= |
---|
233 | 8,1,9, |
---|
234 | 9,2,4, |
---|
235 | 0,6,2, |
---|
236 | 8,8,8, |
---|
237 | 0,9,5; |
---|
238 | cone c=coneViaInequalities(M); |
---|
239 | c; |
---|
240 | cone cc=canonicalizeCone(c); |
---|
241 | cc; |
---|
242 | // computes a unique representation of c |
---|
243 | c == cc; |
---|
244 | // some procedures work with the known inequalities and equations |
---|
245 | // in order to obtain a unique output, |
---|
246 | // bring the cone in canonical form beforehand |
---|
247 | relativeInteriorPoint(c); |
---|
248 | relativeInteriorPoint(cc); |
---|
249 | } |
---|
250 | |
---|
251 | proc codimension() |
---|
252 | "USAGE: codimension(c); c cone |
---|
253 | codimension(f); f fan |
---|
254 | codimension(p); p polytope |
---|
255 | RETURN: int, the codimension of the input |
---|
256 | EXAMPLE: example codimension; shows an example |
---|
257 | " |
---|
258 | { |
---|
259 | |
---|
260 | } |
---|
261 | example |
---|
262 | { |
---|
263 | "EXAMPLE:"; echo = 2; |
---|
264 | intmat M1[1][2]= |
---|
265 | 1,0; |
---|
266 | cone c1=coneViaPoints(M1); |
---|
267 | codimension(c1); |
---|
268 | intmat M2[2][2]= |
---|
269 | 1,0, |
---|
270 | 0,1; |
---|
271 | cone c2=coneViaPoints(M2); |
---|
272 | codimension(c2); |
---|
273 | |
---|
274 | fan f = emptyFan(2); |
---|
275 | codimension(f); |
---|
276 | insertCone(f,c1); |
---|
277 | codimension(f); |
---|
278 | insertCone(f,c2); |
---|
279 | codimension(f); |
---|
280 | } |
---|
281 | |
---|
282 | proc coneViaPoints() |
---|
283 | "USAGE: coneViaPoints(HL); intmat HL |
---|
284 | coneViaPoints(HL,L); intmat HL, intmat L |
---|
285 | coneViaPoints(HL,L,flags); intmat HL, intmat L, int flags |
---|
286 | RETURN: cone |
---|
287 | PURPOSE: cone generated by half lines generated by the row vectors of HL |
---|
288 | and (if stated) by lines generated by the row vectors of L; |
---|
289 | flags may range between 0,..,3 defining an upper and lower bit |
---|
290 | (0=0*2+0, 1=0*2+1, 2=1*2+0, 3=1*2+1), |
---|
291 | if upper bit is 1, then program assumes that each row vector in HL |
---|
292 | generates a ray of the cone, |
---|
293 | if lower bit is 1, then program assumes that the span of the row |
---|
294 | vectors of L is the lineality space of the cone, |
---|
295 | if either bit is 0, then program computes the information itself. |
---|
296 | EXAMPLE: example coneViaPoints; shows an example |
---|
297 | " |
---|
298 | { |
---|
299 | |
---|
300 | } |
---|
301 | example |
---|
302 | { |
---|
303 | "EXAMPLE:"; echo = 2; |
---|
304 | // Let's define a cone in R^3 generated by the following half lines: |
---|
305 | intmat HL[5][3]= |
---|
306 | 1,0, 0, |
---|
307 | -1,0, 0, |
---|
308 | 0,1, 1, |
---|
309 | 0,1,-1, |
---|
310 | 0,0, 1; |
---|
311 | cone c=coneViaPoints(HL); |
---|
312 | c; |
---|
313 | kill HL,c; |
---|
314 | // Note that (1,0,0) and (-1,0,0) form a line, hence also possible: |
---|
315 | intmat HL[3][3]= |
---|
316 | 0,1, 1, |
---|
317 | 0,1,-1, |
---|
318 | 0,0, 1; |
---|
319 | intmat L[1][3]= |
---|
320 | 1,0,0; |
---|
321 | cone c=coneViaPoints(HL,L); |
---|
322 | c; |
---|
323 | kill HL,L,c; |
---|
324 | // lineality space is exactly Lin(1,0,0) |
---|
325 | intmat HL[3][3]= |
---|
326 | 0,1, 1, |
---|
327 | 0,1,-1, |
---|
328 | 0,0, 1; |
---|
329 | intmat L[1][3]= |
---|
330 | 1,0,0; |
---|
331 | cone c=coneViaPoints(HL,L,1); |
---|
332 | c; |
---|
333 | kill HL,L,c; |
---|
334 | // and that (0,1,-1), (0,1,1) generate rays |
---|
335 | intmat HL[3][3]= |
---|
336 | 0,1, 1, |
---|
337 | 0,1,-1; |
---|
338 | intmat L[1][3]= |
---|
339 | 1,0,0; |
---|
340 | cone c=coneViaPoints(HL,L,1); |
---|
341 | c; |
---|
342 | kill HL,L,c; |
---|
343 | // and that (0,1,-1), (0,1,1) generate rays |
---|
344 | intmat HL[3][3]= |
---|
345 | 0,1, 1, |
---|
346 | 0,1,-1; |
---|
347 | intmat L[1][3]= |
---|
348 | 1,0,0; |
---|
349 | cone c=coneViaPoints(HL,L,3); |
---|
350 | c; |
---|
351 | } |
---|
352 | |
---|
353 | proc coneViaInequalities() |
---|
354 | "USAGE: coneViaInequalities(IE); intmat IE |
---|
355 | coneViaInequalities(IE,E); intmat IE, intmat E |
---|
356 | coneViaInequalities(IE,E,flags); intmat IE, intmat E, int flags |
---|
357 | RETURN: cone |
---|
358 | PURPOSE: cone consisting of all points x, such that IE*x >= 0 in each component |
---|
359 | and (if stated) E*x = 0; |
---|
360 | inequalities and (if stated) equations will be transformed, getting rid of |
---|
361 | redundancies; |
---|
362 | flags may range between 0,..,3 defining an upper and lower bit |
---|
363 | (0=0*2+0, 1=0*2+1, 2=1*2+0, 3=1*2+1), |
---|
364 | if higher bit is 1, then program assumes each inequality yields a facet, |
---|
365 | if lower bit is 1, then program assumes the kernel of E is the span of the cone, |
---|
366 | if either bit is 0, then program computes the information itself. |
---|
367 | EXAMPLE: example coneViaInequalities; shows an example |
---|
368 | " |
---|
369 | { |
---|
370 | |
---|
371 | } |
---|
372 | example |
---|
373 | { |
---|
374 | "EXAMPLE:"; echo = 2; |
---|
375 | // Let's define a cone in R^3 given by the following inequalities: |
---|
376 | intmat IE[6][3]= |
---|
377 | 1,3,5, |
---|
378 | 1,5,3, |
---|
379 | 0,1,-1, |
---|
380 | 0,1,1, |
---|
381 | 1,0,0, |
---|
382 | -1,0,0; |
---|
383 | cone c=coneViaInequalities(IE); |
---|
384 | c; |
---|
385 | // Note that the last two inequalities yield x1 = 0, hence also possible: |
---|
386 | intmat IE[4][3]= |
---|
387 | 0,1,-1, |
---|
388 | 0,1,1; |
---|
389 | intmat E[1][3]= |
---|
390 | 1,0,0; |
---|
391 | cone c=coneViaInequalities(IE,E); |
---|
392 | c; |
---|
393 | // each inequalities gives rise to a facet |
---|
394 | intmat IE[2][3]= |
---|
395 | 0,1,-1, |
---|
396 | 0,1,1; |
---|
397 | intmat E[1][3]= |
---|
398 | 1,0,0; |
---|
399 | cone c=coneViaInequalities(IE,E,1); |
---|
400 | c; |
---|
401 | // and the kernel of E is the span of the cone |
---|
402 | intmat IE[2][3]= |
---|
403 | 0,1,-1, |
---|
404 | 0,1,1; |
---|
405 | intmat E[1][3]= |
---|
406 | 1,0,0; |
---|
407 | cone c=coneViaInequalities(IE,E,3); |
---|
408 | c; |
---|
409 | } |
---|
410 | |
---|
411 | proc coneLink() |
---|
412 | "USAGE: coneLink(c,w); c cone, w intvec/bigintmat |
---|
413 | RETURN: cone, the link of c around w |
---|
414 | EXAMPLE: example coneLink; shows an example |
---|
415 | " |
---|
416 | { |
---|
417 | |
---|
418 | } |
---|
419 | example |
---|
420 | { |
---|
421 | "EXAMPLE:"; echo = 2; |
---|
422 | intmat M[3][3]= |
---|
423 | 1,0,0, |
---|
424 | 0,1,0, |
---|
425 | 0,0,1; |
---|
426 | cone c=coneViaPoints(M); |
---|
427 | intvec v=1,0,0; |
---|
428 | cone cv=coneLink(c,v); |
---|
429 | rays(cv); |
---|
430 | generatorsOfLinealitySpace(cv); |
---|
431 | intvec w=1,1,1; |
---|
432 | cone cw=coneLink(c,w); |
---|
433 | rays(cw); |
---|
434 | generatorsOfLinealitySpace(cw); |
---|
435 | } |
---|
436 | |
---|
437 | proc containsAsFace() |
---|
438 | "USAGE: containsAsFace(c,d); c cone, d cone |
---|
439 | RETURN: 1, if d is a face of c; 0 otherwise |
---|
440 | EXAMPLE: example containsAsFace; shows an example |
---|
441 | " |
---|
442 | { |
---|
443 | |
---|
444 | } |
---|
445 | example |
---|
446 | { |
---|
447 | "EXAMPLE:"; echo = 2; |
---|
448 | intmat M[2][2]= |
---|
449 | 1,0, |
---|
450 | 0,1; |
---|
451 | cone c=coneViaPoints(M); |
---|
452 | intmat N1[1][2]= |
---|
453 | 1,1; |
---|
454 | cone d1=coneViaPoints(N1); |
---|
455 | containsInSupport(c,d1); |
---|
456 | containsAsFace(c,d1); |
---|
457 | intmat N2[1][2]= |
---|
458 | 0,1; |
---|
459 | cone d2=coneViaPoints(N2); |
---|
460 | containsInSupport(c,d2); |
---|
461 | containsAsFace(c,d2); |
---|
462 | } |
---|
463 | |
---|
464 | proc containsRelatively() |
---|
465 | "USAGE: containsRelatively(c,p); c cone, intvec p |
---|
466 | RETURN: 1 iff the given cone contains the given point in its relative interior; 0 otherwise |
---|
467 | EXAMPLE: example containsRelatively; shows an example |
---|
468 | " |
---|
469 | { |
---|
470 | |
---|
471 | } |
---|
472 | example |
---|
473 | { |
---|
474 | "EXAMPLE:"; echo = 2; |
---|
475 | intmat M[2][2]= |
---|
476 | 1,0, |
---|
477 | 0,1; |
---|
478 | cone c=coneViaPoints(M); |
---|
479 | intvec p1=1,1; |
---|
480 | containsRelatively(c,p1); |
---|
481 | intvec p2=0,1; |
---|
482 | containsRelatively(c,p2); |
---|
483 | } |
---|
484 | |
---|
485 | proc containsInSupport() |
---|
486 | "USAGE: containsInSupport(c,d); c cone, d cone |
---|
487 | containsInSupport(c,p); c cone, p intvec/bigintmat |
---|
488 | RETURN: 1, if d resp. p is contained in c; 0 otherwise |
---|
489 | EXAMPLE: example containsInSupport; shows an example |
---|
490 | " |
---|
491 | { |
---|
492 | |
---|
493 | } |
---|
494 | example |
---|
495 | { |
---|
496 | "EXAMPLE:"; echo = 2; |
---|
497 | intmat M[2][2]= |
---|
498 | 1,0, |
---|
499 | 0,1; |
---|
500 | cone c=coneViaPoints(M); |
---|
501 | containsInSupport(c,c); |
---|
502 | intmat N1[2][2]= |
---|
503 | 1,1, |
---|
504 | 0,1; |
---|
505 | cone d1=coneViaPoints(N1); |
---|
506 | containsInSupport(c,d1); |
---|
507 | intmat N2[2][2]= |
---|
508 | 1,1, |
---|
509 | 1,-1; |
---|
510 | cone d2=coneViaPoints(N2); |
---|
511 | containsInSupport(c,d2); |
---|
512 | intvec p1=0,1; |
---|
513 | containsInSupport(c,p1); |
---|
514 | intvec p2=1,-1; |
---|
515 | containsInSupport(c,p2); |
---|
516 | } |
---|
517 | |
---|
518 | proc containsPositiveVector() |
---|
519 | "USAGE: containsPositiveVector(c); c cone |
---|
520 | RETURN: 1, if c contains a vector with only positive entries in its relative interior |
---|
521 | EXAMPLE: example containsPositiveVector; shows an example |
---|
522 | " |
---|
523 | { |
---|
524 | |
---|
525 | } |
---|
526 | example |
---|
527 | { |
---|
528 | "EXAMPLE:"; echo = 2; |
---|
529 | intmat M1[2][2]= |
---|
530 | 1,1, |
---|
531 | 1,-1; |
---|
532 | cone c1=coneViaPoints(M1); |
---|
533 | containsPositiveVector(c1); |
---|
534 | intmat M2[2][2]= |
---|
535 | 0,1, |
---|
536 | -1,0; |
---|
537 | cone c2=coneViaPoints(M2); |
---|
538 | containsPositiveVector(c2); |
---|
539 | } |
---|
540 | |
---|
541 | proc convexHull() |
---|
542 | "USAGE: convexHull(c1,c2); c1 cone, c2 cone |
---|
543 | convexHull(c1,p1); c1 cone, p1 polytope |
---|
544 | convexHull(p1,c1); p1 cone, c1 polytope |
---|
545 | convexHull(p1,p2); p1 polytope, p2 polytope |
---|
546 | RETURN: cone resp polytope, the convex hull of its two input objects |
---|
547 | EXAMPLE: example convexHull; shows an example |
---|
548 | " |
---|
549 | { |
---|
550 | |
---|
551 | } |
---|
552 | example |
---|
553 | { |
---|
554 | "EXAMPLE:"; echo = 2; |
---|
555 | intmat M1[2][2]= |
---|
556 | 1,0, |
---|
557 | 0,1; |
---|
558 | cone c1=coneViaPoints(M1); |
---|
559 | intmat M2[2][2]= |
---|
560 | 1,1, |
---|
561 | 1,-1; |
---|
562 | cone c2=coneViaPoints(M2); |
---|
563 | intmat M3[2][2]= |
---|
564 | 1,0, |
---|
565 | 0,-1; |
---|
566 | cone c3=coneViaPoints(M3); |
---|
567 | cone c12=convexHull(c1,c2); |
---|
568 | c12; |
---|
569 | print(rays(c12)); |
---|
570 | cone c23=convexHull(c2,c3); |
---|
571 | c23; |
---|
572 | print(rays(c23)); |
---|
573 | cone c13=convexHull(c1,c3); |
---|
574 | c13; |
---|
575 | print(rays(c13)); |
---|
576 | } |
---|
577 | |
---|
578 | proc convexIntersection() |
---|
579 | "USAGE: convexIntersection(c1,c2); c1 cone, c2 cone |
---|
580 | convexIntersection(c1,p1); c1 cone, p1 polytope |
---|
581 | convexIntersection(p1,c1); p1 cone, c1 polytope |
---|
582 | convexIntersection(p1,p2); p1 polytope, p2 polytope |
---|
583 | RETURN: cone resp polytope, the convex hull of its two input objects |
---|
584 | EXAMPLE: example convexIntersection; shows an example |
---|
585 | " |
---|
586 | { |
---|
587 | |
---|
588 | } |
---|
589 | example |
---|
590 | { |
---|
591 | "EXAMPLE:"; echo = 2; |
---|
592 | intmat M1[2][2]= |
---|
593 | 1,0, |
---|
594 | 0,1; |
---|
595 | cone c1=coneViaPoints(M1); |
---|
596 | intmat M2[2][2]= |
---|
597 | 1,1, |
---|
598 | 1,-1; |
---|
599 | cone c2=coneViaPoints(M2); |
---|
600 | intmat M3[2][2]= |
---|
601 | 1,0, |
---|
602 | 0,-1; |
---|
603 | cone c3=coneViaPoints(M3); |
---|
604 | cone c12=convexIntersection(c1,c2); |
---|
605 | c12; |
---|
606 | print(rays(c12)); |
---|
607 | cone c23=convexIntersection(c2,c3); |
---|
608 | c23; |
---|
609 | print(rays(c23)); |
---|
610 | cone c13=convexIntersection(c1,c3); |
---|
611 | c13; |
---|
612 | print(rays(c13)); |
---|
613 | } |
---|
614 | |
---|
615 | proc dimension() |
---|
616 | "USAGE: dimension(c); c cone |
---|
617 | dimension(f); f fan |
---|
618 | dimension(p); p polytope |
---|
619 | RETURN: int, the dimension of the input |
---|
620 | EXAMPLE: example dimension; shows an example |
---|
621 | " |
---|
622 | { |
---|
623 | |
---|
624 | } |
---|
625 | example |
---|
626 | { |
---|
627 | "EXAMPLE:"; echo = 2; |
---|
628 | intmat M1[1][2]= |
---|
629 | 1,0; |
---|
630 | cone c1=coneViaPoints(M1); |
---|
631 | dimension(c1); |
---|
632 | intmat M2[2][2]= |
---|
633 | 1,0, |
---|
634 | 0,1; |
---|
635 | cone c2=coneViaPoints(M2); |
---|
636 | dimension(c2); |
---|
637 | |
---|
638 | fan f = emptyFan(2); |
---|
639 | dimension(f); |
---|
640 | insertCone(f,c1); |
---|
641 | dimension(f); |
---|
642 | insertCone(f,c2); |
---|
643 | dimension(f); |
---|
644 | } |
---|
645 | |
---|
646 | proc dualCone() |
---|
647 | "USAGE: dualCone(c); c cone |
---|
648 | RETURN: cone, the dual of c |
---|
649 | EXAMPLE: example dualCone; shows an example |
---|
650 | " |
---|
651 | { |
---|
652 | |
---|
653 | } |
---|
654 | example |
---|
655 | { |
---|
656 | "EXAMPLE:"; echo = 2; |
---|
657 | intmat M1[2][2]= |
---|
658 | 1,0, |
---|
659 | 0,1; |
---|
660 | cone c1=coneViaPoints(M1); |
---|
661 | cone d1=dualCone(c1); |
---|
662 | d1; |
---|
663 | print(rays(d1)); |
---|
664 | intmat M2[2][2]= |
---|
665 | 1,1, |
---|
666 | 0,1; |
---|
667 | cone c2=coneViaPoints(M2); |
---|
668 | cone d2=dualCone(c2); |
---|
669 | d2; |
---|
670 | print(rays(d2)); |
---|
671 | } |
---|
672 | |
---|
673 | proc equations() |
---|
674 | "USAGE: equations(c); c cone |
---|
675 | equations(p); p polytope |
---|
676 | RETURN: bigintmat, defining equations of c resp p |
---|
677 | NOTE: neither unique nor complete, unless c resp p in canonical form |
---|
678 | EXAMPLE: example equations; shows an example |
---|
679 | " |
---|
680 | { |
---|
681 | |
---|
682 | } |
---|
683 | example |
---|
684 | { |
---|
685 | "EXAMPLE:"; echo = 2; |
---|
686 | intmat M1[2][2]= |
---|
687 | 1,0, |
---|
688 | 0,1; |
---|
689 | cone c1=coneViaPoints(M1); |
---|
690 | bigintmat E1=equations(c1); |
---|
691 | print(E1); |
---|
692 | intmat M2[1][2]= |
---|
693 | 1,0; |
---|
694 | cone c2=coneViaPoints(M2); |
---|
695 | bigintmat E2=equations(c2); |
---|
696 | print(E2); |
---|
697 | } |
---|
698 | |
---|
699 | proc faceContaining() |
---|
700 | "USAGE: faceContaining(c,w); c cone, w intvec/bigintmat |
---|
701 | ASSUME: containsInSupport(c,w)==1 |
---|
702 | RETURN: cone, the face of c containing w in its relative interior |
---|
703 | EXAMPLE: example faceContaining; shows an example |
---|
704 | " |
---|
705 | { |
---|
706 | |
---|
707 | } |
---|
708 | example |
---|
709 | { |
---|
710 | "EXAMPLE:"; echo = 2; |
---|
711 | intmat M[2][2]= |
---|
712 | 1,0, |
---|
713 | 0,1; |
---|
714 | cone c=coneViaPoints(M); |
---|
715 | faceContaining(c,intvec(1,0)); |
---|
716 | faceContaining(c,intvec(0,1)); |
---|
717 | faceContaining(c,intvec(1,1)); |
---|
718 | faceContaining(c,intvec(0,0)); |
---|
719 | } |
---|
720 | |
---|
721 | proc facets() |
---|
722 | "USAGE: facets(c); c cone |
---|
723 | facets(p); p polytope |
---|
724 | RETURN: bigintmat, the facets of c resp p |
---|
725 | EXAMPLE: example facets; shows an example |
---|
726 | " |
---|
727 | { |
---|
728 | |
---|
729 | } |
---|
730 | example |
---|
731 | { |
---|
732 | "EXAMPLE:"; echo = 2; |
---|
733 | intmat M1[2][2]= |
---|
734 | 1,0, |
---|
735 | 0,1; |
---|
736 | cone c1=coneViaPoints(M1); |
---|
737 | bigintmat F1=facets(c1); |
---|
738 | print(F1); |
---|
739 | intmat M2[2][2]= |
---|
740 | 1,1, |
---|
741 | 0,-1; |
---|
742 | cone c2=coneViaPoints(M2); |
---|
743 | bigintmat F2=facets(c2); |
---|
744 | print(F2); |
---|
745 | } |
---|
746 | |
---|
747 | proc generatorsOfLinealitySpace() |
---|
748 | "USAGE: generatorsOfLinealitySpace(c); c cone |
---|
749 | RETURN: bigintmat, generators of the lineality space of c |
---|
750 | EXAMPLE: example generatorsOfLinealitySpace; shows an example |
---|
751 | " |
---|
752 | { |
---|
753 | |
---|
754 | } |
---|
755 | example |
---|
756 | { |
---|
757 | "EXAMPLE:"; echo = 2; |
---|
758 | intmat M[5][3]= |
---|
759 | 1,0,0, |
---|
760 | 0,1,0, |
---|
761 | 0,0,1, |
---|
762 | -1,0,0, |
---|
763 | 0,-1,0; |
---|
764 | cone c=coneViaPoints(M); |
---|
765 | bigintmat L=generatorsOfLinealitySpace(c); |
---|
766 | print(L); |
---|
767 | } |
---|
768 | |
---|
769 | proc generatorsOfSpan() |
---|
770 | "USAGE: generatorsOfSpan(c); c cone |
---|
771 | RETURN: bigintmat, generators of the span of c |
---|
772 | EXAMPLE: example generatorsOfSpan; shows an example |
---|
773 | " |
---|
774 | { |
---|
775 | |
---|
776 | } |
---|
777 | example |
---|
778 | { |
---|
779 | "EXAMPLE:"; echo = 2; |
---|
780 | intmat M[3][5]= |
---|
781 | 1,0,0,0,0, |
---|
782 | 0,1,0,0,0, |
---|
783 | 0,0,1,0,0; |
---|
784 | cone c=coneViaPoints(M); |
---|
785 | bigintmat S=generatorsOfSpan(c); |
---|
786 | print(S); |
---|
787 | } |
---|
788 | |
---|
789 | proc getLinearForms() |
---|
790 | "USAGE: getLinearForms(c); c cone |
---|
791 | getLinearForms(p); p polytope |
---|
792 | RETURN: bigintmat, linear forms previously stored in c resp p |
---|
793 | EXAMPLE: example getLinearForms; shows an example |
---|
794 | " |
---|
795 | { |
---|
796 | |
---|
797 | } |
---|
798 | example |
---|
799 | { |
---|
800 | "EXAMPLE:"; echo = 2; |
---|
801 | intmat M[2][3]= |
---|
802 | -1,0,0, |
---|
803 | 0,-1,0; |
---|
804 | cone c=coneViaPoints(M); |
---|
805 | getLinearForms(c); |
---|
806 | intvec v=1,1,1; |
---|
807 | setLinearForms(c,v); |
---|
808 | getLinearForms(c); |
---|
809 | } |
---|
810 | |
---|
811 | proc getMultiplicity() |
---|
812 | "USAGE: getMultiplicity(c); c cone |
---|
813 | getMultiplicity(p); p polytope |
---|
814 | RETURN: bigint, 1 or a multiplicity previously stored in c resp p |
---|
815 | EXAMPLE: example getMultiplicity; shows an example |
---|
816 | " |
---|
817 | { |
---|
818 | |
---|
819 | } |
---|
820 | example |
---|
821 | { |
---|
822 | "EXAMPLE:"; echo = 2; |
---|
823 | intmat M[2][3]= |
---|
824 | -1,0,0, |
---|
825 | 0,-1,0; |
---|
826 | cone c=coneViaPoints(M); |
---|
827 | getMultiplicity(c); |
---|
828 | setMultiplicity(c,3); |
---|
829 | getMultiplicity(c); |
---|
830 | } |
---|
831 | |
---|
832 | proc inequalities() |
---|
833 | "USAGE: inequalities(c); c cone |
---|
834 | inequalities(p); p polytope |
---|
835 | RETURN: bigintmat, the inequalities of c resp p |
---|
836 | NOTE: neither unique nor irredundant, unless c resp p in canonical form |
---|
837 | EXAMPLE: example inequalities; shows an example |
---|
838 | " |
---|
839 | { |
---|
840 | |
---|
841 | } |
---|
842 | example |
---|
843 | { |
---|
844 | "EXAMPLE:"; echo = 2; |
---|
845 | intmat M1[2][2]= |
---|
846 | 1,0, |
---|
847 | 0,1; |
---|
848 | cone c1=coneViaPoints(M1); |
---|
849 | bigintmat I1=inequalities(c1); |
---|
850 | print(I1); |
---|
851 | intmat M2[2][2]= |
---|
852 | 1,1, |
---|
853 | 0,-1; |
---|
854 | cone c2=coneViaPoints(M2); |
---|
855 | bigintmat I2=inequalities(c2); |
---|
856 | print(I2); |
---|
857 | } |
---|
858 | |
---|
859 | proc isFullSpace() |
---|
860 | "USAGE: isFullSpace(c); c cone |
---|
861 | RETURN: 1, if c is the entire ambient space; 0 otherwise |
---|
862 | EXAMPLE: example isFullSpace; shows an example |
---|
863 | " |
---|
864 | { |
---|
865 | |
---|
866 | } |
---|
867 | example |
---|
868 | { |
---|
869 | "EXAMPLE:"; echo = 2; |
---|
870 | cone c1; |
---|
871 | isFullSpace(c1); |
---|
872 | intmat M2[2][2]= |
---|
873 | 1,0, |
---|
874 | 0,1; |
---|
875 | cone c2=coneViaPoints(M2); |
---|
876 | isFullSpace(c2); |
---|
877 | intmat M3[4][2]= |
---|
878 | 1,0, |
---|
879 | 0,1, |
---|
880 | -1,0, |
---|
881 | 0,-1; |
---|
882 | cone c3=coneViaPoints(M3); |
---|
883 | isFullSpace(c3); |
---|
884 | } |
---|
885 | |
---|
886 | proc isOrigin() |
---|
887 | "USAGE: isOrigin(c); c cone |
---|
888 | RETURN: 1, if c is the origin; 0 otherwise |
---|
889 | EXAMPLE: example isOrigin; shows an example |
---|
890 | " |
---|
891 | { |
---|
892 | |
---|
893 | } |
---|
894 | example |
---|
895 | { |
---|
896 | "EXAMPLE:"; echo = 2; |
---|
897 | cone c1; |
---|
898 | isOrigin(c1); |
---|
899 | intmat M2[2][2]= |
---|
900 | 1,0, |
---|
901 | 0,1; |
---|
902 | cone c2=coneViaPoints(M2); |
---|
903 | isOrigin(c2); |
---|
904 | intmat M3[4][2]= |
---|
905 | 1,0, |
---|
906 | 0,1, |
---|
907 | -1,0, |
---|
908 | 0,-1; |
---|
909 | cone c3=coneViaPoints(M3); |
---|
910 | isOrigin(c3); |
---|
911 | } |
---|
912 | |
---|
913 | proc isSimplicial() |
---|
914 | "USAGE: isSimplicial(c); c cone |
---|
915 | isSimplicial(f); f fan |
---|
916 | RETURN: 1, if c resp f is simplicial; 0 otherwise |
---|
917 | EXAMPLE: example isSimplicial; shows an example |
---|
918 | " |
---|
919 | { |
---|
920 | |
---|
921 | } |
---|
922 | example |
---|
923 | { |
---|
924 | "EXAMPLE:"; echo = 2; |
---|
925 | intmat M1[3][3]= |
---|
926 | 1,0,0, |
---|
927 | 0,1,0, |
---|
928 | 0,0,1; |
---|
929 | cone c1=coneViaPoints(M1); |
---|
930 | isSimplicial(c1); |
---|
931 | intmat M2[4][3]= |
---|
932 | 1,0,0, |
---|
933 | 0,1,0, |
---|
934 | 0,0,1, |
---|
935 | 1,1,-1; |
---|
936 | cone c2=coneViaPoints(M2); |
---|
937 | isSimplicial(c2); |
---|
938 | /***********************/ |
---|
939 | fan f=emptyFan(3); |
---|
940 | isSimplicial(f); |
---|
941 | intmat N1[3][3]= |
---|
942 | 1,0,0, |
---|
943 | 0,1,0, |
---|
944 | 0,0,1; |
---|
945 | cone d1=coneViaPoints(N1); |
---|
946 | insertCone(f,d1); |
---|
947 | isSimplicial(f); |
---|
948 | intmat N2[4][3]= |
---|
949 | 1,0,0, |
---|
950 | 0,1,0, |
---|
951 | 1,0,-1, |
---|
952 | 0,1,-1; |
---|
953 | cone d2=coneViaPoints(N2); |
---|
954 | insertCone(f,d2); |
---|
955 | isSimplicial(f); |
---|
956 | } |
---|
957 | |
---|
958 | proc linealityDimension() |
---|
959 | "USAGE: linealityDimension(c); c cone |
---|
960 | linealityDimension(f); f fan |
---|
961 | RETURN: int, the dimension of the lineality space of c resp f |
---|
962 | EXAMPLE: example linealityDimension; shows an example |
---|
963 | " |
---|
964 | { |
---|
965 | |
---|
966 | } |
---|
967 | example |
---|
968 | { |
---|
969 | "EXAMPLE:"; echo = 2; |
---|
970 | intmat M1[3][3]= |
---|
971 | 1,0,0, |
---|
972 | 0,1,0, |
---|
973 | 0,0,1; |
---|
974 | cone c1=coneViaPoints(M1); |
---|
975 | linealityDimension(c1); |
---|
976 | intmat M2[4][3]= |
---|
977 | 1,0,0, |
---|
978 | 0,1,0, |
---|
979 | 0,0,1, |
---|
980 | -1,0,0; |
---|
981 | cone c2=coneViaPoints(M2); |
---|
982 | linealityDimension(c2); |
---|
983 | } |
---|
984 | |
---|
985 | proc linealitySpace() |
---|
986 | "USAGE: linealitySpace(c); c cone |
---|
987 | RETURN: cone, the lineality space of c |
---|
988 | EXAMPLE: example linealitySpace; shows an example |
---|
989 | " |
---|
990 | { |
---|
991 | |
---|
992 | } |
---|
993 | example |
---|
994 | { |
---|
995 | "EXAMPLE:"; echo = 2; |
---|
996 | intmat M1[3][3]= |
---|
997 | 1,0,0, |
---|
998 | 0,1,0, |
---|
999 | 0,0,1; |
---|
1000 | cone c1=coneViaPoints(M1); |
---|
1001 | cone l1=linealitySpace(c1); |
---|
1002 | l1; |
---|
1003 | intmat M2[4][3]= |
---|
1004 | 1,0,0, |
---|
1005 | 0,1,0, |
---|
1006 | 0,0,1, |
---|
1007 | -1,0,0; |
---|
1008 | cone c2=coneViaPoints(M2); |
---|
1009 | cone l2=linealitySpace(c2); |
---|
1010 | l2; |
---|
1011 | } |
---|
1012 | |
---|
1013 | proc negatedCone() |
---|
1014 | "USAGE: negatedCone(c); c cone |
---|
1015 | RETURN: cone, the negative of c |
---|
1016 | EXAMPLE: example negatedCone; shows an example |
---|
1017 | " |
---|
1018 | { |
---|
1019 | |
---|
1020 | } |
---|
1021 | example |
---|
1022 | { |
---|
1023 | "EXAMPLE:"; echo = 2; |
---|
1024 | intmat M[2][2]= |
---|
1025 | 1,0, |
---|
1026 | 0,1; |
---|
1027 | cone c=coneViaPoints(M); |
---|
1028 | cone cn=negatedCone(c); |
---|
1029 | print(rays(cn)); |
---|
1030 | } |
---|
1031 | |
---|
1032 | proc quotientLatticeBasis() |
---|
1033 | "USAGE: quotientLatticeBasis(c); c cone |
---|
1034 | RETURN: bigintmat, a basis of Z^n intersected with the span of c modulo Z^n intersected with the lineality space of c |
---|
1035 | EXAMPLE: example quotientLatticeBasis; shows an example |
---|
1036 | " |
---|
1037 | { |
---|
1038 | |
---|
1039 | } |
---|
1040 | example |
---|
1041 | { |
---|
1042 | "EXAMPLE:"; echo = 2; |
---|
1043 | intmat M[3][2]= |
---|
1044 | 1,0, |
---|
1045 | 0,1, |
---|
1046 | -1,0; |
---|
1047 | cone c=coneViaPoints(M); |
---|
1048 | bigintmat Q=quotientLatticeBasis(c); |
---|
1049 | print(Q); |
---|
1050 | } |
---|
1051 | |
---|
1052 | proc randomPoint() |
---|
1053 | "USAGE: randomPoint(c); c cone |
---|
1054 | randomPoint(c,b); c cone, b int |
---|
1055 | RETURN: bigintmat, a random point in the relative interior of c |
---|
1056 | NOTE: returns a weighted sum over all its rays |
---|
1057 | if b is given and b>0, only chooses weights between 1 and b |
---|
1058 | EXAMPLE: example randomPoint; shows an example |
---|
1059 | " |
---|
1060 | { |
---|
1061 | |
---|
1062 | } |
---|
1063 | example |
---|
1064 | { |
---|
1065 | "EXAMPLE:"; echo = 2; |
---|
1066 | intmat M[2][2]= |
---|
1067 | 1,0, |
---|
1068 | 0,1; |
---|
1069 | cone c=coneViaPoints(M); |
---|
1070 | bigintmat Q=randomPoint(c); |
---|
1071 | print(Q); |
---|
1072 | bigintmat P=randomPoint(c,5); |
---|
1073 | print(P); |
---|
1074 | } |
---|
1075 | |
---|
1076 | proc rays() |
---|
1077 | "USAGE: rays(c); c cone |
---|
1078 | RETURN: bigintmat, generators of the rays of c, orthogonal to its lineality space |
---|
1079 | EXAMPLE: example rays; shows an example |
---|
1080 | " |
---|
1081 | { |
---|
1082 | |
---|
1083 | } |
---|
1084 | example |
---|
1085 | { |
---|
1086 | "EXAMPLE:"; echo = 2; |
---|
1087 | intmat M1[2][2]= |
---|
1088 | 1,0, |
---|
1089 | 0,1; |
---|
1090 | cone c1=coneViaPoints(M1); |
---|
1091 | bigintmat R1=rays(c1); |
---|
1092 | print(R1); |
---|
1093 | intmat M2[3][2]= |
---|
1094 | 1,0, |
---|
1095 | 0,1, |
---|
1096 | -1,0; |
---|
1097 | cone c2=coneViaPoints(M2); |
---|
1098 | bigintmat R2=rays(c2); |
---|
1099 | print(R2); |
---|
1100 | } |
---|
1101 | |
---|
1102 | proc relativeInteriorPoint() |
---|
1103 | "USAGE: relativeInteriorPoint(c); c cone |
---|
1104 | RETURN: bigintmat, a point in the relative interior of c |
---|
1105 | NOTE: not unique, unless c is in its canonical form |
---|
1106 | EXAMPLE: example relativeInteriorPoint; shows an example |
---|
1107 | " |
---|
1108 | { |
---|
1109 | |
---|
1110 | } |
---|
1111 | example |
---|
1112 | { |
---|
1113 | "EXAMPLE:"; echo = 2; |
---|
1114 | intmat M1[2][2]= |
---|
1115 | 1,0, |
---|
1116 | 0,1; |
---|
1117 | cone c1=coneViaPoints(M1); |
---|
1118 | relativeInteriorPoint(c1); |
---|
1119 | intmat M2[2][2]= |
---|
1120 | 1,0, |
---|
1121 | 1,1; |
---|
1122 | cone c2=coneViaPoints(M2); |
---|
1123 | relativeInteriorPoint(c2); |
---|
1124 | } |
---|
1125 | |
---|
1126 | proc semigroupGenerator() |
---|
1127 | "USAGE: semigroupGenerator(c); c cone |
---|
1128 | RETURN: bigintmat, the generator of Z^n intersected with c modulo Z^n intersected with the lineality space of c |
---|
1129 | ASSUME: dimension(c) == linealityDimension(c)+1 |
---|
1130 | EXAMPLE: example semigroupGenerator; shows an example |
---|
1131 | " |
---|
1132 | { |
---|
1133 | |
---|
1134 | } |
---|
1135 | example |
---|
1136 | { |
---|
1137 | "EXAMPLE:"; echo = 2; |
---|
1138 | intmat M[3][2]= |
---|
1139 | 1,0, |
---|
1140 | 0,1, |
---|
1141 | -1,0; |
---|
1142 | cone c=coneViaPoints(M); |
---|
1143 | semigroupGenerator(c); |
---|
1144 | } |
---|
1145 | |
---|
1146 | proc setLinearForms() |
---|
1147 | "USAGE: setLinearForms(c); c cone |
---|
1148 | setLinearForms(p); p polytope |
---|
1149 | RETURN: none, stores linear forms in c resp p |
---|
1150 | EXAMPLE: example setLinearForms; shows an example |
---|
1151 | " |
---|
1152 | { |
---|
1153 | |
---|
1154 | } |
---|
1155 | example |
---|
1156 | { |
---|
1157 | "EXAMPLE:"; echo = 2; |
---|
1158 | intmat M[2][3]= |
---|
1159 | -1,0,0, |
---|
1160 | 0,-1,0; |
---|
1161 | cone c=coneViaPoints(M); |
---|
1162 | getLinearForms(c); |
---|
1163 | intvec v=1,1,1; |
---|
1164 | setLinearForms(c,v); |
---|
1165 | getLinearForms(c); |
---|
1166 | } |
---|
1167 | |
---|
1168 | proc setMultiplicity() |
---|
1169 | "USAGE: setMultiplicity(c); c cone |
---|
1170 | setMultiplicity(p); p polytope |
---|
1171 | RETURN: none, stores a multiplicity in c resp p |
---|
1172 | EXAMPLE: example setMultiplicity; shows an example |
---|
1173 | " |
---|
1174 | { |
---|
1175 | |
---|
1176 | } |
---|
1177 | example |
---|
1178 | { |
---|
1179 | "EXAMPLE:"; echo = 2; |
---|
1180 | intmat M[2][3]= |
---|
1181 | -1,0,0, |
---|
1182 | 0,-1,0; |
---|
1183 | cone c=coneViaPoints(M); |
---|
1184 | getMultiplicity(c); |
---|
1185 | setMultiplicity(c,3); |
---|
1186 | getMultiplicity(c); |
---|
1187 | } |
---|
1188 | |
---|
1189 | proc span() |
---|
1190 | "USAGE: span(c); c cone |
---|
1191 | RETURN: bigintmat, unique irredundant equations of c |
---|
1192 | NOTE: the name 'span' was chosen to be in line with polymake's nomenclature |
---|
1193 | EXAMPLE: example span; shows an example |
---|
1194 | " |
---|
1195 | { |
---|
1196 | |
---|
1197 | } |
---|
1198 | example |
---|
1199 | { |
---|
1200 | "EXAMPLE:"; echo = 2; |
---|
1201 | intmat M[3][5]= |
---|
1202 | 1,0,0,0,0, |
---|
1203 | 0,1,0,0,0, |
---|
1204 | 0,0,1,0,0; |
---|
1205 | cone c=coneViaPoints(M); |
---|
1206 | bigintmat Eq=span(c); |
---|
1207 | print(Eq); |
---|
1208 | } |
---|
1209 | |
---|
1210 | |
---|
1211 | proc uniquePoint() |
---|
1212 | "USAGE: uniquePoint(c); c cone |
---|
1213 | RETURN: bigintmat, a unique point in c stable under reflections at coordinate hyperplanes |
---|
1214 | EXAMPLE: example uniquePoint; shows an example |
---|
1215 | " |
---|
1216 | { |
---|
1217 | |
---|
1218 | } |
---|
1219 | example |
---|
1220 | { |
---|
1221 | "EXAMPLE:"; echo = 2; |
---|
1222 | intmat M1[2][2]= |
---|
1223 | 1,0, |
---|
1224 | 0,1; |
---|
1225 | cone c1=coneViaPoints(M1); |
---|
1226 | uniquePoint(c1); |
---|
1227 | intmat M2[2][2]= |
---|
1228 | -1,0, |
---|
1229 | 0,1; |
---|
1230 | cone c2=coneViaPoints(M2); |
---|
1231 | uniquePoint(c2); |
---|
1232 | } |
---|
1233 | |
---|
1234 | |
---|
1235 | |
---|
1236 | ///// |
---|
1237 | // fan related functions |
---|
1238 | ///// |
---|
1239 | |
---|
1240 | proc containsInCollection() |
---|
1241 | "USAGE: containsInCollection(f,c); f fan, c cone |
---|
1242 | RETURN: 1, if f contains c; 0 otherwise |
---|
1243 | EXAMPLE: example containsInCollection; shows an example |
---|
1244 | " |
---|
1245 | { |
---|
1246 | |
---|
1247 | } |
---|
1248 | example |
---|
1249 | { |
---|
1250 | "EXAMPLE:"; echo = 2; |
---|
1251 | fan f=emptyFan(2); |
---|
1252 | intmat M[2][2]= |
---|
1253 | 1,0, |
---|
1254 | 0,1; |
---|
1255 | cone c=coneViaPoints(M); |
---|
1256 | containsInCollection(f,c); |
---|
1257 | insertCone(f,c); |
---|
1258 | containsInCollection(f,c); |
---|
1259 | } |
---|
1260 | |
---|
1261 | proc emptyFan() |
---|
1262 | "USAGE: emptyFan(n); n int |
---|
1263 | RETURN: fan, an empty fan in ambient dimension n |
---|
1264 | EXAMPLE: example emptyFan; shows an example |
---|
1265 | " |
---|
1266 | { |
---|
1267 | |
---|
1268 | } |
---|
1269 | example |
---|
1270 | { |
---|
1271 | "EXAMPLE:"; echo = 2; |
---|
1272 | fan f=emptyFan(2); |
---|
1273 | f; |
---|
1274 | } |
---|
1275 | |
---|
1276 | proc fanViaCones() |
---|
1277 | "USAGE: fanViaCones(L); L list |
---|
1278 | fanViaCones(c1[,...,ck]); c1,...,ck cones |
---|
1279 | RETURN: fan, creates a fan generated by the cones in L resp c1,...,ck |
---|
1280 | EXAMPLE: example fanViaCones; shows an example |
---|
1281 | " |
---|
1282 | { |
---|
1283 | |
---|
1284 | } |
---|
1285 | example |
---|
1286 | { |
---|
1287 | "EXAMPLE:"; echo = 2; |
---|
1288 | intmat M[2][2]=1,0,0,1; |
---|
1289 | cone c=coneViaPoints(M); |
---|
1290 | intmat N[2][2]=1,0,0,-1; |
---|
1291 | cone d=coneViaPoints(N); |
---|
1292 | fan f=fanViaCones(c,d); |
---|
1293 | f; |
---|
1294 | list L=c,d; |
---|
1295 | fan g=fanViaCones(L); |
---|
1296 | g; |
---|
1297 | } |
---|
1298 | |
---|
1299 | proc fullFan() |
---|
1300 | "USAGE: fullFan(n); n int |
---|
1301 | RETURN: fan, an full fan in ambient dimension n |
---|
1302 | EXAMPLE: example fullFan; shows an example |
---|
1303 | " |
---|
1304 | { |
---|
1305 | |
---|
1306 | } |
---|
1307 | example |
---|
1308 | { |
---|
1309 | "EXAMPLE:"; echo = 2; |
---|
1310 | fan f=fullFan(2); |
---|
1311 | f; |
---|
1312 | } |
---|
1313 | |
---|
1314 | proc fVector() |
---|
1315 | "USAGE: fVector(f); f fan |
---|
1316 | RETURN: bigintmat, the f-Vector of f |
---|
1317 | EXAMPLE: example fVector; shows an example |
---|
1318 | " |
---|
1319 | { |
---|
1320 | |
---|
1321 | } |
---|
1322 | example |
---|
1323 | { |
---|
1324 | "EXAMPLE:"; echo = 2; |
---|
1325 | fan f=emptyFan(2); |
---|
1326 | fVector(f); |
---|
1327 | intmat M[2][2]=1,0,0,1; |
---|
1328 | cone c=coneViaPoints(M); |
---|
1329 | insertCone(f,c); |
---|
1330 | fVector(f); |
---|
1331 | } |
---|
1332 | |
---|
1333 | proc getCone() |
---|
1334 | "USAGE: getCone(f,d,i[,m]); f fan, d int, i int, m int |
---|
1335 | ASSUME: d is between 0 and ambientDimension(f) |
---|
1336 | i is between 1 and numberOfConesOfDimension(f,d,o,m) |
---|
1337 | RETURN: cone, returns in the fan f of all cones in dimension d the i-th cone |
---|
1338 | if m!=0, it will enumerate over maximal cones only |
---|
1339 | EXAMPLE: example getCone; shows an example |
---|
1340 | " |
---|
1341 | { |
---|
1342 | |
---|
1343 | } |
---|
1344 | example |
---|
1345 | { |
---|
1346 | "EXAMPLE:"; echo = 2; |
---|
1347 | intmat M[3][3]= |
---|
1348 | 1,0,0, |
---|
1349 | 0,1,0, |
---|
1350 | 0,0,1; |
---|
1351 | cone c=coneViaPoints(M); |
---|
1352 | fan f=emptyFan(3); |
---|
1353 | insertCone(f,c); |
---|
1354 | getCone(f,2,1,0); |
---|
1355 | getCone(f,2,2,0); |
---|
1356 | } |
---|
1357 | |
---|
1358 | proc insertCone() |
---|
1359 | "USAGE: insertCone(f,c[,b]); f fan, c cone, b int |
---|
1360 | ASSUME: isCompatible(f,c)=1 |
---|
1361 | RETURN: none, inserts the cone c into f |
---|
1362 | if b=0, then skips check whether f and c are compatible |
---|
1363 | EXAMPLE: example insertCone; shows an example |
---|
1364 | " |
---|
1365 | { |
---|
1366 | |
---|
1367 | } |
---|
1368 | example |
---|
1369 | { |
---|
1370 | "EXAMPLE:"; echo = 2; |
---|
1371 | fan f=emptyFan(3); |
---|
1372 | f; |
---|
1373 | intmat M[3][3]= |
---|
1374 | 1,0,0, |
---|
1375 | 0,1,0, |
---|
1376 | 0,0,1; |
---|
1377 | cone c=coneViaPoints(M); |
---|
1378 | insertCone(f,c); |
---|
1379 | f; |
---|
1380 | } |
---|
1381 | |
---|
1382 | proc isCompatible() |
---|
1383 | "USAGE: isCompatible(f,c); f fan, c cone |
---|
1384 | RETURN: 1 if f and c live in the same ambient space and |
---|
1385 | if the intersection of c with any cone of f is a face of each; |
---|
1386 | 0 otherwise |
---|
1387 | EXAMPLE: example isCompatible; shows an example |
---|
1388 | " |
---|
1389 | { |
---|
1390 | |
---|
1391 | } |
---|
1392 | example |
---|
1393 | { |
---|
1394 | "EXAMPLE:"; echo = 2; |
---|
1395 | fan f=emptyFan(3); |
---|
1396 | intmat M1[3][3]= |
---|
1397 | 1,0,0, |
---|
1398 | 0,1,0, |
---|
1399 | 0,0,1; |
---|
1400 | cone c1=coneViaPoints(M1); |
---|
1401 | isCompatible(f,c1); |
---|
1402 | insertCone(f,c1); |
---|
1403 | intmat M2[3][3]= |
---|
1404 | 1,1,1, |
---|
1405 | 1,0,0, |
---|
1406 | 0,1,0; |
---|
1407 | cone c2=coneViaPoints(M2); |
---|
1408 | isCompatible(f,c2); |
---|
1409 | intmat M3[3][3]= |
---|
1410 | 1,0,0, |
---|
1411 | 0,1,0, |
---|
1412 | 0,0,-1; |
---|
1413 | cone c3=coneViaPoints(M3); |
---|
1414 | isCompatible(f,c3); |
---|
1415 | } |
---|
1416 | |
---|
1417 | proc isPure() |
---|
1418 | "USAGE: isPure(f); f fan |
---|
1419 | RETURN: 1 if all maximal cones of f are of the same dimension |
---|
1420 | 0 otherwise |
---|
1421 | EXAMPLE: example isPure; shows an example |
---|
1422 | " |
---|
1423 | { |
---|
1424 | |
---|
1425 | } |
---|
1426 | example |
---|
1427 | { |
---|
1428 | "EXAMPLE:"; echo = 2; |
---|
1429 | fan f=fullFan(2); |
---|
1430 | isPure(f); |
---|
1431 | fan g=emptyFan(2); |
---|
1432 | intmat M1[2][2]= |
---|
1433 | 1,0, |
---|
1434 | 0,1; |
---|
1435 | cone c1=coneViaPoints(M1); |
---|
1436 | insertCone(g,c1); |
---|
1437 | isPure(g); |
---|
1438 | intmat M2[1][2]= |
---|
1439 | 0,-1; |
---|
1440 | cone c2=coneViaPoints(M2); |
---|
1441 | insertCone(g,c2); |
---|
1442 | isPure(g,c2); |
---|
1443 | } |
---|
1444 | |
---|
1445 | proc nmaxcones() |
---|
1446 | "USAGE: nmaxcones(f); f fan |
---|
1447 | RETURN: int, the number of maximal cones in f |
---|
1448 | EXAMPLE: example nmaxcones; shows an example |
---|
1449 | " |
---|
1450 | { |
---|
1451 | |
---|
1452 | } |
---|
1453 | example |
---|
1454 | { |
---|
1455 | fan f=emptyFan(3); |
---|
1456 | nmaxcones(f); |
---|
1457 | intmat M1[3][3]= |
---|
1458 | 1,0,0, |
---|
1459 | 0,1,0, |
---|
1460 | 0,0,1; |
---|
1461 | cone c1=coneViaPoints(M1); |
---|
1462 | insertCone(f,c1); |
---|
1463 | nmaxcones(f); |
---|
1464 | intmat M2[2][3]= |
---|
1465 | 1,0,0, |
---|
1466 | 0,-1,0; |
---|
1467 | cone c2=coneViaPoints(M2); |
---|
1468 | insertCone(f,c2); |
---|
1469 | nmaxcones(f); |
---|
1470 | } |
---|
1471 | |
---|
1472 | proc ncones() |
---|
1473 | "USAGE: ncones(f); f fan |
---|
1474 | RETURN: int, the number of cones in f |
---|
1475 | EXAMPLE: example ncones; shows an example |
---|
1476 | " |
---|
1477 | { |
---|
1478 | |
---|
1479 | } |
---|
1480 | example |
---|
1481 | { |
---|
1482 | fan f=emptyFan(3); |
---|
1483 | ncones(f); |
---|
1484 | intmat M1[3][3]= |
---|
1485 | 1,0,0, |
---|
1486 | 0,1,0, |
---|
1487 | 0,0,1; |
---|
1488 | cone c1=coneViaPoints(M1); |
---|
1489 | insertCone(f,c1); |
---|
1490 | ncones(f); |
---|
1491 | intmat M2[2][3]= |
---|
1492 | 1,0,0, |
---|
1493 | 0,-1,0; |
---|
1494 | cone c2=coneViaPoints(M2); |
---|
1495 | insertCone(f,c2); |
---|
1496 | ncones(f); |
---|
1497 | } |
---|
1498 | |
---|
1499 | proc numberOfConesOfDimension() |
---|
1500 | "USAGE: numberOfConesOfDimension(f,d[,m]); f fan, d int, m int |
---|
1501 | ASSUME: d is between 0 and ambientDimension(f) |
---|
1502 | RETURN: cone, returns in the fan f the number of cones in dimension d |
---|
1503 | if m!=0, it will only count maximal cones |
---|
1504 | EXAMPLE: example numberOfConesOfDimension; shows an example |
---|
1505 | " |
---|
1506 | { |
---|
1507 | |
---|
1508 | } |
---|
1509 | example |
---|
1510 | { |
---|
1511 | "EXAMPLE:"; echo = 2; |
---|
1512 | fan f=emptyFan(3); |
---|
1513 | ncones(f); |
---|
1514 | intmat M[3][3]= |
---|
1515 | 1,0,0, |
---|
1516 | 0,1,0, |
---|
1517 | 0,0,1; |
---|
1518 | cone c=coneViaPoints(M); |
---|
1519 | insertCone(f,c); |
---|
1520 | numberOfConesOfDimension(f,0,0); |
---|
1521 | numberOfConesOfDimension(f,0,1); |
---|
1522 | numberOfConesOfDimension(f,1,0); |
---|
1523 | numberOfConesOfDimension(f,0,1); |
---|
1524 | numberOfConesOfDimension(f,2,0); |
---|
1525 | numberOfConesOfDimension(f,2,1); |
---|
1526 | numberOfConesOfDimension(f,3,0); |
---|
1527 | numberOfConesOfDimension(f,3,1); |
---|
1528 | } |
---|
1529 | |
---|
1530 | proc removeCone() |
---|
1531 | "USAGE: removeCone(f,c[,b]); f fan, c cone, b int |
---|
1532 | ASSUME: containsInCollection(f,c)=1 |
---|
1533 | RETURN: none, removes the cone c from f |
---|
1534 | if b=0, skips the check whether c is contained in f |
---|
1535 | EXAMPLE: example removeCone; shows an example |
---|
1536 | " |
---|
1537 | { |
---|
1538 | |
---|
1539 | } |
---|
1540 | example |
---|
1541 | { |
---|
1542 | "EXAMPLE:"; echo = 2; |
---|
1543 | intmat M[2][2]=1,0,0,1; |
---|
1544 | intmat N[2][2]=1,0,1,-1; |
---|
1545 | cone c=coneViaPoints(M); |
---|
1546 | cone d=coneViaPoints(N); |
---|
1547 | fan f=emptyFan(2); |
---|
1548 | insertCone(f,c); |
---|
1549 | insertCone(f,d); |
---|
1550 | f; |
---|
1551 | removeCone(f,c); |
---|
1552 | f; |
---|
1553 | } |
---|
1554 | |
---|
1555 | |
---|
1556 | |
---|
1557 | ///// |
---|
1558 | // polytope related functions |
---|
1559 | ///// |
---|
1560 | |
---|
1561 | proc dualPolytope() |
---|
1562 | "USAGE: dualPolytope(p); p polytope |
---|
1563 | RETURN: polytope, the dual of p |
---|
1564 | EXAMPLE: example dualPolytope; shows an example |
---|
1565 | " |
---|
1566 | { |
---|
1567 | |
---|
1568 | } |
---|
1569 | example |
---|
1570 | { |
---|
1571 | "EXAMPLE:"; echo = 2; |
---|
1572 | intmat M[4][2]= |
---|
1573 | 0,0, |
---|
1574 | 1,0, |
---|
1575 | 0,1, |
---|
1576 | 1,1; |
---|
1577 | polytope p=polytopeViaPoints(M); |
---|
1578 | dualPolytope(p); |
---|
1579 | } |
---|
1580 | |
---|
1581 | |
---|
1582 | proc newtonPolytope() |
---|
1583 | "USAGE: newtonPolytope(f); f poly |
---|
1584 | RETURN: polytope, the convex hull of all exponent vectors of f |
---|
1585 | EXAMPLE: example newtonPolytope; shows an example |
---|
1586 | " |
---|
1587 | { |
---|
1588 | |
---|
1589 | } |
---|
1590 | example |
---|
1591 | { |
---|
1592 | "EXAMPLE:"; echo = 2; |
---|
1593 | ring r; |
---|
1594 | poly f=x+y+z; |
---|
1595 | polytope p=newtonPolytope(f); |
---|
1596 | p; |
---|
1597 | } |
---|
1598 | |
---|
1599 | proc polytopeViaPoints() |
---|
1600 | "USAGE: polytopeViaPoints(V [, flags]); intmat V, int flags |
---|
1601 | RETURN: polytope which is the intersection of the cone generated by the row vectors |
---|
1602 | of V with the hyperplane, in which the first coordinate equals 1; |
---|
1603 | flags may be 0 or 1,@* |
---|
1604 | if flags is 1, then program assumes that each row vector of M generates a ray in the cone, |
---|
1605 | if flags is 0, then program computes that information itself |
---|
1606 | EXAMPLE: example polytopeViaPoints; shows an example |
---|
1607 | " |
---|
1608 | { |
---|
1609 | |
---|
1610 | } |
---|
1611 | example |
---|
1612 | { |
---|
1613 | "EXAMPLE:"; echo = 2; |
---|
1614 | // This is a polytope in R^2 generated by (0,0), (1,0), (0,1), (0,0); |
---|
1615 | intmat V[4][3]= |
---|
1616 | 1,0,0, |
---|
1617 | 1,1,0, |
---|
1618 | 1,0,1, |
---|
1619 | 1,1,1; |
---|
1620 | polytope p1=polytopeViaPoints(V); |
---|
1621 | p1; |
---|
1622 | // This is a polytope in R^2 generated by (1/2,2/3), (3/4,4/5), (5/6,6/7): |
---|
1623 | intmat V[3][3]= |
---|
1624 | 6,3,4, |
---|
1625 | 20,15,16, |
---|
1626 | 42,35,36; |
---|
1627 | polytope p2=polytopeViaPoints(V); |
---|
1628 | p2; |
---|
1629 | // This polytope is the positive orthant in R^2: |
---|
1630 | // (0,1,0) and (0,0,1) imply that the polytope is unbounded in that direction |
---|
1631 | intmat V[3][3]= |
---|
1632 | 1,0,0, |
---|
1633 | 0,1,0, |
---|
1634 | 0,0,1; |
---|
1635 | polytope p3=polytopeViaPoints(V); |
---|
1636 | p3; |
---|
1637 | } |
---|
1638 | |
---|
1639 | proc polytopeViaInequalities() |
---|
1640 | "USAGE: polytopeViaInequalities(EV [, E [, flags]]); intmat EV,E, int flags |
---|
1641 | RETURN: polytope consisting of all points x, such that IE*x >= 0 in each component |
---|
1642 | and (if stated) E*x = 0; |
---|
1643 | flags may range between 0,..,3 defining an upper and lower bit |
---|
1644 | (0=0*2+0, 1=0*2+1, 2=1*2+0, 3=1*2+1), |
---|
1645 | if higher bit is 1, then program assumes each inequality yields a facet, |
---|
1646 | if lower bit is 1, then program assumes the kernel of E is the span of the cone, |
---|
1647 | if either bit is 0, then program computes the information itself. |
---|
1648 | EXAMPLE: example polytopeViaPoints; shows an example |
---|
1649 | " |
---|
1650 | { |
---|
1651 | |
---|
1652 | } |
---|
1653 | example |
---|
1654 | { |
---|
1655 | "EXAMPLE:"; echo = 2; |
---|
1656 | intmat IE[2][3]= |
---|
1657 | 1,0,0, |
---|
1658 | 0,1,0; |
---|
1659 | intmat E[1][3]= |
---|
1660 | 0,0,1; |
---|
1661 | polytope p=polytopeViaInequalities(IE,E); |
---|
1662 | p; |
---|
1663 | } |
---|
1664 | |
---|
1665 | proc vertices() |
---|
1666 | "USAGE: vertices(p); p polytope |
---|
1667 | RETURN: bigintmat, the vertices of p modulo its lineality space |
---|
1668 | EXAMPLE: example vertices; shows an example |
---|
1669 | " |
---|
1670 | { |
---|
1671 | |
---|
1672 | } |
---|
1673 | example |
---|
1674 | { |
---|
1675 | "EXAMPLE:"; echo = 2; |
---|
1676 | intmat M[4][3]= |
---|
1677 | 1,0,0, |
---|
1678 | 1,2,0, |
---|
1679 | 1,0,2, |
---|
1680 | 1,2,2, |
---|
1681 | 1,1,1; |
---|
1682 | polytope p=polytopeViaPoints(M); |
---|
1683 | vertices(p); |
---|
1684 | } |
---|
1685 | |
---|
1686 | proc onesVector() |
---|
1687 | "USAGE: onesVector(n); n int |
---|
1688 | RETURN: intvec, intvec of length n with all entries 1 |
---|
1689 | EXAMPLE: example onesVector; shows an example |
---|
1690 | " |
---|
1691 | { |
---|
1692 | |
---|
1693 | } |
---|
1694 | example |
---|
1695 | { |
---|
1696 | "EXAMPLE:"; echo = 2; |
---|
1697 | intvec w = onesVector(3); |
---|
1698 | w; |
---|
1699 | } |
---|
1700 | |
---|
1701 | static proc mod_init() |
---|
1702 | { |
---|
1703 | intvec save=option(get); |
---|
1704 | option(noredefine); |
---|
1705 | LIB "customstd.so"; |
---|
1706 | LIB "gfanlib.so"; |
---|
1707 | option(set,save); |
---|
1708 | } |
---|