Skip to content

Commit

Permalink
Changed to using Tactics themselves as hypotheses.
Browse files Browse the repository at this point in the history
  • Loading branch information
luqui committed Jun 11, 2009
1 parent 6e550dd commit 1b4d766
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
6 changes: 4 additions & 2 deletions ixi/IXi/Proof.hs
Expand Up @@ -20,7 +20,7 @@ data Proof
| XiRule Name Proof Proof | XiRule Name Proof Proof
| HXiRule Name Proof Proof | HXiRule Name Proof Proof
| HHRule | HHRule
| XIHRule Int | XIHRule Proof
| Theorem Theorem | Theorem Theorem


hypothesis = Hypothesis hypothesis = Hypothesis
Expand Down Expand Up @@ -56,7 +56,9 @@ checkProof (HXiRule name hproof hxiproof) seq = do


checkProof HHRule seq = S.hhRule seq checkProof HHRule seq = S.hhRule seq


checkProof (XIHRule z) seq = S.xihRule z seq checkProof (XIHRule pf) seq = do
seq' <- S.xihRule seq
checkProof pf seq'


checkProof (Theorem (MkTheorem t _)) (hyps S.:|- goal) checkProof (Theorem (MkTheorem t _)) (hyps S.:|- goal)
| goal == t = Right () | goal == t = Right ()
Expand Down
12 changes: 6 additions & 6 deletions ixi/IXi/Sequent.hs
Expand Up @@ -58,7 +58,7 @@ xiRule _ _ = invalid "Goal is not a Xi-form"
hxiRule :: Name -> Sequent -> Err (Sequent, Sequent) hxiRule :: Name -> Sequent -> Err (Sequent, Sequent)
hxiRule name (hyps :|- H :% (Xi :% a :% b)) hxiRule name (hyps :|- H :% (Xi :% a :% b))
| nameFree name a || nameFree name b || any (nameFree name) hyps | nameFree name a || nameFree name b || any (nameFree name) hyps
= invalid "Name must no be free in environment" = invalid "Name must not be free in environment"
| otherwise | otherwise
= valid (hyps :|- H :% (a :% n), (a :% n):hyps :|- H :% (b :% n)) = valid (hyps :|- H :% (a :% n), (a :% n):hyps :|- H :% (b :% n))
where n = NameVar name where n = NameVar name
Expand All @@ -72,8 +72,8 @@ newName :: Sequent -> Name
newName seq = safeName' (goal seq : hypotheses seq) newName seq = safeName' (goal seq : hypotheses seq)


-- conservative extension, Γ,x |- Hx -- conservative extension, Γ,x |- Hx
xihRule :: Int -> Sequent -> Err () xihRule :: Sequent -> Err Sequent
xihRule z (hyps :|- goal) xihRule (hyps :|- goal) =
| not (0 <= z && z <= length hyps) = invalid "Index out of range" case goal of
| not (H :% (hyps !! z) == goal) = invalid "Hypothesis does not match goal" H :% x -> valid (hyps :|- x)
| otherwise = valid () _ -> invalid "Goal is not an H-form"
31 changes: 14 additions & 17 deletions ixi/IXi/Tactic.hs
@@ -1,6 +1,6 @@
module IXi.Tactic module IXi.Tactic
( Tactic, Hypothesis ( Tactic
, hypothesis, conversion, implRule, xiRule, hxiRule, hhRule, xihRule, theorem , conversion, implRule, xiRule, hxiRule, hhRule, xihRule, theorem
, inspect, (>|<) , inspect, (>|<)
, newName , newName
, prove , prove
Expand All @@ -15,16 +15,13 @@ import Control.Applicative
import Control.Monad (ap, MonadPlus(..)) import Control.Monad (ap, MonadPlus(..))


newtype Tactic = Tactic { unTactic :: Seq.Sequent -> Seq.Err P.Proof } newtype Tactic = Tactic { unTactic :: Seq.Sequent -> Seq.Err P.Proof }
newtype Hypothesis = Hypothesis Int -- index from the end


topHyp :: Seq.Sequent -> Hypothesis topHyp :: Seq.Sequent -> Tactic
topHyp seq = Hypothesis (length (Seq.hypotheses seq) - 1) topHyp seq = Tactic $ \seq' -> do

() <- Seq.hypothesis ix seq'
hypothesis :: Hypothesis -> Tactic
hypothesis (Hypothesis z) = Tactic $ \seq -> do
let ix = length (Seq.hypotheses seq) - z - 1
() <- Seq.hypothesis ix seq
return (P.hypothesis ix) return (P.hypothesis ix)
where
ix = length (Seq.hypotheses seq) - 1


conversion :: Conversion -> Tactic -> Tactic conversion :: Conversion -> Tactic -> Tactic
conversion conv rest = Tactic $ \seq -> do conversion conv rest = Tactic $ \seq -> do
Expand All @@ -39,14 +36,14 @@ implRule p pxTac xpqTac = Tactic $ \seq -> do
xpqPf <- unTactic xpqTac xpqSeq xpqPf <- unTactic xpqTac xpqSeq
return (P.implRule p pxPf xpqPf) return (P.implRule p pxPf xpqPf)


xiRule :: Name -> Tactic -> (Hypothesis -> Tactic) -> Tactic xiRule :: Name -> Tactic -> (Tactic -> Tactic) -> Tactic
xiRule name hTac implTac = Tactic $ \seq -> do xiRule name hTac implTac = Tactic $ \seq -> do
(hSeq, implSeq) <- Seq.xiRule name seq (hSeq, implSeq) <- Seq.xiRule name seq
hPf <- unTactic hTac hSeq hPf <- unTactic hTac hSeq
implPf <- unTactic (implTac (topHyp implSeq)) implSeq implPf <- unTactic (implTac (topHyp implSeq)) implSeq
return (P.xiRule name hPf implPf) return (P.xiRule name hPf implPf)


hxiRule :: Name -> Tactic -> (Hypothesis -> Tactic) -> Tactic hxiRule :: Name -> Tactic -> (Tactic -> Tactic) -> Tactic
hxiRule name hTac implTac = Tactic $ \seq -> do hxiRule name hTac implTac = Tactic $ \seq -> do
(hSeq, implSeq) <- Seq.hxiRule name seq (hSeq, implSeq) <- Seq.hxiRule name seq
hPf <- unTactic hTac hSeq hPf <- unTactic hTac hSeq
Expand All @@ -58,11 +55,11 @@ hhRule = Tactic $ \seq -> do
() <- Seq.hhRule seq () <- Seq.hhRule seq
return P.hhRule return P.hhRule


xihRule :: Hypothesis -> Tactic xihRule :: Tactic -> Tactic
xihRule (Hypothesis z) = Tactic $ \seq -> do xihRule tac = Tactic $ \seq -> do
let ix = length (Seq.hypotheses seq) - z - 1 seq' <- Seq.xihRule seq
() <- Seq.xihRule ix seq pf <- unTactic tac seq'
return (P.xihRule ix) return (P.xihRule pf)


theorem :: P.Theorem -> Tactic theorem :: P.Theorem -> Tactic
theorem thm = Tactic $ \seq -> do theorem thm = Tactic $ \seq -> do
Expand Down

0 comments on commit 1b4d766

Please sign in to comment.