4
4
5
5
module Minimal where
6
6
7
- import Text.Printf ( printf )
7
+ import Control.Monad.Except
8
8
import Data.Set (Set , (\\) )
9
9
import qualified Data.Set as Set
10
+ import Text.Printf (printf )
10
11
11
12
data Formula
12
13
= Proposition String
@@ -34,39 +35,15 @@ instance Show Formula where
34
35
show (Disjunction a b) = printf " (%s \x2228 %s)" (show a) (show b)
35
36
show (Implication a b) = printf " (%s \x2192 %s)" (show a) (show b)
36
37
37
- {-
38
- - NAME NUM ASSUMPS STACK
39
- - Assume +1 { - a }
40
- - ConjIntro 0 { a b - a^b }
41
- - LDisjIntro 0 { a - a^b }
42
- - RDisjIntro 0 { b - a^b }
43
- - LConjElim 0 { a^b - b }
44
- - RConjElim 0 { a^b - a }
45
- - DisjElim 2 { avb a>c b>c - c }
46
- -
47
- - Assume : takes F and gives a proof of F from {F}
48
- - ConjIntro : takes a proof of A from G and a proof of B from H and
49
- - gives a proof of A^B from G U H
50
- - LDisjIntro : takes a proof of B from G and gives a proof of AvB from G
51
- - LDisjIntro : takes a A and proof of B from G
52
- - and gives a proof of AvB from G
53
- - RDisjIntro : takes a proof of A from G and B
54
- - and gives a proof of AvB from G
55
- - LConjElim : takes a proof of A^B from G and gives a proof of B from G
56
- - RConjElim : takes a proof of A^B from G and gives a proof of A from G
57
- - DisjElim : takes a proof of AvB from G, a proof of C from H1 U {A}
58
- - and a proof of C from H2 U {B}, and gives a proof of
59
- - C from G U H1 U H2.
60
- - ImplElim : takes a proof of A>B from G and a proof of A from H
61
- - and gives a proof of B from G U H
62
- - ImplIntro : takes a proof of B from G U {A} and gives a proof of
63
- - A>B from G
64
- -}
65
-
66
- data Deduction = Deduction { assumptions :: Set Formula ,
67
- conclusion :: Formula
38
+ data Deduction = Deduction { assumptions :: Set Formula
39
+ , conclusion :: Formula
68
40
} deriving (Show )
69
41
42
+ type Proof = Except String Deduction
43
+
44
+ runProof :: Proof -> Either String Deduction
45
+ runProof = runExcept
46
+
70
47
assume' :: Formula -> Deduction
71
48
assume' f = Deduction (Set. singleton f) f
72
49
@@ -75,11 +52,11 @@ implIntro' f d = Deduction (Set.delete f a) (f #> c)
75
52
where a = assumptions d
76
53
c = conclusion d
77
54
78
- implElim :: Deduction -> Deduction -> Maybe Deduction
55
+ implElim :: Deduction -> Deduction -> Proof
79
56
implElim (Deduction aA a') (Deduction aAtoB (Implication a b))
80
- | (a' == a) = Just $ (Deduction (Set. union aA aAtoB) b)
81
- | otherwise = Nothing
82
- implElim _ _ = Nothing
57
+ | (a' == a) = return (Deduction (Set. union aA aAtoB) b)
58
+ | otherwise = throwError " conclusion of first argument must be the antecedent of the conclusion of the second argument "
59
+ implElim _ _ = throwError " second argument to implElim must be an implication "
83
60
84
61
conjIntro' :: Deduction -> Deduction -> Deduction
85
62
conjIntro' l r = Deduction (Set. union al ar) (cl #& cr)
@@ -96,43 +73,43 @@ rightDisjIntro' :: Deduction -> Formula -> Deduction
96
73
rightDisjIntro' d f = Deduction (assumptions d) (l #| f)
97
74
where l = conclusion d
98
75
99
- leftConjElim :: Deduction -> Maybe Deduction
76
+ leftConjElim :: Deduction -> Proof
100
77
leftConjElim d = case (conclusion d) of
101
- (Conjunction _ r) -> Just d { conclusion = r }
102
- _ -> Nothing
78
+ (Conjunction _ r) -> return d { conclusion = r }
79
+ _ -> throwError " argument must be a conjunction "
103
80
104
- rightConjElim :: Deduction -> Maybe Deduction
81
+ rightConjElim :: Deduction -> Proof
105
82
rightConjElim d = case (conclusion d) of
106
- (Conjunction l _) -> Just d { conclusion = l }
107
- _ -> Nothing
83
+ (Conjunction l _) -> return d { conclusion = l }
84
+ _ -> throwError " argument must be a conjunction "
108
85
109
- disjElim :: Deduction -> Deduction -> Deduction -> Maybe Deduction
86
+ disjElim :: Deduction -> Deduction -> Deduction -> Proof
110
87
disjElim avb atoc btoc
111
88
| conclusion atoc == conclusion btoc = disjElimSame
112
- | otherwise = Nothing
89
+ | otherwise = throwError " conclusion of second arg and conclusion of third arg must be equal "
113
90
where disjElimSame = case (conclusion avb) of
114
- (Disjunction a b) -> Just (Deduction (Set. unions [g, hA, hB]) c)
91
+ (Disjunction a b) -> return (Deduction (Set. unions [g, hA, hB]) c)
115
92
where g = assumptions avb
116
93
hA = assumptions atoc \\ Set. singleton a
117
94
hB = assumptions btoc \\ Set. singleton b
118
95
c = conclusion atoc
119
- _ -> Nothing
96
+ _ -> throwError " conclusion of first arg must be a disjunction "
120
97
121
98
-- These allow for a more consistent syntax when doing proofs
122
- assume :: Formula -> Maybe Deduction
123
- assume f = Just $ assume' f
99
+ assume :: Formula -> Proof
100
+ assume f = return $ assume' f
124
101
125
- conjIntro :: Deduction -> Deduction -> Maybe Deduction
126
- conjIntro l r = Just $ conjIntro' l r
102
+ conjIntro :: Deduction -> Deduction -> Proof
103
+ conjIntro l r = return $ conjIntro' l r
127
104
128
- implIntro :: Formula -> Deduction -> Maybe Deduction
129
- implIntro f d = Just $ implIntro' f d
105
+ implIntro :: Formula -> Deduction -> Proof
106
+ implIntro f d = return $ implIntro' f d
130
107
131
- leftDisjIntro :: Formula -> Deduction -> Maybe Deduction
132
- leftDisjIntro f d = Just $ leftDisjIntro' f d
108
+ leftDisjIntro :: Formula -> Deduction -> Proof
109
+ leftDisjIntro f d = return $ leftDisjIntro' f d
133
110
134
- rightDisjIntro :: Deduction -> Formula -> Maybe Deduction
135
- rightDisjIntro d f = Just $ rightDisjIntro' d f
111
+ rightDisjIntro :: Deduction -> Formula -> Proof
112
+ rightDisjIntro d f = return $ rightDisjIntro' d f
136
113
137
114
exampleVacuousIntro = do
138
115
let p = Proposition " P"
0 commit comments