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 / Qsource / libQnormaliz / Qcone_property.cpp
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#ifdef NMZ_MIC_OFFLOAD24#pragma offload_attribute (push, target(mic))25#endif2627#include <vector>28#include <string>29#include <assert.h>3031#include "libQnormaliz/Qcone_property.h"32#include "libQnormaliz/libQnormaliz.h"33#include "libQnormaliz/Qnormaliz_exception.h"3435namespace libQnormaliz {36using std::bitset;37using std::vector;38using std::string;39using std::endl;404142/* Constructors */43ConeProperties::ConeProperties() {44CPs = bitset<ConeProperty::EnumSize>();45}46ConeProperties::ConeProperties(ConeProperty::Enum p1) {47CPs = bitset<ConeProperty::EnumSize>();48CPs.set(p1);49}50ConeProperties::ConeProperties(ConeProperty::Enum p1, ConeProperty::Enum p2) {51CPs = bitset<ConeProperty::EnumSize>();52CPs.set(p1);53CPs.set(p2);54}55ConeProperties::ConeProperties(ConeProperty::Enum p1, ConeProperty::Enum p2,56ConeProperty::Enum p3) {57CPs = bitset<ConeProperty::EnumSize>();58CPs.set(p1);59CPs.set(p2);60CPs.set(p3);61}62ConeProperties::ConeProperties(const bitset<ConeProperty::EnumSize>& props){63CPs = props;64}6566/* set Properties */67ConeProperties& ConeProperties::set(ConeProperty::Enum p1, bool value) {68CPs.set(p1, value);69return *this;70}71ConeProperties& ConeProperties::set(ConeProperty::Enum p1, ConeProperty::Enum p2) {72CPs.set(p1);73CPs.set(p2);74return *this;75}76ConeProperties& ConeProperties::set(const ConeProperties& ConeProps) {77CPs ^= ConeProps.CPs;78return *this;79}8081ConeProperties& ConeProperties::set(const std::string s, bool value) {82CPs.set(toConeProperty(s), value);83return *this;84}8586/* reset (=unset) properties */87ConeProperties& ConeProperties::reset(ConeProperty::Enum Property) {88CPs.set(Property, false);89return *this;90}91ConeProperties& ConeProperties::reset(const ConeProperties& ConeProps) {92CPs &= ~ConeProps.CPs;93return *this;94}9596ConeProperties& ConeProperties::reset_compute_options() {97CPs.set(ConeProperty::Approximate, false);98CPs.set(ConeProperty::BottomDecomposition, false);99CPs.set(ConeProperty::NoBottomDec, false);100CPs.set(ConeProperty::DefaultMode, false);101CPs.set(ConeProperty::DualMode, false);102CPs.set(ConeProperty::KeepOrder, false);103CPs.set(ConeProperty::HSOP, false);104CPs.set(ConeProperty::Symmetrize, false);105CPs.set(ConeProperty::NoSymmetrization, false);106CPs.set(ConeProperty::PrimalMode, false);107CPs.set(ConeProperty::BigInt, false);108return *this;109}110111/* return a new ConeProperties object with only the goals/options set,112* which are set in this object113*/114ConeProperties ConeProperties::goals() {115ConeProperties ret(*this);116ret.reset_compute_options();117return ret;118}119ConeProperties ConeProperties::options() {120ConeProperties ret;121ret.set(ConeProperty::Approximate, CPs.test(ConeProperty::Approximate));122ret.set(ConeProperty::BottomDecomposition, CPs.test(ConeProperty::BottomDecomposition));123ret.set(ConeProperty::BottomDecomposition, CPs.test(ConeProperty::NoBottomDec));124ret.set(ConeProperty::DefaultMode, CPs.test(ConeProperty::DefaultMode));125ret.set(ConeProperty::DualMode, CPs.test(ConeProperty::DualMode));126ret.set(ConeProperty::KeepOrder, CPs.test(ConeProperty::KeepOrder));127ret.set(ConeProperty::HSOP, CPs.test(ConeProperty::HSOP));128ret.set(ConeProperty::Symmetrize, CPs.test(ConeProperty::Symmetrize));129ret.set(ConeProperty::NoSymmetrization, CPs.test(ConeProperty::NoSymmetrization));130ret.set(ConeProperty::PrimalMode, CPs.test(ConeProperty::PrimalMode));131return ret;132}133134/* test which/how many properties are set */135bool ConeProperties::test(ConeProperty::Enum Property) const {136return CPs.test(Property);137}138bool ConeProperties::any() const {139return CPs.any();140}141bool ConeProperties::none() const {142return CPs.none();143}144size_t ConeProperties::count() const {145return CPs.count();146}147148149/* add preconditions */150void ConeProperties::set_preconditions() {151if (CPs.test(ConeProperty::WitnessNotIntegrallyClosed))152CPs.set(ConeProperty::IsIntegrallyClosed);153154if (CPs.test(ConeProperty::IsDeg1HilbertBasis)) {155CPs.set(ConeProperty::HilbertBasis);156CPs.set(ConeProperty::Grading);157}158if (CPs.test(ConeProperty::IsDeg1ExtremeRays)) {159CPs.set(ConeProperty::ExtremeRays);160CPs.set(ConeProperty::Grading);161}162if (CPs.test(ConeProperty::Grading))163CPs.set(ConeProperty::Generators);164165if (CPs.test(ConeProperty::IsPointed))166CPs.set(ConeProperty::ExtremeRays);167168if (CPs.test(ConeProperty::ExtremeRays))169CPs.set(ConeProperty::SupportHyperplanes);170171if (CPs.test(ConeProperty::HSOP)){172CPs.set(ConeProperty::SupportHyperplanes);173CPs.set(ConeProperty::HilbertSeries);174}175// inhomogenous preconditions176if (CPs.test(ConeProperty::VerticesOfPolyhedron))177CPs.set(ConeProperty::ExtremeRays);178179if(CPs.test(ConeProperty::ModuleGeneratorsOverOriginalMonoid))180CPs.set(ConeProperty::HilbertBasis);181182if (CPs.test(ConeProperty::ModuleGenerators))183CPs.set(ConeProperty::HilbertBasis);184185if (CPs.test(ConeProperty::MaximalSubspace))186CPs.set(ConeProperty::SupportHyperplanes);187188// always189190if (CPs.test(ConeProperty::ExtremeRays))191CPs.set(ConeProperty::SupportHyperplanes);192}193194/* removes ignored compute options and sets implications */195void ConeProperties::prepare_compute_options(bool inhomogeneous) {196if (CPs.test(ConeProperty::NumberHull)){197if(inhomogeneous){198CPs.set(ConeProperty::HilbertBasis);199}200else{201CPs.set(ConeProperty::Deg1Elements);202}203}204// -d without -1 means: compute Hilbert basis in dual mode205if (CPs.test(ConeProperty::DualMode) && !CPs.test(ConeProperty::Deg1Elements)){206CPs.set(ConeProperty::HilbertBasis);207}208209if(CPs.test(ConeProperty::ModuleGeneratorsOverOriginalMonoid)) // can't be computed in dual mode210CPs.reset(ConeProperty::DualMode);211212// dual mode has priority, approximation makes no sense if HB is computed213if(CPs.test(ConeProperty::DualMode) || CPs.test(ConeProperty::HilbertBasis))214CPs.reset(ConeProperty::Approximate);215216if ((CPs.test(ConeProperty::DualMode) || CPs.test(ConeProperty::Approximate))217&& (CPs.test(ConeProperty::HilbertSeries) || CPs.test(ConeProperty::StanleyDec))218&& !CPs.test(ConeProperty::HilbertBasis)){219CPs.reset(ConeProperty::DualMode); //it makes no sense to compute only deg 1 elements in dual mode220CPs.reset(ConeProperty::Approximate); // or by approximation if the221} // Stanley decomposition must be computed anyway222if (CPs.test(ConeProperty::Approximate)223&& !CPs.test(ConeProperty::Deg1Elements)) {224errorOutput() << "WARNING: Approximate is ignored since Deg1Elements is not set."<< std::endl;225}226if (CPs.test(ConeProperty::ConeDecomposition))227CPs.set(ConeProperty::Triangulation);228229if (CPs.test(ConeProperty::GradingDenom))230CPs.reset(ConeProperty::Grading);231232if(CPs.test(ConeProperty::UnitGroupIndex))233CPs.set(ConeProperty::HilbertBasis);234235if(CPs.test(ConeProperty::Equations) || CPs.test(ConeProperty::Congruences) || CPs.test(ConeProperty::ExternalIndex))236CPs.set(ConeProperty::Sublattice);237238if(CPs.test(ConeProperty::Rank))239CPs.set(ConeProperty::Sublattice);240241if(CPs.test(ConeProperty::HilbertQuasiPolynomial))242CPs.set(ConeProperty::HilbertSeries);243244if(inhomogeneous && CPs.test(ConeProperty::SupportHyperplanes))245CPs.set(ConeProperty::AffineDim);246247if(CPs.test(ConeProperty::DefaultMode)){248CPs.set(ConeProperty::HilbertBasis);249CPs.set(ConeProperty::HilbertSeries);250if(!inhomogeneous)251CPs.set(ConeProperty::ClassGroup);252CPs.set(ConeProperty::SupportHyperplanes);253}254}255256void ConeProperties::check_Q_permissible() {257ConeProperties copy(*this);258copy.reset(ConeProperty::SupportHyperplanes);259copy.reset(ConeProperty::ExtremeRays);260copy.reset(ConeProperty::VerticesOfPolyhedron);261copy.reset(ConeProperty::KeepOrder);262copy.reset(ConeProperty::Triangulation);263copy.reset(ConeProperty::ConeDecomposition);264copy.reset(ConeProperty::DefaultMode);265copy.reset(ConeProperty::Generators);266copy.reset(ConeProperty::Sublattice);267copy.reset(ConeProperty::MaximalSubspace);268copy.reset(ConeProperty::Equations);269copy.reset(ConeProperty::Dehomogenization);270copy.reset(ConeProperty::Rank);271copy.reset(ConeProperty::EmbeddingDim);272copy.reset(ConeProperty::IsPointed);273copy.reset(ConeProperty::IsInhomogeneous);274copy.reset(ConeProperty::DefaultMode);275276//bvverboseOutput() << copy << endl;277if(copy.any())278throw BadInputException("Cone Property not allowd for field coefficients");279}280281282void ConeProperties::check_sanity(bool inhomogeneous) {283ConeProperty::Enum prop;284if(285(CPs.test(ConeProperty::BottomDecomposition) && CPs.test(ConeProperty::NoBottomDec))286|| (CPs.test(ConeProperty::DualMode) && CPs.test(ConeProperty::PrimalMode))287|| (CPs.test(ConeProperty::Symmetrize) && CPs.test(ConeProperty::NoSymmetrization))288)289throw BadInputException("Contradictory algorithmic variants in options.");290291if(CPs.test(ConeProperty::IsTriangulationNested) || CPs.test(ConeProperty::IsTriangulationPartial))292throw BadInputException("ConeProperty not allowed in compute().");293294for (size_t i=0; i<ConeProperty::EnumSize; i++) {295if (CPs.test(i)) {296prop = static_cast<ConeProperty::Enum>(i);297if (inhomogeneous) {298if ( prop == ConeProperty::Deg1Elements299|| prop == ConeProperty::StanleyDec300|| prop == ConeProperty::Triangulation301|| prop == ConeProperty::ConeDecomposition302|| prop == ConeProperty::IsIntegrallyClosed303|| prop == ConeProperty::WitnessNotIntegrallyClosed304|| prop == ConeProperty::Approximate305|| prop == ConeProperty::ClassGroup306|| prop == ConeProperty::Symmetrize307|| prop == ConeProperty::NoSymmetrization308|| prop == ConeProperty::InclusionExclusionData309|| prop == ConeProperty::ExcludedFaces310|| prop == ConeProperty::UnitGroupIndex311|| prop == ConeProperty::ReesPrimaryMultiplicity312|| prop == ConeProperty::IsReesPrimary313|| prop == ConeProperty::IsDeg1HilbertBasis314|| prop == ConeProperty::IsDeg1ExtremeRays315// || prop == ConeProperty::ModuleGeneratorsOverOriginalMonoid316) {317throw BadInputException(toString(prop) + " not computable in the inhomogeneous case.");318}319} else { // homgeneous320if ( prop == ConeProperty::VerticesOfPolyhedron321|| prop == ConeProperty::ModuleRank322|| prop == ConeProperty::ModuleGenerators ) {323throw BadInputException(toString(prop) + " only computable in the inhomogeneous case.");324}325}326} //end if test(i)327}328}329330331/* conversion */332namespace {333// only to initialize the CPN in ConePropertyNames334vector<string> initializeCPN() {335vector<string> CPN(ConeProperty::EnumSize);336CPN.at(ConeProperty::Generators) = "Generators";337CPN.at(ConeProperty::ExtremeRays) = "ExtremeRays";338CPN.at(ConeProperty::VerticesOfPolyhedron) = "VerticesOfPolyhedron";339CPN.at(ConeProperty::SupportHyperplanes) = "SupportHyperplanes";340CPN.at(ConeProperty::TriangulationSize) = "TriangulationSize";341CPN.at(ConeProperty::TriangulationDetSum) = "TriangulationDetSum";342CPN.at(ConeProperty::Triangulation) = "Triangulation";343CPN.at(ConeProperty::Multiplicity) = "Multiplicity";344CPN.at(ConeProperty::RecessionRank) = "RecessionRank";345CPN.at(ConeProperty::AffineDim) = "AffineDim";346CPN.at(ConeProperty::ModuleRank) = "ModuleRank";347CPN.at(ConeProperty::HilbertBasis) = "HilbertBasis";348CPN.at(ConeProperty::ModuleGenerators) = "ModuleGenerators";349CPN.at(ConeProperty::Deg1Elements) = "Deg1Elements";350CPN.at(ConeProperty::HilbertSeries) = "HilbertSeries";351CPN.at(ConeProperty::Grading) = "Grading";352CPN.at(ConeProperty::IsPointed) = "IsPointed";353CPN.at(ConeProperty::IsDeg1ExtremeRays) = "IsDeg1ExtremeRays";354CPN.at(ConeProperty::IsDeg1HilbertBasis) = "IsDeg1HilbertBasis";355CPN.at(ConeProperty::IsIntegrallyClosed) = "IsIntegrallyClosed";356CPN.at(ConeProperty::WitnessNotIntegrallyClosed) = "WitnessNotIntegrallyClosed";357CPN.at(ConeProperty::OriginalMonoidGenerators) = "OriginalMonoidGenerators";358CPN.at(ConeProperty::IsReesPrimary) = "IsReesPrimary";359CPN.at(ConeProperty::ReesPrimaryMultiplicity) = "ReesPrimaryMultiplicity";360CPN.at(ConeProperty::StanleyDec) = "StanleyDec";361CPN.at(ConeProperty::ExcludedFaces) = "ExcludedFaces";362CPN.at(ConeProperty::Dehomogenization) = "Dehomogenization";363CPN.at(ConeProperty::InclusionExclusionData) = "InclusionExclusionData";364CPN.at(ConeProperty::Sublattice) = "Sublattice";365CPN.at(ConeProperty::ClassGroup) = "ClassGroup";366CPN.at(ConeProperty::ModuleGeneratorsOverOriginalMonoid) = "ModuleGeneratorsOverOriginalMonoid";367// the following are more compute options than real properties of the cone368CPN.at(ConeProperty::Approximate) = "Approximate";369CPN.at(ConeProperty::BottomDecomposition) = "BottomDecomposition";370CPN.at(ConeProperty::DefaultMode) = "DefaultMode";371CPN.at(ConeProperty::DualMode) = "DualMode";372CPN.at(ConeProperty::KeepOrder) = "KeepOrder";373CPN.at(ConeProperty::NumberHull) = "NumberHull";374CPN.at(ConeProperty::MaximalSubspace) = "MaximalSubspace";375CPN.at(ConeProperty::ConeDecomposition) = "ConeDecomposition";376CPN.at(ConeProperty::HSOP) = "HSOP";377CPN.at(ConeProperty::NoBottomDec) = "NoBottomDec";378379CPN.at(ConeProperty::PrimalMode) = "PrimalMode";380CPN.at(ConeProperty::Symmetrize) = "Symmetrize";381CPN.at(ConeProperty::NoSymmetrization) = "NoSymmetrization";382CPN.at(ConeProperty::EmbeddingDim) = "EmbeddingDim";383CPN.at(ConeProperty::Rank) = "Rank";384CPN.at(ConeProperty::InternalIndex) = "InternalIndex";385CPN.at(ConeProperty::IsInhomogeneous) = "IsInhomogeneous";386CPN.at(ConeProperty::UnitGroupIndex) = "UnitGroupIndex";387CPN.at(ConeProperty::GradingDenom) = "GradingDenom";388CPN.at(ConeProperty::Equations) = "Equations";389CPN.at(ConeProperty::Congruences) = "Congruences";390CPN.at(ConeProperty::ExternalIndex) = "ExernalIndex";391CPN.at(ConeProperty::HilbertQuasiPolynomial) = "HilbertQuasiPolynomial";392CPN.at(ConeProperty::IsTriangulationNested) = "IsTriangulationNested";393CPN.at(ConeProperty::IsTriangulationPartial) = "IsTriangulationPartial";394CPN.at(ConeProperty::BigInt) = "BigInt";395396// detect changes in size of Enum, to remember to update CPN!397static_assert (ConeProperty::EnumSize == 57,398"ConeProperties Enum size does not fit! Update cone_property.cpp!");399// assert all fields contain an non-empty string400for (size_t i=0; i<ConeProperty::EnumSize; i++) {401assert(CPN.at(i).size() > 0);402}403return CPN;404}405406const vector<string>& ConePropertyNames() {407static const vector<string> CPN(initializeCPN());408return CPN;409}410}411412bool isConeProperty(ConeProperty::Enum& cp, const std::string& s) {413const vector<string>& CPN = ConePropertyNames();414for (size_t i=0; i<ConeProperty::EnumSize; i++) {415if (CPN[i] == s) {416cp = static_cast<ConeProperty::Enum>(i);417return true;418}419}420return false;421}422423ConeProperty::Enum toConeProperty(const std::string& s) {424ConeProperty::Enum cp;425if (isConeProperty(cp, s)) return cp;426throw BadInputException("Unknown ConeProperty string \"" + s + "\"");427}428429const std::string& toString(ConeProperty::Enum cp) {430return ConePropertyNames()[cp];431}432433/* print it in a nice way */434std::ostream& operator<< (std::ostream& out, const ConeProperties& CP){435for (size_t i=0; i<ConeProperty::EnumSize; i++) {436if (CP.CPs.test(i)) out << toString(static_cast<ConeProperty::Enum>(i)) << " ";437}438return out;439}440441442} /* end namespace libQnormaliz */443444#ifdef NMZ_MIC_OFFLOAD445#pragma offload_attribute (pop)446#endif447448449