annotate automaton-in-agda/src/fin.agda @ 284:c9f20dec63ad

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