Portability | unknown |
---|---|
Stability | unstable |
Maintainer | ecaustin@ittc.ku.edu |
Safe Haskell | None |
- Variable Term Generation
- Common Type Functions
- Common Term Functions
- Common Theorem Functions
- Derived Destructors and Constructors for Basic Terms
- Type Matching Functions
- Predicates, Constructors, and Destructors for Binary Terms
- Predicates, Constructors, and Destructors for Complex Abstractions
- Predicates, Constructors, and Destructors for Propositions
- Predicates, Constructors, and Destructors for Other Terms
- Term Nets
This module defines common utility functions that depend on data types introduced by HaskHOL. See the HaskHOL.Core.Lib module for utility functions that do not have this dependence.
- genVarWithName :: String -> HOLType -> HOL cls thry HOLTerm
- genVar :: HOLType -> HOL cls thry HOLTerm
- occursIn :: HOLType -> HOLType -> Bool
- tysubst :: HOLTypeEnv -> HOLType -> Either String HOLType
- alphaUtype :: HOLType -> HOLType -> Either String HOLType
- freeIn :: HOLTerm -> HOLTerm -> Bool
- subst :: HOLTermEnv -> HOLTerm -> HOL cls thry HOLTerm
- alpha :: HOLTerm -> HOLTerm -> Either String HOLTerm
- alphaTyabs :: HOLType -> HOLTerm -> Either String HOLTerm
- findTerm :: (HOLTerm -> Bool) -> HOLTerm -> Maybe HOLTerm
- findTerms :: (HOLTerm -> Bool) -> HOLTerm -> [HOLTerm]
- findPath :: (HOLTerm -> Bool) -> HOLTerm -> Maybe String
- followPath :: String -> HOLTerm -> Maybe HOLTerm
- typeVarsInThm :: HOLThm -> [HOLType]
- thmFrees :: HOLThm -> [HOLTerm]
- listMkComb :: HOLTerm -> [HOLTerm] -> Either String HOLTerm
- listMkAbs :: [HOLTerm] -> HOLTerm -> Either String HOLTerm
- mkArgs :: String -> [HOLTerm] -> [HOLType] -> [HOLTerm]
- rator :: HOLTerm -> Maybe HOLTerm
- rand :: HOLTerm -> Maybe HOLTerm
- bndvar :: HOLTerm -> Maybe HOLTerm
- body :: HOLTerm -> Maybe HOLTerm
- bndvarTyabs :: HOLTerm -> Maybe HOLType
- bodyTyabs :: HOLTerm -> Maybe HOLTerm
- stripComb :: HOLTerm -> (HOLTerm, [HOLTerm])
- stripAbs :: HOLTerm -> ([HOLTerm], HOLTerm)
- typeMatch :: HOLType -> HOLType -> SubstTrip -> Maybe SubstTrip
- mkMConst :: String -> HOLType -> HOL cls thry HOLTerm
- mkIComb :: HOLTerm -> HOLTerm -> Maybe HOLTerm
- listMkIComb :: String -> [HOLTerm] -> HOL cls thry HOLTerm
- isBinary :: String -> HOLTerm -> Bool
- isBinop :: HOLTerm -> HOLTerm -> Bool
- destBinary :: String -> HOLTerm -> Maybe (HOLTerm, HOLTerm)
- destBinop :: HOLTerm -> HOLTerm -> Maybe (HOLTerm, HOLTerm)
- mkBinary :: String -> HOLTerm -> HOLTerm -> HOL cls thry HOLTerm
- mkBinop :: HOLTerm -> HOLTerm -> HOLTerm -> Either String HOLTerm
- listMkBinop :: HOLTerm -> [HOLTerm] -> Either String HOLTerm
- binops :: HOLTerm -> HOLTerm -> [HOLTerm]
- isGAbs :: HOLTerm -> Bool
- isBinder :: String -> HOLTerm -> Bool
- isTyBinder :: String -> HOLTerm -> Bool
- destGAbs :: HOLTerm -> Maybe (HOLTerm, HOLTerm)
- destBinder :: String -> HOLTerm -> Maybe (HOLTerm, HOLTerm)
- destTyBinder :: String -> HOLTerm -> Maybe (HOLType, HOLTerm)
- mkGAbs :: HOLTerm -> HOLTerm -> HOL cls thry HOLTerm
- mkBinder :: String -> HOLTerm -> HOLTerm -> HOL cls thry HOLTerm
- mkTyBinder :: String -> HOLType -> HOLTerm -> HOL cls thry HOLTerm
- listMkGAbs :: [HOLTerm] -> HOLTerm -> HOL cls thry HOLTerm
- stripGAbs :: HOLTerm -> ([HOLTerm], HOLTerm)
- isConj :: HOLTerm -> Bool
- isImp :: HOLTerm -> Bool
- isForall :: HOLTerm -> Bool
- isExists :: HOLTerm -> Bool
- isDisj :: HOLTerm -> Bool
- isNeg :: HOLTerm -> Bool
- isUExists :: HOLTerm -> Bool
- isTyAll :: HOLTerm -> Bool
- isTyEx :: HOLTerm -> Bool
- destConj :: HOLTerm -> Maybe (HOLTerm, HOLTerm)
- destImp :: HOLTerm -> Maybe (HOLTerm, HOLTerm)
- destForall :: HOLTerm -> Maybe (HOLTerm, HOLTerm)
- destExists :: HOLTerm -> Maybe (HOLTerm, HOLTerm)
- destDisj :: HOLTerm -> Maybe (HOLTerm, HOLTerm)
- destNeg :: HOLTerm -> Maybe HOLTerm
- destUExists :: HOLTerm -> Maybe (HOLTerm, HOLTerm)
- destTyAll :: HOLTerm -> Maybe (HOLType, HOLTerm)
- destTyEx :: HOLTerm -> Maybe (HOLType, HOLTerm)
- mkConj :: HOLTerm -> HOLTerm -> HOL cls thry HOLTerm
- mkImp :: HOLTerm -> HOLTerm -> HOL cls thry HOLTerm
- mkForall :: HOLTerm -> HOLTerm -> HOL cls thry HOLTerm
- mkExists :: HOLTerm -> HOLTerm -> HOL cls thry HOLTerm
- mkDisj :: HOLTerm -> HOLTerm -> HOL cls thry HOLTerm
- mkNeg :: HOLTerm -> HOL cls thry HOLTerm
- mkUExists :: HOLTerm -> HOLTerm -> HOL cls thry HOLTerm
- mkTyAll :: HOLType -> HOLTerm -> HOL cls thry HOLTerm
- mkTyEx :: HOLType -> HOLTerm -> HOL cls thry HOLTerm
- listMkConj :: [HOLTerm] -> HOL cls thry HOLTerm
- listMkDisj :: [HOLTerm] -> HOL cls thry HOLTerm
- listMkForall :: [HOLTerm] -> HOLTerm -> HOL cls thry HOLTerm
- listMkExists :: [HOLTerm] -> HOLTerm -> HOL cls thry HOLTerm
- conjuncts :: HOLTerm -> [HOLTerm]
- disjuncts :: HOLTerm -> [HOLTerm]
- stripForall :: HOLTerm -> ([HOLTerm], HOLTerm)
- stripExists :: HOLTerm -> ([HOLTerm], HOLTerm)
- stripTyAll :: HOLTerm -> ([HOLType], HOLTerm)
- stripTyEx :: HOLTerm -> ([HOLType], HOLTerm)
- isCons :: HOLTerm -> Bool
- isList :: HOLTerm -> Bool
- isLet :: HOLTerm -> Bool
- destCons :: HOLTerm -> Maybe (HOLTerm, HOLTerm)
- destList :: HOLTerm -> Maybe [HOLTerm]
- destLet :: HOLTerm -> Maybe ([(HOLTerm, HOLTerm)], HOLTerm)
- destNumeral :: HOLTerm -> Maybe Integer
- data Net a
- netEmpty :: Net a
- netEnter :: Ord a => [HOLTerm] -> (HOLTerm, a) -> Net a -> HOL cls thry (Net a)
- netLookup :: HOLTerm -> Net a -> [a]
- netMerge :: Ord a => Net a -> Net a -> Net a
Variable Term Generation
genVarWithName :: String -> HOLType -> HOL cls thry HOLTermSource
Generates a new term variable consisting of a given prefix and the next value in the fresh term counter.
genVar :: HOLType -> HOL cls thry HOLTermSource
A version of genVarWithName
that defaults to the prefix "_".
Common Type Functions
occursIn :: HOLType -> HOLType -> BoolSource
Checks to see if the first type occurs in the second type. Note that the predicate is also satisfied if the two types are equal.
tysubst :: HOLTypeEnv -> HOLType -> Either String HOLTypeSource
Basic type substitution that ignores type operators and prunes the
substitution environment of bound variables rather than handle renaming.
Works for all types, variable and non-variable alike. Fails with Left
when
the substitution would result in an invalid type construction.
Note that the order of the elements of the substitution pairs matches other
environments in the systems, such that for the pair (A, B)
B
will be
substituted for all instances of A
.
alphaUtype :: HOLType -> HOLType -> Either String HOLTypeSource
Alpha conversion for universal types. Renames a bound type variable to match
the name of a provided type variable. Fails with Left
in the following
cases:
- First type is not a small type variable.
- Second type is not a universal type.
- The type variable is free in the body of the universal type.
Common Term Functions
freeIn :: HOLTerm -> HOLTerm -> BoolSource
Predicate to check if the first term is free in the second modulo alpha-equivalence.
subst :: HOLTermEnv -> HOLTerm -> HOL cls thry HOLTermSource
Basic term substitution. Throws a HOLException
when the substitution would
result in an invalid term construction.
Note that the order of the elements of the substitution pairs matches other
environments in the systems, such that for the pair (A, B)
B
will be
substituted for all instances of A
.
alpha :: HOLTerm -> HOLTerm -> Either String HOLTermSource
Alpha conversion for term abstractions. Renames a bound variable to match
the name of a provided variable. Fails with Left
in the following cases:
- First term is not a variable.
- Second term is not an abstraction.
- The types of the variable and bound variable do no agree.
- The variable is free in the body of the abstraction.
alphaTyabs :: HOLType -> HOLTerm -> Either String HOLTermSource
Alpha conversion for type abstractions. Renames a bound type variable to
match the name of a provided type variable. Fails with Left
in the
following cases:
- The provided type is not a small type variable.
- The provided term is not a type abstraction.
- The type is free in the body of the type abstraction.
findTerm :: (HOLTerm -> Bool) -> HOLTerm -> Maybe HOLTermSource
Searches a term for a subterm that satisfies a given predicate. Fails with
Nothing
if no such term is found.
findTerms :: (HOLTerm -> Bool) -> HOLTerm -> [HOLTerm]Source
Searches a term for all unique subterms that satisfy a given predicate.
findPath :: (HOLTerm -> Bool) -> HOLTerm -> Maybe StringSource
Searches a term for a subterm that satisfies a given predicate, returning a string that indicates the path to that subterm:
-
'b'
- Take the body of an abstraction. -
't'
- Take the body of a type abstraction. -
'l'
- Take the left path in a term combination. -
'r'
- Take the right path in a term combination. -
'c'
- Take the body in a type combination.
Fails with Nothing
if there is no satisfying subterm.
Common Theorem Functions
typeVarsInThm :: HOLThm -> [HOLType]Source
Returns the list of all free type variables in a theorem.
Derived Destructors and Constructors for Basic Terms
mkArgs :: String -> [HOLTerm] -> [HOLType] -> [HOLTerm]Source
Constructs a list of term variables of a given prefix. Names are adjusted
as necessary with variant
to avoid clashing with the provided list of term
variables. The number and types of the resultant variables is directed by
the provided list of types, i.e.
mkArgs "x" avoids [ty1, ... tyn] === [x1:ty1, ..., xn:tyn] where {x1, ..., xn} are not elements of avoids
rator :: HOLTerm -> Maybe HOLTermSource
Returns the left term of a combination. Fails with Nothing
if the provided
term is not a combination.
rand :: HOLTerm -> Maybe HOLTermSource
Returns the right term of a combination. Fails with Nothing
if the provided
term is not a combination.
bndvar :: HOLTerm -> Maybe HOLTermSource
Returns the bound term of an abstraction. Fails with Nothing
if the
provided term is not an abstraction.
body :: HOLTerm -> Maybe HOLTermSource
Returns the body term of an abstraction. Fails with Nothing
if the
provided term is not an abstraction.
bndvarTyabs :: HOLTerm -> Maybe HOLTypeSource
Returns the bound type of a type abstraction. Fails with Nothing
if the
provided term is not a type abstraction.
bodyTyabs :: HOLTerm -> Maybe HOLTermSource
Returns the body term of a type abstraction. Fails with Nothing
if the
provided term is not a type abstraction.
stripComb :: HOLTerm -> (HOLTerm, [HOLTerm])Source
Destructs a complex combination returning its function term and its list of argument terms.
stripAbs :: HOLTerm -> ([HOLTerm], HOLTerm)Source
Destructs a complex abstraction returning its list of bound variables and its body term.
Type Matching Functions
typeMatch :: HOLType -> HOLType -> SubstTrip -> Maybe SubstTripSource
Computes a tiplet of substitution environments that can be used to make two
types match. The triplet argument can be used to constrain the match, or
its three environments can be left empty to find the most general match.
Fails with Nothing
in the event that a match cannot be found that satisfies
the provided constraint.
mkMConst :: String -> HOLType -> HOL cls thry HOLTermSource
Constructs an instance of a constant of the provided name and type. Relies
internally on typeMatch
in order to provide a match between the most general
type of the constant and the provided type. Throws a HOLException
in the
following cases:
- The provided string is not the name of a defined constant.
- Type matching fails.
listMkIComb :: String -> [HOLTerm] -> HOL cls thry HOLTermSource
An iterative version of mkIComb
that builds a complex combination given a
constant name and a list of arguments, attempting to find a correct
instantiation at every step. Throws a HOLException
in the following cases:
- The provided name is not a currently defiend constant.
- Any internal call to mkIComb fails.
Predicates, Constructors, and Destructors for Binary Terms
isBinary :: String -> HOLTerm -> BoolSource
Predicate that tests if a term is a binary application whose operator has the given name.
isBinop :: HOLTerm -> HOLTerm -> BoolSource
A version of isBinary
that tests for operator terms, not strings.
destBinary :: String -> HOLTerm -> Maybe (HOLTerm, HOLTerm)Source
Destructs a binary application returning its left and right arguments. Fails
with Nothing
if the provided term is not a binary application with the
specified operator name.
destBinop :: HOLTerm -> HOLTerm -> Maybe (HOLTerm, HOLTerm)Source
A version of destBinary
that tests for operator terms, not strings.
mkBinary :: String -> HOLTerm -> HOLTerm -> HOL cls thry HOLTermSource
Constructs a binary application given a constant name and two argument terms.
Note that no instantiation is performed, thus the constant must be monomorphic
or the provided arguments must match the constant's general type. Throws a
HOLException
if any of the internal calls to mkConst
or mkComb
fail.
mkBinop :: HOLTerm -> HOLTerm -> HOLTerm -> Either String HOLTermSource
A version of mkBinary
that accepts the operator as a pre-constructed term.
listMkBinop :: HOLTerm -> [HOLTerm] -> Either String HOLTermSource
Iteratively builds a complex combination using mkBinop
, i.e.
listMkBinop (/\) [T, F, T] === T /\ F /\ T
binops :: HOLTerm -> HOLTerm -> [HOLTerm]Source
The inverse of listMkBinop
. Destructs a complex combination built with
a binary operator into its list of arguments.
Predicates, Constructors, and Destructors for Complex Abstractions
isBinder :: String -> HOLTerm -> BoolSource
Predicate that tests if a term is an abstraction of specified binder name.
isTyBinder :: String -> HOLTerm -> BoolSource
Predicate that tests if a term is an abtraction of a specified type binder name.
destBinder :: String -> HOLTerm -> Maybe (HOLTerm, HOLTerm)Source
Destructs an abstraction of specified binder name into its bound variable and
its body term. Fails with Nothing
if the provided term is not an
abstraction with the specified binder name.
destTyBinder :: String -> HOLTerm -> Maybe (HOLType, HOLTerm)Source
Destructs a type abstraction of specified binder name into its bound type
variable and its body term. Fails with Nothing
if the provided term is not
a type abstraction with the specified type binder name.
mkGAbs :: HOLTerm -> HOLTerm -> HOL cls thry HOLTermSource
Constructor for generalized abstractions. Generalized abstractions extend term abstractions to the more general of notion of a function mapping some structure to some term. This allows us to bind patterns more complicated than a variable, i.e. binding pairs
\ (x:num, y:num) -> x + y
or lists
\ CONS x xs -> x
Note that in the case where the pattern to bind is simply a variable mkGAbs
just calls mkAbs
.
mkBinder :: String -> HOLTerm -> HOLTerm -> HOL cls thry HOLTermSource
Constructs an abstraction given a binder name and two argument terms. Throws
a HOLException
if any of the internal calls to mkConst
, mkAbs
, or
mkComb
fail.
Note that the given string can actually be any constant name of type
(A -> *) -> *
, such that a well-typed term of the form c (\x . t)
can be
produced.
mkTyBinder :: String -> HOLType -> HOLTerm -> HOL cls thry HOLTermSource
Constructs a type abstraction given a type binder name, a type variable to
find, and a body term. Throws a HOLException
if any of the internal calls
to mkConst
, mkTyAbs
, or mkComb
fail.
Note that the given string can actually be any constant name of type
(% 'a . *) -> *
, such that a well-typed term of the form c (\\x . t)
can
be produced.
listMkGAbs :: [HOLTerm] -> HOLTerm -> HOL cls thry HOLTermSource
A specific version of listMkAbs
for general abstractions.
stripGAbs :: HOLTerm -> ([HOLTerm], HOLTerm)Source
A specific version of stripAbs
for general abstractions.
Predicates, Constructors, and Destructors for Propositions
destForall :: HOLTerm -> Maybe (HOLTerm, HOLTerm)Source
Destructor for universal term quantification.
destExists :: HOLTerm -> Maybe (HOLTerm, HOLTerm)Source
Destructor for existential term quantification.
destUExists :: HOLTerm -> Maybe (HOLTerm, HOLTerm)Source
Destructor for unique, existential quantification.
destTyAll :: HOLTerm -> Maybe (HOLType, HOLTerm)Source
Destructor for term-level universal type quantification.
destTyEx :: HOLTerm -> Maybe (HOLType, HOLTerm)Source
Destructor for term-level existential type quantification.
mkConj :: HOLTerm -> HOLTerm -> HOL cls thry HOLTermSource
Constructor for boolean conjunctions. Throws a HOLException
if the internal
call to mkBinary
fails.
mkImp :: HOLTerm -> HOLTerm -> HOL cls thry HOLTermSource
Constructor for boolean implications. Throws a HOLException
if the internal
call to mkBinary
fails.
mkForall :: HOLTerm -> HOLTerm -> HOL cls thry HOLTermSource
Constructor for universal term quantification. Throws a HOLException
if the
internal call to mkBinder
fails.
mkExists :: HOLTerm -> HOLTerm -> HOL cls thry HOLTermSource
Constructor for existential term quantification. Throws a HOLException
if
the internal call to mkBinder
fails.
mkDisj :: HOLTerm -> HOLTerm -> HOL cls thry HOLTermSource
Constructor for boolean disjunctions. Throws a HOLException
if the internal
call to mkBinary
fails.
mkNeg :: HOLTerm -> HOL cls thry HOLTermSource
Constructor for boolean negations. Throws a HOLException
if any of the
internal calls to mkConst
or mkComb
fail.
mkUExists :: HOLTerm -> HOLTerm -> HOL cls thry HOLTermSource
Constructor for unique, existential term quantification. Throws a
HOLException
if the internal call to mkBinder
fails.
mkTyAll :: HOLType -> HOLTerm -> HOL cls thry HOLTermSource
Constructor for term-level universal type quantification. Throws a
HOLException
if the internal call to mkTyBinder
fails.
mkTyEx :: HOLType -> HOLTerm -> HOL cls thry HOLTermSource
Constructor for term-level existential type quantification. Throws a
HOLException
if the internal call to mkTyBinder
fails.
listMkConj :: [HOLTerm] -> HOL cls thry HOLTermSource
Constructs a complex conjunction from a given list of propositions.
listMkDisj :: [HOLTerm] -> HOL cls thry HOLTermSource
Constructs a complex disjunction from a given list of propositions.
listMkForall :: [HOLTerm] -> HOLTerm -> HOL cls thry HOLTermSource
A specific version of listMkAbs
for universal term quantification.
listMkExists :: [HOLTerm] -> HOLTerm -> HOL cls thry HOLTermSource
A specific version of listMkAbs
for existential term quantification.
stripForall :: HOLTerm -> ([HOLTerm], HOLTerm)Source
A specific version of stripAbs
for universal term quantification.
stripExists :: HOLTerm -> ([HOLTerm], HOLTerm)Source
A specific version of stripAbs
for existential term quantification.
stripTyAll :: HOLTerm -> ([HOLType], HOLTerm)Source
A specific version of stripAbs
for term-level universal type quantification.
stripTyEx :: HOLTerm -> ([HOLType], HOLTerm)Source
A specific version of stripAbs
for term-level existential type
quantification.
Predicates, Constructors, and Destructors for Other Terms
destList :: HOLTerm -> Maybe [HOLTerm]Source
Destructor for list terms. Returns a list of the elements in the term. Fails
with Nothing
if internall the term is not of the form
x1 `CONS` .... xn `CONS` NIL
destLet :: HOLTerm -> Maybe ([(HOLTerm, HOLTerm)], HOLTerm)Source
Destructs a let binding term into a list of its name and value pairs and its
body term. Fails with Nothing
if internally the term is not of the form
LET (x1, v1) ... (xn, vn) LET_END
destNumeral :: HOLTerm -> Maybe IntegerSource
Term Nets
Internally, Net
s are represented with a tree structure; each node has a list
of labeled branches and a list of values. The node labels are generated via
the following guidelines:
- Flattening of combinations favors the left hand side such that the head of an application is looked at first.
- If the head of an application is variable, the whole term is considered variable.
- Type abstractions and type combinations are effectively treated as local
constants, though they do have their own node lable representations to avoid
any potential issues with user provided variable lists for
enter
. - Matching is conservative, such that all matching values will be returned,
but some non-matching values may be returned. For example, a pattern term
of the form
x `op` x
will match any term of the forma `op` b
regardless of the values ofa
andb
.
netEnter :: Ord a => [HOLTerm] -> (HOLTerm, a) -> Net a -> HOL cls thry (Net a)Source
Inserts a new element, paired with a pattern term, into a provided net. The
first argument is a list of variables that should be treated as local
constants, such that only patterns with those variables at the exact same
position will match. See the documentation for Net
for more details.
Never fails.