annotate automaton-in-agda/src/fin.agda @ 286:f49c6d768e19

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 28 Dec 2021 02:43:07 +0900
parents 6e85b8b0d8db
children ce16779e72a5
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
285
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
156 record NList (n : ℕ) (qs : List (Fin (suc n))) : Set where
283
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
286
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
160 ls< : (length ls ≡ length qs) ∨ (suc (length ls) ≡ length qs)
284
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 283
diff changeset
161
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
162 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
163 fin-dup-in-list>n {zero} [] ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
164 fin-dup-in-list>n {zero} (() ∷ qs) lt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
165 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
166 open import Level using ( Level )
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
167 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
168 fdup+1 qs i p = f1-phase1 qs p where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
169 f1-phase2 : (qs : List (Fin (suc n)) ) → fin-phase2 i (list-less qs) ≡ true → fin-phase2 (fin+1 i) qs ≡ true
286
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
170 f1-phase2 (x ∷ qs) p with NatP.<-cmp (toℕ x) n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
171 f1-phase2 (x ∷ qs) p | tri< a ¬b ¬c with <-fcmp (fin+1 i) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
172 ... | tri< a₁ ¬b₁ ¬c₁ = f1-phase2 qs {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
173 ... | tri≈ ¬a b ¬c₁ = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
174 ... | tri> ¬a ¬b₁ c = f1-phase2 qs {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
175 f1-phase2 (x ∷ qs) p | tri≈ ¬a b ¬c = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
176 f1-phase2 (x ∷ qs) p | tri> ¬a ¬b c = ⊥-elim ( nat-≤> (fin≤n x) c )
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
177 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
178 f1-phase1 [] ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
179 f1-phase1 (x ∷ qs) p with <-fcmp (fin+1 i) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
180 ... | tri< a ¬b ¬c = f1-phase1 qs {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
181 ... | tri≈ ¬a b ¬c = f1-phase2 qs {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
182 ... | tri> ¬a ¬b c = f1-phase1 qs {!!}
285
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
183 fdup-phase2 : (qs : List (Fin (suc n)) )
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
184 → ( fin-phase2 (fromℕ< a<sa ) qs ≡ true ) ∨ NList n qs
286
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
185 fdup-phase2 [] = case2 record { ls = [] ; lseq = refl ; ls< = case1 refl }
285
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
186 fdup-phase2 (x ∷ qs) with <-fcmp (fromℕ< a<sa) x
284
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 283
diff changeset
187 ... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ x < suc k) (sym fin<asa) fin<n ))
285
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
188 fdup-phase2 (x ∷ qs) | tri≈ ¬a b ¬c = case1 refl
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
189 fdup-phase2 (x ∷ qs) | tri> ¬a ¬b c with fdup-phase2 qs
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
190 ... | case1 p = case1 p
286
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
191 ... | case2 nlist = case2 record { ls = x<y→fin-1 c ∷ NList.ls nlist ; lseq = fdup01 ; ls< = case1 {!!} } where
285
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
192 fdup01 : list-less (x ∷ qs) ≡ x<y→fin-1 c ∷ NList.ls nlist
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
193 fdup01 with NatP.<-cmp (toℕ x) n
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
194 ... | tri< a ¬b ¬c = begin
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
195 fromℕ< a ∷ list-less qs ≡⟨ cong₂ (λ j k → j ∷ k ) (lemma10 refl) (NList.lseq nlist) ⟩
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
196 fromℕ< (≤-trans c (fin≤n (fromℕ< a<sa))) ∷ NList.ls nlist ∎ where open ≡-Reasoning
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
197 ... | tri≈ ¬a b ¬c = ⊥-elim ( nat-≡< b (subst (λ k → toℕ x < k ) fin<asa c ))
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
198 ... | tri> ¬a ¬b c = ⊥-elim ( nat-≤> (fin≤n x) c )
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
199 fdup-phase1 : (qs : List (Fin (suc n)) ) → (fin-phase1 (fromℕ< a<sa) qs ≡ true) ∨ NList n qs
286
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
200 fdup-phase1 [] = case2 record { ls = [] ; lseq = refl ; ls< = case1 refl }
285
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
201 fdup-phase1 (x ∷ qs) with <-fcmp (fromℕ< a<sa) x
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
202 fdup-phase1 (x ∷ qs) | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ x < suc k) (sym fin<asa) fin<n ))
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
203 fdup-phase1 (x ∷ qs) | tri≈ ¬a b ¬c with fdup-phase2 qs
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
204 ... | case1 p = case1 p
286
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
205 ... | case2 nlist = case2 record { ls = NList.ls nlist ; lseq = {!!} ; ls< = case2 {!!} } where
285
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
206 fdup03 : list-less (x ∷ qs) ≡ NList.ls nlist
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
207 fdup03 = {!!}
286
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
208 fdup06 : suc (length (NList.ls nlist)) ≡ length (x ∷ qs)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
209 fdup06 = {!!}
285
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
210 fdup-phase1 (x ∷ qs) | tri> ¬a ¬b c with fdup-phase1 qs
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
211 ... | case1 p = case1 p
286
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
212 ... | case2 nlist = case2 record { ls = x<y→fin-1 c ∷ NList.ls nlist ; lseq = {!!} ; ls< = case1 fdup5 } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
213 fdup5 : length (x<y→fin-1 c ∷ NList.ls nlist) ≡ length (x ∷ qs)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
214 fdup5 = {!!}
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
215 fdup-phase0 : FDup-in-list (suc n) qs
285
6e85b8b0d8db remove ls<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 284
diff changeset
216 fdup-phase0 with fdup-phase1 qs
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
217 ... | case1 dup = record { dup = fromℕ< a<sa ; is-dup = dup }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
218 ... | case2 nlist = record { dup = fin+1 (FDup-in-list.dup fdup)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
219 ; is-dup = fdup+1 qs (FDup-in-list.dup fdup) (FDup-in-list.is-dup fdup) } where
286
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
220 fdup04 : (length (NList.ls nlist) ≡ length qs) ∨ (suc (length (NList.ls nlist)) ≡ length qs) → length (list-less qs) > n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
221 fdup04 (case1 eq) = px≤py ( begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
222 suc (suc n) ≤⟨ lt ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
223 length qs ≡⟨ sym eq ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
224 length (NList.ls nlist) ≡⟨ cong (λ k → length k) (sym (NList.lseq nlist )) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
225 length (list-less qs) ≤⟨ refl-≤s ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
226 suc (length (list-less qs)) ∎ ) where open ≤-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
227 fdup04 (case2 eq) = px≤py ( begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
228 suc (suc n) ≤⟨ lt ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
229 length qs ≡⟨ sym eq ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
230 suc (length (NList.ls nlist)) ≡⟨ cong (λ k → suc (length k)) (sym (NList.lseq nlist )) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
231 suc (length (list-less qs)) ∎ ) where open ≤-Reasoning
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
232 fdup : FDup-in-list n (list-less qs)
286
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
233 fdup = fin-dup-in-list>n (list-less qs) ( fdup04 (NList.ls< nlist) )