NumberTheory
CalkinWilfSequence
compute the nth term in the Calkin-Wilf sequence
Calling Sequence
Parameters
Description
Examples
Compatibility
CalkinWilfSequence(n)
n
-
positive integer
The CalkinWilfSequence function computes the nth term in the Calkin-Wilf sequence.
The vertices of the Calkin-Wilf tree are labeled with rational numbers . The root vertex is defined to be . For any vertex , its children are and .
The Calkin-Wilf sequence is obtained by breadth-first traversal of the Calkin-Wilf tree, where the lesser child is traversed first.
Every positive rational number occurs exactly once in the Calkin-Wilf tree.
The Calkin-Wilf tree and sequence for the first seven vertices.
Graphs for larger trees can be generated using the following procedure:
DrawCWTree := proc( n, { graphstyle := tree } ) local cwseq, cwgraph; cwseq := (x -> convert( x, 'string' ))~( [ seq( NumberTheory:-CalkinWilfSequence(i), i = 1 .. n ) ] ): cwgraph := GraphTheory:-Graph( { seq( { cwseq[i], cwseq[ floor( (1/2) * i ) ] }, i = 2 .. n ) } ): return GraphTheory:-DrawGraph( cwgraph, style = graphstyle ); end proc:
The NumberTheory[CalkinWilfSequence] command was introduced in Maple 2016.
For more information on Maple 2016 changes, see Updates in Maple 2016.
See Also
GraphTheory[DrawGraph]
GraphTheory[Graph]
Download Help Document