Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Sequent = Sequent {}
- ppSequent :: Sequent -> String
- type RuleName = String
- type Rules = RulesM (RuleName, [Sequent])
- newtype RulesM a = RulesM {
- applyRulesM :: ReaderT Sequent Logic a
- data DefinedRules = DefinedRules {}
- fromDefinedRules :: DefinedRules -> Rules
- rulesLJ :: DefinedRules
- rulesEQ :: DefinedRules
- rulesLJE :: DefinedRules
- rulesLEQ :: Rules
- ruleTop :: Rules
- ruleBottom :: Rules
- leftAnd :: Rules
- leftOr :: Rules
- leftImplies :: Rules
- rightImplies :: Rules
- rightAnd :: Rules
- rightOrL :: Rules
- rightOrR :: Rules
- axiom :: Rules
- reflEQ :: Rules
- transEQ :: Rules
- symEQ :: Rules
- substEQ :: Rules
- reflLEQ :: Rules
- transLEQ :: Rules
- antisymLEQ :: Rules
- lemLEQ :: Rules
- zeroLEQ :: Rules
- oneLEQ :: Rules
- distinctLEQ :: Rules
- orElse :: MonadLogic m => m a -> m a -> m a
- selectN :: Alternative f => Int -> [a] -> f ([a], [a])
- selectOne :: (Alternative f, MonadFail f) => [a] -> f (a, [a])
- choose :: Alternative f => [a] -> f a
- type Proof = ProofTree Void
- data ProofTree a
- close :: Alternative f => ProofTree a -> f Proof
- ppProof :: Proof -> String
- proofNodesWithDepth :: Proof -> [(Int, String)]
- ppNodesWithDepth :: [(Int, String)] -> String
- depthsTree :: [Int] -> [String]
- proveWithDFS :: Int -> Rules -> Sequent -> Logic (ProofTree Sequent)
- proveWithBFSviaDFS :: Int -> Int -> Rules -> Sequent -> Logic Proof
- markIncomplete :: ProofTree Sequent -> Proof
- tryClose :: Logic (ProofTree a) -> Logic (Either [ProofTree a] Proof)
- proveWithDFS' :: Int -> Rules -> Sequent -> Maybe Proof
- proveWithBFSviaDFS' :: Int -> Int -> Rules -> Sequent -> Maybe Proof
- proveAndPrintBFS :: Int -> Rules -> Sequent -> IO ()
- proveAndPrintBFSviaDFS :: Int -> Int -> Rules -> Sequent -> IO ()
- proveAndPrintDFS :: Int -> Rules -> Sequent -> IO ()
- ex1 :: Sequent
- ex2 :: Sequent
- ex3 :: Sequent
- ex4 :: Sequent
- ex5 :: Sequent
Documentation
>>>
:set -XOverloadedStrings
>>>
import RSTT.Tope
Tope sequent
Tope sequent \( \Xi \mid \Phi \vdash \psi \).
Sequent | |
|
ppSequent :: Sequent -> String Source #
Pretty-print a Sequent
.
>>>
points = [("t", "I"), ("s", "J")]
>>>
topes = [("φ" `TopeOr` "ζ") `TopeAnd` ("ψ" `TopeOr` "χ"), ("t" `TopeEQ` "s")]
>>>
putStrLn (ppSequent (Sequent points topes ("s" `TopeEQ` "t")))
t : I, s : J | (φ ∨ ζ) ∧ (ψ ∨ χ), t ≡ s ⊢ s ≡ t
Rules
A collection of generalized tope inference rules.
Intuitively,
is a non-deterministic function from RulesM
aSequent
to a
.
RulesM | |
|
Instances
MonadFail RulesM Source # | |
Defined in RSTT.Tope.Proof | |
Alternative RulesM Source # | |
Applicative RulesM Source # | |
Functor RulesM Source # | |
Monad RulesM Source # | |
MonadPlus RulesM Source # | |
MonadLogic RulesM Source # | |
MonadReader Sequent RulesM Source # | |
Monoid (RulesM a) Source # | |
Semigroup (RulesM a) Source # | |
data DefinedRules Source #
Rules, collected by type.
DefinedRules | |
|
Instances
Monoid DefinedRules Source # | |
Defined in RSTT.Tope.Proof mempty :: DefinedRules # mappend :: DefinedRules -> DefinedRules -> DefinedRules # mconcat :: [DefinedRules] -> DefinedRules # | |
Semigroup DefinedRules Source # | |
Defined in RSTT.Tope.Proof (<>) :: DefinedRules -> DefinedRules -> DefinedRules # sconcat :: NonEmpty DefinedRules -> DefinedRules # stimes :: Integral b => b -> DefinedRules -> DefinedRules # |
fromDefinedRules :: DefinedRules -> Rules Source #
Sets of rules
rulesLJ :: DefinedRules Source #
Rules for intuitionistic tope logic:
axiom
rule- \(\land\)-rules (
leftAnd
andrightAnd
) - \(\lor\)-rules (
leftOr
,rightOrL
, andrightOrR
) - \(\Rightarrow\)-rules (
leftImplies
,rightImplies
)
Rules for inequality tope (not built-in).
- reflexivity (
reflLEQ
) - antisymmetry (
antisymLEQ
) - transitivity (
transLEQ
) - excluded middle (
lemLEQ
) - infimum (
zeroLEQ
) - supremum (
oneLEQ
) - distinctness of 0 and 1 (
distinctLEQ
)
Intuitionistic logic rules (LJ)
ruleBottom :: Rules Source #
leftImplies :: Rules Source #
rightImplies :: Rules Source #
Equality tope \((\equiv)\) rules
Transitivity rule for equality tope (see TopeEQ
).
x ≡ y, y ≡ z ⊢ φ ————————————————————————— x ≡ y, y ≡ z, x ≡ z ⊢ φ
Symmetry rule for equality tope (see TopeEQ
).
x ≡ y ⊢ φ —————————————————— x ≡ y, y ≡ x ⊢ φ
Substitution rule for equality tope (see TopeEQ
).
Г, x ≡ y ⊢ φ ————————————————— Г[yx] ⊢ φ[yx]
NOTE: limited to replacing a variable, not an arbitrary point subterm.
Inequality tope \((\leq)\) rules
antisymLEQ :: Rules Source #
distinctLEQ :: Rules Source #
Helpers
orElse :: MonadLogic m => m a -> m a -> m a Source #
Try the second computation only if the first one fails (i.e. no backtracking).
The following examples show the difference between orElse
and mplus
for Logic
:
>>>
observeAll (pure 1 `orElse` pure 2)
[1]>>>
observeAll (pure 1 `mplus` pure 2)
[1,2]
>>>
observeAll $ do { x <- pure 1 `orElse` pure 2; guard (even x); return x }
[]>>>
observeAll $ do { x <- pure 1 `mplus` pure 2; guard (even x); return x }
[2]
selectN :: Alternative f => Int -> [a] -> f ([a], [a]) Source #
Nondeterministically select exactly \(N\) elements from a given list, also returning the remaining part of the list.
selectOne :: (Alternative f, MonadFail f) => [a] -> f (a, [a]) Source #
Nondeterministically select exactly one element from a given list, also returning the remaining part of the list.
choose :: Alternative f => [a] -> f a Source #
Nondeterministically select exactly one element from a given list.
Proof tree
A proof tree parametrized by the type of leaves (unfinished proofs).
Leaf a | A leaf represents an unfinished part of a proof. |
Node Sequent RuleName [ProofTree a] | A node in a proof tree corresponds to a single rule application. |
Instances
Foldable ProofTree Source # | |
Defined in RSTT.Tope.Proof fold :: Monoid m => ProofTree m -> m # foldMap :: Monoid m => (a -> m) -> ProofTree a -> m # foldMap' :: Monoid m => (a -> m) -> ProofTree a -> m # foldr :: (a -> b -> b) -> b -> ProofTree a -> b # foldr' :: (a -> b -> b) -> b -> ProofTree a -> b # foldl :: (b -> a -> b) -> b -> ProofTree a -> b # foldl' :: (b -> a -> b) -> b -> ProofTree a -> b # foldr1 :: (a -> a -> a) -> ProofTree a -> a # foldl1 :: (a -> a -> a) -> ProofTree a -> a # toList :: ProofTree a -> [a] # length :: ProofTree a -> Int # elem :: Eq a => a -> ProofTree a -> Bool # maximum :: Ord a => ProofTree a -> a # minimum :: Ord a => ProofTree a -> a # | |
Traversable ProofTree Source # | |
Applicative ProofTree Source # | |
Functor ProofTree Source # | |
Monad ProofTree Source # | |
Show a => Show (ProofTree a) Source # | |
Eq a => Eq (ProofTree a) Source # | |
close :: Alternative f => ProofTree a -> f Proof Source #
Convert a proof tree into a complete proof if possible.
ASCII rendering
proofNodesWithDepth :: Proof -> [(Int, String)] Source #
Extract proof nodes with corresponding depths.
ppNodesWithDepth :: [(Int, String)] -> String Source #
Pretty-print depth-annotated nodes as a ASCII tree-like structure.
>>>
putStr $ ppNodesWithDepth (zip [0,1,2,1,2,3,3,2,3] (map show [0..]))
0 ├─ 1 │ └─ 2 └─ 3 ├─ 4 │ ├─ 5 │ └─ 6 └─ 7 └─ 8
depthsTree :: [Int] -> [String] Source #
Pretty-print an ASCII tree-like structure based on depth list.
>>>
mapM_ putStrLn $ depthsTree [0,1,2,1,2,3,3,2,3]
└─ ├─ │ └─ └─ ├─ │ ├─ │ └─ └─ └─
Provers
:: Int | Maximum search depth. |
-> Rules | Set of rules. |
-> Sequent | Starting sequent (one to prove). |
-> Logic (ProofTree Sequent) | A proof tree, possibly with unproven sequents in leaves (for when maximum search depth is insufficient). |
A simple DFS proof search algorithm for a given set of rules.
:: Int | Maximum number of limited DFS iterations. |
-> Int | Maximum depth per one DFS iteration. |
-> Rules | A set of rules. |
-> Sequent | A starting sequent (one to prove). |
-> Logic Proof |
A simple k-depth proof search algorithm for a given set of rules.
:: Int | Maximum search depth. |
-> Rules | Set of rules. |
-> Sequent | Starting sequent (one to prove). |
-> Maybe Proof |
Search for a proof using simple DFS algorithm (see proveWithDFS
).
:: Int | Maximum number of limited DFS iterations. |
-> Int | Maximum depth per one DFS iteration. |
-> Rules | A set of rules. |
-> Sequent | A starting sequent (one to prove). |
-> Maybe Proof |
Search for a proof using a combination of BFS and DFS algorithms (see proveWithBFS
).
With printers
Search for a proof using BFS and print proof tree (see ppProof
).
proveAndPrintBFSviaDFS :: Int -> Int -> Rules -> Sequent -> IO () Source #
Search for a proof using a combination of BFS and DFS
and print proof tree (see ppProof
).
proveAndPrintDFS :: Int -> Rules -> Sequent -> IO () Source #
Search for a proof using DFS and print proof tree (see ppProof
).
Examples
>>>
putStrLn (ppSequent ex1)
⋅ | (φ ∨ ζ) ∧ (ψ ∨ χ) ⊢ φ ∧ ψ ∨ ζ ∧ ψ ∨ χ
>>>
proveAndPrintBFS 8 (fromDefinedRules rulesLJ) ex1
[∧L] ⋅ | (φ ∨ ζ) ∧ (ψ ∨ χ) ⊢ φ ∧ ψ ∨ ζ ∧ ψ ∨ χ └─ [∨L] ⋅ | φ ∨ ζ, ψ ∨ χ ⊢ φ ∧ ψ ∨ ζ ∧ ψ ∨ χ ├─ [∨L] ⋅ | φ, ψ ∨ χ ⊢ φ ∧ ψ ∨ ζ ∧ ψ ∨ χ │ ├─ [∨R₁] ⋅ | ψ, φ ⊢ φ ∧ ψ ∨ ζ ∧ ψ ∨ χ │ │ └─ [∧R] ⋅ | ψ, φ ⊢ φ ∧ ψ │ │ ├─ [Ax] ⋅ | ψ, φ ⊢ φ │ │ └─ [Ax] ⋅ | ψ, φ ⊢ ψ │ └─ [∨R₂] ⋅ | χ, φ ⊢ φ ∧ ψ ∨ ζ ∧ ψ ∨ χ │ └─ [∨R₂] ⋅ | χ, φ ⊢ ζ ∧ ψ ∨ χ │ └─ [Ax] ⋅ | χ, φ ⊢ χ └─ [∨L] ⋅ | ζ, ψ ∨ χ ⊢ φ ∧ ψ ∨ ζ ∧ ψ ∨ χ ├─ [∨R₂] ⋅ | ψ, ζ ⊢ φ ∧ ψ ∨ ζ ∧ ψ ∨ χ │ └─ [∨R₁] ⋅ | ψ, ζ ⊢ ζ ∧ ψ ∨ χ │ └─ [∧R] ⋅ | ψ, ζ ⊢ ζ ∧ ψ │ ├─ [Ax] ⋅ | ψ, ζ ⊢ ζ │ └─ [Ax] ⋅ | ψ, ζ ⊢ ψ └─ [∨R₂] ⋅ | χ, ζ ⊢ φ ∧ ψ ∨ ζ ∧ ψ ∨ χ └─ [∨R₂] ⋅ | χ, ζ ⊢ ζ ∧ ψ ∨ χ └─ [Ax] ⋅ | χ, ζ ⊢ χ
>>>
putStrLn (ppSequent ex2)
⋅ | φ ∧ ψ ∨ ζ ∧ χ ⊢ (φ ∨ ζ) ∧ (ψ ∨ χ)
>>>
proveAndPrintBFS 8 (fromDefinedRules rulesLJ) ex2
[∧R] ⋅ | φ ∧ ψ ∨ ζ ∧ χ ⊢ (φ ∨ ζ) ∧ (ψ ∨ χ) ├─ [∨L] ⋅ | φ ∧ ψ ∨ ζ ∧ χ ⊢ φ ∨ ζ │ ├─ [∧L] ⋅ | φ ∧ ψ ⊢ φ ∨ ζ │ │ └─ [∨R₁] ⋅ | φ, ψ ⊢ φ ∨ ζ │ │ └─ [Ax] ⋅ | φ, ψ ⊢ φ │ └─ [∧L] ⋅ | ζ ∧ χ ⊢ φ ∨ ζ │ └─ [∨R₂] ⋅ | ζ, χ ⊢ φ ∨ ζ │ └─ [Ax] ⋅ | ζ, χ ⊢ ζ └─ [∨L] ⋅ | φ ∧ ψ ∨ ζ ∧ χ ⊢ ψ ∨ χ ├─ [∧L] ⋅ | φ ∧ ψ ⊢ ψ ∨ χ │ └─ [∨R₁] ⋅ | φ, ψ ⊢ ψ ∨ χ │ └─ [Ax] ⋅ | φ, ψ ⊢ ψ └─ [∧L] ⋅ | ζ ∧ χ ⊢ ψ ∨ χ └─ [∨R₂] ⋅ | ζ, χ ⊢ ψ ∨ χ └─ [Ax] ⋅ | ζ, χ ⊢ χ
>>>
putStrLn (ppSequent ex3)
⋅ | x ≡ y ∧ y ≡ z ⊢ z ≡ x
>>>
proveAndPrintBFS 35 (fromDefinedRules rulesLJE) ex3
[∧L] ⋅ | x ≡ y ∧ y ≡ z ⊢ z ≡ x └─ [≡L(trans)] ⋅ | x ≡ y, y ≡ z ⊢ z ≡ x └─ [≡L(sym)] ⋅ | x ≡ z, x ≡ y, y ≡ z ⊢ z ≡ x └─ [Ax] ⋅ | z ≡ x, x ≡ z, x ≡ y, y ≡ z ⊢ z ≡ x
>>>
putStrLn (ppSequent ex4)
⋅ | (t ≡ s ∨ t ≡ u) ∧ s ≡ u ⊢ t ≡ s
>>>
proveAndPrintBFS 8 (fromDefinedRules rulesLJE) ex4
[∧L] ⋅ | (t ≡ s ∨ t ≡ u) ∧ s ≡ u ⊢ t ≡ s └─ [∨L] ⋅ | t ≡ s ∨ t ≡ u, s ≡ u ⊢ t ≡ s ├─ [Ax] ⋅ | t ≡ s, s ≡ u ⊢ t ≡ s └─ [≡L(sym)] ⋅ | t ≡ u, s ≡ u ⊢ t ≡ s └─ [≡L(trans)] ⋅ | u ≡ t, t ≡ u, s ≡ u ⊢ t ≡ s └─ [≡L(sym)] ⋅ | s ≡ t, u ≡ t, t ≡ u, s ≡ u ⊢ t ≡ s └─ [Ax] ⋅ | t ≡ s, s ≡ t, u ≡ t, t ≡ u, s ≡ u ⊢ t ≡ s
>>>
putStrLn (ppSequent ex5)
⋅ | (≤(t, s) ∨ ≤(s, u)) ∧ ≤(t, u) ⊢ ≤(t, u) ∨ ≤(s, t) ∨ ≤(u, s)
>>>
proveAndPrintBFS 5 (fromDefinedRules rulesLJE) ex5
[∧L] ⋅ | (≤(t, s) ∨ ≤(s, u)) ∧ ≤(t, u) ⊢ ≤(t, u) ∨ ≤(s, t) ∨ ≤(u, s) └─ [∨L] ⋅ | ≤(t, s) ∨ ≤(s, u), ≤(t, u) ⊢ ≤(t, u) ∨ ≤(s, t) ∨ ≤(u, s) ├─ [∨R₁] ⋅ | ≤(t, s), ≤(t, u) ⊢ ≤(t, u) ∨ ≤(s, t) ∨ ≤(u, s) │ └─ [∨R₁] ⋅ | ≤(t, s), ≤(t, u) ⊢ ≤(t, u) ∨ ≤(s, t) │ └─ [Ax] ⋅ | ≤(t, s), ≤(t, u) ⊢ ≤(t, u) └─ [∨R₁] ⋅ | ≤(s, u), ≤(t, u) ⊢ ≤(t, u) ∨ ≤(s, t) ∨ ≤(u, s) └─ [∨R₁] ⋅ | ≤(s, u), ≤(t, u) ⊢ ≤(t, u) ∨ ≤(s, t) └─ [Ax] ⋅ | ≤(s, u), ≤(t, u) ⊢ ≤(t, u)