// // $Source: /cvsroot/gambit/gambit/sources/tools/enumpoly/ideal.imp,v $ // $Date: 2006/01/07 06:37:21 $ // $Revision: 1.5 $ // // DESCRIPTION: // Implementation of gIdeal // // 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 "ideal.h" //--------------------------------------------------------------- // gIdeal //--------------------------------------------------------------- //--------------------------- // Constructors / Destructors //--------------------------- template gIdeal::gIdeal(const gSpace * ls, const term_order * ordr) : Space(ls), order(ordr), basis(ls,ordr) { } template gIdeal::gIdeal(const gSpace * ls, const term_order * ordr, const Gambit::List< gPoly *> & polys) : Space(ls), order(ordr), basis(ls,ordr,polys) { } template gIdeal::gIdeal(const term_order * ordr, const gPolyList & bss) : Space(bss.AmbientSpace()), order(ordr), basis(bss) { basis.ToSortedReducedGrobner(*ordr); } template gIdeal::gIdeal(const gIdeal & ideal) : Space(ideal.Space), order(ideal.order), basis(ideal.basis) { } template gIdeal::~gIdeal() { } //---------------------------------- // Operators //---------------------------------- template gIdeal& gIdeal::operator=(const gIdeal & rhs) { assert (Space == rhs.Space); if (*this != rhs) { this->order = rhs.order; this->basis = rhs.basis; } return *this; } template bool gIdeal::operator==(const gIdeal & rhs) const { if (Space != rhs.Space) { return false; } else { if (*order == *(rhs.order)) { if (basis == rhs.basis) return true; else return false; } if (basis.Length() != rhs.basis.Length()) return false; else { // gPolyList reordered_rhs(rhs.basis,*order); // gPolyList reordered_rhs(rhs.basis); const gIdeal reordered_rhs(order,rhs.basis); if (basis == reordered_rhs.basis) return true; else return false; } } } template bool gIdeal::operator!=(const gIdeal & rhs) const { return !(*this == rhs); } template gIdeal gIdeal::operator+ (const gIdeal & rhs) const { Gambit::List *> combined; for (int i = 1; i <= basis.Length(); i++) { gPoly* temp = new gPoly(basis[i]); combined.Append(temp); } for (int j = 1; j <= rhs.basis.Length(); j++) { gPoly* temp = new gPoly(rhs.basis[j]); combined.Append(temp); } return gIdeal(Space,order,combined); } template gIdeal gIdeal::operator* (const gIdeal & rhs) const { Gambit::List *> basis_products; for (int i = 1; i <= basis.Length(); i++) for (int j = 1; j <= rhs.basis.Length(); j++) { gPoly* temp = new gPoly(basis[i] * rhs.basis[j]); basis_products.Append(temp); } return gIdeal(Space,order,basis_products); } //---------------------------------- // Information //---------------------------------- template gIdeal gIdeal::MonomialIdeal() const { gPolyList mon_bss(Space,order); for (int i = 1; i <= basis.Length(); i++) mon_bss += basis[i].LeadingTerm(*order); return gIdeal(order,mon_bss); } template Gambit::List gIdeal::MonomialBasis() const { Gambit::List answer; Gambit::Array MinIndices(Dmnsn()), MaxIndices(Dmnsn()); for (int i = 1; i <= Dmnsn(); i++) MinIndices[i] = 0; for (int j = 1; j <= basis.Length(); j++) { if (basis[j].LeadingPowerProduct(*order).IsUnivariate()) MaxIndices[basis[j].LeadingPowerProduct(*order).SoleActiveVariable()] = basis[j].LeadingPowerProduct(*order).TotalDegree() - 1; } gIndexOdometer odometer(MinIndices,MaxIndices); while (odometer.Turn()) { exp_vect candidate(Space,odometer.CurrentIndices()); bool add = true; for (int j = 1; j <= basis.Length(); j++) if (basis[j].LeadingPowerProduct(*order) <= candidate) add = false; if (add) answer.Append(candidate); } return answer; } template bool gIdeal::IsRoot(const Gambit::Vector& v) const { for (int i = 1; i <= basis.Length(); i++) if (basis[i].Evaluate(v) != (T)0) return false; return true; } template bool gIdeal::ZeroDimensional() const { if (Dmnsn() == 0) return true; Gambit::Array HasLeadingTermThatIsPowerOfVariable(Dmnsn()); int i; for (i = 1; i <= Dmnsn(); i++) HasLeadingTermThatIsPowerOfVariable[i] = false; for (int j = 1; j <= basis.Length(); j++) { if (basis[j].LeadingPowerProduct(*order).IsConstant()) return false; if (basis[j].LeadingPowerProduct(*order).IsUnivariate()) HasLeadingTermThatIsPowerOfVariable[ basis[j].LeadingPowerProduct(*order).SoleActiveVariable() ] = true; } for (i = 1; i <= Dmnsn(); i++) if (!HasLeadingTermThatIsPowerOfVariable[i]) return false; return true; } template bool gIdeal::Contains(gPoly & f) const { gPoly zero(Space,(T)0,order); return (basis.ReductionOf(f,*order) == zero); } template bool gIdeal::IsEntireRing() const { gPoly one(Space,(T)1,order); return Contains(one); }