application "tropical"; # Let's start with some basic tropical arithmetic. $a = new TropicalNumber(3); $b = new TropicalNumber(-4); print $a + $b; print $a * $b; # We have basic tropical linear algebra $m = new Matrix >([[0,1],["inf",-3]]); $v = new Vector >(1,0); print $m * $v; print $v * $v; print tdet($m); # Tropical polynomials are created just like ordinary polynomials: $r = new Ring >(2); #Tropical polynomial ring in two variables ($x,$y) = $r->variables; $p = (new TropicalNumber(3)) * $x*$x + $y; print $p; # There is an easier way to do this: $p = toTropicalPolynomial("max(2x + 3,y)"); $p = toTropicalPolynomial("max(2x0 + 3, x1)",$r); $p = toTropicalPolynomial("max(2x + 3,y)",$r,1); #We can create tropical convex hulls $c = new Polytope(POINTS=>[[0,0,"-inf"],[0,1,1],[0,0,2]]); $c->VISUAL; $c->VISUAL_SUBDIVISION; $c->POLYTOPE_COVECTOR_DECOMPOSITION->VISUAL; $d = cyclic(3,5); $d->VISUAL; $e = new Polytope(POINTS=>[[0,0,"inf","inf"],[0,"inf",0,"inf"],[0,"inf","inf",0],["inf",0,0,"inf"],["inf",0,"inf",0],["inf","inf",0,0]]); $e->VISUAL; #Parametrized linear programming $monomial=new UniMonomial(1); $t=new PuiseuxFraction($monomial); $c = polytope::cube >(3,$t,0); print $c->VERTICES; print new Matrix >($c->FACETS); $c->LP = new polytope::LinearProgram >(LINEAR_OBJECTIVE=>[1,1,-$t,1]); print $c->LP->MAXIMAL_VALUE; print $c->LP->MAXIMAL_VERTEX; print $c->VOLUME; # The basic object of tropical geometry: The tropical cycle # Note that everything is in projective coordinates and has an additional leading coordinate. $c = new Cycle(PROJECTIVE_VERTICES=>[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],MAXIMAL_POLYTOPES=>[[0,1],[0,2],[0,3]],WEIGHTS=>[1,1,1]); print is_balanced($c); $c = new Cycle(PROJECTIVE_VERTICES=>thomog([[1,0,0],[0,1,0],[0,0,1],[0,-1,-1]]),MAXIMAL_POLYTOPES=>[[0,1],[0,2],[0,3]],WEIGHTS=>[1,1,1]); $d = new Cycle(PROJECTIVE_VERTICES=>thomog([[1,0,0],[0,1,0],[0,0,1],[0,-1,-1]]),MAXIMAL_POLYTOPES=>[[0,1],[0,2],[0,3]],WEIGHTS=>[1,1,1]); print $d->DEGREE; # We can construct hypersurfaces from homogeneous polynomials! $p = toTropicalPolynomial("min(a,b,c)"); $h = new Hypersurface(POLYNOMIAL=>$p); print $h->VERTICES; print $h->MAXIMAL_POLYTOPES; print $h->WEIGHTS; $h->VISUAL; # Polymake can compute arbitrary tropical linear spaces $p=new Vector( [0,0,3,1,2,1,0,1,0,2,2,0,3,0,4,1,2,2,0,0]); #This is an element of the (min-) tropical Grassmannian! $I=ideal::pluecker_ideal(3,6); #Initial ideals always use max and require nonnegative weight vectors. $pp=new Vector(5*ones_vector(20)-$p); $J=new ideal::Ideal(GENERATORS=> $I->GROEBNER(ORDER_VECTOR=>$pp)->INITIAL_FORMS); print $J->contains_monomial(); #Let's compute the corresponding tropical linear space. $mat = new matroid::ValuatedMatroid( BASES=>matroid::uniform_matroid(3,6)->BASES, VALUATION_ON_BASES=>$p, N_ELEMENTS=>6); $tl = linear_space($mat); #Let's compute its bounded cells. @bounded = map { grep { ($_ * $tl->FAR_VERTICES)->size == 0} @{rows($_)} } @{$tl->CONES}; print join(",",@bounded); # Now for some intersection theory $F = toTropicalPolynomial("min(12+3*x0,-131+2*x0+x1, -67+2*x0+x2,-9+2*x0+x3,-131+x0+2*x1,-129+x0+x1+x2, -131+x0+x1+x3,-116+x0+2*x2,-76+x0+x2+x3,-24+x0+2*x3,-95+3*x1, -108+2*x1+x2,-92+2*x1+x3,-115+x1+2*x2,-117+x1+x2+x3, -83+x1+2*x3,-119+3*x2,-119+2*x2+x3,-82+x2+2*x3,-36+3*x3)"); $V = new Hypersurface(POLYNOMIAL=>$F); print intersect(intersect($V,$V),$V)->DEGREE; #The standard tropical line lies in this hypersurface. $B = matroid_fan(matroid::uniform_matroid(2,4)); print intersect_in_smooth_surface($V,$B,$B)->DEGREE; # Let's look at the lines in this cubic $L = lines_in_cubic($F); print $L->N_ISOLATED,", ",$L->N_FAMILIES,"\n"; @rp = map { $_->representative() } $L->all_families; visualize_in_surface($V, @rp); # There is an interface to gfan $r = new Ring(4); ($x,$y,$z,$w) = $r->variables; $p = $x + $y +$z + $w; $q = $x*$x - 3*$w*$z; $ideal = new ideal::Ideal(GENERATORS=>[$p,$q]); $trop = gfan_tropicalvariety_of_prime($ideal); print $trop->VERTICES;