-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypes.hs
More file actions
184 lines (151 loc) · 7.59 KB
/
Types.hs
File metadata and controls
184 lines (151 loc) · 7.59 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
module Types where
type Atom = String
data Sentence =
Atom Atom
| Neg Sentence
| Conj Sentence Sentence
| Disj Sentence Sentence
| Imp Sentence Sentence
deriving (Eq, Ord)
{-instance Eq Sentence where
Atom v == Atom u = v == u
Neg s == Neg t = s == t
Conj s1 s2 == Conj t1 t2 = s1 == t1 && s2 == t2
Disj s1 s2 == Disj t1 t2 = s1 == t1 && s2 == t2
Imp s1 s2 == Imp t1 t2 = s1 == t1 && s2 == t2
_ == _ = False-}
type Cedent = [Sentence]
data Proof =
-- leaf : (A : Atom) → ([ atom A ] ==> [ atom A ])
Leaf Atom
-- cut : (Γ Δ : Cedent) (A : Sentence) →
-- (Γ ==> Δ ¸ A) → (A ¸ Γ ==> Δ) →
-- (Γ ==> Δ)
| Cut Cedent Cedent Sentence Proof Proof
-- exchangeₗ : (Γ Δ Π : Cedent) (A B : Sentence) →
-- (Γ ¸ A ¸ B ¸ Δ ==> Π) →
-- (Γ ¸ B ¸ A ¸ Δ ==> Π)
| ExchangeL Cedent Cedent Cedent Sentence Sentence Proof
-- exchangeᵣ : (Γ Δ Π : Cedent) (A B : Sentence) →
-- (Γ ==> Δ ¸ A ¸ B ¸ Π) →
-- (Γ ==> Δ ¸ B ¸ A ¸ Π)
| ExchangeR Cedent Cedent Cedent Sentence Sentence Proof
-- contractionₗ : (Γ Δ : Cedent) (A : Sentence) →
-- (A ¸ A ¸ Γ ==> Δ) →
-- (A ¸ Γ ==> Δ)
| ContractionL Cedent Cedent Sentence Proof
-- contractionᵣ : (Γ Δ : Cedent) (A : Sentence) →
-- (Γ ==> Δ ¸ A ¸ A) →
-- (Γ ==> Δ ¸ A)
| ContractionR Cedent Cedent Sentence Proof
-- weakeningₗ : (Γ Δ : Cedent) (A : Sentence) →
-- (Γ ==> Δ) →
-- (A ¸ Γ ==> Δ)
| WeakeningL Cedent Cedent Sentence Proof
-- weakeningᵣ : (Γ Δ : Cedent) (A : Sentence) →
-- (Γ ==> Δ) →
-- (Γ ==> Δ ¸ A)
| WeakeningR Cedent Cedent Sentence Proof
-- ¬ₗ : (Γ Δ : Cedent) (A : Sentence) →
-- (Γ ==> Δ ¸ A) →
-- (¬ A ¸ Γ ==> Δ)
| NegL Cedent Cedent Sentence Proof
-- ¬ᵣ : (Γ Δ : Cedent) (A : Sentence) →
-- (A ¸ Γ ==> Δ) →
-- (Γ ==> Δ ¸ ¬ A)
| NegR Cedent Cedent Sentence Proof
-- ∧ₗ : (Γ Δ : Cedent) (A B : Sentence) →
-- (A ¸ B ¸ Γ ==> Δ) →
-- (A ∧ B ¸ Γ ==> Δ)
| ConjL Cedent Cedent Sentence Sentence Proof
-- ∧ᵣ : (Γ Δ : Cedent) (A B : Sentence) →
-- (Γ ==> Δ ¸ A) → (Γ ==> Δ ¸ B) →
-- (Γ ==> Δ ¸ A ∧ B)
| ConjR Cedent Cedent Sentence Sentence Proof Proof
-- ∨ₗ : (Γ Δ : Cedent) (A B : Sentence) →
-- (A ¸ Γ ==> Δ) → (B ¸ Γ ==> Δ) →
-- (A ∨ B ¸ Γ ==> Δ)
| DisjL Cedent Cedent Sentence Sentence Proof Proof
-- ∨ᵣ : (Γ Δ : Cedent) (A B : Sentence) →
-- (Γ ==> Δ ¸ A ¸ B) →
-- (Γ ==> Δ ¸ A ∨ B)
| DisjR Cedent Cedent Sentence Sentence Proof
-- ⊃ₗ : (Γ Δ : Cedent) (A B : Sentence) →
-- (Γ ==> Δ ¸ A) → (B ¸ Γ ==> Δ) →
-- (A ⊃ B ¸ Γ ==> Δ)
| ImpL Cedent Cedent Sentence Sentence Proof Proof
-- ⊃ᵣ : (Γ Δ : Cedent) (A B : Sentence) →
-- (A ¸ Γ ==> Δ ¸ B) →
-- (Γ ==> Δ ¸ A ⊃ B)
| ImpR Cedent Cedent Sentence Sentence Proof
deriving (Eq, Ord)
typeof :: Proof -> (Cedent, Cedent)
typeof (Leaf a) = ([Atom a], [Atom a])
typeof (Cut gamma delta a x1 x2) = ((gamma), (delta))
typeof (ExchangeL gamma delta pi a b x) = ((gamma ++ [b, a] ++ delta), (pi))
typeof (ExchangeR gamma delta pi a b x) = ((gamma), (delta ++ [b, a] ++ pi))
typeof (ContractionL gamma delta a x) = (([a] ++ gamma), (delta))
typeof (ContractionR gamma delta a x) = ((gamma), (delta ++ [a]))
typeof (WeakeningL gamma delta a x) = (([a] ++ gamma), (delta))
typeof (WeakeningR gamma delta a x) = ((gamma), (delta ++ [a]))
typeof (NegL gamma delta a x) = (([Neg a] ++ gamma), (delta))
typeof (NegR gamma delta a x) = ((gamma), (delta ++ [Neg a]))
typeof (ConjL gamma delta a b x) = (([Conj a b] ++ gamma), (delta))
typeof (ConjR gamma delta a b x1 x2) = ((gamma), (delta ++ [Conj a b]))
typeof (DisjL gamma delta a b x1 x2) = (([Disj a b] ++ gamma), (delta))
typeof (DisjR gamma delta a b x) = ((gamma), (delta ++ [Disj a b]))
typeof (ImpL gamma delta a b x1 x2) = (([Imp a b] ++ gamma), (delta))
typeof (ImpR gamma delta a b x) = ((gamma), (delta ++ [Imp a b]))
data RuleLabel = RuleLeaf | RuleCut | RuleExchangeL | RuleExchangeR | RuleContractionL | RuleContractionR | RuleWeakeningL | RuleWeakeningR | RuleNegL | RuleNegR | RuleConjL | RuleConjR | RuleDisjL | RuleDisjR | RuleImpL | RuleImpR
deriving (Eq, Ord)
data ProofS = ProofS RuleLabel [Cedent] [Sentence] [ProofS]
deriving (Eq, Ord)
foldProofS :: (RuleLabel -> [Cedent] -> [Sentence] -> [a] -> a) -> ProofS -> a
foldProofS f (ProofS rl cs ss ps) = f rl cs ss (foldProofS f <$> ps)
foldProofSS :: (RuleLabel -> [Cedent] -> [Sentence] -> [ProofS] -> [a] -> a) -> ProofS -> a
foldProofSS f (ProofS rl cs ss ps) = f rl cs ss ps (foldProofSS f <$> ps)
simplify :: Proof -> ProofS
simplify (Leaf a) = (ProofS RuleLeaf [] [Atom a] [])
simplify (Cut g d a x1 x2) = (ProofS RuleCut [g, d] [a] [simplify x1, simplify x2])
simplify (ExchangeL g d p a b x) = (ProofS RuleExchangeL [g, d, p] [a, b] [simplify x])
simplify (ExchangeR g d p a b x) = (ProofS RuleExchangeR [g, d, p] [a, b] [simplify x])
simplify (ContractionL g d a x) = (ProofS RuleContractionL [g, d] [a] [simplify x])
simplify (ContractionR g d a x) = (ProofS RuleContractionR [g, d] [a] [simplify x])
simplify (WeakeningL g d a x) = (ProofS RuleWeakeningL [g, d] [a] [simplify x])
simplify (WeakeningR g d a x) = (ProofS RuleWeakeningR [g, d] [a] [simplify x])
simplify (NegL g d a x) = (ProofS RuleNegL [g, d] [a] [simplify x])
simplify (NegR g d a x) = (ProofS RuleNegR [g, d] [a] [simplify x])
simplify (ConjL g d a b x) = (ProofS RuleConjL [g, d] [a, b] [simplify x])
simplify (ConjR g d a b x1 x2) = (ProofS RuleConjR [g, d] [a, b] [simplify x1, simplify x2])
simplify (DisjL g d a b x1 x2) = (ProofS RuleDisjL [g, d] [a, b] [simplify x1, simplify x2])
simplify (DisjR g d a b x) = (ProofS RuleDisjR [g, d] [a, b] [simplify x])
simplify (ImpL g d a b x1 x2) = (ProofS RuleImpL [g, d] [a, b] [simplify x1, simplify x2])
simplify (ImpR g d a b x) = (ProofS RuleImpR [g, d] [a, b] [simplify x])
expand :: ProofS -> Proof
expand (ProofS RuleLeaf [] [Atom a] []) = (Leaf a)
expand (ProofS RuleCut [g, d] [a] [x1, x2]) = (Cut g d a (expand x1) (expand x2))
expand (ProofS RuleExchangeL [g, d, p] [a, b] [x]) = (ExchangeL g d p a b (expand x))
expand (ProofS RuleExchangeR [g, d, p] [a, b] [x]) = (ExchangeR g d p a b (expand x))
expand (ProofS RuleContractionL [g, d] [a] [x]) = (ContractionL g d a (expand x))
expand (ProofS RuleContractionR [g, d] [a] [x]) = (ContractionR g d a (expand x))
expand (ProofS RuleWeakeningL [g, d] [a] [x]) = (WeakeningL g d a (expand x))
expand (ProofS RuleWeakeningR [g, d] [a] [x]) = (WeakeningR g d a (expand x))
expand (ProofS RuleNegL [g, d] [a] [x]) = (NegL g d a (expand x))
expand (ProofS RuleNegR [g, d] [a] [x]) = (NegR g d a (expand x))
expand (ProofS RuleConjL [g, d] [a, b] [x]) = (ConjL g d a b (expand x))
expand (ProofS RuleConjR [g, d] [a, b] [x1, x2]) = (ConjR g d a b (expand x1) (expand x2))
expand (ProofS RuleDisjL [g, d] [a, b] [x1, x2]) = (DisjL g d a b (expand x1) (expand x2))
expand (ProofS RuleDisjR [g, d] [a, b] [x]) = (DisjR g d a b (expand x))
expand (ProofS RuleImpL [g, d] [a, b] [x1, x2]) = (ImpL g d a b (expand x1) (expand x2))
expand (ProofS RuleImpR [g, d] [a, b] [x]) = (ImpR g d a b (expand x))
weakRules :: [RuleLabel]
weakRules = [RuleExchangeL, RuleExchangeR,
RuleContractionL, RuleContractionR,
RuleWeakeningL, RuleWeakeningR]
propRules :: [RuleLabel]
propRules = [RuleNegL, RuleNegR,
RuleConjL, RuleConjR,
RuleDisjL, RuleDisjR,
RuleImpL, RuleImpR]
binaryRules :: [RuleLabel]
binaryRules = [RuleCut, RuleConjR, RuleDisjL, RuleImpL]