// // $Source: /cvsroot/gambit/gambit/sources/tools/enumpoly/monomial.imp,v $ // $Date: 2006/07/20 16:23:15 $ // $Revision: 1.5 $ // // DESCRIPTION: // Implementation of monomial classes // // This file is part of Gambit // Copyright (c) 2002, The Gambit Project // // 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 of the License, or // (at your option) any later version. // // 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. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "monomial.h" //-------------------------------------------------------------------------- // gMono -- constructors and destructor //-------------------------------------------------------------------------- template gMono::gMono(const gSpace* p, const T& x) : coef(x), exps(p) { } template gMono::gMono(const T& x, const exp_vect& e) : coef(x), exps(e) { if (x == (T)0) exps.ToZero(); } template gMono::gMono(const gMono& y) : coef(y.coef), exps(y.exps) { } template gMono::~gMono() { } //-------------------------------------------------------------------------- // gMono -- operators //-------------------------------------------------------------------------- template gMono& gMono::operator = (const gMono& y) { if (this != &y) { coef = y.coef; exps = y.exps; } return *this; } template bool gMono::operator == (const gMono& y) const { return (coef == y.coef && exps == y.exps); } template bool gMono::operator != (const gMono& y) const { return !(*this == y); } template gMono gMono::operator * (const gMono & y) const { return gMono(coef * y.coef,exps + y.exps); } template gMono gMono::operator / (const gMono& y) const { //assert ( y.coef != (T)0); return gMono(coef / y.coef,exps - y.exps); } template gMono gMono::operator + (const gMono & y) const { //assert (exps == y.exps); return gMono(coef + y.coef,exps); } template gMono& gMono::operator += (const gMono & y) { //assert (exps == y.exps); coef += y.coef; return *this; } template gMono& gMono::operator *= (const T& val) { coef *= val; return *this; } template gMono gMono::operator - () const { return gMono(-coef,exps); } //-------------------------------------------------------------------------- // gMono -- information //-------------------------------------------------------------------------- template const T &gMono::Coef() const { return coef; } template int gMono::Dmnsn() const { return exps.Dmnsn(); } template int gMono::TotalDegree() const { return exps.TotalDegree(); } template const exp_vect &gMono::ExpV() const { return exps; } template bool gMono::IsConstant() const { return exps.IsConstant(); } template bool gMono::IsMultiaffine() const { return exps.IsMultiaffine(); } template T gMono::Evaluate(const Gambit::Array& vals) const { T answer = Coef(); for (int i = 1; i <= Dmnsn(); i++) for (int j = 1; j <= exps[i]; j++) answer *= vals[i]; return answer; } template T gMono::Evaluate(const Gambit::Vector& vals) const { T answer = Coef(); for (int i = 1; i <= Dmnsn(); i++) for (int j = 1; j <= exps[i]; j++) answer *= vals[i]; return answer; }