#  Copyright (c) 1997-2010
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Darmstadt, Germany)
#  http://www.polymake.de
#
#  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.
#-------------------------------------------------------------------------------
#  $Project: polymake $$Id: main.rules 9547 2010-03-09 07:21:34Z smoeser $

# @topic application
# This application concentrates on tropical hypersurfaces and tropical polytopes.
# It provides the functionality for the computation of basic properties. Visualization and various constructions are possible.

IMPORT
  graph

USE
  polytope

file_suffix trop

# Tropical convex hull of finitely many points in the tropical (d-1)-torus, as introduced by Develin and Sturmfels.
# One construction is via the bounded subcomplex of an unbounded ordinary convex polyhedron.
declare object TropicalPolytope<Scalar=Rational [ typechecks::is_ordered_field_with_unlimited_precision(Scalar) ]>;

INCLUDE
  tropical_properties.rules
  hypersurface.rules
  singular.rules
  visual.rules

sub scalar_product($$) {
  my ($x,$y)=@_; my $z=$x->[0]+$y->[0];
  map { $z=min($x->[$_]+$y->[$_],$z) } 1..$#$x;
  return $z;
}

object TropicalPolytope {

rule AMBIENT_DIM : VERTICES | PSEUDOVERTICES | POINTS {
  $this->AMBIENT_DIM=($this->VERTICES | PSEUDOVERTICES | POINTS)->cols-1;
}
weight 0.10;

rule VERTICES : POINTS {
  discard_non_vertices($this, "POINTS");
}
weight 1.20;

rule VERTICES : PSEUDOVERTICES {
  discard_non_vertices($this, "PSEUDOVERTICES");
}
weight 1.10;

# It is structurally important that the envelope depends on the [[POINTS]].
# If the exact subdivision does not matter it may be advisable to create a new
# tropical polytope whose generators are the [[VERTICES]] of the former.
rule ENVELOPE.INEQUALITIES, ENVELOPE.EQUATIONS : POINTS, AMBIENT_DIM {
  $this->ENVELOPE = trop2poly($this);
}

rule PSEUDOVERTICES, PSEUDOVERTEX_GRAPH.ADJACENCY : AMBIENT_DIM, ENVELOPE {
  extract_pseudovertices($this, $this->ENVELOPE);
}
permutation : PseudoVertexPerm;

rule VERTEX_TYPES : VERTICES {
  $this->VERTEX_TYPES=types($this->VERTICES,$this->VERTICES);
}
weight 1.10;

rule default.pseudovertex_types: PSEUDOVERTEX_TYPES : PSEUDOVERTICES, POINTS {
  $this->PSEUDOVERTEX_TYPES=types($this->PSEUDOVERTICES,$this->POINTS);
}
weight 1.10;

rule PSEUDOVERTEX_COARSE_TYPES : PSEUDOVERTICES, POINTS {
  $this->PSEUDOVERTEX_COARSE_TYPES=coarse_types($this->PSEUDOVERTICES,$this->POINTS);
}
weight 1.10;

rule ENVELOPE.BOUNDED_COMPLEX : AMBIENT_DIM, ENVELOPE.VERTICES_IN_FACETS, ENVELOPE.FAR_FACE {
   $this->ENVELOPE->BOUNDED_COMPLEX=polytope::bounded_complex($this->ENVELOPE->VERTICES_IN_FACETS, $this->ENVELOPE->FAR_FACE, $this->AMBIENT_DIM);
}
weight 4.20;

rule CONVEX_HULL_2D_CYCLIC : POINTS, PSEUDOVERTEX_TYPES, PSEUDOVERTEX_GRAPH.ADJACENCY {
  $this->CONVEX_HULL_2D_CYCLIC=ch2d_3phases(scalar(@{$this->POINTS}),$this->PSEUDOVERTEX_TYPES,$this->PSEUDOVERTEX_GRAPH->ADJACENCY);
}
precondition : AMBIENT_DIM {
  $this->AMBIENT_DIM==2
}

}
# Local Variables:
# mode: perl
# c-basic-offset:3
# End:
