annotate automaton-in-agda/src/finiteSetUtil.agda @ 278:e89957b99662

dup in finiteSet in long list
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 26 Dec 2021 12:38:37 +0900
parents 8006cbd87b20
children 681df12f0edc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
1 {-# OPTIONS --allow-unsolved-metas #-}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
3 module finiteSetUtil where
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Data.Nat hiding ( _≟_ )
278
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
6 open import Data.Fin renaming ( _<_ to _<<_ ; _>_ to _f>_ ; _≟_ to _f≟_ ) hiding (_≤_ )
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 open import Data.Fin.Properties
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import Data.Empty
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import Relation.Nullary
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import Relation.Binary.Definitions
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 open import Relation.Binary.PropositionalEquality
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 open import logic
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 open import nat
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 open import finiteSet
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
15 open import fin
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 open import Data.Nat.Properties as NatP hiding ( _≟_ )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 open import Relation.Binary.HeterogeneousEquality as HE using (_≅_ )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
19 record Found ( Q : Set ) (p : Q → Bool ) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
20 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
21 found-q : Q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
22 found-p : p found-q ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
23
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
24 open Bijection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
25
268
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
26 open import Axiom.Extensionality.Propositional
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
27 open import Level hiding (suc ; zero)
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
28 postulate f-extensionality : { n : Level} → Axiom.Extensionality.Propositional.Extensionality n n -- (Level.suc n)
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
29
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
30 module _ {Q : Set } (F : FiniteSet Q) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
31 open FiniteSet F
268
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
32 equal?-refl : { x : Q } → equal? x x ≡ true
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
33 equal?-refl {x} with F←Q x ≟ F←Q x
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
34 ... | yes refl = refl
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
35 ... | no ne = ⊥-elim (ne refl)
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
36 equal→refl : { x y : Q } → equal? x y ≡ true → x ≡ y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
37 equal→refl {q0} {q1} eq with F←Q q0 ≟ F←Q q1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
38 equal→refl {q0} {q1} refl | yes eq = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
39 q0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
40 ≡⟨ sym ( finiso→ q0) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
41 Q←F (F←Q q0)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
42 ≡⟨ cong (λ k → Q←F k ) eq ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
43 Q←F (F←Q q1)
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
44 ≡⟨ finiso→ q1 ⟩
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
45 q1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
46 ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
47 End : (m : ℕ ) → (p : Q → Bool ) → Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
48 End m p = (i : Fin finite) → m ≤ toℕ i → p (Q←F i ) ≡ false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
49 first-end : ( p : Q → Bool ) → End finite p
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
50 first-end p i i>n = ⊥-elim (nat-≤> i>n (fin<n {finite} {i}) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
51 next-end : {m : ℕ } → ( p : Q → Bool ) → End (suc m) p
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
52 → (m<n : m < finite ) → p (Q←F (fromℕ< m<n )) ≡ false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
53 → End m p
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
54 next-end {m} p prev m<n np i m<i with NatP.<-cmp m (toℕ i)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
55 next-end p prev m<n np i m<i | tri< a ¬b ¬c = prev i a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
56 next-end p prev m<n np i m<i | tri> ¬a ¬b c = ⊥-elim ( nat-≤> m<i c )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
57 next-end {m} p prev m<n np i m<i | tri≈ ¬a b ¬c = subst ( λ k → p (Q←F k) ≡ false) (m<n=i i b m<n ) np where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
58 m<n=i : {n : ℕ } (i : Fin n) {m : ℕ } → m ≡ (toℕ i) → (m<n : m < n ) → fromℕ< m<n ≡ i
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
59 m<n=i i refl m<n = fromℕ<-toℕ i m<n
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
60 found : { p : Q → Bool } → (q : Q ) → p q ≡ true → exists p ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
61 found {p} q pt = found1 finite (NatP.≤-refl ) ( first-end p ) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
62 found1 : (m : ℕ ) (m<n : m Data.Nat.≤ finite ) → ((i : Fin finite) → m ≤ toℕ i → p (Q←F i ) ≡ false ) → exists1 m m<n p ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
63 found1 0 m<n end = ⊥-elim ( ¬-bool (subst (λ k → k ≡ false ) (cong (λ k → p k) (finiso→ q) ) (end (F←Q q) z≤n )) pt )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
64 found1 (suc m) m<n end with bool-≡-? (p (Q←F (fromℕ< m<n))) true
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
65 found1 (suc m) m<n end | yes eq = subst (λ k → k \/ exists1 m (<to≤ m<n) p ≡ true ) (sym eq) (bool-or-4 {exists1 m (<to≤ m<n) p} )
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
66 found1 (suc m) m<n end | no np = begin
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
67 p (Q←F (fromℕ< m<n)) \/ exists1 m (<to≤ m<n) p
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
68 ≡⟨ bool-or-1 (¬-bool-t np ) ⟩
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
69 exists1 m (<to≤ m<n) p
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
70 ≡⟨ found1 m (<to≤ m<n) (next-end p end m<n (¬-bool-t np )) ⟩
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
71 true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
72 ∎ where open ≡-Reasoning
268
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
73 not-found : { p : Q → Bool } → ( (q : Q ) → p q ≡ false ) → exists p ≡ false
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
74 not-found {p} pn = not-found2 finite NatP.≤-refl where
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
75 not-found2 : (m : ℕ ) → (m<n : m Data.Nat.≤ finite ) → exists1 m m<n p ≡ false
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
76 not-found2 zero _ = refl
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
77 not-found2 ( suc m ) m<n with pn (Q←F (fromℕ< {m} {finite} m<n))
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
78 not-found2 (suc m) m<n | eq = begin
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
79 p (Q←F (fromℕ< m<n)) \/ exists1 m (<to≤ m<n) p
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
80 ≡⟨ bool-or-1 eq ⟩
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
81 exists1 m (<to≤ m<n) p
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
82 ≡⟨ not-found2 m (<to≤ m<n) ⟩
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
83 false
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
84 ∎ where open ≡-Reasoning
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
85 found← : { p : Q → Bool } → exists p ≡ true → Found Q p
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
86 found← {p} exst = found2 finite NatP.≤-refl (first-end p ) where
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
87 found2 : (m : ℕ ) (m<n : m Data.Nat.≤ finite ) → End m p → Found Q p
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
88 found2 0 m<n end = ⊥-elim ( ¬-bool (not-found (λ q → end (F←Q q) z≤n ) ) (subst (λ k → exists k ≡ true) (sym lemma) exst ) ) where
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
89 lemma : (λ z → p (Q←F (F←Q z))) ≡ p
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
90 lemma = f-extensionality ( λ q → subst (λ k → p k ≡ p q ) (sym (finiso→ q)) refl )
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
91 found2 (suc m) m<n end with bool-≡-? (p (Q←F (fromℕ< m<n))) true
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
92 found2 (suc m) m<n end | yes eq = record { found-q = Q←F (fromℕ< m<n) ; found-p = eq }
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
93 found2 (suc m) m<n end | no np =
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
94 found2 m (<to≤ m<n) (next-end p end m<n (¬-bool-t np ))
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
95 not-found← : { p : Q → Bool } → exists p ≡ false → (q : Q ) → p q ≡ false
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
96 not-found← {p} np q = ¬-bool-t ( contra-position {_} {_} {_} {exists p ≡ true} (found q) (λ ep → ¬-bool np ep ) )
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
97
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
98
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
99
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
100 iso-fin : {A B : Set} → FiniteSet A → Bijection A B → FiniteSet B
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 iso-fin {A} {B} fin iso = record {
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
102 Q←F = λ f → fun→ iso ( FiniteSet.Q←F fin f )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
103 ; F←Q = λ b → FiniteSet.F←Q fin (fun← iso b )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
104 ; finiso→ = finiso→
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
105 ; finiso← = finiso←
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 } where
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
107 finiso→ : (q : B) → fun→ iso (FiniteSet.Q←F fin (FiniteSet.F←Q fin (Bijection.fun← iso q))) ≡ q
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 finiso→ q = begin
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
109 fun→ iso (FiniteSet.Q←F fin (FiniteSet.F←Q fin (Bijection.fun← iso q)))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
110 ≡⟨ cong (λ k → fun→ iso k ) (FiniteSet.finiso→ fin _ ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
111 fun→ iso (Bijection.fun← iso q)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
112 ≡⟨ fiso→ iso _ ⟩
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 q
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
114 ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
115 finiso← : (f : Fin (FiniteSet.finite fin ))→ FiniteSet.F←Q fin (Bijection.fun← iso (Bijection.fun→ iso (FiniteSet.Q←F fin f))) ≡ f
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 finiso← f = begin
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
117 FiniteSet.F←Q fin (Bijection.fun← iso (Bijection.fun→ iso (FiniteSet.Q←F fin f)))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
118 ≡⟨ cong (λ k → FiniteSet.F←Q fin k ) (Bijection.fiso← iso _) ⟩
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 FiniteSet.F←Q fin (FiniteSet.Q←F fin f)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 ≡⟨ FiniteSet.finiso← fin _ ⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 f
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 ∎ where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 open ≡-Reasoning
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 data One : Set where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 one : One
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 fin-∨1 : {B : Set} → (fb : FiniteSet B ) → FiniteSet (One ∨ B)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 fin-∨1 {B} fb = record {
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 Q←F = Q←F
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 ; F←Q = F←Q
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 ; finiso→ = finiso→
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 ; finiso← = finiso←
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 } where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 b = FiniteSet.finite fb
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 Q←F : Fin (suc b) → One ∨ B
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 Q←F zero = case1 one
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 Q←F (suc f) = case2 (FiniteSet.Q←F fb f)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 F←Q : One ∨ B → Fin (suc b)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 F←Q (case1 one) = zero
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 F←Q (case2 f ) = suc (FiniteSet.F←Q fb f)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 finiso→ : (q : One ∨ B) → Q←F (F←Q q) ≡ q
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 finiso→ (case1 one) = refl
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 finiso→ (case2 b) = cong (λ k → case2 k ) (FiniteSet.finiso→ fb b)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 finiso← : (q : Fin (suc b)) → F←Q (Q←F q) ≡ q
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 finiso← zero = refl
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 finiso← (suc f) = cong ( λ k → suc k ) (FiniteSet.finiso← fb f)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 fin-∨2 : {B : Set} → ( a : ℕ ) → FiniteSet B → FiniteSet (Fin a ∨ B)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 fin-∨2 {B} zero fb = iso-fin fb iso where
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
152 iso : Bijection B (Fin zero ∨ B)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
153 iso = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
154 fun← = fun←1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
155 ; fun→ = λ b → case2 b
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
156 ; fiso→ = fiso→1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
157 ; fiso← = λ _ → refl
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 } where
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
159 fun←1 : Fin zero ∨ B → B
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
160 fun←1 (case2 x) = x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
161 fiso→1 : (f : Fin zero ∨ B ) → case2 (fun←1 f) ≡ f
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
162 fiso→1 (case2 x) = refl
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 fin-∨2 {B} (suc a) fb = iso-fin (fin-∨1 (fin-∨2 a fb) ) iso
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 where
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
165 iso : Bijection (One ∨ (Fin a ∨ B) ) (Fin (suc a) ∨ B)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
166 fun← iso (case1 zero) = case1 one
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
167 fun← iso (case1 (suc f)) = case2 (case1 f)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
168 fun← iso (case2 b) = case2 (case2 b)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
169 fun→ iso (case1 one) = case1 zero
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
170 fun→ iso (case2 (case1 f)) = case1 (suc f)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
171 fun→ iso (case2 (case2 b)) = case2 b
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
172 fiso← iso (case1 one) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
173 fiso← iso (case2 (case1 x)) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
174 fiso← iso (case2 (case2 x)) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
175 fiso→ iso (case1 zero) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
176 fiso→ iso (case1 (suc x)) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
177 fiso→ iso (case2 x) = refl
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
180 FiniteSet→Fin : {A : Set} → (fin : FiniteSet A ) → Bijection (Fin (FiniteSet.finite fin)) A
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
181 fun← (FiniteSet→Fin fin) f = FiniteSet.F←Q fin f
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
182 fun→ (FiniteSet→Fin fin) f = FiniteSet.Q←F fin f
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
183 fiso← (FiniteSet→Fin fin) = FiniteSet.finiso← fin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
184 fiso→ (FiniteSet→Fin fin) = FiniteSet.finiso→ fin
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 fin-∨ : {A B : Set} → FiniteSet A → FiniteSet B → FiniteSet (A ∨ B)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 fin-∨ {A} {B} fa fb = iso-fin (fin-∨2 a fb ) iso2 where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 a = FiniteSet.finite fa
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 ia = FiniteSet→Fin fa
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
191 iso2 : Bijection (Fin a ∨ B ) (A ∨ B)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
192 fun← iso2 (case1 x) = case1 (fun← ia x )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
193 fun← iso2 (case2 x) = case2 x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
194 fun→ iso2 (case1 x) = case1 (fun→ ia x )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
195 fun→ iso2 (case2 x) = case2 x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
196 fiso← iso2 (case1 x) = cong ( λ k → case1 k ) (Bijection.fiso← ia x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
197 fiso← iso2 (case2 x) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
198 fiso→ iso2 (case1 x) = cong ( λ k → case1 k ) (Bijection.fiso→ ia x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
199 fiso→ iso2 (case2 x) = refl
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200
278
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
201 open import Data.Product hiding ( map )
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 fin-× : {A B : Set} → FiniteSet A → FiniteSet B → FiniteSet (A × B)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 fin-× {A} {B} fa fb with FiniteSet→Fin fa
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 ... | a=f = iso-fin (fin-×-f a ) iso-1 where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 a = FiniteSet.finite fa
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 b = FiniteSet.finite fb
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
208 iso-1 : Bijection (Fin a × B) ( A × B )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
209 fun← iso-1 x = ( FiniteSet.F←Q fa (proj₁ x) , proj₂ x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
210 fun→ iso-1 x = ( FiniteSet.Q←F fa (proj₁ x) , proj₂ x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
211 fiso← iso-1 x = lemma where
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 lemma : (FiniteSet.F←Q fa (FiniteSet.Q←F fa (proj₁ x)) , proj₂ x) ≡ ( proj₁ x , proj₂ x )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 lemma = cong ( λ k → ( k , proj₂ x ) ) (FiniteSet.finiso← fa _ )
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
214 fiso→ iso-1 x = cong ( λ k → ( k , proj₂ x ) ) (FiniteSet.finiso→ fa _ )
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
216 iso-2 : {a : ℕ } → Bijection (B ∨ (Fin a × B)) (Fin (suc a) × B)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
217 fun← iso-2 (zero , b ) = case1 b
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
218 fun← iso-2 (suc fst , b ) = case2 ( fst , b )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
219 fun→ iso-2 (case1 b) = ( zero , b )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
220 fun→ iso-2 (case2 (a , b )) = ( suc a , b )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
221 fiso← iso-2 (case1 x) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
222 fiso← iso-2 (case2 x) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
223 fiso→ iso-2 (zero , b ) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
224 fiso→ iso-2 (suc a , b ) = refl
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 fin-×-f : ( a : ℕ ) → FiniteSet ((Fin a) × B)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 fin-×-f zero = record { Q←F = λ () ; F←Q = λ () ; finiso→ = λ () ; finiso← = λ () ; finite = 0 }
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 fin-×-f (suc a) = iso-fin ( fin-∨ fb ( fin-×-f a ) ) iso-2
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 open _∧_
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 fin-∧ : {A B : Set} → FiniteSet A → FiniteSet B → FiniteSet (A ∧ B)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 fin-∧ {A} {B} fa fb with FiniteSet→Fin fa -- same thing for our tool
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 ... | a=f = iso-fin (fin-×-f a ) iso-1 where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 a = FiniteSet.finite fa
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 b = FiniteSet.finite fb
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
237 iso-1 : Bijection (Fin a ∧ B) ( A ∧ B )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
238 fun← iso-1 x = record { proj1 = FiniteSet.F←Q fa (proj1 x) ; proj2 = proj2 x}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
239 fun→ iso-1 x = record { proj1 = FiniteSet.Q←F fa (proj1 x) ; proj2 = proj2 x}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
240 fiso← iso-1 x = lemma where
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 lemma : record { proj1 = FiniteSet.F←Q fa (FiniteSet.Q←F fa (proj1 x)) ; proj2 = proj2 x} ≡ record {proj1 = proj1 x ; proj2 = proj2 x }
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 lemma = cong ( λ k → record {proj1 = k ; proj2 = proj2 x } ) (FiniteSet.finiso← fa _ )
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
243 fiso→ iso-1 x = cong ( λ k → record {proj1 = k ; proj2 = proj2 x } ) (FiniteSet.finiso→ fa _ )
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
245 iso-2 : {a : ℕ } → Bijection (B ∨ (Fin a ∧ B)) (Fin (suc a) ∧ B)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
246 fun← iso-2 (record { proj1 = zero ; proj2 = b }) = case1 b
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
247 fun← iso-2 (record { proj1 = suc fst ; proj2 = b }) = case2 ( record { proj1 = fst ; proj2 = b } )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
248 fun→ iso-2 (case1 b) = record {proj1 = zero ; proj2 = b }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
249 fun→ iso-2 (case2 (record { proj1 = a ; proj2 = b })) = record { proj1 = suc a ; proj2 = b }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
250 fiso← iso-2 (case1 x) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
251 fiso← iso-2 (case2 x) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
252 fiso→ iso-2 (record { proj1 = zero ; proj2 = b }) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
253 fiso→ iso-2 (record { proj1 = suc a ; proj2 = b }) = refl
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 fin-×-f : ( a : ℕ ) → FiniteSet ((Fin a) ∧ B)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 fin-×-f zero = record { Q←F = λ () ; F←Q = λ () ; finiso→ = λ () ; finiso← = λ () ; finite = 0 }
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 fin-×-f (suc a) = iso-fin ( fin-∨ fb ( fin-×-f a ) ) iso-2
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 -- import Data.Nat.DivMod
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260
278
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
261 open import Data.Vec hiding ( map ; length )
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 import Data.Product
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 exp2 : (n : ℕ ) → exp 2 (suc n) ≡ exp 2 n Data.Nat.+ exp 2 n
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 exp2 n = begin
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 exp 2 (suc n)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 ≡⟨⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 2 * ( exp 2 n )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 ≡⟨ *-comm 2 (exp 2 n) ⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 ( exp 2 n ) * 2
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 ≡⟨ *-suc ( exp 2 n ) 1 ⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 (exp 2 n ) Data.Nat.+ ( exp 2 n ) * 1
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 ≡⟨ cong ( λ k → (exp 2 n ) Data.Nat.+ k ) (proj₂ *-identity (exp 2 n) ) ⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 exp 2 n Data.Nat.+ exp 2 n
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 ∎ where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 open ≡-Reasoning
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 open Data.Product
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
278
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 cast-iso : {n m : ℕ } → (eq : n ≡ m ) → (f : Fin m ) → cast eq ( cast (sym eq ) f) ≡ f
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 cast-iso refl zero = refl
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 cast-iso refl (suc f) = cong ( λ k → suc k ) ( cast-iso refl f )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 fin2List : {n : ℕ } → FiniteSet (Vec Bool n)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 fin2List {zero} = record {
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 Q←F = λ _ → Vec.[]
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 ; F←Q = λ _ → # 0
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 ; finiso→ = finiso→
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 ; finiso← = finiso←
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 } where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 Q = Vec Bool zero
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 finiso→ : (q : Q) → [] ≡ q
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 finiso→ [] = refl
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 finiso← : (f : Fin (exp 2 zero)) → # 0 ≡ f
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 finiso← zero = refl
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 fin2List {suc n} = subst (λ k → FiniteSet (Vec Bool (suc n)) ) (sym (exp2 n)) ( iso-fin (fin-∨ (fin2List ) (fin2List )) iso )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 QtoR : Vec Bool (suc n) → Vec Bool n ∨ Vec Bool n
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 QtoR ( true ∷ x ) = case1 x
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 QtoR ( false ∷ x ) = case2 x
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 RtoQ : Vec Bool n ∨ Vec Bool n → Vec Bool (suc n)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 RtoQ ( case1 x ) = true ∷ x
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 RtoQ ( case2 x ) = false ∷ x
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 isoRQ : (x : Vec Bool (suc n) ) → RtoQ ( QtoR x ) ≡ x
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 isoRQ (true ∷ _ ) = refl
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 isoRQ (false ∷ _ ) = refl
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 isoQR : (x : Vec Bool n ∨ Vec Bool n ) → QtoR ( RtoQ x ) ≡ x
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 isoQR (case1 x) = refl
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 isoQR (case2 x) = refl
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
310 iso : Bijection (Vec Bool n ∨ Vec Bool n) (Vec Bool (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
311 iso = record { fun← = QtoR ; fun→ = RtoQ ; fiso← = isoQR ; fiso→ = isoRQ }
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 F2L : {Q : Set } {n : ℕ } → (fin : FiniteSet Q ) → n < suc (FiniteSet.finite fin) → ( (q : Q) → toℕ (FiniteSet.F←Q fin q ) < n → Bool ) → Vec Bool n
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 F2L {Q} {zero} fin _ Q→B = []
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 F2L {Q} {suc n} fin (s≤s n<m) Q→B = Q→B (FiniteSet.Q←F fin (fromℕ< n<m)) lemma6 ∷ F2L {Q} fin (NatP.<-trans n<m a<sa ) qb1 where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 lemma6 : toℕ (FiniteSet.F←Q fin (FiniteSet.Q←F fin (fromℕ< n<m))) < suc n
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 lemma6 = subst (λ k → toℕ k < suc n ) (sym (FiniteSet.finiso← fin _ )) (subst (λ k → k < suc n) (sym (toℕ-fromℕ< n<m )) a<sa )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 qb1 : (q : Q) → toℕ (FiniteSet.F←Q fin q) < n → Bool
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 qb1 q q<n = Q→B q (NatP.<-trans q<n a<sa)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 List2Func : { Q : Set } → {n : ℕ } → (fin : FiniteSet Q ) → n < suc (FiniteSet.finite fin) → Vec Bool n → Q → Bool
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 List2Func {Q} {zero} fin (s≤s z≤n) [] q = false
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 List2Func {Q} {suc n} fin (s≤s n<m) (h ∷ t) q with FiniteSet.F←Q fin q ≟ fromℕ< n<m
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 ... | yes _ = h
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 ... | no _ = List2Func {Q} fin (NatP.<-trans n<m a<sa ) t q
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 open import Level renaming ( suc to Suc ; zero to Zero)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 open import Axiom.Extensionality.Propositional
268
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 264
diff changeset
329 -- postulate f-extensionality : { n : Level} → Axiom.Extensionality.Propositional.Extensionality n n
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 F2L-iso : { Q : Set } → (fin : FiniteSet Q ) → (x : Vec Bool (FiniteSet.finite fin) ) → F2L fin a<sa (λ q _ → List2Func fin a<sa x q ) ≡ x
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 F2L-iso {Q} fin x = f2l m a<sa x where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 m = FiniteSet.finite fin
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 f2l : (n : ℕ ) → (n<m : n < suc m )→ (x : Vec Bool n ) → F2L fin n<m (λ q q<n → List2Func fin n<m x q ) ≡ x
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 f2l zero (s≤s z≤n) [] = refl
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
336 f2l (suc n) (s≤s n<m) (h ∷ t ) = lemma1 lemma2 lemma3f where
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 lemma1 : {n : ℕ } → {h h1 : Bool } → {t t1 : Vec Bool n } → h ≡ h1 → t ≡ t1 → h ∷ t ≡ h1 ∷ t1
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 lemma1 refl refl = refl
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 lemma2 : List2Func fin (s≤s n<m) (h ∷ t) (FiniteSet.Q←F fin (fromℕ< n<m)) ≡ h
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 lemma2 with FiniteSet.F←Q fin (FiniteSet.Q←F fin (fromℕ< n<m)) ≟ fromℕ< n<m
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 lemma2 | yes p = refl
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 lemma2 | no ¬p = ⊥-elim ( ¬p (FiniteSet.finiso← fin _) )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 lemma4 : (q : Q ) → toℕ (FiniteSet.F←Q fin q ) < n → List2Func fin (s≤s n<m) (h ∷ t) q ≡ List2Func fin (NatP.<-trans n<m a<sa) t q
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 lemma4 q _ with FiniteSet.F←Q fin q ≟ fromℕ< n<m
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 lemma4 q lt | yes p = ⊥-elim ( nat-≡< (toℕ-fromℕ< n<m) (lemma5 n lt (cong (λ k → toℕ k) p))) where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 lemma5 : {j k : ℕ } → ( n : ℕ) → suc j ≤ n → j ≡ k → k < n
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 lemma5 {zero} (suc n) (s≤s z≤n) refl = s≤s z≤n
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 lemma5 {suc j} (suc n) (s≤s lt) refl = s≤s (lemma5 {j} n lt refl)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 lemma4 q _ | no ¬p = refl
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
350 lemma3f : F2L fin (NatP.<-trans n<m a<sa) (λ q q<n → List2Func fin (s≤s n<m) (h ∷ t) q ) ≡ t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
351 lemma3f = begin
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 F2L fin (NatP.<-trans n<m a<sa) (λ q q<n → List2Func fin (s≤s n<m) (h ∷ t) q )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 ≡⟨ cong (λ k → F2L fin (NatP.<-trans n<m a<sa) ( λ q q<n → k q q<n ))
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 (f-extensionality ( λ q →
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 (f-extensionality ( λ q<n → lemma4 q q<n )))) ⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 F2L fin (NatP.<-trans n<m a<sa) (λ q q<n → List2Func fin (NatP.<-trans n<m a<sa) t q )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 ≡⟨ f2l n (NatP.<-trans n<m a<sa ) t ⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 t
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 ∎ where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 open ≡-Reasoning
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 L2F : {Q : Set } {n : ℕ } → (fin : FiniteSet Q ) → n < suc (FiniteSet.finite fin) → Vec Bool n → (q : Q ) → toℕ (FiniteSet.F←Q fin q ) < n → Bool
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 L2F fin n<m x q q<n = List2Func fin n<m x q
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 L2F-iso : { Q : Set } → (fin : FiniteSet Q ) → (f : Q → Bool ) → (q : Q ) → (L2F fin a<sa (F2L fin a<sa (λ q _ → f q) )) q (toℕ<n _) ≡ f q
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 L2F-iso {Q} fin f q = l2f m a<sa (toℕ<n _) where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 m = FiniteSet.finite fin
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
369 lemma11f : {n : ℕ } → (n<m : n < m ) → ¬ ( FiniteSet.F←Q fin q ≡ fromℕ< n<m ) → toℕ (FiniteSet.F←Q fin q) ≤ n → toℕ (FiniteSet.F←Q fin q) < n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
370 lemma11f n<m ¬q=n q≤n = lemma13 n<m (contra-position (lemma12 n<m _) ¬q=n ) q≤n where
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 lemma13 : {n nq : ℕ } → (n<m : n < m ) → ¬ ( nq ≡ n ) → nq ≤ n → nq < n
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 lemma13 {0} {0} (s≤s z≤n) nt z≤n = ⊥-elim ( nt refl )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 lemma13 {suc _} {0} (s≤s (s≤s n<m)) nt z≤n = s≤s z≤n
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 lemma13 {suc n} {suc nq} n<m nt (s≤s nq≤n) = s≤s (lemma13 {n} {nq} (NatP.<-trans a<sa n<m ) (λ eq → nt ( cong ( λ k → suc k ) eq )) nq≤n)
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
375 lemma3f : {a b : ℕ } → (lt : a < b ) → fromℕ< (s≤s lt) ≡ suc (fromℕ< lt)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
376 lemma3f (s≤s lt) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
377 lemma12f : {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: 141
diff changeset
378 lemma12f {zero} {suc m} (s≤s z≤n) zero refl = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
379 lemma12f {suc n} {suc m} (s≤s n<m) (suc f) refl = subst ( λ k → suc f ≡ k ) (sym (lemma3f n<m) ) ( cong ( λ k → suc k ) ( lemma12f {n} {m} n<m f refl ) )
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 l2f : (n : ℕ ) → (n<m : n < suc m ) → (q<n : toℕ (FiniteSet.F←Q fin q ) < n ) → (L2F fin n<m (F2L fin n<m (λ q _ → f q))) q q<n ≡ f q
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 l2f zero (s≤s z≤n) ()
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 l2f (suc n) (s≤s n<m) (s≤s n<q) with FiniteSet.F←Q fin q ≟ fromℕ< n<m
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 l2f (suc n) (s≤s n<m) (s≤s n<q) | yes p = begin
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 f (FiniteSet.Q←F fin (fromℕ< n<m))
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 ≡⟨ cong ( λ k → f (FiniteSet.Q←F fin k )) (sym p) ⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 f (FiniteSet.Q←F fin ( FiniteSet.F←Q fin q ))
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 ≡⟨ cong ( λ k → f k ) (FiniteSet.finiso→ fin _ ) ⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 f q
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 ∎ where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 open ≡-Reasoning
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
391 l2f (suc n) (s≤s n<m) (s≤s n<q) | no ¬p = l2f n (NatP.<-trans n<m a<sa) (lemma11f n<m ¬p n<q)
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
392
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 fin→ : {A : Set} → FiniteSet A → FiniteSet (A → Bool )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 fin→ {A} fin = iso-fin fin2List iso where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 a = FiniteSet.finite fin
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
396 iso : Bijection (Vec Bool a ) (A → Bool)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
397 fun← iso x = F2L fin a<sa ( λ q _ → x q )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
398 fun→ iso x = List2Func fin a<sa x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
399 fiso← iso x = F2L-iso fin x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
400 fiso→ iso x = lemma where
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 lemma : List2Func fin a<sa (F2L fin a<sa (λ q _ → x q)) ≡ x
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 lemma = f-extensionality ( λ q → L2F-iso fin x q )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
403
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
404
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 Fin2Finite : ( n : ℕ ) → FiniteSet (Fin n)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 Fin2Finite n = record { F←Q = λ x → x ; Q←F = λ x → x ; finiso← = λ q → refl ; finiso→ = λ q → refl }
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
407
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 data fin-less { n : ℕ } { A : Set } (fa : FiniteSet A ) (n<m : n < FiniteSet.finite fa ) : Set where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 elm1 : (elm : A ) → toℕ (FiniteSet.F←Q fa elm ) < n → fin-less fa n<m
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
410
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 get-elm : { n : ℕ } { A : Set } {fa : FiniteSet A } {n<m : n < FiniteSet.finite fa } → fin-less fa n<m → A
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 get-elm (elm1 a _ ) = a
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
413
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 get-< : { n : ℕ } { A : Set } {fa : FiniteSet A } {n<m : n < FiniteSet.finite fa }→ (f : fin-less fa n<m ) → toℕ (FiniteSet.F←Q fa (get-elm f )) < n
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 get-< (elm1 _ b ) = b
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
416
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 fin-less-cong : { n : ℕ } { A : Set } (fa : FiniteSet A ) (n<m : n < FiniteSet.finite fa )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 → (x y : fin-less fa n<m ) → get-elm {n} {A} {fa} x ≡ get-elm {n} {A} {fa} y → get-< x ≅ get-< y → x ≡ y
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 fin-less-cong fa n<m (elm1 elm x) (elm1 elm x) refl HE.refl = refl
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
420
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 fin-< : {A : Set} → { n : ℕ } → (fa : FiniteSet A ) → (n<m : n < FiniteSet.finite fa ) → FiniteSet (fin-less fa n<m )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 fin-< {A} {n} fa n<m = iso-fin (Fin2Finite n) iso where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 m = FiniteSet.finite fa
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
424 iso : Bijection (Fin n) (fin-less fa n<m )
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
425 lemma8f : {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: 141
diff changeset
426 lemma8f {zero} {zero} {suc n} refl {s≤s z≤n} {s≤s z≤n} = HE.refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
427 lemma8f {suc i} {suc i} {suc n} refl {s≤s i<n} {s≤s j<n} = HE.cong (λ k → s≤s k ) ( lemma8f {i} {i} refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
428 lemma10f : {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: 141
diff changeset
429 lemma10f refl = HE.≅-to-≡ (HE.cong (λ k → fromℕ< k ) (lemma8f refl ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
430 lemma3f : {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: 141
diff changeset
431 lemma3f {a} {b} {c} {a<b} {b<c} {a<c} = HE.≅-to-≡ (lemma8f refl)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
432 lemma11f : {n : ℕ } {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: 141
diff changeset
433 lemma11f {n} {x} n<m = begin
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 toℕ (fromℕ< (NatP.<-trans (toℕ<n x) n<m))
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 ≡⟨ toℕ-fromℕ< _ ⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 toℕ x
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 ∎ where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 open ≡-Reasoning
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
439 fun← iso (elm1 elm x) = fromℕ< x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
440 fun→ iso x = elm1 (FiniteSet.Q←F fa (fromℕ< (NatP.<-trans x<n n<m ))) to<n where
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 x<n : toℕ x < n
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 x<n = toℕ<n x
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 to<n : toℕ (FiniteSet.F←Q fa (FiniteSet.Q←F fa (fromℕ< (NatP.<-trans x<n n<m)))) < n
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 to<n = subst (λ k → toℕ k < n ) (sym (FiniteSet.finiso← fa _ )) (subst (λ k → k < n ) (sym ( toℕ-fromℕ< (NatP.<-trans x<n n<m) )) x<n )
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
445 fiso← iso x = lemma2 where
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 lemma2 : fromℕ< (subst (λ k → toℕ k < n) (sym
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 (FiniteSet.finiso← fa (fromℕ< (NatP.<-trans (toℕ<n x) n<m)))) (subst (λ k → k < n)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 (sym (toℕ-fromℕ< (NatP.<-trans (toℕ<n x) n<m))) (toℕ<n x))) ≡ x
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 lemma2 = begin
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 fromℕ< (subst (λ k → toℕ k < n) (sym
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 (FiniteSet.finiso← fa (fromℕ< (NatP.<-trans (toℕ<n x) n<m)))) (subst (λ k → k < n)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 (sym (toℕ-fromℕ< (NatP.<-trans (toℕ<n x) n<m))) (toℕ<n x)))
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 ≡⟨⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 fromℕ< ( subst (λ k → toℕ ( k ) < n ) (sym (FiniteSet.finiso← fa _ )) lemma6 )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 ≡⟨ lemma10 (cong (λ k → toℕ k) (FiniteSet.finiso← fa _ ) ) ⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 fromℕ< lemma6
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 ≡⟨ lemma10 (lemma11 n<m ) ⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 fromℕ< ( toℕ<n x )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 ≡⟨ fromℕ<-toℕ _ _ ⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 x
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 ∎ where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 open ≡-Reasoning
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 lemma6 : toℕ (fromℕ< (NatP.<-trans (toℕ<n x) n<m)) < n
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 lemma6 = subst ( λ k → k < n ) (sym (toℕ-fromℕ< (NatP.<-trans (toℕ<n x) n<m))) (toℕ<n x )
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
465 fiso→ iso (elm1 elm x) = fin-less-cong fa n<m _ _ lemma (lemma8 (cong (λ k → toℕ (FiniteSet.F←Q fa k) ) lemma ) ) where
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 lemma13 : toℕ (fromℕ< x) ≡ toℕ (FiniteSet.F←Q fa elm)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 lemma13 = begin
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 toℕ (fromℕ< x)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 ≡⟨ toℕ-fromℕ< _ ⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 toℕ (FiniteSet.F←Q fa elm)
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 ∎ where open ≡-Reasoning
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
472 lemma : FiniteSet.Q←F fa (fromℕ< (NatP.<-trans (toℕ<n (Bijection.fun← iso (elm1 elm x))) n<m)) ≡ elm
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 lemma = begin
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
474 FiniteSet.Q←F fa (fromℕ< (NatP.<-trans (toℕ<n (Bijection.fun← iso (elm1 elm x))) n<m))
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 ≡⟨⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 FiniteSet.Q←F fa (fromℕ< ( NatP.<-trans (toℕ<n ( fromℕ< x ) ) n<m))
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
477 ≡⟨ cong (λ k → FiniteSet.Q←F fa k) (lemma10 lemma13 ) ⟩
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 FiniteSet.Q←F fa (fromℕ< ( NatP.<-trans x n<m))
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
479 ≡⟨ cong (λ k → FiniteSet.Q←F fa (fromℕ< k )) (HE.≅-to-≡ (lemma8 refl)) ⟩
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 FiniteSet.Q←F fa (fromℕ< ( toℕ<n (FiniteSet.F←Q fa elm)))
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 ≡⟨ cong (λ k → FiniteSet.Q←F fa k ) ( fromℕ<-toℕ _ _ ) ⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 FiniteSet.Q←F fa (FiniteSet.F←Q fa elm )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 ≡⟨ FiniteSet.finiso→ fa _ ⟩
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 elm
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 ∎ where open ≡-Reasoning
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
486
278
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
487 open import Data.List
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
488
278
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
489 open FiniteSet
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
490
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
491 memberQ : { Q : Set } (finq : FiniteSet Q) (q : Q) (qs : List Q ) → Bool
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
492 memberQ {Q} finq q [] = false
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
493 memberQ {Q} finq q (q0 ∷ qs) with equal? finq q q0
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
494 ... | true = true
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
495 ... | false = memberQ finq q qs
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
496
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
497 phase2 : { Q : Set } (finq : FiniteSet Q) (q : Q) (qs : List Q ) → Bool
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
498 phase2 finq q [] = false
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
499 phase2 finq q (x ∷ qs) with equal? finq q x
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
500 ... | true = true
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
501 ... | false = phase2 finq q qs
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
502 phase1 : { Q : Set } (finq : FiniteSet Q) (q : Q) (qs : List Q ) → Bool
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
503 phase1 finq q [] = false
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
504 phase1 finq q (x ∷ qs) with equal? finq q x
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
505 ... | true = phase2 finq q qs
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
506 ... | false = phase1 finq q qs
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
507
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
508 dup-in-list : { Q : Set } (finq : FiniteSet Q) (q : Q) (qs : List Q ) → Bool
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
509 dup-in-list {Q} finq q qs = phase1 finq q qs
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
510
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
511
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
512 dup-in-list+1 : { Q : Set } (finq : FiniteSet Q)
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
513 → (q : Q) (qs : List Q ) → dup-in-list finq q qs ≡ true
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
514 → dup-in-list (fin-∨1 finq) (case2 q) (map case2 qs ) ≡ true
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
515 dup-in-list+1 {Q} finq q qs p = 1-phase1 qs p where
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
516 dup04 : {q x : Q} → equal? finq q x ≡ equal? (fin-∨1 finq) (case2 q) (case2 x)
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
517 dup04 {q} {x} with F←Q finq q f≟ F←Q finq x
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
518 ... | yes _ = refl
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
519 ... | no _ = refl
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
520 1-phase2 : (qs : List Q) → phase2 finq q qs ≡ true → phase2 (fin-∨1 finq) (case2 q) (map case2 qs ) ≡ true
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
521 1-phase2 (x ∷ qs ) p with equal? finq q x | equal? (fin-∨1 finq) (case2 q) (case2 x) | dup04 {q} {x}
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
522 ... | true | true | t = refl
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
523 ... | false | false | t = 1-phase2 qs p
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
524 1-phase1 : (qs : List Q) → phase1 finq q qs ≡ true → phase1 (fin-∨1 finq) (case2 q) (map case2 qs ) ≡ true
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
525 1-phase1 (x ∷ qs ) p with equal? finq q x | equal? (fin-∨1 finq) (case2 q) (case2 x) | dup04 {q} {x}
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
526 ... | true | true | t = 1-phase2 qs p
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
527 ... | false | false | t = 1-phase1 qs p
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
528
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
529 dup-in-list+iso : { Q : Set } (finq : FiniteSet Q)
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
530 → (q : Q) (qs : List Q )
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
531 → dup-in-list (Fin2Finite (finite finq)) (F←Q finq q) (map (F←Q finq) qs) ≡ true
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
532 → dup-in-list finq q qs ≡ true
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
533 dup-in-list+iso {Q} finq q qs p = i-phase1 qs p where
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
534 dup05 : {q x : Q} → equal? finq q x ≡ equal? (Fin2Finite (finite finq)) (F←Q finq q) (F←Q finq x)
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
535 dup05 {q} {x} with F←Q finq q f≟ F←Q finq x
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
536 ... | yes _ = refl
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
537 ... | no _ = refl
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
538 i-phase2 : (qs : List Q) → phase2 (Fin2Finite (finite finq)) (F←Q finq q) (map (F←Q finq) qs) ≡ true
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
539 → phase2 finq q qs ≡ true
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
540 i-phase2 (x ∷ qs) p with equal? finq q x | equal? (Fin2Finite (finite finq)) (F←Q finq q) (F←Q finq x) | dup05 {q} {x}
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
541 ... | true | true | t2 = refl
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
542 ... | false | false | t2 = i-phase2 qs p
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
543 i-phase1 : (qs : List Q) → dup-in-list (Fin2Finite (finite finq)) (F←Q finq q) (map (F←Q finq) qs) ≡ true
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
544 → phase1 finq q qs ≡ true
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
545 i-phase1 (x ∷ qs) p with equal? finq q x | equal? (Fin2Finite (finite finq)) (F←Q finq q) (F←Q finq x) | dup05 {q} {x}
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
546 ... | true | true | t2 = i-phase2 qs p
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
547 ... | false | false | t2 = i-phase1 qs p
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
548
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
549 record Dup-in-list {Q : Set } (finq : FiniteSet Q) (qs : List Q) : Set where
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
550 field
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
551 dup : Q
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
552 is-dup : dup-in-list finq dup qs ≡ true
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
553
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
554
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
555 dup-in-list>n : {Q : Set } → (finq : FiniteSet Q) → (qs : List Q) → (len> : length qs > finite finq ) → Dup-in-list finq qs
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
556 dup-in-list>n {Q} finq qs lt = record {
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
557 dup = dup-05
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
558 ; is-dup = dup-in-list+iso finq dup-05 qs dup-06 } where
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
559 LEM-dup : Dup-in-list finq qs ∨ ( ¬ Dup-in-list finq qs )
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
560 LEM-dup with exists finq ( λ q → dup-in-list finq q qs ) | inspect (exists finq) ( λ q → dup-in-list finq q qs )
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
561 ... | true | record { eq = eq1 } = case1 ( record { dup = Found.found-q dup-01 ; is-dup = Found.found-p dup-01} ) where
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
562 dup-01 : Found Q ( λ q → dup-in-list finq q qs )
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
563 dup-01 = found← finq eq1
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
564 ... | false | record { eq = eq1 } = case2 (λ D → ¬-bool ( not-found← finq eq1 (Dup-in-list.dup D)) (Dup-in-list.is-dup D) )
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
565 record NList (n : ℕ) : Set where
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
566 field
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
567 ls : List (Fin n)
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
568 ls>n : length ls > n
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
569 dup-02 : (n : ℕ) → (ls : NList n ) → Dup-in-list (Fin2Finite n) (NList.ls ls)
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
570 dup-02 zero ls = {!!}
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
571 dup-02 (suc n) ls = dup-03 where
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
572 n1 : Fin (suc n)
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
573 n1 = fromℕ< refl-≤
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
574 d-phase2 : (qs : List (Fin (suc n)) ) → NList n ∨ ( phase2 (Fin2Finite (suc n)) n1 qs ≡ true )
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
575 d-phase2 [] = {!!}
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
576 d-phase2 (x ∷ qs) with equal? (Fin2Finite (suc n)) n1 x
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
577 ... | true = case2 refl
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
578 ... | false with d-phase2 qs
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
579 ... | case1 p = case1 record { ls = {!!} ∷ NList.ls p ; ls>n = {!!} }
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
580 ... | case2 eq = case2 eq
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
581 d-phase1 : (qs : List (Fin (suc n)) ) → NList n ∨ ( phase1 (Fin2Finite (suc n)) n1 qs ≡ true )
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
582 d-phase1 [] = {!!}
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
583 d-phase1 (x ∷ qs) with equal? (Fin2Finite (suc n)) n1 x
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
584 ... | true with d-phase2 qs
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
585 ... | case1 p = case1 record { ls = {!!} ∷ NList.ls p ; ls>n = {!!} }
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
586 ... | case2 eq = case2 eq
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
587 d-phase1 (x ∷ qs) | false with d-phase1 qs
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
588 ... | case1 p = case1 record { ls = {!!} ∷ NList.ls p ; ls>n = {!!} }
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
589 ... | case2 eq = case2 eq
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
590 dup-03 : Dup-in-list (Fin2Finite (suc n)) (NList.ls ls)
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
591 dup-03 with d-phase1 (NList.ls ls)
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
592 ... | case1 ls1 = record { dup = fin+1 (Dup-in-list.dup dup-04) ; is-dup = dup-07 } where
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
593 dup-04 : Dup-in-list (Fin2Finite n) (NList.ls ls1)
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
594 dup-04 = dup-02 n ls1
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
595 dup-07 : dup-in-list (Fin2Finite (suc n)) (fin+1 (Dup-in-list.dup dup-04)) (NList.ls ls) ≡ true
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
596 dup-07 = dup-in-list+iso finq {!!} {!!} (dup-in-list+1 {!!} {!!} qs {!!})
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
597 ... | case2 dup = record { dup = n1 ; is-dup = dup }
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
598 dup-05 : Q
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
599 dup-05 = Q←F finq (Dup-in-list.dup (dup-02 (finite finq) record { ls = map (F←Q finq) qs ; ls>n = {!!} } ))
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
600 dup-06 : dup-in-list (Fin2Finite (finite finq)) (F←Q finq dup-05) (map (F←Q finq) qs) ≡ true
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
601 dup-06 = subst (λ k → dup-in-list (Fin2Finite (finite finq)) k (map (F←Q finq) qs) ≡ true )
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
602 {!!} (Dup-in-list.is-dup (dup-02 (finite finq) record { ls = map (F←Q finq) qs ; ls>n = {!!} } ) )
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
603