CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

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

Views: 418384
1
# encoding=utf8
2
3
import PyNormaliz_cpp
4
from PyNormaliz_cpp import *
5
6
7
class Cone:
8
9
def __init__(self, *args, **kwargs):
10
input_list = [k for k in args]
11
for i in kwargs:
12
current_input = kwargs[i]
13
if type(current_input) == list and len(current_input) > 0 and type(current_input[0]) != list:
14
kwargs[i] = [current_input]
15
elif type(current_input) == bool and current_input == True:
16
kwargs[i] = current_input = [[]]
17
elif type(current_input) == bool and current_input == False:
18
kwargs.pop(i)
19
20
for i in kwargs:
21
input_list.append(i)
22
input_list.append(kwargs[i])
23
24
self.cone = PyNormaliz_cpp.NmzCone(input_list)
25
26
def __process_keyword_args(self, keywords):
27
input_list = []
28
for i in keywords:
29
if keywords[i] == True:
30
input_list.append(i)
31
return input_list
32
33
def print_properties(self):
34
props = PyNormaliz_cpp.NmzListConeProperties()
35
goals = props[0]
36
for x in goals:
37
if (PyNormaliz_cpp.NmzIsComputed(self.cone, x)):
38
print(x + ":")
39
print(PyNormaliz_cpp.NmzResult(self.cone, x))
40
print("\n")
41
42
def __str__(self):
43
return "<Normaliz Cone>"
44
45
def __repr__(self):
46
return "<Normaliz Cone>"
47
48
def Compute(self, *args):
49
return PyNormaliz_cpp.NmzCompute(self.cone, args)
50
51
def setVerbose(self, verbose=True):
52
return NmzSetVerbose(self.cone, verbose)
53
54
# This one is not like the others!
55
def IntegerHull(self, **kwargs):
56
input_list = self.__process_keyword_args(kwargs)
57
input_list.append("IntegerHull")
58
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
59
new_inner_cone = PyNormaliz_cpp.NmzResult(self.cone, "IntegerHull")
60
return_cone = Cone.__new__(Cone)
61
return_cone.cone = new_inner_cone
62
return return_cone
63
64
def HilbertSeries(self, **kwargs):
65
try:
66
as_hsop = kwargs["HSOP"]
67
except KeyError:
68
as_hsop = 28
69
input_list = self.__process_keyword_args(kwargs)
70
input_list.append("HilbertSeries")
71
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
72
if as_hsop == 28:
73
return PyNormaliz_cpp.NmzHilbertSeries(self.cone)
74
if type(as_hsop) == bool:
75
return PyNormaliz_cpp.NmzHilbertSeries(self.cone, as_hsop)
76
raise TypeError("If HSOP is given, it must be True or False")
77
78
def Polynomial(self, **kwargs):
79
return PyNormaliz_cpp.NmzGetPolynomial(self.cone)
80
81
def NrCoeffQuasiPol(self, bound=-1):
82
return PyNormaliz_cpp.NmzSetNrCoeffQuasiPol(self.cone, bound)
83
84
def SymmetrizedCone(self, **kwargs):
85
new_inner_cone = PyNormaliz_cpp.NmzSymmetrizedCone(self.cone)
86
if new_inner_cone == None:
87
return None
88
return_cone = Cone.__new__(Cone)
89
return_cone.cone = new_inner_cone
90
return return_cone
91
92
def PrettyPolynomialTuple(self, numCoefficients, denCoefficients):
93
"""
94
Strings for numerator and denominator of the a hilbert series.
95
96
Parameters
97
----------
98
numCoefficients : list
99
The coefficients for the numerator.
100
denCofficients : list
101
The coefficients for the denominator where the value represents the
102
exponent of 't' and the frequency indicates the outer coefficient.
103
104
Returns
105
-------
106
PrettyPolynomialTuple: tuple of strings
107
108
Examples
109
--------
110
111
>>> numCoefficients = [3, 7, 4, -4, -6, 5]
112
>>> denCoefficients = [1, 1, 2, 2, 2, 4]
113
>>> PrettyPolynomialTuple(numCoefficients,denCoefficients)
114
115
('(3 + 7t + 4t² - 4t³ - 6t⁴ + 5t⁵)', '(1 - t)² (1 - t²)³ (1 - t⁴)')
116
117
"""
118
def to_sup(s):
119
sups = {u'0': u'\u2070',
120
u'1': u'\xb9',
121
u'2': u'\xb2',
122
u'3': u'\xb3',
123
u'4': u'\u2074',
124
u'5': u'\u2075',
125
u'6': u'\u2076',
126
u'7': u'\u2077',
127
u'8': u'\u2078',
128
u'9': u'\u2079'}
129
if s is 1:
130
return ''
131
# lose the list comprehension
132
return ''.join(sups.get(str(char), str(char)) for char in str(s))
133
134
def getNumerator(coefficients):
135
136
numerator = ''
137
138
def isPositive(x):
139
return x > 0
140
141
firstNonZero = next(
142
(i for i, x in enumerate(coefficients) if x != 0), 0)
143
for exp, coefficient in enumerate(coefficients):
144
if coefficient is 0:
145
continue
146
# Exponent is 0 so keep only the coefficient
147
if exp is 0:
148
numerator += '({}{!s}'.format('-' if not isPositive(coefficient)
149
else '', abs(coefficient))
150
# Only include sign if `coefficient` is negative
151
elif i is firstNonZero:
152
numerator += '{}{!s}t{}'.format('-' if not isPositive(
153
coefficient) else '', abs(coefficient), to_sup(exp))
154
else:
155
numerator += ' {}{!s}t{}'.format('+ ' if isPositive(
156
coefficient) else '- ', abs(coefficient), to_sup(exp))
157
numerator += ')'
158
return numerator
159
160
def getDenominator(coefficients):
161
exponents = [(inner, coefficients.count(inner))
162
for inner in set(coefficients)]
163
denominator = ' '.join('(1 - t{}){}'. format(to_sup(x[0]) if x[
164
0] is not 1 else '', to_sup(x[1]) if x[1] is not 1 else '') for x in exponents)
165
return denominator
166
167
num = getNumerator(numCoefficients)
168
den = getDenominator(denCoefficients)
169
prettyPolynomial = (num, den)
170
return prettyPolynomial
171
172
def PrintPrettyHilbertSeries(self, numCoefficients, denCoefficients):
173
"""
174
Make a pretty hilbert series string
175
176
Parameters
177
----------
178
numCoefficients : list of ints
179
The coefficients for the numerator.
180
denCofficients : list of ints
181
The coefficients for the denominator where the value represents
182
the exponent of 't' and the frequency indicates the outer
183
coefficient.
184
185
Returns
186
-------
187
PrintPrettyHilbertSeries : string
188
189
Examples
190
--------
191
192
>>> numCoefficients = [3, 7, 4, -4, -6, 5]
193
>>> deCoefficients = [1, 1, 2, 2, 2, 4]
194
>>> PrintPrettyHilbertSeries(numCoefficients,deCoefficients)
195
196
(3 + 7t + 4t² - 4t³ - 6t⁴ + 5t⁵)
197
--------------------------------
198
(1 - t)² (1 - t²)³ (1 - t⁴)
199
200
"""
201
num, den = self.PrettyPolynomialTuple(numCoefficients, denCoefficients)
202
prettyPolynomial = '{:^}\n{:-^{width}}\n{:^{width}}'.format(
203
num, '', den, width=max(len(den),len(num)))
204
return prettyPolynomial
205
206
def PrintHilbertSeries(self):
207
hilbert_series=self.HilbertSeries()
208
shift=hilbert_series[2]
209
shift=[ 0 for x in range(1,shift) ]
210
numerator=shift+hilbert_series[0]
211
denominator=hilbert_series[1]
212
print(self.PrintPrettyHilbertSeries(numerator,denominator))
213
return None
214
215
# Auto generated stuff
216
217
def Generators(self, **kwargs):
218
input_list = self.__process_keyword_args(kwargs)
219
input_list.append("Generators")
220
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
221
return PyNormaliz_cpp.NmzResult(self.cone, "Generators")
222
223
def ExtremeRays(self, **kwargs):
224
input_list = self.__process_keyword_args(kwargs)
225
input_list.append("ExtremeRays")
226
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
227
return PyNormaliz_cpp.NmzResult(self.cone, "ExtremeRays")
228
229
def VerticesOfPolyhedron(self, **kwargs):
230
input_list = self.__process_keyword_args(kwargs)
231
input_list.append("VerticesOfPolyhedron")
232
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
233
return PyNormaliz_cpp.NmzResult(self.cone, "VerticesOfPolyhedron")
234
235
def SupportHyperplanes(self, **kwargs):
236
input_list = self.__process_keyword_args(kwargs)
237
input_list.append("SupportHyperplanes")
238
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
239
return PyNormaliz_cpp.NmzResult(self.cone, "SupportHyperplanes")
240
241
def HilbertBasis(self, **kwargs):
242
input_list = self.__process_keyword_args(kwargs)
243
input_list.append("HilbertBasis")
244
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
245
return PyNormaliz_cpp.NmzResult(self.cone, "HilbertBasis")
246
247
def ModuleGenerators(self, **kwargs):
248
input_list = self.__process_keyword_args(kwargs)
249
input_list.append("ModuleGenerators")
250
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
251
return PyNormaliz_cpp.NmzResult(self.cone, "ModuleGenerators")
252
253
def Deg1Elements(self, **kwargs):
254
input_list = self.__process_keyword_args(kwargs)
255
input_list.append("Deg1Elements")
256
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
257
return PyNormaliz_cpp.NmzResult(self.cone, "Deg1Elements")
258
259
def ModuleGeneratorsOverOriginalMonoid(self, **kwargs):
260
input_list = self.__process_keyword_args(kwargs)
261
input_list.append("ModuleGeneratorsOverOriginalMonoid")
262
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
263
return PyNormaliz_cpp.NmzResult(self.cone, "ModuleGeneratorsOverOriginalMonoid")
264
265
def Sublattice(self, **kwargs):
266
input_list = self.__process_keyword_args(kwargs)
267
input_list.append("Sublattice")
268
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
269
return PyNormaliz_cpp.NmzResult(self.cone, "Sublattice")
270
271
def ExcludedFaces(self, **kwargs):
272
input_list = self.__process_keyword_args(kwargs)
273
input_list.append("ExcludedFaces")
274
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
275
return PyNormaliz_cpp.NmzResult(self.cone, "ExcludedFaces")
276
277
def OriginalMonoidGenerators(self, **kwargs):
278
input_list = self.__process_keyword_args(kwargs)
279
input_list.append("OriginalMonoidGenerators")
280
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
281
return PyNormaliz_cpp.NmzResult(self.cone, "OriginalMonoidGenerators")
282
283
def MaximalSubspace(self, **kwargs):
284
input_list = self.__process_keyword_args(kwargs)
285
input_list.append("MaximalSubspace")
286
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
287
return PyNormaliz_cpp.NmzResult(self.cone, "MaximalSubspace")
288
289
def Equations(self, **kwargs):
290
input_list = self.__process_keyword_args(kwargs)
291
input_list.append("Equations")
292
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
293
return PyNormaliz_cpp.NmzResult(self.cone, "Equations")
294
295
def Congruences(self, **kwargs):
296
input_list = self.__process_keyword_args(kwargs)
297
input_list.append("Congruences")
298
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
299
return PyNormaliz_cpp.NmzResult(self.cone, "Congruences")
300
301
def Grading(self, **kwargs):
302
input_list = self.__process_keyword_args(kwargs)
303
input_list.append("Grading")
304
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
305
return PyNormaliz_cpp.NmzResult(self.cone, "Grading")
306
307
def Dehomogenization(self, **kwargs):
308
input_list = self.__process_keyword_args(kwargs)
309
input_list.append("Dehomogenization")
310
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
311
return PyNormaliz_cpp.NmzResult(self.cone, "Dehomogenization")
312
313
def WitnessNotIntegrallyClosed(self, **kwargs):
314
input_list = self.__process_keyword_args(kwargs)
315
input_list.append("WitnessNotIntegrallyClosed")
316
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
317
return PyNormaliz_cpp.NmzResult(self.cone, "WitnessNotIntegrallyClosed")
318
319
def TriangulationSize(self, **kwargs):
320
input_list = self.__process_keyword_args(kwargs)
321
input_list.append("TriangulationSize")
322
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
323
return PyNormaliz_cpp.NmzResult(self.cone, "TriangulationSize")
324
325
def TriangulationDetSum(self, **kwargs):
326
input_list = self.__process_keyword_args(kwargs)
327
input_list.append("TriangulationDetSum")
328
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
329
return PyNormaliz_cpp.NmzResult(self.cone, "TriangulationDetSum")
330
331
def ReesPrimaryMultiplicity(self, **kwargs):
332
input_list = self.__process_keyword_args(kwargs)
333
input_list.append("ReesPrimaryMultiplicity")
334
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
335
return PyNormaliz_cpp.NmzResult(self.cone, "ReesPrimaryMultiplicity")
336
337
def GradingDenom(self, **kwargs):
338
input_list = self.__process_keyword_args(kwargs)
339
input_list.append("GradingDenom")
340
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
341
return PyNormaliz_cpp.NmzResult(self.cone, "GradingDenom")
342
343
def UnitGroupIndex(self, **kwargs):
344
input_list = self.__process_keyword_args(kwargs)
345
input_list.append("UnitGroupIndex")
346
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
347
return PyNormaliz_cpp.NmzResult(self.cone, "UnitGroupIndex")
348
349
def InternalIndex(self, **kwargs):
350
input_list = self.__process_keyword_args(kwargs)
351
input_list.append("InternalIndex")
352
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
353
return PyNormaliz_cpp.NmzResult(self.cone, "InternalIndex")
354
355
def ExternalIndex(self, **kwargs):
356
input_list = self.__process_keyword_args(kwargs)
357
input_list.append("ExternalIndex")
358
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
359
return PyNormaliz_cpp.NmzResult(self.cone, "ExternalIndex")
360
361
def Multiplicity(self, **kwargs):
362
input_list = self.__process_keyword_args(kwargs)
363
input_list.append("Multiplicity")
364
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
365
return PyNormaliz_cpp.NmzResult(self.cone, "Multiplicity")
366
367
def RecessionRank(self, **kwargs):
368
input_list = self.__process_keyword_args(kwargs)
369
input_list.append("RecessionRank")
370
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
371
return PyNormaliz_cpp.NmzResult(self.cone, "RecessionRank")
372
373
def AffineDim(self, **kwargs):
374
input_list = self.__process_keyword_args(kwargs)
375
input_list.append("AffineDim")
376
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
377
return PyNormaliz_cpp.NmzResult(self.cone, "AffineDim")
378
379
def ModuleRank(self, **kwargs):
380
input_list = self.__process_keyword_args(kwargs)
381
input_list.append("ModuleRank")
382
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
383
return PyNormaliz_cpp.NmzResult(self.cone, "ModuleRank")
384
385
def Rank(self, **kwargs):
386
input_list = self.__process_keyword_args(kwargs)
387
input_list.append("Rank")
388
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
389
return PyNormaliz_cpp.NmzResult(self.cone, "Rank")
390
391
def EmbeddingDim(self, **kwargs):
392
input_list = self.__process_keyword_args(kwargs)
393
input_list.append("EmbeddingDim")
394
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
395
return PyNormaliz_cpp.NmzResult(self.cone, "EmbeddingDim")
396
397
def IsPointed(self, **kwargs):
398
input_list = self.__process_keyword_args(kwargs)
399
input_list.append("IsPointed")
400
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
401
return PyNormaliz_cpp.NmzResult(self.cone, "IsPointed")
402
403
def IsDeg1ExtremeRays(self, **kwargs):
404
input_list = self.__process_keyword_args(kwargs)
405
input_list.append("IsDeg1ExtremeRays")
406
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
407
return PyNormaliz_cpp.NmzResult(self.cone, "IsDeg1ExtremeRays")
408
409
def IsDeg1HilbertBasis(self, **kwargs):
410
input_list = self.__process_keyword_args(kwargs)
411
input_list.append("IsDeg1HilbertBasis")
412
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
413
return PyNormaliz_cpp.NmzResult(self.cone, "IsDeg1HilbertBasis")
414
415
def IsIntegrallyClosed(self, **kwargs):
416
input_list = self.__process_keyword_args(kwargs)
417
input_list.append("IsIntegrallyClosed")
418
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
419
return PyNormaliz_cpp.NmzResult(self.cone, "IsIntegrallyClosed")
420
421
def IsReesPrimary(self, **kwargs):
422
input_list = self.__process_keyword_args(kwargs)
423
input_list.append("IsReesPrimary")
424
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
425
return PyNormaliz_cpp.NmzResult(self.cone, "IsReesPrimary")
426
427
def IsInhomogeneous(self, **kwargs):
428
input_list = self.__process_keyword_args(kwargs)
429
input_list.append("IsInhomogeneous")
430
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
431
return PyNormaliz_cpp.NmzResult(self.cone, "IsInhomogeneous")
432
433
def Triangulation(self, **kwargs):
434
input_list = self.__process_keyword_args(kwargs)
435
input_list.append("Triangulation")
436
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
437
return PyNormaliz_cpp.NmzResult(self.cone, "Triangulation")
438
439
def InclusionExclusionData(self, **kwargs):
440
input_list = self.__process_keyword_args(kwargs)
441
input_list.append("InclusionExclusionData")
442
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
443
return PyNormaliz_cpp.NmzResult(self.cone, "InclusionExclusionData")
444
445
def StanleyDec(self, **kwargs):
446
input_list = self.__process_keyword_args(kwargs)
447
input_list.append("StanleyDec")
448
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
449
return PyNormaliz_cpp.NmzResult(self.cone, "StanleyDec")
450
451
def ClassGroup(self, **kwargs):
452
input_list = self.__process_keyword_args(kwargs)
453
input_list.append("ClassGroup")
454
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
455
return PyNormaliz_cpp.NmzResult(self.cone, "ClassGroup")
456
457
def ConeDecomposition(self, **kwargs):
458
input_list = self.__process_keyword_args(kwargs)
459
input_list.append("ConeDecomposition")
460
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
461
return PyNormaliz_cpp.NmzResult(self.cone, "ConeDecomposition")
462
463
def HilbertQuasiPolynomial(self, **kwargs):
464
input_list = self.__process_keyword_args(kwargs)
465
input_list.append("HilbertQuasiPolynomial")
466
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
467
return PyNormaliz_cpp.NmzResult(self.cone, "HilbertQuasiPolynomial")
468
469
def IsTriangulationNested(self, **kwargs):
470
input_list = self.__process_keyword_args(kwargs)
471
input_list.append("IsTriangulationNested")
472
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
473
return PyNormaliz_cpp.NmzResult(self.cone, "IsTriangulationNested")
474
475
def IsTriangulationPartial(self, **kwargs):
476
input_list = self.__process_keyword_args(kwargs)
477
input_list.append("IsTriangulationPartial")
478
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
479
return PyNormaliz_cpp.NmzResult(self.cone, "IsTriangulationPartial")
480
481
def WeightedEhrhartQuasiPolynomial(self, **kwargs):
482
input_list = self.__process_keyword_args(kwargs)
483
input_list.append("WeightedEhrhartQuasiPolynomial")
484
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
485
return PyNormaliz_cpp.NmzResult(self.cone, "WeightedEhrhartQuasiPolynomial")
486
487
def WeightedEhrhartSeries(self, **kwargs):
488
input_list = self.__process_keyword_args(kwargs)
489
input_list.append("WeightedEhrhartSeries")
490
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
491
return PyNormaliz_cpp.NmzResult(self.cone, "WeightedEhrhartSeries")
492
493
def Integral(self, **kwargs):
494
input_list = self.__process_keyword_args(kwargs)
495
input_list.append("Integral")
496
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
497
return PyNormaliz_cpp.NmzResult(self.cone, "Integral")
498
499
def VirtualMultiplicity(self, **kwargs):
500
input_list = self.__process_keyword_args(kwargs)
501
input_list.append("VirtualMultiplicity")
502
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
503
return PyNormaliz_cpp.NmzResult(self.cone, "VirtualMultiplicity")
504
505
def IsGorenstein(self, **kwargs):
506
input_list = self.__process_keyword_args(kwargs)
507
input_list.append("IsGorenstein")
508
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
509
return PyNormaliz_cpp.NmzResult(self.cone, "IsGorenstein")
510
511
def GeneratorOfInterior(self, **kwargs):
512
input_list = self.__process_keyword_args(kwargs)
513
input_list.append("GeneratorOfInterior")
514
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
515
return PyNormaliz_cpp.NmzResult(self.cone, "GeneratorOfInterior")
516
517
def VerticesFloat(self, **kwargs):
518
input_list = self.__process_keyword_args(kwargs)
519
input_list.append("VerticesFloat")
520
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
521
return PyNormaliz_cpp.NmzResult(self.cone, "VerticesFloat")
522
523