@@ -15,15 +15,15 @@ Documentation/Resources
15
15
16
16
::
17
17
18
- sage: sage.combinat.
18
+ sage: sage.combinat. # not tested
19
19
20
20
::
21
21
22
- sage: sage.combinat.sf.
22
+ sage: sage.combinat.sf. # not tested
23
23
24
24
::
25
25
26
- sage: sage.combinat.words.
26
+ sage: sage.combinat.words. # not tested
27
27
28
28
- There is a chapter on *Combinatorics * in the *Reference Manual *.
29
29
@@ -44,33 +44,17 @@ The Python command ``iter`` returns an iterator from an object (the object its
44
44
45
45
sage: it = iter([1,2,3])
46
46
sage: it
47
- <listiterator object at 0x35a3950>
48
-
49
- .. end of output
50
-
51
- ::
47
+ <list_iterator object at ...>
52
48
53
49
sage: next(it)
54
50
1
55
51
56
- .. end of output
57
-
58
- ::
59
-
60
52
sage: next(it)
61
53
2
62
54
63
- .. end of output
64
-
65
- ::
66
-
67
55
sage: next(it)
68
56
3
69
57
70
- .. end of output
71
-
72
- ::
73
-
74
58
sage: next(it)
75
59
Traceback (most recent call last):
76
60
...
@@ -89,61 +73,29 @@ A *generator* is a function that is used to define an iterator. Instead of ``
89
73
....: yield b
90
74
....: a, b = b, a+b
91
75
92
-
93
- .. end of output
94
-
95
- ::
96
-
97
76
sage: f = fibonacci_iterator()
98
77
99
-
100
- .. end of output
101
-
102
- ::
103
-
104
78
sage: next(f)
105
79
1
106
80
107
- .. end of output
108
-
109
- ::
110
-
111
81
sage: next(f)
112
82
1
113
83
114
- .. end of output
115
-
116
- ::
117
-
118
84
sage: next(f)
119
85
2
120
86
121
- .. end of output
122
-
123
- ::
124
-
125
87
sage: next(f)
126
88
3
127
89
128
- .. end of output
129
-
130
- ::
131
-
132
90
sage: next(f)
133
91
5
134
92
135
- .. end of output
136
-
137
- ::
138
-
139
93
sage: next(f)
140
94
8
141
95
142
- .. end of output
143
-
144
96
145
97
`Project Euler Problem 2 <http://projecteuler.net/index.php?section=problems&id=2 >`_
146
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147
99
148
100
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
149
101
@@ -158,22 +110,12 @@ Find the sum of all the even\-valued terms in the sequence which do not exceed f
158
110
159
111
sage: result = 0
160
112
161
-
162
- .. end of output
163
-
164
- ::
165
-
166
113
sage: for f in fibonacci_iterator():
167
114
....: if f > 4000000:
168
115
....: break
169
116
....: if is_even(f):
170
117
....: result += f
171
118
172
-
173
- .. end of output
174
-
175
- ::
176
-
177
119
sage: result
178
120
4613732
179
121
@@ -193,17 +135,9 @@ There are many objects in Sage that model sets of combinatorial objects.
193
135
sage: P
194
136
Standard permutations of 3
195
137
196
- .. end of output
197
-
198
- ::
199
-
200
138
sage: P.cardinality()
201
139
6
202
140
203
- .. end of output
204
-
205
- ::
206
-
207
141
sage: P.list()
208
142
[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
209
143
@@ -216,21 +150,13 @@ There are many objects in Sage that model sets of combinatorial objects.
216
150
217
151
.. end of output
218
152
219
-
220
153
::
221
154
222
- sage: time P = Permutations(7, avoiding=[2,1,4,3])
223
- sage: P
224
- Time: CPU 0.00 s, Wall: 0.00 s
155
+ sage: P = Permutations(7, avoiding=[2,1,4,3]); P
225
156
Standard permutations of 7 avoiding [[2, 1, 4, 3]]
226
157
227
- .. end of output
228
-
229
- ::
230
-
231
- sage: time P.cardinality()
158
+ sage: P.cardinality()
232
159
2761
233
- Time: CPU 4.10 s, Wall: 4.20 s
234
160
235
161
.. end of output
236
162
@@ -309,21 +235,13 @@ There are many objects in Sage that model sets of combinatorial objects.
309
235
310
236
::
311
237
312
- sage: W = Words("ab")
238
+ sage: W = Words("ab", finite=True )
313
239
sage: W
314
- Words over Ordered Alphabet ['a', 'b']
315
-
316
- .. end of output
317
-
318
- ::
240
+ Finite words over {'a', 'b'}
319
241
320
242
sage: W.cardinality()
321
243
+Infinity
322
244
323
- .. end of output
324
-
325
- ::
326
-
327
245
sage: it = iter(W)
328
246
sage: for a in range(16):
329
247
....: print(next(it))
@@ -352,18 +270,7 @@ There are many objects in Sage that model sets of combinatorial objects.
352
270
353
271
sage: P = posets()
354
272
sage: P
355
- Posets
356
-
357
- .. end of output
358
-
359
- ::
360
-
361
- sage: P.cardinality()
362
- +Infinity
363
-
364
- .. end of output
365
-
366
- ::
273
+ Category of posets
367
274
368
275
sage: it = iter(P)
369
276
sage: for a in range(10):
@@ -395,10 +302,6 @@ Sage supports several ways of creating new combinatorial classes from objects.
395
302
sage: C
396
303
Combinations of [1, 2, 3] of length 2
397
304
398
- .. end of output
399
-
400
- ::
401
-
402
305
sage: C.list()
403
306
[[1, 2], [1, 3], [2, 3]]
404
307
@@ -411,10 +314,6 @@ Sage supports several ways of creating new combinatorial classes from objects.
411
314
sage: S
412
315
Subsets of {1, 2, 3} of size 2
413
316
414
- .. end of output
415
-
416
- ::
417
-
418
317
sage: S.list()
419
318
[{1, 2}, {1, 3}, {2, 3}]
420
319
@@ -427,16 +326,8 @@ Sage supports several ways of creating new combinatorial classes from objects.
427
326
sage: S
428
327
Set partitions of ['a', 'b', 'c']
429
328
430
- .. end of output
431
-
432
- ::
433
-
434
329
sage: S.list()
435
- [{{'a', 'c', 'b'}}, {{'c', 'b'}, {'a'}}, {{'c'}, {'a', 'b'}}, {{'a', 'c'}, {'b'}}, {{'c'}, {'b'}, {'a'}}]
436
-
437
- .. end of output
438
-
439
- ::
330
+ [{{'a', 'b', 'c'}}, ...]
440
331
441
332
sage: S.cardinality()
442
333
5
@@ -449,8 +340,6 @@ Example: Vexillary involutions
449
340
450
341
A *vexillary involution * is a permutation that:
451
342
452
-
453
-
454
343
#. avoids the pattern 2143;
455
344
456
345
#. is an involution (that is, :math: `p = p^{-1 }`).
@@ -464,26 +353,13 @@ We can create the set of vexillary involutions of the set {1,2,3,4} in Sage by
464
353
sage: def is_involution(p):
465
354
....: return p == p.inverse()
466
355
467
-
468
- .. end of output
469
-
470
- ::
471
-
472
356
sage: P = Permutations(4, avoiding=[2,1,4,3]).filter(is_involution)
473
357
sage: P
474
358
Filtered sublass of Standard permutations of 4 avoiding [[2, 1, 4, 3]]
475
359
476
- .. end of output
477
-
478
- ::
479
-
480
360
sage: P.cardinality()
481
361
9
482
362
483
- .. end of output
484
-
485
- ::
486
-
487
363
sage: P.list()
488
364
[[1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 4, 3, 2], [3, 4, 1, 2], [2, 1, 3, 4], [4, 2, 3, 1], [3, 2, 1, 4], [4, 3, 2, 1]]
489
365
@@ -497,17 +373,9 @@ We can create the set of vexillary involutions of the set {1,2,3,4} in Sage by
497
373
....: return P.cardinality()
498
374
499
375
500
- .. end of output
501
-
502
- ::
503
-
504
376
sage: SL = sloane_find([number_of_vexillary_involutions(n) for n in range(1,7)])
505
377
Searching Sloane's online database...
506
378
507
- .. end of output
508
-
509
- ::
510
-
511
379
sage: SL[0]
512
380
[1006, 'Motzkin numbers: number of ways of drawing any number of nonintersecting chords joining n (labeled) points on a circle.', [1, 1, 2, 4, 9, 21, 51, 127, 323, 835, 2188, 5798, 15511, 41835, 113634, 310572, 853467, 2356779, 6536382, 18199284, 50852019, 142547559, 400763223, 1129760415, 3192727797, 9043402501, 25669818476, 73007772802, 208023278209, 593742784829]]
513
381
@@ -604,26 +472,13 @@ At the very minimum, you should implement the following methods:
604
472
....: p = Permutation(p)
605
473
....: return len(p) == self._n and p.avoids([2,1,4,3]) and p == p.inverse()
606
474
607
-
608
- .. end of output
609
-
610
- ::
611
-
612
475
sage: V = VexillaryInvolutions(4)
613
476
sage: V
614
477
Vexillary involutions of 4
615
478
616
- .. end of output
617
-
618
- ::
619
-
620
479
sage: [2,1,3,4] in V
621
480
True
622
481
623
- .. end of output
624
-
625
- ::
626
-
627
482
sage: [2,1,4,3] in V
628
483
False
629
484
0 commit comments