forked from crypto-agda/crypto-agda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircuit-fun-universe.agda
55 lines (51 loc) · 2.03 KB
/
circuit-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
open import Type
open import Data.Nat using (ℕ; _+_)
open import Data.Bits using (Bits)
open import Data.Fin using (Fin)
open import data-universe
module circuit-fun-universe where
infix 0 _⌥_
data _⌥_ : ℕ → ℕ → ★ where
rewire : ∀ {i o} → (Fin o → Fin i) → i ⌥ o
-- cost: 0 time, o space
_∘_ : ∀ {m n o} → (n ⌥ o) → (m ⌥ n) → (m ⌥ o)
-- cost: sum time and space
<_×_> : ∀ {m n o p} → (m ⌥ o) → (n ⌥ p) → (m + n) ⌥ (o + p)
-- cost: max time and sum space
cond : ∀ {n} → (1 + (n + n)) ⌥ n
-- cost: 1 time, 1 space
bits : ∀ {n _⊤} → Bits n → _⊤ ⌥ n
-- cost: 0 time, n space
xor : ∀ {n} → Bits n → n ⌥ n
-- cost: 1 time, n space
{- derived rewiring
id : ∀ {A} → A `→ A
dup : ∀ {A} → A `→ A `× A
fst : ∀ {A B} → A `× B `→ A
snd : ∀ {A B} → A `× B `→ B
swap : ∀ {A B} → (A `× B) `→ (B `× A)
assoc : ∀ {A B C} → ((A `× B) `× C) `→ (A `× (B `× C))
tt : ∀ {_⊤} → _⊤ `→ `⊤
<[]> : ∀ {_⊤ A} → _⊤ `→ `Vec A 0
<∷> : ∀ {n A} → (A `× `Vec A n) `→ `Vec A (1 + n)
uncons : ∀ {n A} → `Vec A (1 + n) `→ (A `× `Vec A n)
<tt,id> : ∀ {A} → A `→ `⊤ `× A
snd<tt,> : ∀ {A} → `⊤ `× A `→ A
tt→[] : ∀ {A} → `⊤ `→ `Vec A 0
[]→tt : ∀ {A} → `Vec A 0 `→ `⊤
rewireTbl : ∀ {i o} → RewireTbl i o → `Bits i `→ `Bits o
-}
{- derived from <_×_> and id:
first : ∀ {A B C} → (A `→ C) → (A `× B) `→ (C `× B)
second : ∀ {A B C} → (B `→ C) → (A `× B) `→ (A `× C)
-}
{- derived from <_×_> and dup:
<_,_> : ∀ {A B C} → (A `→ B) → (A `→ C) → A `→ B `× C
-}
{- derived from cond:
bijFork : ∀ {A B} (f g : A `→ B) → `Bit `× A `→ `Bit `× B
fork : ∀ {A B} (f g : A `→ B) → `Bit `× A `→ B
-}
{- derived from bits
<0b> <1b> : ∀ {_⊤} → _⊤ `→ `Bit
-}