annotate src/bijection.agda @ 1324:1eefc6600354

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 11 Jun 2023 18:49:13 +0900
parents 95f6216499d7
children 8b909deb840e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
1 {-# OPTIONS --allow-unsolved-metas #-}
1302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
2
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 module bijection where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
1302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
5
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 open import Level renaming ( zero to Zero ; suc to Suc )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 open import Data.Nat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import Data.Maybe
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import Data.List hiding ([_] ; sum )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import Data.Nat.Properties
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 open import Relation.Nullary
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 open import Data.Empty
1322
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
13 open import Data.Unit using ( tt ; ⊤ )
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 open import Relation.Binary.Core hiding (_⇔_)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 open import Relation.Binary.Definitions
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 open import Relation.Binary.PropositionalEquality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 open import logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 open import nat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 -- record Bijection {n m : Level} (R : Set n) (S : Set m) : Set (n Level.⊔ m) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 -- field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 -- fun← : S → R
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 -- fun→ : R → S
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
25 -- fiso← : (x : R) → fun← ( fun→ x ) ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
26 -- fiso→ : (x : S ) → fun→ ( fun← x ) ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
27 --
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 -- injection : {n m : Level} (R : Set n) (S : Set m) (f : R → S ) → Set (n Level.⊔ m)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 -- injection R S f = (x y : R) → f x ≡ f y → x ≡ y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
31 open Bijection
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 bi-trans : {n m l : Level} (R : Set n) (S : Set m) (T : Set l) → Bijection R S → Bijection S T → Bijection R T
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 bi-trans R S T rs st = record { fun← = λ x → fun← rs ( fun← st x ) ; fun→ = λ x → fun→ st ( fun→ rs x )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 ; fiso← = λ x → trans (cong (λ k → fun← rs k) (fiso← st (fun→ rs x))) ( fiso← rs x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 ; fiso→ = λ x → trans (cong (λ k → fun→ st k) (fiso→ rs (fun← st x))) ( fiso→ st x) }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 bid : {n : Level} (R : Set n) → Bijection R R
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
39 bid {n} R = record { fun← = λ x → x ; fun→ = λ x → x ; fiso← = λ _ → refl ; fiso→ = λ _ → refl }
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 bi-sym : {n m : Level} (R : Set n) (S : Set m) → Bijection R S → Bijection S R
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
42 bi-sym R S eq = record { fun← = fun→ eq ; fun→ = fun← eq ; fiso← = fiso→ eq ; fiso→ = fiso← eq }
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
1322
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
44 bi-inject← : {n m : Level} {R : Set n} {S : Set m} → (rs : Bijection R S) → {x y : S} → fun← rs x ≡ fun← rs y → x ≡ y
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
45 bi-inject← rs {x} {y} eq = subst₂ (λ j k → j ≡ k ) (fiso→ rs _) (fiso→ rs _) (cong (fun→ rs) eq)
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
46
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
47 bi-inject→ : {n m : Level} {R : Set n} {S : Set m} → (rs : Bijection R S) → {x y : R} → fun→ rs x ≡ fun→ rs y → x ≡ y
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
48 bi-inject→ rs {x} {y} eq = subst₂ (λ j k → j ≡ k ) (fiso← rs _) (fiso← rs _) (cong (fun← rs) eq)
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
49
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 open import Relation.Binary.Structures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 bijIsEquivalence : {n : Level } → IsEquivalence (Bijection {n} {n})
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 bijIsEquivalence = record { refl = λ {R} → bid R ; sym = λ {R} {S} → bi-sym R S ; trans = λ {R} {S} {T} → bi-trans R S T }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
55 -- ¬ A = A → ⊥
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 -- famous diagnostic function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 diag : {S : Set } (b : Bijection ( S → Bool ) S) → S → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 diag b n = not (fun← b n n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 diagonal : { S : Set } → ¬ Bijection ( S → Bool ) S
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 diagonal {S} b = diagn1 (fun→ b (λ n → diag b n) ) refl where
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
65 diagn1 : (n : S ) → ¬ (fun→ b (λ n → diag b n) ≡ n )
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 diagn1 n dn = ¬t=f (diag b n ) ( begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 not (diag b n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 ≡⟨⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 not (not (fun← b n n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 ≡⟨ cong (λ k → not (k n) ) (sym (fiso← b _)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 not (fun← b (fun→ b (diag b)) n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 ≡⟨ cong (λ k → not (fun← b k n) ) dn ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 not (fun← b n n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 ≡⟨⟩
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
75 diag b n
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 ∎ ) where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
78 b1 : (b : Bijection ( ℕ → Bool ) ℕ) → ℕ
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 b1 b = fun→ b (diag b)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 b-iso : (b : Bijection ( ℕ → Bool ) ℕ) → fun← b (b1 b) ≡ (diag b)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 b-iso b = fiso← b _
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 -- ℕ <=> ℕ + 1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 to1 : {n : Level} {R : Set n} → Bijection ℕ R → Bijection ℕ (⊤ ∨ R )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 to1 {n} {R} b = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 fun← = to11
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 ; fun→ = to12
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 ; fiso← = to13
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 ; fiso→ = to14
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 to11 : ⊤ ∨ R → ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 to11 (case1 tt) = 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 to11 (case2 x) = suc ( fun← b x )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 to12 : ℕ → ⊤ ∨ R
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 to12 zero = case1 tt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 to12 (suc n) = case2 ( fun→ b n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 to13 : (x : ℕ) → to11 (to12 x) ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 to13 zero = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 to13 (suc x) = cong suc (fiso← b x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 to14 : (x : ⊤ ∨ R) → to12 (to11 x) ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 to14 (case1 x) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 to14 (case2 x) = cong case2 (fiso→ b x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 open _∧_
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 record NN ( i : ℕ) (nxn→n : ℕ → ℕ → ℕ) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 j k : ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 k1 : nxn→n j k ≡ i
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
114 nn-unique : {j0 k0 : ℕ } → nxn→n j0 k0 ≡ i → ⟪ j , k ⟫ ≡ ⟪ j0 , k0 ⟫
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 i≤0→i≡0 : {i : ℕ } → i ≤ 0 → i ≡ 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 i≤0→i≡0 {0} z≤n = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 nxn : Bijection ℕ (ℕ ∧ ℕ)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 nxn = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 fun← = λ p → nxn→n (proj1 p) (proj2 p)
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
123 ; fun→ = n→nxn
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 ; fiso← = λ i → NN.k1 (nn i)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 ; fiso→ = λ x → nn-id (proj1 x) (proj2 x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 nxn→n : ℕ → ℕ → ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 nxn→n zero zero = zero
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 nxn→n zero (suc j) = j + suc (nxn→n zero j)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 nxn→n (suc i) zero = suc i + suc (nxn→n i zero)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 nxn→n (suc i) (suc j) = suc i + suc j + suc (nxn→n i (suc j))
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
132 nn : ( i : ℕ) → NN i nxn→n
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 n→nxn : ℕ → ℕ ∧ ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 n→nxn n = ⟪ NN.j (nn n) , NN.k (nn n) ⟫
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
135 k0 : {i : ℕ } → n→nxn i ≡ ⟪ NN.j (nn i) , NN.k (nn i) ⟫
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 k0 {i} = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 nxn→n0 : { j k : ℕ } → nxn→n j k ≡ 0 → ( j ≡ 0 ) ∧ ( k ≡ 0 )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 nxn→n0 {zero} {zero} eq = ⟪ refl , refl ⟫
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 nxn→n0 {zero} {(suc k)} eq = ⊥-elim ( nat-≡< (sym eq) (subst (λ k → 0 < k) (+-comm _ k) (s≤s z≤n)))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 nxn→n0 {(suc j)} {zero} eq = ⊥-elim ( nat-≡< (sym eq) (s≤s z≤n) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 nxn→n0 {(suc j)} {(suc k)} eq = ⊥-elim ( nat-≡< (sym eq) (s≤s z≤n) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 nid20 : (i : ℕ) → i + (nxn→n 0 i) ≡ nxn→n i 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 nid20 zero = refl -- suc (i + (i + suc (nxn→n 0 i))) ≡ suc (i + suc (nxn→n i 0))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 nid20 (suc i) = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 suc (i + (i + suc (nxn→n 0 i))) ≡⟨ cong (λ k → suc (i + k)) (sym (+-assoc i 1 (nxn→n 0 i))) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 suc (i + ((i + 1) + nxn→n 0 i)) ≡⟨ cong (λ k → suc (i + (k + nxn→n 0 i))) (+-comm i 1) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 suc (i + suc (i + nxn→n 0 i)) ≡⟨ cong ( λ k → suc (i + suc k)) (nid20 i) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 suc (i + suc (nxn→n i 0)) ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 nid4 : {i j : ℕ} → i + 1 + j ≡ i + suc j
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 nid4 {zero} {j} = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 nid4 {suc i} {j} = cong suc (nid4 {i} {j} )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 nid5 : {i j k : ℕ} → i + suc (suc j) + suc k ≡ i + suc j + suc (suc k )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 nid5 {zero} {j} {k} = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 suc (suc j) + suc k ≡⟨ +-assoc 1 (suc j) _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 1 + (suc j + suc k) ≡⟨ +-comm 1 _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 (suc j + suc k) + 1 ≡⟨ +-assoc (suc j) (suc k) _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 suc j + (suc k + 1) ≡⟨ cong (λ k → suc j + k ) (+-comm (suc k) 1) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 suc j + suc (suc k) ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 nid5 {suc i} {j} {k} = cong suc (nid5 {i} {j} {k} )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 -- increment in the same stage
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
165 nid2 : (i j : ℕ) → suc (nxn→n i (suc j)) ≡ nxn→n (suc i) j
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 nid2 zero zero = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 nid2 zero (suc j) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 nid2 (suc i) zero = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 suc (nxn→n (suc i) 1) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 suc (suc (i + 1 + suc (nxn→n i 1))) ≡⟨ cong (λ k → suc (suc k)) nid4 ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 suc (suc (i + suc (suc (nxn→n i 1)))) ≡⟨ cong (λ k → suc (suc (i + suc (suc k)))) (nid3 i) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 suc (suc (i + suc (suc (i + suc (nxn→n i 0))))) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 nxn→n (suc (suc i)) zero ∎ where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 nid3 : (i : ℕ) → nxn→n i 1 ≡ i + suc (nxn→n i 0)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 nid3 zero = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 nid3 (suc i) = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 suc (i + 1 + suc (nxn→n i 1)) ≡⟨ cong suc nid4 ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 suc (i + suc (suc (nxn→n i 1))) ≡⟨ cong (λ k → suc (i + suc (suc k))) (nid3 i) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 suc (i + suc (suc (i + suc (nxn→n i 0)))) ∎
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 nid2 (suc i) (suc j) = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 suc (nxn→n (suc i) (suc (suc j))) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 suc (suc (i + suc (suc j) + suc (nxn→n i (suc (suc j))))) ≡⟨ cong (λ k → suc (suc (i + suc (suc j) + k))) (nid2 i (suc j)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 suc (suc (i + suc (suc j) + suc (i + suc j + suc (nxn→n i (suc j))))) ≡⟨ cong ( λ k → suc (suc k)) nid5 ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 suc (suc (i + suc j + suc (suc (i + suc j + suc (nxn→n i (suc j)))))) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 nxn→n (suc (suc i)) (suc j) ∎ where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 -- increment the stage
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
190 nid00 : (i : ℕ) → suc (nxn→n i 0) ≡ nxn→n 0 (suc i)
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 nid00 zero = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 nid00 (suc i) = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 suc (suc (i + suc (nxn→n i 0))) ≡⟨ cong (λ k → suc (suc (i + k ))) (nid00 i) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 suc (suc (i + (nxn→n 0 (suc i)))) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 suc (suc (i + (i + suc (nxn→n 0 i)))) ≡⟨ cong suc (sym ( +-assoc 1 i (i + suc (nxn→n 0 i)))) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 suc ((1 + i) + (i + suc (nxn→n 0 i))) ≡⟨ cong (λ k → suc (k + (i + suc (nxn→n 0 i)))) (+-comm 1 i) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 suc ((i + 1) + (i + suc (nxn→n 0 i))) ≡⟨ cong suc (+-assoc i 1 (i + suc (nxn→n 0 i))) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 suc (i + suc (i + suc (nxn→n 0 i))) ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 -----
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 -- create the invariant NN for all n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 --
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
204 nn zero = record { j = 0 ; k = 0 ; k1 = refl
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 ; nn-unique = λ {j0} {k0} eq → cong₂ (λ x y → ⟪ x , y ⟫) (sym (proj1 (nxn→n0 eq))) (sym (proj2 (nxn→n0 {j0} {k0} eq))) }
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
206 nn (suc i) with NN.k (nn i) | inspect NN.k (nn i)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
207 ... | zero | record { eq = eq } = record { k = suc (sum ) ; j = 0
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 ; k1 = nn02 ; nn-unique = nn04 } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 ---
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 --- increment the stage
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 ---
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 sum = NN.j (nn i) + NN.k (nn i)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 stage = minus i (NN.j (nn i))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 j = NN.j (nn i)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 NNnn : NN.j (nn i) + NN.k (nn i) ≡ sum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 NNnn = sym refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 nn02 : nxn→n 0 (suc sum) ≡ suc i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 nn02 = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 sum + suc (nxn→n 0 sum) ≡⟨ sym (+-assoc sum 1 (nxn→n 0 sum)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 (sum + 1) + nxn→n 0 sum ≡⟨ cong (λ k → k + nxn→n 0 sum ) (+-comm sum 1 )⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 suc (sum + nxn→n 0 sum) ≡⟨ cong suc (nid20 sum ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 suc (nxn→n sum 0) ≡⟨ cong (λ k → suc (nxn→n k 0 )) (sym (NNnn )) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 suc (nxn→n (NN.j (nn i) + (NN.k (nn i)) ) 0) ≡⟨ cong₂ (λ j k → suc (nxn→n (NN.j (nn i) + j) k )) eq (sym eq) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 suc (nxn→n (NN.j (nn i) + 0 ) (NN.k (nn i))) ≡⟨ cong (λ k → suc ( nxn→n k (NN.k (nn i)))) (+-comm (NN.j (nn i)) 0) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 suc (nxn→n (NN.j (nn i)) (NN.k (nn i))) ≡⟨ cong suc (NN.k1 (nn i) ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 suc i ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 nn04 : {j0 k0 : ℕ} → nxn→n j0 k0 ≡ suc i → ⟪ 0 , suc (sum ) ⟫ ≡ ⟪ j0 , k0 ⟫
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
228 nn04 {zero} {suc k0} eq1 = cong (λ k → ⟪ 0 , k ⟫ ) (cong suc (sym nn08)) where -- eq : nxn→n zero (suc k0) ≡ suc i --
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 nn07 : nxn→n k0 0 ≡ i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 nn07 = cong pred ( begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 suc ( nxn→n k0 0 ) ≡⟨ nid00 k0 ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 nxn→n 0 (suc k0 ) ≡⟨ eq1 ⟩
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
233 suc i ∎ ) where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
234 nn08 : k0 ≡ sum
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 nn08 = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 k0 ≡⟨ cong proj1 (sym (NN.nn-unique (nn i) nn07)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 NN.j (nn i) ≡⟨ +-comm 0 _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 NN.j (nn i) + 0 ≡⟨ cong (λ k → NN.j (nn i) + k) (sym eq) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 NN.j (nn i) + NN.k (nn i) ≡⟨ NNnn ⟩
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
240 sum ∎ where open ≡-Reasoning
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 nn04 {suc j0} {k0} eq1 = ⊥-elim ( nat-≡< (cong proj2 (nn06 nn05)) (subst (λ k → k < suc k0) (sym eq) (s≤s z≤n))) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 nn05 : nxn→n j0 (suc k0) ≡ i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 nn05 = begin
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
244 nxn→n j0 (suc k0) ≡⟨ cong pred ( begin
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 suc (nxn→n j0 (suc k0)) ≡⟨ nid2 j0 k0 ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 nxn→n (suc j0) k0 ≡⟨ eq1 ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 suc i ∎ ) ⟩
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
248 i ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
249 nn06 : nxn→n j0 (suc k0) ≡ i → ⟪ NN.j (nn i) , NN.k (nn i) ⟫ ≡ ⟪ j0 , suc k0 ⟫
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 nn06 = NN.nn-unique (nn i)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 ... | suc k | record {eq = eq} = record { k = k ; j = suc (NN.j (nn i)) ; k1 = nn11 ; nn-unique = nn13 } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 ---
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 --- increment in a stage
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 ---
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 sum = NN.j (nn i) + NN.k (nn i)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 stage = minus i (NN.j (nn i))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 j = NN.j (nn i)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 NNnn : NN.j (nn i) + NN.k (nn i) ≡ sum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 NNnn = sym refl
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
260 nn10 : suc (NN.j (nn i)) + k ≡ sum
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 nn10 = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 suc (NN.j (nn i)) + k ≡⟨ cong (λ x → x + k) (+-comm 1 _) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 (NN.j (nn i) + 1) + k ≡⟨ +-assoc (NN.j (nn i)) 1 k ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 NN.j (nn i) + suc k ≡⟨ cong (λ k → NN.j (nn i) + k) (sym eq) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 NN.j (nn i) + NN.k (nn i) ≡⟨ NNnn ⟩
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
266 sum ∎ where open ≡-Reasoning
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 nn11 : nxn→n (suc (NN.j (nn i))) k ≡ suc i -- nxn→n ( NN.j (nn i)) (NN.k (nn i) ≡ i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 nn11 = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 nxn→n (suc (NN.j (nn i))) k ≡⟨ sym (nid2 (NN.j (nn i)) k) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 suc (nxn→n (NN.j (nn i)) (suc k)) ≡⟨ cong (λ k → suc (nxn→n (NN.j (nn i)) k)) (sym eq) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 suc (nxn→n ( NN.j (nn i)) (NN.k (nn i))) ≡⟨ cong suc (NN.k1 (nn i)) ⟩
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
272 suc i ∎ where open ≡-Reasoning
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 nn18 : zero < NN.k (nn i)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 nn18 = subst (λ k → 0 < k ) ( begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 suc k ≡⟨ sym eq ⟩
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
276 NN.k (nn i) ∎ ) (s≤s z≤n ) where open ≡-Reasoning
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 nn13 : {j0 k0 : ℕ} → nxn→n j0 k0 ≡ suc i → ⟪ suc (NN.j (nn i)) , k ⟫ ≡ ⟪ j0 , k0 ⟫
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 nn13 {zero} {suc k0} eq1 = ⊥-elim ( nat-≡< (sym (cong proj2 nn17)) nn18 ) where -- (nxn→n zero (suc k0)) ≡ suc i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 nn16 : nxn→n k0 zero ≡ i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 nn16 = cong pred ( subst (λ k → k ≡ suc i) (sym ( nid00 k0 )) eq1 )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 nn17 : ⟪ NN.j (nn i) , NN.k (nn i) ⟫ ≡ ⟪ k0 , zero ⟫
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 nn17 = NN.nn-unique (nn i) nn16
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 nn13 {suc j0} {k0} eq1 = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 ⟪ suc (NN.j (nn i)) , pred (suc k) ⟫ ≡⟨ cong (λ k → ⟪ suc (NN.j (nn i)) , pred k ⟫ ) (sym eq) ⟩
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
285 ⟪ suc (NN.j (nn i)) , pred (NN.k (nn i)) ⟫ ≡⟨ cong (λ k → ⟪ suc (proj1 k) , pred (proj2 k) ⟫) ( begin
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 ⟪ NN.j (nn i) , NN.k (nn i) ⟫ ≡⟨ nn15 ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 ⟪ j0 , suc k0 ⟫ ∎ ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 ⟪ suc j0 , k0 ⟫ ∎ where -- nxn→n (suc j0) k0 ≡ suc i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 nn14 : nxn→n j0 (suc k0) ≡ i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 nn14 = cong pred ( subst (λ k → k ≡ suc i) (sym ( nid2 j0 k0 )) eq1 )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 nn15 : ⟪ NN.j (nn i) , NN.k (nn i) ⟫ ≡ ⟪ j0 , suc k0 ⟫
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 nn15 = NN.nn-unique (nn i) nn14
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 nn-id : (j k : ℕ) → n→nxn (nxn→n j k) ≡ ⟪ j , k ⟫
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 nn-id j k = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 n→nxn (nxn→n j k) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 ⟪ NN.j (nn (nxn→n j k)) , NN.k (nn (nxn→n j k)) ⟫ ≡⟨ NN.nn-unique (nn (nxn→n j k)) refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 ⟪ j , k ⟫ ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 -- [] 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 -- 0 → 1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 -- 1 → 2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 -- 01 → 3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 -- 11 → 4
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 -- ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 -- binary invariant
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 record LB (n : ℕ) (lton : List Bool → ℕ ) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 nlist : List Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 isBin : lton nlist ≡ n
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
316 isUnique : (x : List Bool) → lton x ≡ n → nlist ≡ x
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 lb+1 : List Bool → List Bool
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
319 lb+1 [] = false ∷ []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
320 lb+1 (false ∷ t) = true ∷ t
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 lb+1 (true ∷ t) = false ∷ lb+1 t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 lb-1 : List Bool → List Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 lb-1 [] = []
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
325 lb-1 (true ∷ t) = false ∷ t
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 lb-1 (false ∷ t) with lb-1 t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 ... | [] = true ∷ []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 ... | x ∷ t1 = true ∷ x ∷ t1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
330 LBℕ : Bijection ℕ ( List Bool )
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 LBℕ = record {
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
332 fun← = λ x → lton x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
333 ; fun→ = λ n → LB.nlist (lb n)
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 ; fiso← = λ n → LB.isBin (lb n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 ; fiso→ = λ x → LB.isUnique (lb (lton x)) x refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 lton1 : List Bool → ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 lton1 [] = 1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 lton1 (true ∷ t) = suc (lton1 t + lton1 t)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 lton1 (false ∷ t) = lton1 t + lton1 t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 lton : List Bool → ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 lton x = pred (lton1 x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
343
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
344 lton1>0 : (x : List Bool ) → 0 < lton1 x
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 lton1>0 [] = a<sa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 lton1>0 (true ∷ x₁) = 0<s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 lton1>0 (false ∷ t) = ≤-trans (lton1>0 t) x≤x+y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
348
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 2lton1>0 : (t : List Bool ) → 0 < lton1 t + lton1 t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 2lton1>0 t = ≤-trans (lton1>0 t) x≤x+y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
351
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 lb=3 : {x y : ℕ} → 0 < x → 0 < y → 1 ≤ pred (x + y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 lb=3 {suc x} {suc y} (s≤s 0<x) (s≤s 0<y) = subst (λ k → 1 ≤ k ) (+-comm (suc y) _ ) (s≤s z≤n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
354
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 lton-cons>0 : {x : Bool} {y : List Bool } → 0 < lton (x ∷ y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 lton-cons>0 {true} {[]} = refl-≤s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 lton-cons>0 {true} {x ∷ y} = ≤-trans ( lb=3 (lton1>0 (x ∷ y)) (lton1>0 (x ∷ y))) px≤x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 lton-cons>0 {false} {[]} = refl-≤
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 lton-cons>0 {false} {x ∷ y} = lb=3 (lton1>0 (x ∷ y)) (lton1>0 (x ∷ y))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 lb=0 : {x y : ℕ } → pred x < pred y → suc (x + x ∸ 1) < suc (y + y ∸ 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 lb=0 {0} {suc y} lt = s≤s (subst (λ k → 0 < k ) (+-comm (suc y) y ) 0<s)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 lb=0 {suc x} {suc y} lt = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 suc (suc ((suc x + suc x) ∸ 1)) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 suc (suc x) + suc x ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 suc (suc x + suc x) ≤⟨ <-plus (s≤s lt) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 suc y + suc x <⟨ <-plus-0 {suc x} {suc y} {suc y} (s≤s lt) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 suc y + suc y ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 suc ((suc y + suc y) ∸ 1) ∎ where open ≤-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 lb=2 : {x y : ℕ } → pred x < pred y → suc (x + x ) < suc (y + y )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 lb=2 {zero} {suc y} lt = s≤s 0<s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 lb=2 {suc x} {suc y} lt = s≤s (lb=0 {suc x} {suc y} lt)
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
373 lb=1 : {x y : List Bool} {z : Bool} → lton (z ∷ x) ≡ lton (z ∷ y) → lton x ≡ lton y
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 lb=1 {x} {y} {true} eq with <-cmp (lton x) (lton y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 ... | tri< a ¬b ¬c = ⊥-elim (nat-≡< (cong suc eq) (lb=2 {lton1 x} {lton1 y} a))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 ... | tri≈ ¬a b ¬c = b
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 ... | tri> ¬a ¬b c = ⊥-elim (nat-≡< (cong suc (sym eq)) (lb=2 {lton1 y} {lton1 x} c))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 lb=1 {x} {y} {false} eq with <-cmp (lton x) (lton y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 ... | tri< a ¬b ¬c = ⊥-elim (nat-≡< (cong suc eq) (lb=0 {lton1 x} {lton1 y} a))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 ... | tri≈ ¬a b ¬c = b
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 ... | tri> ¬a ¬b c = ⊥-elim (nat-≡< (cong suc (sym eq)) (lb=0 {lton1 y} {lton1 x} c))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
382
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 ---
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 --- lton is unique in a head
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 ---
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 lb-tf : {x y : List Bool } → ¬ (lton (true ∷ x) ≡ lton (false ∷ y))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 lb-tf {x} {y} eq with <-cmp (lton1 x) (lton1 y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 ... | tri< a ¬b ¬c = ⊥-elim ( nat-≡< eq (lb=01 a)) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 lb=01 : {x y : ℕ } → x < y → x + x < (y + y ∸ 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 lb=01 {x} {y} x<y = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 suc (x + x) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 suc x + x ≤⟨ ≤-plus x<y ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 y + x ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 pred (suc y + x) ≡⟨ cong (λ k → pred ( k + x)) (+-comm 1 y) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 pred ((y + 1) + x ) ≡⟨ cong pred (+-assoc y 1 x) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 pred (y + suc x) ≤⟨ px≤py (≤-plus-0 {suc x} {y} {y} x<y) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 (y + y) ∸ 1 ∎ where open ≤-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 ... | tri> ¬a ¬b c = ⊥-elim ( nat-≡< (sym eq) (lb=02 c) ) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 lb=02 : {x y : ℕ } → x < y → x + x ∸ 1 < y + y
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
400 lb=02 {0} {y} lt = ≤-trans lt x≤x+y
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 lb=02 {suc x} {y} lt = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 suc ( suc x + suc x ∸ 1 ) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 suc x + suc x ≤⟨ ≤-plus {suc x} (<to≤ lt) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 y + suc x ≤⟨ ≤-plus-0 (<to≤ lt) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 y + y ∎ where open ≤-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 ... | tri≈ ¬a b ¬c = ⊥-elim ( nat-≡< (sym eq) ( begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 suc (lton1 y + lton1 y ∸ 1) ≡⟨ sucprd ( 2lton1>0 y) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 lton1 y + lton1 y ≡⟨ cong (λ k → k + k ) (sym b) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 lton1 x + lton1 x ∎ )) where open ≤-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
410
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 ---
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 --- lton injection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 ---
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 lb=b : (x y : List Bool) → lton x ≡ lton y → x ≡ y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 lb=b [] [] eq = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 lb=b [] (x ∷ y) eq = ⊥-elim ( nat-≡< eq (lton-cons>0 {x} {y} ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 lb=b (x ∷ y) [] eq = ⊥-elim ( nat-≡< (sym eq) (lton-cons>0 {x} {y} ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 lb=b (true ∷ x) (false ∷ y) eq = ⊥-elim ( lb-tf {x} {y} eq )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 lb=b (false ∷ x) (true ∷ y) eq = ⊥-elim ( lb-tf {y} {x} (sym eq) )
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
420 lb=b (true ∷ x) (true ∷ y) eq = cong (λ k → true ∷ k ) (lb=b x y (lb=1 {x} {y} {true} eq))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
421 lb=b (false ∷ x) (false ∷ y) eq = cong (λ k → false ∷ k ) (lb=b x y (lb=1 {x} {y} {false} eq))
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
422
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 lb : (n : ℕ) → LB n lton
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 lb zero = record { nlist = [] ; isBin = refl ; isUnique = lb05 } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 lb05 : (x : List Bool) → lton x ≡ zero → [] ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 lb05 x eq = lb=b [] x (sym eq)
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
427 lb (suc n) with LB.nlist (lb n) | inspect LB.nlist (lb n)
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 ... | [] | record { eq = eq } = record { nlist = false ∷ [] ; isUnique = lb06 ; isBin = lb10 } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 lb10 : lton1 (false ∷ []) ∸ 1 ≡ suc n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 lb10 = begin
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
432 lton (false ∷ []) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
433 suc 0 ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
434 suc (lton []) ≡⟨ cong (λ k → suc (lton k)) (sym eq) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
435 suc (lton (LB.nlist (lb n))) ≡⟨ cong suc (LB.isBin (lb n) ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
436 suc n ∎
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 lb06 : (x : List Bool) → pred (lton1 x ) ≡ suc n → false ∷ [] ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 lb06 x eq1 = lb=b (false ∷ []) x (trans lb10 (sym eq1)) -- lton (false ∷ []) ≡ lton x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 ... | false ∷ t | record { eq = eq } = record { nlist = true ∷ t ; isBin = lb01 ; isUnique = lb09 } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 lb01 : lton (true ∷ t) ≡ suc n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 lb01 = begin
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
442 lton (true ∷ t) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
443 lton1 t + lton1 t ≡⟨ sym ( sucprd (2lton1>0 t) ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
444 suc (pred (lton1 t + lton1 t )) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
445 suc (lton (false ∷ t)) ≡⟨ cong (λ k → suc (lton k )) (sym eq) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
446 suc (lton (LB.nlist (lb n))) ≡⟨ cong suc (LB.isBin (lb n)) ⟩
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 suc n ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 lb09 : (x : List Bool) → lton1 x ∸ 1 ≡ suc n → true ∷ t ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 lb09 x eq1 = lb=b (true ∷ t) x (trans lb01 (sym eq1) ) -- lton (true ∷ t) ≡ lton x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 ... | true ∷ t | record { eq = eq } = record { nlist = lb+1 (true ∷ t) ; isBin = lb02 (true ∷ t) lb03 ; isUnique = lb07 } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 lb03 : lton (true ∷ t) ≡ n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 lb03 = begin
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
453 lton (true ∷ t) ≡⟨ cong (λ k → lton k ) (sym eq ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
454 lton (LB.nlist (lb n)) ≡⟨ LB.isBin (lb n) ⟩
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 n ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
456
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 add11 : (x1 : ℕ ) → suc x1 + suc x1 ≡ suc (suc (x1 + x1))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 add11 zero = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 add11 (suc x) = cong (λ k → suc (suc k)) (trans (+-comm x _) (cong suc (+-comm _ x)))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
460
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
461 lb04 : (t : List Bool) → suc (lton1 t) ≡ lton1 (lb+1 t)
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 lb04 [] = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 lb04 (false ∷ t) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 lb04 (true ∷ []) = refl
1309
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
465 lb04 (true ∷ t0 @ (_ ∷ _)) = begin
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
466 suc (suc (lton1 t0 + lton1 t0)) ≡⟨ sym (add11 (lton1 t0)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
467 suc (lton1 t0) + suc (lton1 t0) ≡⟨ cong (λ k → k + k ) (lb04 t0 ) ⟩
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 lton1 (lb+1 t0) + lton1 (lb+1 t0) ∎ where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
470
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 lb02 : (t : List Bool) → lton t ≡ n → lton (lb+1 t) ≡ suc n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 lb02 [] refl = refl
1309
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
473 lb02 (t @ (_ ∷ _)) eq1 = begin
1283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 lton (lb+1 t) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 pred (lton1 (lb+1 t)) ≡⟨ cong pred (sym (lb04 t)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 pred (suc (lton1 t)) ≡⟨ sym (sucprd (lton1>0 t)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 suc (pred (lton1 t)) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 suc (lton t) ≡⟨ cong suc eq1 ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 suc n ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
480
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 lb07 : (x : List Bool) → pred (lton1 x ) ≡ suc n → lb+1 (true ∷ t) ≡ x
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
482 lb07 x eq1 = lb=b (lb+1 (true ∷ t)) x (trans ( lb02 (true ∷ t) lb03 ) (sym eq1))
1302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
483
1303
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
484 -- Bernstein is non constructive, so we cannot use this without some assumption
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
485 -- but in case of ℕ, we can construct it directly.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
486
1322
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
487 open import Data.Product
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
488 open import Relation.Nary using (⌊_⌋)
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
489 open import Relation.Nullary.Decidable hiding (⌊_⌋)
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
490 open import Data.Unit.Base using (⊤ ; tt)
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
491 open import Data.List.Fresh hiding ([_])
1323
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
492 open import Data.List.Fresh.Relation.Unary.Any
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
493 open import Data.List.Fresh.Relation.Unary.All
1322
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
494
1303
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
495 record InjectiveF (A B : Set) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
496 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
497 f : A → B
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
498 inject : {x y : A} → f x ≡ f y → x ≡ y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
499
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
500 record Is (A C : Set) (f : A → C) (c : C) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
501 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
502 a : A
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
503 fa=c : f a ≡ c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
504
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
505 Countable-Bernstein : (A B C : Set) → Bijection A ℕ → Bijection C ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
506 → (fi : InjectiveF A B ) → (gi : InjectiveF B C )
1303
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
507 → (is-A : (c : C ) → Dec (Is A C (λ x → (InjectiveF.f gi (InjectiveF.f fi x))) c )) → (is-B : (c : C ) → Dec (Is B C (InjectiveF.f gi) c) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
508 → Bijection B ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
509 Countable-Bernstein A B C an cn fi gi is-A is-B = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
510 fun→ = λ x → bton x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
511 ; fun← = λ n → ntob n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
512 ; fiso→ = λ n → ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
513 ; fiso← = λ x → ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
514 } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
515 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
516 -- an f g cn
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
517 -- ℕ → A → B → C → ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
518 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
519 open Bijection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
520 f = InjectiveF.f fi
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
521 g = InjectiveF.f gi
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
522
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
523 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
524 -- count number of valid A and B in C
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
525 -- the count of B is the numner of B in Bijection B ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
526 -- if we have a , number a of A is larger than the numner of B C, so we have the inverse
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
527 --
1309
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
528
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
529 count-B : ℕ → ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
530 count-B zero with is-B (fun← cn zero)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
531 ... | yes isb = 1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
532 ... | no nisb = 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
533 count-B (suc n) with is-B (fun← cn (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
534 ... | yes isb = suc (count-B n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
535 ... | no nisb = count-B n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
536
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
537 bton : B → ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
538 bton b = count-B (fun→ cn (g b))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
539
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
540 count-A : ℕ → ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
541 count-A zero with is-A (fun← cn zero)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
542 ... | yes isb = 1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
543 ... | no nisb = 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
544 count-A (suc n) with is-A (fun← cn (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
545 ... | yes isb = suc (count-A n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
546 ... | no nisb = count-A n
1303
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
547
1321
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
548 count-A-homo : {i j : ℕ} → i ≤ j → count-A i ≤ count-A j
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
549 count-A-homo {i} {j} i≤j with ≤-∨ i≤j
1313
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
550 ... | case1 refl = ≤-refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
551 ... | case2 i<j = lem00 _ _ i<j where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
552 lem00 : (i j : ℕ) → i < j → count-A i ≤ count-A j
1321
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
553 lem00 i (suc j) (s≤s i<j) = ≤-trans (count-A-homo i<j) (lem01 j) where
1313
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
554 lem01 : (j : ℕ) → count-A j ≤ count-A (suc j)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
555 lem01 zero with is-A (fun← cn (suc zero))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
556 ... | yes isb = refl-≤s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
557 ... | no nisb = ≤-refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
558 lem01 (suc n) with is-A (fun← cn (suc (suc n)))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
559 ... | yes isb = refl-≤s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
560 ... | no nisb = ≤-refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
561
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
562 count-A<i : (i : ℕ) → count-A i ≤ suc i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
563 count-A<i zero with is-A (fun← cn zero) | inspect ( count-A ) zero
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
564 ... | yes isa | record { eq = eq1 } = ≤-refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
565 ... | no nisa | record { eq = eq1 } = refl-≤s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
566 count-A<i (suc i) with is-A (fun← cn (suc i)) | inspect ( count-A ) (suc i)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
567 ... | yes isa | record { eq = eq1 } = s≤s ( count-A<i i )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
568 ... | no nisa | record { eq = eq1 } = ≤-trans (count-A<i i ) refl-≤s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
569
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
570 full-a : (i : ℕ) → i < count-A i → Is A C (λ x → g (f x)) (fun← cn i)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
571 full-a zero i<ci with is-A (fun← cn zero) | inspect ( count-A ) zero
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
572 ... | yes isa | record { eq = eq1 } = isa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
573 ... | no nisa | record { eq = eq1 } = ⊥-elim ( nat-≡< refl i<ci )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
574 full-a (suc i) i<ci with is-A (fun← cn (suc i)) | inspect ( count-A ) (suc i)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
575 ... | yes isa | record { eq = eq1 } = isa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
576 ... | no nisa | record { eq = eq1 } = ⊥-elim ( nat-≤> (≤-trans lem36 lem39) a<sa ) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
577 lem36 : suc (suc i) ≤ count-A i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
578 lem36 = i<ci
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
579 lem39 : count-A i ≤ suc i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
580 lem39 = count-A<i i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
581
1303
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
582 ¬isA∧isB : (y : C ) → Is A C (λ x → g ( f x)) y → ¬ Is B C g y → ⊥
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
583 ¬isA∧isB y isa nisb = ⊥-elim ( nisb record { a = f (Is.a isa) ; fa=c = lem } ) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
584 lem : g (f (Is.a isa)) ≡ y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
585 lem = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
586 g (f (Is.a isa)) ≡⟨ Is.fa=c isa ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
587 y ∎ where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
588 open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
589
1309
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
590 ca≤cb0 : (n : ℕ) → count-A n ≤ count-B n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
591 ca≤cb0 zero with is-A (fun← cn zero) | is-B (fun← cn zero)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
592 ... | yes isA | yes isB = ≤-refl
1303
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
593 ... | yes isA | no nisB = ⊥-elim ( ¬isA∧isB _ isA nisB )
1309
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
594 ... | no nisA | yes isB = px≤x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
595 ... | no nisA | no nisB = ≤-refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
596 ca≤cb0 (suc n) with is-A (fun← cn (suc n)) | is-B (fun← cn (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
597 ... | yes isA | yes isB = s≤s (ca≤cb0 n)
1304
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1303
diff changeset
598 ... | yes isA | no nisB = ⊥-elim ( ¬isA∧isB _ isA nisB )
1309
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
599 ... | no nisA | yes isB = ≤-trans (ca≤cb0 n) px≤x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
600 ... | no nisA | no nisB = ca≤cb0 n
1304
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1303
diff changeset
601
1323
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
602 data FL (n : ℕ ) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
603 ca<n : (i : ℕ) → fun→ cn (g (f (fun← an i))) < n → FL n
1322
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
604
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
605 _f<_ : {n : ℕ } (x : FL n ) (y : FL n) → Set
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
606 _f<_ {n} (ca<n i i<n) (ca<n j j<n) = fun→ cn (g (f (fun← an i))) < fun→ cn (g (f (fun← an j)))
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
607
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
608 infixr 250 _f<?_
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
609
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
610 f<-trans : {n : ℕ } { x y z : FL n } → x f< y → y f< z → x f< z
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
611 f<-trans {n} {ca<n i x} {ca<n i₁ x₁} {ca<n i₂ x₂} x<y y<z = <-trans x<y y<z
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
612
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
613 FL-eq0 : {n i j : ℕ} → {x : fun→ cn (g (f (fun← an i))) < n } {y : fun→ cn (g (f (fun← an j))) < n}
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
614 → ca<n i x ≡ ca<n j y
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
615 → fun→ cn (g (f (fun← an i))) ≡ fun→ cn (g (f (fun← an j)))
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
616 FL-eq0 {n} {i} {.i} {x} {.x} refl = refl
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
617
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
618 -- open import Relation.Binary.HeterogeneousEquality as HE using (_≅_;refl)
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
619
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
620 FL-eq1 : {n i j : ℕ} → {x : fun→ cn (g (f (fun← an i))) < n } {y : fun→ cn (g (f (fun← an j))) < n}
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
621 → fun→ cn (g (f (fun← an i))) ≡ fun→ cn (g (f (fun← an j)))
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
622 → ca<n i x ≡ ca<n j y
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
623 FL-eq1 {n} {i} {j} {x} {y} eq = lem00 i=j where
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
624 i=j : i ≡ j
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
625 i=j = bi-inject← an (InjectiveF.inject fi ( InjectiveF.inject gi (bi-inject→ cn eq) ))
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
626 lem00 : {x : fun→ cn (g (f (fun← an i))) < n } {y : fun→ cn (g (f (fun← an j))) < n} → i ≡ j → ca<n i x ≡ ca<n j y
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
627 lem00 {x} {y} refl with <-irrelevant x y
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
628 ... | refl = refl
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
629
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
630 FLcmp : {n : ℕ } → Trichotomous {Level.zero} {FL n} _≡_ _f<_
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
631 FLcmp {n} (ca<n i x) (ca<n j y) with <-cmp (fun→ cn (g (f (fun← an i)))) (fun→ cn (g (f (fun← an j))) )
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
632 ... | tri< a ¬b ¬c = tri< a (λ eq → ¬b (FL-eq0 eq) ) ¬c
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
633 ... | tri≈ ¬a eq ¬c = tri≈ ¬a (FL-eq1 eq) ¬c
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
634 ... | tri> ¬a ¬b c = tri> ¬a (λ eq → ¬b (FL-eq0 eq) ) c
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
635
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
636 _f<?_ : {n : ℕ} → (x y : FL n ) → Dec (x f< y )
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
637 _f<?_ {n} x y with FLcmp x y
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
638 ... | tri< a ¬b ¬c = yes a
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
639 ... | tri≈ ¬a b ¬c = no ¬a
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
640 ... | tri> ¬a ¬b c = no ¬a
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
641
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
642 FList : (n : ℕ ) → Set
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
643 FList n = List# (FL n) ⌊ _f<?_ ⌋
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
644
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
645 ttf : {n : ℕ } {x a : FL (n)} → x f< a → (y : FList (n)) → fresh (FL (n)) ⌊ _f<?_ ⌋ a y → fresh (FL (n)) ⌊ _f<?_ ⌋ x y
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
646 ttf _ [] fr = Level.lift tt
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
647 ttf {_} {x} {a} lt (cons a₁ y x1) (lift lt1 , x2 ) = (Level.lift (fromWitness (ttf1 lt1 lt ))) , ttf (ttf1 lt1 lt) y x1 where
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
648 ttf1 : True (a f<? a₁) → x f< a → x f< a₁
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
649 ttf1 t x<a = f<-trans x<a (toWitness t)
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
650
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
651 FLinsert : {n : ℕ } → FL n → FList n → FList n
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
652 FLfresh : {n : ℕ } → (a x : FL (suc n) ) → (y : FList (suc n) ) → a f< x
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
653 → fresh (FL (suc n)) ⌊ _f<?_ ⌋ a y → fresh (FL (suc n)) ⌊ _f<?_ ⌋ a (FLinsert x y)
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
654 FLinsert {zero} f0 y = f0 ∷# []
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
655 FLinsert {suc n} x [] = x ∷# []
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
656 FLinsert {suc n} x (cons a y x₁) with FLcmp x a
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
657 ... | tri≈ ¬a b ¬c = cons a y x₁
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
658 ... | tri< lt ¬b ¬c = cons x ( cons a y x₁) ( Level.lift (fromWitness lt ) , ttf lt y x₁)
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
659 FLinsert {suc n} x (cons a [] x₁) | tri> ¬a ¬b lt = cons a ( x ∷# [] ) ( Level.lift (fromWitness lt) , Level.lift tt )
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
660 FLinsert {suc n} x (cons a y yr) | tri> ¬a ¬b a<x = cons a (FLinsert x y) (FLfresh a x y a<x yr )
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
661
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
662 FLfresh a x [] a<x (Level.lift tt) = Level.lift (fromWitness a<x) , Level.lift tt
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
663 FLfresh a x (cons b [] (Level.lift tt)) a<x (Level.lift a<b , a<y) with FLcmp x b
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
664 ... | tri< x<b ¬b ¬c = Level.lift (fromWitness a<x) , Level.lift a<b , Level.lift tt
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
665 ... | tri≈ ¬a refl ¬c = Level.lift (fromWitness a<x) , Level.lift tt
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
666 ... | tri> ¬a ¬b b<x = Level.lift a<b , Level.lift (fromWitness (f<-trans (toWitness a<b) b<x)) , Level.lift tt
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
667 FLfresh a x (cons b y br) a<x (Level.lift a<b , a<y) with FLcmp x b
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
668 ... | tri< x<b ¬b ¬c = Level.lift (fromWitness a<x) , Level.lift a<b , ttf (toWitness a<b) y br
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
669 ... | tri≈ ¬a refl ¬c = Level.lift (fromWitness a<x) , ttf a<x y br
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
670 FLfresh a x (cons b [] br) a<x (Level.lift a<b , a<y) | tri> ¬a ¬b b<x =
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
671 Level.lift a<b , Level.lift (fromWitness (f<-trans (toWitness a<b) b<x)) , Level.lift tt
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
672 FLfresh a x (cons b (cons a₁ y x₁) br) a<x (Level.lift a<b , a<y) | tri> ¬a ¬b b<x =
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
673 Level.lift a<b , FLfresh a x (cons a₁ y x₁) a<x a<y
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
674
1323
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
675 x∈FLins : {n : ℕ} → (x : FL n ) → (xs : FList n) → Any (x ≡_) (FLinsert x xs)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
676 x∈FLins {zero} f0 [] = here refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
677 x∈FLins {zero} f0 (cons f1 xs x) = here refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
678 x∈FLins {suc n} x [] = here refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
679 x∈FLins {suc n} x (cons a xs x₁) with FLcmp x a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
680 ... | tri< x<a ¬b ¬c = here refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
681 ... | tri≈ ¬a b ¬c = here b
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
682 x∈FLins {suc n} x (cons a [] x₁) | tri> ¬a ¬b a<x = there ( here refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
683 x∈FLins {suc n} x (cons a (cons a₁ xs x₂) x₁) | tri> ¬a ¬b a<x = there ( x∈FLins x (cons a₁ xs x₂) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
684
1311
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1310
diff changeset
685 record maxAC (n : ℕ) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1310
diff changeset
686 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1310
diff changeset
687 ac : ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1310
diff changeset
688 n<ca : n < count-A ac
1318
579f1bf9122c include all A less than n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1315
diff changeset
689 all-a : (i : ℕ) → i ≤ n → fun→ cn (g (f (fun← an i))) ≤ ac
1311
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1310
diff changeset
690
1323
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
691 fla-max : (n : ℕ) → ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
692 fla-max zero = fun→ cn (g (f (fun← an zero)))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
693 fla-max (suc n) = max (fun→ cn (g (f (fun← an (suc n))))) (fla-max n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
694
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
695 fla-max< : (i n : ℕ) → i < suc n → fun→ cn (g (f (fun← an i))) < fla-max n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
696 fla-max< zero n i≤n = ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
697 fla-max< (suc i) n i≤n = ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
698
1324
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
699 fla0 : (i n : ℕ ) → i < suc n → FList (fla-max n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
700 fla0 zero n lt = FLinsert fl0 [] where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
701 fl0 : FL (fla-max n )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
702 fl0 = ca<n zero (fla-max< zero n 0<s )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
703 fla0 (suc i) n (s≤s lt) = FLinsert fl0 fl1 where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
704 fl0 : FL (fla-max n )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
705 fl0 = ca<n (suc i) (fla-max< (suc i) n ? )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
706 fl1 = fla0 i n (≤-trans refl-≤s (s≤s lt))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
707 fla : (n : ℕ) → FList (fla-max n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
708 fla n = fla0 n n a<sa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
709
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
710 record FLany (n : ℕ ) : Set where
1323
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
711 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
712 flist : FList (fla-max n)
1324
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
713 flany : (i : ℕ) → (i<n : i < suc n ) → Any ( ca<n i (fla-max< i n i<n ) ≡_) flist
1323
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
714
1324
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
715 flany : (n : ℕ) → FLany n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
716 flany n = record { flist = fla0 n n a<sa ; flany = ? } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
717 flany0 : (i : ℕ) → (i<n : i < suc n ) → Any ( ca<n i (fla-max< i n i<n ) ≡_) (fla0 i n i<n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
718 flany0 zero i<n = fl1 where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
719 fl0 = ca<n zero (fla-max< zero n 0<s )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
720 fl1 = x∈FLins fl0 []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
721 flany0 (suc i) (s≤s i<n) = fl3 where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
722 fl0 : FL (fla-max n )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
723 fl0 = ca<n (suc i) (fla-max< (suc i) n ? )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
724 fl1 = fla0 i n (≤-trans refl-≤s (s≤s i<n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
725 fl3 = x∈FLins fl0 fl1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
726 fl4 : Any ( ca<n i (fla-max< i n (≤-trans refl-≤s (s≤s i<n)) ) ≡_) (fla0 i n (≤-trans refl-≤s (s≤s i<n)))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
727 fl4 = flany0 i (≤-trans refl-≤s (s≤s i<n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1323
diff changeset
728
1323
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1322
diff changeset
729
1311
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1310
diff changeset
730 lem02 : (n : ℕ) → maxAC n
1312
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1311
diff changeset
731 lem02 n = lem03 n where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1311
diff changeset
732 lem03 : (i : ℕ) → maxAC i
1313
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
733 lem03 i = lem10 i where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
734 lem10 : (j : ℕ) → maxAC j
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1312
diff changeset
735 lem10 zero = lem12 _ refl where
1312
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1311
diff changeset
736 lem12 : (i : ℕ) → i ≡ fun→ cn (g (f (fun← an zero))) → maxAC zero
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1311
diff changeset
737 lem12 zero i=z with is-A (fun← cn zero) | inspect ( count-A ) zero
1318
579f1bf9122c include all A less than n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1315
diff changeset
738 ... | yes isa | record { eq = eq1 } = record { ac = zero ; n<ca = subst (λ k → 0 < k) (sym eq1) (s≤s z≤n) ; all-a = ? }
1312
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1311
diff changeset
739 ... | no nisa | record { eq = eq1 } = ⊥-elim ( nisa record { a = fun← an 0 ; fa=c = trans (sym (fiso← cn _)) (sym (cong (fun← cn) i=z)) } )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1311
diff changeset
740 lem12 (suc i) i=z with is-A (fun← cn (suc i)) | inspect ( count-A ) (suc i)
1318
579f1bf9122c include all A less than n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1315
diff changeset
741 ... | yes isa | record { eq = eq1 } = record { ac = suc i ; n<ca = subst (λ k → 0 < k) (sym eq1) 0<s ; all-a = ? }
1312
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1311
diff changeset
742 ... | no nisa | record { eq = eq1 } = ⊥-elim ( nisa record { a = fun← an zero ; fa=c = trans (sym (fiso← cn _)) (sym (cong (fun← cn) i=z)) } )
1322
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
743 lem10 (suc j) = record { ac = max (fun→ cn (g (f (fun← an (suc j))))) (maxAC.ac (lem10 j)) ; n<ca = ? ; all-a = ? } where
1321
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
744
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
745 fan = fun→ cn (g (f (fun← an (suc j))))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
746 ac = maxAC.ac (lem10 j)
1319
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1318
diff changeset
747 nac : ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1318
diff changeset
748 nac = max (fun→ cn (g (f (fun← an (suc j))))) (maxAC.ac (lem10 j))
1321
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
749
1320
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
750 n<ca : suc j < count-A nac
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
751 n<ca = ? where
1321
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
752 n<ca0 : j < count-A (maxAC.ac (lem10 j))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
753 n<ca0 = maxAC.n<ca (lem10 j)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
754 n<ca2 : j < count-A nac
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
755 n<ca2 = ≤-trans n<ca0 (count-A-homo (y≤max fan ac))
1322
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
756 fun< : (i : ℕ) → count-A (fun→ cn (g (f (fun← an i)))) < count-A (suc (fun→ cn (g (f (fun← an i)))))
70d46c446b0d using Fresh List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1321
diff changeset
757 fun< = ?
1321
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
758
1320
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
759 n<ca1 : (i n : ℕ ) → i ≤ suc j → n ≤ nac → i < count-A n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
760 n<ca1 zero n with is-A (fun← cn zero)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
761 ... | yes isa = ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
762 ... | no nisa = ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
763 n<ca1 (suc i) n with is-A (fun← cn (suc i))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
764 ... | yes isa = ? -- n<ca1 ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
765 ... | no nisa = ? -- n<ca1 ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
766
1311
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1310
diff changeset
767
1320
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
768 record CountB (n : ℕ) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
769 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
770 b : B
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
771 cb : ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
772 b=cn : fun← cn cb ≡ g b
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
773 cb=n : count-B cb ≡ n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
774
1321
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
775 lem01 : (n i : ℕ) → n < count-B i → CountB n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
776 lem01 zero zero lt with is-B (fun← cn zero)
1320
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
777 ... | no nisB = ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
778 ... | yes isB = ?
1321
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
779 lem01 (suc n) zero ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
780 lem01 n (suc i) n≤i with is-B (fun← cn (suc i))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
781 ... | no nisB = lem01 n i n≤i
1320
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
782 ... | yes isB with <-cmp (count-B (suc i)) n
1321
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
783 ... | tri< a ¬b ¬c = lem01 n i ?
1320
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
784 ... | tri≈ ¬a eq ¬c = record { b = Is.a isB ; cb = suc i ; b=cn = sym (Is.fa=c isB) ; cb=n = eq }
1321
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
785 ... | tri> ¬a ¬b c = lem01 n i ?
1320
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
786
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1319
diff changeset
787
1309
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
788 ntob : (n : ℕ) → B
1321
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1320
diff changeset
789 ntob n = CountB.b (lem01 n (maxAC.ac (lem02 n)) (≤-trans (maxAC.n<ca (lem02 n)) (ca≤cb0 (maxAC.ac (lem02 n))) ))
1308
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1307
diff changeset
790
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1307
diff changeset
791 biso : (n : ℕ) → bton (ntob n) ≡ n
1311
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1310
diff changeset
792 biso n = ? -- lem03 _ (≤-trans (maxAC.n<ca (lem02 n )) ?) refl
1308
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1307
diff changeset
793
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1307
diff changeset
794 biso1 : (b : B) → ntob (bton b) ≡ b
1309
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1308
diff changeset
795 biso1 b = ?
1302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
796
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
797 bi-∧ : {A B C D : Set} → Bijection A B → Bijection C D → Bijection (A ∧ C) (B ∧ D)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
798 bi-∧ {A} {B} {C} {D} ab cd = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
799 fun← = λ x → ⟪ fun← ab (proj1 x) , fun← cd (proj2 x) ⟫
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
800 ; fun→ = λ n → ⟪ fun→ ab (proj1 n) , fun→ cd (proj2 n) ⟫
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
801 ; fiso← = lem0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
802 ; fiso→ = lem1
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
803 } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
804 open Bijection
1302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
805 lem0 : (x : A ∧ C) → ⟪ fun← ab (fun→ ab (proj1 x)) , fun← cd (fun→ cd (proj2 x)) ⟫ ≡ x
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
806 lem0 ⟪ x , y ⟫ = cong₂ ⟪_,_⟫ (fiso← ab x) (fiso← cd y)
1302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
807 lem1 : (x : B ∧ D) → ⟪ fun→ ab (fun← ab (proj1 x)) , fun→ cd (fun← cd (proj2 x)) ⟫ ≡ x
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
808 lem1 ⟪ x , y ⟫ = cong₂ ⟪_,_⟫ (fiso→ ab x) (fiso→ cd y)
1302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
809
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
810
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
811 LM1 : (A : Set ) → Bijection (List A ) ℕ → Bijection (List A ∧ List Bool) ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
812 LM1 A Ln = bi-trans (List A ∧ List Bool) (ℕ ∧ ℕ) ℕ (bi-∧ Ln (bi-sym _ _ LBℕ) ) (bi-sym _ _ nxn)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
813
1303
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
814 open import Data.List.Properties
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
815 open import Data.Maybe.Properties
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
816
1302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
817 LMℕ : (A : Set ) → Bijection (List A) ℕ → Bijection (List (Maybe A)) ℕ
1303
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
818 LMℕ A Ln = Countable-Bernstein (List A) (List (Maybe A)) (List A ∧ List Bool) Ln (LM1 A Ln) fi gi ? ? where
1302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
819 f : List A → List (Maybe A)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
820 f [] = []
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
821 f (x ∷ t) = just x ∷ f t
1303
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
822 f-inject : {x y : List A} → f x ≡ f y → x ≡ y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
823 f-inject {[]} {[]} refl = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
824 f-inject {x ∷ xt} {y ∷ yt} eq = cong₂ (λ j k → j ∷ k ) (just-injective (∷-injectiveˡ eq)) (f-inject (∷-injectiveʳ eq) )
1302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
825 g : List (Maybe A) → List A ∧ List Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
826 g [] = ⟪ [] , [] ⟫
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
827 g (just h ∷ t) = ⟪ h ∷ proj1 (g t) , true ∷ proj2 (g t) ⟫
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
828 g (nothing ∷ t) = ⟪ proj1 (g t) , false ∷ proj2 (g t) ⟫
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
829 g⁻¹ : List A ∧ List Bool → List (Maybe A)
1303
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
830 g⁻¹ ⟪ [] , [] ⟫ = []
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
831 g⁻¹ ⟪ x ∷ xt , [] ⟫ = just x ∷ g⁻¹ ⟪ xt , [] ⟫
1303
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
832 g⁻¹ ⟪ [] , true ∷ y ⟫ = []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
833 g⁻¹ ⟪ x ∷ xt , true ∷ yt ⟫ = just x ∷ g⁻¹ ⟪ xt , yt ⟫
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
834 g⁻¹ ⟪ [] , false ∷ y ⟫ = nothing ∷ g⁻¹ ⟪ [] , y ⟫
1303
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
835 g⁻¹ ⟪ x ∷ x₁ , false ∷ y ⟫ = nothing ∷ g⁻¹ ⟪ x ∷ x₁ , y ⟫
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
836 g-iso : {x : List (Maybe A)} → g⁻¹ (g x) ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
837 g-iso {[]} = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
838 g-iso {just x ∷ xt} = cong ( λ k → just x ∷ k) ( g-iso )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
839 g-iso {nothing ∷ []} = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
840 g-iso {nothing ∷ just x ∷ xt} = cong (λ k → nothing ∷ k ) ( g-iso {_} )
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
841 g-iso {nothing ∷ nothing ∷ xt} with g-iso {nothing ∷ xt}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
842 ... | t = trans (lemma01 (proj1 (g xt)) (proj2 (g xt)) ) ( cong (λ k → nothing ∷ k ) t ) where
1303
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
843 lemma01 : (x : List A) (y : List Bool ) → g⁻¹ ⟪ x , false ∷ false ∷ y ⟫ ≡ nothing ∷ g⁻¹ ⟪ x , false ∷ y ⟫
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
844 lemma01 [] y = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
845 lemma01 (x ∷ x₁) y = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
846 g-inject : {x y : List (Maybe A)} → g x ≡ g y → x ≡ y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
847 g-inject {x} {y} eq = subst₂ (λ j k → j ≡ k ) g-iso g-iso (cong g⁻¹ eq )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
848 fi : InjectiveF (List A) (List (Maybe A))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
849 fi = record { f = f ; inject = f-inject }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
850 gi : InjectiveF (List (Maybe A)) (List A ∧ List Bool )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
851 gi = record { f = g ; inject = g-inject }
1302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
852
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
853 -- open import Data.Fin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
854 --
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
855 --- LBFin : {n : ℕ } → Bijection (List (Meybe (Fin n))) ( List (Fin (suc n)))
1303
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1302
diff changeset
856 --
1305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1304
diff changeset
857 --- LBFin : {n : ℕ } → Bijection ℕ ( List (Fin n))
1302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
858 --- LBFin = ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
859
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1283
diff changeset
860 --