Debian Codegraph @

dwtools/manual_Permutation.cpp

raw
1 /* manual_Permutation.cpp
2 *
3 * Copyright (C) 2005-2025 David Weenink
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /*
20 20050709 djmw
21 */
22
23 #include "ManPagesM.h"
24
25 void manual_Permutation_init (ManPages me);
26 void manual_Permutation_init (ManPages me)
27 {
28 MAN_BEGIN (U"natural sort order", U"djmw", 20221023)
29 NORMAL (U"Natural sort order uses the following rules to sort strings: ")
30 LIST_ITEM (U"1. The space character sorts before numbers; numbers sort before non-numbers. Example: \n"
31 "' 5' < '5' < 'a'")
32 LIST_ITEM (U"2. Numbers sort in numerical order; leading zeroes and spaces on numbers are ignored, except as a tie-breaker "
33 "for numbers that have the same numerical value like ' 5' < ' 5 ' < '5' < '05' < '005'")
34 LIST_ITEM (U"3. Non-numbers sort in the asciibetical order ('Z' before 'a'), like "
35 "'A' < 'B' ... < 'Z' < 'a' ... 'z'")
36 ENTRY (U"##Examples#")
37 NORMAL (U" 1. The alphabetically sorted 'd1', 'd10', 'd11', 'd2' in natural sort order: 'd1', 'd2', 'd10', 'd11'.")
38 NORMAL (U" 2. Example from https://github.com/sourcefrog/natsort/blob/master/example-out.txt. The alphabetically "
39 "sorted list of the following 29 strings '1-02', '1-2', '1-20', '10-20', 'fred', 'jane', 'pic 7', 'pic 4 else', "
40 "'pic 5', 'pic 5 ', 'pic 5 something', 'pic 6', 'pic01', 'pic02', 'pic02000', 'pic02a', 'pic05', 'pic100', "
41 "'pic100a', 'pic120', 'pic121', 'pic2', 'pic3', 'pic4', 'tom', 'x2-g8', 'x2-y08', 'x2-y7', 'x8-y8' "
42 "will appear in natural sort order as: ")
43 NORMAL (U"'1-2', '1-02', '1-20', '10-20', 'fred', 'jane', 'pic01', 'pic2', 'pic02', 'pic02a', 'pic3', 'pic4', 'pic 4 else', "
44 "'pic 5', 'pic05', 'pic 5 ', 'pic 5 something', 'pic 6', 'pic 7', 'pic100', 'pic100a', 'pic120', 'pic121', 'pic02000', "
45 "'tom', 'x2-g8', 'x2-y7', 'x2-y08', 'x8-y8'.")
46 MAN_END
47
48 MAN_BEGIN (U"Permutation", U"djmw", 20250120)
49 INTRO (U"One of the @@types of objects@ in Praat. A Permutation object with %n elements consists of some ordering of "
50 "the numbers 1,2...%n.")
51 ENTRY (U"Interpretation")
52 NORMAL (U"A permutation like for example (2,3,5,4,1) is an %arrangement of the five objects 1, 2, 3, 4, and 5. "
53 "It tells us that the second object is in the first position, the third object is in the second position, "
54 "the fifth object in the third position and so on.")
55 NORMAL (U"If we combine a Permutation together with an other object, like a Strings for example, we may force a "
56 "new arrangement of the strings, according to the specification in the Permutation (see @@Strings & Permutation: Permute strings@)." )
57 ENTRY (U"Commands")
58 NORMAL (U"Creation:")
59 LIST_ITEM (U"\\bu @@Create Permutation...@")
60 NORMAL (U"Query:")
61 LIST_ITEM (U"\\bu ##Get number of elements#")
62 LIST_ITEM (U"\\bu @@Permutation: Get value...|Get value...@")
63 LIST_ITEM (U"\\bu @@Permutation: Get index...|Get index...@")
64 LIST_ITEM (U"\\bu @@Permutation: Get number of inversions|Get number of inversions...@")
65 NORMAL (U"Modification:")
66 LIST_ITEM (U"\\bu @@Permutation: Sort|Sort@")
67 LIST_ITEM (U"\\bu @@Permutation: Swap blocks...|Swap blocks...@")
68 LIST_ITEM (U"\\bu @@Permutation: Swap positions...|Swap positions...@")
69 LIST_ITEM (U"\\bu @@Permutation: Swap numbers...|Swap numbers...@")
70 LIST_ITEM (U"\\bu @@Permutation: Swap one from range...|Swap one from range...@")
71 NORMAL (U"Permutations:")
72 LIST_ITEM (U"\\bu @@Permutation: Permute randomly...|Permute randomly...@")
73 LIST_ITEM (U"\\bu @@Permutation: Permute randomly (blocks)...|Permute randomly (blocks)...@")
74 LIST_ITEM (U"\\bu @@Permutation: Interleave...|Interleave...@")
75 LIST_ITEM (U"\\bu @@Permutation: Rotate...|Rotate...@")
76 LIST_ITEM (U"\\bu @@Permutation: Reverse...|Reverse...@")
77 LIST_ITEM (U"\\bu @@Permutation: Invert|Invert@")
78 NORMAL (U"Successive permutations:")
79 LIST_ITEM (U"\\bu @@Permutations: Multiply|Multiply@")
80 ENTRY (U"Usage")
81 LIST_ITEM (U"@@Strings & Permutation: Permute strings@ to rearrange the strings in a Strings object.")
82 LIST_ITEM (U"@@TableOfReal & Permutation: Permute rows@ to rearrange the rows in a TableOfReal object.")
83 MAN_END
84
85 MAN_BEGIN (U"Create Permutation...", U"djmw", 20050709)
86 INTRO (U"A command to create a @Permutation of the numbers 1,2, ..., %numberOfElements.")
87 ENTRY (U"Settings")
88 TERM (U"##Name")
89 DEFINITION (U"the name of the new permutation.")
90 TERM (U"##Number of elements%")
91 DEFINITION (U"the number of elements in the permutation.")
92 TERM (U"##Identity permutation")
93 DEFINITION (U"determines whether the permutation will be a randomly chosen one, or the @@identity permutation@.")
94 MAN_END
95
96 MAN_BEGIN (U"identity permutation", U"djmw", 20050713)
97 INTRO (U"The identity permutation is (1,2,3,...,%numberOfElements), i.e. the numbers 1 to "
98 "%numberOfElements in their natural order. ")
99 MAN_END
100
101 MAN_BEGIN (U"Permutation: Get value...", U"djmw", 20050709)
102 INTRO (U"Get the value at the index position.")
103 ENTRY (U"Example")
104 NORMAL (U"The query for the value at index 3 for the permutation (3,2,4,5,1) gives 4.")
105 MAN_END
106
107 MAN_BEGIN (U"Permutation: Get index...", U"djmw", 20050714)
108 INTRO (U"Get the index position of the value. ")
109 ENTRY (U"Example")
110 NORMAL (U"The query for the index of value 3 for the permutation (3,2,4,5,1) gives 1.")
111 MAN_END
112
113 MAN_BEGIN (U"Permutation: Get number of inversions", U"djmw", 20250120)
114 INTRO (U"Get the number of %inversions in a Permutation object. An inversion is defined as: if i < j then p(i) > p(j).")
115 ENTRY (U"Examples")
116 NORMAL (U"The query for the number of inversions in the permutation (3,2,4,5,1) gives 3 because 3>2, 3>1 and 2>1.")
117 NORMAL (U"The permutation (1,2,3,4) has 0 inversions.")
118 NORMAL (U"The permutation (4,3,2,1) has 6 inversions.")
119 NORMAL (U"The number of inversions of a permutation with %n elements is always in the closed interval [0, %n(%n-1)/2].")
120 MAN_END
121
122 MAN_BEGIN (U"Permutation: Table jump...", U"djmw", 20191211)
123 INTRO (U"Reorder by jumping columnwise to next row over the permutation indices layed out like a table with "
124 "%%jumpSize% columns. ")
125 ENTRY (U"Settings")
126 TERM (U"##Jump size#")
127 DEFINITION (U"defines how many indices to jump over, i.e. the number of columns in the \"table\".")
128 TERM (U"##First#")
129 DEFINITION (U"The first new position.")
130 ENTRY (U"Example 1")
131 NORMAL (U"Consider the identity permutation of 14 elements layed out like a table with %%jumpSize% = 4 columns.")
132 CODE (U" 1 2 3 4")
133 CODE (U" 5 6 7 8")
134 CODE (U" 9 10 11 12")
135 CODE (U"13 14")
136 NORMAL (U"1. ##Table jump: 4, 1# will result in the permutation (1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 4, 8, 12)")
137 NORMAL (U"2. ##Table jump: 4, 2# will result in the permutation (2, 6, 10, 14, 3, 7, 11, 4, 8, 12, 1, 5. 9, 13)")
138 NORMAL (U"3. ##Table jump: 4, 5# will result in the permutation (5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 4, 8, 12, 1)")
139 NORMAL (U"4. ##Table jump: 4, 12# will result in the permutation (12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 4, 8)")
140 ENTRY (U"Example 2")
141 NORMAL (U"Consider the identity permutation of 14 elements layed out like a table with %%jumpSize% = 7 columns.")
142 CODE (U" 1 2 3 4 5 6 7")
143 CODE (U" 8 9 10 11 12 13 14")
144 NORMAL (U"1. ##Table jump: 7, 1# will result in the permutation (1, 8, 2, 9, 3, 10, 4, 11, 5, 12, 6, 13, 7, 14)")
145 MAN_END
146
147 MAN_BEGIN (U"Permutation: Reverse...", U"djmw", 20110105)
148 INTRO (U"Reverse the elements in the given range.")
149 ENTRY (U"Setting")
150 TERM (U"##Index range#")
151 DEFINITION (U"defines the range of indices that will be reversed.")
152 ENTRY (U"Examples")
153 NORMAL (U"1. With ##Index range# = [0,0], the permutation (1,2,3,4,5) is turned into (5,4,3,2,1). ")
154 NORMAL (U"2. With ##Index range# = [3,0], the permutation (1,2,3,4,5) is turned into (1,2,5,4,3). ")
155 MAN_END
156
157 MAN_BEGIN (U"Permutation: Swap one from range...", U"djmw", 20110105)
158 INTRO (U"An element at an index, randomly chosen from a range, will be permuted with an element at a prescribed index position.")
159 ENTRY (U"Settings")
160 TERM (U"##Index range#")
161 DEFINITION (U"defines the range of indices from which one will be randomly chosen.")
162 TERM (U"##Index#")
163 DEFINITION (U"defines the special index position whose element will be interchanged with the one chosen from the range.")
164 TERM (U"##Forbid same")
165 DEFINITION (U"when %on, forbids the randomly chosen position and the index position to be the same. "
166 "This switch is only of relevance when the chosen range happens to overlap the index position.")
167 ENTRY (U"Examples")
168 NORMAL (U"With ##Index range# = [0,0], ##Index# = 3, ##Forbid same# is %off and (1,2,3,4,5) as the starting permutation, the outcome might be one of "
169 "the five permutations (3,2,1,4,5), (1,3,2,4,5), (1,2,3,4,5), (1,2,4,3,5), (1,2,5,4,3). If ##Forbid same# were chosen as %on, the "
170 "(1,2,3,4,5) permutation is forbidden and the outcome could only be one of the four remaining permutations.")
171 MAN_END
172
173 MAN_BEGIN (U"Permutation: Permute randomly...", U"djmw", 20111123)
174 INTRO (U"Generates a new @@Permutation@ by randomly permuting a range of elements in the selected Permutation object.")
175 ENTRY (U"Setting")
176 TERM (U"##Index range#")
177 DEFINITION (U"defines the range of elements that will be permuted. The elements outside this range will be kept intact.")
178 ENTRY (U"Example")
179 NORMAL (U"If we start with the permutation (4,6,3,1,5,2,7) and a chosen ##Index range# that runs from 3 to 6, a new permutation will be generated as follows:")
180 LIST_ITEM (U"1. A new permutation of the same dimension as the selected one will be created. ")
181 LIST_ITEM (U"2. Because the index range starts at 3, the first two elements of the selected permutation will be copied "
182 "to the first two locations in the newly created permutation. The new permutation is now (4,6,.,.,.,.,.), where a "
183 "dot (.) means that the element is unspecified.")
184 LIST_ITEM (U"3. The elements 3 to 6 of the selected permutation, i.e. the numbers (3,1,5,2) will be randomly permuted. "
185 "There are 24 possible permutations of these 4 numbers. Say the outcome happens to be (5,1,3,2). The new permutation is now (4,6,5,1,3,2,.).")
186 LIST_ITEM (U"4. The remaining element (7) is copied to the new permutation. Finally, this results "
187 "in the new permutation being (4,6,5,1,3,2,7).")
188 MAN_END
189
190 MAN_BEGIN (U"Permutation: Permute randomly (blocks)...", U"djmw", 20110105)
191 INTRO (U"Generates a new @Permutation by randomly permuting blocks of size %blocksize.")
192 ENTRY (U"Settings")
193 TERM (U"##Index range#")
194 DEFINITION (U"the range of elements whose blocks will be permuted.")
195 TERM (U"##Block size#")
196 DEFINITION (U"the size of the blocks that will be permuted. There must fit an integer number of blocks "
197 "in the chosen range.")
198 TERM (U"##Permute within blocks#")
199 DEFINITION (U"when %on, the elements in each block are also randomly permuted.")
200 TERM (U"##No doublets#")
201 DEFINITION (U"guarantees that the first element in each block does not equal the last element of the previous block modulo "
202 "the block size. E.g. the numbers 3, 6, 9 are all equal modulo 3. "
203 "This parameter only has effect when ##Permute within blocks# is %on.")
204 ENTRY (U"Examples")
205 NORMAL (U"1. With ##Index range# = [0,0], ##Block size# = 3 and ##Permute within blocks# is %off, the permutation ((1,2,3),(4,5,6),(7,8,9)) "
206 "is turned into one of six possible permutations, for example into ((4,5,6),(7,8,9),(1,2,3)). (The option ##No doublets# will be ignored and the parentheses are only there to indicate the blocks.)")
207 NORMAL (U"2. With ##Index range# = [0,0], ##Block size# = 3, ##Permute within blocks# is %on and ##No doublets# is %off, "
208 "the permutation ((1,2,3),(4,5,6),(7,8,9)) might turn into ((5,4,6),(9,8,7),(3,1,2)).")
209 NORMAL (U"3. With the same options as 2 but ##No doublets# is %on, the previously given outcome is forbidden because "
210 "the last element of the first block (6) and the first element of the next block (9) are equal modulo 3 (the "
211 "blocksize). A valid outcome might then be ((5,4,6),(8,9,7),(3,1,2)).")
212 MAN_END
213
214 MAN_BEGIN (U"Permutation: Permute part...", U"djmw", 20220929)
215 INTRO (U"A command to create a new @Permutation which is a copy of the first selected Permutation but with a part "
216 "that has been permuted according to a specification given by the second one.")
217 ENTRY (U"Settings")
218 TERM (U"##Start index#")
219 DEFINITION (U"the position in the first selected Permutation where the modification by the second one should start.")
220 ENTRY (U"Examples")
221 NORMAL (U"Suppose the first permutation p1 is (1,2,3,4,5,6,7,8,9,10,11) and the second one p2 is (2,3,5,1,4).")
222 NORMAL (U"1. With ##Start index# set to 1, the newly generated permutation p3 will be ((2,3,5,1,4), 6,7,8,9,10,11). "
223 "The new p3 will have the same number of elements as p1. The permutation p2 which has 5 elements starts to operate at "
224 "the first element and will stop after the fifth element. The first five elements in p3 will therefore equal "
225 "the permuted first five elements of p1, while the last 6 elements of p3 will be a copy of those in p1.")
226 NORMAL (U"2. With ##Start index# set to 6, the newly generated permutation will be (1,2,3,4,5, (7,8,10,6,9), 11).")
227 MAN_END
228
229 MAN_BEGIN (U"Permutation: Swap blocks...", U"djmw", 20110105)
230 INTRO (U"A command to swap the contents of two index ranges in the selected @Permutation.")
231 ENTRY (U"Settings")
232 TERM (U"##From index#, ##To index#")
233 DEFINITION (U"the two starting positions from where elements are to be swapped. The blocks may overlap.")
234 TERM (U"##Block size#")
235 DEFINITION (U"determines the number of pairs to swap. ")
236 ENTRY (U"Behaviour")
237 NORMAL (U"If the ##Block size# equals one, only the elements at the ##From index# and ##To index# position are swapped. If blocksize is greater than one, the two elements at ##From index#+1 and ##To index#+1 will be swapped too. This goes on until the last two elements in each block have been swapped.")
238 ENTRY (U"Examples")
239 NORMAL (U"1. Swap two blocks: with ##From index# = 1, ##To index# = 4, and ##Block size# = 2, the permutation (1,2,3,4,5) is turned into (4,5,3,1,2).")
240 NORMAL (U"2. Swap two elements: with ##From index# = 1, ##To index# = 4, and ##Block size# = 1, the permutation (1,2,3,4,5) is turned into (4,2,3,1,5).")
241 NORMAL (U"3. Swap two overlapping blocks: with ##From index# = 1, ##To index# = 3, and ##Block size# = 3, the permutation (1,2,3,4,5) is turned into "
242 "(3,4,5,2,1).")
243 MAN_END
244
245 MAN_BEGIN (U"Permutation: Swap positions...", U"djmw", 20110105)
246 INTRO (U"Swaps the contents at two indices in the selected @@Permutation@.")
247 ENTRY (U"Settings")
248 TERM (U"##First index#, ##Second index#")
249 DEFINITION (U"the two indices from where elements have to be swapped. The order of these indices is not important.")
250 ENTRY (U"Example")
251 NORMAL (U"With ##First index# = 1 and ##Second index# = 3, the permutation (1,3,4,2,5) is turned into (4,3,1,2,5).")
252 MAN_END
253
254 MAN_BEGIN (U"Permutation: Swap numbers...", U"djmw", 20110105)
255 INTRO (U"Swaps two numbers in the selected @@Permutation@.")
256 ENTRY (U"Settings")
257 TERM (U"##First number#, ##Second number#")
258 DEFINITION (U"the two numbers that have to be swapped. The order of these numbers is not important.")
259 ENTRY (U"Example")
260 NORMAL (U"With ##First number# = 1 and ##Second number# = 3, the permutation (1,3,4,2,5) is turned into (3,1,4,2,5).")
261 MAN_END
262
263 MAN_BEGIN (U"Permutation: Interleave...", U"djmw", 20110105)
264 INTRO (U"Generates a new @Permutation by interleaving elements from successive blocks. ")
265 NORMAL (U"We always start with the first element in the first block. When the offset is zero, the next element will be the first "
266 "element of the second block, then the first element of the third block. After the first element of the last block, we start again "
267 "with the second elements in each block. And so on. (In card playing, with two blocks of 26 cards each, this is called a faro "
268 "shuffle and eight successive faro shuffles will return the deck to precisely the order in which you began.)")
269 NORMAL (U"If the offset differs from zero and equals 1 for example, we start with the first element in the first block, then the "
270 "second element in the second block, the third element in the third block and so on. When the last element of a block is reached "
271 "and the number of blocks is not exhausted the next element will be the first from the next block. When the last block is reached, "
272 "we start the same cycle again with the next lower element in the first block (which by the way need not be the second element, "
273 "see also example 4).")
274 ENTRY (U"Settings")
275 TERM (U"##Index range#")
276 DEFINITION (U"the range of elements that will be permuted.")
277 TERM (U"##Block size#")
278 DEFINITION (U"the size of a block. An integer number of blocks must fit "
279 "in the chosen ##Index range#.")
280 TERM (U"##Offset#")
281 DEFINITION (U"determines the relative positions of selected elements in successive blocks.")
282 ENTRY (U"Examples")
283 NORMAL (U"1. With ##Index range# = [0,0], ##Block size# = 3, and ##Offset# = 0, the permutation ((1,2,3),(4,5,6),(7,8,9)) is turned into (1,4,7,2,5,8,3,6,9).")
284 NORMAL (U"2. With ##Index range# = [0,0], ##Block size# = 3, and ##Offset# = 1, the permutation ((1,2,3),(4,5,6),(7,8,9)) is turned into (1,5,9,2,6,7,3,4,8).")
285 NORMAL (U"3. With ##Index range# = [0,0], ##Block size# = 3, and ##Offset# = 2, the permutation ((1,2,3),(4,5,6),(7,8,9)) is turned into (1,6,8,2,4,9,3,5,7).")
286 NORMAL (U"4. With ##Index range# = [0,0], ##Block size# = 4, and ##Offset# = 1, the permutation ((1,2,3,4),(5,6,7,8)) is turned into (1,6,3,8,2,7,4,5).")
287 MAN_END
288
289 MAN_BEGIN (U"lexicographic permutation order", U"djmw", 20140131)
290 INTRO (U"We can order the %n numbers 1, 2, 3,..., n in %n! different ways. Each of these n! orderings represents a different permutation of "
291 "the numbers 1, 2, 3,..., n. For example, if %n equals 3 we have 6 (=3\\.c2\\.c1) possible orderings: (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2) and (3,2,1). "
292 "The %%lexicographic permutation order% starts from the identity permutation (1,2,..., n). By successively swapping only two numbers one "
293 "obtains all possible permutations. The last permutation in lexicographic order will be the permutation with all numbers in reversed order, "
294 "i.e. (n,n-1,...,2,1). The example given above has all 6 permutations in lexicographic permutation order.")
295 MAN_END
296
297 MAN_BEGIN (U"Permutation: Next", U"djmw", 20140131)
298 INTRO (U"Get the next @@Permutation|permutation@ in @@lexicographic permutation order@. ")
299 NORMAL (U"The next permutation is obtained from the selected permutation "
300 "by swapping values %%at only two positions%. Starting with the identity permutation and "
301 "repeatedly applying this function will iterate through all possible permutations. If no further permutation "
302 "is available, i.e. the selected permutation is at the lexicographic end position (n, n-1, ..., 3, 2, 1), the current permutation will not change anymore. ")
303 ENTRY (U"Examples")
304 NORMAL (U"If we start with (1,2,3,4) successively applying ##Next# will generate the following sequence (1,2,4,3), (1,3,2,4), (1,3,4,2), (1,4,2,3), (1,4,3,2), etc.")
305 MAN_END
306
307 MAN_BEGIN (U"Permutation: Previous", U"djmw", 20140131)
308 NORMAL (U"Get the previous @@Permutation|permutation@ in @@lexicographic permutation order@. The previous permutation is obtained "
309 "from the selected permutation by swapping values %%at only two positions%. If no further permutation "
310 "is available, i.e. the current permutation is at the lexicographic start position (1, 2, 3, ..., n-1, n), the current permutation will not change anymore. ")
311 NORMAL (U"The ##Previous# operation follows the opposite order of @@Permutation: Next@.")
312 MAN_END
313
314 MAN_BEGIN (U"Permutation: Rotate...", U"djmw", 20110105)
315 INTRO (U"A circular shift of all elements within the given range.")
316 ENTRY (U"Settings")
317 TERM (U"##Index range#")
318 DEFINITION (U"the range of elements that will be circularly permuted.") // ambiguous; are these the positions or the numbers?
319 TERM (U"##Step size#")
320 DEFINITION (U"define how many positions each element will be shifted.")
321 ENTRY (U"Examples")
322 NORMAL (U"1. With ##Step size# = 2 and ##Index range# = [1,5], the permutation (1,2,3,4,5) is turned into (4,5,1,2,3). ")
323 NORMAL (U"2. With ##Step size# = 2 and ##Index range# = [2,5], the permutation ((1),(2,3,4,5)) is turned into ((1),(4,5,2,3))")
324 NORMAL (U"3. With ##Step size# = -1 and ##Index range# = [0,0], the permutation (1,2,3,4,5) is turned into (2,3,4,5,1).")
325 MAN_END
326
327 MAN_BEGIN (U"Permutation: Invert", U"djmw", 20050709)
328 INTRO (U"Generates the inverse of the selected @Permutation.")
329 ENTRY (U"Example")
330 NORMAL (U"If the permutation is (1,5,3,2,4) the inverse will be (1,4,3,5,2). If we @@Permutations: Multiply|multiply@ these two permutations the result will be the identity permutation (1,2,3,4,5).")
331 MAN_END
332
333 MAN_BEGIN (U"Permutations: Multiply", U"djmw", 20050717)
334 INTRO (U"Apply the selected @@Permutation@s one after the other. ")
335 NORMAL (U"Permutations are %not commutative, i.e. applying permutation %p__1_ after %p__2_ might not give the same outcome as applying "
336 "%p__2_ after %p__1_.")
337 MAN_END
338
339 MAN_BEGIN (U"Permutation: Sort", U"djmw", 20050709)
340 INTRO (U"Sorts the elements ascending, i.e. set the selected @@Permutation@ to the @@identity permutation@.")
341 MAN_END
342
343 MAN_BEGIN (U"TableOfReal & Permutation: Permute rows", U"djmw", 20050709)
344 INTRO (U"Generate a new @TableOfReal with a row ordering determined by the @Permutation.")
345 ENTRY (U"Example")
346 NORMAL (U"If the selected TableOfReal has 5 rows and the permutation is (5,4,3,2,1) the first row of the new TableOfReal equals the fifth row of the selected, the second row of new equals the fourth row of the selected and so on.")
347 MAN_END
348
349 MAN_BEGIN (U"Strings & Permutation: Permute strings", U"djmw", 20140130)
350 INTRO (U"Generate a new @Strings with a strings ordering determined by the @Permutation.")
351 NORMAL (U"The number of strings in the #Strings and the number of elements in the #Permutation have to be equal.")
352 ENTRY (U"Examples")
353 NORMAL (U"1. If the selected Strings has the 4 strings ordered as \"heed\", \"hid\", \"hood\", \"hud\", and the permutation is "
354 "(4,3,2,1), the new Strings has the ordering \"hud\", \"hood\", \"hid\", \"heed\".")
355 NORMAL (U"2. In the example that is discussed in the @@ExperimentMFC|listening experiment@ section, we have four stimuli \"heed.wav\", "
356 "\"hid.wav\", \"hood.wav\", \"hud.wav\" that we want to present three times to each subject with a <PermuteBalancedNoDoublets> "
357 "randomization strategy, i.e. stimuli presented in blocks of four, randomized, and no two successive stimuli equal. "
358 "This type of randomization can easily be accomplished with a Permutation object and a Strings." )
359 LIST_ITEM (U"1. Fill the Strings object with 12 strings, i.e. three repetitions of the four stimuli. ")
360 LIST_ITEM (U"2. Create a Permutation object with 12 elements and perform ##@@Permutation: Permute randomly (blocks)...|Permute randomly (blocks):@ 0, 0, 4, \"yes\", \"yes\"#. We randomly permute blocks of size 4 and permute randomly within these blocks and make sure that on the transition from on block to the other no two stimuli are equal. (Of course, the random permutation of the blocks makes no difference here since all the blocks have the same content.)")
361 LIST_ITEM (U"3. Select the Strings and the Permutation together and choose ##Permute strings#. "
362 "Now the new Strings will contain the new ordering of the stimuli.")
363 MAN_END
364
365 MAN_BEGIN (U"Strings: To Permutation...", U"djmw", 20050721)
366 INTRO (U"Generates a @Permutation with the same number of elements as the @Strings.")
367 ENTRY (U"Setting")
368 TERM (U"##Sort")
369 DEFINITION (U"determines whether the Permutation will have an element ordering that can be used to sort the Strings alphabetically.")
370 ENTRY (U"Example")
371 NORMAL (U"If \"Sort\" is %on, and the selected Strings contains 4 strings ordered as \"hud\", \"hid\", \"hood\", "
372 "\"heed\", the generated Permutation will be (4,2,3,1). If you now select the String and the Permutation "
373 "together and choose @@Strings & Permutation: Permute strings|Permute strings@, the new Strings will have "
374 "the strings ordered alphabetically as \"heed\", \"hid\", \"hood\", \"hud\". "
375 "You can also sort the Strings alphabetically descending, by first @@Permutation: Reverse...|reversing@ "
376 "the elements in the Permutation before you select the Permutation and the Strings together. ")
377 MAN_END
378
379 MAN_BEGIN (U"Index", U"djmw", 20050725)
380 INTRO (U"One of the @@Types of objects|types of objects@ in the Praat program.")
381 MAN_END
382
383 MAN_BEGIN (U"Strings: To Index", U"djmw", 20050721)
384 INTRO (U"Generates an @Index from the selected @Strings.")
385 ENTRY (U"Example")
386 NORMAL (U"We start from the following #Strings:")
387 CODE (U"6 (number of strings)")
388 CODE (U"\"hallo\"")
389 CODE (U"\"dag allemaal\"")
390 CODE (U"\"hallo\"")
391 CODE (U"\"tot morgen\"")
392 CODE (U"\"hallo\"")
393 CODE (U"\"tot morgen\"")
394 NORMAL (U"This will give us the following #Index:")
395 CODE (U"1 (number of columns) \"\" (no column name)")
396 CODE (U"\"dag allemaal\"")
397 CODE (U"\"hallo\"")
398 CODE (U"\"tot morgen\"")
399 CODE (U"6 (number of elements)")
400 CODE (U"2")
401 CODE (U"1")
402 CODE (U"2")
403 CODE (U"3")
404 CODE (U"2")
405 CODE (U"3")
406 MAN_END
407
408 MAN_BEGIN (U"Index: To Permutation...", U"djmw", 20050725)
409 INTRO (U"Generates a @Permutation from the selected @Index by randomly permuting blocks of equivalent elements.")
410 NORMAL (U"Suppose your data consists of groups of equivalent elements and the number of elements in the groups are not equal. You want to make random ordering of your data such that the elements in a group stay together. The following example shows you how.")
411 ENTRY (U"Setting")
412 TERM (U"##Permute within classes")
413 DEFINITION (U"determines whether the elements within a class will be randomly permuted.")
414 ENTRY (U"Example")
415 NORMAL (U"Suppose your data, for example a @Strings, consists of groups of equivalent elements and the number of elements in the groups are not equal. You want to make a random ordering of your data such that the elements in a group stay together. The following example shows you how.")
416 NORMAL (U"We start from the following Strings:")
417 CODE (U"6 (number of strings)")
418 CODE (U"\"hallo\"")
419 CODE (U"\"dag allemaal\"")
420 CODE (U"\"hallo\"")
421 CODE (U"\"tot morgen\"")
422 CODE (U"\"hallo\"")
423 CODE (U"\"tot morgen\"")
424 NORMAL (U"We choose @@Strings: To Index|To Index@ which will give us the following #Index:")
425 CODE (U"1 (number of columns) \"\" (no column name)")
426 CODE (U"\"dag allemaal\"")
427 CODE (U"\"hallo\"")
428 CODE (U"\"tot morgen\"")
429 CODE (U"6 (number of elements)")
430 CODE (U"2")
431 CODE (U"1")
432 CODE (U"2")
433 CODE (U"3")
434 CODE (U"2")
435 CODE (U"3")
436 NORMAL (U"We choose ##To Permutation# and with ##Permute within classes# %off, this might generate the permutation (2,4,6,1,3,5).")
437 NORMAL (U"Selecting the Permutation and the Strings together and choosing @@Strings & Permutation: "
438 "Permute strings|Permute strings@ will generate the following Strings:")
439 CODE (U"\"dag allemaal\"")
440 CODE (U"\"tot morgen\"")
441 CODE (U"\"tot morgen\"")
442 CODE (U"\"hallo\"")
443 CODE (U"\"hallo\"")
444 CODE (U"\"hallo\"")
445 NORMAL (U"We see that the permutation always keeps identical strings together.")
446 MAN_END
447
448 MAN_BEGIN (U"Index: Extract part...", U"djmw", 20221015)
449 INTRO (U"Creates a new @Index by copying a part of selected Index.")
450 ENTRY (U"Example")
451 NORMAL (U"Given the following Index:")
452 CODE (U"1 (number of columns) \"\" (no column name)")
453 CODE (U"\"dag allemaal\"")
454 CODE (U"\"hallo\"")
455 CODE (U"\"tot morgen\"")
456 CODE (U"6 (number of elements)")
457 CODE (U"2")
458 CODE (U"1")
459 CODE (U"2")
460 CODE (U"3")
461 CODE (U"2")
462 CODE (U"3")
463 NORMAL (U"The command ##Extract part... 1 2# gives you the new Index:")
464 CODE (U"1 (number of columns) \"\" (no column name)")
465 CODE (U"\"dag allemaal\"")
466 CODE (U"\"hallo\"")
467 CODE (U"\"tot morgen\"")
468 CODE (U"2 (number of elements)")
469 CODE (U"2")
470 CODE (U"1")
471 NORMAL (U"Note that all classes stay intact and may have zero references like for example the \"tot morgen\" class. ")
472 MAN_END
473 }
474
475 /* End of file manual_Permutation.cpp */
476