annotate automaton-in-agda/src/fin.agda @ 283:e5a0499e7b40

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 27 Dec 2021 19:48:00 +0900
parents 8006cbd87b20
children c9f20dec63ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 {-# OPTIONS --allow-unsolved-metas #-}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 module fin where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
5 open import Data.Fin hiding (_<_ ; _≤_ ; _>_ ; _+_ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
6 open import Data.Fin.Properties hiding ( <-trans ; ≤-refl ) renaming ( <-cmp to <-fcmp )
163
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 logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import nat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import Relation.Binary.PropositionalEquality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 -- toℕ<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 fin<n : {n : ℕ} {f : Fin n} → toℕ f < n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 fin<n {_} {zero} = s≤s z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 fin<n {suc n} {suc f} = s≤s (fin<n {n} {f})
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 -- toℕ≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 fin≤n : {n : ℕ} (f : Fin (suc n)) → toℕ f ≤ n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 fin≤n {_} zero = z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 fin≤n {suc n} (suc f) = s≤s (fin≤n {n} f)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 pred<n : {n : ℕ} {f : Fin (suc n)} → n > 0 → Data.Nat.pred (toℕ f) < n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 pred<n {suc n} {zero} (s≤s z≤n) = s≤s z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 pred<n {suc n} {suc f} (s≤s z≤n) = fin<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 fin<asa : {n : ℕ} → toℕ (fromℕ< {n} a<sa) ≡ n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 fin<asa = toℕ-fromℕ< nat.a<sa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 -- fromℕ<-toℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 toℕ→from : {n : ℕ} {x : Fin (suc n)} → toℕ x ≡ n → fromℕ n ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 toℕ→from {0} {zero} refl = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 toℕ→from {suc n} {suc x} eq = cong (λ k → suc k ) ( toℕ→from {n} {x} (cong (λ k → Data.Nat.pred k ) eq ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 0≤fmax : {n : ℕ } → (# 0) Data.Fin.≤ fromℕ< {n} a<sa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 0≤fmax = subst (λ k → 0 ≤ k ) (sym (toℕ-fromℕ< a<sa)) z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 0<fmax : {n : ℕ } → (# 0) Data.Fin.< fromℕ< {suc n} a<sa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 0<fmax = subst (λ k → 0 < k ) (sym (toℕ-fromℕ< a<sa)) (s≤s z≤n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 -- toℕ-injective
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 i=j : {n : ℕ} (i j : Fin n) → toℕ i ≡ toℕ j → i ≡ j
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 i=j {suc n} zero zero refl = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 i=j {suc n} (suc i) (suc j) eq = cong ( λ k → suc k ) ( i=j i j (cong ( λ k → Data.Nat.pred k ) eq) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 -- raise 1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 fin+1 : { n : ℕ } → Fin n → Fin (suc n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 fin+1 zero = zero
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 fin+1 (suc x) = suc (fin+1 x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 open import Data.Nat.Properties as NatP hiding ( _≟_ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 fin+1≤ : { i n : ℕ } → (a : i < n) → fin+1 (fromℕ< a) ≡ fromℕ< (<-trans a a<sa)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 fin+1≤ {0} {suc i} (s≤s z≤n) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 fin+1≤ {suc n} {suc (suc i)} (s≤s (s≤s a)) = cong (λ k → suc k ) ( fin+1≤ {n} {suc i} (s≤s a) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 fin+1-toℕ : { n : ℕ } → { x : Fin n} → toℕ (fin+1 x) ≡ toℕ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 fin+1-toℕ {suc n} {zero} = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 fin+1-toℕ {suc n} {suc x} = cong (λ k → suc k ) (fin+1-toℕ {n} {x})
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 open import Relation.Nullary
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 open import Data.Empty
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 fin-1 : { n : ℕ } → (x : Fin (suc n)) → ¬ (x ≡ zero ) → Fin n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 fin-1 zero ne = ⊥-elim (ne refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 fin-1 {n} (suc x) ne = x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 fin-1-sx : { n : ℕ } → (x : Fin n) → fin-1 (suc x) (λ ()) ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 fin-1-sx zero = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 fin-1-sx (suc x) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 fin-1-xs : { n : ℕ } → (x : Fin (suc n)) → (ne : ¬ (x ≡ zero )) → suc (fin-1 x ne ) ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 fin-1-xs zero ne = ⊥-elim ( ne refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 fin-1-xs (suc x) ne = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 -- suc-injective
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 -- suc-eq : {n : ℕ } {x y : Fin n} → Fin.suc x ≡ Fin.suc y → x ≡ y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 -- suc-eq {n} {x} {y} eq = subst₂ (λ j k → j ≡ k ) {!!} {!!} (cong (λ k → Data.Fin.pred k ) eq )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 -- this is refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 lemma3 : {a b : ℕ } → (lt : a < b ) → fromℕ< (s≤s lt) ≡ suc (fromℕ< lt)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 lemma3 (s≤s lt) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 -- fromℕ<-toℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 lemma12 : {n m : ℕ } → (n<m : n < m ) → (f : Fin m ) → toℕ f ≡ n → f ≡ fromℕ< n<m
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 lemma12 {zero} {suc m} (s≤s z≤n) zero refl = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 lemma12 {suc n} {suc m} (s≤s n<m) (suc f) refl = cong suc ( lemma12 {n} {m} n<m f refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 open import Relation.Binary.HeterogeneousEquality as HE using (_≅_ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 -- <-irrelevant
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 <-nat=irr : {i j n : ℕ } → ( i ≡ j ) → {i<n : i < n } → {j<n : j < n } → i<n ≅ j<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 <-nat=irr {zero} {zero} {suc n} refl {s≤s z≤n} {s≤s z≤n} = HE.refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 <-nat=irr {suc i} {suc i} {suc n} refl {s≤s i<n} {s≤s j<n} = HE.cong (λ k → s≤s k ) ( <-nat=irr {i} {i} {n} refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 lemma8 : {i j n : ℕ } → ( i ≡ j ) → {i<n : i < n } → {j<n : j < n } → i<n ≅ j<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 lemma8 {zero} {zero} {suc n} refl {s≤s z≤n} {s≤s z≤n} = HE.refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 lemma8 {suc i} {suc i} {suc n} refl {s≤s i<n} {s≤s j<n} = HE.cong (λ k → s≤s k ) ( lemma8 {i} {i} {n} refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 -- fromℕ<-irrelevant
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 lemma10 : {n i j : ℕ } → ( i ≡ j ) → {i<n : i < n } → {j<n : j < n } → fromℕ< i<n ≡ fromℕ< j<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 lemma10 {n} refl = HE.≅-to-≡ (HE.cong (λ k → fromℕ< k ) (lemma8 refl ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 lemma31 : {a b c : ℕ } → { a<b : a < b } { b<c : b < c } { a<c : a < c } → NatP.<-trans a<b b<c ≡ a<c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 lemma31 {a} {b} {c} {a<b} {b<c} {a<c} = HE.≅-to-≡ (lemma8 refl)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 -- toℕ-fromℕ<
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 lemma11 : {n m : ℕ } {x : Fin n } → (n<m : n < m ) → toℕ (fromℕ< (NatP.<-trans (toℕ<n x) n<m)) ≡ toℕ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 lemma11 {n} {m} {x} n<m = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 toℕ (fromℕ< (NatP.<-trans (toℕ<n x) n<m))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 ≡⟨ toℕ-fromℕ< _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 toℕ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 ∎ where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
116 open import Data.List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
117 open import Relation.Binary.Definitions
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
118
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
119 fin-phase2 : { n : ℕ } (q : Fin n) (qs : List (Fin n) ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
120 fin-phase2 q [] = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
121 fin-phase2 q (x ∷ qs) with <-fcmp q x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
122 ... | tri< a ¬b ¬c = fin-phase2 q qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
123 ... | tri≈ ¬a b ¬c = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
124 ... | tri> ¬a ¬b c = fin-phase2 q qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
125 fin-phase1 : { n : ℕ } (q : Fin n) (qs : List (Fin n) ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
126 fin-phase1 q [] = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
127 fin-phase1 q (x ∷ qs) with <-fcmp q x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
128 ... | tri< a ¬b ¬c = fin-phase1 q qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
129 ... | tri≈ ¬a b ¬c = fin-phase2 q qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
130 ... | tri> ¬a ¬b c = fin-phase1 q qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
131
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
132 fin-dup-in-list : { n : ℕ} (q : Fin n) (qs : List (Fin n) ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
133 fin-dup-in-list {n} q qs = fin-phase1 q qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
134
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
135 record FDup-in-list (n : ℕ ) (qs : List (Fin n)) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
136 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
137 dup : Fin n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
138 is-dup : fin-dup-in-list dup qs ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
139
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
140 list-less : {n : ℕ } → List (Fin (suc n)) → List (Fin n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
141 list-less [] = []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
142 list-less {n} (i ∷ ls) with NatP.<-cmp (toℕ i) n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
143 ... | tri< a ¬b ¬c = fromℕ< a ∷ list-less ls
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
144 ... | tri≈ ¬a b ¬c = list-less ls
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
145 ... | tri> ¬a ¬b c = ⊥-elim ( nat-≤> (fin≤n i) c )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
146
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
147 record NList (n m : ℕ) (qs : List (Fin (suc n))) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
148 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
149 ls : List (Fin n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
150 lseq : list-less qs ≡ ls
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
151 ls>n : m + length ls > n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
152
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
153 fin-dup-in-list>n : {n : ℕ } → (qs : List (Fin n)) → (len> : length qs > n ) → FDup-in-list n qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
154 fin-dup-in-list>n {zero} [] ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
155 fin-dup-in-list>n {zero} (() ∷ qs) lt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
156 fin-dup-in-list>n {suc n} qs lt = fdup-phase0 where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
157 fdup+1 : (qs : List (Fin (suc n))) (i : Fin n) → fin-dup-in-list i (list-less qs) ≡ true → fin-dup-in-list (fin+1 i) qs ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
158 fdup+1 qs i p = f1-phase1 qs p where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
159 f1-phase2 : (qs : List (Fin (suc n)) ) → fin-phase2 i (list-less qs) ≡ true → fin-phase2 (fin+1 i) qs ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
160 f1-phase2 (x ∷ qs) p with <-fcmp (fin+1 i) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
161 ... | tri< a ¬b ¬c = f1-phase2 qs {!!} -- fin-phase2 i (list-less (x ∷ qs)) ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
162 ... | tri≈ ¬a b ¬c = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
163 ... | tri> ¬a ¬b c = f1-phase2 qs {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
164 f1-phase1 : (qs : List (Fin (suc n)) ) → fin-phase1 i (list-less qs) ≡ true → fin-phase1 (fin+1 i) qs ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
165 f1-phase1 [] ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
166 f1-phase1 (x ∷ qs) p with <-fcmp (fin+1 i) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
167 ... | tri< a ¬b ¬c = f1-phase1 qs {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
168 ... | tri≈ ¬a b ¬c = f1-phase2 qs {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
169 ... | tri> ¬a ¬b c = f1-phase1 qs {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
170 fdup-phase2 : (qs : List (Fin (suc n)) ) → {m : ℕ} → m + length qs > n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
171 → ( fin-phase2 (fromℕ< a<sa ) qs ≡ true ) ∨ NList n m qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
172 fdup-phase2 [] {m} lt = case2 record { ls = [] ; lseq = refl ; ls>n = lt }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
173 fdup-phase2 (x ∷ qs) {m} lt with <-fcmp (fromℕ< a<sa) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
174 ... | tri< a ¬b ¬c = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
175 fdup-phase2 (x ∷ qs) {m} lt | tri≈ ¬a b ¬c = case1 refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
176 fdup-phase2 (x ∷ qs) {m} lt | tri> ¬a ¬b c with fdup-phase2 qs {suc m} {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
177 ... | case1 p = case1 p
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
178 ... | case2 nlist = case2 record { ls = {!!} ∷ NList.ls nlist ; lseq = {!!} ; ls>n = {!!} }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
179 fdup-phase1 : (qs : List (Fin (suc n)) ) → {m : ℕ} → m + length qs > n → (fin-phase1 (fromℕ< a<sa) qs ≡ true) ∨ NList n m qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
180 fdup-phase1 [] {m} lt = case2 record { ls = [] ; lseq = refl ; ls>n = lt }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
181 fdup-phase1 (x ∷ qs) {m} lt with <-fcmp (fromℕ< a<sa) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
182 fdup-phase1 (x ∷ qs) {m} lt | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a {!!} )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
183 fdup-phase1 (x ∷ qs) {m} lt | tri≈ ¬a b ¬c with fdup-phase2 qs {m} {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
184 ... | case1 p = case1 p
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
185 ... | case2 nlist = case2 record { ls = {!!} ∷ NList.ls nlist ; lseq = {!!} ; ls>n = {!!} }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
186 fdup-phase1 (x ∷ qs) {m} lt | tri> ¬a ¬b c with fdup-phase1 qs {m} {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
187 ... | case1 p = case1 p
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
188 ... | case2 nlist = case2 record { ls = {!!} ∷ NList.ls nlist ; lseq = {!!} ; ls>n = {!!} }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
189 fdup-phase0 : FDup-in-list (suc n) qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
190 fdup-phase0 with fdup-phase1 qs {0} ( <-trans a<sa lt )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
191 ... | case1 dup = record { dup = fromℕ< a<sa ; is-dup = dup }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
192 ... | case2 nlist = record { dup = fin+1 (FDup-in-list.dup fdup)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
193 ; is-dup = fdup+1 qs (FDup-in-list.dup fdup) (FDup-in-list.is-dup fdup) } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
194 flt : length (list-less qs) > n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
195 flt = subst ( λ k → length k > n ) (sym (NList.lseq nlist)) ( NList.ls>n nlist )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
196 fdup : FDup-in-list n (list-less qs)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
197 fdup = fin-dup-in-list>n (list-less qs) flt