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
Views: 418425/*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#ifndef CONE_H_24#define CONE_H_2526#include <sys/stat.h>27#include <vector>28#include <map>29#include <utility> //for pair30#include <boost/dynamic_bitset.hpp>3132#include <libnormaliz/libnormaliz.h>33#include <libnormaliz/cone_property.h>34#include <libnormaliz/sublattice_representation.h>35#include <libnormaliz/matrix.h>36#include <libnormaliz/HilbertSeries.h>3738namespace libnormaliz {39using std::vector;40using std::map;41using std::pair;4243template<typename Integer> class Full_Cone;44//template<typename Integer> class Matrix;4546// type for simplex, short in contrast to class Simplex47template<typename Integer> struct SHORTSIMPLEX {48vector<key_t> key; // full key of simplex49Integer height; // height of last vertex over opposite facet50Integer vol; // volume if computed, 0 else51vector<bool> Excluded; // for disjoint decomposition of cone52// true in position i indictate sthat the facet53// opposite of generator i must be excluded54};5556template<typename Integer>57bool compareKeys(const SHORTSIMPLEX<Integer>& A, const SHORTSIMPLEX<Integer>& B){5859return(A.key < B.key);60}6162struct STANLEYDATA_int { // for internal use63vector<key_t> key;64Matrix<long> offsets;65vector<long> degrees; // degrees and classNr are used in nmz_integral.cpp66size_t classNr; // number of class of this simplicial cone67};6869template<typename Integer> struct STANLEYDATA {70vector<key_t> key;71Matrix<Integer> offsets;72};7374template<typename Integer>75class Cone {7677//---------------------------------------------------------------------------78// public methods79//---------------------------------------------------------------------------80public:8182//---------------------------------------------------------------------------83// Constructors, they preprocess the input84//---------------------------------------------------------------------------8586Cone(); //default constructor8788/* give up to 3 matrices as input89* the types must be pairwise different90*/91Cone(InputType type, const vector< vector<Integer> >& input_data);9293Cone(InputType type1, const vector< vector<Integer> >& input_data1,94InputType type2, const vector< vector<Integer> >& input_data2);9596Cone(InputType type1, const vector< vector<Integer> >& input_data1,97InputType type2, const vector< vector<Integer> >& input_data2,98InputType type3, const vector< vector<Integer> >& input_data3);99100/* give multiple input */101Cone(const map< InputType , vector< vector<Integer> > >& multi_input_data);102103//-----------------------------------------------------------------------------104// the same for mpq_class105106Cone(InputType type, const vector< vector<mpq_class> >& input_data);107108Cone(InputType type1, const vector< vector<mpq_class> >& input_data1,109InputType type2, const vector< vector<mpq_class> >& input_data2);110111Cone(InputType type1, const vector< vector<mpq_class> >& input_data1,112InputType type2, const vector< vector<mpq_class> >& input_data2,113InputType type3, const vector< vector<mpq_class> >& input_data3);114115/* give multiple input */116Cone(const map< InputType , vector< vector<mpq_class> > >& multi_input_data);117118//-----------------------------------------------------------------------------119// the same for nmz_float120121Cone(InputType type, const vector< vector<nmz_float> >& input_data);122123Cone(InputType type1, const vector< vector<nmz_float> >& input_data1,124InputType type2, const vector< vector<nmz_float> >& input_data2);125126Cone(InputType type1, const vector< vector<nmz_float> >& input_data1,127InputType type2, const vector< vector<nmz_float> >& input_data2,128InputType type3, const vector< vector<nmz_float> >& input_data3);129130/* give multiple input */131Cone(const map< InputType , vector< vector<nmz_float> > >& multi_input_data);132133//-----------------------------------------------------------------------------134// Now with Matrix135136Cone(InputType type, const Matrix<Integer>& input_data);137138Cone(InputType type1, const Matrix<Integer>& input_data1,139InputType type2, const Matrix<Integer>& input_data2);140141Cone(InputType type1, const Matrix<Integer>& input_data1,142InputType type2, const Matrix<Integer>& input_data2,143InputType type3, const Matrix<Integer>& input_data3);144145/* give multiple input */146Cone(const map< InputType , Matrix<Integer> >& multi_input_data);147148//-----------------------------------------------------------------------------149// Now with Matrix and mpq_class150151Cone(InputType type, const Matrix<mpq_class>& input_data);152153Cone(InputType type1, const Matrix<mpq_class>& input_data1,154InputType type2, const Matrix<mpq_class>& input_data2);155156Cone(InputType type1, const Matrix<mpq_class>& input_data1,157InputType type2, const Matrix<mpq_class>& input_data2,158InputType type3, const Matrix<mpq_class>& input_data3);159160/* give multiple input */161Cone(const map< InputType , Matrix<mpq_class> >& multi_input_data);162163//-----------------------------------------------------------------------------164// Now with Matrix and nmz_float165166Cone(InputType type, const Matrix<nmz_float>& input_data);167168Cone(InputType type1, const Matrix<nmz_float>& input_data1,169InputType type2, const Matrix<nmz_float>& input_data2);170171Cone(InputType type1, const Matrix<nmz_float>& input_data1,172InputType type2, const Matrix<nmz_float>& input_data2,173InputType type3, const Matrix<nmz_float>& input_data3);174175/* give multiple input */176Cone(const map< InputType , Matrix<nmz_float> >& multi_input_data);177178179//---------------------------------------------------------------------------180// Destructor181//---------------------------------------------------------------------------182183~Cone();184185//---------------------------------------------------------------------------186// give additional data187//---------------------------------------------------------------------------188189/* Sets if the Cone prints verbose output.190* The default value for the Cone is the global verbose.191* returns the old value192*/193bool setVerbose (bool v);194195void deactivateChangeOfPrecision();196197//---------------------------------------------------------------------------198// make computations199//---------------------------------------------------------------------------200201// return what was NOT computed202// ConeProperties compute(ComputationMode mode = Mode::hilbertBasisSeries); //default: everything203ConeProperties compute_inner(ConeProperties ToCompute);204// special case for up to 3 CPs205ConeProperties compute(ConeProperties ToCompute);206ConeProperties compute(ConeProperty::Enum);207ConeProperties compute(ConeProperty::Enum, ConeProperty::Enum);208ConeProperties compute(ConeProperty::Enum, ConeProperty::Enum, ConeProperty::Enum);209210//---------------------------------------------------------------------------211// check what is computed212//---------------------------------------------------------------------------213214bool isComputed(ConeProperty::Enum prop) const;215//returns true, when ALL properties in CheckComputed are computed216bool isComputed(ConeProperties CheckComputed) const;217218void resetComputed(ConeProperty::Enum prop);219220//---------------------------------------------------------------------------221// get the results, these methods will start a computation if necessary222// throws an NotComputableException if not succesful223//---------------------------------------------------------------------------224225// dimension and rank invariants226size_t getEmbeddingDim() const { return dim; }; // is always known227size_t getRank(); // depends on ExtremeRays228Integer getIndex(); // depends on OriginalMonoidGenerators229Integer getInternalIndex(); // = getIndex()230Integer getUnitGroupIndex(); // ditto231// only for inhomogeneous case:232size_t getRecessionRank();233long getAffineDim();234size_t getModuleRank();235236Cone<Integer>& getIntegerHullCone() const;237Cone<Integer>& getSymmetrizedCone() const;238239const Matrix<Integer>& getGeneratorsMatrix();240const vector< vector<Integer> >& getGenerators();241size_t getNrGenerators();242243const Matrix<Integer>& getExtremeRaysMatrix();244const vector< vector<Integer> >& getExtremeRays();245size_t getNrExtremeRays();246247const Matrix<nmz_float>& getVerticesFloatMatrix();248const vector< vector<nmz_float> >& getVerticesFloat();249size_t getNrVerticesFloat();250251const Matrix<Integer>& getVerticesOfPolyhedronMatrix();252const vector< vector<Integer> >& getVerticesOfPolyhedron();253size_t getNrVerticesOfPolyhedron();254255const Matrix<Integer>& getSupportHyperplanesMatrix();256const vector< vector<Integer> >& getSupportHyperplanes();257size_t getNrSupportHyperplanes();258259const Matrix<Integer>& getMaximalSubspaceMatrix();260const vector< vector<Integer> >& getMaximalSubspace();261size_t getDimMaximalSubspace();262263// depends on the ConeProperty::s SupportHyperplanes and Sublattice264map< InputType, vector< vector<Integer> > > getConstraints();265266const Matrix<Integer>& getExcludedFacesMatrix();267const vector< vector<Integer> >& getExcludedFaces();268size_t getNrExcludedFaces();269270size_t getTriangulationSize();271Integer getTriangulationDetSum();272273vector<Integer> getWitnessNotIntegrallyClosed();274vector<Integer> getGeneratorOfInterior();275276const Matrix<Integer>& getHilbertBasisMatrix();277const vector< vector<Integer> >& getHilbertBasis();278size_t getNrHilbertBasis();279280const Matrix<Integer>& getModuleGeneratorsOverOriginalMonoidMatrix();281const vector< vector<Integer> >& getModuleGeneratorsOverOriginalMonoid();282size_t getNrModuleGeneratorsOverOriginalMonoid();283284const Matrix<Integer>& getModuleGeneratorsMatrix();285const vector< vector<Integer> >& getModuleGenerators();286size_t getNrModuleGenerators();287288const Matrix<Integer>& getDeg1ElementsMatrix();289const vector< vector<Integer> >& getDeg1Elements();290size_t getNrDeg1Elements();291292// the actual grading is Grading/GradingDenom293vector<Integer> getGrading();294Integer getGradingDenom();295296vector<Integer> getDehomogenization();297298vector<Integer> getClassGroup();299300mpq_class getMultiplicity();301mpq_class getVirtualMultiplicity();302mpq_class getIntegral();303const pair<HilbertSeries, mpz_class>& getWeightedEhrhartSeries();304305string getPolynomial() const;306307bool inequalities_present;308309bool isPointed();310bool isInhomogeneous();311bool isDeg1ExtremeRays();312bool isDeg1HilbertBasis();313bool isIntegrallyClosed();314bool isGorenstein();315bool isReesPrimary();316Integer getReesPrimaryMultiplicity();317const Matrix<Integer>& getOriginalMonoidGeneratorsMatrix();318const vector< vector<Integer> >& getOriginalMonoidGenerators();319size_t getNrOriginalMonoidGenerators();320321const Sublattice_Representation<Integer>& getSublattice();322const HilbertSeries& getHilbertSeries(); //general purpose object323324// the following 2 methods give information about the last used triangulation325// if no triangulation was computed so far they return false326bool isTriangulationNested();327bool isTriangulationPartial();328const vector< pair<vector<key_t>, Integer> >& getTriangulation();329const vector< vector<bool> >& getOpenFacets();330const vector< pair<vector<key_t>, long> >& getInclusionExclusionData();331const list< STANLEYDATA<Integer> >& getStanleyDec();332list< STANLEYDATA_int >& getStanleyDec_mutable(); //allows us to erase the StanleyDec333// in order to save memeory for weighted Ehrhart334335void set_project(string name);336void set_nmz_call(const string& path);337void set_output_dir(string name);338339void setPolynomial(string poly);340void setNrCoeffQuasiPol(long nr_coeff);341342bool get_verbose ();343344IntegrationData& getIntData();345346//---------------------------------------------------------------------------347// private part348//---------------------------------------------------------------------------349350private:351352bool already_in_compute; // protection against call of compute within compute353// such calls must go via recursive_compute.354355string project;356string output_dir;357string nmz_call;358size_t dim;359360// the following three matrices store the constraints of the input361Matrix<Integer> Inequalities;362Matrix<Integer> Equations;363Matrix<Integer> Congruences;364// we must register some information about thew input365bool lattice_ideal_input;366size_t nr_latt_gen, nr_cone_gen; // they count matrices in the input367368Sublattice_Representation<Integer> BasisChange; //always use compose_basis_change() !369Sublattice_Representation<Integer> BasisChangePointed; // to the pointed cone370bool BC_set;371bool verbose;372ConeProperties is_Computed;373// Matrix<Integer> GeneratorsOfToricRing;374Matrix<Integer> OriginalMonoidGenerators;375Matrix<Integer> Generators;376Matrix<Integer> ExtremeRays;377Matrix<nmz_float> VerticesFloat;378vector<bool> ExtremeRaysIndicator;379Matrix<Integer> VerticesOfPolyhedron;380Matrix<Integer> SupportHyperplanes;381Matrix<Integer> ExcludedFaces;382Matrix<Integer> PreComputedSupportHyperplanes;383size_t TriangulationSize;384Integer TriangulationDetSum;385bool triangulation_is_nested;386bool triangulation_is_partial;387vector< pair<vector<key_t>, Integer> > Triangulation;388vector<vector<bool> > OpenFacets;389vector< pair<vector<key_t>, long> > InExData;390list< STANLEYDATA_int > StanleyDec;391list< STANLEYDATA<Integer> > StanleyDec_export;392mpq_class multiplicity;393mpq_class Integral;394mpq_class VirtualMultiplicity;395vector<Integer> WitnessNotIntegrallyClosed;396vector<Integer> GeneratorOfInterior;397Matrix<Integer> HilbertBasis;398Matrix<Integer> BasisMaxSubspace;399Matrix<Integer> ModuleGeneratorsOverOriginalMonoid;400Matrix<Integer> Deg1Elements;401HilbertSeries HSeries;402IntegrationData IntData;403vector<Integer> Grading;404vector<Integer> Dehomogenization;405Integer GradingDenom;406Integer index; // the internal index407Integer unit_group_index;408409vector<boost::dynamic_bitset<> > Pair; // for indicator vectors in project-and_lift410vector<boost::dynamic_bitset<> > ParaInPair; // if polytope is a parallelotope411bool check_parallelotope();412413bool pointed;414bool inhomogeneous;415bool gorensetin;416bool deg1_extreme_rays;417bool deg1_hilbert_basis;418bool integrally_closed;419bool Gorenstein;420bool rees_primary;421Integer ReesPrimaryMultiplicity;422int affine_dim; //dimension of polyhedron423size_t recession_rank; // rank of recession monoid424size_t module_rank; // for the inhomogeneous case425Matrix<Integer> ModuleGenerators;426vector<Integer> ClassGroup;427428bool is_approximation;429Cone* ApproximatedCone;430431// some properties of the current computation taken from ToCompute432bool explicit_HilbertSeries; // true = Hilbert series set explicitly and not only via default mode433bool naked_dual; // true = dual mode set, but neither Hilbert basis nor deg 1 points434bool default_mode; // true default mode set435436Matrix<Integer> WeightsGrad;437vector<bool> GradAbs;438439bool no_lattice_restriction; // true if cine generators are known to be in the relevant lattice440bool normalization; // true if input type normalization is used441442// if this is true we allow to change to a smaller integer type in the computation443bool change_integer_type;444445Cone<Integer>* IntHullCone;446Cone<Integer>* SymmCone;447448// In cone based algorithms we use the following information449bool Grading_Is_Coordinate; // indicates that the grading or dehomogenization is a coordinate450key_t GradingCoordinate; // namely this one451452void compose_basis_change(const Sublattice_Representation<Integer>& SR); // composes SR453454// main input processing455void process_multi_input(const map< InputType, vector< vector<Integer> > >& multi_input_data);456void process_multi_input_inner(map< InputType, vector< vector<Integer> > >& multi_input_data);457void process_multi_input(const map< InputType, vector< vector<mpq_class> > >& multi_input_data);458void process_multi_input(const map< InputType, vector< vector<nmz_float> > >& multi_input_data);459460void prepare_input_lattice_ideal(map< InputType, vector< vector<Integer> > >& multi_input_data);461void prepare_input_constraints(const map< InputType, vector< vector<Integer> > >& multi_input_data);462void prepare_input_generators(map< InputType, vector< vector<Integer> > >& multi_input_data,463Matrix<Integer>& LatticeGenerators);464void homogenize_input(map< InputType, vector< vector<Integer> > >& multi_input_data);465void check_precomputed_support_hyperplanes();466void check_excluded_faces();467468void setGrading (const vector<Integer>& lf);469void setWeights ();470void setDehomogenization (const vector<Integer>& lf);471void checkGrading();472void checkDehomogenization();473void check_vanishing_of_grading_and_dehom();474void process_lattice_data(const Matrix<Integer>& LatticeGenerators, Matrix<Integer>& Congruences, Matrix<Integer>& Equations);475476ConeProperties recursive_compute(ConeProperties ToCompute);477478void try_symmetrization(ConeProperties& ToCompute);479void try_approximation_or_projection (ConeProperties& ToCompute);480481Matrix<Integer> prepare_input_type_2(const vector< vector<Integer> >& Input);482Matrix<Integer> prepare_input_type_3(const vector< vector<Integer> >& Input);483void prepare_input_type_4(Matrix<Integer>& Inequalities);484485/* only used by the constructors */486void initialize();487488template<typename IntegerFC>489void compute_full_cone(ConeProperties& ToCompute);490491/* compute the generators using the support hyperplanes */492void compute_generators();493template<typename IntegerFC>494void compute_generators_inner();495496/* compute method for the dual_mode, used in compute(mode) */497void compute_dual(ConeProperties& ToCompute);498template<typename IntegerFC>499void compute_dual_inner(ConeProperties& ToCompute);500501void set_implicit_dual_mode(ConeProperties& ToCompute);502503/* extract the data from Full_Cone, this may remove data from Full_Cone!*/504template<typename IntegerFC>505void extract_data(Full_Cone<IntegerFC>& FC);506template<typename IntegerFC>507void extract_supphyps(Full_Cone<IntegerFC>& FC);508509void extract_supphyps(Full_Cone<Integer>& FC);510511512/* set OriginalMonoidGenerators */513void set_original_monoid_generators(const Matrix<Integer>&);514515/* set ExtremeRays, in inhomogeneous case also VerticesOfPolyhedron */516void set_extreme_rays(const vector<bool>&);517518/* If the Hilbert basis and the original monoid generators are computed,519* use them to check whether the original monoid is integrally closed. */520void check_integrally_closed();521void compute_unit_group_index();522/* try to find a witness for not integrally closed in the Hilbert basis */523void find_witness();524525void check_Gorenstein (ConeProperties& ToCompute);526527Integer compute_primary_multiplicity();528template<typename IntegerFC>529Integer compute_primary_multiplicity_inner();530531void compute_integer_hull();532void complete_sublattice_comp(ConeProperties& ToCompute); // completes the sublattice computations533void complete_HilbertSeries_comp(ConeProperties& ToCompute);534535void compute_integral (ConeProperties& ToCompute);536void compute_virt_mult (ConeProperties& ToCompute);537void compute_weighted_Ehrhart(ConeProperties& ToCompute);538539void compute_vertices_float(ConeProperties& ToCompute);540541void make_StanleyDec_export();542543void NotComputable (string message); // throws NotComputableException if default_mode = false544545void set_parallelization();546547template<typename IntegerFC>548void give_data_of_approximated_cone_to(Full_Cone<IntegerFC>& FC);549550void project_and_lift(Matrix<Integer>& Deg1, const Matrix<Integer>& Gens, Matrix<Integer>& Supps, bool float_projection);551552};553554// helpers555556template<typename Integer>557vector<vector<Integer> > find_input_matrix(const map< InputType, vector< vector<Integer> > >& multi_input_data,558const InputType type);559560template<typename Integer>561void insert_zero_column(vector< vector<Integer> >& mat, size_t col);562563template<typename Integer>564void insert_column(vector< vector<Integer> >& mat, size_t col, Integer entry);565566567} //end namespace libnormaliz568569#endif /* CONE_H_ */570571572