#include "parser.h"
#include "printer.h"
#include "polynomial.h"
#include "division.h"
#include "buchberger.h"
#include "wallideal.h"
#include "lp.h"
#include "reversesearch.h"
#include "termorder.h"
#include "gfanapplication.h"
#include "wallideal.h"

class HomogenizeApplication : public GFanApplication
{
  SimpleOption optionIdeal;
  SimpleOption optionHomogenizationVector;
  FieldOption theFieldOption;
public:
  const char *helpText()
  {
    return "This program homogenises a list of polynomials by introducing an extra variable. Without the -w option the homogenisation is done with respect to total degree.\n";
  }
  HomogenizeApplication():
    optionIdeal("-i","Treat input as an ideal. This will make the program compute the homogenisation of the input ideal. This is done by computing a degree Groebner basis and homogenising it."),
    optionHomogenizationVector("-w","Specify a homogenisation vector. The length of the vector must be the same as the number of variables in the ring. The vector is read from the input after the list of polynomials.\n")
  {
    registerOptions();
  }
  
  char *name()
  {
    return "_homogenize";
  }

  int main()
  {
    LpSolver::printList(Stderr);
    lpSetSolver("cddgmp");
    
    FileParser P(Stdin);

    PolynomialSet g=P.parsePolynomialSet();

    IntegerVector grading;
    if(optionHomogenizationVector.getValue())
      grading=P.parseIntegerVector();
    else
      grading=IntegerVector::allOnes(g.numberOfVariablesInRing());

    if(optionIdeal.getValue())
      {
	WeightReverseLexicographicTermOrder t(grading); 
	buchberger(&g,t);
      }

    PolynomialSet h;


    for(PolynomialSet::const_iterator i=g.begin();i!=g.end();i++)
      {
	h.push_back(i->homogenization(-1,-1,&grading));
	//h.push_back(i->homogenization(-1,4));
      }
    
    AsciiPrinter(Stdout).printPolynomialSet(h);
    
    return 0;
  }
};

static HomogenizeApplication theApplication;
