/* 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: newton.cc 9512 2010-02-28 22:24:19Z herr $
*/

#include <Rational.h>
#include <Polynomial.h>
#include <Matrix.h>
#include <polymake.h>

namespace polymake { namespace polytope {

template <typename Coefficient, typename Exponent>
perl::Object newton(const Polynomial<Coefficient,Exponent>& p)
{
   perl::Object np("LatticePolytope");
   np.set_description() << "Newton polytope of " << p << endl;

   const Matrix<Exponent> exps(p.template monomials_as_matrix< Matrix<Exponent> >());
   const int n=exps.rows();
   const int d=exps.cols();

   np.take("POINTS") << (same_element_vector(1,n) | exps);
   np.take("AMBIENT_DIM") << d;
   np.take("BOUNDED") << true;

   return np;
}

UserFunctionTemplate4perl("# @category Producing from scratch"
		          "# Produce the Newton polytope of a polynomial //p//."
			  "# @param Polynomial p"
			  "# @return LatticePolytope",
		          "newton(Polynomial)");
} }
