-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ip.agda
118 lines (87 loc) · 2.54 KB
/
Ip.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
-- Intuitionistic propositional logic, de Bruijn approach, final encoding
module Bf.Ip where
open import Lib using (List; _,_; LMem; lzero; lsuc)
-- Types
infixl 2 _&&_
infixl 1 _||_
infixr 0 _=>_
data Ty : Set where
UNIT : Ty
_=>_ : Ty -> Ty -> Ty
_&&_ : Ty -> Ty -> Ty
_||_ : Ty -> Ty -> Ty
FALSE : Ty
infixr 0 _<=>_
_<=>_ : Ty -> Ty -> Ty
a <=> b = (a => b) && (b => a)
NOT : Ty -> Ty
NOT a = a => FALSE
TRUE : Ty
TRUE = FALSE => FALSE
-- Context and truth judgement
Cx : Set
Cx = List Ty
isTrue : Ty -> Cx -> Set
isTrue a tc = LMem a tc
-- Terms
TmRepr : Set1
TmRepr = Cx -> Ty -> Set
module ArrMp where
record Tm (tr : TmRepr) : Set1 where
infixl 1 _$_
infixr 0 lam=>_
field
var : forall {tc a} -> isTrue a tc -> tr tc a
lam=>_ : forall {tc a b} -> tr (tc , a) b -> tr tc (a => b)
_$_ : forall {tc a b} -> tr tc (a => b) -> tr tc a -> tr tc b
v0 : forall {tc a} -> tr (tc , a) a
v0 = var lzero
v1 : forall {tc a b} -> tr (tc , a , b) a
v1 = var (lsuc lzero)
v2 : forall {tc a b c} -> tr (tc , a , b , c) a
v2 = var (lsuc (lsuc lzero))
open Tm {{...}} public
module Mp where
record Tm (tr : TmRepr) : Set1 where
field
pair' : forall {tc a b} -> tr tc a -> tr tc b -> tr tc (a && b)
fst : forall {tc a b} -> tr tc (a && b) -> tr tc a
snd : forall {tc a b} -> tr tc (a && b) -> tr tc b
left : forall {tc a b} -> tr tc a -> tr tc (a || b)
right : forall {tc a b} -> tr tc b -> tr tc (a || b)
case' : forall {tc a b c} -> tr tc (a || b) -> tr (tc , a) c -> tr (tc , b) c -> tr tc c
isArrMp : ArrMp.Tm tr
open ArrMp.Tm isArrMp public
syntax pair' x y = [ x , y ]
syntax case' xy x y = case xy => x => y
open Tm {{...}} public
module Ip where
record Tm (tr : TmRepr) : Set1 where
field
abort : forall {tc a} -> tr tc FALSE -> tr tc a
isMp : Mp.Tm tr
open Mp.Tm isMp public
open Tm {{...}} public
Thm : Ty -> Set1
Thm a = forall {tr tc} {{_ : Tm tr}} -> tr tc a
open Ip public
-- Example theorems
t1 : forall {a b} -> Thm (a => NOT a => b)
t1 =
lam=>
lam=> abort (v0 $ v1)
t2 : forall {a b} -> Thm (NOT a => a => b)
t2 =
lam=>
lam=> abort (v1 $ v0)
t3 : forall {a} -> Thm (a => NOT (NOT a))
t3 =
lam=>
lam=> v0 $ v1
t4 : forall {a} -> Thm (NOT a <=> NOT (NOT (NOT a)))
t4 =
[ lam=>
lam=> v0 $ v1
, lam=>
lam=> v1 $ (lam=> v0 $ v1)
]