Polynomial.h
Go to the documentation of this file.
/* Frobby: Software for monomial ideal computations.
Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
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, see http://www.gnu.org/licenses/.
*/
#ifndef POLYNOMIAL_GUARD
#define POLYNOMIAL_GUARD
#include "Term.h"
#include <vector>
class Polynomial {
public:
Polynomial();
Polynomial(size_t varCount);
size_t getVarCount() const;
size_t getTermCount() const;
const mpz_class& getCoef(size_t index) const;
const Term& getTerm(size_t index) const;
// Add coef*term to the polynomial. Does not collect terms with the
// same exponents. Does nothing if coef is zero.
void add(const mpz_class& coef, const Term& term);
// Sort the terms in reverse lexicographic order. Also adds
// same-monomial terms and removes zero coefficients if collect is
// true.
void sortTermsReverseLex(bool collect = true);
void clear();
void clearAndSetVarCount(size_t varCount);
void print(FILE* out);
void print(ostream& out);
private:
struct CoefTerm {
bool operator<(const CoefTerm& coefTerm) const;
mpz_class coef;
Term term;
};
vector<CoefTerm> _terms;
size_t _varCount;
};
#endif
Term.h
Polynomial::clearAndSetVarCount
void clearAndSetVarCount(size_t varCount)
Definition Polynomial.cpp:50
Polynomial::getTermCount
size_t getTermCount() const
Definition Polynomial.cpp:36
Polynomial::print
void print(FILE *out)
Definition Polynomial.cpp:110
Polynomial::getVarCount
size_t getVarCount() const
Definition Polynomial.cpp:32
Polynomial::getTerm
const Term & getTerm(size_t index) const
Definition Polynomial.cpp:45
Polynomial::_terms
vector< CoefTerm > _terms
Definition Polynomial.h:57
Polynomial::Polynomial
Polynomial()
Definition Polynomial.cpp:24
Polynomial::sortTermsReverseLex
void sortTermsReverseLex(bool collect=true)
Definition Polynomial.cpp:71
Polynomial::clear
void clear()
Definition Polynomial.cpp:106
Polynomial::_varCount
size_t _varCount
Definition Polynomial.h:58
Polynomial::add
void add(const mpz_class &coef, const Term &term)
Definition Polynomial.cpp:55
Polynomial::getCoef
const mpz_class & getCoef(size_t index) const
Definition Polynomial.cpp:40
Term
Term represents a product of variables which does not include a coefficient.
Definition Term.h:49
Polynomial::CoefTerm
Definition Polynomial.h:50
Polynomial::CoefTerm::coef
mpz_class coef
Definition Polynomial.h:53
Polynomial::CoefTerm::operator<
bool operator<(const CoefTerm &coefTerm) const
Definition Polynomial.cpp:101
Polynomial::CoefTerm::term
Term term
Definition Polynomial.h:54