Near Perfect Parentheses - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Mathematics : Discrete Mathematics : Combinatorics : Iterator : Iterator/NearPerfectParentheses

Iterator

  

NearPerfectParentheses

  

generate positions of left-parentheses in pairs of nested parentheses

 

Calling Sequence

Parameters

Options

Description

Examples

References

Compatibility

Calling Sequence

NearPerfectParentheses(n)

Parameters

n

-

integer greater than 1

Options

• 

compile = truefalse

  

True means compile the iterator. The default is true.

Description

• 

The NearPerfectParentheses command returns an iterator that generates all n-combinations of the integers 1..2n 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.

Examples

withIterator:

Generate the combinations of four pairs of nested parentheses.

PNearPerfectParentheses4

PNearPerfectParentheses4

(1)

PrintP,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.

NumberNearPerfectParentheses4

14

(2)

References

  

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.

Compatibility

• 

The Iterator[NearPerfectParentheses] command was introduced in Maple 2016.

• 

For more information on Maple 2016 changes, see Updates in Maple 2016.

See Also

Iterator

Iterator[NestedParentheses]