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
|
# 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.
#-------------------------------------------------------------------------------
# @Category Combinatorics
object Patchwork {
# Sign distribution on the support of the [[POLYNOMIAL]].
# Indices correspond to row indices of [[MONOMIALS]].
property SIGNS : Array<Bool>;
# Facets of the real part of the patchworked hypersurface.
# Row indices correspond to orthants (ordered lexicographically),
# column indices correspond to facets of the original hypersurface.
# This is the transpose of [[REAL_PHASE]].
property REAL_FACETS : IncidenceMatrix<NonSymmetric>;
# Real phase structure of the patchworked hypersurface.
# Row indices correspond to facets of the original hypersurface,
# column indices correspond to orthants (ordered lexicographically).
# I.e., a copy of facet i appears in orthant j,
# iff the j-th entry in the i-th row is 1.
# This is the transpose of [[REAL_FACETS]].
# @example
# > $h = new tropical::Hypersurface<Max>(MONOMIALS=>unit_matrix(3),COEFFICIENTS=>ones_vector(3));
# > $p = $h->PATCHWORK(SIGNS=>[0,1,0]);
# > print $p->REAL_PHASE;
# | {0 2}
# | {2 3}
# | {0 3}
# > $p->realize->VISUAL;
property REAL_PHASE : IncidenceMatrix<NonSymmetric>;
permutation TermPerm : PermBase;
permutation ConesPerm : PermBase;
rule SIGNS : TermPerm.SIGNS, TermPerm.PERMUTATION {
$this->SIGNS=permuted($this->TermPerm->SIGNS, $this->TermPerm->PERMUTATION);
}
# weight 1.10;
rule REAL_FACETS : ConesPerm.REAL_FACETS, ConesPerm.PERMUTATION {
$this->REAL_FACETS=permuted_cols($this->ConesPerm->REAL_FACETS, $this->ConesPerm->PERMUTATION);
}
# weight 1.10;
rule REAL_PHASE : ConesPerm.REAL_PHASE, ConesPerm.PERMUTATION {
$this->REAL_PHASE=permuted_rows($this->ConesPerm->REAL_PHASE, $this->ConesPerm->PERMUTATION);
}
# weight 1.10;
# The real part of the patchworked hypersurface,
# realized as a polyhedral hypersurface in IR^dim.
# The vertices of each of the 2^dim copies of the hypersurface
# will be moved to the interior of the respective orthant
# (according to method), and relevant unbounded facets will be joined.
# If method is "rigid" (default), vertices will be translated to the positive orthant,
# and then reflected to their corresponding orthant.
# If method is "uniform", vertices will be moved to the barycenter
# of the respective dual cell in the dual subdivision of the support,
# and then reflected to their corresponding orthant
# (this only works if the hypersurface is simplicial, e.g. for curves).
# @param String method "rigid" (default) or "uniform"
# @return fan::PolyhedralComplex<Rational>
# @example Visualize a patchworked plane:
# > $h1 = new tropical::Hypersurface<Max>(POLYNOMIAL=>toTropicalPolynomial("max(a,b,c,d)"));
# > $p1 = $h1->PATCHWORK(SIGNS=>[1,0,1,0]);
# > $p1->realize->VISUAL;
# @example A "nice" visualization for a curve:
# > $h2 = harnack_curve(3);
# > $p2 = $h2->PATCHWORK;
# > $p2->realize("uniform")->VISUAL;
user_method realize(;String = "rigid") : REAL_FACETS {
my ($this, $method) = @_;
return real_part_realize($this->parent->MONOMIALS, $this->parent->COEFFICIENTS, $this->parent->VERTICES, $this->parent->MAXIMAL_POLYTOPES, $this->parent->FAR_VERTICES, $this->REAL_FACETS, $method);
}
# The cellular chain complex with Z_2 coefficients
# of the patchworked hypersurface.
# The d-th entry represents the d-th boundary matrix,
# i.e., the one mapping (d+1)-chains to d-chains.
# It is computed directly from the dual subdivision,
# which means that, instead of a tropical polynomial,
# one may initiate the Hypersurface object via its
# dual subdivision, which in turn allows this computation
# to be carried out on non-regular subdivisions.
# @example A patchworked line in the real projective plane is combinatorially a triangle:
# > $h = new tropical::Hypersurface<Max>(MONOMIALS=>unit_matrix(3),COEFFICIENTS=>ones_vector(3));
# > $p = $h->PATCHWORK(SIGNS=>[0,1,0]);
# > $c = $p->CHAIN_COMPLEX_Z2;
# > $b = $c->boundary_matrix(1);
# > print $b->rows, "x", $b->cols;
# | 3x3
# > print rank($b);
# | 2
# @example A non-regular example:
# > $points = [[1,4,0,0],[1,0,4,0],[1,0,0,4],[1,2,1,1],[1,1,2,1],[1,1,1,2]];
# > $cells = [[0,1,3],[0,2,5],[0,3,5],[1,2,4],[1,3,4],[2,4,5],[3,4,5]];
# > $moae = new fan::SubdivisionOfPoints(POINTS=>$points, MAXIMAL_CELLS=>$cells);
# > $h = new Hypersurface<Min>(DUAL_SUBDIVISION=>$moae);
# > $p = $h->PATCHWORK(SIGNS=>[0,0,0,0,0,0]);
# > print $p->CHAIN_COMPLEX_Z2->type->full_name;
# | ChainComplex<SparseMatrix<GF2, NonSymmetric>>
property CHAIN_COMPLEX_Z2 : topaz::ChainComplex<SparseMatrix<GF2>>;
# The Z_2 Betti numbers of the patchworked hypersurface.
# See the documentation of CHAIN_COMPLEX_Z2 for details.
# @example A patchworked hyperplane in n-dimensional real projective space
# is topologically the (n-1)-dimensional real projective space:
# > $h = new tropical::Hypersurface<Max>(POLYNOMIAL=>toTropicalPolynomial("max(a,b,c,d,e,f)"));
# > $p = $h->PATCHWORK(SIGNS=>[0,0,0,0,0,0]);
# > print $p->BETTI_NUMBERS_Z2;
# | 1 1 1 1 1
property BETTI_NUMBERS_Z2 : Array<Int>;
}
object Hypersurface {
# property GENERIC : Bool;
# @Category Combinatorics
# This encodes a patchworking structure on a tropical hypersurface.
# Its lone input property is [[SIGNS]] - a sign distribution on the vertices
# of the induced regular subdivision of the corresponding Newton polytope.
# As it is a multiple subobject, you can create multiple patchworking structures
# (for different sign distributions) on the same tropical hypersurface object.
# @example
# > $h = new tropical::Hypersurface<Max>(POLYNOMIAL=>toTropicalPolynomial("max(a,b,c)"));
# > $p1 = $h->PATCHWORK(SIGNS=>[0,1,0]);
# > $p2 = $h->PATCHWORK(SIGNS=>[1,1,1]);
property PATCHWORK : Patchwork : multiple;
rule PATCHWORK.REAL_FACETS : PATCHWORK.SIGNS, MONOMIALS, COEFFICIENTS, VERTICES, MAXIMAL_POLYTOPES {
if ($this->MONOMIALS->rows() != $this->PATCHWORK->SIGNS->size()) {
die "Error: dimension mismatch between signs and monomials";
}
$this->PATCHWORK->REAL_FACETS = real_facets($this->PATCHWORK->SIGNS, $this->MONOMIALS, $this->COEFFICIENTS, $this->VERTICES, $this->MAXIMAL_POLYTOPES);
}
weight 5.05;
rule PATCHWORK.REAL_FACETS : PATCHWORK.REAL_PHASE {
$this->PATCHWORK->REAL_FACETS = transpose($this->PATCHWORK->REAL_PHASE);
}
rule PATCHWORK.REAL_PHASE : PATCHWORK.SIGNS, MONOMIALS, COEFFICIENTS, VERTICES, MAXIMAL_POLYTOPES {
if ($this->MONOMIALS->rows() != $this->PATCHWORK->SIGNS->size()) {
die "Error: dimension mismatch between signs and monomials";
}
$this->PATCHWORK->REAL_PHASE = real_phase($this->PATCHWORK->SIGNS, $this->MONOMIALS, $this->COEFFICIENTS, $this->VERTICES, $this->MAXIMAL_POLYTOPES);
}
weight 5.05;
rule PATCHWORK.REAL_PHASE : PATCHWORK.REAL_FACETS {
$this->PATCHWORK->REAL_PHASE = transpose($this->PATCHWORK->REAL_FACETS);
}
rule PATCHWORK.CHAIN_COMPLEX_Z2 : PATCHWORK.SIGNS, DUAL_SUBDIVISION.POLYHEDRAL_COMPLEX.VERTICES, DUAL_SUBDIVISION.POLYHEDRAL_COMPLEX.HASSE_DIAGRAM {
# $this->PATCHWORK->CHAIN_COMPLEX_Z2 = new topaz::ChainComplex<SparseMatrix<GF2>>(chain_complex_from_dualsub($this,$this->PATCHWORK->SIGNS));
my $cc = chain_complex_from_dualsub($this->PATCHWORK->SIGNS, $this->DUAL_SUBDIVISION->POLYHEDRAL_COMPLEX->HASSE_DIAGRAM, $this->DUAL_SUBDIVISION->POLYHEDRAL_COMPLEX->VERTICES);
$this->PATCHWORK->CHAIN_COMPLEX_Z2 = new topaz::ChainComplex<SparseMatrix<GF2>>($cc);
# $this->PATCHWORK->CHAIN_COMPLEX_Z2 = new topaz::ChainComplex<SparseMatrix<GF2>>(chain_complex_from_dualsub($this->PATCHWORK->SIGNS, $this->DUAL_SUBDIVISION->POLYHEDRAL_COMPLEX->HASSE_DIAGRAM, $this->DUAL_SUBDIVISION->POLYHEDRAL_COMPLEX->VERTICES));
}
weight 5.10;
rule PATCHWORK.BETTI_NUMBERS_Z2 : PATCHWORK.CHAIN_COMPLEX_Z2 {
$this->PATCHWORK->BETTI_NUMBERS_Z2 = topaz::betti_numbers<GF2>($this->PATCHWORK->CHAIN_COMPLEX_Z2);
}
rule PATCHWORK.TermPerm.PERMUTATION = TermPerm.PERMUTATION;
rule PATCHWORK.ConesPerm.PERMUTATION = ConesPerm.PERMUTATION;
}
### examples:
# This returns a Hypersurface object, and a unique attached [[PATCHWORK]] property
# which represents an M-curve of given degree with Harnack's configuration.
# @param Int d the degree of the curve
# @return tropical::Hypersurface<Min>
# @example Create a Harnack curve of degree 6:
# > $h = harnack_curve(6);
# > $p = $h->PATCHWORK;
# > print $p->BETTI_NUMBERS_Z2;
# | 11 11
# > $p->realize("uniform")->VISUAL;
user_function harnack_curve( Int ) {
my $n = shift;
my @monoms;
my @weights;
my @signs;
foreach my $i (0 .. $n) {
foreach my $j (0 .. $n-$i) {
push @weights, ($i*$j+$i*$i+$j*$j);
push @monoms, [$n-$i-$j, $i, $j];
push @signs, ($i*$j+$i+$j)%2;
}
}
my $m = new Matrix<Int>(\@monoms);
my $c = new Vector<TropicalNumber<Min>>(\@weights);
my $s = new Array<Bool>(\@signs);
my $h = new Hypersurface<Min>(MONOMIALS=>$m, COEFFICIENTS=>$c);
$h->PATCHWORK(SIGNS=>$s);
return $h;
}
# This returns a Hypersurface object, and a unique attached [[PATCHWORK]] property
# which represents an M-curve of degree 6 with Gudkov's configuration.
# @return tropical::Hypersurface<Min>
# @example
# > $h = gudkov_curve;
# > $p = $h->PATCHWORK;
# > print $p->BETTI_NUMBERS_Z2;
# | 11 11
# > $p->realize("uniform")->VISUAL;
user_function gudkov_curve {
my @monoms;
my $n = 6;
foreach my $i (0 .. $n) {
foreach my $j (0 .. $n-$i) {
push @monoms, [$n-$i-$j, $i, $j];
}
}
my $signs = [
1, 0, 0, 0, 0, 0, 1,
0, 0, 1, 0, 1, 0,
1, 0, 1, 0, 0,
0, 0, 0, 0,
1, 0, 1,
0, 0,
1
];
my $weights = [
0, 0, 66, 156, 252, 369, 507,
0, 6, 23, 95, 200, 332,
66, 23, 24, 61, 178,
156, 95, 61, 45,
252, 200, 178,
369, 332,
507
];
my $m = new Matrix<Int>(\@monoms);
my $c = new Vector<TropicalNumber<Min>>($weights);
my $s = new Array<Bool>($signs);
my $h = new Hypersurface<Min>(MONOMIALS=>$m, COEFFICIENTS=>$c);
$h->PATCHWORK(SIGNS=>$s);
return $h;
}
# This returns a Hypersurface object, and a unique attached [[PATCHWORK]] property
# which represents a curve of degree 10 that is a counterexample
# to Ragsdale's conjecture.
# @return tropical::Hypersurface<Min>
# @example
# > $h = ragsdale_counterexample;
# > $p = $h->PATCHWORK;
# > $p->realize("uniform")->VISUAL;
user_function ragsdale_counterexample {
my @monoms;
foreach my $i (0 .. 10) {
foreach my $j (0 .. 10-$i) {
push @monoms, [10-$i-$j, $i, $j];
}
}
my $weights = [ # yes these were done by hand
224, 142, 76, 12, 76, 142, 224, 311, 401, 494, 600,
144, 58, 22, 6, 22, 58, 144, 232, 324, 419,
66, 34, 10, 2, 10, 34, 66, 156, 250,
48, 18, 2, 0, 2, 18, 48, 140,
66, 34, 10, 2, 10, 34, 68,
144, 58, 22, 6, 22, 55,
224, 142, 76, 12, 44,
310, 232, 167, 104,
402, 326, 262,
498, 424,
600
];
my $signs = [
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 1, 0, 1,
0, 0, 1, 1, 1, 0, 0, 0,
1, 0, 0, 0, 0, 0, 1,
0, 0, 0, 1, 0, 0,
1, 0, 1, 0, 1,
0, 0, 0, 0,
1, 0, 1,
0, 0,
1
];
my $m = new Matrix<Int>(\@monoms);
my $c = new Vector<TropicalNumber<Min>>($weights);
my $s = new Array<Bool>($signs);
my $h = new Hypersurface<Min>(MONOMIALS=>$m, COEFFICIENTS=>$c);
$h->PATCHWORK(SIGNS=>$s);
return $h;
}
# Local Variables:
# mode: perl
# cperl-indent-level:3
# indent-tabs-mode:nil
# End:
|