File: analyze_this.pl

package info (click to toggle)
polymake 4.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,888 kB
  • sloc: cpp: 168,933; perl: 43,407; javascript: 31,575; ansic: 3,007; java: 2,654; python: 632; sh: 268; xml: 117; makefile: 61
file content (162 lines) | stat: -rw-r--r-- 5,116 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
#  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.
#-------------------------------------------------------------------------------

# This script is meant for non-expert users to get some idea about a polytope they are
# dealing with.  Supposed to become (a bit) more sophisticated.

use application "polytope";

sub header() {
  return << ".";
\\documentclass{article}
\\usepackage{tikz,graphicx,xspace,url,csquotes}
\\newcommand\\polymake{\\texttt{polymake}\\xspace}
\\title{\\polymake description of a big object of type \\texttt{Polytope}}
\\begin{document}
\\maketitle
\\noindent
.
}

sub footer() {
  return << ".";

For details on how to use \\polymake see the tutorial section at \\url{www.polymake.org}
and the forum at \\url{forum.polymake.org}.
\\end{document}
.
}

sub tikzfigure($$$$) {
  my ($poly,$vis,$name,$tikzfile)=@_;
  tikz($poly->$vis(VertexLabels=>"hidden"),File=>$tikzfile);
  return << ".";
\\begin{figure}[ht]
\\centering
\\resizebox{0.67\\textwidth}{!}{\\input $tikzfile}
\\caption{This is how \\enquote{$name} looks like}
\\label{fig}
\\end{figure}
.
}

sub palindromic($) {
  my ($v)=@_;
  my $len=$v->dim();
  my $pal=true;
  for (my $i=0; $i<$len/2; ++$i) {
    $pal = false if $v->[$i] != $v->[$len-$i-1];
  }
  return $pal;
}

sub analyze_this($) {
  my ($poly) = @_;
  my $pdflatex = $Visual::pdflatex;
  my $pdfviewer = $Visual::pdfviewer;
  my $tempfile = new Tempfile();
  my $latextemplate = $tempfile.".tex";
  my $tikzfile = $tempfile.".tikz";
  my $pdfout = $tempfile.".pdf";
  my $pdfout_dir = $tempfile->dirname;
  my $pdfout_name = $tempfile->basename;

  print STDERR "writing to $latextemplate\n";
  
  my $name = $poly->description();
  if ($name eq "") {
    $name = defined($poly->name)? $poly->name : "unnamed polyhedron";
  }
  my ($AMBIENT_DIM, $DIM) = map { $poly->$_ } ("AMBIENT_DIM", "DIM");
  my $simplicial = $poly->SIMPLICIAL ? "simplicial" : "not simplicial";
  my $simple = $poly->SIMPLE ? "simple" : "not simple";
  my $cubical = $poly->CUBICAL ? "cubical" : "not cubical";
  open TEX, ">$latextemplate" or die "analyze_this: cannot write $latextemplate";
  print TEX header();

  print TEX << ".";
The object called \\enquote{$name} describes a $DIM-dimensional polyhedron, which lives in $AMBIENT_DIM-space, and which is
.
  if ($poly->BOUNDED) {
    print TEX << ".";
bounded.
.
  } else {
    print TEX << ".";
unbounded.  All combinatorial data refers to the projective closure of the quotient by the lineality space.
This is always a polytope. This means that \\polymake treats unbounded polyhedra like polytopes with a marked face (at infinity).
.
  }
  print TEX << ".";
Its \$f\$-vector reads
\\[
.
  print TEX "(", (join ",", @{$poly->F_VECTOR}), ") \\enspace .";
  print TEX << ".";
\\]
The polytope is $simplicial, $simple and $cubical.
.
  if (palindromic($poly->F_VECTOR)) {
    if (isomorphic($poly->VERTICES_IN_FACETS,$poly->FACETS_THRU_VERTICES)) {
      print TEX << ".";
It is selfdual, which is a rather rare property.
.
    } else {
      print TEX << ".";
While the \$f\$-vector is palindromic, the polytope is not selfdual.
.
    }
  }
  print TEX << ".";

.
  if ($AMBIENT_DIM<=3) {
    print TEX << ".";
A direct visualization in $3$-space is shown in Figure~\\ref{fig}.
.
    print TEX tikzfigure($poly,"VISUAL",$name,$tikzfile);
  } elsif ($AMBIENT_DIM<=4) {
    print TEX << ".";
A Schlegel diagram, projected onto the facet which happens to appear first in the list of \\texttt{FACETS},
is shown in Figure~\\ref{fig}.  Notice that projecting onto another facet may result in a very different
picture.
.
    print TEX tikzfigure($poly,"VISUAL",$name,$tikzfile);
  } else {
    print TEX << ".";
The dimension of the polytope is too high to allow for any canonical visualization. 
Yet it may be possible that there are interesting pictures which reveal geometric or combinatorial properties.
One way is to visualize the dual graph, and this is shown in Figure~\\ref{fig}; but this choice is rather arbitrary.
.
    print TEX tikzfigure($poly,"VISUAL_DUAL_GRAPH",$name,$tikzfile);
  }

  print TEX footer();
  close TEX;

  # LaTeX twice to get references right
  system("$pdflatex --output-directory=$pdfout_dir --jobname=$pdfout_name $latextemplate 1>/dev/null");
  system("$pdflatex --output-directory=$pdfout_dir --jobname=$pdfout_name $latextemplate 1>/dev/null");

  print STDERR "viewing $pdfout\n";
  system("$pdfviewer $pdfout");
}


# Local Variables:
# c-basic-offset:3
# mode: cperl
# End: