annotate automaton-in-agda/src/libbijection.agda @ 285:6e85b8b0d8db

remove ls<n
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 28 Dec 2021 00:28:29 +0900
parents d1e8e5eadc38
children cd73fe566291
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
1 module libbijection where
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 open import Level renaming ( zero to Zero ; suc to Suc )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 open import Data.Nat
142
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
5 open import Data.Maybe
256
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
6 open import Data.List hiding ([_] ; sum )
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 open import Data.Nat.Properties
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import Relation.Nullary
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import Data.Empty
256
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
10 open import Data.Unit hiding ( _≤_ )
142
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
11 open import Relation.Binary.Core hiding (_⇔_)
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 open import Relation.Binary.Definitions
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 open import Relation.Binary.PropositionalEquality
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
14 open import Function.Inverse hiding (sym)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
15 open import Function.Bijection renaming (Bijection to Bijection1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
16 open import Function.Equality hiding (cong)
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 open import logic
256
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
19 open import nat
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
21 -- record Bijection {n m : Level} (R : Set n) (S : Set m) : Set (n Level.⊔ m) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
22 -- field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
23 -- fun← : S → R
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
24 -- fun→ : R → S
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
25 -- fiso← : (x : R) → fun← ( fun→ x ) ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
26 -- fiso→ : (x : S ) → fun→ ( fun← x ) ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
27 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
28 -- injection : {n m : Level} (R : Set n) (S : Set m) (f : R → S ) → Set (n Level.⊔ m)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
29 -- injection R S f = (x y : R) → f x ≡ f y → x ≡ y
164
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
30
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 open Bijection
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
33 b→injection1 : {n m : Level} (R : Set n) (S : Set m) → (b : Bijection R S) → injection S R (fun← b)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
34 b→injection1 R S b x y eq = trans ( sym ( fiso→ b x ) ) (trans ( cong (λ k → fun→ b k ) eq ) ( fiso→ b y ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
35
263
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 262
diff changeset
36 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 262
diff changeset
37 -- injection as an uniquneness of bijection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 262
diff changeset
38 --
164
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
39 b→injection0 : {n m : Level} (R : Set n) (S : Set m) → (b : Bijection R S) → injection R S (fun→ b)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
40 b→injection0 R S b x y eq = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
41 x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
42 ≡⟨ sym ( fiso← b x ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
43 fun← b ( fun→ b x )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
44 ≡⟨ cong (λ k → fun← b k ) eq ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
45 fun← b ( fun→ b y )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
46 ≡⟨ fiso← b y ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
47 y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
48 ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
49
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
50 open import Relation.Binary using (Rel; Setoid; Symmetric; Total)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
51 open import Function.Surjection
263
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 262
diff changeset
52
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
53 ≡-Setoid : {n : Level} (R : Set n) → Setoid n n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
54 ≡-Setoid R = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
55 Carrier = R
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
56 ; _≈_ = _≡_
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
57 ; isEquivalence = record { sym = sym ; refl = refl ; trans = trans }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
58 }
256
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
59
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
60
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
61 libBijection : {n m : Level} (R : Set n) (S : Set m) → Bijection R S → Bijection1 (≡-Setoid R) (≡-Setoid S)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
62 libBijection R S b = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
63 to = record { _⟨$⟩_ = λ x → fun→ b x ; cong = λ i=j → cong (fun→ b) i=j }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
64 ; bijective = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
65 injective = λ {x} {y} eq → b→injection0 R S b x y eq
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
66 ; surjective = record { from = record { _⟨$⟩_ = λ x → fun← b x ; cong = λ i=j → cong (fun← b) i=j }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
67 ; right-inverse-of = λ x → fiso→ b x }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
68 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
69 }
256
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
70
264
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
71 fromBijection1 : {n m : Level} (R : Set n) (S : Set m) → Bijection1 (≡-Setoid R) (≡-Setoid S) → Bijection R S
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
72 fromBijection1 R S b = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
73 fun← = Π._⟨$⟩_ (Surjective.from (Bijective.surjective (Bijection1.bijective b)))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
74 ; fun→ = Π._⟨$⟩_ (Bijection1.to b)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
75 ; fiso← = λ x → Bijective.injective (Bijection1.bijective b) (fb1 x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
76 ; fiso→ = Surjective.right-inverse-of (Bijective.surjective (Bijection1.bijective b))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
77 } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
78 -- fun← b x ≡ fun← b y → x ≡ y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
79 -- fun← (fun→ ( fun← x )) ≡ fun← x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
80 -- fun→ ( fun← x ) ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
81 fb1 : (x : R) → Π._⟨$⟩_ (Bijection1.to b) (Surjective.from (Bijective.surjective (Bijection1.bijective b)) ⟨$⟩ (Bijection1.to b ⟨$⟩ x)) ≡ Π._⟨$⟩_ (Bijection1.to b) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
82 fb1 x = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
83 Π._⟨$⟩_ (Bijection1.to b) (Surjective.from (Bijective.surjective (Bijection1.bijective b)) ⟨$⟩ (Bijection1.to b ⟨$⟩ x))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
84 ≡⟨ Surjective.right-inverse-of (Bijective.surjective (Bijection1.bijective b)) _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 263
diff changeset
85 Π._⟨$⟩_ (Bijection1.to b) x ∎ where open ≡-Reasoning
260
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
86