ivor-0.1.9: 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
Errors
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 => Context -> Goal -> a -> TTM Term
converts :: (IsTerm a, IsTerm b) => Context -> Goal -> a -> b -> TTM Bool
compile :: Context -> String -> IO ()
class IsTerm a where
check :: Context -> a -> TTM Term
class IsData a where
addData :: Context -> a -> TTM Context
addDataNoElim :: Context -> a -> TTM Context
data TTError
= CantUnify ViewTerm ViewTerm
| NotConvertible ViewTerm ViewTerm
| Message String
| Unbound ViewTerm ViewTerm ViewTerm ViewTerm [Name]
| NoSuchVar Name
| ErrContext String TTError
ttfail :: String -> TTM a
getError :: IError -> TTError
type TTM = Either TTError
addDef :: IsTerm a => Context -> Name -> a -> TTM Context
addTypedDef :: (IsTerm term, IsTerm ty) => Context -> Name -> term -> ty -> TTM Context
addAxiom :: IsTerm a => Context -> Name -> a -> TTM Context
declare :: IsTerm a => Context -> Name -> a -> TTM Context
declareData :: IsTerm a => Context -> Name -> a -> TTM Context
theorem :: IsTerm a => Context -> Name -> a -> TTM Context
interactive :: IsTerm a => Context -> Name -> a -> TTM Context
addPrimitive :: Context -> Name -> TTM Context
addBinOp :: (ViewConst a, ViewConst b, ViewConst c, IsTerm ty) => Context -> Name -> (a -> b -> c) -> ty -> TTM Context
addBinFn :: (ViewConst a, ViewConst b, IsTerm ty) => Context -> Name -> (a -> b -> ViewTerm) -> ty -> TTM Context
addPrimFn :: (ViewConst a, IsTerm ty) => Context -> Name -> (a -> ViewTerm) -> ty -> TTM Context
addExternalFn :: IsTerm ty => Context -> Name -> Int -> ([ViewTerm] -> Maybe ViewTerm) -> ty -> TTM Context
addEquality :: Context -> Name -> Name -> TTM Context
forgetDef :: Context -> Name -> TTM Context
addGenRec :: Context -> Name -> TTM Context
addImplicit :: Context -> ViewTerm -> (Int, ViewTerm)
data PClause
= PClause {
arguments :: [ViewTerm]
returnval :: ViewTerm
}
| PWithClause {
arguments :: [ViewTerm]
scrutinee :: ViewTerm
patterns :: Patterns
}
data Patterns = Patterns [PClause]
data PattOpt
= Partial
| GenRec
| Holey
addPatternDef :: IsTerm ty => Context -> Name -> ty -> Patterns -> [PattOpt] -> TTM (Context, [(Name, ViewTerm)])
toPattern :: Context -> ViewTerm -> ViewTerm
proving :: Context -> Bool
numUnsolved :: Context -> Int
suspend :: Context -> Context
resume :: Context -> Name -> TTM Context
save :: Context -> Context
restore :: Context -> TTM Context
clearSaved :: Context -> Context
proofterm :: Context -> TTM Term
getGoals :: Context -> [Goal]
getGoal :: Context -> Goal -> TTM ([(Name, Term)], Term)
uniqueName :: Context -> Name -> TTM Name
allSolved :: Context -> Bool
qed :: Context -> TTM Context
eval :: Context -> Term -> Term
whnf :: Context -> Term -> Term
evalnew :: Context -> Term -> Term
evalCtxt :: IsTerm a => Context -> Goal -> a -> TTM Term
getDef :: Context -> Name -> TTM Term
defined :: Context -> Name -> Bool
getPatternDef :: Context -> Name -> TTM (ViewTerm, Patterns)
getAllTypes :: Context -> [(Name, Term)]
getAllDefs :: Context -> [(Name, Term)]
getAllPatternDefs :: Context -> [(Name, (ViewTerm, Patterns))]
getConstructors :: Context -> Name -> TTM [Name]
getInductive :: Context -> Name -> TTM Inductive
getAllInductives :: Context -> [(Name, Inductive)]
getType :: Context -> Name -> TTM Term
data Rule
= Case
| Elim
getElimRule :: Context -> Name -> Rule -> TTM Patterns
nameType :: Context -> Name -> TTM NameType
getConstructorTag :: Context -> Name -> TTM Int
getConstructorArity :: Context -> Name -> TTM Int
freeze :: Context -> Name -> TTM Context
thaw :: Context -> Name -> TTM Context
data Goal
goal :: String -> Goal
defaultGoal :: Goal
type Tactic = Goal -> Context -> TTM Context
data GoalData
bindings :: GoalData -> [(Name, Term)]
goalName :: GoalData -> Goal
goalType :: GoalData -> Term
goalData :: Context -> Bool -> Goal -> TTM GoalData
subGoals :: Context -> TTM [(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 :: [Goal -> Context -> TTM Context] -> Goal -> Context -> TTM 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 => Context -> Goal -> a -> TTM TermSource
Check a term in the context of the given goal
converts :: (IsTerm a, IsTerm b) => Context -> Goal -> a -> b -> TTM 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 :: Context -> a -> TTM TermSource
Typecheck a term
show/hide Instances
class IsData a whereSource
Methods
addData :: Context -> a -> TTM ContextSource
addDataNoElim :: Context -> a -> TTM ContextSource
show/hide Instances
Errors
data TTError Source
Constructors
CantUnify ViewTerm ViewTerm
NotConvertible ViewTerm ViewTerm
Message String
Unbound ViewTerm ViewTerm ViewTerm ViewTerm [Name]
NoSuchVar Name
ErrContext String TTError
show/hide Instances
ttfail :: String -> TTM aSource
getError :: IError -> TTErrorSource
type TTM = Either TTErrorSource
Definitions and Theorems
addDef :: IsTerm a => Context -> Name -> a -> TTM ContextSource
Add a new definition to the global state.
addTypedDef :: (IsTerm term, IsTerm ty) => Context -> Name -> term -> ty -> TTM ContextSource
Add a new definition, with its type to the global state. These definitions can be recursive, so use with care.
addAxiom :: IsTerm a => Context -> Name -> a -> TTM ContextSource
Add a new axiom to the global state.
declare :: IsTerm a => Context -> Name -> a -> TTM ContextSource
Declare a name which is to be defined later
declareData :: IsTerm a => Context -> Name -> a -> TTM ContextSource
Declare a type constructor which is to be defined later
theorem :: IsTerm a => Context -> Name -> a -> TTM ContextSource
Begin a new proof.
interactive :: IsTerm a => Context -> Name -> a -> TTM 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
:: Context
-> NameType name
-> TTM 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) => Context -> Name -> (a -> b -> c) -> ty -> TTM ContextSource
Add a new binary operator on constants. Warning: The type you give is not checked!
addBinFn :: (ViewConst a, ViewConst b, IsTerm ty) => Context -> Name -> (a -> b -> ViewTerm) -> ty -> TTM ContextSource
Add a new binary function on constants. Warning: The type you give is not checked!
addPrimFn :: (ViewConst a, IsTerm ty) => Context -> Name -> (a -> ViewTerm) -> ty -> TTM 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
=> Context
-> Name
-> Intarity
-> [ViewTerm] -> Maybe ViewTermThe function, which must accept a list of the right length given by arity.
-> ty
-> TTM Context
Add a new externally defined function. Warning: The type you give is not checked!
addEqualitySource
:: Context
-> NameName to give equality type
-> NameName to give constructor
-> TTM Context
Add the heterogenous ("John Major") equality rule and its reduction
forgetDef :: Context -> Name -> TTM ContextSource
Forget a definition and all following definitions.
addGenRecSource
:: Context
-> NameName to give recursion rule
-> TTM 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
PWithClause
arguments :: [ViewTerm]
scrutinee :: ViewTerm
patterns :: Patterns
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
=> Context
-> Name
-> tyType
-> PatternsDefinition
-> [PattOpt]Options to set which definitions will be accepted
-> TTM (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 :: Context -> Name -> TTM 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 :: Context -> TTM 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 :: Context -> TTM 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 :: Context -> Goal -> TTM ([(Name, Term)], Term)Source
Get the type and context of the given goal, if it exists
uniqueNameSource
:: Context
-> NameSuggested name
-> TTM 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 :: Context -> TTM 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 => Context -> Goal -> a -> TTM TermSource
Evaluate a term in the context of the given goal
getDef :: Context -> Name -> TTM TermSource
Lookup a definition in the context.
defined :: Context -> Name -> BoolSource
Check whether a name is defined
getPatternDef :: Context -> Name -> TTM (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 :: Context -> Name -> TTM [Name]Source
Get the names of all of the constructors of an inductive family
getInductive :: Context -> Name -> TTM 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 :: Context -> Name -> TTM TermSource
Get the type of a definition in the context.
data Rule Source
Types of elimination rule
Constructors
Case
Elim
getElimRuleSource
:: Context
-> NameType
-> RuleWhich rule to get patterns for (case or elim)
-> TTM Patterns
Get the pattern matching elimination rule for a type
nameType :: Context -> Name -> TTM NameTypeSource
Find out what type of variable the given name is
getConstructorTag :: Context -> Name -> TTM 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 :: Context -> Name -> TTM IntSource
Get the arity of the given constructor.
freeze :: Context -> Name -> TTM ContextSource
Freeze a name (i.e., set it so that it does not reduce) Fails if the name does not exist.
thaw :: Context -> Name -> TTM 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 = Goal -> Context -> TTM 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
:: Context
-> BoolGet all bindings (True), or just lambda bindings (False)
-> Goal
-> TTM GoalData
Get information about a subgoal.
subGoals :: Context -> TTM [(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 :: [Goal -> Context -> TTM Context] -> Goal -> Context -> TTM 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