1 #include <iostream>
2 #include <stdlib.h>
3 #include "parser.h"
4 #include "printer.h"
5 #include "polynomial.h"
6 #include "division.h"
7 #include "buchberger.h"
8 #include "wallideal.h"
9 #include "lp.h"
10 #include "reversesearch.h"
11 #include "termorder.h"
12 #include "ep_standard.h"
13 #include "ep_xfig.h"
14 #include "polyhedralcone.h"
15 #include "gfanapplication.h"
16 #include "saturation.h"
17 #include "field_rationals.h"
18 #include "field_zmodpz.h"
19 #include "field_rationalfunctions.h"
20 #include "symmetry.h"
21 #include "linalg.h"
22 #include "fieldlp.h"
23 #include "integer.h"
24 #include "polynomialgcd.h"
25 #include "packedmonomial.h"
26 #include "gfanlib_zcone.h"
27 
28 using namespace gfan;
29 
30 class TropicalVarietySpanApplication : public GFanApplication
31 {
32 public:
includeInDefaultInstallation()33 	bool includeInDefaultInstallation() // Not included since the program does not follow the specifications of the help text. Moreover, doing this using Hadamard products is extremely slow. This should be replaced by the algorithm in the paper by Kahle, Katthan and Jensen.
34 	{
35 		return false;
36 	}
helpText()37   const char *helpText()
38   {
39     return "This program takes a ring and an ideal as input and computes the span of the tropical variety defined by the ideal.\n";
40   }
TropicalVarietySpanApplication()41   TropicalVarietySpanApplication()
42   {
43     registerOptions();
44   }
45 
name()46   const char *name()
47   {
48     return "_tropicalvarietyspan";
49   }
50 
hadamardProduct(PolynomialSet const & I,PolynomialSet const & J)51   PolynomialSet hadamardProduct(PolynomialSet const &I, PolynomialSet const &J)
52   {
53 	  PolynomialRing R=I.getRing();
54 	  int n=R.getNumberOfVariables();
55 	  PolynomialRing bigRing(R.getField(),n*3);
56 	  vector<int> var1;
57 	  vector<int> var2;
58 	  for(int i=0;i<n;i++)
59 	  {
60 		  var1.push_back(i+n);
61 		  var2.push_back(i+2*n);
62 	  }
63 	  PolynomialSet all(bigRing);
64 	  all.unionSet(I.embeddedInto2(bigRing,var1));
65 	  all.unionSet(J.embeddedInto2(bigRing,var2));
66 	  for(int i=0;i<n;i++)
67 		  all.push_back(bigRing.ithVariable(i)-bigRing.ithVariable(n+i)*bigRing.ithVariable(2*n+i));
68 
69 	  IntegerVectorList l;
70 //	  l.push_back();
71 	  l.push_back(IntegerVector(3*n));
72 	  l.push_back(concatenation(IntegerVector(n+n),IntegerVector::allOnes(n)));
73 	  MatrixTermOrder T(l);
74 	  buchberger(&all,T,true);
75 	  return all.polynomialRingIntersection(R);
76   }
77 
main()78   int main()
79   {
80 	  FileParser P(Stdin);
81 
82 	  PolynomialSet g=P.parsePolynomialSetWithRing();
83 
84 	  PolynomialSet s=g;
85 	  s=hadamardProduct(s,g);
86 	  pout<<s;
87 	  s=hadamardProduct(s,s);
88 	  pout<<s;
89 
90 
91 //	  pout<<hadamardProduct(g,g);
92 
93 	  return 0;
94   }
95 };
96 
97 static TropicalVarietySpanApplication theApplication;
98