1 #include "parser.h"
2 #include "printer.h"
3 #include "polynomial.h"
4 #include "division.h"
5 #include "buchberger.h"
6 #include "wallideal.h"
7 #include "lp.h"
8 #include "reversesearch.h"
9 #include "termorder.h"
10 #include "ep_standard.h"
11 #include "ep_xfig.h"
12 #include "gfanapplication.h"
13 #include "polyhedralcone.h"
14 #include "polyhedralfan.h"
15 #include "tropical.h"
16 #include "tropical2.h"
17 #include "tropicalbasis.h"
18 #include "log.h"
19 
20 class TropicalBasisApplication : public GFanApplication
21 {
22 
23   SimpleOption optionHomogenize;
24 public:
helpText()25   const char *helpText()
26   {
27     return "This program computes a tropical basis for an ideal defining a tropical curve. Defining a tropical curve means that the Krull dimension of R/I is at most 1 + the dimension of the homogeneity space of I where R is the polynomial ring. The input is a generating set for the ideal. If the input is not homogeneous option -h must be used.\n";
28   }
TropicalBasisApplication()29   TropicalBasisApplication():
30     optionHomogenize("-h","Homogenise the input before computing a tropical basis and dehomogenise the output. This is needed if the input generators are not already homogeneous.")
31   {
32     registerOptions();
33   }
34 
name()35   const char *name()
36   {
37     return "_tropicalbasis";
38   }
main()39   int main()
40   {
41     FileParser P(Stdin);
42 
43     /*    StringParser P1("{1+76*a2*b*c+6*a2*c4+72*a*b3*c3,"
44 		    "46*b3*c+68*b3*a2*c+42*a3*c4+47*b6*a2}");
45     StringParser P2("{1-79ab^4-27b^3c^2+32a^4b^2c,"
46 		    "-36c-35b^3c^3+11a^4b^2c^2+90a^3b^6}");
47     */
48     PolynomialSet theInput=P.parsePolynomialSetWithRing();
49     PolynomialRing originalRing=theInput.getRing();
50 
51     if(optionHomogenize.getValue())
52       {
53 	log1 fprintf(Stderr,"Homogenizing...\n");
54 	IntegerVector grading=IntegerVector::allOnes(theInput.numberOfVariablesInRing());
55 
56 	/*	{  // It is not necessary to compute the true homogenization
57 	  WeightReverseLexicographicTermOrder t(grading);
58 	  buchberger(&theInput,t);
59 	  }*/
60 
61 	PolynomialSet h=theInput.homogenization(theInput.getRing().withVariablesAppended("H"));
62 wallInequalities(h);
63 
64 	log1 fprintf(Stderr,"The homogenized ideal:\n");
65 	log1 AsciiPrinter(Stderr).printPolynomialSet(h);
66 
67 	theInput=h;
68       }
69 
70 
71     int n=theInput.numberOfVariablesInRing();
72 
73     int homog=-1;
74     {
75       log1 debug.printString("Computing homogeneity space\n");
76       PolynomialSet idealGroebnerBasis=theInput;
77       IntegerVector grading=IntegerVector::allOnes(theInput.numberOfVariablesInRing());
78       WeightReverseLexicographicTermOrder t(grading);
79       buchberger(&idealGroebnerBasis,t);
80       PolyhedralCone hspace=homogeneitySpace(idealGroebnerBasis);
81       IntegerVectorList hv=hspace.dualCone().getEquations();
82       homog=hv.size();
83       log1 debug.printString("..done homogeneity space.\n");
84     }
85 
86     PolynomialSet theOutput=tropicalBasisOfCurve(n,theInput,0,homog);
87 
88     if(optionHomogenize.getValue())
89       {
90 	theOutput=theOutput.embeddedInto(originalRing);
91       }
92     AsciiPrinter(Stdout).printPolynomialRing(theOutput.getRing());
93     AsciiPrinter(Stdout).printNewLine();
94     AsciiPrinter(Stdout).printPolynomialSet(theOutput);
95 
96     return 0;
97   }
98 };
99 
100 static TropicalBasisApplication theApplication;
101