Skip to content

Commit b086f94

Browse files
committed
Trac #22067 comment:117 and comment:121: make code for split=True more transparent
1 parent 122d080 commit b086f94

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/sage/geometry/polyhedron/generating_function.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -512,16 +512,21 @@ def generating_function_of_integral_points(polyhedron, split=False,
512512

513513
parts = None
514514
if split is True:
515-
split = (
516-
(Polyhedron(
517-
ieqs=[tuple(1 if i==b else (-1 if i==a or i==0 and a > b else 0)
518-
for i in range(d+1))
519-
for a, b in zip(pi[:-1], pi[1:])]),
520-
'b{}'.format(pi[0]-1) +
521-
''.join((' <= ' if a < b else ' < ') +
522-
'b{}'.format(b-1)
523-
for a, b in zip(pi[:-1], pi[1:])))
524-
for pi in Permutations(d))
515+
def polyhedron_from_permutation(pi):
516+
def ieq(a, b):
517+
return ((0 if a < b else -1,) +
518+
tuple(1 if i==b else (-1 if i==a else 0)
519+
for i in range(1, d+1)))
520+
def ieq_repr_rhs(a, b):
521+
return (' <= ' if a < b else ' < ') + 'b{}'.format(b-1)
522+
def ieqs_repr_lhs(pi):
523+
return 'b{}'.format(pi[0]-1)
524+
525+
ieqs, repr_rhss = zip(*[(ieq(a, b), ieq_repr_rhs(a, b))
526+
for a, b in zip(pi[:-1], pi[1:])])
527+
return Polyhedron(ieqs=ieqs), ieqs_repr_lhs(pi) + ''.join(repr_rhss)
528+
529+
split = (polyhedron_from_permutation(pi) for pi in Permutations(d))
525530
parts = ZZ(d).factorial()
526531
else:
527532
if isinstance(split, (list, tuple)):

0 commit comments

Comments
 (0)