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# encoding=utf812import PyNormaliz_cpp3from PyNormaliz_cpp import *456class Cone:78def __init__(self, *args, **kwargs):9input_list = [k for k in args]10for i in kwargs:11current_input = kwargs[i]12if type(current_input) == list and len(current_input) > 0 and type(current_input[0]) != list:13kwargs[i] = [current_input]14elif type(current_input) == bool and current_input == True:15kwargs[i] = current_input = [[]]16elif type(current_input) == bool and current_input == False:17kwargs.pop(i)1819for i in kwargs:20input_list.append(i)21input_list.append(kwargs[i])2223self.cone = PyNormaliz_cpp.NmzCone(input_list)2425def __process_keyword_args(self, keywords):26input_list = []27for i in keywords:28if keywords[i] == True:29input_list.append(i)30return input_list3132def print_properties(self):33props = PyNormaliz_cpp.NmzListConeProperties()34goals = props[0]35for x in goals:36if (PyNormaliz_cpp.NmzIsComputed(self.cone, x)):37print(x + ":")38print(PyNormaliz_cpp.NmzResult(self.cone, x))39print("\n")4041def __str__(self):42return "<Normaliz Cone>"4344def __repr__(self):45return "<Normaliz Cone>"4647def Compute(self, *args):48return PyNormaliz_cpp.NmzCompute(self.cone, args)4950def setVerbose(self, verbose=True):51return NmzSetVerbose(self.cone, verbose)5253# This one is not like the others!54def IntegerHull(self, **kwargs):55input_list = self.__process_keyword_args(kwargs)56input_list.append("IntegerHull")57PyNormaliz_cpp.NmzCompute(self.cone, input_list)58new_inner_cone = PyNormaliz_cpp.NmzResult(self.cone, "IntegerHull")59return_cone = Cone.__new__(Cone)60return_cone.cone = new_inner_cone61return return_cone6263def HilbertSeries(self, **kwargs):64try:65as_hsop = kwargs["HSOP"]66except KeyError:67as_hsop = 2868input_list = self.__process_keyword_args(kwargs)69input_list.append("HilbertSeries")70PyNormaliz_cpp.NmzCompute(self.cone, input_list)71if as_hsop == 28:72return PyNormaliz_cpp.NmzHilbertSeries(self.cone)73if type(as_hsop) == bool:74return PyNormaliz_cpp.NmzHilbertSeries(self.cone, as_hsop)75raise TypeError("If HSOP is given, it must be True or False")7677def Polynomial(self, **kwargs):78return PyNormaliz_cpp.NmzGetPolynomial(self.cone)7980def NrCoeffQuasiPol(self, bound=-1):81return PyNormaliz_cpp.NmzSetNrCoeffQuasiPol(self.cone, bound)8283def SymmetrizedCone(self, **kwargs):84new_inner_cone = PyNormaliz_cpp.NmzSymmetrizedCone(self.cone)85if new_inner_cone == None:86return None87return_cone = Cone.__new__(Cone)88return_cone.cone = new_inner_cone89return return_cone9091def PrettyPolynomialTuple(self, numCoefficients, denCoefficients):92"""93Strings for numerator and denominator of the a hilbert series.9495Parameters96----------97numCoefficients : list98The coefficients for the numerator.99denCofficients : list100The coefficients for the denominator where the value represents the101exponent of 't' and the frequency indicates the outer coefficient.102103Returns104-------105PrettyPolynomialTuple: tuple of strings106107Examples108--------109110>>> numCoefficients = [3, 7, 4, -4, -6, 5]111>>> denCoefficients = [1, 1, 2, 2, 2, 4]112>>> PrettyPolynomialTuple(numCoefficients,denCoefficients)113114('(3 + 7t + 4t² - 4t³ - 6t⁴ + 5t⁵)', '(1 - t)² (1 - t²)³ (1 - t⁴)')115116"""117def to_sup(s):118sups = {u'0': u'\u2070',119u'1': u'\xb9',120u'2': u'\xb2',121u'3': u'\xb3',122u'4': u'\u2074',123u'5': u'\u2075',124u'6': u'\u2076',125u'7': u'\u2077',126u'8': u'\u2078',127u'9': u'\u2079'}128if s is 1:129return ''130# lose the list comprehension131return ''.join(sups.get(str(char), str(char)) for char in str(s))132133def getNumerator(coefficients):134135numerator = ''136137def isPositive(x):138return x > 0139140firstNonZero = next(141(i for i, x in enumerate(coefficients) if x != 0), 0)142for exp, coefficient in enumerate(coefficients):143if coefficient is 0:144continue145# Exponent is 0 so keep only the coefficient146if exp is 0:147numerator += '({}{!s}'.format('-' if not isPositive(coefficient)148else '', abs(coefficient))149# Only include sign if `coefficient` is negative150elif i is firstNonZero:151numerator += '{}{!s}t{}'.format('-' if not isPositive(152coefficient) else '', abs(coefficient), to_sup(exp))153else:154numerator += ' {}{!s}t{}'.format('+ ' if isPositive(155coefficient) else '- ', abs(coefficient), to_sup(exp))156numerator += ')'157return numerator158159def getDenominator(coefficients):160exponents = [(inner, coefficients.count(inner))161for inner in set(coefficients)]162denominator = ' '.join('(1 - t{}){}'. format(to_sup(x[0]) if x[1630] is not 1 else '', to_sup(x[1]) if x[1] is not 1 else '') for x in exponents)164return denominator165166num = getNumerator(numCoefficients)167den = getDenominator(denCoefficients)168prettyPolynomial = (num, den)169return prettyPolynomial170171def PrintPrettyHilbertSeries(self, numCoefficients, denCoefficients):172"""173Make a pretty hilbert series string174175Parameters176----------177numCoefficients : list of ints178The coefficients for the numerator.179denCofficients : list of ints180The coefficients for the denominator where the value represents181the exponent of 't' and the frequency indicates the outer182coefficient.183184Returns185-------186PrintPrettyHilbertSeries : string187188Examples189--------190191>>> numCoefficients = [3, 7, 4, -4, -6, 5]192>>> deCoefficients = [1, 1, 2, 2, 2, 4]193>>> PrintPrettyHilbertSeries(numCoefficients,deCoefficients)194195(3 + 7t + 4t² - 4t³ - 6t⁴ + 5t⁵)196--------------------------------197(1 - t)² (1 - t²)³ (1 - t⁴)198199"""200num, den = self.PrettyPolynomialTuple(numCoefficients, denCoefficients)201prettyPolynomial = '{:^}\n{:-^{width}}\n{:^{width}}'.format(202num, '', den, width=max(len(den),len(num)))203return prettyPolynomial204205def PrintHilbertSeries(self):206hilbert_series=self.HilbertSeries()207shift=hilbert_series[2]208shift=[ 0 for x in range(1,shift) ]209numerator=shift+hilbert_series[0]210denominator=hilbert_series[1]211print(self.PrintPrettyHilbertSeries(numerator,denominator))212return None213214# Auto generated stuff215216def Generators(self, **kwargs):217input_list = self.__process_keyword_args(kwargs)218input_list.append("Generators")219PyNormaliz_cpp.NmzCompute(self.cone, input_list)220return PyNormaliz_cpp.NmzResult(self.cone, "Generators")221222def ExtremeRays(self, **kwargs):223input_list = self.__process_keyword_args(kwargs)224input_list.append("ExtremeRays")225PyNormaliz_cpp.NmzCompute(self.cone, input_list)226return PyNormaliz_cpp.NmzResult(self.cone, "ExtremeRays")227228def VerticesOfPolyhedron(self, **kwargs):229input_list = self.__process_keyword_args(kwargs)230input_list.append("VerticesOfPolyhedron")231PyNormaliz_cpp.NmzCompute(self.cone, input_list)232return PyNormaliz_cpp.NmzResult(self.cone, "VerticesOfPolyhedron")233234def SupportHyperplanes(self, **kwargs):235input_list = self.__process_keyword_args(kwargs)236input_list.append("SupportHyperplanes")237PyNormaliz_cpp.NmzCompute(self.cone, input_list)238return PyNormaliz_cpp.NmzResult(self.cone, "SupportHyperplanes")239240def HilbertBasis(self, **kwargs):241input_list = self.__process_keyword_args(kwargs)242input_list.append("HilbertBasis")243PyNormaliz_cpp.NmzCompute(self.cone, input_list)244return PyNormaliz_cpp.NmzResult(self.cone, "HilbertBasis")245246def ModuleGenerators(self, **kwargs):247input_list = self.__process_keyword_args(kwargs)248input_list.append("ModuleGenerators")249PyNormaliz_cpp.NmzCompute(self.cone, input_list)250return PyNormaliz_cpp.NmzResult(self.cone, "ModuleGenerators")251252def Deg1Elements(self, **kwargs):253input_list = self.__process_keyword_args(kwargs)254input_list.append("Deg1Elements")255PyNormaliz_cpp.NmzCompute(self.cone, input_list)256return PyNormaliz_cpp.NmzResult(self.cone, "Deg1Elements")257258def ModuleGeneratorsOverOriginalMonoid(self, **kwargs):259input_list = self.__process_keyword_args(kwargs)260input_list.append("ModuleGeneratorsOverOriginalMonoid")261PyNormaliz_cpp.NmzCompute(self.cone, input_list)262return PyNormaliz_cpp.NmzResult(self.cone, "ModuleGeneratorsOverOriginalMonoid")263264def Sublattice(self, **kwargs):265input_list = self.__process_keyword_args(kwargs)266input_list.append("Sublattice")267PyNormaliz_cpp.NmzCompute(self.cone, input_list)268return PyNormaliz_cpp.NmzResult(self.cone, "Sublattice")269270def ExcludedFaces(self, **kwargs):271input_list = self.__process_keyword_args(kwargs)272input_list.append("ExcludedFaces")273PyNormaliz_cpp.NmzCompute(self.cone, input_list)274return PyNormaliz_cpp.NmzResult(self.cone, "ExcludedFaces")275276def OriginalMonoidGenerators(self, **kwargs):277input_list = self.__process_keyword_args(kwargs)278input_list.append("OriginalMonoidGenerators")279PyNormaliz_cpp.NmzCompute(self.cone, input_list)280return PyNormaliz_cpp.NmzResult(self.cone, "OriginalMonoidGenerators")281282def MaximalSubspace(self, **kwargs):283input_list = self.__process_keyword_args(kwargs)284input_list.append("MaximalSubspace")285PyNormaliz_cpp.NmzCompute(self.cone, input_list)286return PyNormaliz_cpp.NmzResult(self.cone, "MaximalSubspace")287288def Equations(self, **kwargs):289input_list = self.__process_keyword_args(kwargs)290input_list.append("Equations")291PyNormaliz_cpp.NmzCompute(self.cone, input_list)292return PyNormaliz_cpp.NmzResult(self.cone, "Equations")293294def Congruences(self, **kwargs):295input_list = self.__process_keyword_args(kwargs)296input_list.append("Congruences")297PyNormaliz_cpp.NmzCompute(self.cone, input_list)298return PyNormaliz_cpp.NmzResult(self.cone, "Congruences")299300def Grading(self, **kwargs):301input_list = self.__process_keyword_args(kwargs)302input_list.append("Grading")303PyNormaliz_cpp.NmzCompute(self.cone, input_list)304return PyNormaliz_cpp.NmzResult(self.cone, "Grading")305306def Dehomogenization(self, **kwargs):307input_list = self.__process_keyword_args(kwargs)308input_list.append("Dehomogenization")309PyNormaliz_cpp.NmzCompute(self.cone, input_list)310return PyNormaliz_cpp.NmzResult(self.cone, "Dehomogenization")311312def WitnessNotIntegrallyClosed(self, **kwargs):313input_list = self.__process_keyword_args(kwargs)314input_list.append("WitnessNotIntegrallyClosed")315PyNormaliz_cpp.NmzCompute(self.cone, input_list)316return PyNormaliz_cpp.NmzResult(self.cone, "WitnessNotIntegrallyClosed")317318def TriangulationSize(self, **kwargs):319input_list = self.__process_keyword_args(kwargs)320input_list.append("TriangulationSize")321PyNormaliz_cpp.NmzCompute(self.cone, input_list)322return PyNormaliz_cpp.NmzResult(self.cone, "TriangulationSize")323324def TriangulationDetSum(self, **kwargs):325input_list = self.__process_keyword_args(kwargs)326input_list.append("TriangulationDetSum")327PyNormaliz_cpp.NmzCompute(self.cone, input_list)328return PyNormaliz_cpp.NmzResult(self.cone, "TriangulationDetSum")329330def ReesPrimaryMultiplicity(self, **kwargs):331input_list = self.__process_keyword_args(kwargs)332input_list.append("ReesPrimaryMultiplicity")333PyNormaliz_cpp.NmzCompute(self.cone, input_list)334return PyNormaliz_cpp.NmzResult(self.cone, "ReesPrimaryMultiplicity")335336def GradingDenom(self, **kwargs):337input_list = self.__process_keyword_args(kwargs)338input_list.append("GradingDenom")339PyNormaliz_cpp.NmzCompute(self.cone, input_list)340return PyNormaliz_cpp.NmzResult(self.cone, "GradingDenom")341342def UnitGroupIndex(self, **kwargs):343input_list = self.__process_keyword_args(kwargs)344input_list.append("UnitGroupIndex")345PyNormaliz_cpp.NmzCompute(self.cone, input_list)346return PyNormaliz_cpp.NmzResult(self.cone, "UnitGroupIndex")347348def InternalIndex(self, **kwargs):349input_list = self.__process_keyword_args(kwargs)350input_list.append("InternalIndex")351PyNormaliz_cpp.NmzCompute(self.cone, input_list)352return PyNormaliz_cpp.NmzResult(self.cone, "InternalIndex")353354def ExternalIndex(self, **kwargs):355input_list = self.__process_keyword_args(kwargs)356input_list.append("ExternalIndex")357PyNormaliz_cpp.NmzCompute(self.cone, input_list)358return PyNormaliz_cpp.NmzResult(self.cone, "ExternalIndex")359360def Multiplicity(self, **kwargs):361input_list = self.__process_keyword_args(kwargs)362input_list.append("Multiplicity")363PyNormaliz_cpp.NmzCompute(self.cone, input_list)364return PyNormaliz_cpp.NmzResult(self.cone, "Multiplicity")365366def RecessionRank(self, **kwargs):367input_list = self.__process_keyword_args(kwargs)368input_list.append("RecessionRank")369PyNormaliz_cpp.NmzCompute(self.cone, input_list)370return PyNormaliz_cpp.NmzResult(self.cone, "RecessionRank")371372def AffineDim(self, **kwargs):373input_list = self.__process_keyword_args(kwargs)374input_list.append("AffineDim")375PyNormaliz_cpp.NmzCompute(self.cone, input_list)376return PyNormaliz_cpp.NmzResult(self.cone, "AffineDim")377378def ModuleRank(self, **kwargs):379input_list = self.__process_keyword_args(kwargs)380input_list.append("ModuleRank")381PyNormaliz_cpp.NmzCompute(self.cone, input_list)382return PyNormaliz_cpp.NmzResult(self.cone, "ModuleRank")383384def Rank(self, **kwargs):385input_list = self.__process_keyword_args(kwargs)386input_list.append("Rank")387PyNormaliz_cpp.NmzCompute(self.cone, input_list)388return PyNormaliz_cpp.NmzResult(self.cone, "Rank")389390def EmbeddingDim(self, **kwargs):391input_list = self.__process_keyword_args(kwargs)392input_list.append("EmbeddingDim")393PyNormaliz_cpp.NmzCompute(self.cone, input_list)394return PyNormaliz_cpp.NmzResult(self.cone, "EmbeddingDim")395396def IsPointed(self, **kwargs):397input_list = self.__process_keyword_args(kwargs)398input_list.append("IsPointed")399PyNormaliz_cpp.NmzCompute(self.cone, input_list)400return PyNormaliz_cpp.NmzResult(self.cone, "IsPointed")401402def IsDeg1ExtremeRays(self, **kwargs):403input_list = self.__process_keyword_args(kwargs)404input_list.append("IsDeg1ExtremeRays")405PyNormaliz_cpp.NmzCompute(self.cone, input_list)406return PyNormaliz_cpp.NmzResult(self.cone, "IsDeg1ExtremeRays")407408def IsDeg1HilbertBasis(self, **kwargs):409input_list = self.__process_keyword_args(kwargs)410input_list.append("IsDeg1HilbertBasis")411PyNormaliz_cpp.NmzCompute(self.cone, input_list)412return PyNormaliz_cpp.NmzResult(self.cone, "IsDeg1HilbertBasis")413414def IsIntegrallyClosed(self, **kwargs):415input_list = self.__process_keyword_args(kwargs)416input_list.append("IsIntegrallyClosed")417PyNormaliz_cpp.NmzCompute(self.cone, input_list)418return PyNormaliz_cpp.NmzResult(self.cone, "IsIntegrallyClosed")419420def IsReesPrimary(self, **kwargs):421input_list = self.__process_keyword_args(kwargs)422input_list.append("IsReesPrimary")423PyNormaliz_cpp.NmzCompute(self.cone, input_list)424return PyNormaliz_cpp.NmzResult(self.cone, "IsReesPrimary")425426def IsInhomogeneous(self, **kwargs):427input_list = self.__process_keyword_args(kwargs)428input_list.append("IsInhomogeneous")429PyNormaliz_cpp.NmzCompute(self.cone, input_list)430return PyNormaliz_cpp.NmzResult(self.cone, "IsInhomogeneous")431432def Triangulation(self, **kwargs):433input_list = self.__process_keyword_args(kwargs)434input_list.append("Triangulation")435PyNormaliz_cpp.NmzCompute(self.cone, input_list)436return PyNormaliz_cpp.NmzResult(self.cone, "Triangulation")437438def InclusionExclusionData(self, **kwargs):439input_list = self.__process_keyword_args(kwargs)440input_list.append("InclusionExclusionData")441PyNormaliz_cpp.NmzCompute(self.cone, input_list)442return PyNormaliz_cpp.NmzResult(self.cone, "InclusionExclusionData")443444def StanleyDec(self, **kwargs):445input_list = self.__process_keyword_args(kwargs)446input_list.append("StanleyDec")447PyNormaliz_cpp.NmzCompute(self.cone, input_list)448return PyNormaliz_cpp.NmzResult(self.cone, "StanleyDec")449450def ClassGroup(self, **kwargs):451input_list = self.__process_keyword_args(kwargs)452input_list.append("ClassGroup")453PyNormaliz_cpp.NmzCompute(self.cone, input_list)454return PyNormaliz_cpp.NmzResult(self.cone, "ClassGroup")455456def ConeDecomposition(self, **kwargs):457input_list = self.__process_keyword_args(kwargs)458input_list.append("ConeDecomposition")459PyNormaliz_cpp.NmzCompute(self.cone, input_list)460return PyNormaliz_cpp.NmzResult(self.cone, "ConeDecomposition")461462def HilbertQuasiPolynomial(self, **kwargs):463input_list = self.__process_keyword_args(kwargs)464input_list.append("HilbertQuasiPolynomial")465PyNormaliz_cpp.NmzCompute(self.cone, input_list)466return PyNormaliz_cpp.NmzResult(self.cone, "HilbertQuasiPolynomial")467468def IsTriangulationNested(self, **kwargs):469input_list = self.__process_keyword_args(kwargs)470input_list.append("IsTriangulationNested")471PyNormaliz_cpp.NmzCompute(self.cone, input_list)472return PyNormaliz_cpp.NmzResult(self.cone, "IsTriangulationNested")473474def IsTriangulationPartial(self, **kwargs):475input_list = self.__process_keyword_args(kwargs)476input_list.append("IsTriangulationPartial")477PyNormaliz_cpp.NmzCompute(self.cone, input_list)478return PyNormaliz_cpp.NmzResult(self.cone, "IsTriangulationPartial")479480def WeightedEhrhartQuasiPolynomial(self, **kwargs):481input_list = self.__process_keyword_args(kwargs)482input_list.append("WeightedEhrhartQuasiPolynomial")483PyNormaliz_cpp.NmzCompute(self.cone, input_list)484return PyNormaliz_cpp.NmzResult(self.cone, "WeightedEhrhartQuasiPolynomial")485486def WeightedEhrhartSeries(self, **kwargs):487input_list = self.__process_keyword_args(kwargs)488input_list.append("WeightedEhrhartSeries")489PyNormaliz_cpp.NmzCompute(self.cone, input_list)490return PyNormaliz_cpp.NmzResult(self.cone, "WeightedEhrhartSeries")491492def Integral(self, **kwargs):493input_list = self.__process_keyword_args(kwargs)494input_list.append("Integral")495PyNormaliz_cpp.NmzCompute(self.cone, input_list)496return PyNormaliz_cpp.NmzResult(self.cone, "Integral")497498def VirtualMultiplicity(self, **kwargs):499input_list = self.__process_keyword_args(kwargs)500input_list.append("VirtualMultiplicity")501PyNormaliz_cpp.NmzCompute(self.cone, input_list)502return PyNormaliz_cpp.NmzResult(self.cone, "VirtualMultiplicity")503504def IsGorenstein(self, **kwargs):505input_list = self.__process_keyword_args(kwargs)506input_list.append("IsGorenstein")507PyNormaliz_cpp.NmzCompute(self.cone, input_list)508return PyNormaliz_cpp.NmzResult(self.cone, "IsGorenstein")509510def GeneratorOfInterior(self, **kwargs):511input_list = self.__process_keyword_args(kwargs)512input_list.append("GeneratorOfInterior")513PyNormaliz_cpp.NmzCompute(self.cone, input_list)514return PyNormaliz_cpp.NmzResult(self.cone, "GeneratorOfInterior")515516def VerticesFloat(self, **kwargs):517input_list = self.__process_keyword_args(kwargs)518input_list.append("VerticesFloat")519PyNormaliz_cpp.NmzCompute(self.cone, input_list)520return PyNormaliz_cpp.NmzResult(self.cone, "VerticesFloat")521522523