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: 418346/*1* NormalizInterface: GAP wrapper for Normaliz2* Copyright (C) 2014 Sebastian Gutsche, Max Horn, Christof Söger3*4* This program is free software; you can redistribute it and/or5* modify it under the terms of the GNU General Public License6* as published by the Free Software Foundation; either version 27* of the License, or (at your option) any later version.8*9* This program is distributed in the hope that it will be useful,10* but WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12* GNU General Public License for more details.13*14* You should have received a copy of the GNU General Public License15* along with this program; if not, write to the Free Software16* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.17*/1819/*20#! @Chapter Functions21#! @Section YOU FORGOT TO SET A SECTION22*/2324#include <gmp.h>2526extern "C" {27#include "src/compiled.h" /* GAP headers */28}29#include "libnormaliz/cone.h"30#include <assert.h>313233#include "libnormaliz/map_operations.h"3435#include <vector>36#include <iostream>3738#include <csignal>39using std::signal;4041typedef void (*sighandler_t)(int);4243// the TNUM used for NormalizInterface objects,44extern UInt T_NORMALIZ;4546// old versions of libnormaliz (before 2.99.1) did not include such a define47#if !defined(NMZ_RELEASE) || NMZ_RELEASE < 3040048#error Your Normaliz version is to old! Update to 3.4.0 or newer.49#endif5051#define FUNC_BEGIN try {5253#define FUNC_END \54} catch (std::exception& e) { \55ErrorQuit(e.what(),0,0); \56return Fail; \57} catch (const char* a) { \58ErrorQuit(a,0,0); \59return Fail; \60}6162#define SIGNAL_HANDLER_BEGIN \63sighandler_t current_interpreter_sigint_handler = signal( SIGINT, signal_handler ); \64try{6566#define SIGNAL_HANDLER_END \67} catch (libnormaliz::InterruptException& e ) {\68signal(SIGINT,current_interpreter_sigint_handler);\69libnormaliz::nmz_interrupted = false; \70ErrorQuit( "computation interrupted", 0, 0 ); \71return 0; \72} catch (...) { \73signal(SIGINT,current_interpreter_sigint_handler);\74throw;\75} \76signal(SIGINT,current_interpreter_sigint_handler);7778extern Obj TheTypeNormalizCone;7980#define IS_CONE(o) (TNUM_OBJ(o) == T_NORMALIZ)818283// Paranoia check84#ifdef SYS_IS_64_BIT85#if GMP_LIMB_BITS != 6486#error GAP compiled in 64 bit mode, but GMP limbs are not 64 bit87#endif88#else89#if GMP_LIMB_BITS != 3290#error GAP compiled in 32 bit mode, but GMP limbs are not 32 bit91#endif92#endif939495using libnormaliz::Cone;96//using libnormaliz::ConeProperty;97using libnormaliz::ConeProperties;98using libnormaliz::Sublattice_Representation;99using libnormaliz::Type::InputType;100101using std::map;102using std::vector;103using std::string;104using std::pair;105106using std::cerr;107using std::endl;108109void signal_handler(int signal)110{111libnormaliz::nmz_interrupted = true;112}113114115Obj TheTypeNormalizCone;116117UInt T_NORMALIZ = 0;118119template<typename Integer>120inline void SET_CONE(Obj o, libnormaliz::Cone<Integer>* p) {121ADDR_OBJ(o)[0] = reinterpret_cast<Obj>(p);122}123124template<typename Integer>125inline libnormaliz::Cone<Integer>* GET_CONE(Obj o) {126return reinterpret_cast<libnormaliz::Cone<Integer>*>(ADDR_OBJ(o)[0]);127}128129Obj NewCone(Cone<mpz_class>* C)130{131Obj o;132o = NewBag(T_NORMALIZ, 1 * sizeof(Obj));133SET_CONE<mpz_class>(o, C);134return o;135}136137Obj NewProxyCone(Cone<mpz_class>* C, Obj parentCone)138{139Obj o;140o = NewBag(T_NORMALIZ, 2 * sizeof(Obj) );141SET_CONE<mpz_class>(o, C);142ADDR_OBJ(o)[1] = parentCone;143return o;144}145146#define IS_PROXY_CONE(o) (SIZE_OBJ(o) == 2)147148/* Free function */149void NormalizFreeFunc(Obj o)150{151if (!IS_PROXY_CONE(o)) {152delete GET_CONE<mpz_class>(o);153}154}155156/* Type object function for the object */157Obj NormalizTypeFunc(Obj o)158{159return TheTypeNormalizCone;160}161162Obj NormalizCopyFunc(Obj o, Int mut)163{164// Cone objects are mathematically immutable, so165// we don't need to do anything,166return o;167}168169void NormalizCleanFunc(Obj o)170{171}172173Int NormalizIsMutableObjFuncs(Obj o)174{175// Cone objects are mathematically immutable.176return 0L;177}178179180static Obj MpzToGAP(const mpz_t x)181{182Obj res;183Int size = x->_mp_size;184int sign;185if (size == 0) {186return INTOBJ_INT(0);187} else if (size < 0) {188size = -size;189sign = -1;190} else {191sign = +1;192}193if (size == 1) {194res = ObjInt_UInt(x->_mp_d[0]);195if (sign < 0)196res = AInvInt(res);197} else {198size = sizeof(mp_limb_t) * size;199if (sign > 0)200res = NewBag(T_INTPOS, size);201else202res = NewBag(T_INTNEG, size);203memcpy(ADDR_INT(res), x->_mp_d, size);204}205return res;206}207208static inline Obj MpzClassToGAP(const mpz_class& x)209{210return MpzToGAP(x.get_mpz_t());211}212213static Obj MpqClassToGAP(const mpq_class& x)214{215Obj num = MpzClassToGAP(x.get_num());216Obj den = MpzClassToGAP(x.get_den());217return QUO(num, den);218}219220template<typename Number>221Obj NmzNumberToGAP(Number x)222{223return Number::unimplemented_function;224}225226template<>227Obj NmzNumberToGAP(libnormaliz::key_t x) // key_t = unsigned int228{229return ObjInt_UInt(x);230}231232#ifdef SYS_IS_64_BIT233template<>234Obj NmzNumberToGAP(size_t x) // size_t = unsigned long235{236return ObjInt_UInt(x);237}238#endif239240template<>241Obj NmzNumberToGAP(long x)242{243return ObjInt_Int(x);244}245246template<>247Obj NmzNumberToGAP(mpz_class x)248{249return MpzClassToGAP(x);250}251252template<>253Obj NmzNumberToGAP(double x)254{255return NEW_MACFLOAT(x);256}257258259template<typename Integer>260bool GAPIntToNmz(Obj x, Integer &out)261{262return Integer::unimplemented_function;263}264265template<>266bool GAPIntToNmz(Obj x, long &out)267{268if (IS_INTOBJ(x)) {269out = INT_INTOBJ(x);270return true;271} else if (TNUM_OBJ(x) == T_INTPOS || TNUM_OBJ(x) == T_INTNEG) {272UInt size = SIZE_INT(x);273if (size == 1) {274out = *ADDR_INT(x);275if (out < 0)276return false; // overflow277if (TNUM_OBJ(x) == T_INTNEG)278out = -out;279return true;280}281}282return false;283}284285template<>286bool GAPIntToNmz(Obj x, mpz_class &out)287{288mpz_ptr m = out.get_mpz_t();289290if (IS_INTOBJ(x)) {291mpz_realloc2(m, 1 * GMP_NUMB_BITS);292293if (INT_INTOBJ(x) == 0) {294mpz_set_ui(m, 0);295} else if (INT_INTOBJ(x) >= 0) {296m->_mp_d[0] = INT_INTOBJ(x);297m->_mp_size = 1;298} else {299m->_mp_d[0] = -INT_INTOBJ(x);300m->_mp_size = -1;301}302303return true;304} else if (TNUM_OBJ(x) == T_INTPOS || TNUM_OBJ(x) == T_INTNEG) {305UInt size = SIZE_INT(x);306mpz_realloc2(m, size * GMP_NUMB_BITS);307memcpy(m->_mp_d, ADDR_INT(x), sizeof(mp_limb_t) * size);308m->_mp_size = (TNUM_OBJ(x) == T_INTPOS) ? (Int)size : - (Int)size;309return true;310}311return false;312}313314template<typename Integer>315static bool GAPIntVectorToNmz(vector<Integer>& out, Obj V)316{317if (!IS_PLIST(V) || !IS_DENSE_LIST(V))318return false;319const int n = LEN_PLIST(V);320out.resize(n);321for (int i = 0; i < n; ++i) {322Obj tmp = ELM_PLIST(V, i+1);323if (!GAPIntToNmz(tmp, out[i]))324return false;325}326return true;327}328329template<typename Integer>330static bool GAPIntMatrixToNmz(vector< vector<Integer> >& out, Obj M)331{332if (!IS_PLIST(M) || !IS_DENSE_LIST(M))333return false;334const int nr = LEN_PLIST(M);335out.resize(nr);336for (int i = 0; i < nr; ++i) {337bool okay = GAPIntVectorToNmz(out[i], ELM_PLIST(M, i+1));338if (!okay)339return false;340}341return true;342}343344template<typename Number>345static Obj NmzVectorToGAP(const vector<Number>& in)346{347Obj M;348const size_t n = in.size();349M = NEW_PLIST((n > 0) ? T_PLIST_CYC : T_PLIST, n);350SET_LEN_PLIST(M, n);351for (size_t i = 0; i < n; ++i) {352SET_ELM_PLIST(M, i+1, NmzNumberToGAP(in[i]));353CHANGED_BAG( M );354}355return M;356}357358template<typename Number>359static Obj NmzMatrixToGAP(const vector< vector<Number> >& in)360{361Obj M;362const size_t n = in.size();363M = NEW_PLIST(T_PLIST, n);364SET_LEN_PLIST(M, n);365for (size_t i = 0; i < n; ++i) {366SET_ELM_PLIST(M, i+1, NmzVectorToGAP(in[i]));367CHANGED_BAG( M );368}369CHANGED_BAG( M );370return M;371}372373static Obj NmzBoolMatrixToGAP(const vector< vector<bool> >& in)374{375Obj M;376Obj N;377const size_t m = in.size();378size_t n;379// TODO: Use BLIST instead380M = NEW_PLIST(T_PLIST, m);381SET_LEN_PLIST(M, m);382for (size_t i = 0; i < m; ++i) {383n = in[i].size();384N = NEW_PLIST( T_PLIST, n );385SET_LEN_PLIST( N, n );386for( size_t j = 0; j < n; ++j ){387SET_ELM_PLIST(N, j+1, in[i][j] ? True : False );388}389SET_ELM_PLIST( M, i+1, N );390CHANGED_BAG( M );391}392CHANGED_BAG( M );393return M;394}395396/* TODO: HSOP397* There are two representations for Hilbert series in Normaliz, standard and HSOP.398* Currently, only the standard representation is returned.399*/400static Obj NmzHilbertSeriesToGAP(const libnormaliz::HilbertSeries& HS)401{402Obj ret;403ret = NEW_PLIST(T_PLIST, 3);404SET_LEN_PLIST(ret, 3);405AssPlist(ret, 1, NmzVectorToGAP(HS.getNum()));406AssPlist(ret, 2, NmzVectorToGAP(libnormaliz::to_vector(HS.getDenom())));407AssPlist(ret, 3, NmzNumberToGAP(HS.getShift()));408return ret;409}410411template<typename Integer>412static Obj NmzWeightedEhrhartSeriesToGAP(const std::pair<libnormaliz::HilbertSeries,Integer>& HS)413{414Obj ret;415ret = NEW_PLIST(T_PLIST, 4);416SET_LEN_PLIST(ret, 4);417AssPlist(ret, 1, NmzVectorToGAP(HS.first.getNum()));418AssPlist(ret, 2, NmzVectorToGAP(libnormaliz::to_vector(HS.first.getDenom())));419AssPlist(ret, 3, NmzNumberToGAP(HS.first.getShift()));420AssPlist(ret, 4, NmzNumberToGAP(HS.second));421return ret;422}423424static Obj NmzHilbertQuasiPolynomialToGAP(const libnormaliz::HilbertSeries& HS)425{426Obj ret;427vector< vector<mpz_class> > HQ = HS.getHilbertQuasiPolynomial();428const size_t n = HS.getPeriod();429ret = NEW_PLIST(T_PLIST, n+1);430SET_LEN_PLIST(ret, n+1);431432for (size_t i = 0; i < n; ++i) {433SET_ELM_PLIST(ret, i+1, NmzVectorToGAP(HQ[i]));434CHANGED_BAG( ret );435}436AssPlist(ret, n+1, NmzNumberToGAP(HS.getHilbertQuasiPolynomialDenom()));437return ret;438}439440static Obj NmzWeightedEhrhartQuasiPolynomialToGAP(const libnormaliz::IntegrationData& int_data)441{442Obj ret;443vector< vector<mpz_class> > ehrhart_qp = int_data.getWeightedEhrhartQuasiPolynomial();444const size_t n = ehrhart_qp.size();445ret = NEW_PLIST(T_PLIST, n+1);446for (size_t i = 0; i < n; ++i) {447SET_ELM_PLIST(ret, i+1 , NmzVectorToGAP(ehrhart_qp[i]));448CHANGED_BAG( ret );449}450AssPlist(ret, n+1, NmzNumberToGAP(int_data.getWeightedEhrhartQuasiPolynomialDenom()));451return ret;452}453454template<typename Integer>455static Obj NmzTriangleListToGAP(const vector< pair<vector<libnormaliz::key_t>, Integer> >& in)456{457Obj M;458const size_t n = in.size();459M = NEW_PLIST(T_PLIST, n);460SET_LEN_PLIST(M, n);461for (size_t i = 0; i < n; ++i) {462// convert the pair463Obj pair = NEW_PLIST(T_PLIST, 2);464SET_LEN_PLIST(pair, 2);465SET_ELM_PLIST(pair, 1, NmzVectorToGAP<libnormaliz::key_t>(in[i].first));466SET_ELM_PLIST(pair, 2, NmzNumberToGAP(in[i].second));467CHANGED_BAG( pair );468469SET_ELM_PLIST(M, i+1, pair);470CHANGED_BAG( M );471}472CHANGED_BAG( M );473return M;474}475476477template<typename Integer>478static Obj _NmzConeIntern(Obj input_list)479{480bool has_polynomial_input = false;481string polynomial;482map <InputType, vector< vector<Integer> > > input;483const int n = LEN_PLIST(input_list);484if (n&1) {485throw std::runtime_error("Input list must have even number of elements");486}487for (int i = 0; i < n; i += 2) {488Obj type = ELM_PLIST(input_list, i+1);489if (!IS_STRING_REP(type)) {490throw std::runtime_error("Element " + std::to_string(i+1) + " of the input list must be a type string");491}492string type_str(CSTR_STRING(type));493Obj M = ELM_PLIST(input_list, i+2);494if (type_str.compare("polynomial") == 0) {495if (!IS_STRING_REP(M)) {496throw std::runtime_error("Element " + std::to_string(i+2) + " of the input list must be a string");497}498polynomial = string(CSTR_STRING(M));499has_polynomial_input = true;500continue;501}502vector<vector<Integer> > Mat;503bool okay = GAPIntMatrixToNmz(Mat, M);504if (!okay) {505throw std::runtime_error("Element " + std::to_string(i+2) + " of the input list must integer matrix");506}507508input[libnormaliz::to_type(type_str)] = Mat;509}510511Cone<Integer>* C = new Cone<Integer>(input);512if (has_polynomial_input) {513C->setPolynomial(polynomial);514}515Obj Cone = NewCone(C);516return Cone;517518}519520Obj _NmzCone(Obj self, Obj input_list)521{522if (!IS_PLIST(input_list) || !IS_DENSE_LIST(input_list))523ErrorQuit("Input argument must be a list", 0, 0);524525FUNC_BEGIN526return _NmzConeIntern<mpz_class>(input_list);527FUNC_END528}529530Obj _NmzCompute(Obj self, Obj cone, Obj to_compute)531{532if (!IS_CONE(cone))533ErrorQuit("<cone> must be a Normaliz cone", 0, 0);534if (!IS_PLIST(to_compute) || !IS_DENSE_LIST(to_compute))535ErrorQuit("<props> must be a list of strings", 0, 0);536537FUNC_BEGIN538ConeProperties propsToCompute;539// we have a list540const int n = LEN_PLIST(to_compute);541542for (int i = 0; i < n; ++i) {543Obj prop = ELM_PLIST(to_compute, i+1);544if (!IS_STRING_REP(prop)) {545throw std::runtime_error("Element " + std::to_string(i+1) + " of the input list must be a type string");546}547string prop_str(CSTR_STRING(prop));548propsToCompute.set( libnormaliz::toConeProperty(prop_str) );549}550551Cone<mpz_class>* C = GET_CONE<mpz_class>(cone);552553ConeProperties notComputed;554SIGNAL_HANDLER_BEGIN555notComputed = C->compute(propsToCompute);556SIGNAL_HANDLER_END557558// Cone.compute returns the not computed properties559// we return a bool, true when everything requested was computed560return notComputed.none() ? True : False;561FUNC_END562}563564565/*566#! @Section Use a NmzCone567#! @Arguments cone property568#! @Returns whether the cone has already computed the given property569#! @Description570#! See <Ref Func="NmzConeProperty"/> for a list of recognized properties.571#!572#! @InsertChunk NmzHasConeProperty example573DeclareGlobalFunction("NmzHasConeProperty");574*/575Obj NmzHasConeProperty(Obj self, Obj cone, Obj prop)576{577if (!IS_CONE(cone))578ErrorQuit("<cone> must be a Normaliz cone", 0, 0);579if (!IS_STRING_REP(prop))580ErrorQuit("<prop> must be a string", 0, 0);581582FUNC_BEGIN583584libnormaliz::ConeProperty::Enum p = libnormaliz::toConeProperty(CSTR_STRING(prop));585586Cone<mpz_class>* C = GET_CONE<mpz_class>(cone);587return C->isComputed(p) ? True : False;588589FUNC_END590}591592/*593#! @Section Use a NmzCone594#! @Arguments cone595#! @Returns a list of strings representing the known (computed) cone properties596#! @Description597#! Given a Normaliz cone object, return a list of all properties already598#! computed for the cone.599#!600#! @InsertChunk NmzKnownConeProperties example601DeclareGlobalFunction("NmzKnownConeProperties");602*/603Obj NmzKnownConeProperties(Obj self, Obj cone)604{605if (!IS_CONE(cone))606ErrorQuit("<cone> must be a Normaliz cone", 0, 0);607608FUNC_BEGIN609610size_t n = 0;611Obj M = NEW_PLIST(T_PLIST, libnormaliz::ConeProperty::EnumSize);612613// FIXME: This code could be a lot simpler if there was614// a Cone method for reading the value of is_Computed.615for (int i = 0; i < libnormaliz::ConeProperty::EnumSize; ++i) {616libnormaliz::ConeProperty::Enum p = (libnormaliz::ConeProperty::Enum)i;617618Cone<mpz_class>* C = GET_CONE<mpz_class>(cone);619bool isComputed = C->isComputed(p);620621if (isComputed) {622string prop_name(libnormaliz::toString(p));623624Obj prop_name_gap;625C_NEW_STRING(prop_name_gap, prop_name.size(), prop_name.c_str());626627n++; // Increment counter628SET_ELM_PLIST(M, n, prop_name_gap);629CHANGED_BAG(M);630if (p == libnormaliz::ConeProperty::HilbertSeries) {631Cone<mpz_class>* C = GET_CONE<mpz_class>(cone);632C->getHilbertSeries().computeHilbertQuasiPolynomial();633isComputed = C->getHilbertSeries().isHilbertQuasiPolynomialComputed();634635if (isComputed) {636string prop_name("HilbertQuasiPolynomial");637638Obj prop_name_gap;639C_NEW_STRING(prop_name_gap, prop_name.size(), prop_name.c_str());640641n++; // Increment counter642SET_ELM_PLIST(M, n, prop_name_gap);643CHANGED_BAG(M);644}645}646}647}648SET_LEN_PLIST(M, n);649return M;650651FUNC_END652}653654template<typename Integer>655static Obj _NmzConePropertyImpl(Obj cone, Obj prop)656{657Cone<Integer>* C = GET_CONE<Integer>(cone);658659libnormaliz::ConeProperty::Enum p = libnormaliz::toConeProperty(CSTR_STRING(prop));660ConeProperties notComputed;661SIGNAL_HANDLER_BEGIN662notComputed = C->compute(ConeProperties(p));663SIGNAL_HANDLER_END664if (notComputed.any()) {665return Fail;666}667668switch (p) {669case libnormaliz::ConeProperty::Generators:670return NmzMatrixToGAP(C->getGenerators());671672case libnormaliz::ConeProperty::ExtremeRays:673return NmzMatrixToGAP(C->getExtremeRays());674675case libnormaliz::ConeProperty::VerticesOfPolyhedron:676return NmzMatrixToGAP(C->getVerticesOfPolyhedron());677678case libnormaliz::ConeProperty::SupportHyperplanes:679return NmzMatrixToGAP(C->getSupportHyperplanes());680681case libnormaliz::ConeProperty::TriangulationSize:682return ObjInt_UInt(C->getTriangulationSize());683684case libnormaliz::ConeProperty::TriangulationDetSum:685return NmzNumberToGAP(C->getTriangulationDetSum());686687case libnormaliz::ConeProperty::Triangulation:688return NmzTriangleListToGAP<Integer>(C->getTriangulation());689690case libnormaliz::ConeProperty::Multiplicity:691{692mpq_class mult = C->getMultiplicity();693return MpqClassToGAP(mult);694}695696case libnormaliz::ConeProperty::Integral:697return MpqClassToGAP(C->getIntegral());698699case libnormaliz::ConeProperty::VirtualMultiplicity:700return MpqClassToGAP(C->getVirtualMultiplicity());701702case libnormaliz::ConeProperty::RecessionRank:703return NmzNumberToGAP(C->getRecessionRank());704705case libnormaliz::ConeProperty::AffineDim:706return NmzNumberToGAP(C->getAffineDim());707708case libnormaliz::ConeProperty::ModuleRank:709return NmzNumberToGAP(C->getModuleRank());710711case libnormaliz::ConeProperty::HilbertBasis:712return NmzMatrixToGAP(C->getHilbertBasis());713714case libnormaliz::ConeProperty::MaximalSubspace:715return NmzMatrixToGAP(C->getMaximalSubspace());716717case libnormaliz::ConeProperty::ModuleGenerators:718return NmzMatrixToGAP(C->getModuleGenerators());719720case libnormaliz::ConeProperty::Deg1Elements:721return NmzMatrixToGAP(C->getDeg1Elements());722723case libnormaliz::ConeProperty::HilbertSeries:724return NmzHilbertSeriesToGAP(C->getHilbertSeries());725break;726727case libnormaliz::ConeProperty::Grading:728{729vector<Integer> grad = C->getGrading();730grad.push_back(C->getGradingDenom());731return NmzVectorToGAP(grad);732}733734case libnormaliz::ConeProperty::GradingDenom:735return NmzNumberToGAP( C->getGradingDenom() );736737case libnormaliz::ConeProperty::IsPointed:738return C->isPointed() ? True : False;739740case libnormaliz::ConeProperty::IsDeg1ExtremeRays:741return C->isDeg1ExtremeRays() ? True : False;742743case libnormaliz::ConeProperty::IsDeg1HilbertBasis:744return C->isDeg1HilbertBasis() ? True : False;745746case libnormaliz::ConeProperty::IsIntegrallyClosed:747return C->isIntegrallyClosed() ? True : False;748749case libnormaliz::ConeProperty::OriginalMonoidGenerators:750return NmzMatrixToGAP(C->getOriginalMonoidGenerators());751752case libnormaliz::ConeProperty::IsReesPrimary:753return C->isReesPrimary() ? True : False;754755case libnormaliz::ConeProperty::ReesPrimaryMultiplicity:756return NmzNumberToGAP(C->getReesPrimaryMultiplicity());757758// StanleyDec is special and we do not support the required conversion at759// this time. If you really need this, contact the developers.760case libnormaliz::ConeProperty::StanleyDec:761//C->getStanleyDec();762break;763764case libnormaliz::ConeProperty::ExcludedFaces:765return NmzMatrixToGAP(C->getExcludedFaces());766767case libnormaliz::ConeProperty::Dehomogenization:768return NmzVectorToGAP(C->getDehomogenization());769770case libnormaliz::ConeProperty::InclusionExclusionData:771return NmzTriangleListToGAP<long>(C->getInclusionExclusionData());772773case libnormaliz::ConeProperty::ClassGroup:774return NmzVectorToGAP(C->getClassGroup());775776case libnormaliz::ConeProperty::IsInhomogeneous:777return C->isInhomogeneous() ? True : False;778779case libnormaliz::ConeProperty::Equations:780return NmzMatrixToGAP(C->getSublattice().getEquations());781782case libnormaliz::ConeProperty::Congruences:783return NmzMatrixToGAP(C->getSublattice().getCongruences());784785case libnormaliz::ConeProperty::EmbeddingDim:786return NmzNumberToGAP(C->getEmbeddingDim());787788case libnormaliz::ConeProperty::Rank:789return NmzNumberToGAP(C->getRank());790791case libnormaliz::ConeProperty::Sublattice:792return _NmzBasisChangeIntern(C);793794case libnormaliz::ConeProperty::IntegerHull:795{796Cone<Integer>* int_hull = &(C->getIntegerHullCone());797return NewProxyCone( int_hull, cone );798}799800case libnormaliz::ConeProperty::HilbertQuasiPolynomial:801return NmzHilbertQuasiPolynomialToGAP(C->getHilbertSeries());802803case libnormaliz::ConeProperty::WeightedEhrhartQuasiPolynomial:804return NmzWeightedEhrhartQuasiPolynomialToGAP(C->getIntData());805806case libnormaliz::ConeProperty::IsTriangulationNested:807return C->isTriangulationNested() ? True : False;808809case libnormaliz::ConeProperty::IsTriangulationPartial:810return C->isTriangulationPartial() ? True : False;811812case libnormaliz::ConeProperty::ConeDecomposition:813return NmzBoolMatrixToGAP(C->getOpenFacets());814815case libnormaliz::ConeProperty::ExternalIndex:816return NmzNumberToGAP(C->getSublattice().getExternalIndex());817818case libnormaliz::ConeProperty::InternalIndex:819return NmzNumberToGAP(C->getIndex());820821case libnormaliz::ConeProperty::WitnessNotIntegrallyClosed:822return NmzVectorToGAP(C->getWitnessNotIntegrallyClosed());823824case libnormaliz::ConeProperty::UnitGroupIndex:825return NmzNumberToGAP(C->getUnitGroupIndex());826827case libnormaliz::ConeProperty::WeightedEhrhartSeries:828return NmzWeightedEhrhartSeriesToGAP(C->getWeightedEhrhartSeries());829830case libnormaliz::ConeProperty::IsGorenstein:831return C->isGorenstein() ? True : False;832833case libnormaliz::ConeProperty::GeneratorOfInterior:834return NmzVectorToGAP( C->getGeneratorOfInterior() );835836case libnormaliz::ConeProperty::VerticesFloat:837return NmzMatrixToGAP( C->getVerticesFloat() );838839// the following properties are compute options and do not return anything840case libnormaliz::ConeProperty::DefaultMode:841case libnormaliz::ConeProperty::Approximate:842case libnormaliz::ConeProperty::BottomDecomposition:843case libnormaliz::ConeProperty::KeepOrder:844case libnormaliz::ConeProperty::NoBottomDec:845case libnormaliz::ConeProperty::PrimalMode:846case libnormaliz::ConeProperty::Symmetrize:847case libnormaliz::ConeProperty::NoSymmetrization:848case libnormaliz::ConeProperty::BigInt:849case libnormaliz::ConeProperty::NoNestedTri:850case libnormaliz::ConeProperty::HSOP:851case libnormaliz::ConeProperty::Projection:852case libnormaliz::ConeProperty::NoProjection:853case libnormaliz::ConeProperty::ProjectionFloat:854case libnormaliz::ConeProperty::SCIP:855case libnormaliz::ConeProperty::NoPeriodBound:856throw "cone property is input-only";857858default:859throw "unknown cone property";860}861862return Fail;863}864865Obj _NmzConeProperty(Obj self, Obj cone, Obj prop)866{867if (!IS_CONE(cone))868ErrorQuit("<cone> must be a Normaliz cone", 0, 0);869if (!IS_STRING_REP(prop))870ErrorQuit("<prop> must be a string", 0, 0);871872FUNC_BEGIN873return _NmzConePropertyImpl<mpz_class>(cone, prop);874FUNC_END875}876877878879/*880#! @Section Use a NmzCone881#! @Arguments verboseFlag882#! @Returns the previous verbosity883#! @Description884#! Set the global default verbosity state in libnormaliz.885#! This will influence all NmzCone created afterwards, but not any existing ones.886#!887#! See also <Ref Func="NmzSetVerbose"/>888DeclareGlobalFunction("NmzSetVerboseDefault");889*/890Obj NmzSetVerboseDefault(Obj self, Obj value)891{892if (value != True && value != False)893ErrorQuit("<value> must be a boolean value", 0, 0);894FUNC_BEGIN895return libnormaliz::setVerboseDefault(value == True) ? True : False;896FUNC_END897}898/*899#! @Arguments cone verboseFlag900#! @Returns the previous verbosity901#! @Description902#! Set the verbosity state for a cone.903#!904#! See also <Ref Func="NmzSetVerboseDefault"/>905DeclareGlobalFunction("NmzSetVerbose");906*/907Obj NmzSetVerbose(Obj self, Obj cone, Obj value)908{909if (!IS_CONE(cone))910ErrorQuit("<cone> must be a Normaliz cone", 0, 0);911if (value != True && value != False)912ErrorQuit("<value> must be a boolean value", 0, 0);913bool old_value;914915FUNC_BEGIN916Cone<mpz_class>* C = GET_CONE<mpz_class>(cone);917old_value = C->setVerbose(value == True);918return old_value ? True : False;919FUNC_END920}921922/*923#! @Section Cone properties924*/925926927template<typename Integer>928static Obj _NmzBasisChangeIntern(Cone<Integer>* C)929{930Sublattice_Representation<Integer> bc;931SIGNAL_HANDLER_BEGIN932bc = C->getSublattice();933SIGNAL_HANDLER_END934935Obj res = NEW_PLIST(T_PLIST, 3);936SET_LEN_PLIST(res, 3);937AssPlist(res, 1, NmzMatrixToGAP(bc.getEmbedding()));938AssPlist(res, 2, NmzMatrixToGAP(bc.getProjection()));939AssPlist(res, 3, NmzNumberToGAP(bc.getAnnihilator()));940// Dim, Rank, Equations and Congruences are already covered by special functions941// The index is not always computed and not so relevant942return res;943}944945946typedef Obj (* GVarFuncType)(/*arguments*/);947948#define GVAR_FUNC_TABLE_ENTRY(srcfile, name, nparam, params) \949{#name, nparam, \950params, \951(GVarFuncType)name, \952srcfile ":Func" #name }953954// Table of functions to export955static StructGVarFunc GVarFuncs[] = {956GVAR_FUNC_TABLE_ENTRY("normaliz.cc", _NmzCone, 1, "list"),957958GVAR_FUNC_TABLE_ENTRY("normaliz.cc", _NmzCompute, 2, "cone, props"),959GVAR_FUNC_TABLE_ENTRY("normaliz.cc", NmzSetVerboseDefault, 1, "value"),960GVAR_FUNC_TABLE_ENTRY("normaliz.cc", NmzSetVerbose, 2, "cone, value"),961962GVAR_FUNC_TABLE_ENTRY("normaliz.cc", NmzHasConeProperty, 2, "cone, prop"),963GVAR_FUNC_TABLE_ENTRY("normaliz.cc", _NmzConeProperty, 2, "cone, prop"),964GVAR_FUNC_TABLE_ENTRY("normaliz.cc", NmzKnownConeProperties, 1, "cone"),965966{ 0 } /* Finish with an empty entry */967968};969970/******************************************************************************971*F InitKernel( <module> ) . . . . . . . . initialise kernel data structures972*/973static Int InitKernel( StructInitInfo *module )974{975/* init filters and functions */976InitHdlrFuncsFromTable( GVarFuncs );977978InitCopyGVar( "TheTypeNormalizCone", &TheTypeNormalizCone );979980T_NORMALIZ = RegisterPackageTNUM("NormalizCone", NormalizTypeFunc);981982InitMarkFuncBags(T_NORMALIZ, &MarkAllSubBags);983InitFreeFuncBag(T_NORMALIZ, &NormalizFreeFunc);984985CopyObjFuncs[ T_NORMALIZ ] = &NormalizCopyFunc;986CleanObjFuncs[ T_NORMALIZ ] = &NormalizCleanFunc;987IsMutableObjFuncs[ T_NORMALIZ ] = &NormalizIsMutableObjFuncs;988989/* return success */990return 0;991}992993/******************************************************************************994*F InitLibrary( <module> ) . . . . . . . initialise library data structures995*/996static Int InitLibrary( StructInitInfo *module )997{998/* init filters and functions */999InitGVarFuncsFromTable( GVarFuncs );10001001/* return success */1002return 0;1003}10041005/******************************************************************************1006*F InitInfopl() . . . . . . . . . . . . . . . . . table of init functions1007*/1008static StructInitInfo module = {1009#ifdef NORMALIZSTATIC1010/* type = */ MODULE_STATIC,1011#else1012/* type = */ MODULE_DYNAMIC,1013#endif1014/* name = */ "Normaliz",1015/* revision_c = */ 0,1016/* revision_h = */ 0,1017/* version = */ 0,1018/* crc = */ 0,1019/* initKernel = */ InitKernel,1020/* initLibrary = */ InitLibrary,1021/* checkInit = */ 0,1022/* preSave = */ 0,1023/* postSave = */ 0,1024/* postRestore = */ 01025};10261027#ifndef NORMALIZSTATIC1028extern "C"1029StructInitInfo * Init__Dynamic ( void )1030{1031return &module;1032}1033#endif10341035extern "C"1036StructInitInfo * Init__normaliz ( void )1037{1038return &module;1039}104010411042