1 #include "parser.h" 2 #include "printer.h" 3 #include "polynomial.h" 4 #include "wallideal.h" 5 #include "lp.h" 6 #include "polyhedralcone.h" 7 #include "gfanapplication.h" 8 #include "polyhedralfan.h" 9 #include "halfopencone.h" 10 #include "linalg.h" 11 #include "log.h" 12 13 class GroebnerConeApplication : public GFanApplication 14 { 15 SimpleOption optionRestrict; 16 SimpleOption optionPair; 17 SimpleOption optionAsFan; 18 SimpleOption optionVectorInput; 19 public: helpText()20 const char *helpText() 21 { 22 return "This program computes a Groebner cone. Three different cases are handled. The input may be a marked reduced Groebner basis in which case its Groebner cone is computed. The input may be just a marked minimal basis in which case the cone computed is not a Groebner cone in the usual sense but smaller. (These cones are described in [Fukuda, Jensen, Lauritzen, Thomas]). The third possible case is that the Groebner cone is possibly lower dimensional and given by a pair of Groebner bases as it is useful to do for tropical varieties, see option --pair. The facets of the cone can be read off in section FACETS and the equations in section IMPLIED_EQUATIONS.\n"; 23 } GroebnerConeApplication()24 GroebnerConeApplication(): 25 optionRestrict("--restrict","Add an inequality for each coordinate, so that the the cone is restricted to the non-negative orthant."), 26 optionPair("--pair","The Groebner cone is given by a pair of compatible Groebner bases. The first basis is for the initial ideal and the second for the ideal itself. See the tropical section of the manual."), 27 optionAsFan("--asfan","Writes the cone as a polyhedral fan with all its faces instead. In this way the extreme rays of the cone are also computed."), 28 optionVectorInput("--vectorinput","Compute a cone given list of inequalities rather than a Groebner cone. The input is an integer which specifies the dimension of the ambient space, a list of inequalities given as vectors and a list of equations.") 29 { 30 registerOptions(); 31 } 32 name()33 const char *name() 34 { 35 return "_groebnercone"; 36 } 37 main()38 int main() 39 { 40 IntegerVectorList equalities; 41 IntegerVectorList normals; 42 int n; 43 44 if(optionVectorInput.getValue()) 45 { 46 FileParser P(Stdin); 47 n=P.parseInt(); 48 normals=P.parseIntegerVectorList(); 49 equalities=P.parseIntegerVectorList(); 50 } 51 else 52 { 53 PolynomialSet m=FileParser(Stdin).parsePolynomialSetWithRing(); 54 PolynomialSet g(m.getRing()); 55 if(optionPair.getValue()) 56 { 57 g=FileParser(Stdin).parsePolynomialSet(m.getRing()); 58 } 59 else 60 { 61 g=m; 62 m=g.markedTermIdeal(); 63 } 64 65 { 66 //Check that markings are consistent 67 PolynomialSet M1=g.markedTermIdeal(); 68 PolynomialSet M2=m.markedTermIdeal(); 69 assert(M1.size()==M2.size()); 70 PolynomialSet::const_iterator i1=M1.begin(); 71 for(PolynomialSet::const_iterator i2=M2.begin();i2!=M2.end();i1++,i2++) 72 { 73 assert((*i1-*i2).isZero()); 74 } 75 } 76 77 n=g.getRing().getNumberOfVariables(); 78 79 equalities=wallInequalities(m); 80 normals=(wallInequalities(g)); 81 if(optionRestrict.getValue()) 82 { 83 for(int i=0;i<n;i++) 84 normals.push_back(IntegerVector::standardVector(n,i)); 85 } 86 } 87 88 89 90 { 91 FieldMatrix A=integerMatrixToFieldMatrix(rowsToIntegerMatrix(equalities,n),Q); 92 A.reduce(); 93 A.removeZeroRows(); 94 equalities=IntegerVectorList(); 95 for(int i=0;i<A.getHeight();i++) 96 equalities.push_back(A[i].primitive()); 97 98 set<IntegerVector> newInequalities; 99 for(IntegerVectorList::const_iterator i=normals.begin();i!=normals.end();i++) 100 newInequalities.insert(A.canonicalize(integerVectorToFieldVector(*i,Q)).primitive()); 101 102 normals=IntegerVectorList(); 103 for(set<IntegerVector>::const_iterator i=newInequalities.begin();i!=newInequalities.end();i++) 104 normals.push_back(*i); 105 } 106 107 108 log1 fprintf(Stderr,"Inequalities"); 109 log1 AsciiPrinter(Stderr).printVectorList(normals); 110 log1 fprintf(Stderr,"Equations"); 111 log1 AsciiPrinter(Stderr).printVectorList(equalities); 112 113 PolyhedralCone c(normals,equalities,n); 114 c.canonicalize(); 115 if(!optionAsFan.getValue()) 116 AsciiPrinter(Stdout).printPolyhedralCone(c); 117 else 118 { 119 AsciiPrinter P(Stdout); 120 IntegerVectorList empty; 121 HalfOpenCone C(n,c.getEquations(),c.getHalfSpaces(),empty,true); 122 // PolyhedralFan F=faceComplexOfCone(C); 123 PolyhedralCone C2=C.closure(); 124 C2.canonicalize(); 125 PolyhedralFan F(n);F.insert(C2); 126 F.printWithIndices(&P,FPF_default); 127 // F.printWithIndices(&P,false,0,false,false,optionXml.getValue()); 128 } 129 130 return 0; 131 } 132 }; 133 134 static GroebnerConeApplication theApplication; 135 136