Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Path: gap4r8 / pkg / NormalizInterface-1.0.2 / Normaliz.git / DST / include / libnormaliz / HilbertSeries.h
Views: 418452/*1* Normaliz2* Copyright (C) 2007-2014 Winfried Bruns, Bogdan Ichim, Christof Soeger3* This program is free software: you can redistribute it and/or modify4* it under the terms of the GNU General Public License as published by5* the Free Software Foundation, either version 3 of the License, or6* (at your option) any later version.7*8* This program is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11* GNU General Public License for more details.12*13* You should have received a copy of the GNU General Public License14* along with this program. If not, see <http://www.gnu.org/licenses/>.15*16* As an exception, when this program is distributed through (i) the App Store17* by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or (iii) Google Play18* by Google Inc., then that store may impose any digital rights management,19* device limits and/or redistribution restrictions that are required by its20* terms of service.21*/2223/*24* HilbertSeries represents a Hilbert series of a (ZZ_+)-graded algebra25* with generators of different degrees.26* It is represented as a polynomial divided by a product of (1-t^i).27* The numerator is represented as vector of coefficients, the h-vector28* h vector repr.: sum of h[i]*t^i29* and the denominator is represented as a map d of the exponents of (1-t^i)30* d vector repr.: product of (1-t^i)^d[i] over i in d31* Input of the denominator is also possible as a vector of degrees of the32* generators.33*34* The class offers basic operations on the series, a simplification and35* different forms of representation of the series.36*37* Furthermore this file include operations for the polynomials used.38*/3940//---------------------------------------------------------------------------4142#ifndef HILBERT_SERIES_H43#define HILBERT_SERIES_H4445//---------------------------------------------------------------------------4647#include <vector>48#include <map>49#include <ostream>50#include <string>5152#include <libnormaliz/general.h>5354//---------------------------------------------------------------------------5556namespace libnormaliz {57using std::vector;58using std::map;59using std::ostream;60using std::string;61using std::pair;6263class HilbertSeries;6465// write a readable representation to the stream66ostream& operator<< (ostream& out, const HilbertSeries& HS);6768typedef long long num_t; //integer type for numerator69typedef long denom_t; //integer type for denominator7071class HilbertSeries {7273public:74// Constructor, creates 0/175HilbertSeries();76// Constructor, creates num/denom, see class description for format77HilbertSeries(const vector<num_t>& num, const vector<denom_t>& gen_degrees);78// Constructor, creates num/denom, see class description for format79HilbertSeries(const vector<mpz_class>& num, const map<long, denom_t>& denom);80// Constructor, string as created by to_string_rep81HilbertSeries(const string& str);8283// resets to 0/184void reset();8586// add another HilbertSeries to this87HilbertSeries& operator+=(const HilbertSeries& other);8889// add another HilbertSeries to this90void add(const vector<num_t>& num, const vector<denom_t>& gen_degrees);9192// simplify, see class description93// it changes the representation of the series, but not the series itself94// therefore it is declared const95void simplify() const;96// collect data from the denom_classes97void collectData() const;9899// returns the numerator, repr. as vector of coefficients, the h-vector100const vector<mpz_class>& getNum() const;101// returns the denominator, repr. as a map of the exponents of (1-t^i)^e102const map<long, denom_t>& getDenom() const;103104// returns the numerator, repr. as vector of coefficients105const vector<mpz_class>& getCyclotomicNum() const;106// returns the denominator, repr. as a map of the exponents of the cyclotomic polynomials107const map<long, denom_t>& getCyclotomicDenom() const;108109void setHSOPDenom(vector<denom_t> new_denom);110void setHSOPDenom(map<long,denom_t> new_denom);111112// returns the numerator, repr. as vector of coefficients113const vector<mpz_class>& getHSOPNum() const;114// returns the denominator, repr. as a map of the exponents of (1-t^i)^e115const map<long, denom_t>& getHSOPDenom() const;116117long getDegreeAsRationalFunction() const;118119long getPeriod() const;120121void computeHilbertQuasiPolynomial() const;122bool isHilbertQuasiPolynomialComputed() const;123vector< vector<mpz_class> > getHilbertQuasiPolynomial() const;124mpz_class getHilbertQuasiPolynomialDenom() const;125126// setting the shift will not change the numerator directly, only its interpretation127// the shift will be considered in the computation of the (quasi) polynomial128void setShift(long s);129// adjust the shift so that the series starts in degree 0130// it does not change the (quasi) polynomial131void adjustShift();132// returns the shift of the Hilbert series, that is the lowest degree of an element133long getShift() const;134135// methods for textual transfer of a Hilbert Series136string to_string_rep() const;137void from_string_rep(const string&);138139void setVerbose(bool v) { verbose = v; }140141// compute the new numerator by multiplying the HS with a denominator142// of the form (1-t^i)143void compute_hsop_num() const;144145void set_nr_coeff_quasipol(long nr_coeff);146long get_nr_coeff_quasipol() const;147148void set_period_bounded(bool on_off) const;149bool get_period_bounded() const;150151private:152153void initialize();154155// collected data in denominator classes156mutable map< vector<denom_t>, vector<num_t> > denom_classes;157// add the classes if they get too many158static const size_t DENOM_CLASSES_BOUND = 50000;159static const long PERIOD_BOUND = 1000000;160mutable bool period_bounded;161162// the numerator, repr. as vector of coefficients, the h-vector163mutable vector<mpz_class> num;164// the denominator, repr. as a map of the exponents of (1-t^i)^e165mutable map<long, denom_t> denom;166167// the numerator, repr. as vector of coefficients168mutable vector<mpz_class> cyclo_num;169// the denominator, repr. as a map of the exponents of the cyclotomic polynomials170mutable map<long, denom_t> cyclo_denom;171172// the numerator, repr. as vector of coefficients173mutable vector<mpz_class> hsop_num;174// the denominator, repr. as a map of the exponents of the cyclotomic polynomials175mutable map<long, denom_t> hsop_denom;176177mutable bool is_simplified;178mutable long dim;179mutable long period;180mutable long degree; // as rational function181long shift;182183// the quasi polynomial, can have big coefficients184mutable vector< vector<mpz_class> > quasi_poly;185mutable mpz_class quasi_denom;186mutable long nr_coeff_quasipol; // limits the computation of coefficients of the computeHilbertQuasiPolynomial187// <0: all coeff, =0: no coeff188189bool verbose;190191// these are only const when used properly!!192void performAdd(const vector<num_t>& num, const vector<denom_t>& gen_degrees) const;193void performAdd(vector<mpz_class>& num, const map<long, denom_t>& denom) const;194195void computeDegreeAsRationalFunction() const;196197198friend ostream& operator<< (ostream& out, const HilbertSeries& HS);199200};201//class end *****************************************************************202203204//---------------------------------------------------------------------------205// polynomial operations, for polynomials repr. as vector of coefficients206//---------------------------------------------------------------------------207208// a += b209template<typename Integer>210void poly_add_to (vector<Integer>& a, const vector<Integer>& b);211212// a += b*t^m213template<typename Integer>214void poly_add_to_tm (vector<Integer>& a, const vector<Integer>& b,long m);215216// a -= b217template<typename Integer>218void poly_sub_to (vector<Integer>& a, const vector<Integer>& b);219220221// a * b222template<typename Integer>223vector<Integer> poly_mult(const vector<Integer>& a, const vector<Integer>& b);224225// a*b via Karatsuba226template<typename Integer>227vector<Integer> karatsubamult(const vector<Integer>& a, const vector<Integer>& b);228229// a *= (1-t^d)^e230template<typename Integer>231void poly_mult_to(vector<Integer>& a, long d, long e = 1);232233// a *= t^m234template<typename Integer>235void poly_mult_by_tm(vector<Integer>& a, long m);236237238// division with remainder, a = q * b + r239template<typename Integer>240void poly_div(vector<Integer>& q, vector<Integer>& r, const vector<Integer>& a, const vector<Integer>&b);241242243// remove leading zero coefficients, 0 polynomial leads to empty list244template<typename Integer>245void remove_zeros(vector<Integer>& a);246247248// Returns the n-th cyclotomic polynomial, all smaller are computed and stored.249// The n-th cyclotomic polynomial is the product of (X-w) over all250// n-th primitive roots of unity w.251template<typename Integer>252vector<Integer> cyclotomicPoly(long n);253254// returns the coefficient vector of 1-t^i255template<typename Integer>256vector<Integer> coeff_vector(size_t i);257258// substitutes t by (t-a), overwrites the polynomial!259template<typename Integer>260void linear_substitution(vector<Integer>& poly, const Integer& a);261262//---------------------------------------------------------------------------263// computing the Hilbert polynomial from h-vector264//---------------------------------------------------------------------------265266template<typename Integer>267vector<Integer> compute_e_vector(vector<Integer> h_vector, int dim);268269template<typename Integer>270vector<Integer> compute_polynomial(vector<Integer> h_vector, int dim);271272//---------------------------------------------------------------------------273// A class collecting integrals and weighted Ehrhart series274//---------------------------------------------------------------------------275276class IntegrationData{277278string polynomial;279long degree_of_polynomial;280bool polynomial_is_homogeneous;281mpq_class integral, virtual_multiplicity;282pair<HilbertSeries, mpz_class> weighted_Ehrhart_series; // the second component holds the common283// denominator of the coefficients in the numerator284public:285286void setIntegral(const mpq_class I);287void setVirtualMultiplicity(const mpq_class I);288void setWeightedEhrhartSeries(const pair<HilbertSeries, mpz_class>& E);289void setHomogeneity(const bool hom);290// void setCommonDenom(const mpq_class D);291void setDegreeOfPolynomial(const long d);292void set_nr_coeff_quasipol(long nr_coeff);293294string getPolynomial() const;295long getDegreeOfPolynomial() const;296mpq_class getIntegral() const;297mpq_class getVirtualMultiplicity() const;298const pair<HilbertSeries, mpz_class>& getWeightedEhrhartSeries() const;299bool isPolynomialHomogeneous() const;300mpz_class getNumeratorCommonDenom() const;301302const vector<mpz_class>& getNum_ZZ() const;303// returns the denominator, repr. as a map of the exponents of (1-t^i)^e304const map<long, denom_t>& getDenom() const;305306const vector<mpz_class>& getCyclotomicNum_ZZ() const;307// returns the denominator, repr. as a map of the exponents of the cyclotomic polynomials308const map<long, denom_t>& getCyclotomicDenom() const;309310void computeWeightedEhrhartQuasiPolynomial() const;311bool isWeightedEhrhartQuasiPolynomialComputed() const;312vector< vector<mpz_class> > getWeightedEhrhartQuasiPolynomial() const;313void computeWeightedEhrhartQuasiPolynomial();314mpz_class getWeightedEhrhartQuasiPolynomialDenom() const;315316IntegrationData(const string& poly);317IntegrationData();318}; // class end319320} //end namespace libnormaliz321322//---------------------------------------------------------------------------323#endif324//---------------------------------------------------------------------------325326327328