Cantor's Enumerations (3)



; Grand finale of these few posts on Cantor's enumerations is
; enumeration of all finite sequences of natural numbers - including
; singles. Same Cantor's trick, but this time on more abstract
; level, can be used:
;
;    a11, a12, .... is enumerated list of all singles
;    a21, a22, .... is enumerated list of all pairs
;    a31, a32, .... is enumerated list of all triplets
;    ...
;    
; It doesn't matter that aij's are the result of the Cantor's enumeration;
; Same Cantor's enumeration can be applied again:
;    a11, a12, a21, a31, a22, a32 ...
;
; After such enumeration, all finite sequences will be on our list, enumerated.
;
; What might be the next step - enumerating all infinite sequences?
; Unfortunately, it is impossible.
;
; If you want to run this post as program, you need to cut and paste
; previous two posts on the beginning. Alternatively, you can simply
; read the posts and believe me about results.

(println)

(define cantors-enumeration-finite
        (lambda(n)
          (cantors-enumeration (cantors-row n) (cantors-column n))))
          
(define cantors-enumeration-finite-inverse
        (lambda()
          (let((arguments (args)))
            (cantors-enumeration-inverse (length arguments)
                                         (apply cantors-enumeration-inverse arguments)))))
                                         
; Test

(for(i1 1 45)
  (letn((i2 (cantors-enumeration-finite i1))
        (i3 (apply cantors-enumeration-finite-inverse i2)))
        (println (format "%2d" i1) " -> " i2 " -> " (format "%2d" i3))))

; The result is pretty:
        
 1 -> (1) ->  1
 2 -> (2) ->  2
 3 -> (1 1) ->  3
 4 -> (3) ->  4
 5 -> (1 2) ->  5
 6 -> (1 1 1) ->  6
 7 -> (4) ->  7
 8 -> (2 1) ->  8
 9 -> (1 1 2) ->  9
10 -> (1 1 1 1) -> 10
11 -> (5) -> 11
12 -> (1 3) -> 12
13 -> (2 1 1) -> 13
14 -> (1 1 1 2) -> 14
15 -> (1 1 1 1 1) -> 15
16 -> (6) -> 16
17 -> (2 2) -> 17
18 -> (1 2 1) -> 18
19 -> (2 1 1 1) -> 19
20 -> (1 1 1 1 2) -> 20
21 -> (1 1 1 1 1 1) -> 21
22 -> (7) -> 22
23 -> (3 1) -> 23
24 -> (2 1 2) -> 24
25 -> (1 2 1 1) -> 25
26 -> (2 1 1 1 1) -> 26
27 -> (1 1 1 1 1 2) -> 27
28 -> (1 1 1 1 1 1 1) -> 28
29 -> (8) -> 29
30 -> (1 4) -> 30
31 -> (3 1 1) -> 31
32 -> (2 1 1 2) -> 32
33 -> (1 2 1 1 1) -> 33
34 -> (2 1 1 1 1 1) -> 34
35 -> (1 1 1 1 1 1 2) -> 35
36 -> (1 1 1 1 1 1 1 1) -> 36
37 -> (9) -> 37
38 -> (2 3) -> 38
39 -> (1 1 3) -> 39
40 -> (3 1 1 1) -> 40
41 -> (2 1 1 1 2) -> 41
42 -> (1 2 1 1 1 1) -> 42
43 -> (2 1 1 1 1 1 1) -> 43
44 -> (1 1 1 1 1 1 1 2) -> 44
45 -> (1 1 1 1 1 1 1 1 1) -> 45
        

No comments:

Post a Comment