/* Copyright (c) 1997-2010
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Darmstadt, Germany)
   http://www.polymake.de

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
--------------------------------------------------------------------------------
   $Project: polymake $$Id: points2hypersurface.cc 10083 2011-03-23 10:59:34Z joswig $
*/

#include "polymake/client.h"
#include "polymake/tropical/liftings.h"

namespace polymake { namespace tropical {

perl::Object points2hypersurface(const Matrix<Rational>& points)
{
  const int n=points.cols();
  PuiseuxRing r(n);
  PuiseuxPolynomial poly(PuiseuxRing::coefficient_type(1), r);
  //  cerr << "main: poly = " << poly << endl;
  for (Entire<Rows<Matrix<Rational > > >::const_iterator i=entire(rows(points)); !i.at_end();++i) {
    poly*=pointlift(-(*i),r);
    //    cerr << "main: poly = " << poly << endl;
  }
  perl::Object h("tropical::TropicalHypersurface");
  const TropicalPolynomial tpoly=tropicalize(poly);
  h.take("MONOMIALS") << tpoly.first;
  h.take("COEFFICIENTS") << tpoly.second;

  return h;
}
    
UserFunction4perl("# @category Other"
                  "# Constructs a tropical hypersurface defined by the linear"
                  "# hypersurfaces associated to the points."
                  "# @param Matrix<Rational> points"
                  "# @return TropicalHypersurface",
                   &points2hypersurface, "points2hypersurface");
} }

// Local Variables:
// mode:C++
// c-basic-offset:3
// indent-tabs-mode:nil
// End:
