passagemath-repl 10.5.28__py3-none-any.whl → 10.5.30__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- passagemath_repl-10.5.30.data/data/share/jupyter/kernels/sagemath/kernel.json +1 -0
- passagemath_repl-10.5.30.data/data/share/jupyter/kernels/sagemath/logo-64x64.png +0 -0
- passagemath_repl-10.5.30.data/data/share/jupyter/kernels/sagemath/logo.svg +352 -0
- {passagemath_repl-10.5.28.dist-info → passagemath_repl-10.5.30.dist-info}/METADATA +3 -3
- {passagemath_repl-10.5.28.dist-info → passagemath_repl-10.5.30.dist-info}/RECORD +95 -24
- {passagemath_repl-10.5.28.dist-info → passagemath_repl-10.5.30.dist-info}/top_level.txt +1 -0
- sage/ext_data/all__sagemath_repl.py +1 -0
- sage/interfaces/all__sagemath_repl.py +1 -0
- sage/repl/ipython_kernel/install.py +6 -8
- sage/tests/books/__init__.py +2 -0
- sage/tests/books/computational-mathematics-with-sagemath/__init__.py +1 -0
- sage/tests/books/computational-mathematics-with-sagemath/calculus_doctest.py +550 -0
- sage/tests/books/computational-mathematics-with-sagemath/combinat_doctest.py +1054 -0
- sage/tests/books/computational-mathematics-with-sagemath/domaines_doctest.py +444 -0
- sage/tests/books/computational-mathematics-with-sagemath/float_doctest.py +478 -0
- sage/tests/books/computational-mathematics-with-sagemath/graphique_doctest.py +255 -0
- sage/tests/books/computational-mathematics-with-sagemath/graphtheory_doctest.py +419 -0
- sage/tests/books/computational-mathematics-with-sagemath/integration_doctest.py +291 -0
- sage/tests/books/computational-mathematics-with-sagemath/linalg_doctest.py +455 -0
- sage/tests/books/computational-mathematics-with-sagemath/linsolve_doctest.py +422 -0
- sage/tests/books/computational-mathematics-with-sagemath/lp_doctest.py +235 -0
- sage/tests/books/computational-mathematics-with-sagemath/mpoly_doctest.py +561 -0
- sage/tests/books/computational-mathematics-with-sagemath/nonlinear_doctest.py +491 -0
- sage/tests/books/computational-mathematics-with-sagemath/numbertheory_doctest.py +156 -0
- sage/tests/books/computational-mathematics-with-sagemath/polynomes_doctest.py +406 -0
- sage/tests/books/computational-mathematics-with-sagemath/premierspas_doctest.py +181 -0
- sage/tests/books/computational-mathematics-with-sagemath/programmation_doctest.py +663 -0
- sage/tests/books/computational-mathematics-with-sagemath/recequadiff_doctest.py +393 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/__init__.py +1 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/calculus_doctest.py +265 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/combinat_doctest.py +218 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/domaines_doctest.py +60 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/float_doctest.py +142 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/graphique_doctest.py +106 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/graphtheory_doctest.py +54 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/integration_doctest.py +57 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/linalg_doctest.py +57 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/linsolve_doctest.py +26 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/lp_doctest.py +48 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/mpoly_doctest.py +116 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/nonlinear_doctest.py +112 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/numbertheory_doctest.py +168 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/polynomes_doctest.py +108 -0
- sage/tests/books/computational-mathematics-with-sagemath/sol/recequadiff_doctest.py +59 -0
- sage/tests/books/judson-abstract-algebra/__init__.py +1 -0
- sage/tests/books/judson-abstract-algebra/actions-sage-exercises.py +52 -0
- sage/tests/books/judson-abstract-algebra/actions-sage.py +174 -0
- sage/tests/books/judson-abstract-algebra/algcodes-sage.py +131 -0
- sage/tests/books/judson-abstract-algebra/boolean-sage.py +270 -0
- sage/tests/books/judson-abstract-algebra/cosets-sage-exercises.py +88 -0
- sage/tests/books/judson-abstract-algebra/cosets-sage.py +171 -0
- sage/tests/books/judson-abstract-algebra/crypt-sage.py +152 -0
- sage/tests/books/judson-abstract-algebra/cyclic-sage.py +451 -0
- sage/tests/books/judson-abstract-algebra/domains-sage.py +164 -0
- sage/tests/books/judson-abstract-algebra/fields-sage.py +300 -0
- sage/tests/books/judson-abstract-algebra/finite-sage.py +109 -0
- sage/tests/books/judson-abstract-algebra/galois-sage.py +485 -0
- sage/tests/books/judson-abstract-algebra/groups-sage.py +281 -0
- sage/tests/books/judson-abstract-algebra/homomorph-sage-exercises.py +66 -0
- sage/tests/books/judson-abstract-algebra/homomorph-sage.py +201 -0
- sage/tests/books/judson-abstract-algebra/integers-sage.py +198 -0
- sage/tests/books/judson-abstract-algebra/isomorph-sage.py +173 -0
- sage/tests/books/judson-abstract-algebra/normal-sage.py +134 -0
- sage/tests/books/judson-abstract-algebra/permute-sage.py +320 -0
- sage/tests/books/judson-abstract-algebra/poly-sage.py +301 -0
- sage/tests/books/judson-abstract-algebra/rings-sage.py +414 -0
- sage/tests/books/judson-abstract-algebra/sets-sage.py +164 -0
- sage/tests/books/judson-abstract-algebra/struct-sage.py +64 -0
- sage/tests/books/judson-abstract-algebra/sylow-sage.py +251 -0
- sage/tests/books/judson-abstract-algebra/vect-sage-exercises.py +49 -0
- sage/tests/books/judson-abstract-algebra/vect-sage.py +212 -0
- sage/tests/memcheck/__init__.py +1 -0
- sage/tests/memcheck/run_tests.py +25 -0
- sage/tests/memcheck/run_tests_in_valgrind.py +36 -0
- sage/tests/memcheck/symbolic_expression.py +12 -0
- sage/tests/memcheck/verify_no_leak.py +28 -0
- sage/tests/all.py +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-cachegrind +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-callgrind +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-cleaner +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-coverage +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-eval +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-fixdoctests +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-inline-fortran +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-ipynb2rst +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-ipython +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-massif +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-notebook +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-omega +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-preparse +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-run +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-run-cython +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-runtests +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-startuptime.py +0 -0
- {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-valgrind +0 -0
- {passagemath_repl-10.5.28.dist-info → passagemath_repl-10.5.30.dist-info}/WHEEL +0 -0
@@ -0,0 +1,1054 @@
|
|
1
|
+
# sage_setup: distribution = sagemath-repl
|
2
|
+
# sage.doctest: needs sage.symbolic
|
3
|
+
"""
|
4
|
+
This file (./combinat_doctest.sage) was *autogenerated* from ./combinat.tex,
|
5
|
+
with sagetex.sty version 2011/05/27 v2.3.1.
|
6
|
+
It contains the contents of all the sageexample environments from this file.
|
7
|
+
You should be able to doctest this file with:
|
8
|
+
sage -t ./combinat_doctest.sage
|
9
|
+
It is always safe to delete this file; it is not used in typesetting your
|
10
|
+
document.
|
11
|
+
|
12
|
+
Sage example in ./combinat.tex, line 147::
|
13
|
+
|
14
|
+
sage: Suits = Set(["Hearts", "Diamonds", "Spades", "Clubs"])
|
15
|
+
sage: Values = Set([2, 3, 4, 5, 6, 7, 8, 9, 10,
|
16
|
+
....: "Jack", "Queen", "King", "Ace"])
|
17
|
+
sage: Cards = cartesian_product([Values, Suits])
|
18
|
+
|
19
|
+
Sage example in ./combinat.tex, line 167::
|
20
|
+
|
21
|
+
sage: Suits.cardinality()
|
22
|
+
4
|
23
|
+
sage: Values.cardinality()
|
24
|
+
13
|
25
|
+
sage: Cards.cardinality()
|
26
|
+
52
|
27
|
+
|
28
|
+
Sage example in ./combinat.tex, line 184::
|
29
|
+
|
30
|
+
sage: Cards.random_element() # random
|
31
|
+
(6, 'Clubs')
|
32
|
+
|
33
|
+
Sage example in ./combinat.tex, line 196::
|
34
|
+
|
35
|
+
sage: Set([Cards.random_element(), Cards.random_element()]) # random
|
36
|
+
{(2, 'Hearts'), (4, 'Spades')}
|
37
|
+
|
38
|
+
Sage example in ./combinat.tex, line 221::
|
39
|
+
|
40
|
+
sage: Hands = Subsets(Cards, 5)
|
41
|
+
sage: Hands.random_element() # random
|
42
|
+
{(4, 'Hearts'), (9, 'Diamonds'), (8, 'Spades'),
|
43
|
+
(9, 'Clubs'), (7, 'Hearts')}
|
44
|
+
|
45
|
+
Sage example in ./combinat.tex, line 236::
|
46
|
+
|
47
|
+
sage: binomial(52, 5)
|
48
|
+
2598960
|
49
|
+
|
50
|
+
Sage example in ./combinat.tex, line 250::
|
51
|
+
|
52
|
+
sage: Hands.cardinality()
|
53
|
+
2598960
|
54
|
+
|
55
|
+
Sage example in ./combinat.tex, line 283::
|
56
|
+
|
57
|
+
sage: Flushes = cartesian_product([Subsets(Values, 5), Suits])
|
58
|
+
sage: Flushes.cardinality()
|
59
|
+
5148
|
60
|
+
|
61
|
+
Sage example in ./combinat.tex, line 305::
|
62
|
+
|
63
|
+
sage: Flushes.cardinality() / Hands.cardinality()
|
64
|
+
33/16660
|
65
|
+
|
66
|
+
Sage example in ./combinat.tex, line 310::
|
67
|
+
|
68
|
+
sage: 1000.0 * Flushes.cardinality() / Hands.cardinality()
|
69
|
+
1.98079231692677
|
70
|
+
|
71
|
+
Sage example in ./combinat.tex, line 345::
|
72
|
+
|
73
|
+
sage: def is_flush(hand):
|
74
|
+
....: return len(set(suit for (val, suit) in hand)) == 1
|
75
|
+
|
76
|
+
Sage example in ./combinat.tex, line 354::
|
77
|
+
|
78
|
+
sage: n = 10000
|
79
|
+
sage: nflush = 0
|
80
|
+
sage: for i in range(n):
|
81
|
+
....: hand = Hands.random_element()
|
82
|
+
....: if is_flush(hand):
|
83
|
+
....: nflush += 1
|
84
|
+
sage: print(n, nflush) # random
|
85
|
+
10000, 18
|
86
|
+
|
87
|
+
Sage example in ./combinat.tex, line 600::
|
88
|
+
|
89
|
+
sage: C, z = var('C, z'); sys = [ C == z + C*C ]
|
90
|
+
|
91
|
+
Sage example in ./combinat.tex, line 605::
|
92
|
+
|
93
|
+
sage: sol = solve(sys, C, solution_dict=True); sol
|
94
|
+
[{C: -1/2*sqrt(-4*z + 1) + 1/2}, {C: 1/2*sqrt(-4*z + 1) + 1/2}]
|
95
|
+
sage: s0 = sol[0][C]; s1 = sol[1][C]
|
96
|
+
|
97
|
+
Sage example in ./combinat.tex, line 612::
|
98
|
+
|
99
|
+
sage: s0.series(z, 6)
|
100
|
+
1*z + 1*z^2 + 2*z^3 + 5*z^4 + 14*z^5 + Order(z^6)
|
101
|
+
sage: s1.series(z, 6)
|
102
|
+
1 + (-1)*z + (-1)*z^2 + (-2)*z^3 + (-5)*z^4 + (-14)*z^5 + Order(z^6)
|
103
|
+
|
104
|
+
Sage example in ./combinat.tex, line 622::
|
105
|
+
|
106
|
+
sage: C = s0
|
107
|
+
|
108
|
+
Sage example in ./combinat.tex, line 627::
|
109
|
+
|
110
|
+
sage: C.series(z, 11)
|
111
|
+
1*z + 1*z^2 + 2*z^3 + 5*z^4 + 14*z^5 + 42*z^6 +
|
112
|
+
132*z^7 + 429*z^8 + 1430*z^9 + 4862*z^10 + Order(z^11)
|
113
|
+
|
114
|
+
Sage example in ./combinat.tex, line 634::
|
115
|
+
|
116
|
+
sage: C.series(z, 101).coefficient(z,100)
|
117
|
+
227508830794229349661819540395688853956041682601541047340
|
118
|
+
|
119
|
+
Sage example in ./combinat.tex, line 654::
|
120
|
+
|
121
|
+
sage: L.<z> = LazyPowerSeriesRing(QQ)
|
122
|
+
|
123
|
+
Sage example in ./combinat.tex, line 661::
|
124
|
+
|
125
|
+
sage: C = L.undefined(valuation=1)
|
126
|
+
sage: C.define( z + C * C )
|
127
|
+
|
128
|
+
Sage example in ./combinat.tex, line 666::
|
129
|
+
|
130
|
+
sage: [C.coefficient(i) for i in range(11)]
|
131
|
+
[0, 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862]
|
132
|
+
|
133
|
+
Sage example in ./combinat.tex, line 674::
|
134
|
+
|
135
|
+
sage: C.coefficient(100)
|
136
|
+
227508830794229349661819540395688853956041682601541047340
|
137
|
+
|
138
|
+
Sage example in ./combinat.tex, line 684::
|
139
|
+
|
140
|
+
sage: C.coefficient(200)
|
141
|
+
129013158064429114001222907669676675134349530552728882499810851598901419013348319045534580850847735528275750122188940
|
142
|
+
|
143
|
+
Sage example in ./combinat.tex, line 693::
|
144
|
+
|
145
|
+
sage: z = var('z'); C = s0; C
|
146
|
+
-1/2*sqrt(-4*z + 1) + 1/2
|
147
|
+
|
148
|
+
Sage example in ./combinat.tex, line 703::
|
149
|
+
|
150
|
+
sage: derivative(C, z, 1)
|
151
|
+
1/sqrt(-4*z + 1)
|
152
|
+
sage: derivative(C, z, 2)
|
153
|
+
2/(-4*z + 1)^(3/2)
|
154
|
+
sage: derivative(C, z, 3)
|
155
|
+
12/(-4*z + 1)^(5/2)
|
156
|
+
|
157
|
+
Sage example in ./combinat.tex, line 716::
|
158
|
+
|
159
|
+
sage: def d(n): return derivative(C, n).subs(z=0)
|
160
|
+
|
161
|
+
Sage example in ./combinat.tex, line 721::
|
162
|
+
|
163
|
+
sage: [ (d(n+1) / d(n)) for n in range(1,17) ]
|
164
|
+
[2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62]
|
165
|
+
|
166
|
+
Sage example in ./combinat.tex, line 737::
|
167
|
+
|
168
|
+
sage: def c(n): return 1/n*binomial(2*(n-1),n-1)
|
169
|
+
sage: [c(k) for k in range(1, 11)]
|
170
|
+
[1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862]
|
171
|
+
sage: [catalan_number(k-1) for k in range(1, 11)]
|
172
|
+
[1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862]
|
173
|
+
|
174
|
+
Sage example in ./combinat.tex, line 814::
|
175
|
+
|
176
|
+
sage: x, y, z = var('x, y, z')
|
177
|
+
sage: P = function('P')(x, y); C = function('C')(z)
|
178
|
+
sage: equation = P(x=z, y=C) == 0
|
179
|
+
sage: diff(equation, z)
|
180
|
+
diff(C(z), z)*D[1](P)(z, C(z)) + D[0](P)(z, C(z)) == 0
|
181
|
+
|
182
|
+
Sage example in ./combinat.tex, line 834::
|
183
|
+
|
184
|
+
sage: P = y^2 - y + x; Px = diff(P, x); Py = diff(P, y)
|
185
|
+
sage: - Px / Py
|
186
|
+
-1/(2*y - 1)
|
187
|
+
|
188
|
+
Sage example in ./combinat.tex, line 847::
|
189
|
+
|
190
|
+
sage: Qx = QQ['x'].fraction_field(); Qxy = Qx['y']
|
191
|
+
sage: R = Qxy.quo(P); R
|
192
|
+
Univariate Quotient Polynomial Ring in ybar
|
193
|
+
over Fraction Field of Univariate Polynomial Ring in x
|
194
|
+
over Rational Field with modulus y^2 - y + x
|
195
|
+
|
196
|
+
Sage example in ./combinat.tex, line 863::
|
197
|
+
|
198
|
+
sage: fraction = R( - Px / Py ); fraction
|
199
|
+
Traceback (most recent call last):
|
200
|
+
...
|
201
|
+
TypeError: unable to convert -1/(2*y - 1) to an element of Univariate Quotient Polynomial Ring in ybar over Fraction Field of Univariate Polynomial Ring in x over Rational Field with modulus y^2 - y + x
|
202
|
+
|
203
|
+
Sage example in ./combinat.tex, line 869::
|
204
|
+
|
205
|
+
sage: fraction = - R(Px) / R(Py); fraction
|
206
|
+
(1/2/(x - 1/4))*ybar - 1/4/(x - 1/4)
|
207
|
+
|
208
|
+
Sage example in ./combinat.tex, line 877::
|
209
|
+
|
210
|
+
sage: fraction = fraction.lift(); fraction
|
211
|
+
(1/2/(x - 1/4))*y - 1/4/(x - 1/4)
|
212
|
+
sage: fraction(x=z, y=C)
|
213
|
+
2*C(z)/(4*z - 1) - 1/(4*z - 1)
|
214
|
+
|
215
|
+
Sage example in ./combinat.tex, line 894::
|
216
|
+
|
217
|
+
sage: equadiff = diff(C,z) == fraction(x=z, y=C); equadiff
|
218
|
+
diff(C(z), z) == 2*C(z)/(4*z - 1) - 1/(4*z - 1)
|
219
|
+
sage: equadiff = equadiff.simplify_rational()
|
220
|
+
sage: equadiff = equadiff * equadiff.rhs().denominator()
|
221
|
+
sage: equadiff = equadiff - equadiff.rhs()
|
222
|
+
sage: equadiff
|
223
|
+
(4*z - 1)*diff(C(z), z) - 2*C(z) + 1 == 0
|
224
|
+
|
225
|
+
Sage example in ./combinat.tex, line 913::
|
226
|
+
|
227
|
+
sage: Cf = sage.symbolic.function_factory.function('C')
|
228
|
+
sage: equadiff.substitute_function(Cf, lambda z: s0(z=z))
|
229
|
+
(4*z - 1)/sqrt(-4*z + 1) + sqrt(-4*z + 1) == 0
|
230
|
+
|
231
|
+
Sage example in ./combinat.tex, line 923::
|
232
|
+
|
233
|
+
sage: Cf = sage.symbolic.function_factory.function('C')
|
234
|
+
sage: bool(equadiff.substitute_function(Cf, lambda z: s0(z=z)))
|
235
|
+
True
|
236
|
+
|
237
|
+
Sage example in ./combinat.tex, line 959::
|
238
|
+
|
239
|
+
sage: def C(n): return n if n <= 1 else (4*n-6)/n * C(n-1)
|
240
|
+
sage: [ C(i) for i in range(10) ]
|
241
|
+
[0, 1, 1, 2, 5, 14, 42, 132, 429, 1430]
|
242
|
+
|
243
|
+
Sage example in ./combinat.tex, line 1078::
|
244
|
+
|
245
|
+
sage: binomial(4, 2)
|
246
|
+
6
|
247
|
+
|
248
|
+
Sage example in ./combinat.tex, line 1088::
|
249
|
+
|
250
|
+
sage: S = Subsets([1,2,3,4], 2); S.cardinality()
|
251
|
+
6
|
252
|
+
|
253
|
+
Sage example in ./combinat.tex, line 1097::
|
254
|
+
|
255
|
+
sage: S.list()
|
256
|
+
[{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}]
|
257
|
+
sage: S.random_element() # random
|
258
|
+
{1, 4}
|
259
|
+
sage: S.an_element()
|
260
|
+
{2, 3}
|
261
|
+
|
262
|
+
Sage example in ./combinat.tex, line 1118::
|
263
|
+
|
264
|
+
sage: S.unrank(4)
|
265
|
+
{2, 4}
|
266
|
+
sage: S[4]
|
267
|
+
{2, 4}
|
268
|
+
|
269
|
+
Sage example in ./combinat.tex, line 1133::
|
270
|
+
|
271
|
+
sage: s = S([2,4]); S.rank(s)
|
272
|
+
4
|
273
|
+
|
274
|
+
Sage example in ./combinat.tex, line 1145::
|
275
|
+
|
276
|
+
sage: E = Set([1,2,3,4])
|
277
|
+
sage: S = Subsets(Subsets(Subsets(E))); S.cardinality()
|
278
|
+
2003529930406846464979072351560255750447825475569751419265016...736
|
279
|
+
|
280
|
+
Sage example in ./combinat.tex, line 1167::
|
281
|
+
|
282
|
+
sage: S.cardinality().ndigits()
|
283
|
+
19729
|
284
|
+
|
285
|
+
Sage example in ./combinat.tex, line 1179::
|
286
|
+
|
287
|
+
sage: sorted(sorted(sorted(x) for x in y) for y in S.unrank(237102123) )
|
288
|
+
[[[], [1, 2, 4], [1, 3], [1, 3, 4], [1, 4], [2], [2, 3], [2, 4], [4]],
|
289
|
+
[[], [1, 2, 4], [1, 3], [2, 4], [3, 4]]]
|
290
|
+
|
291
|
+
Sage example in ./combinat.tex, line 1237::
|
292
|
+
|
293
|
+
sage: P5 = Partitions(5); P5
|
294
|
+
Partitions of the integer 5
|
295
|
+
|
296
|
+
Sage example in ./combinat.tex, line 1243::
|
297
|
+
|
298
|
+
sage: P5.cardinality()
|
299
|
+
7
|
300
|
+
|
301
|
+
Sage example in ./combinat.tex, line 1251::
|
302
|
+
|
303
|
+
sage: P5.list()
|
304
|
+
[[5], [4, 1], [3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1],
|
305
|
+
[1, 1, 1, 1, 1]]
|
306
|
+
|
307
|
+
Sage example in ./combinat.tex, line 1279::
|
308
|
+
|
309
|
+
sage: Partitions(100000).cardinality()
|
310
|
+
27493510569775696512677516320986352688173429315980054758203125984302147328114964173055050741660736621590157844774296248940493063070200461792764493033510116079342457190155718943509725312466108452006369558934464248716828789832182345009262853831404597021307130674510624419227311238999702284408609370935531629697851569569892196108480158600569421098519
|
311
|
+
|
312
|
+
Sage example in ./combinat.tex, line 1291::
|
313
|
+
|
314
|
+
sage: P7 = Partitions(7); p = P7.unrank(5); p
|
315
|
+
[4, 2, 1]
|
316
|
+
|
317
|
+
Sage example in ./combinat.tex, line 1295::
|
318
|
+
|
319
|
+
sage: type(p)
|
320
|
+
<class 'sage.combinat.partition.Partitions_n_with_category.element_class'>
|
321
|
+
|
322
|
+
Sage example in ./combinat.tex, line 1302::
|
323
|
+
|
324
|
+
sage: print(p.ferrers_diagram())
|
325
|
+
****
|
326
|
+
**
|
327
|
+
*
|
328
|
+
|
329
|
+
Sage example in ./combinat.tex, line 1315::
|
330
|
+
|
331
|
+
sage: Partition([4,2,1])
|
332
|
+
[4, 2, 1]
|
333
|
+
sage: P7([4,2,1])
|
334
|
+
[4, 2, 1]
|
335
|
+
|
336
|
+
Sage example in ./combinat.tex, line 1330::
|
337
|
+
|
338
|
+
sage: WeightedIntegerVectors(8, [2,3,5]).list()
|
339
|
+
[[0, 1, 1], [1, 2, 0], [4, 0, 0]]
|
340
|
+
|
341
|
+
Sage example in ./combinat.tex, line 1343::
|
342
|
+
|
343
|
+
sage: C5 = Compositions(5); C5
|
344
|
+
Compositions of 5
|
345
|
+
sage: C5.cardinality()
|
346
|
+
16
|
347
|
+
sage: C5.list()
|
348
|
+
[[1, 1, 1, 1, 1], [1, 1, 1, 2], [1, 1, 2, 1], [1, 1, 3],
|
349
|
+
[1, 2, 1, 1], [1, 2, 2], [1, 3, 1], [1, 4], [2, 1, 1, 1],
|
350
|
+
[2, 1, 2], [2, 2, 1], [2, 3], [3, 1, 1], [3, 2], [4, 1], [5]]
|
351
|
+
|
352
|
+
Sage example in ./combinat.tex, line 1360::
|
353
|
+
|
354
|
+
sage: [ Compositions(n).cardinality() for n in range(10) ]
|
355
|
+
[1, 1, 2, 4, 8, 16, 32, 64, 128, 256]
|
356
|
+
|
357
|
+
Sage example in ./combinat.tex, line 1368::
|
358
|
+
|
359
|
+
sage: x = var('x'); sum( x^len(c) for c in C5 )
|
360
|
+
x^5 + 4*x^4 + 6*x^3 + 4*x^2 + x
|
361
|
+
|
362
|
+
Sage example in ./combinat.tex, line 1414::
|
363
|
+
|
364
|
+
sage: C = IntegerRange(3, 21, 2); C
|
365
|
+
{3, 5, ..., 19}
|
366
|
+
sage: C.cardinality()
|
367
|
+
9
|
368
|
+
sage: C.list()
|
369
|
+
[3, 5, 7, 9, 11, 13, 15, 17, 19]
|
370
|
+
|
371
|
+
Sage example in ./combinat.tex, line 1424::
|
372
|
+
|
373
|
+
sage: C = Permutations(4); C
|
374
|
+
Standard permutations of 4
|
375
|
+
sage: C.cardinality()
|
376
|
+
24
|
377
|
+
sage: C.list()
|
378
|
+
[[1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2],
|
379
|
+
[1, 4, 2, 3], [1, 4, 3, 2], [2, 1, 3, 4], [2, 1, 4, 3],
|
380
|
+
[2, 3, 1, 4], [2, 3, 4, 1], [2, 4, 1, 3], [2, 4, 3, 1],
|
381
|
+
[3, 1, 2, 4], [3, 1, 4, 2], [3, 2, 1, 4], [3, 2, 4, 1],
|
382
|
+
[3, 4, 1, 2], [3, 4, 2, 1], [4, 1, 2, 3], [4, 1, 3, 2],
|
383
|
+
[4, 2, 1, 3], [4, 2, 3, 1], [4, 3, 1, 2], [4, 3, 2, 1]]
|
384
|
+
|
385
|
+
Sage example in ./combinat.tex, line 1455::
|
386
|
+
|
387
|
+
sage: C = SetPartitions([1,2,3]); C
|
388
|
+
Set partitions of {1, 2, 3}
|
389
|
+
sage: C.cardinality()
|
390
|
+
5
|
391
|
+
sage: C.list() # random
|
392
|
+
[{{1, 2, 3}}, {{1}, {2, 3}}, {{1, 3}, {2}}, {{1, 2}, {3}}, {{1}, {2}, {3}}]
|
393
|
+
|
394
|
+
Sage example in ./combinat.tex, line 1466::
|
395
|
+
|
396
|
+
sage: C = Posets(8); C
|
397
|
+
Posets containing 8 elements
|
398
|
+
sage: C.cardinality()
|
399
|
+
16999
|
400
|
+
|
401
|
+
Sage example in ./combinat.tex, line 1475::
|
402
|
+
|
403
|
+
sage: show(C.unrank(20))
|
404
|
+
Finite poset containing 8 elements
|
405
|
+
|
406
|
+
Sage example in ./combinat.tex, line 1496::
|
407
|
+
|
408
|
+
sage: len(list(graphs(5)))
|
409
|
+
34
|
410
|
+
|
411
|
+
Sage example in ./combinat.tex, line 1504::
|
412
|
+
|
413
|
+
sage: for g in graphs(5, lambda G: G.size() <= 4):
|
414
|
+
....: show(g)
|
415
|
+
|
416
|
+
Sage example in ./combinat.tex, line 1528::
|
417
|
+
|
418
|
+
sage: G = DihedralGroup(4); G
|
419
|
+
Dihedral group of order 8 as a permutation group
|
420
|
+
sage: G.cardinality()
|
421
|
+
8
|
422
|
+
sage: sorted(G.list(), key=str)
|
423
|
+
[(), (1,2)(3,4), (1,2,3,4), (1,3), (1,3)(2,4), (1,4)(2,3), (1,4,3,2), (2,4)]
|
424
|
+
|
425
|
+
Sage example in ./combinat.tex, line 1542::
|
426
|
+
|
427
|
+
sage: import sage.repl.display.util
|
428
|
+
sage: sage.repl.display.util.TallListFormatter.MAX_COLUMN = 67
|
429
|
+
|
430
|
+
Sage example in ./combinat.tex, line 1547::
|
431
|
+
|
432
|
+
sage: C = MatrixSpace(GF(2), 2); C.list()
|
433
|
+
[
|
434
|
+
[0 0] [1 0] [0 1] [0 0] [0 0] [1 1] [1 0] [1 0] [0 1]
|
435
|
+
[0 0], [0 0], [0 0], [1 0], [0 1], [0 0], [1 0], [0 1], [1 0],
|
436
|
+
<BLANKLINE>
|
437
|
+
[0 1] [0 0] [1 1] [1 1] [1 0] [0 1] [1 1]
|
438
|
+
[0 1], [1 1], [1 0], [0 1], [1 1], [1 1], [1 1]
|
439
|
+
]
|
440
|
+
|
441
|
+
Sage example in ./combinat.tex, line 1557::
|
442
|
+
|
443
|
+
sage: C.cardinality()
|
444
|
+
16
|
445
|
+
|
446
|
+
Sage example in ./combinat.tex, line 1634::
|
447
|
+
|
448
|
+
sage: [ i^2 for i in [1, 3, 7] ]
|
449
|
+
[1, 9, 49]
|
450
|
+
|
451
|
+
Sage example in ./combinat.tex, line 1640::
|
452
|
+
|
453
|
+
sage: [ i^2 for i in range(1,10) ]
|
454
|
+
[1, 4, 9, 16, 25, 36, 49, 64, 81]
|
455
|
+
|
456
|
+
Sage example in ./combinat.tex, line 1651::
|
457
|
+
|
458
|
+
sage: [ i^2 for i in range(1,10) if is_prime(i) ]
|
459
|
+
[4, 9, 25, 49]
|
460
|
+
|
461
|
+
Sage example in ./combinat.tex, line 1661::
|
462
|
+
|
463
|
+
sage: [ (i,j) for i in range(1,6) for j in range(1,i) ]
|
464
|
+
[(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3),
|
465
|
+
(5, 1), (5, 2), (5, 3), (5, 4)]
|
466
|
+
|
467
|
+
Sage example in ./combinat.tex, line 1668::
|
468
|
+
|
469
|
+
sage: [[binomial(n, i) for i in range(n+1)] for n in range(10)]
|
470
|
+
[[1],
|
471
|
+
[1, 1],
|
472
|
+
[1, 2, 1],
|
473
|
+
[1, 3, 3, 1],
|
474
|
+
[1, 4, 6, 4, 1],
|
475
|
+
[1, 5, 10, 10, 5, 1],
|
476
|
+
[1, 6, 15, 20, 15, 6, 1],
|
477
|
+
[1, 7, 21, 35, 35, 21, 7, 1],
|
478
|
+
[1, 8, 28, 56, 70, 56, 28, 8, 1],
|
479
|
+
[1, 9, 36, 84, 126, 126, 84, 36, 9, 1]]
|
480
|
+
|
481
|
+
Sage example in ./combinat.tex, line 1718::
|
482
|
+
|
483
|
+
sage: it = (binomial(3, i) for i in range(4))
|
484
|
+
|
485
|
+
Sage example in ./combinat.tex, line 1724::
|
486
|
+
|
487
|
+
sage: next(it)
|
488
|
+
1
|
489
|
+
sage: next(it)
|
490
|
+
3
|
491
|
+
sage: next(it)
|
492
|
+
3
|
493
|
+
sage: next(it)
|
494
|
+
1
|
495
|
+
|
496
|
+
Sage example in ./combinat.tex, line 1736::
|
497
|
+
|
498
|
+
sage: next(it)
|
499
|
+
Traceback (most recent call last):
|
500
|
+
...
|
501
|
+
StopIteration
|
502
|
+
|
503
|
+
Sage example in ./combinat.tex, line 1754::
|
504
|
+
|
505
|
+
sage: for s in Subsets(3): s
|
506
|
+
{}
|
507
|
+
{1}
|
508
|
+
{2}
|
509
|
+
{3}
|
510
|
+
{1, 2}
|
511
|
+
{1, 3}
|
512
|
+
{2, 3}
|
513
|
+
{1, 2, 3}
|
514
|
+
|
515
|
+
Sage example in ./combinat.tex, line 1765::
|
516
|
+
|
517
|
+
sage: [ s.cardinality() for s in Subsets(3) ]
|
518
|
+
[0, 1, 1, 1, 2, 2, 2, 3]
|
519
|
+
|
520
|
+
Sage example in ./combinat.tex, line 1772::
|
521
|
+
|
522
|
+
sage: sum( [ binomial(8, i) for i in range(9) ] )
|
523
|
+
256
|
524
|
+
|
525
|
+
Sage example in ./combinat.tex, line 1784::
|
526
|
+
|
527
|
+
sage: sum( binomial(8, i) for i in range(9) )
|
528
|
+
256
|
529
|
+
|
530
|
+
Sage example in ./combinat.tex, line 1811::
|
531
|
+
|
532
|
+
sage: list(binomial(8, i) for i in range(9))
|
533
|
+
[1, 8, 28, 56, 70, 56, 28, 8, 1]
|
534
|
+
sage: tuple(binomial(8, i) for i in range(9))
|
535
|
+
(1, 8, 28, 56, 70, 56, 28, 8, 1)
|
536
|
+
|
537
|
+
Sage example in ./combinat.tex, line 1823::
|
538
|
+
|
539
|
+
sage: all([True, True, True, True])
|
540
|
+
True
|
541
|
+
sage: all([True, False, True, True])
|
542
|
+
False
|
543
|
+
sage: any([False, False, False, False])
|
544
|
+
False
|
545
|
+
sage: any([False, False, True, False])
|
546
|
+
True
|
547
|
+
|
548
|
+
Sage example in ./combinat.tex, line 1839::
|
549
|
+
|
550
|
+
sage: all( is_odd(p) for p in range(3,100) if is_prime(p) )
|
551
|
+
True
|
552
|
+
|
553
|
+
Sage example in ./combinat.tex, line 1852::
|
554
|
+
|
555
|
+
sage: def mersenne(p): return 2^p - 1
|
556
|
+
sage: [ is_prime(p) for p in range(1000) if is_prime(mersenne(p)) ]
|
557
|
+
[True, True, True, True, True, True, True, True, True, True,
|
558
|
+
True, True, True, True]
|
559
|
+
|
560
|
+
Sage example in ./combinat.tex, line 1867::
|
561
|
+
|
562
|
+
sage: all( [ is_prime(mersenne(p)) for p in range(1000) if is_prime(p)] )
|
563
|
+
False
|
564
|
+
sage: all( is_prime(mersenne(p)) for p in range(1000) if is_prime(p) )
|
565
|
+
False
|
566
|
+
|
567
|
+
Sage example in ./combinat.tex, line 1879::
|
568
|
+
|
569
|
+
sage: exists( (p for p in range(1000) if is_prime(p)),
|
570
|
+
....: lambda p: not is_prime(mersenne(p)) )
|
571
|
+
(True, 11)
|
572
|
+
|
573
|
+
Sage example in ./combinat.tex, line 1895::
|
574
|
+
|
575
|
+
sage: counter_examples = \
|
576
|
+
....: (p for p in range(1000)
|
577
|
+
....: if is_prime(p) and not is_prime(mersenne(p)))
|
578
|
+
sage: next(counter_examples)
|
579
|
+
11
|
580
|
+
sage: next(counter_examples)
|
581
|
+
23
|
582
|
+
|
583
|
+
Sage example in ./combinat.tex, line 1909::
|
584
|
+
|
585
|
+
sage: cubes = [t**3 for t in range(-999,1000)]
|
586
|
+
sage: exists([(x,y) for x in cubes for y in cubes], lambda xy: sum(xy) == 218) # long time
|
587
|
+
(True, (-125, 343))
|
588
|
+
sage: exists(((x,y) for x in cubes for y in cubes), lambda xy: sum(xy) == 218) # long time
|
589
|
+
(True, (-125, 343))
|
590
|
+
|
591
|
+
Sage example in ./combinat.tex, line 1927::
|
592
|
+
|
593
|
+
sage: x = var('x'); sum( x^len(s) for s in Subsets(8) )
|
594
|
+
x^8 + 8*x^7 + 28*x^6 + 56*x^5 + 70*x^4 + 56*x^3 + 28*x^2 + 8*x + 1
|
595
|
+
|
596
|
+
Sage example in ./combinat.tex, line 1931::
|
597
|
+
|
598
|
+
sage: sum( x^p.length() for p in Permutations(3) )
|
599
|
+
x^3 + 2*x^2 + 2*x + 1
|
600
|
+
|
601
|
+
Sage example in ./combinat.tex, line 1940::
|
602
|
+
|
603
|
+
sage: P = Permutations(5)
|
604
|
+
sage: all( p in P for p in P )
|
605
|
+
True
|
606
|
+
|
607
|
+
Sage example in ./combinat.tex, line 1945::
|
608
|
+
|
609
|
+
sage: for p in GL(2, 2): print(p); print("-----")
|
610
|
+
[1 0]
|
611
|
+
[0 1]
|
612
|
+
-----
|
613
|
+
[0 1]
|
614
|
+
[1 0]
|
615
|
+
-----
|
616
|
+
[0 1]
|
617
|
+
[1 1]
|
618
|
+
-----
|
619
|
+
[1 1]
|
620
|
+
[0 1]
|
621
|
+
-----
|
622
|
+
[1 1]
|
623
|
+
[1 0]
|
624
|
+
-----
|
625
|
+
[1 0]
|
626
|
+
[1 1]
|
627
|
+
-----
|
628
|
+
|
629
|
+
Sage example in ./combinat.tex, line 1966::
|
630
|
+
|
631
|
+
sage: for p in Partitions(3): print(p)
|
632
|
+
[3]
|
633
|
+
[2, 1]
|
634
|
+
[1, 1, 1]
|
635
|
+
|
636
|
+
Sage example in ./combinat.tex, line 1987::
|
637
|
+
|
638
|
+
sage: exists( Primes(), lambda p: not is_prime(mersenne(p)) )
|
639
|
+
(True, 11)
|
640
|
+
|
641
|
+
Sage example in ./combinat.tex, line 2026::
|
642
|
+
|
643
|
+
sage: import itertools
|
644
|
+
|
645
|
+
Sage example in ./combinat.tex, line 2033::
|
646
|
+
|
647
|
+
sage: list(Permutations(3))
|
648
|
+
[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
|
649
|
+
|
650
|
+
Sage example in ./combinat.tex, line 2039::
|
651
|
+
|
652
|
+
sage: list(enumerate(Permutations(3)))
|
653
|
+
[(0, [1, 2, 3]), (1, [1, 3, 2]), (2, [2, 1, 3]),
|
654
|
+
(3, [2, 3, 1]), (4, [3, 1, 2]), (5, [3, 2, 1])]
|
655
|
+
|
656
|
+
Sage example in ./combinat.tex, line 2048::
|
657
|
+
|
658
|
+
sage: list(itertools.islice(Permutations(3), 1r, 4r))
|
659
|
+
[[1, 3, 2], [2, 1, 3], [2, 3, 1]]
|
660
|
+
|
661
|
+
Sage example in ./combinat.tex, line 2054::
|
662
|
+
|
663
|
+
sage: list(map(lambda z: z.cycle_type(), Permutations(3)))
|
664
|
+
[[1, 1, 1], [2, 1], [2, 1], [3], [3], [2, 1]]
|
665
|
+
|
666
|
+
Sage example in ./combinat.tex, line 2060::
|
667
|
+
|
668
|
+
sage: list(filter(lambda z: z.has_pattern([1,2]),
|
669
|
+
....: Permutations(3)))
|
670
|
+
[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2]]
|
671
|
+
|
672
|
+
Sage example in ./combinat.tex, line 2069::
|
673
|
+
|
674
|
+
sage: list(map(attrcall("cycle_type"), Permutations(3)))
|
675
|
+
[[1, 1, 1], [2, 1], [2, 1], [3], [3], [2, 1]]
|
676
|
+
|
677
|
+
Sage example in ./combinat.tex, line 2084::
|
678
|
+
|
679
|
+
sage: def f(n):
|
680
|
+
....: for i in range(n):
|
681
|
+
....: yield i
|
682
|
+
|
683
|
+
Sage example in ./combinat.tex, line 2097::
|
684
|
+
|
685
|
+
sage: g = f(4)
|
686
|
+
sage: next(g)
|
687
|
+
0
|
688
|
+
sage: next(g)
|
689
|
+
1
|
690
|
+
sage: next(g)
|
691
|
+
2
|
692
|
+
sage: next(g)
|
693
|
+
3
|
694
|
+
|
695
|
+
Sage example in ./combinat.tex, line 2108::
|
696
|
+
|
697
|
+
sage: next(g)
|
698
|
+
Traceback (most recent call last):
|
699
|
+
...
|
700
|
+
StopIteration
|
701
|
+
|
702
|
+
Sage example in ./combinat.tex, line 2116::
|
703
|
+
|
704
|
+
sage: [ x for x in f(5) ]
|
705
|
+
[0, 1, 2, 3, 4]
|
706
|
+
|
707
|
+
Sage example in ./combinat.tex, line 2130::
|
708
|
+
|
709
|
+
sage: def words(alphabet, l):
|
710
|
+
....: if l == 0: yield []
|
711
|
+
....: else:
|
712
|
+
....: for word in words(alphabet, l-1):
|
713
|
+
....: for l in alphabet: yield word + [l]
|
714
|
+
sage: [ w for w in words(['a','b'], 3) ]
|
715
|
+
[['a', 'a', 'a'], ['a', 'a', 'b'], ['a', 'b', 'a'], ['a', 'b', 'b'],
|
716
|
+
['b', 'a', 'a'], ['b', 'a', 'b'], ['b', 'b', 'a'], ['b', 'b', 'b']]
|
717
|
+
|
718
|
+
Sage example in ./combinat.tex, line 2142::
|
719
|
+
|
720
|
+
sage: sum(1 for w in words(['a','b','c','d'], 10))
|
721
|
+
1048576
|
722
|
+
|
723
|
+
Sage example in ./combinat.tex, line 2169::
|
724
|
+
|
725
|
+
sage: def dyck_words(l):
|
726
|
+
....: if l == 0: yield ''
|
727
|
+
....: else:
|
728
|
+
....: for k in range(l):
|
729
|
+
....: for w1 in dyck_words(k):
|
730
|
+
....: for w2 in dyck_words(l-k-1):
|
731
|
+
....: yield '(' + w1 + ')' + w2
|
732
|
+
|
733
|
+
Sage example in ./combinat.tex, line 2180::
|
734
|
+
|
735
|
+
sage: list(dyck_words(4))
|
736
|
+
['()()()()', '()()(())', '()(())()', '()(()())', '()((()))',
|
737
|
+
'(())()()', '(())(())', '(()())()', '((()))()', '(()()())',
|
738
|
+
'(()(()))', '((())())', '((()()))', '(((())))']
|
739
|
+
|
740
|
+
Sage example in ./combinat.tex, line 2188::
|
741
|
+
|
742
|
+
sage: [ sum(1 for w in dyck_words(l)) for l in range(10) ]
|
743
|
+
[1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862]
|
744
|
+
|
745
|
+
Sage example in ./combinat.tex, line 2208::
|
746
|
+
|
747
|
+
sage: BT = BinaryTree
|
748
|
+
sage: BT()
|
749
|
+
.
|
750
|
+
sage: t = BT([BT([BT(), BT([BT(),BT()])]), BT()]); t
|
751
|
+
[[., [., .]], .]
|
752
|
+
|
753
|
+
Sage example in ./combinat.tex, line 2261::
|
754
|
+
|
755
|
+
sage: C = cartesian_product([Compositions(8), Permutations(20)]); C
|
756
|
+
The Cartesian product of (Compositions of 8, Standard permutations of 20)
|
757
|
+
sage: C.cardinality()
|
758
|
+
311411457046609920000
|
759
|
+
|
760
|
+
Sage example in ./combinat.tex, line 2274::
|
761
|
+
|
762
|
+
sage: C.random_element() # random
|
763
|
+
([2, 3, 2, 1], [10, 6, 11, 13, 14, 3, 4, 19, 5, 12, 7, 18, 15, 8, 20, 1, 17, 2, 9, 16])
|
764
|
+
|
765
|
+
Sage example in ./combinat.tex, line 2288::
|
766
|
+
|
767
|
+
sage: G = DihedralGroup(4)
|
768
|
+
sage: H = cartesian_product([G,G])
|
769
|
+
sage: H.cardinality()
|
770
|
+
64
|
771
|
+
sage: H in Sets().Enumerated().Finite()
|
772
|
+
True
|
773
|
+
sage: H in Groups()
|
774
|
+
True
|
775
|
+
|
776
|
+
Sage example in ./combinat.tex, line 2305::
|
777
|
+
|
778
|
+
sage: C = DisjointUnionEnumeratedSets([Compositions(4),Permutations(3)])
|
779
|
+
sage: C
|
780
|
+
Disjoint union of Family (Compositions of 4, Standard permutations of 3)
|
781
|
+
sage: C.cardinality()
|
782
|
+
14
|
783
|
+
sage: C.list()
|
784
|
+
[[1, 1, 1, 1], [1, 1, 2], [1, 2, 1], [1, 3], [2, 1, 1], [2, 2], [3, 1],
|
785
|
+
[4], [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
|
786
|
+
|
787
|
+
Sage example in ./combinat.tex, line 2328::
|
788
|
+
|
789
|
+
sage: F = Family(NonNegativeIntegers(), Permutations); F
|
790
|
+
Lazy family (<class 'sage.combinat.permutation.Permutations'>(i))_{i in Non negative integers}
|
791
|
+
sage: F.keys()
|
792
|
+
Non negative integers
|
793
|
+
sage: F[1000]
|
794
|
+
Standard permutations of 1000
|
795
|
+
|
796
|
+
Sage example in ./combinat.tex, line 2339::
|
797
|
+
|
798
|
+
sage: U = DisjointUnionEnumeratedSets(F); U
|
799
|
+
Disjoint union of
|
800
|
+
Lazy family (<class 'sage.combinat.permutation.Permutations'>(i))_{i in Non negative integers}
|
801
|
+
|
802
|
+
Sage example in ./combinat.tex, line 2346::
|
803
|
+
|
804
|
+
sage: U.cardinality()
|
805
|
+
+Infinity
|
806
|
+
|
807
|
+
Sage example in ./combinat.tex, line 2372::
|
808
|
+
|
809
|
+
sage: U = Permutations(); U
|
810
|
+
Standard permutations
|
811
|
+
|
812
|
+
Sage example in ./combinat.tex, line 2450::
|
813
|
+
|
814
|
+
sage: IntegerVectors(10, 3, min_part = 2, max_part = 5,
|
815
|
+
....: inner = [2, 4, 2]).list()
|
816
|
+
[[4, 4, 2], [3, 5, 2], [3, 4, 3], [2, 5, 3], [2, 4, 4]]
|
817
|
+
|
818
|
+
Sage example in ./combinat.tex, line 2459::
|
819
|
+
|
820
|
+
sage: Compositions(5, max_part = 3,
|
821
|
+
....: min_length = 2, max_length = 3).list()
|
822
|
+
[[3, 2], [3, 1, 1], [2, 3], [2, 2, 1], [2, 1, 2], [1, 3, 1],
|
823
|
+
[1, 2, 2], [1, 1, 3]]
|
824
|
+
|
825
|
+
Sage example in ./combinat.tex, line 2467::
|
826
|
+
|
827
|
+
sage: Partitions(5, max_slope = -1).list()
|
828
|
+
[[5], [4, 1], [3, 2]]
|
829
|
+
|
830
|
+
Sage example in ./combinat.tex, line 2484::
|
831
|
+
|
832
|
+
sage: IntegerListsLex(10, length=3, min_part = 2, max_part = 5,
|
833
|
+
....: floor = [2, 4, 2]).list()
|
834
|
+
[[4, 4, 2], [3, 5, 2], [3, 4, 3], [2, 5, 3], [2, 4, 4]]
|
835
|
+
|
836
|
+
Sage example in ./combinat.tex, line 2489::
|
837
|
+
|
838
|
+
sage: IntegerListsLex(5, min_part = 1, max_part = 3,
|
839
|
+
....: min_length = 2, max_length = 3).list()
|
840
|
+
[[3, 2], [3, 1, 1], [2, 3], [2, 2, 1], [2, 1, 2], [1, 3, 1],
|
841
|
+
[1, 2, 2], [1, 1, 3]]
|
842
|
+
|
843
|
+
Sage example in ./combinat.tex, line 2495::
|
844
|
+
|
845
|
+
sage: IntegerListsLex(5, min_part = 1, max_slope = -1).list()
|
846
|
+
[[5], [4, 1], [3, 2]]
|
847
|
+
|
848
|
+
Sage example in ./combinat.tex, line 2499::
|
849
|
+
|
850
|
+
sage: list(Compositions(5, max_length=2))
|
851
|
+
[[5], [4, 1], [3, 2], [2, 3], [1, 4]]
|
852
|
+
|
853
|
+
Sage example in ./combinat.tex, line 2503::
|
854
|
+
|
855
|
+
sage: list(IntegerListsLex(5, max_length=2, min_part=1))
|
856
|
+
[[5], [4, 1], [3, 2], [2, 3], [1, 4]]
|
857
|
+
|
858
|
+
Sage example in ./combinat.tex, line 2625::
|
859
|
+
|
860
|
+
sage: A = random_matrix(ZZ, 6, 3, x=7)
|
861
|
+
sage: L = LatticePolytope(A.rows())
|
862
|
+
sage: L.points() # random
|
863
|
+
M(1, 4, 3),
|
864
|
+
M(6, 4, 1),
|
865
|
+
...
|
866
|
+
M(3, 5, 5)
|
867
|
+
in 3-d lattice M
|
868
|
+
sage: L.points().cardinality() # random
|
869
|
+
23
|
870
|
+
|
871
|
+
Sage example in ./combinat.tex, line 2637::
|
872
|
+
|
873
|
+
sage: L.points()
|
874
|
+
M(...),
|
875
|
+
M(...),
|
876
|
+
...
|
877
|
+
M(...)
|
878
|
+
in 3-d lattice M
|
879
|
+
|
880
|
+
Sage example in ./combinat.tex, line 2647::
|
881
|
+
|
882
|
+
sage: L.plot3d()
|
883
|
+
Graphics3d Object
|
884
|
+
|
885
|
+
Sage example in ./combinat.tex, line 2688::
|
886
|
+
|
887
|
+
sage: from sage.combinat.species.library import *
|
888
|
+
sage: o = var('o')
|
889
|
+
|
890
|
+
Sage example in ./combinat.tex, line 2697::
|
891
|
+
|
892
|
+
sage: BT = CombinatorialSpecies(min=1)
|
893
|
+
sage: Leaf = SingletonSpecies()
|
894
|
+
sage: BT.define( Leaf + (BT*BT) )
|
895
|
+
|
896
|
+
Sage example in ./combinat.tex, line 2707::
|
897
|
+
|
898
|
+
sage: BT5 = BT.isotypes([o]*5); BT5.cardinality()
|
899
|
+
14
|
900
|
+
sage: BT5.list()
|
901
|
+
[o*(o*(o*(o*o))), o*(o*((o*o)*o)), o*((o*o)*(o*o)), o*((o*(o*o))*o),
|
902
|
+
o*(((o*o)*o)*o), (o*o)*(o*(o*o)), (o*o)*((o*o)*o), (o*(o*o))*(o*o),
|
903
|
+
((o*o)*o)*(o*o), (o*(o*(o*o)))*o, (o*((o*o)*o))*o, ((o*o)*(o*o))*o,
|
904
|
+
((o*(o*o))*o)*o, (((o*o)*o)*o)*o]
|
905
|
+
|
906
|
+
Sage example in ./combinat.tex, line 2727::
|
907
|
+
|
908
|
+
sage: g = BT.isotype_generating_series(); g
|
909
|
+
z + z^2 + 2*z^3 + 5*z^4 + 14*z^5 + 42*z^6 + 132*z^7 + O(z^8)
|
910
|
+
|
911
|
+
Sage example in ./combinat.tex, line 2733::
|
912
|
+
|
913
|
+
sage: g[100]
|
914
|
+
227508830794229349661819540395688853956041682601541047340
|
915
|
+
|
916
|
+
Sage example in ./combinat.tex, line 2743::
|
917
|
+
|
918
|
+
sage: Eps = EmptySetSpecies(); Z0 = SingletonSpecies()
|
919
|
+
sage: Z1 = Eps*SingletonSpecies()
|
920
|
+
sage: FW = CombinatorialSpecies()
|
921
|
+
sage: FW.define(Eps + Z0*FW + Z1*Eps + Z1*Z0*FW)
|
922
|
+
|
923
|
+
Sage example in ./combinat.tex, line 2752::
|
924
|
+
|
925
|
+
sage: L = FW.isotype_generating_series()[:15]; L
|
926
|
+
[1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]
|
927
|
+
|
928
|
+
Sage example in ./combinat.tex, line 2769::
|
929
|
+
|
930
|
+
sage: FW3 = FW.isotypes([o]*3)
|
931
|
+
sage: FW3.list()
|
932
|
+
[o*(o*(o*{})), o*(o*(({}*o)*{})), o*((({}*o)*o)*{}),
|
933
|
+
(({}*o)*o)*(o*{}), (({}*o)*o)*(({}*o)*{})]
|
934
|
+
|
935
|
+
Sage example in ./combinat.tex, line 3007::
|
936
|
+
|
937
|
+
sage: [len(list(graphs(n, property = lambda G: G.is_planar())))
|
938
|
+
....: for n in range(7)]
|
939
|
+
[1, 1, 2, 4, 11, 33, 142]
|
940
|
+
|
941
|
+
Sage example in ./combinat.tex, line 3066::
|
942
|
+
|
943
|
+
sage: V = [1,2,3,4]
|
944
|
+
sage: F = Subsets(V, 2); F.list()
|
945
|
+
[{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}]
|
946
|
+
|
947
|
+
Sage example in ./combinat.tex, line 3072::
|
948
|
+
|
949
|
+
sage: S = SymmetricGroup(V)
|
950
|
+
|
951
|
+
Sage example in ./combinat.tex, line 3077::
|
952
|
+
|
953
|
+
sage: def on_pair(sigma, pair):
|
954
|
+
....: return Set(sigma(i) for i in pair)
|
955
|
+
sage: def on_pairs(sigma):
|
956
|
+
....: return [on_pair(sigma, e) for e in F]
|
957
|
+
|
958
|
+
Sage example in ./combinat.tex, line 3086::
|
959
|
+
|
960
|
+
sage: sigma = S([(1,2,3,4)]); sigma
|
961
|
+
(1,2,3,4)
|
962
|
+
sage: for e in F: print((e, on_pair(sigma, e)))
|
963
|
+
({1, 2}, {2, 3})
|
964
|
+
({1, 3}, {2, 4})
|
965
|
+
({1, 4}, {1, 2})
|
966
|
+
({2, 3}, {3, 4})
|
967
|
+
({2, 4}, {1, 3})
|
968
|
+
({3, 4}, {1, 4})
|
969
|
+
sage: on_pairs(sigma)
|
970
|
+
[{2, 3}, {2, 4}, {1, 2}, {3, 4}, {1, 3}, {1, 4}]
|
971
|
+
|
972
|
+
Sage example in ./combinat.tex, line 3102::
|
973
|
+
|
974
|
+
sage: G = PermutationGroup([ on_pairs(sigma) for sigma in S.gens() ],
|
975
|
+
....: domain=F)
|
976
|
+
|
977
|
+
Sage example in ./combinat.tex, line 3109::
|
978
|
+
|
979
|
+
sage: Z = G.cycle_index(); Z
|
980
|
+
1/24*p[1, 1, 1, 1, 1, 1] + 3/8*p[2, 2, 1, 1] + 1/3*p[3, 3] + 1/4*p[4, 2]
|
981
|
+
|
982
|
+
Sage example in ./combinat.tex, line 3117::
|
983
|
+
|
984
|
+
sage: sorted(sigma for sigma in G if sigma.cycle_type() == [4,2])
|
985
|
+
[({1,2},{1,3},{3,4},{2,4})({1,4},{2,3}),
|
986
|
+
({1,2},{1,4},{3,4},{2,3})({1,3},{2,4}),
|
987
|
+
({1,2},{2,3},{3,4},{1,4})({1,3},{2,4}),
|
988
|
+
({1,2},{2,4},{3,4},{1,3})({1,4},{2,3}),
|
989
|
+
({1,2},{3,4})({1,3},{1,4},{2,4},{2,3}),
|
990
|
+
({1,2},{3,4})({1,3},{2,3},{2,4},{1,4})]
|
991
|
+
|
992
|
+
Sage example in ./combinat.tex, line 3136::
|
993
|
+
|
994
|
+
sage: q,t = QQ['q,t'].gens()
|
995
|
+
sage: p = Z.expand(2, [q,t]); p
|
996
|
+
q^6 + q^5*t + 2*q^4*t^2 + 3*q^3*t^3 + 2*q^2*t^4 + q*t^5 + t^6
|
997
|
+
|
998
|
+
Sage example in ./combinat.tex, line 3146::
|
999
|
+
|
1000
|
+
sage: p(q=1,t=1)
|
1001
|
+
11
|
1002
|
+
|
1003
|
+
Sage example in ./combinat.tex, line 3159::
|
1004
|
+
|
1005
|
+
sage: q = var('q')
|
1006
|
+
sage: H = sum( c * prod( 1/(1-q^k) for k in partition )
|
1007
|
+
....: for partition, c in Z )
|
1008
|
+
sage: H
|
1009
|
+
1/3/(q^3 - 1)^2 + 1/4/((q^4 - 1)*(q^2 - 1))
|
1010
|
+
+ 3/8/((q^2 - 1)^2*(q - 1)^2) + 1/24/(q - 1)^6
|
1011
|
+
|
1012
|
+
Sage example in ./combinat.tex, line 3171::
|
1013
|
+
|
1014
|
+
sage: H.series(q)
|
1015
|
+
1 + 1*q + 3*q^2 + 6*q^3 + 11*q^4 + 18*q^5 + 32*q^6 + 48*q^7
|
1016
|
+
+ 75*q^8 + 111*q^9 + 160*q^10 + 224*q^11 + 313*q^12 + 420*q^13
|
1017
|
+
+ 562*q^14 + 738*q^15 + 956*q^16 + 1221*q^17 + 1550*q^18 + 1936*q^19
|
1018
|
+
+ Order(q^20)
|
1019
|
+
|
1020
|
+
Sage example in ./combinat.tex, line 3185::
|
1021
|
+
|
1022
|
+
sage: n = 10
|
1023
|
+
sage: V = range(1,n+1)
|
1024
|
+
sage: F = Subsets(V, 2)
|
1025
|
+
sage: S = SymmetricGroup(V)
|
1026
|
+
sage: G = PermutationGroup([ on_pairs(sigma) for sigma in S.gens() ],
|
1027
|
+
....: domain=F)
|
1028
|
+
sage: q,t = QQ['q,t'].gens()
|
1029
|
+
sage: Z = G.cycle_index()
|
1030
|
+
sage: Z.expand(2, [q,t])(q=1,t=1)
|
1031
|
+
12005168
|
1032
|
+
|
1033
|
+
Sage example in ./combinat.tex, line 3202::
|
1034
|
+
|
1035
|
+
sage: n = 20
|
1036
|
+
sage: V = range(1,n+1)
|
1037
|
+
sage: F = Subsets(V, 2)
|
1038
|
+
sage: S = SymmetricGroup(V)
|
1039
|
+
sage: CC = S.conjugacy_classes(); CC # long time
|
1040
|
+
[...
|
1041
|
+
Conjugacy class of cycle type [19, 1] in Symmetric group of order 20! as a permutation group,
|
1042
|
+
Conjugacy class of cycle type [20] in Symmetric group of order 20! as a permutation group]
|
1043
|
+
|
1044
|
+
Sage example in ./combinat.tex, line 3214::
|
1045
|
+
|
1046
|
+
sage: p = SymmetricFunctions(QQ).powersum()
|
1047
|
+
sage: G = PermutationGroup([ on_pairs(sigma) for sigma in S.gens() ],
|
1048
|
+
....: domain=F)
|
1049
|
+
sage: Z = p.sum_of_terms([G(on_pairs(c.representative())).cycle_type(), # long time
|
1050
|
+
....: c.cardinality()]
|
1051
|
+
....: for c in CC) / factorial(n)
|
1052
|
+
sage: Z.expand(2, [q,t])(q=1,t=1) # long time
|
1053
|
+
645490122795799841856164638490742749440
|
1054
|
+
"""
|