ivor-0.1.8: Theorem proving library based on dependent type theorySource codeContentsIndex
Ivor.TT
Portabilitynon-portable
Stabilityexperimental
Maintainereb@dcs.st-and.ac.uk
Contents
System state
Exported view of terms
Definitions and Theorems
Pattern matching definitions
Manipulating Proof State
Examining the Context
Goals, tactic types
Primitive Tactics
Basics
Proof navigation
Introductions
Eliminations
Conversions
Equality
Computations
Staging
Tactic combinators
Description
Public interface for theorem proving gadgets.
Synopsis
emptyContext :: Context
data Context
fastCheck :: Context -> ViewTerm -> Term
checkCtxt :: (IsTerm a, Monad m) => Context -> Goal -> a -> m Term
converts :: (Monad m, IsTerm a, IsTerm b) => Context -> Goal -> a -> b -> m Bool
compile :: Context -> String -> IO ()
class IsTerm a where
check :: Monad m => Context -> a -> m Term
class IsData a where
addData :: Monad m => Context -> a -> m Context
addDataNoElim :: Monad m => Context -> a -> m Context
addDef :: (IsTerm a, Monad m) => Context -> Name -> a -> m Context
addTypedDef :: (IsTerm term, IsTerm ty, Monad m) => Context -> Name -> term -> ty -> m Context
addAxiom :: (IsTerm a, Monad m) => Context -> Name -> a -> m Context
declare :: (IsTerm a, Monad m) => Context -> Name -> a -> m Context
declareData :: (IsTerm a, Monad m) => Context -> Name -> a -> m Context
theorem :: (IsTerm a, Monad m) => Context -> Name -> a -> m Context
interactive :: (IsTerm a, Monad m) => Context -> Name -> a -> m Context
addPrimitive :: Monad m => Context -> Name -> m Context
addBinOp :: (ViewConst a, ViewConst b, ViewConst c, IsTerm ty, Monad m) => Context -> Name -> (a -> b -> c) -> ty -> m Context
addBinFn :: (ViewConst a, ViewConst b, IsTerm ty, Monad m) => Context -> Name -> (a -> b -> ViewTerm) -> ty -> m Context
addPrimFn :: (ViewConst a, IsTerm ty, Monad m) => Context -> Name -> (a -> ViewTerm) -> ty -> m Context
addExternalFn :: (IsTerm ty, Monad m) => Context -> Name -> Int -> ([ViewTerm] -> Maybe ViewTerm) -> ty -> m Context
addEquality :: Monad m => Context -> Name -> Name -> m Context
forgetDef :: Monad m => Context -> Name -> m Context
addGenRec :: Monad m => Context -> Name -> m Context
addImplicit :: Context -> ViewTerm -> (Int, ViewTerm)
data PClause = PClause {
arguments :: [ViewTerm]
returnval :: ViewTerm
}
data Patterns = Patterns [PClause]
data PattOpt
= Partial
| GenRec
| Holey
addPatternDef :: (IsTerm ty, Monad m) => Context -> Name -> ty -> Patterns -> [PattOpt] -> m (Context, [(Name, ViewTerm)])
toPattern :: Context -> ViewTerm -> ViewTerm
proving :: Context -> Bool
numUnsolved :: Context -> Int
suspend :: Context -> Context
resume :: Monad m => Context -> Name -> m Context
save :: Context -> Context
restore :: Monad m => Context -> m Context
clearSaved :: Context -> Context
proofterm :: Monad m => Context -> m Term
getGoals :: Context -> [Goal]
getGoal :: Monad m => Context -> Goal -> m ([(Name, Term)], Term)
uniqueName :: Monad m => Context -> Name -> m Name
allSolved :: Context -> Bool
qed :: Monad m => Context -> m Context
eval :: Context -> Term -> Term
whnf :: Context -> Term -> Term
evalnew :: Context -> Term -> Term
evalCtxt :: (IsTerm a, Monad m) => Context -> Goal -> a -> m Term
getDef :: Monad m => Context -> Name -> m Term
defined :: Context -> Name -> Bool
getPatternDef :: Monad m => Context -> Name -> m (ViewTerm, Patterns)
getAllTypes :: Context -> [(Name, Term)]
getAllDefs :: Context -> [(Name, Term)]
getAllPatternDefs :: Context -> [(Name, (ViewTerm, Patterns))]
getConstructors :: Monad m => Context -> Name -> m [Name]
getInductive :: Monad m => Context -> Name -> m Inductive
getAllInductives :: Context -> [(Name, Inductive)]
getType :: Monad m => Context -> Name -> m Term
data Rule
= Case
| Elim
getElimRule :: Monad m => Context -> Name -> Rule -> m Patterns
nameType :: Monad m => Context -> Name -> m NameType
getConstructorTag :: Monad m => Context -> Name -> m Int
getConstructorArity :: Monad m => Context -> Name -> m Int
freeze :: Monad m => Context -> Name -> m Context
thaw :: Monad m => Context -> Name -> m Context
data Goal
goal :: String -> Goal
defaultGoal :: Goal
type Tactic = forall m. Monad m => Goal -> Context -> m Context
data GoalData
bindings :: GoalData -> [(Name, Term)]
goalName :: GoalData -> Goal
goalType :: GoalData -> Term
goalData :: Monad m => Context -> Bool -> Goal -> m GoalData
subGoals :: Monad m => Context -> m [(Name, Term)]
intro :: Tactic
introName :: Name -> Tactic
intros :: Tactic
intros1 :: Tactic
introsNames :: [Name] -> Tactic
addArg :: IsTerm a => Name -> a -> Tactic
generalise :: IsTerm a => a -> Tactic
dependentGeneralise :: IsTerm a => a -> Tactic
claim :: IsTerm a => Name -> a -> Tactic
focus :: Tactic
rename :: Name -> Tactic
attack :: Tactic
attackWith :: Name -> Tactic
solve :: Tactic
trySolve :: Tactic
keepSolving :: Tactic
abandon :: Tactic
hide :: Tactic
fill :: IsTerm a => a -> Tactic
refine :: IsTerm a => a -> Tactic
basicRefine :: IsTerm a => a -> Tactic
refineWith :: IsTerm a => a -> [a] -> Tactic
trivial :: Tactic
axiomatise :: Name -> [Name] -> Tactic
by :: IsTerm a => a -> Tactic
induction :: IsTerm a => a -> Tactic
cases :: IsTerm a => a -> Tactic
equiv :: IsTerm a => a -> Tactic
compute :: Tactic
beta :: Tactic
unfold :: Name -> Tactic
replace :: (IsTerm a, IsTerm b, IsTerm c, IsTerm d) => a -> b -> c -> d -> Bool -> Tactic
call :: IsTerm a => a -> Tactic
returnComputation :: Tactic
quoteVal :: Tactic
idTac :: Tactic
tacs :: Monad m => [Goal -> Context -> m Context] -> Goal -> Context -> m Context
(>->) :: Tactic -> Tactic -> Tactic
(>=>) :: Tactic -> Tactic -> Tactic
(>+>) :: Tactic -> Tactic -> Tactic
(>|>) :: Tactic -> Tactic -> Tactic
try :: Tactic -> Tactic -> Tactic -> Tactic
traceTac :: Tactic
System state
emptyContext :: ContextSource
Initialise a context, with no data or definitions and an empty proof state.
data Context Source
Abstract type representing state of the system.
fastCheck :: Context -> ViewTerm -> TermSource
Quickly convert a ViewTerm into a real Term. This is dangerous; you must know that typechecking will succeed, and the resulting term won't have a valid type, but you will be able to run it. This is useful if you simply want to do a substitution into a ViewTerm.
checkCtxt :: (IsTerm a, Monad m) => Context -> Goal -> a -> m TermSource
Check a term in the context of the given goal
converts :: (Monad m, IsTerm a, IsTerm b) => Context -> Goal -> a -> b -> m BoolSource
Check whether the conversion relation holds between two terms, in the context of the given goal
compileSource
:: Contextcontext to compile
-> Stringroot of filenames to generate
-> IO ()
Create a .hs file containing (unreadable) Haskell code implementing all of the definitions. (TODO: Generate a more readable, usable interface)
Exported view of terms
class IsTerm a whereSource
Methods
check :: Monad m => Context -> a -> m TermSource
Typecheck a term
show/hide Instances
class IsData a whereSource
Methods
addData :: Monad m => Context -> a -> m ContextSource
addDataNoElim :: Monad m => Context -> a -> m ContextSource
show/hide Instances
Definitions and Theorems
addDef :: (IsTerm a, Monad m) => Context -> Name -> a -> m ContextSource
Add a new definition to the global state.
addTypedDef :: (IsTerm term, IsTerm ty, Monad m) => Context -> Name -> term -> ty -> m ContextSource
Add a new definition, with its type to the global state. These definitions can be recursive, so use with care.
addAxiom :: (IsTerm a, Monad m) => Context -> Name -> a -> m ContextSource
Add a new axiom to the global state.
declare :: (IsTerm a, Monad m) => Context -> Name -> a -> m ContextSource
Declare a name which is to be defined later
declareData :: (IsTerm a, Monad m) => Context -> Name -> a -> m ContextSource
Declare a type constructor which is to be defined later
theorem :: (IsTerm a, Monad m) => Context -> Name -> a -> m ContextSource
Begin a new proof.
interactive :: (IsTerm a, Monad m) => Context -> Name -> a -> m ContextSource
Begin a new interactive definition. Actually, just the same as theorem but this version allows you to make recursive calls, which should of course be done with care.
addPrimitiveSource
:: Monad m
=> Context
-> NameType name
-> m Context
Add a new primitive type. This should be done in assocation with creating an instance of ViewConst for the type, and creating appropriate primitive functions.
addBinOp :: (ViewConst a, ViewConst b, ViewConst c, IsTerm ty, Monad m) => Context -> Name -> (a -> b -> c) -> ty -> m ContextSource
Add a new binary operator on constants. Warning: The type you give is not checked!
addBinFn :: (ViewConst a, ViewConst b, IsTerm ty, Monad m) => Context -> Name -> (a -> b -> ViewTerm) -> ty -> m ContextSource
Add a new binary function on constants. Warning: The type you give is not checked!
addPrimFn :: (ViewConst a, IsTerm ty, Monad m) => Context -> Name -> (a -> ViewTerm) -> ty -> m ContextSource
Add a new primitive function on constants, usually used for converting to some form which can be examined in the type theory itself. Warning: The type you give is not checked!
addExternalFnSource
:: (IsTerm ty, Monad m)
=> Context
-> Name
-> Intarity
-> [ViewTerm] -> Maybe ViewTermThe function, which must accept a list of the right length given by arity.
-> ty
-> m Context
Add a new externally defined function. Warning: The type you give is not checked!
addEqualitySource
:: Monad m
=> Context
-> NameName to give equality type
-> NameName to give constructor
-> m Context
Add the heterogenous ("John Major") equality rule and its reduction
forgetDef :: Monad m => Context -> Name -> m ContextSource
Forget a definition and all following definitions.
addGenRecSource
:: Monad m
=> Context
-> NameName to give recursion rule
-> m Context
Add the general recursion elimination rule, thus making all further definitions untrustworthy :).
addImplicit :: Context -> ViewTerm -> (Int, ViewTerm)Source
Add implicit binders for names used in a type, but not declared. |Returns the new type and the number of implicit names bound.
Pattern matching definitions
data PClause Source
Constructors
PClause
arguments :: [ViewTerm]
returnval :: ViewTerm
show/hide Instances
data Patterns Source
Constructors
Patterns [PClause]
show/hide Instances
data PattOpt Source
Constructors
PartialNo need to cover all cases
GenRecNo termination checking
HoleyAllow metavariables in the definition, which will become theorems which need to be proved.
show/hide Instances
addPatternDefSource
:: (IsTerm ty, Monad m)
=> Context
-> Name
-> tyType
-> PatternsDefinition
-> [PattOpt]Options to set which definitions will be accepted
-> m (Context, [(Name, ViewTerm)])
Add a new definition to the global state. By default, these definitions must cover all cases and be well-founded, but can be optionally partial or general recursive. Returns the new context, and a list of names which need to be defined to complete the definition.
toPattern :: Context -> ViewTerm -> ViewTermSource
Manipulating Proof State
proving :: Context -> BoolSource
Return whether we are in the middle of proving something.
numUnsolved :: Context -> IntSource
Get the number of unsolved goals
suspend :: Context -> ContextSource
Suspend the current proof. Clears the current proof state; use resume to continue the proof.
resume :: Monad m => Context -> Name -> m ContextSource
Resume an unfinished proof, suspending the current one if necessary. Fails if there is no such name. Can also be used to begin a proof of an identifier previously claimed as an axiom. Remember that you will need to attack the goal if you are resuming an axiom.
save :: Context -> ContextSource
Save the state (e.g. for Undo)
restore :: Monad m => Context -> m ContextSource
Restore a saved state; fails if none have been saved.
clearSaved :: Context -> ContextSource
Clears the saved state (e.g. if undo no longer makes sense, like when a proof has been completed)
proofterm :: Monad m => Context -> m TermSource
Get the current proof term, if we are in the middle of a proof.
getGoals :: Context -> [Goal]Source
Get the goals still to be solved.
getGoal :: Monad m => Context -> Goal -> m ([(Name, Term)], Term)Source
Get the type and context of the given goal, if it exists
uniqueNameSource
:: Monad m
=> Context
-> NameSuggested name
-> m NameUnique name based on suggested name
Create a name unique in the proof state
allSolved :: Context -> BoolSource
Return whether all goals have been solved.
qed :: Monad m => Context -> m ContextSource
Lift a finished proof into the context
Examining the Context
eval :: Context -> Term -> TermSource
Normalise a term and its type (using old evaluator_
whnf :: Context -> Term -> TermSource
Reduce a term and its type to Weak Head Normal Form
evalnew :: Context -> Term -> TermSource
Reduce a term and its type to Normal Form (using new evaluator)
evalCtxt :: (IsTerm a, Monad m) => Context -> Goal -> a -> m TermSource
Evaluate a term in the context of the given goal
getDef :: Monad m => Context -> Name -> m TermSource
Lookup a definition in the context.
defined :: Context -> Name -> BoolSource
Check whether a name is defined
getPatternDef :: Monad m => Context -> Name -> m (ViewTerm, Patterns)Source
Lookup a pattern matching definition in the context. Return the type and the pattern definition.
getAllTypes :: Context -> [(Name, Term)]Source
Get all the names and types in the context
getAllDefs :: Context -> [(Name, Term)]Source
getAllPatternDefs :: Context -> [(Name, (ViewTerm, Patterns))]Source
Get all the pattern matching definitions in the context. Also returns CAFs (i.e. 0 argument functions)
getConstructors :: Monad m => Context -> Name -> m [Name]Source
Get the names of all of the constructors of an inductive family
getInductive :: Monad m => Context -> Name -> m InductiveSource
Return the data type with the given name. Note that this knows nothing about the difference between parameters and indices; that information is discarded after the elimination rule is constructed.
getAllInductives :: Context -> [(Name, Inductive)]Source
Get all the inductive type definitions in the context.
getType :: Monad m => Context -> Name -> m TermSource
Get the type of a definition in the context.
data Rule Source
Types of elimination rule
Constructors
Case
Elim
getElimRuleSource
:: Monad m
=> Context
-> NameType
-> RuleWhich rule to get patterns for (case or elim)
-> m Patterns
Get the pattern matching elimination rule for a type
nameType :: Monad m => Context -> Name -> m NameTypeSource
Find out what type of variable the given name is
getConstructorTag :: Monad m => Context -> Name -> m IntSource
Get an integer tag for a constructor. Each constructor has a tag unique within the data type, which could be used by a compiler.
getConstructorArity :: Monad m => Context -> Name -> m IntSource
Get the arity of the given constructor.
freeze :: Monad m => Context -> Name -> m ContextSource
Freeze a name (i.e., set it so that it does not reduce) Fails if the name does not exist.
thaw :: Monad m => Context -> Name -> m ContextSource
Unfreeze a name (i.e., allow it to reduce). Fails if the name does not exist.
Goals, tactic types
data Goal Source
Abstract type representing goal or subgoal names.
show/hide Instances
goal :: String -> GoalSource
defaultGoal :: GoalSource
type Tactic = forall m. Monad m => Goal -> Context -> m ContextSource
A tactic is any function which manipulates a term at the given goal binding. Tactics may fail, hence the monad.
data GoalData Source
Environment and goal type for a given subgoal
bindings :: GoalData -> [(Name, Term)]Source
Get the premises of the goal
goalName :: GoalData -> GoalSource
Get the name of the goal
goalType :: GoalData -> TermSource
Get the type of the goal
goalDataSource
:: Monad m
=> Context
-> BoolGet all bindings (True), or just lambda bindings (False)
-> Goal
-> m GoalData
Get information about a subgoal.
subGoals :: Monad m => Context -> m [(Name, Term)]Source
Get the names and types of all goals
Primitive Tactics
Basics
intro :: TacticSource
Introduce an assumption (i.e. a lambda binding)
introNameSource
:: NameName for the assumption
-> Tactic
Introduce an assumption (i.e. a lambda binding)
intros :: TacticSource
Keep introducing things until there's nothing left to introduce.
intros1 :: TacticSource
Keep introducing things until there's nothing left to introduce, Must introduce at least one thing.
introsNames :: [Name] -> TacticSource
As intros, but with names, and stop when we've run out of names. Fails if too many names are given.
addArg :: IsTerm a => Name -> a -> TacticSource
Add a new top level argument after the arguments its type depends on (changing the type of the theorem). This can be useful if, for example, you find you need an extra premise to prove a goal.
generalise :: IsTerm a => a -> TacticSource
Abstract over the given term in the goal.
dependentGeneralise :: IsTerm a => a -> TacticSource
Abstract over the given term in the goal, and also all variables appearing in the goal whose types depend on it.
claim :: IsTerm a => Name -> a -> TacticSource
Make a local claim
Proof navigation
focus :: TacticSource
Focus on a different hole, i.e. set the default goal.
rename :: Name -> TacticSource
Rename the outermost binder in the given goal
attack :: TacticSource
Prepare a goal for introduction.
attackWithSource
:: NameName for new goal
-> Tactic
Prepare a goal for introduction.
solve :: TacticSource
Finalise a goal's solution.
trySolve :: TacticSource
If the goal has a solution, finalise it, otherwise prepare the goal (with attack). Typically, could be used on the subgoals generated by refinement, where some may have solutions attached already, and others will need to be prepared.
keepSolving :: TacticSource
Finalise as many solutions of as many goals as possible.
abandon :: TacticSource
Remove a solution from a goal.
hide :: TacticSource
Hide a premise
Introductions
fill :: IsTerm a => a -> TacticSource
Attach a solution to a goal.
refine :: IsTerm a => a -> TacticSource
Solve a goal by applying a function. If the term given has arguments, attempts to fill in these arguments by unification and solves them (with solve). See refineWith and basicRefine for slight variations.
basicRefine :: IsTerm a => a -> TacticSource
Solve a goal by applying a function. If the term given has arguments, this will create a subgoal for each. Some arguments may be solved by unification, in which case they will already have a guess attached after refinement, but the guess will not be solved (via solve).
refineWith :: IsTerm a => a -> [a] -> TacticSource
Solve a goal by applying a function with some arguments filled in. See refine for details.
trivial :: TacticSource
Find a trivial solution to the goal by searching through the context for a premise which solves it immediately by refinement
axiomatiseSource
:: NameName to give axiom
-> [Name]Premises to pass to axiom
-> Tactic
Add an axiom to the global context which would solve the goal, and apply it. FIXME: This tactic doesn't pick up all dependencies on types, but is okay for simply typed axioms, e.g. equations on Nats.
Eliminations
bySource
:: IsTerm a
=> aAn elimination rule applied to a target.
-> Tactic
Apply an eliminator.
inductionSource
:: IsTerm a
=> atarget of the elimination
-> Tactic
Apply the appropriate induction rule to the term.
casesSource
:: IsTerm a
=> atarget of the case analysis
-> Tactic
Apply the appropriate case analysis rule to the term. Like induction, but no induction hypotheses generated.
Conversions
equiv :: IsTerm a => a -> TacticSource
Check that the goal is definitionally equal to the given term, and rewrite the goal accordingly.
compute :: TacticSource
Normalise the goal
beta :: TacticSource
Beta reduce in the goal
unfold :: Name -> TacticSource
Beta reduce the goal, unfolding the given function
Equality
replaceSource
:: (IsTerm a, IsTerm b, IsTerm c, IsTerm d)
=> aEquality type (e.g. Eq : (A:*)(a:A)(b:A)*)
-> breplacement lemma (e.g. repl : (A:*)(a:A)(b:A)(q:Eq _ a b)(P:(a:A)*)(p:P a)(P b))
-> csymmetry lemma (e.g. sym : (A:*)(a:A)(b:A)(p:Eq _ a b)(Eq _ b a))
-> dequality premise
-> Boolapply premise backwards (i.e. apply symmetry)
-> Tactic
Replace a term in the goal according to an equality premise. Any equality type with three arguments is acceptable (i.e. the type, and the two values), provided there are suitable replacement and symmetry lemmas. Heterogeneous equality as provided by addEquality is acceptable (if you provide the lemmas!).
Computations
call :: IsTerm a => a -> TacticSource
Make a recursive call of a computation. The term must be an allowed recursive call, identified in the context by having a labelled type.
returnComputation :: TacticSource
Prepare to return a value in a computation
Staging
quoteVal :: TacticSource
Prepare to return a quoted value
Tactic combinators
idTac :: TacticSource
The Identity tactic, does nothing.
tacs :: Monad m => [Goal -> Context -> m Context] -> Goal -> Context -> m ContextSource
Apply a sequence of tactics to the default goal. Read the type as [Tactic] -> Tactic
(>->) :: Tactic -> Tactic -> TacticSource
Sequence two tactics; applies two tactics sequentially to the same goal
(>=>) :: Tactic -> Tactic -> TacticSource
Apply a tactic, then apply another to each subgoal generated.
(>+>) :: Tactic -> Tactic -> TacticSource
Apply a tactic, then apply the next tactic to the next default subgoal.
(>|>) :: Tactic -> Tactic -> TacticSource
Tries the left tactic, if that fails try the right one. Shorthand for try x idTac y.
trySource
:: TacticTactic to apply
-> TacticApply if first tactic succeeds
-> TacticApply if first tactic fails.
-> Tactic
Try a tactic.
traceTac :: TacticSource
The Tracing tactic; does nothing, but uses trace to dump the current proof state
Produced by Haddock version 2.4.2