Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 68b6530

Browse files
committedDec 14, 2015
Removed TODO in doc
1 parent 82fd1e4 commit 68b6530

File tree

1 file changed

+0
-115
lines changed

1 file changed

+0
-115
lines changed
 

‎src/sage/sets/recursively_enumerated_set.pyx

-115
Original file line numberDiff line numberDiff line change
@@ -21,121 +21,6 @@ AUTHORS:
2121
2222
EXAMPLES:
2323
24-
.. TODO:: Merge in the following documentation by Florent:
25-
26-
How to define a set using those classes ?
27-
28-
Only two things are necessary to define a set using a
29-
:class:`RecursivelyEnumeratedSet` object (the other classes being very similar) :
30-
31-
.. MATH::
32-
33-
\begin{picture}(-300,0)(600,0)
34-
% Root
35-
\put(0,0){\circle*{7}}
36-
\put(0,10){\makebox(0,10){``\ ''}}
37-
% First Children
38-
\put(-150,-60){\makebox(0,10){``a''}}
39-
\put(0,-60){\makebox(0,10){``b''}}
40-
\put(150,-60){\makebox(0,10){``c''}}
41-
\multiput(-150,-70)(150,0){3}{\circle*{7}}
42-
% Second children
43-
\put(-200,-130){\makebox(0,10){``aa''}}
44-
\put(-150,-130){\makebox(0,10){``ab''}}
45-
\put(-100,-130){\makebox(0,10){``ac''}}
46-
\put(-50,-130){\makebox(0,10){``ba''}}
47-
\put(0,-130){\makebox(0,10){``bb''}}
48-
\put(50,-130){\makebox(0,10){``bc''}}
49-
\put(100,-130){\makebox(0,10){``ca''}}
50-
\put(150,-130){\makebox(0,10){``cb''}}
51-
\put(200,-130){\makebox(0,10){``cc''}}
52-
\multiput(-200,-140)(50,0){9}{\circle*{7}}
53-
% Legend
54-
\put(100,-5){\makebox(0,10)[l]{1) An initial element}}
55-
\put(-250,-5){\makebox(0,10)[l]{2) A function of an element enumerating}}
56-
\put(-235,-20){\makebox(0,10)[l]{its children (if any)}}
57-
% Arrows
58-
\thicklines
59-
\put(0,-10){\vector(0,-1){30}}
60-
\put(-15,-5){\vector(-2,-1){110}}
61-
\put(15,-5){\vector(2,-1){110}}
62-
\multiput(-150,-80)(150,0){3}{\vector(0,-1){30}}
63-
\multiput(-160,-80)(150,0){3}{\vector(-1,-1){30}}
64-
\multiput(-140,-80)(150,0){3}{\vector(1,-1){30}}
65-
\put(90,0){\vector(-1,0){70}}
66-
\put(-215,-30){\vector(1,-1){40}}
67-
\end{picture}
68-
69-
For the previous example, the two necessary pieces of information are :
70-
71-
- The initial element ``""``
72-
73-
- The function ``lambda x : [x+letter for letter in ['a', 'b', 'c']``
74-
75-
Err.. Well, this would actually describe an **infinite** set, as such rules
76-
describes "all words" on 3 letters. Hence, it is a good idea to replace the
77-
function by
78-
79-
``lambda x : [x+letter for letter in ['a', 'b', 'c']] if len(x) < 2 else []``
80-
81-
or even::
82-
83-
sage: def children(x):
84-
....: if len(x) < 2:
85-
....: for letter in ['a', 'b', 'c']:
86-
....: yield x+letter
87-
88-
We can then create the :class:`RecursivelyEnumeratedSet` object with either ::
89-
90-
sage: S = RecursivelyEnumeratedSet( [''],
91-
....: lambda x: [x+letter for letter in ['a', 'b', 'c']]
92-
....: if len(x) < 2 else [],
93-
....: structure='forest', enumeration='depth',
94-
....: category=FiniteEnumeratedSets())
95-
sage: S.list()
96-
['', 'a', 'aa', 'ab', 'ac', 'b', 'ba', 'bb', 'bc', 'c', 'ca', 'cb', 'cc']
97-
98-
Or::
99-
100-
sage: S = RecursivelyEnumeratedSet( [''], children,
101-
....: structure='forest', enumeration='depth',
102-
....: category=FiniteEnumeratedSets())
103-
sage: S.list()
104-
['', 'a', 'aa', 'ab', 'ac', 'b', 'ba', 'bb', 'bc', 'c', 'ca', 'cb', 'cc']
105-
106-
Here is a little more involved example. We want to iterate through all
107-
permutations of a given set S. One solution is to take elements of S one by
108-
one an insert them at every positions. So a node of the generating tree
109-
contains two informations
110-
111-
- the list ``lst`` of already inserted element;
112-
- the set ``st`` of the yet to be inserted element.
113-
114-
We want to generate a permutation only if ``st`` is empty (leaves on the
115-
tree). Also suppose for the sake of the example, that instead of list we want
116-
to generate tuples. This selection of some nodes and final mapping of a
117-
function to the element is done by the ``post_process = f`` argument. The
118-
convention is that the generated elements are the ``s := f(n)``, except when
119-
``s`` not ``None`` when no element is generated at all. Here is the code::
120-
121-
sage: def children((lst, st)):
122-
....: st = set(st) # make a copy
123-
....: if st:
124-
....: el = st.pop()
125-
....: for i in range(0, len(lst)+1):
126-
....: yield (lst[0:i]+[el]+lst[i:], st)
127-
sage: list(children(([1,2], {3,7,9})))
128-
[([9, 1, 2], {3, 7}), ([1, 9, 2], {3, 7}), ([1, 2, 9], {3, 7})]
129-
sage: S = RecursivelyEnumeratedSet( [([], {1,3,6,8})],
130-
....: children,
131-
....: post_process = lambda (l, s): tuple(l) if not s else None,
132-
....: structure='forest', enumeration='depth',
133-
....: category=FiniteEnumeratedSets())
134-
sage: S.list()
135-
[(6, 3, 1, 8), (3, 6, 1, 8), (3, 1, 6, 8), (3, 1, 8, 6), (6, 1, 3, 8), (1, 6, 3, 8), (1, 3, 6, 8), (1, 3, 8, 6), (6, 1, 8, 3), (1, 6, 8, 3), (1, 8, 6, 3), (1, 8, 3, 6), (6, 3, 8, 1), (3, 6, 8, 1), (3, 8, 6, 1), (3, 8, 1, 6), (6, 8, 3, 1), (8, 6, 3, 1), (8, 3, 6, 1), (8, 3, 1, 6), (6, 8, 1, 3), (8, 6, 1, 3), (8, 1, 6, 3), (8, 1, 3, 6)]
136-
sage: S.cardinality()
137-
24
138-
13924
Forest structure
14025
----------------
14126

0 commit comments

Comments
 (0)
This repository has been archived.