1########################################################################
2#  This program is free software; you can redistribute it and/or
3#  modify it under the terms of the GNU General Public License
4#  as published by the Free Software Foundation; either version 2
5#  of the License, or (at your option) any later version.
6#
7#  This program is distributed in the hope that it will be useful,
8#  but WITHOUT ANY WARRANTY; without even the implied warranty of
9#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10#  GNU General Public License for more details.
11#
12#  You should have received a copy of the GNU General Public License
13#  along with this program; if not, write to the Free Software
14#  Foundation, Inc., 51 Franklin Street, Fifth Floor,
15#  Boston, MA  02110-1301, USA.
16#
17#  ---
18#  Copyright (C) 2011-2015, Simon Hampe <simon.hampe@googlemail.com>
19#
20#  ---
21#  Copyright (c) 2016-2021
22#  Ewgenij Gawrilow, Michael Joswig, and the polymake team
23#  Technische Universität Berlin, Germany
24#  https://polymake.org
25#
26#
27#	This file contains functions for general intersection-theoretic computations
28#
29########################################################################
30
31# @category Intersection theory
32# Computes the degree of a tropical variety as the total weight of the
33# 0-dimensional intersection product obtained by intersecting with the
34# complementary uniform linear space.
35# @param Cycle A tropical cycle
36# @return Integer The degree
37user_function degree<Addition>(Cycle<Addition>) {
38	my $X = shift;
39
40	if(is_empty($X)) { return 0; }
41
42	my $dim = $X->PROJECTIVE_DIM;
43
44	if($dim == 0) {
45		return $X->WEIGHTS * ones_vector<Integer>($X->WEIGHTS->dim());
46	}
47
48	my $ambient_dim = $X->PROJECTIVE_AMBIENT_DIM;
49
50   my $expnum = unit_matrix<Int>($ambient_dim+1);
51   my $coeffnum = ones_vector<TropicalNumber<Addition>>($ambient_dim+1);
52	my $num = new Polynomial<TropicalNumber<Addition>>($coeffnum, $expnum);
53	my $expden = new Matrix<Int>(1,$ambient_dim+1);
54   $expden->elem(0,0) = 1;
55   my $coeffden = new Vector<TropicalNumber<Addition>>([0]);
56   my $den = new Polynomial<TropicalNumber<Addition>>($coeffden, $expden);
57
58   my $rat_fct = new TropicalRationalFunction<Addition>(NUMERATOR=>$num, DENOMINATOR=>$den);
59
60	my $div = divisor( $X, $rat_fct^$dim);
61	return $div->WEIGHTS * ones_vector<Integer>($div->WEIGHTS->dim());
62}
63