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 ab. The root vertex is defined to be 11. For any vertex ab, its children are aa+b and a+bb.
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.
with⁡NumberTheory:
CalkinWilfSequence⁡1
1
CalkinWilfSequence⁡2
12
The Calkin-Wilf tree and sequence for the first seven vertices.
cw≔GraphTheory:-Graph⁡1/1,1/2,1/1,2/1,1/2,1/3,1/2,3/2,2/1,2/3,2/1,3/1:
GraphTheory:-DrawGraph⁡cw,style=tree,root=1/1
seq⁡CalkinWilfSequence⁡n,n=1..7
1,12,2,13,32,23,3
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:
DrawCWTree⁡15
DrawCWTree⁡63,graphstyle=spring
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