forked from crypto-agda/crypto-agda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inverse-fun-universe.agda
74 lines (54 loc) · 2.13 KB
/
inverse-fun-universe.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
open import fun-universe
open import Data.Nat
module inverse-fun-universe {t} {T : Set t}
(funU : FunUniverse T)
(bijU : Bijective funU) where
opU : FunUniverse T
opU = OpFunU.opFunU funU
open FunUniverse opU
invLinRewiring : LinRewiring funU → LinRewiring opU
invLinRewiring linRewiring = mk id _∘_ first swap assoc <tt,id> snd<tt,>
<_×_> second tt→[] []→tt <∷> uncons
where
module L = LinRewiring linRewiring
-- Functions
id : ∀ {A} → A `→ A
id = L.id
_∘_ : ∀ {A B C} → (B `→ C) → (A `→ B) → (A `→ C)
f ∘ g = g L.∘ f
-- Products (group 2 primitive functions or derived from group 1)
first : ∀ {A B C} → (A `→ C) → (A `× B) `→ (C `× B)
first f = L.first f
swap : ∀ {A B} → (A `× B) `→ (B `× A)
swap = L.swap
assoc : ∀ {A B C} → ((A `× B) `× C) `→ (A `× (B `× C))
assoc = L.assoc′
<tt,id> : ∀ {A} → A `→ `⊤ `× A
<tt,id> = L.snd<tt,>
snd<tt,> : ∀ {A} → `⊤ `× A `→ A
snd<tt,> = L.<tt,id>
-- Products (derived from group 1 or 2)
<_×_> : ∀ {A B C D} → (A `→ C) → (B `→ D) → (A `× B) `→ (C `× D)
< f × g > = L.< f × g >
second : ∀ {A B C} → (B `→ C) → (A `× B) `→ (A `× C)
second f = L.second f
-- Vectors
tt→[] : ∀ {A} → `⊤ `→ `Vec A 0
tt→[] = L.[]→tt
[]→tt : ∀ {A} → `Vec A 0 `→ `⊤
[]→tt = L.tt→[]
<∷> : ∀ {n A} → (A `× `Vec A n) `→ `Vec A (1 + n)
<∷> = L.uncons
uncons : ∀ {n A} → `Vec A (1 + n) `→ (A `× `Vec A n)
uncons = L.<∷>
invHasBijFork : HasBijFork funU → HasBijFork opU
invHasBijFork hasBijFork = mk F.bijFork
where module F = HasBijFork hasBijFork
invHasXor : HasXor funU → HasXor opU
invHasXor hasXor = mk H.⟨⊕_⟩
where module H = HasXor hasXor
invU : Bijective funU → Bijective opU
invU bijective = mk (invLinRewiring linRewiring)
(invHasBijFork hasBijFork)
(invHasXor hasXor)
where open Bijective bijective