Iterator
NearPerfectParentheses
generate positions of left-parentheses in pairs of nested parentheses
Calling Sequence
Parameters
Options
Description
Examples
References
Compatibility
NearPerfectParentheses(n)
n
-
nonnegative integer
compile = truefalse
True means compile the iterator. The default is true.
The NearPerfectParentheses command returns an iterator that generates all n-combinations of the integers 1..2⁢n that represent the positions of left parentheses in a string of n-pairs of nested parentheses. For example, the string ()()() is represented by 1,3,5, while ((())) is represented by 1,2,3.
Adjacent combinations differ by a single index.
Methods
In addition to the common iterator methods, this iterator object has the following methods. The self parameter is the iterator object.
Number(self): return the number of iterations required to step through the iterator, assuming it started at rank one.
with⁡Iterator:
Generate the combinations of four pairs of nested parentheses.
P≔NearPerfectParentheses⁡4
Print⁡P,showrank:
1: 1 3 5 7 2: 1 3 5 6 3: 1 3 4 6 4: 1 3 4 5 5: 1 3 4 7 6: 1 2 4 6 7: 1 2 4 5 8: 1 2 4 7 9: 1 2 3 6 10: 1 2 3 4 11: 1 2 3 5 12: 1 2 3 7 13: 1 2 5 6 14: 1 2 5 7
Compute the number of iterations.
Number⁡NearPerfectParentheses⁡4
14
Knuth, Donald Ervin. The Art of Computer Programming, volume 4, fascicle 4; generating all trees, sec. 7.2.1.6, generating all trees, algorithm N, near-perfect parentheses, p. 8.
The Iterator[NearPerfectParentheses] command was introduced in Maple 2016.
For more information on Maple 2016 changes, see Updates in Maple 2016.
The Iterator[NearPerfectParentheses] command was updated in Maple 2022.
The n parameter was updated in Maple 2022.
See Also
Iterator[NestedParentheses]
Download Help Document