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: 418384/*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 <vector>27#include <map>28#include <utility> //for pair29//#include <boost/dynamic_bitset.hpp>3031#include <libQnormaliz/libQnormaliz.h>32#include <libQnormaliz/Qcone_property.h>33#include <libQnormaliz/Qsublattice_representation.h>34#include <libQnormaliz/Qmatrix.h>35// #include <libQnormaliz/QHilbertSeries.h>3637namespace libQnormaliz {38using std::vector;39using std::map;40using std::pair;4142template<typename Number> class Full_Cone;43//template<typename Number> class Matrix;4445// type for simplex, short in contrast to class Simplex46template<typename Number> struct SHORTSIMPLEX {47vector<key_t> key; // full key of simplex48Number height; // height of last vertex over opposite facet49Number vol; // volume if computed, 0 else50vector<bool> Excluded; // for disjoint decomposition of cone51// true in position i indictate sthat the facet52// opposite of generator i must be excluded53};545556template<typename Number>57class Cone {5859//---------------------------------------------------------------------------60// public methods61//---------------------------------------------------------------------------62public:6364//---------------------------------------------------------------------------65// Constructors, they preprocess the input66//---------------------------------------------------------------------------6768/* give up to 3 matrices as input69* the types must be pairwise different70*/71Cone(InputType type, const vector< vector<Number> >& input_data);7273Cone(InputType type1, const vector< vector<Number> >& input_data1,74InputType type2, const vector< vector<Number> >& input_data2);7576Cone(InputType type1, const vector< vector<Number> >& input_data1,77InputType type2, const vector< vector<Number> >& input_data2,78InputType type3, const vector< vector<Number> >& input_data3);7980/* give multiple input */81Cone(const map< InputType , vector< vector<Number> > >& multi_input_data);8283// Now with Matrix84Cone(InputType type, const Matrix<Number>& input_data);8586Cone(InputType type1, const Matrix<Number>& input_data1,87InputType type2, const Matrix<Number>& input_data2);8889Cone(InputType type1, const Matrix<Number>& input_data1,90InputType type2, const Matrix<Number>& input_data2,91InputType type3, const Matrix<Number>& input_data3);9293/* give multiple input */94Cone(const map< InputType , Matrix<Number> >& multi_input_data);95//---------------------------------------------------------------------------96// Destructor97//---------------------------------------------------------------------------9899~Cone();100101//---------------------------------------------------------------------------102// give additional data103//---------------------------------------------------------------------------104105/* Sets if the Cone prints verbose output.106* The default value for the Cone is the global verbose.107* returns the old value108*/109bool setVerbose (bool v);110111//---------------------------------------------------------------------------112// make computations113//---------------------------------------------------------------------------114115// return what was NOT computed116// ConeProperties compute(ComputationMode mode = Mode::hilbertBasisSeries); //default: everything117ConeProperties compute(ConeProperties ToCompute);118// special case for up to 3 CPs119ConeProperties compute(ConeProperty::Enum);120ConeProperties compute(ConeProperty::Enum, ConeProperty::Enum);121ConeProperties compute(ConeProperty::Enum, ConeProperty::Enum, ConeProperty::Enum);122123//---------------------------------------------------------------------------124// check what is computed125//---------------------------------------------------------------------------126127bool isComputed(ConeProperty::Enum prop) const;128//returns true, when ALL properties in CheckComputed are computed129bool isComputed(ConeProperties CheckComputed) const;130131//---------------------------------------------------------------------------132// get the results, these methods will start a computation if necessary133// throws an NotComputableException if not succesful134//---------------------------------------------------------------------------135136// dimension and rank invariants137size_t getEmbeddingDim() const { return dim; }; // is always known138size_t getRank(); // depends on ExtremeRays139Number getIndex(); // depends on OriginalMonoidGenerators140Number getInternalIndex(); // = getIndex()141Number getUnitGroupIndex(); // ditto142// only for inhomogeneous case:143size_t getRecessionRank();144long getAffineDim();145size_t getModuleRank();146147const Matrix<Number>& getGeneratorsMatrix();148const vector< vector<Number> >& getGenerators();149size_t getNrGenerators();150151const Matrix<Number>& getExtremeRaysMatrix();152const vector< vector<Number> >& getExtremeRays();153size_t getNrExtremeRays();154155const Matrix<Number>& getVerticesOfPolyhedronMatrix();156const vector< vector<Number> >& getVerticesOfPolyhedron();157size_t getNrVerticesOfPolyhedron();158159const Matrix<Number>& getSupportHyperplanesMatrix();160const vector< vector<Number> >& getSupportHyperplanes();161size_t getNrSupportHyperplanes();162163const Matrix<Number>& getMaximalSubspaceMatrix();164const vector< vector<Number> >& getMaximalSubspace();165size_t getDimMaximalSubspace();166167// depends on the ConeProperty::s SupportHyperplanes and Sublattice168map< InputType, vector< vector<Number> > > getConstraints();169170size_t getTriangulationSize();171Number getTriangulationDetSum();172173// the actual grading is Grading/GradingDenom174vector<Number> getGrading();175Number getGradingDenom();176177vector<Number> getDehomogenization();178179bool inequalities_present;180181bool isPointed();182bool isInhomogeneous();183bool isDeg1ExtremeRays();184185const Matrix<Number>& getOriginalMonoidGeneratorsMatrix();186const vector< vector<Number> >& getOriginalMonoidGenerators();187size_t getNrOriginalMonoidGenerators();188189const Sublattice_Representation<Number>& getSublattice();190// the following 2 methods give information about the last used triangulation191// if no triangulation was computed so far they return false192bool isTriangulationNested();193bool isTriangulationPartial();194const vector< pair<vector<key_t>, Number> >& getTriangulation();195const vector< vector<bool> >& getOpenFacets();196197//---------------------------------------------------------------------------198// private part199//---------------------------------------------------------------------------200201private:202size_t dim;203204Sublattice_Representation<Number> BasisChange; //always use compose_basis_change() !205Sublattice_Representation<Number> BasisChangePointed; // to the pointed cone206bool BC_set;207bool verbose;208ConeProperties is_Computed;209// Matrix<Number> GeneratorsOfToricRing;210Matrix<Number> OriginalMonoidGenerators;211Matrix<Number> Generators;212Matrix<Number> ExtremeRays;213vector<bool> ExtremeRaysIndicator;214Matrix<Number> VerticesOfPolyhedron;215Matrix<Number> SupportHyperplanes;216Matrix<Number> ExcludedFaces;217Matrix<Number> PreComputedSupportHyperplanes;218size_t TriangulationSize;219Number TriangulationDetSum;220bool triangulation_is_nested;221bool triangulation_is_partial;222vector< pair<vector<key_t>, Number> > Triangulation;223vector<vector<bool> > OpenFacets;224vector< pair<vector<key_t>, long> > InExData;225// mpq_class multiplicity;226vector<Number> WitnessNotIntegrallyClosed;227Matrix<Number> HilbertBasis;228Matrix<Number> BasisMaxSubspace;229Matrix<Number> ModuleGeneratorsOverOriginalMonoid;230Matrix<Number> Deg1Elements;231232vector<Number> Grading;233vector<Number> Dehomogenization;234Number GradingDenom;235Number index; // the internal index236Number unit_group_index;237238bool pointed;239bool inhomogeneous;240241int affine_dim; //dimension of polyhedron242size_t recession_rank; // rank of recession monoid243size_t module_rank; // for the inhomogeneous case244Matrix<Number> ModuleGenerators;245246bool explicit_HilbertSeries;247bool naked_dual;248249Matrix<Number> WeightsGrad;250vector<bool> GradAbs;251252bool no_lattice_restriction; // true if cine generators are known to be in the relevant lattice253bool normalization; // true if input type normalization is used254255// if this is true we allow to change to a smaller integer type in the computation256bool change_integer_type;257258259void compose_basis_change(const Sublattice_Representation<Number>& SR); // composes SR260261// main input processing262void process_multi_input(const map< InputType, vector< vector<Number> > >& multi_input_data);263void prepare_input_lattice_ideal(map< InputType, vector< vector<Number> > >& multi_input_data);264void prepare_input_constraints(const map< InputType, vector< vector<Number> > >& multi_input_data,265Matrix<Number>& equations, Matrix<Number>& congruence, Matrix<Number>& Inequalities);266void prepare_input_generators(map< InputType, vector< vector<Number> > >& multi_input_data,267Matrix<Number>& LatticeGenerators);268void homogenize_input(map< InputType, vector< vector<Number> > >& multi_input_data);269void check_precomputed_support_hyperplanes();270271272void setWeights ();273void setDehomogenization (const vector<Number>& lf);274275void checkDehomogenization();276void check_vanishing_of_grading_and_dehom();277void process_lattice_data(const Matrix<Number>& LatticeGenerators, Matrix<Number>& Congruences, Matrix<Number>& Equations);278279ConeProperties recursive_compute(ConeProperties ToCompute);280281Matrix<Number> prepare_input_type_2(const vector< vector<Number> >& Input);282Matrix<Number> prepare_input_type_3(const vector< vector<Number> >& Input);283void prepare_input_type_4(Matrix<Number>& Inequalities);284285/* only used by the constructors */286void initialize();287288template<typename NumberFC>289void compute_inner(ConeProperties& ToCompute);290291/* compute the generators using the support hyperplanes */292void compute_generators();293template<typename NumberFC>294void compute_generators_inner();295296/* compute method for the dual_mode, used in compute(mode) */297void compute_dual(ConeProperties& ToCompute);298template<typename NumberFC>299void compute_dual_inner(ConeProperties& ToCompute);300301void set_implicit_dual_mode(ConeProperties& ToCompute);302303/* extract the data from Full_Cone, this may remove data from Full_Cone!*/304template<typename NumberFC>305void extract_data(Full_Cone<NumberFC>& FC);306template<typename NumberFC>307void extract_supphyps(Full_Cone<NumberFC>& FC);308309void extract_supphyps(Full_Cone<Number>& FC);310311312/* set OriginalMonoidGenerators */313void set_original_monoid_generators(const Matrix<Number>&);314315/* set ExtremeRays, in inhomogeneous case also VerticesOfPolyhedron */316void set_extreme_rays(const vector<bool>&);317318/* If the Hilbert basis and the original monoid generators are computed,319* use them to check whether the original monoid is integrally closed. */320void check_integrally_closed();321void compute_unit_group_index();322/* try to find a witness for not integrally closed in the Hilbert basis */323void find_witness();324325Number compute_primary_multiplicity();326template<typename NumberFC>327Number compute_primary_multiplicity_inner();328329void compute_integer_hull();330void complete_sublattice_comp(ConeProperties& ToCompute); // completes the sublattice computations331void complete_HilbertSeries_comp(ConeProperties& ToCompute);332333};334335// helpers336337template<typename Number>338vector<vector<Number> > find_input_matrix(const map< InputType, vector< vector<Number> > >& multi_input_data,339const InputType type);340341template<typename Number>342void insert_zero_column(vector< vector<Number> >& mat, size_t col);343344template<typename Number>345void insert_column(vector< vector<Number> >& mat, size_t col, Number entry);346347} //end namespace libQnormaliz348349#endif /* CONE_H_ */350351352