| Copyright | (c) Leon Vatthauer 2026 |
|---|---|
| License | GPL-3 |
| Maintainer | Leon Vatthauer <leon.vatthauer@fau.de> |
| Stability | experimental |
| Portability | non-portable (ghc-wasm-meta) |
| Safe Haskell | None |
| Language | GHC2024 |
Fitch.Proof
Description
Synopsis
- class PrettyPrint a where
- prettyPrint :: a -> Text
- data Wrapper a where
- isUnparsed :: Wrapper a -> Bool
- isParseValid :: Wrapper a -> Bool
- fromWrapper :: Wrapper a -> Maybe a
- getText :: Wrapper a -> Text
- proofPreviewTex :: Proof -> Text
- type Name = Text
- data Term
- isFun :: Term -> Bool
- data RawFormula
- = Pred Name [Term]
- | InfixPred Name Term Term
- | Opr Text [RawFormula]
- | Quantifier Name Name RawFormula
- data Reference where
- LineReference :: Int -> Reference
- ProofReference :: Int -> Int -> Reference
- type Formula = Wrapper RawFormula
- data RawAssumption
- type Assumption = (Wrapper RawAssumption, Wrapper RuleApplication)
- mkAssumption :: Wrapper RawAssumption -> Assumption
- toAssumption :: Derivation -> Assumption
- toDerivation :: Assumption -> Derivation
- data RuleApplication = RuleApplication Name [Reference]
- data Derivation = Derivation Formula (Wrapper RuleApplication)
- data Proof where
- SubProof :: [Assumption] -> [Either Derivation Proof] -> Derivation -> Proof
- pFoldLines :: (a -> Assumption -> a) -> (a -> Derivation -> a) -> a -> Proof -> a
- pLength :: Proof -> Int
- pFoldLinesM :: Monad m => (a -> Assumption -> m a) -> (a -> Derivation -> m a) -> a -> Proof -> m a
- pSerialize :: (Assumption -> a) -> (Derivation -> a) -> ([a] -> a) -> (Derivation -> a) -> Proof -> [a]
- pSerializeLines :: (Assumption -> a) -> (Derivation -> a) -> Proof -> [a]
- pSerializeLinesWithAddr :: (NodeAddr -> Assumption -> a) -> (NodeAddr -> Derivation -> a) -> Proof -> [a]
- pMapLines :: (Assumption -> Assumption) -> (Derivation -> Derivation) -> Proof -> Proof
- pMapLinesAccumL :: (s -> Assumption -> (s, Assumption)) -> (s -> Derivation -> (s, Derivation)) -> s -> Proof -> (s, Proof)
- pMapLinesWithLineNo :: (Int -> Assumption -> Assumption) -> (Int -> Derivation -> Derivation) -> Proof -> Proof
- pMapLinesWithAddr :: (NodeAddr -> Assumption -> Assumption) -> (NodeAddr -> Derivation -> Derivation) -> Proof -> Proof
- pMapLinesM :: Monad m => (Assumption -> m Assumption) -> (Derivation -> m Derivation) -> Proof -> m Proof
- pMapLinesMAccumL :: Monad m => (s -> Assumption -> m (s, Assumption)) -> (s -> Derivation -> m (s, Derivation)) -> s -> Proof -> m (s, Proof)
- pMapRefs :: (Reference -> Maybe Reference) -> Proof -> Proof
- data NodeAddr
- isNAAssumption :: NodeAddr -> Bool
- isNestedNAAssumption :: NodeAddr -> Bool
- isNestedNAConclusion :: NodeAddr -> Bool
- naInSameProof :: NodeAddr -> NodeAddr -> Bool
- paInSameProof :: ProofAddr -> ProofAddr -> Bool
- isFirstLineIn :: Proof -> NodeAddr -> Bool
- data ProofAddr
- paProofToNested :: ProofAddr -> ProofAddr -> ProofAddr
- paContaining :: NodeAddr -> ProofAddr
- fromLineNo :: Int -> Proof -> Maybe NodeAddr
- fromNodeAddr :: NodeAddr -> Proof -> Maybe Int
- lineNoOr999 :: NodeAddr -> Proof -> Int
- fromLineRange :: Int -> Int -> Proof -> Maybe ProofAddr
- lineRangeFromProofAddr :: ProofAddr -> Proof -> Maybe (Int, Int)
- incrementNodeAddr :: NodeAddr -> Maybe NodeAddr
- paFromNA :: NodeAddr -> Proof -> Maybe ProofAddr
- naFromPA :: ProofAddr -> NodeAddr -> NodeAddr
- naLevelup2 :: NodeAddr -> Maybe (NodeAddr -> NodeAddr)
- proofErrors :: Proof -> Int
- holdsAt :: (a -> Bool) -> [a] -> Int -> Bool
- holdsAtNA :: (Either Assumption Derivation -> Bool) -> Proof -> NodeAddr -> Bool
- naValid :: NodeAddr -> Proof -> Bool
- naLookup :: NodeAddr -> Proof -> Maybe (Either Assumption Derivation)
- paLookup :: ProofAddr -> Proof -> Maybe Proof
- pIndex :: Int -> Proof -> Maybe (Either Assumption Derivation)
- pIndexProof :: Int -> Int -> Proof -> Maybe Proof
- naAffectsFreshness :: NodeAddr -> NodeAddr -> Bool
- pCollectFreshnessNodes :: Proof -> NodeAddr -> [(NodeAddr, Either Assumption Derivation)]
- naUpdateFormula :: Either (Assumption -> Assumption) (Formula -> Formula) -> NodeAddr -> Proof -> Maybe Proof
- naUpdateRule :: (Wrapper RuleApplication -> Wrapper RuleApplication) -> NodeAddr -> Proof -> Maybe Proof
- naRemoveRaw :: NodeAddr -> Proof -> Maybe Proof
- paRemoveRaw :: ProofAddr -> Proof -> Maybe Proof
- naRemove :: NodeAddr -> Proof -> Maybe Proof
- paRemove :: ProofAddr -> Proof -> Maybe Proof
- naInsertBeforeRaw :: Either Assumption Derivation -> NodeAddr -> Proof -> Maybe (NodeAddr, Proof)
- naInsertBefore :: Either Assumption Derivation -> NodeAddr -> Proof -> Maybe (NodeAddr, Proof)
- paInsertBeforeRaw :: Proof -> ProofAddr -> Proof -> Maybe (ProofAddr, Proof)
- paInsertBefore :: Proof -> ProofAddr -> Proof -> Maybe (ProofAddr, Proof)
- naMoveBeforeRaw :: NodeAddr -> NodeAddr -> Proof -> Maybe (NodeAddr, Proof)
- targetInRange :: Int -> (Int, Int) -> Proof -> Bool
- naMoveBefore :: NodeAddr -> NodeAddr -> Proof -> Maybe (NodeAddr, Proof)
- naContainedIn :: NodeAddr -> ProofAddr -> Bool
- paContainedIn :: ProofAddr -> ProofAddr -> Bool
- naSameOrNext :: NodeAddr -> NodeAddr -> Proof -> Bool
- paSameOrNext :: ProofAddr -> ProofAddr -> Bool
- naCanMoveConclusion :: NodeAddr -> Proof -> Bool
- naCanMoveBefore :: Proof -> NodeAddr -> NodeAddr -> Bool
- paCanMoveBefore :: ProofAddr -> ProofAddr -> Bool
- paMoveBeforeRaw :: ProofAddr -> ProofAddr -> Proof -> Maybe (ProofAddr, Proof)
- paMoveBefore :: ProofAddr -> ProofAddr -> Proof -> Maybe (ProofAddr, Proof)
Pretty-printing
class PrettyPrint a where Source #
Type class for pretty printing as Text.
Instances
Parsed wrappers
Wraps data with parsing and semantic information.
Constructors
| ParsedValid :: forall a. Text -> a -> Wrapper a | Semantically valid parse success. |
| ParsedInvalid | Semantically invalid parse success. |
| Unparsed | Parse failure. |
Instances
| PrettyPrint Assumption Source # | |
Defined in Fitch.Proof Methods prettyPrint :: Assumption -> Text Source # | |
| Functor Wrapper Source # | |
| PrettyPrint (Wrapper RuleApplication) Source # | |
Defined in Fitch.Proof Methods prettyPrint :: Wrapper RuleApplication -> Text Source # | |
| PrettyPrint (Wrapper a) Source # | |
Defined in Fitch.Proof Methods prettyPrint :: Wrapper a -> Text Source # | |
| Show a => Show (Wrapper a) Source # | |
| Eq a => Eq (Wrapper a) Source # | |
isParseValid :: Wrapper a -> Bool Source #
Returns whether a Wrapper represents a semantically valid parse.
fromWrapper :: Wrapper a -> Maybe a Source #
Extract data from a wrapper, returns Nothing if no data is present.
proofPreviewTex :: Proof -> Text Source #
Renders a short preview of a Proof as assumptions followed by its conclusion.
Proof Types
Type of symbolic names such as variables, predicates, rules, and operators.
A term in first-order logics consists either of a variable or a function applied to terms.
Constructors
| Var Name | A single variable in first-order logic |
| Fun Name [Term] | A function applied to terms in first-order logic |
Instances
| PrettyPrint Term Source # | |
Defined in Fitch.Proof Methods prettyPrint :: Term -> Text Source # | |
| AllVars Term Source # | |
| FreeVars Term Source # | |
| Show Term Source # | |
| Eq Term Source # | |
| Ord Term Source # | |
| Substitute RawFormula Term Source # | |
Defined in Fitch.Unification Methods subst :: Subst Term -> RawFormula -> RawFormula Source # | |
| Substitute Term Term Source # | |
data RawFormula Source #
A formula of first-order logic.
It can also represent propositional formulae by using Pred without any Terms.
Constructors
| Pred Name [Term] | A predicate applied to terms. |
| InfixPred Name Term Term | A predicate written in infix notation. |
| Opr Text [RawFormula] | An n-ary operator, like |
| Quantifier Name Name RawFormula | A quantifier, like |
Instances
| FromText RawFormula Source # | |
Defined in App.Update | |
| PrettyPrint RawFormula Source # | |
Defined in Fitch.Proof Methods prettyPrint :: RawFormula -> Text Source # | |
| AllVars RawFormula Source # | |
Defined in Fitch.Unification | |
| FreeVars RawFormula Source # | |
Defined in Fitch.Unification | |
| Show RawFormula Source # | |
Defined in Fitch.Proof Methods showsPrec :: Int -> RawFormula -> ShowS # show :: RawFormula -> String # showList :: [RawFormula] -> ShowS # | |
| Eq RawFormula Source # | |
Defined in Fitch.Proof | |
| Ord RawFormula Source # | |
Defined in Fitch.Proof Methods compare :: RawFormula -> RawFormula -> Ordering # (<) :: RawFormula -> RawFormula -> Bool # (<=) :: RawFormula -> RawFormula -> Bool # (>) :: RawFormula -> RawFormula -> Bool # (>=) :: RawFormula -> RawFormula -> Bool # max :: RawFormula -> RawFormula -> RawFormula # min :: RawFormula -> RawFormula -> RawFormula # | |
| Substitute RawFormula Term Source # | |
Defined in Fitch.Unification Methods subst :: Subst Term -> RawFormula -> RawFormula Source # | |
A reference to either a single line or a whole subproof.
Constructors
| LineReference :: Int -> Reference | Referencing a single line. |
| ProofReference :: Int -> Int -> Reference | Referencing a subproof by its line range. |
type Formula = Wrapper RawFormula Source #
A formula with parsing and semantic information.
data RawAssumption Source #
The raw content of an Assumption.
Constructors
| FreshVar Name | A fresh variable of a |
| RawAssumption RawFormula | A regular |
Instances
| FromText RawAssumption Source # | |
Defined in App.Update | |
| PrettyPrint Assumption Source # | |
Defined in Fitch.Proof Methods prettyPrint :: Assumption -> Text Source # | |
| PrettyPrint RawAssumption Source # | |
Defined in Fitch.Proof Methods prettyPrint :: RawAssumption -> Text Source # | |
| AllVars RawAssumption Source # | |
Defined in Fitch.Unification | |
| FreeVars RawAssumption Source # | |
Defined in Fitch.Unification | |
| Show RawAssumption Source # | |
Defined in Fitch.Proof Methods showsPrec :: Int -> RawAssumption -> ShowS # show :: RawAssumption -> String # showList :: [RawAssumption] -> ShowS # | |
| Eq RawAssumption Source # | |
Defined in Fitch.Proof Methods (==) :: RawAssumption -> RawAssumption -> Bool # (/=) :: RawAssumption -> RawAssumption -> Bool # | |
type Assumption = (Wrapper RawAssumption, Wrapper RuleApplication) Source #
A wrapped assumption together with its attached RuleApplication
for easily converting between Assumption and Derivation.
mkAssumption :: Wrapper RawAssumption -> Assumption Source #
Constructs an Assumption with the default rule (⊤I).
toAssumption :: Derivation -> Assumption Source #
Converts a Derivation into an Assumption by wrapping its formula
as a RawAssumption.
toDerivation :: Assumption -> Derivation Source #
Converts an Assumption into a Derivation.
Fresh-variable assumptions cannot be converted to formulas and are therefore turned
into Unparsed.
data RuleApplication Source #
Application of a rule.
Constructors
| RuleApplication Name [Reference] | Application of a rule, consisting of the rule |
Instances
| FromText RuleApplication Source # | |
Defined in App.Update | |
| PrettyPrint Assumption Source # | |
Defined in Fitch.Proof Methods prettyPrint :: Assumption -> Text Source # | |
| PrettyPrint RuleApplication Source # | |
Defined in Fitch.Proof Methods prettyPrint :: RuleApplication -> Text Source # | |
| Show RuleApplication Source # | |
Defined in Fitch.Proof Methods showsPrec :: Int -> RuleApplication -> ShowS # show :: RuleApplication -> String # showList :: [RuleApplication] -> ShowS # | |
| Eq RuleApplication Source # | |
Defined in Fitch.Proof Methods (==) :: RuleApplication -> RuleApplication -> Bool # (/=) :: RuleApplication -> RuleApplication -> Bool # | |
| PrettyPrint (Wrapper RuleApplication) Source # | |
Defined in Fitch.Proof Methods prettyPrint :: Wrapper RuleApplication -> Text Source # | |
data Derivation Source #
A derivation inside a Proof.
Constructors
| Derivation Formula (Wrapper RuleApplication) | A single proof line consisting of a |
Instances
| PrettyPrint Derivation Source # | |
Defined in Fitch.Proof Methods prettyPrint :: Derivation -> Text Source # | |
| Show Derivation Source # | |
Defined in Fitch.Proof Methods showsPrec :: Int -> Derivation -> ShowS # show :: Derivation -> String # showList :: [Derivation] -> ShowS # | |
| Eq Derivation Source # | |
Defined in Fitch.Proof | |
A datatype for representing Fitch-style proofs.
Constructors
| SubProof :: [Assumption] -> [Either Derivation Proof] -> Derivation -> Proof | A sub proof consisting of |
Folds and Maps
pFoldLines :: (a -> Assumption -> a) -> (a -> Derivation -> a) -> a -> Proof -> a Source #
folds the proof pFoldLines af df s pp line-wise to a value
of type a with starting value s.
pFoldLinesM :: Monad m => (a -> Assumption -> m a) -> (a -> Derivation -> m a) -> a -> Proof -> m a Source #
Monadic variant of pFoldLines.
pSerialize :: (Assumption -> a) -> (Derivation -> a) -> ([a] -> a) -> (Derivation -> a) -> Proof -> [a] Source #
Serializes a Proof by mapping Assumptions, Derivations, Proofs,
and conclusions.
Nested proofs are first serialized recursively
and then combined with the given proof function.
pSerializeLines :: (Assumption -> a) -> (Derivation -> a) -> Proof -> [a] Source #
pSerializeLines af df p serializes the Proof p line-by-line,
applying af to each Assumption and df to each Derivation,
and collecting the results into a flat list.
pSerializeLinesWithAddr :: (NodeAddr -> Assumption -> a) -> (NodeAddr -> Derivation -> a) -> Proof -> [a] Source #
Like pSerializeLines but also passes the current NodeAddr
to each mapping function.
pMapLines :: (Assumption -> Assumption) -> (Derivation -> Derivation) -> Proof -> Proof Source #
maps each line of the pMapLines af df pProof p,
applying af to every Assumption and df to every Derivation.
pMapLinesAccumL :: (s -> Assumption -> (s, Assumption)) -> (s -> Derivation -> (s, Derivation)) -> s -> Proof -> (s, Proof) Source #
Like pMapLines, but threads an accumulator from left to right.
pMapLinesWithLineNo :: (Int -> Assumption -> Assumption) -> (Int -> Derivation -> Derivation) -> Proof -> Proof Source #
Like pMapLines, but also passes the current line number to the mapping functions.
pMapLinesWithAddr :: (NodeAddr -> Assumption -> Assumption) -> (NodeAddr -> Derivation -> Derivation) -> Proof -> Proof Source #
pMapLinesM :: Monad m => (Assumption -> m Assumption) -> (Derivation -> m Derivation) -> Proof -> m Proof Source #
Like pMapLines but lifted to monadic results.
pMapLinesMAccumL :: Monad m => (s -> Assumption -> m (s, Assumption)) -> (s -> Derivation -> m (s, Derivation)) -> s -> Proof -> m (s, Proof) Source #
Like pMapLinesM but threads an accumulator from left to right.
Indexing proofs
This type is used for indexing lines in a proof. Its recursive structure makes defining functions that manipulate proofs more convenient
A NodeAddr may either be a reference to
- a single
Assumption:NAAssumptionn, - the conclusion:
NAConclusionof theProof - the spot after the conclusion:
NAAfterConclusion - a single
Derivationinside the proofNALinen - a reference to a nested element inside the
ProofNAProofn(Justa)
Constructors
| NAAssumption Int | The |
| NAConclusion | The conclusion of the current proof. |
| NAAfterConclusion | The position directly after the conclusion of the current proof. |
| NALine Int | The |
| NAProof Int NodeAddr | A nested address inside the |
isNAAssumption :: NodeAddr -> Bool Source #
Returns whether a NodeAddr points to an assumption of the current proof level.
isNestedNAAssumption :: NodeAddr -> Bool Source #
Returns whether a NodeAddr points to a possibly nested Assumption.
isNestedNAConclusion :: NodeAddr -> Bool Source #
Returns whether a NodeAddr points to a possibly nested Assumption.
isFirstLineIn :: Proof -> NodeAddr -> Bool Source #
Returns whether a NodeAddr is the first line
in a Proof. This could be because:
- it is the first assumption;
- there are no assumptions and it is the first line;
- there are no assumptions and it is the first line of the first subproof;
- there are no assumptions, no lines, no subproofs and it is the conclusion.
Instances
| Show ProofAddr Source # | |
| Eq ProofAddr Source # | |
| Ord ProofAddr Source # | |
Conversion between line numbers and NodeAddr
lineNoOr999 :: NodeAddr -> Proof -> Int Source #
Like fromNodeAddr,
but falls back to line number 999 if the NodeAddr is invalid.
Utilities for working with addresses
incrementNodeAddr :: NodeAddr -> Maybe NodeAddr Source #
Increments a NodeAddr index by 1, keeping the nesting structure unchanged.
Returns Nothing for addresses without a numeric index (e.g. NAConclusion).
naLevelup2 :: NodeAddr -> Maybe (NodeAddr -> NodeAddr) Source #
Returns a function that lifts a nested NodeAddr by one proof level, if possible.
Querying proofs
proofErrors :: Proof -> Int Source #
Counts the number of parse or validation errors occurring in a Proof.
holdsAt :: (a -> Bool) -> [a] -> Int -> Bool Source #
Returns whether the element at the given index exists and satisfies a predicate.
holdsAtNA :: (Either Assumption Derivation -> Bool) -> Proof -> NodeAddr -> Bool Source #
Returns whether the element at the given NodeAddr exists
and satisfies a predicate.
naLookup :: NodeAddr -> Proof -> Maybe (Either Assumption Derivation) Source #
pIndex :: Int -> Proof -> Maybe (Either Assumption Derivation) Source #
Returns the Assumption or Derivation at the given line number if it exists.
pIndexProof :: Int -> Int -> Proof -> Maybe Proof Source #
Returns the Proof spanning the given start and end line numbers if it exists.
pCollectFreshnessNodes :: Proof -> NodeAddr -> [(NodeAddr, Either Assumption Derivation)] Source #
Collects all lines relevant for freshness checking of the given NodeAddr.
Updating proof contents
naUpdateFormula :: Either (Assumption -> Assumption) (Formula -> Formula) -> NodeAddr -> Proof -> Maybe Proof Source #
naUpdateFormula f addr proof replaces the Assumption or
tFormula at addr in proof using f.
Pass Left to update an Assumption, or Right
to update the Formula of a Derivation.
Returns Nothing if the address does not exist or is incompatible
with the chosen update function.
naUpdateRule :: (Wrapper RuleApplication -> Wrapper RuleApplication) -> NodeAddr -> Proof -> Maybe Proof Source #
naUpdateRule f addr proof updates the RuleApplication
at addr in proof using f.
Returns Nothing if the address does not exist
or points to an Assumption (which has no editable RuleApplication).
(Re-)moving inside a proof
naRemoveRaw :: NodeAddr -> Proof -> Maybe Proof Source #
removes the element at a valid naRemoveRaw addr proofaddr from proof
without updating any References.
For the NAConclusion case: if the last element of ps is a Derivation,
it is promoted to become the new conclusion. Otherwise Nothing is returned.
Note: Use naRemove if references must stay consistent.
naRemove :: NodeAddr -> Proof -> Maybe Proof Source #
Removes the line at a valid NodeAddr and updates all affected references.
naInsertBeforeRaw :: Either Assumption Derivation -> NodeAddr -> Proof -> Maybe (NodeAddr, Proof) Source #
Inserts a line before the given NodeAddr in the Proof,
without updating References.
naInsertBeforeRaw(Lefta)addrproofinserts theAssumptionabeforeaddr.naInsertBeforeRaw(Rightd)addrproofinserts theDerivationdbeforeaddr.
Returns the NodeAddr of the inserted line together with the updated Proof.
Returns Nothing if line could not be inserted.
Note: Use naInsertBefore if references must stay consistent.
naInsertBefore :: Either Assumption Derivation -> NodeAddr -> Proof -> Maybe (NodeAddr, Proof) Source #
Like naInsertBeforeRaw, but also updates references affected by the insertion.
Returns the NodeAddr of the inserted line together with the updated Proof.
paInsertBefore :: Proof -> ProofAddr -> Proof -> Maybe (ProofAddr, Proof) Source #
Like paInsertBeforeRaw, but also updates references affected by the insertion.
Returns the ProofAddr of the inserted Proof together with the updated Proof.
targetInRange :: Int -> (Int, Int) -> Proof -> Bool Source #
Returns whether lineNo falls within the given line range,
accounting for same-proof boundary rules.
naMoveBefore :: NodeAddr -> NodeAddr -> Proof -> Maybe (NodeAddr, Proof) Source #
Moves the line at source before the line at target in Proof p,
and updates all References affected by the move.
Returns Nothing if the move is rejected by naCanMoveBefore.
naSameOrNext :: NodeAddr -> NodeAddr -> Proof -> Bool Source #
Returns whether the target address is identical to, or immediately after, the source.
paSameOrNext :: ProofAddr -> ProofAddr -> Bool Source #
Returns whether the target address is identical to, or immediately after, the source.
naCanMoveConclusion :: NodeAddr -> Proof -> Bool Source #
Helper for deciding whether a NodeAddr may be moved to the target position
defaulting to True and only does a real check for NAConclusion where it
checks whether the conclusion has a Derivation that can take its place, when it moves.