annotate automaton-in-agda/src/fin.agda @ 317:16e47a3c4eda

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 03 Jan 2022 18:50:01 +0900
parents 248711134141
children 4a00e5f2b793
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
289
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
125 f<→< : {n : ℕ } → { x y : Fin n} → x Data.Fin.< y → toℕ x < toℕ y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
126 f<→< {_} {zero} {suc y} (s≤s lt) = s≤s z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
127 f<→< {_} {suc x} {suc y} (s≤s lt) = s≤s (f<→< {_} {x} {y} lt)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
128
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
129 f≡→≡ : {n : ℕ } → { x y : Fin n} → x ≡ y → toℕ x ≡ toℕ y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
130 f≡→≡ refl = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
131
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
132 open import Data.List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
133 open import Relation.Binary.Definitions
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
134
317
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
135 -- fin-count : { n : ℕ } (q : Fin n) (qs : List (Fin n) ) → ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
136 -- fin-count q p[ = 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
137 -- fin-count q (q0 ∷ qs ) with <-fcmp q q0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
138 -- ... | tri-e = suc (fin-count q qs)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
139 -- ... | false = fin-count q qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
140
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
141 -- fin-not-dup-in-list : { n : ℕ} (qs : List (Fin n) ) → Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
142 -- fin-not-dup-in-list {n} qs = (q : Fin n) → fin-count q ≤ 1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
143
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
144 -- this is far easier
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
145 -- fin-not-dup-in-list→len<n : { n : ℕ} (qs : List (Fin n) ) → ( (q : Fin n) → fin-not-dup-in-list qs q) → length qs ≤ n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
146 -- fin-not-dup-in-list→len<n = ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
147
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
148 fin-phase2 : { n : ℕ } (q : Fin n) (qs : List (Fin n) ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
149 fin-phase2 q [] = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
150 fin-phase2 q (x ∷ qs) with <-fcmp q x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
151 ... | tri< a ¬b ¬c = fin-phase2 q qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
152 ... | tri≈ ¬a b ¬c = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
153 ... | tri> ¬a ¬b c = fin-phase2 q qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
154 fin-phase1 : { n : ℕ } (q : Fin n) (qs : List (Fin n) ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
155 fin-phase1 q [] = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
156 fin-phase1 q (x ∷ qs) with <-fcmp q x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
157 ... | tri< a ¬b ¬c = fin-phase1 q qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
158 ... | tri≈ ¬a b ¬c = fin-phase2 q qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
159 ... | tri> ¬a ¬b c = fin-phase1 q qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
161 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
162 fin-dup-in-list {n} q qs = fin-phase1 q qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
164 record FDup-in-list (n : ℕ ) (qs : List (Fin n)) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
165 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
166 dup : Fin n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
167 is-dup : fin-dup-in-list dup qs ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
168
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
169 list-less : {n : ℕ } → List (Fin (suc n)) → List (Fin n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
170 list-less [] = []
288
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
171 list-less {n} (i ∷ ls) with <-fcmp (fromℕ< a<sa) i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
172 ... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ i < suc k ) (sym fin<asa) (fin≤n _ )))
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
173 ... | tri≈ ¬a b ¬c = list-less ls
288
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
174 ... | tri> ¬a ¬b c = x<y→fin-1 c ∷ list-less ls
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
175
289
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
176 fin010 : {n m : ℕ } {x : Fin n} (c : suc (toℕ x) ≤ toℕ (fromℕ< {m} a<sa) ) → toℕ (fromℕ< (≤-trans c (fin≤n (fromℕ< a<sa)))) ≡ toℕ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
177 fin010 {_} {_} {x} c = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
178 toℕ (fromℕ< (≤-trans c (fin≤n (fromℕ< a<sa)))) ≡⟨ toℕ-fromℕ< _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
179 toℕ x ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
180
291
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 290
diff changeset
181 ---
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 290
diff changeset
182 --- if List (Fin n) is longer than n, there is at most one duplication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 290
diff changeset
183 ---
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
184 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
185 fin-dup-in-list>n {zero} [] ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
186 fin-dup-in-list>n {zero} (() ∷ qs) lt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
187 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
188 open import Level using ( Level )
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 293
diff changeset
189 -- make a dup from one level below
292
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
190 fdup+1 : (qs : List (Fin (suc n))) (i : Fin n) → fin-dup-in-list (fromℕ< a<sa ) qs ≡ false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
191 → fin-dup-in-list i (list-less qs) ≡ true → FDup-in-list (suc n) qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
192 fdup+1 qs i ne p = record { dup = fin+1 i ; is-dup = f1-phase1 qs p (case1 ne) } where
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 293
diff changeset
193 -- we have two loops on the max element and the current level. The disjuction means the phases may differ.
288
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
194 f1-phase2 : (qs : List (Fin (suc n)) ) → fin-phase2 i (list-less qs) ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
195 → (fin-phase1 (fromℕ< a<sa) qs ≡ false ) ∨ (fin-phase2 (fromℕ< a<sa) qs ≡ false)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
196 → fin-phase2 (fin+1 i) qs ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
197 f1-phase2 (x ∷ qs) p (case1 q1) with <-fcmp (fromℕ< a<sa) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
198 ... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ x < suc k ) (sym fin<asa) (fin≤n _ )))
289
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
199 f1-phase2 (x ∷ qs) p (case1 q1) | tri≈ ¬a b ¬c with <-fcmp (fin+1 i) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
200 ... | tri< a ¬b ¬c₁ = f1-phase2 qs p (case2 q1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
201 ... | tri≈ ¬a₁ b₁ ¬c₁ = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
202 ... | tri> ¬a₁ ¬b c = f1-phase2 qs p (case2 q1)
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 293
diff changeset
203 -- two fcmp is only different in the size of Fin, but to develop both f1-phase and list-less both fcmps are required
288
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
204 f1-phase2 (x ∷ qs) p (case1 q1) | tri> ¬a ¬b c with <-fcmp i (fromℕ< (≤-trans c (fin≤n (fromℕ< a<sa)))) | <-fcmp (fin+1 i) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
205 ... | tri< a ¬b₁ ¬c | tri< a₁ ¬b₂ ¬c₁ = f1-phase2 qs p (case1 q1)
289
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
206 ... | tri< a ¬b₁ ¬c | tri≈ ¬a₁ b ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
207 ... | tri< a ¬b₁ ¬c | tri> ¬a₁ ¬b₂ c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
208 ... | tri≈ ¬a₁ b ¬c | tri< a ¬b₁ ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) fin+1-toℕ (sym (toℕ-fromℕ< _)) a ))
288
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
209 ... | tri≈ ¬a₁ b ¬c | tri≈ ¬a₂ b₁ ¬c₁ = refl
289
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
210 ... | tri≈ ¬a₁ b ¬c | tri> ¬a₂ ¬b₁ c₁ = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) fin+1-toℕ (sym (toℕ-fromℕ< _)) c₁ ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
211 ... | tri> ¬a₁ ¬b₁ c₁ | tri< a ¬b₂ ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
212 ... | tri> ¬a₁ ¬b₁ c₁ | tri≈ ¬a₂ b ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
288
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
213 ... | tri> ¬a₁ ¬b₁ c₁ | tri> ¬a₂ ¬b₂ c₂ = f1-phase2 qs p (case1 q1)
289
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
214 f1-phase2 (x ∷ qs) p (case2 q1) with <-fcmp (fromℕ< a<sa) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
215 ... | 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: 288
diff changeset
216 f1-phase2 (x ∷ qs) p (case2 q1) | tri≈ ¬a b ¬c with <-fcmp (fin+1 i) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
217 ... | tri< a ¬b ¬c₁ = ⊥-elim ( ¬-bool q1 refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
218 ... | tri≈ ¬a₁ b₁ ¬c₁ = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
219 ... | tri> ¬a₁ ¬b c = ⊥-elim ( ¬-bool q1 refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
220 f1-phase2 (x ∷ qs) p (case2 q1) | tri> ¬a ¬b c with <-fcmp i (fromℕ< (≤-trans c (fin≤n (fromℕ< a<sa)))) | <-fcmp (fin+1 i) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
221 ... | tri< a ¬b₁ ¬c | tri< a₁ ¬b₂ ¬c₁ = f1-phase2 qs p (case2 q1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
222 ... | tri< a ¬b₁ ¬c | tri≈ ¬a₁ b ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
223 ... | tri< a ¬b₁ ¬c | tri> ¬a₁ ¬b₂ c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
224 ... | tri≈ ¬a₁ b ¬c | tri< a ¬b₁ ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) fin+1-toℕ (sym (toℕ-fromℕ< _)) a ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
225 ... | tri≈ ¬a₁ b ¬c | tri≈ ¬a₂ b₁ ¬c₁ = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
226 ... | tri≈ ¬a₁ b ¬c | tri> ¬a₂ ¬b₁ c₁ = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) fin+1-toℕ (sym (toℕ-fromℕ< _)) c₁ ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
227 ... | tri> ¬a₁ ¬b₁ c₁ | tri< a ¬b₂ ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
228 ... | tri> ¬a₁ ¬b₁ c₁ | tri≈ ¬a₂ b ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
229 ... | tri> ¬a₁ ¬b₁ c₁ | tri> ¬a₂ ¬b₂ c₂ = f1-phase2 qs p (case2 q1 )
288
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
230 f1-phase1 : (qs : List (Fin (suc n)) ) → fin-phase1 i (list-less qs) ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
231 → (fin-phase1 (fromℕ< a<sa) qs ≡ false ) ∨ (fin-phase2 (fromℕ< a<sa) qs ≡ false)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
232 → fin-phase1 (fin+1 i) qs ≡ true
290
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
233 f1-phase1 (x ∷ qs) p (case1 q1) with <-fcmp (fromℕ< a<sa) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
234 ... | 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: 289
diff changeset
235 f1-phase1 (x ∷ qs) p (case1 q1) | tri≈ ¬a b ¬c with <-fcmp (fin+1 i) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
236 ... | tri< a ¬b ¬c₁ = f1-phase1 qs p (case2 q1)
291
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 290
diff changeset
237 ... | tri≈ ¬a₁ b₁ ¬c₁ = ⊥-elim (fdup-10 b b₁) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 290
diff changeset
238 fdup-10 : fromℕ< a<sa ≡ x → fin+1 i ≡ x → ⊥
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 290
diff changeset
239 fdup-10 eq eq1 = nat-≡< (cong toℕ (trans eq1 (sym eq))) (subst₂ (λ j k → j < k ) (sym fin+1-toℕ) (sym fin<asa) fin<n )
290
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
240 ... | tri> ¬a₁ ¬b c = f1-phase1 qs p (case2 q1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
241 f1-phase1 (x ∷ qs) p (case1 q1) | tri> ¬a ¬b c with <-fcmp i (fromℕ< (≤-trans c (fin≤n (fromℕ< a<sa)))) | <-fcmp (fin+1 i) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
242 ... | tri< a ¬b₁ ¬c | tri< a₁ ¬b₂ ¬c₁ = f1-phase1 qs p (case1 q1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
243 ... | tri< a ¬b₁ ¬c | tri≈ ¬a₁ b ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
244 ... | tri< a ¬b₁ ¬c | tri> ¬a₁ ¬b₂ c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
245 ... | tri≈ ¬a₁ b ¬c | tri< a ¬b₁ ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) fin+1-toℕ (sym (toℕ-fromℕ< _)) a ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
246 ... | tri≈ ¬a₁ b ¬c | tri≈ ¬a₂ b₁ ¬c₁ = f1-phase2 qs p (case1 q1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
247 ... | tri≈ ¬a₁ b ¬c | tri> ¬a₂ ¬b₁ c₁ = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) fin+1-toℕ (sym (toℕ-fromℕ< _)) c₁ ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
248 ... | tri> ¬a₁ ¬b₁ c₁ | tri< a ¬b₂ ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
249 ... | tri> ¬a₁ ¬b₁ c₁ | tri≈ ¬a₂ b ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
250 ... | tri> ¬a₁ ¬b₁ c₁ | tri> ¬a₂ ¬b₂ c₂ = f1-phase1 qs p (case1 q1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
251 f1-phase1 (x ∷ qs) p (case2 q1) with <-fcmp (fromℕ< a<sa) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
252 ... | 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: 289
diff changeset
253 f1-phase1 (x ∷ qs) p (case2 q1) | tri≈ ¬a b ¬c = ⊥-elim ( ¬-bool q1 refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
254 f1-phase1 (x ∷ qs) p (case2 q1) | tri> ¬a ¬b c with <-fcmp i (fromℕ< (≤-trans c (fin≤n (fromℕ< a<sa)))) | <-fcmp (fin+1 i) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
255 ... | tri< a ¬b₁ ¬c | tri< a₁ ¬b₂ ¬c₁ = f1-phase1 qs p (case2 q1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
256 ... | tri< a ¬b₁ ¬c | tri≈ ¬a₁ b ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
257 ... | tri< a ¬b₁ ¬c | tri> ¬a₁ ¬b₂ c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
258 ... | tri≈ ¬a₁ b ¬c | tri< a ¬b₁ ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) fin+1-toℕ (sym (toℕ-fromℕ< _)) a ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
259 ... | tri≈ ¬a₁ b ¬c | tri≈ ¬a₂ b₁ ¬c₁ = f1-phase2 qs p (case2 q1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
260 ... | tri≈ ¬a₁ b ¬c | tri> ¬a₂ ¬b₁ c₁ = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) fin+1-toℕ (sym (toℕ-fromℕ< _)) c₁ ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
261 ... | tri> ¬a₁ ¬b₁ c₁ | tri< a ¬b₂ ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
262 ... | tri> ¬a₁ ¬b₁ c₁ | tri≈ ¬a₂ b ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
263 ... | tri> ¬a₁ ¬b₁ c₁ | tri> ¬a₂ ¬b₂ c₂ = f1-phase1 qs p (case2 q1)
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
264 fdup-phase0 : FDup-in-list (suc n) qs
292
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
265 fdup-phase0 with fin-dup-in-list (fromℕ< a<sa) qs | inspect (fin-dup-in-list (fromℕ< a<sa)) qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
266 ... | true | record { eq = eq } = record { dup = fromℕ< a<sa ; is-dup = eq }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
267 ... | false | record { eq = ne } = fdup+1 qs (FDup-in-list.dup fdup) ne (FDup-in-list.is-dup fdup) where
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 293
diff changeset
268 -- if no dup in the max element, the list without the element is only one length shorter
292
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
269 fless : (qs : List (Fin (suc n))) → length qs > suc n → fin-dup-in-list (fromℕ< a<sa) qs ≡ false → n < length (list-less qs)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
270 fless qs lt p = fl-phase1 n qs lt p where
293
8992ecc40eb1 fin side done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 292
diff changeset
271 fl-phase2 : (n1 : ℕ) (qs : List (Fin (suc n))) → length qs > n1 → fin-phase2 (fromℕ< a<sa) qs ≡ false → n1 < length (list-less qs)
292
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
272 fl-phase2 zero (x ∷ qs) (s≤s lt) p with <-fcmp (fromℕ< a<sa) x
293
8992ecc40eb1 fin side done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 292
diff changeset
273 ... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ x < suc k ) (sym fin<asa) (fin≤n _ )))
8992ecc40eb1 fin side done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 292
diff changeset
274 ... | tri> ¬a ¬b c = s≤s z≤n
292
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
275 fl-phase2 (suc n1) (x ∷ qs) (s≤s lt) p with <-fcmp (fromℕ< a<sa) x
293
8992ecc40eb1 fin side done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 292
diff changeset
276 ... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ x < suc k ) (sym fin<asa) (fin≤n _ )))
8992ecc40eb1 fin side done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 292
diff changeset
277 ... | tri> ¬a ¬b c = s≤s ( fl-phase2 n1 qs lt p )
292
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
278 fl-phase1 : (n1 : ℕ) (qs : List (Fin (suc n))) → length qs > suc n1 → fin-phase1 (fromℕ< a<sa) qs ≡ false → n1 < length (list-less qs)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
279 fl-phase1 zero (x ∷ qs) (s≤s lt) p with <-fcmp (fromℕ< a<sa) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
280 ... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ x < suc k ) (sym fin<asa) (fin≤n _ )))
293
8992ecc40eb1 fin side done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 292
diff changeset
281 ... | tri≈ ¬a b ¬c = fl-phase2 0 qs lt p
292
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
282 ... | tri> ¬a ¬b c = s≤s z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
283 fl-phase1 (suc n1) (x ∷ qs) (s≤s lt) p with <-fcmp (fromℕ< a<sa) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
284 ... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ x < suc k ) (sym fin<asa) (fin≤n _ )))
293
8992ecc40eb1 fin side done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 292
diff changeset
285 ... | tri≈ ¬a b ¬c = fl-phase2 (suc n1) qs lt p
292
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
286 ... | tri> ¬a ¬b c = s≤s ( fl-phase1 n1 qs lt p )
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 293
diff changeset
287 -- if the list without the max element is only one length shorter, we can recurse
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
288 fdup : FDup-in-list n (list-less qs)
292
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
289 fdup = fin-dup-in-list>n (list-less qs) (fless qs lt ne)