File: rational.rules

package info (click to toggle)
polymake 3.2r4-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 22,564 kB
  • sloc: cpp: 153,464; perl: 40,590; ansic: 2,829; java: 2,654; python: 589; sh: 219; xml: 117; makefile: 63
file content (113 lines) | stat: -rw-r--r-- 3,836 bytes parent folder | download
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
#  Copyright (c) 1997-2018
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
#  http://www.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 Cone<Rational> {

rule TRIANGULATION.FACETS : RAYS, TRIANGULATION.WEIGHTS {
   $this->TRIANGULATION->FACETS=regular_subdivision($this->RAYS, $this->TRIANGULATION->WEIGHTS);
}
weight 3.10;
incurs TRIANGULATION.FacetPerm;

rule TRIANGULATION.WEIGHTS : RAYS, TRIANGULATION.FACETS {
   $this->TRIANGULATION->WEIGHTS=is_regular($this->RAYS,$this->TRIANGULATION->FACETS);
}

}

object Polytope<Rational> {

# @category Geometry
# A rational polytope is lattice if each bounded vertex has integer coordinates.
property LATTICE : Bool;

rule LATTICE : VERTICES , FAR_FACE {
   $this->LATTICE=is_integral($this->VERTICES->minor(~$this->FAR_FACE,All));
}
precondition : POINTED;

rule TRIANGULATION.GKZ_VECTOR : RAYS, TRIANGULATION.FACETS {
   $this->TRIANGULATION->GKZ_VECTOR=gkz_vector($this->RAYS,$this->TRIANGULATION->FACETS);
}
precondition : FULL_DIM;
precondition : BOUNDED;


# @category Geometry
# Number of points with 0/1-coordinates in a polytope.
# @depends azove
property N_01POINTS : Int;


# @category Triangulation and volume
# The //k//-dimensional Euclidean volume of a //k//-dimensional rational polytope 
# embedded in R^n.
# This value is obtained by summing the square roots of the entries in SQUARED_RELATIVE_VOLUMES
# using the function //naive_sum_of_square_roots//. Since this latter function
# does not try very hard to compute the real value, you may have to resort to
# a computer algebra package.
# The value is encoded as a map collecting the coefficients of various roots encountered in the sum.
# For example, {(3 1/2),(5 7)} represents sqrt{3}/2 + 7 sqrt{5}.
# If the output is not satisfactory, please use a symbolic algebra package.
# @example The following prints the 2-dimensional volume of a centered square with side length 2 embedded in the 3-space (the result is 4):
# > $M = new Matrix([1,-1,1,0],[1,-1,-1,0],[1,1,-1,0],[1,1,1,0]);
# > $p = new Polytope<Rational>(VERTICES=>$M);
# > print $p->RELATIVE_VOLUME;
# | {(1 4)}
property RELATIVE_VOLUME : Map<Rational, Rational>;

rule RELATIVE_VOLUME : SQUARED_RELATIVE_VOLUMES {
    $this->RELATIVE_VOLUME = sum_of_square_roots_naive($this->SQUARED_RELATIVE_VOLUMES);
}

}

# self-configuring rules interfacing external software
INCLUDE
   porta.rules

# @category Optimization
#  Read an .ieq or .poi file (porta input) or .poi.ieq or .ieq.poi (porta output)
#  and convert it to a [[Polytope<Rational>]] object
# @param String file filename of a porta file (.ieq or .poi)
# @return Polytope<Rational>
user_function porta2poly($) {
   require PortaParser;
   my $parser=new PortaParser(shift);
   my $P=new Polytope<Rational>($parser->name);
   $P->CONE_AMBIENT_DIM=($parser->dim)+1;

   if ($parser->has_points) {
      if ($parser->computed) {
	 $P->VERTICES=$parser->Points;
      } else {
	 $P->POINTS=$parser->Points;
      }
   } else {
      if ($parser->computed) {
	 $P->FACETS=$parser->Ineq;  $P->AFFINE_HULL=$parser->Eq;
      } else {
	 $P->INEQUALITIES=$parser->Ineq;  $P->EQUATIONS=$parser->Eq;
      }
   }

   $P->commit;
   $P;
}

# Local Variables:
# cperl-indent-level:3
# mode: perl
# End: