Skip to content

Commit 24e4084

Browse files
committed
change lambda to def
1 parent 31bfb69 commit 24e4084

File tree

1 file changed

+57
-57
lines changed

1 file changed

+57
-57
lines changed

src/sage/combinat/bijectionist.py

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
4343
sage: N = 3
4444
sage: A = B = [pi for n in range(N+1) for pi in Permutations(n)]
45-
sage: alpha1 = lambda p: len(p.weak_excedences())
46-
sage: alpha2 = lambda p: len(p.fixed_points())
47-
sage: beta1 = lambda p: len(p.descents(final_descent=True)) if p else 0
48-
sage: beta2 = lambda p: len([e for (e, f) in zip(p, p[1:]+[0]) if e == f+1])
45+
sage: def alpha1(p): return len(p.weak_excedences())
46+
sage: def alpha2(p): return len(p.fixed_points())
47+
sage: def beta1(p): return len(p.descents(final_descent=True)) if p else 0
48+
sage: def beta2(p): return len([e for (e, f) in zip(p, p[1:]+[0]) if e == f+1])
4949
sage: tau = Permutation.longest_increasing_subsequence_length
5050
sage: def rotate_permutation(p):
5151
....: cycle = Permutation(tuple(range(1, len(p)+1)))
@@ -125,7 +125,7 @@
125125
sage: N = 8;
126126
sage: A = [SetPartition(d.to_noncrossing_partition()) for n in range(N) for d in DyckWords(n)]
127127
sage: B = [t for n in range(1, N+1) for t in OrderedTrees(n)]
128-
sage: theta = lambda m: SetPartition([[i % m.size() + 1 for i in b] for b in m])
128+
sage: def theta(m): return SetPartition([[i % m.size() + 1 for i in b] for b in m])
129129
130130
The following code is equivalent to ``tau = findstat(397)``::
131131
@@ -195,7 +195,7 @@
195195
TESTS::
196196
197197
sage: N = 4; A = B = [permutation for n in range(N) for permutation in Permutations(n)]
198-
sage: theta = lambda pi: Permutation([x+1 if x != len(pi) else 1 for x in pi[-1:]+pi[:-1]])
198+
sage: def theta(pi): return Permutation([x+1 if x != len(pi) else 1 for x in pi[-1:]+pi[:-1]])
199199
sage: def tau(pi):
200200
....: n = len(pi)
201201
....: return sum([1 for i in range(1, n+1) for j in range(1, n+1)
@@ -213,9 +213,9 @@
213213
A test including intertwining relations::
214214
215215
sage: N = 2; A = B = [dyck_word for n in range(N+1) for dyck_word in DyckWords(n)]
216-
sage: alpha = lambda D: (D.area(), D.bounce())
217-
sage: beta = lambda D: (D.bounce(), D.area())
218-
sage: tau = lambda D: D.number_of_touch_points()
216+
sage: def alpha(D): return (D.area(), D.bounce())
217+
sage: def beta(D): return (D.bounce(), D.area())
218+
sage: def tau(D): return D.number_of_touch_points()
219219
220220
The following looks correct::
221221
@@ -263,9 +263,9 @@
263263
Repeating some tests, but using the constructor instead of set_XXX() methods:
264264
265265
sage: N = 2; A = B = [dyck_word for n in range(N+1) for dyck_word in DyckWords(n)]
266-
sage: alpha = lambda D: (D.area(), D.bounce())
267-
sage: beta = lambda D: (D.bounce(), D.area())
268-
sage: tau = lambda D: D.number_of_touch_points()
266+
sage: def alpha(D): return (D.area(), D.bounce())
267+
sage: def beta(D): return (D.bounce(), D.area())
268+
sage: def tau(D): return D.number_of_touch_points()
269269
270270
sage: bij = Bijectionist(A, B, tau, alpha_beta=((lambda d: d.semilength(), lambda d: d.semilength()),))
271271
sage: for solution in sorted(list(bij.solutions_iterator()), key=lambda d: tuple(sorted(d.items()))):
@@ -276,8 +276,8 @@
276276
Constant blocks::
277277
278278
sage: A = B = 'abcd'
279-
sage: pi = lambda p1, p2: 'abcdefgh'[A.index(p1) + A.index(p2)]
280-
sage: rho = lambda s1, s2: (s1 + s2) % 2
279+
sage: def pi(p1, p2): return 'abcdefgh'[A.index(p1) + A.index(p2)]
280+
sage: def rho(s1, s2): return (s1 + s2) % 2
281281
sage: bij = Bijectionist(A, B, lambda x: B.index(x) % 2, P=[['a', 'c']], pi_rho=((2, pi, rho),))
282282
sage: list(bij.solutions_iterator())
283283
[{'a': 0, 'b': 1, 'c': 0, 'd': 1}]
@@ -298,7 +298,7 @@
298298
299299
Intertwining relations::
300300
301-
sage: concat = lambda p1, p2: Permutation(p1 + [i + len(p1) for i in p2])
301+
sage: def concat(p1, p2): return Permutation(p1 + [i + len(p1) for i in p2])
302302
303303
sage: A = B = [permutation for n in range(4) for permutation in Permutations(n)]
304304
sage: bij = Bijectionist(A, B, Permutation.number_of_fixed_points, alpha_beta=((len, len),), pi_rho=((2, concat, lambda x, y: x + y),))
@@ -311,9 +311,9 @@
311311
Statistics::
312312
313313
sage: N = 4; A = B = [permutation for n in range(N) for permutation in Permutations(n)]
314-
sage: wex = lambda p: len(p.weak_excedences())
315-
sage: fix = lambda p: len(p.fixed_points())
316-
sage: des = lambda p: len(p.descents(final_descent=True)) if p else 0
314+
sage: def wex(p): return len(p.weak_excedences())
315+
sage: def fix(p): return len(p.fixed_points())
316+
sage: def des(p): return len(p.descents(final_descent=True)) if p else 0
317317
sage: bij = Bijectionist(A, B, fix, alpha_beta=((wex, des), (len, len)))
318318
sage: for solution in sorted(list(bij.solutions_iterator()), key=lambda d: tuple(sorted(d.items()))):
319319
....: print(solution)
@@ -567,8 +567,8 @@ def set_constant_blocks(self, P):
567567
568568
We now add a map that combines some blocks::
569569
570-
sage: pi = lambda p1, p2: 'abcdefgh'[A.index(p1) + A.index(p2)]
571-
sage: rho = lambda s1, s2: (s1 + s2) % 2
570+
sage: def pi(p1, p2): return 'abcdefgh'[A.index(p1) + A.index(p2)]
571+
sage: def rho(s1, s2): return (s1 + s2) % 2
572572
sage: bij.set_intertwining_relations((2, pi, rho))
573573
sage: list(bij.solutions_iterator())
574574
[{'a': 0, 'b': 1, 'c': 0, 'd': 1}]
@@ -672,10 +672,10 @@ def set_statistics(self, *alpha_beta):
672672
of fixed points of `S(\pi)` equals `s(\pi)`::
673673
674674
sage: N = 4; A = B = [permutation for n in range(N) for permutation in Permutations(n)]
675-
sage: wex = lambda p: len(p.weak_excedences())
676-
sage: fix = lambda p: len(p.fixed_points())
677-
sage: des = lambda p: len(p.descents(final_descent=True)) if p else 0
678-
sage: adj = lambda p: len([e for (e, f) in zip(p, p[1:]+[0]) if e == f+1])
675+
sage: def wex(p): return len(p.weak_excedences())
676+
sage: def fix(p): return len(p.fixed_points())
677+
sage: def des(p): return len(p.descents(final_descent=True)) if p else 0
678+
sage: def adj(p): return len([e for (e, f) in zip(p, p[1:]+[0]) if e == f+1])
679679
sage: bij = Bijectionist(A, B, fix)
680680
sage: bij.set_statistics((wex, des), (len, len))
681681
sage: for solution in sorted(list(bij.solutions_iterator()), key=lambda d: tuple(sorted(d.items()))):
@@ -708,9 +708,9 @@ def set_statistics(self, *alpha_beta):
708708
Calling ``set_statistics`` without arguments should restore the previous state::
709709
710710
sage: N = 3; A = B = [permutation for n in range(N) for permutation in Permutations(n)]
711-
sage: wex = lambda p: len(p.weak_excedences())
712-
sage: fix = lambda p: len(p.fixed_points())
713-
sage: des = lambda p: len(p.descents(final_descent=True)) if p else 0
711+
sage: def wex(p): return len(p.weak_excedences())
712+
sage: def fix(p): return len(p.fixed_points())
713+
sage: def des(p): return len(p.descents(final_descent=True)) if p else 0
714714
sage: bij = Bijectionist(A, B, fix)
715715
sage: bij.set_statistics((wex, des), (len, len))
716716
sage: for solution in bij.solutions_iterator():
@@ -783,10 +783,10 @@ def statistics_fibers(self):
783783
784784
sage: A = B = [permutation for n in range(4) for permutation in Permutations(n)]
785785
sage: tau = Permutation.longest_increasing_subsequence_length
786-
sage: wex = lambda p: len(p.weak_excedences())
787-
sage: fix = lambda p: len(p.fixed_points())
788-
sage: des = lambda p: len(p.descents(final_descent=True)) if p else 0
789-
sage: adj = lambda p: len([e for (e, f) in zip(p, p[1:]+[0]) if e == f+1])
786+
sage: def wex(p): return len(p.weak_excedences())
787+
sage: def fix(p): return len(p.fixed_points())
788+
sage: def des(p): return len(p.descents(final_descent=True)) if p else 0
789+
sage: def adj(p): return len([e for (e, f) in zip(p, p[1:]+[0]) if e == f+1])
790790
sage: bij = Bijectionist(A, B, tau)
791791
sage: bij.set_statistics((len, len), (wex, des), (fix, adj))
792792
sage: table([[key, AB[0], AB[1]] for key, AB in bij.statistics_fibers().items()])
@@ -828,10 +828,10 @@ def statistics_table(self, header=True):
828828
829829
sage: A = B = [permutation for n in range(4) for permutation in Permutations(n)]
830830
sage: tau = Permutation.longest_increasing_subsequence_length
831-
sage: wex = lambda p: len(p.weak_excedences())
832-
sage: fix = lambda p: len(p.fixed_points())
833-
sage: des = lambda p: len(p.descents(final_descent=True)) if p else 0
834-
sage: adj = lambda p: len([e for (e, f) in zip(p, p[1:]+[0]) if e == f+1])
831+
sage: def wex(p): return len(p.weak_excedences())
832+
sage: def fix(p): return len(p.fixed_points())
833+
sage: def des(p): return len(p.descents(final_descent=True)) if p else 0
834+
sage: def adj(p): return len([e for (e, f) in zip(p, p[1:]+[0]) if e == f+1])
835835
sage: bij = Bijectionist(A, B, tau)
836836
sage: bij.set_statistics((wex, des), (fix, adj))
837837
sage: a, b = bij.statistics_table()
@@ -1193,8 +1193,8 @@ def set_distributions(self, *elements_distributions):
11931193
Another example with statistics::
11941194
11951195
sage: bij = Bijectionist(A, B, tau)
1196-
sage: alpha = lambda p: p(1) if len(p) > 0 else 0
1197-
sage: beta = lambda p: p(1) if len(p) > 0 else 0
1196+
sage: def alpha(p): return p(1) if len(p) > 0 else 0
1197+
sage: def beta(p): return p(1) if len(p) > 0 else 0
11981198
sage: bij.set_statistics((alpha, beta), (len, len))
11991199
sage: for sol in sorted(list(bij.solutions_iterator()), key=lambda d: tuple(sorted(d.items()))):
12001200
....: print(sol)
@@ -1304,7 +1304,7 @@ def set_intertwining_relations(self, *pi_rho):
13041304
of the second permutation by the length of the first
13051305
permutation::
13061306
1307-
sage: concat = lambda p1, p2: Permutation(p1 + [i + len(p1) for i in p2])
1307+
sage: def concat(p1, p2): return Permutation(p1 + [i + len(p1) for i in p2])
13081308
13091309
We may be interested in statistics on permutations which are
13101310
equidistributed with the number of fixed points, such that
@@ -1496,7 +1496,7 @@ def _forced_constant_blocks(self):
14961496
14971497
sage: N = 4
14981498
sage: A = B = [permutation for n in range(2, N) for permutation in Permutations(n)]
1499-
sage: tau = lambda p: p[0] if len(p) else 0
1499+
sage: def tau(p): return p[0] if len(p) else 0
15001500
sage: add_n = lambda p1: Permutation(p1 + [1 + len(p1)])
15011501
sage: add_1 = lambda p1: Permutation([1] + [1 + i for i in p1])
15021502
sage: bij = Bijectionist(A, B, tau)
@@ -1528,8 +1528,8 @@ def _forced_constant_blocks(self):
15281528
sage: bij.constant_blocks()
15291529
{{[2, 3, 1], [3, 1, 2]}}
15301530
1531-
sage: concat = lambda p1, p2: Permutation(p1 + [i + len(p1) for i in p2])
1532-
sage: union = lambda p1, p2: Partition(sorted(list(p1) + list(p2), reverse=True))
1531+
sage: def concat(p1, p2): return Permutation(p1 + [i + len(p1) for i in p2])
1532+
sage: def union(p1, p2): return Partition(sorted(list(p1) + list(p2), reverse=True))
15331533
sage: bij.set_intertwining_relations((2, concat, union))
15341534
15351535
In this case we do not discover constant blocks by looking at the intertwining_relations only::
@@ -1546,10 +1546,10 @@ def _forced_constant_blocks(self):
15461546
15471547
sage: N = 4
15481548
sage: A = B = [permutation for n in range(N + 1) for permutation in Permutations(n)]
1549-
sage: alpha1 = lambda p: len(p.weak_excedences())
1550-
sage: alpha2 = lambda p: len(p.fixed_points())
1551-
sage: beta1 = lambda p: len(p.descents(final_descent=True)) if p else 0
1552-
sage: beta2 = lambda p: len([e for (e, f) in zip(p, p[1:] + [0]) if e == f + 1])
1549+
sage: def alpha1(p): return len(p.weak_excedences())
1550+
sage: def alpha2(p): return len(p.fixed_points())
1551+
sage: def beta1(p): return len(p.descents(final_descent=True)) if p else 0
1552+
sage: def beta2(p): return len([e for (e, f) in zip(p, p[1:] + [0]) if e == f + 1])
15531553
sage: tau = Permutation.longest_increasing_subsequence_length
15541554
sage: def rotate_permutation(p):
15551555
....: cycle = Permutation(tuple(range(1, len(p) + 1)))
@@ -1826,7 +1826,7 @@ def minimal_subdistributions_iterator(self):
18261826
Another example::
18271827
18281828
sage: N = 2; A = B = [dyck_word for n in range(N+1) for dyck_word in DyckWords(n)]
1829-
sage: tau = lambda D: D.number_of_touch_points()
1829+
sage: def tau(D): return D.number_of_touch_points()
18301830
sage: bij = Bijectionist(A, B, tau)
18311831
sage: bij.set_statistics((lambda d: d.semilength(), lambda d: d.semilength()))
18321832
sage: for solution in sorted(list(bij.solutions_iterator()), key=lambda d: tuple(sorted(d.items()))):
@@ -1974,7 +1974,7 @@ def minimal_subdistributions_blocks_iterator(self):
19741974
Another example::
19751975
19761976
sage: N = 2; A = B = [dyck_word for n in range(N+1) for dyck_word in DyckWords(n)]
1977-
sage: tau = lambda D: D.number_of_touch_points()
1977+
sage: def tau(D): return D.number_of_touch_points()
19781978
sage: bij = Bijectionist(A, B, tau)
19791979
sage: bij.set_statistics((lambda d: d.semilength(), lambda d: d.semilength()))
19801980
sage: for solution in sorted(list(bij.solutions_iterator()), key=lambda d: tuple(sorted(d.items()))):
@@ -2143,8 +2143,8 @@ def _preprocess_intertwining_relations(self):
21432143
21442144
sage: A = B = 'abcd'
21452145
sage: bij = Bijectionist(A, B, lambda x: B.index(x) % 2)
2146-
sage: pi = lambda p1, p2: 'abcdefgh'[A.index(p1) + A.index(p2)]
2147-
sage: rho = lambda s1, s2: (s1 + s2) % 2
2146+
sage: def pi(p1, p2): return 'abcdefgh'[A.index(p1) + A.index(p2)]
2147+
sage: def rho(s1, s2): return (s1 + s2) % 2
21482148
sage: bij.set_intertwining_relations((2, pi, rho))
21492149
sage: bij._preprocess_intertwining_relations()
21502150
sage: bij._P
@@ -2909,8 +2909,8 @@ def add_intertwining_relation_constraints(self):
29092909
29102910
sage: A = B = 'abcd'
29112911
sage: bij = Bijectionist(A, B, lambda x: B.index(x) % 2)
2912-
sage: pi = lambda p1, p2: 'abcdefgh'[A.index(p1) + A.index(p2)]
2913-
sage: rho = lambda s1, s2: (s1 + s2) % 2
2912+
sage: def pi(p1, p2): return 'abcdefgh'[A.index(p1) + A.index(p2)]
2913+
sage: def rho(s1, s2): return (s1 + s2) % 2
29142914
sage: bij.set_intertwining_relations((2, pi, rho))
29152915
sage: from sage.combinat.bijectionist import _BijectionistMILP
29162916
sage: bmilp = _BijectionistMILP(bij) # indirect doctest
@@ -3127,8 +3127,8 @@ def _non_copying_intersection(sets):
31273127
Note that adding ``[(2,-2,-1), (2,2,-1), (2,-2,1), (2,2,1)]`` makes
31283128
it take (seemingly) forever.::
31293129
3130-
sage: c1 = lambda a, b: (a[0]+b[0], a[1]*b[1], a[2]*b[2])
3131-
sage: c2 = lambda a: (a[0], -a[1], a[2])
3130+
sage: def c1(a, b): return (a[0]+b[0], a[1]*b[1], a[2]*b[2])
3131+
sage: def c2(a): return (a[0], -a[1], a[2])
31323132
31333133
sage: bij = Bijectionist(sum(As, []), sum(Bs, []))
31343134
sage: bij.set_statistics((lambda x: x[0], lambda x: x[0]))
@@ -3168,10 +3168,10 @@ def _non_copying_intersection(sets):
31683168
Our benchmark example::
31693169
31703170
sage: from sage.combinat.cyclic_sieving_phenomenon import orbit_decomposition
3171-
sage: alpha1 = lambda p: len(p.weak_excedences())
3172-
sage: alpha2 = lambda p: len(p.fixed_points())
3173-
sage: beta1 = lambda p: len(p.descents(final_descent=True)) if p else 0
3174-
sage: beta2 = lambda p: len([e for (e, f) in zip(p, p[1:]+[0]) if e == f+1])
3171+
sage: def alpha1(p): return len(p.weak_excedences())
3172+
sage: def alpha2(p): return len(p.fixed_points())
3173+
sage: def beta1(p): return len(p.descents(final_descent=True)) if p else 0
3174+
sage: def beta2(p): return len([e for (e, f) in zip(p, p[1:]+[0]) if e == f+1])
31753175
sage: gamma = Permutation.longest_increasing_subsequence_length
31763176
sage: def rotate_permutation(p):
31773177
....: cycle = Permutation(tuple(range(1, len(p)+1)))

0 commit comments

Comments
 (0)