-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | An equational theorem prover -- -- Twee is an experimental equational theorem prover based on -- Knuth-Bendix completion. -- -- Given a set of equational axioms and a set of equational conjectures -- it will try to prove the conjectures. It will terminate if the -- conjectures are true but normally fail to terminate if they are false. -- -- The input problem should be in TPTP format (see http://www.tptp.org). -- You can use types and quantifiers, but apart from that the problem -- must be equational. -- -- This package contains only the library part of twee. @package twee-lib @version 2.1.2 -- | Assignment of unique IDs to values. Inspired by the intern -- package. module Twee.Label -- | A value of type a which has been given a unique ID. data Label a -- | Construct a Label a from its unique ID, which must be -- the labelNum of an already existing Label. Extremely -- unsafe! unsafeMkLabel :: Int32 -> Label a -- | The unique ID of a label. labelNum :: Label a -> Int32 -- | Assign a label to a value. label :: forall a. (Typeable a, Ord a) => a -> Label a -- | Recover the underlying value from a label. find :: Label a -> a instance GHC.Show.Show (Twee.Label.Label a) instance GHC.Classes.Ord (Twee.Label.Label a) instance GHC.Classes.Eq (Twee.Label.Label a) -- | A module which can run housekeeping tasks every so often. module Twee.Task -- | A task which runs in the monad m and produces a value of type -- a. data Task m a -- | Create a new task that should be run a certain proportion of the time. -- The first argument is how often in seconds the task should run, at -- most. The second argument is the maximum percentage of time that -- should be spent on the task. newTask :: MonadIO m => Double -> Double -> m a -> m (Task m a) -- | Run a task if it's time to run it. checkTask :: MonadIO m => Task m a -> m (Maybe a) -- | Terms and substitutions. -- -- Terms in twee are represented as arrays rather than as an algebraic -- data type. This module defines pattern synonyms (App, -- Var, Cons, Empty) which means that pattern -- matching on terms works just as normal. The pattern synonyms can not -- be used to create new terms; for that you have to use a builder -- interface (Build). -- -- This module also provides: -- --
-- u = f(x,y) -- us = [x, y, g(z)] ---- | Like Cons, but does not check that the termlist is non-empty. -- Use only if you are sure the termlist is non-empty. -- | Like ConsSym, but does not check that the termlist is -- non-empty. Use only if you are sure the termlist is non-empty. -- | The empty termlist. empty :: forall f. TermList f -- | Convert a termlist into an ordinary list of terms. unpack :: TermList f -> [Term f] -- | The length of (number of symbols in) a termlist. lenList :: TermList f -> Int -- | A function symbol. f is the underlying type of function -- symbols defined by the user; Fun f is an f -- together with an automatically-generated unique number. data Fun f -- | Construct a Fun from a function symbol. fun :: (Ord f, Typeable f) => f -> Fun f -- | The unique number of a Fun. fun_id :: Fun f -> Int -- | The underlying function symbol of a Fun. fun_value :: Fun f -> f -- | A pattern which extracts the fun_value from a Fun. -- | A variable. newtype Var V :: Int -> Var -- | The variable's number. Don't use huge variable numbers: they will be -- truncated to 32 bits when stored in a term. [var_id] :: Var -> Int -- | Instances of Build can be turned into terms using build -- or buildList, and turned into term builders using -- builder. Has instances for terms, termlists, builders, and -- Haskell lists. class Build a where { type family BuildFun a; } -- | Convert a value into a Builder. builder :: Build a => a -> Builder (BuildFun a) -- | A monoid for building terms. mempty represents the empty -- termlist, while mappend appends two termlists. data Builder f -- | Build a term. The given builder must produce exactly one term. build :: Build a => a -> Term (BuildFun a) -- | Build a termlist. buildList :: Build a => a -> TermList (BuildFun a) -- | Build a constant (a function with no arguments). con :: Fun f -> Builder f -- | Build a function application. app :: Build a => Fun (BuildFun a) -> a -> Builder (BuildFun a) -- | Build a variable. var :: Var -> Builder f -- | Get the children (direct subterms) of a term. children :: Term f -> TermList f -- | Find all proper subterms of a term. properSubterms :: Term f -> [Term f] -- | Find all subterms of a termlist. subtermsList :: TermList f -> [Term f] -- | Find all subterms of a term. subterms :: Term f -> [Term f] -- | Check if a variable occurs in a term. occurs :: Var -> Term f -> Bool -- | Is a term a subterm of another one? isSubtermOf :: Term f -> Term f -> Bool -- | Is a term contained as a subterm in a given termlist? isSubtermOfList :: Term f -> TermList f -> Bool -- | Index into a termlist. at :: Int -> TermList f -> Term f -- | A class for values which act as substitutions. -- -- Instances include Subst as well as functions from variables to -- terms. class Substitution s where { type family SubstFun s; } -- | Apply the substitution to a variable. evalSubst :: Substitution s => s -> Var -> Builder (SubstFun s) -- | Apply the substitution to a termlist. substList :: Substitution s => s -> TermList (SubstFun s) -> Builder (SubstFun s) -- | Apply a substitution to a term. subst :: Substitution s => s -> Term (SubstFun s) -> Builder (SubstFun s) -- | A substitution which maps variables to terms of type Term -- f. newtype Subst f Subst :: IntMap (TermList f) -> Subst f [unSubst] :: Subst f -> IntMap (TermList f) -- | The empty substitution. emptySubst :: () => Subst f -- | Construct a substitution from a list. Returns Nothing if a -- variable is bound to several different terms. listToSubst :: [(Var, Term f)] -> Maybe (Subst f) -- | Convert a substitution to a list of bindings. substToList :: Subst f -> [(Var, Term f)] -- | Look up a variable in a substitution. lookup :: Var -> Subst f -> Maybe (Term f) -- | Look up a variable in a substitution, returning a termlist. lookupList :: Var -> Subst f -> Maybe (TermList f) -- | Add a new binding to a substitution. extend :: Var -> Term f -> Subst f -> Maybe (Subst f) -- | Add a new binding to a substitution, giving a termlist. extendList :: Var -> TermList f -> Subst f -> Maybe (Subst f) -- | Add a new binding to a substitution. Overwrites any existing binding. unsafeExtendList :: Var -> TermList f -> Subst f -> Subst f -- | Remove a binding from a substitution. retract :: Var -> Subst f -> Subst f -- | Fold a function over a substitution. foldSubst :: (Var -> TermList f -> b -> b) -> b -> Subst f -> b -- | Check if all bindings of a substitution satisfy a given property. allSubst :: (Var -> TermList f -> Bool) -> Subst f -> Bool -- | Compute the set of variables bound by a substitution. substDomain :: Subst f -> [Var] -- | Return the highest-number variable in a substitution plus 1. substSize :: Subst f -> Int -- | Compose two substitutions. substCompose :: Substitution s => Subst (SubstFun s) -> s -> Subst (SubstFun s) -- | Check if two substitutions are compatible (they do not send the same -- variable to different terms). substCompatible :: Subst f -> Subst f -> Bool -- | Take the union of two substitutions. The substitutions must be -- compatible, which is not checked. substUnion :: Subst f -> Subst f -> Subst f -- | Check if a substitution is idempotent (applying it twice has the same -- effect as applying it once). idempotent :: Subst f -> Bool -- | Check if a substitution has no effect on a given term. idempotentOn :: Subst f -> TermList f -> Bool -- | Return a substitution which renames the variables of a list of terms -- to put them in a canonical order. canonicalise :: [TermList f] -> Subst f -- | match pat t matches the term t against the -- pattern pat. match :: Term f -> Term f -> Maybe (Subst f) -- | A variant of match which extends an existing substitution. matchIn :: Subst f -> Term f -> Term f -> Maybe (Subst f) -- | A variant of match which works on termlists. matchList :: TermList f -> TermList f -> Maybe (Subst f) -- | A variant of match which works on termlists and extends an -- existing substitution. matchListIn :: Subst f -> TermList f -> TermList f -> Maybe (Subst f) -- | t `'isInstanceOf'\` pat checks if t is an instance -- of pat. isInstanceOf :: Term f -> Term f -> Bool -- | Check if two terms are renamings of one another. isVariantOf :: Term f -> Term f -> Bool -- | Unify two terms. unify :: Term f -> Term f -> Maybe (Subst f) -- | Unify two termlists. unifyList :: TermList f -> TermList f -> Maybe (Subst f) -- | Unify two terms, returning a triangle substitution. This is slightly -- faster than unify. unifyTri :: Term f -> Term f -> Maybe (TriangleSubst f) -- | Unify two termlists, returning a triangle substitution. This is -- slightly faster than unify. unifyListTri :: TermList f -> TermList f -> Maybe (TriangleSubst f) -- | A triangle substitution is one in which variables can be defined in -- terms of each other, though not in a circular way. -- -- The main use of triangle substitutions is in unification; -- unifyTri returns one. A triangle substitution can be converted -- to an ordinary substitution with close, or used directly using -- its Substitution instance. newtype TriangleSubst f Triangle :: Subst f -> TriangleSubst f [unTriangle] :: TriangleSubst f -> Subst f -- | Iterate a triangle substitution to make it idempotent. close :: TriangleSubst f -> Subst f -- | Convert a position in a term, expressed as a single number, into a -- path. positionToPath :: Term f -> Int -> [Int] -- | Convert a path in a term into a position. pathToPosition :: Term f -> [Int] -> Int -- | Replace the term at a given position in a term with a different term. replacePosition :: (Build a, BuildFun a ~ f) => Int -> a -> TermList f -> Builder f -- | Replace the term at a given position in a term with a different term, -- while simultaneously applying a substitution. Useful for building -- critical pairs. replacePositionSub :: (Substitution sub, SubstFun sub ~ f) => sub -> Int -> TermList f -> TermList f -> Builder f -- | Return the lowest- and highest-numbered variables in a term. bound :: Term f -> (Var, Var) -- | Return the lowest- and highest-numbered variables in a termlist. boundList :: TermList f -> (Var, Var) -- | Return the lowest- and highest-numbered variables in a list of -- termlists. boundLists :: [TermList f] -> (Var, Var) -- | Map a function over the function symbols in a term. mapFun :: (Fun f -> Fun g) -> Term f -> Builder g -- | Map a function over the function symbols in a termlist. mapFunList :: (Fun f -> Fun g) -> TermList f -> Builder g -- | Compare the fun_values of two Funs. (<<) :: Ord f => Fun f -> Fun f -> Bool instance GHC.Show.Show (Twee.Term.TriangleSubst f) instance GHC.Classes.Eq (Twee.Term.Subst f) instance Twee.Term.Substitution (Twee.Term.TriangleSubst f) instance Twee.Term.Substitution (Twee.Term.Subst f) instance GHC.Show.Show (Twee.Term.Subst f) instance (Twee.Term.Build a, v ~ Twee.Term.Core.Var) => Twee.Term.Substitution (v -> a) instance Twee.Term.Build (Twee.Term.Core.Builder f) instance Twee.Term.Build (Twee.Term.Core.Term f) instance Twee.Term.Build (Twee.Term.Core.TermList f) instance Twee.Term.Build a => Twee.Term.Build [a] instance GHC.Show.Show (Twee.Term.Core.Term f) instance GHC.Show.Show (Twee.Term.Core.TermList f) -- | Pretty-printing of terms and assorted other values. module Twee.Pretty -- | Print a value to the console. prettyPrint :: Pretty a => a -> IO () -- | The empty document. Used to avoid name clashes with empty. pPrintEmpty :: Doc -- | Print a tuple of values. pPrintTuple :: [Doc] -> Doc -- | Print a set of vlaues. pPrintSet :: [Doc] -> Doc -- | Generate a list of candidate names for pretty-printing. supply :: [String] -> [String] -- | A class for customising the printing of function symbols. class Pretty f => PrettyTerm f -- | The style of the function symbol. Defaults to curried. termStyle :: PrettyTerm f => f -> TermStyle -- | Defines how to print out a function symbol. newtype TermStyle TermStyle :: (forall a. Pretty a => PrettyLevel -> Rational -> Doc -> [a] -> Doc) -> TermStyle -- | Renders a function application. Takes the following arguments in this -- order: Pretty-printing level, current precedence, pretty-printed -- function symbol and list of arguments to the function. [pPrintTerm] :: TermStyle -> forall a. Pretty a => PrettyLevel -> Rational -> Doc -> [a] -> Doc -- | For operators like $ that should be printed as a blank space. invisible :: TermStyle -- | For functions that should be printed curried. curried :: TermStyle -- | For functions that should be printed uncurried. uncurried :: TermStyle -- | For prefix operators. prefix :: TermStyle -- | For postfix operators. postfix :: TermStyle -- | A helper function that deals with under- and oversaturated -- applications. fixedArity :: Int -> TermStyle -> TermStyle -- | A helper function that drops a certain number of arguments. implicitArguments :: Int -> TermStyle -> TermStyle -- | For infix operators. infixStyle :: Int -> TermStyle -- | For tuples. tupleStyle :: TermStyle -- | Pretty printing class. The precedence level is used in a similar way -- as in the Show class. Minimal complete definition is either -- pPrintPrec or pPrint. class Pretty a pPrintPrec :: Pretty a => PrettyLevel -> Rational -> a -> Doc pPrint :: Pretty a => a -> Doc pPrintList :: Pretty a => PrettyLevel -> [a] -> Doc instance Twee.Pretty.PrettyTerm f => Twee.Pretty.PrettyTerm (Twee.Term.Core.Fun f) instance Twee.Pretty.PrettyTerm f => Text.PrettyPrint.HughesPJClass.Pretty (Twee.Term.Core.Term f) instance Twee.Pretty.PrettyTerm f => Text.PrettyPrint.HughesPJClass.Pretty (Twee.Term.Core.TermList f) instance Twee.Pretty.PrettyTerm f => Text.PrettyPrint.HughesPJClass.Pretty (Twee.Term.Subst f) instance Text.PrettyPrint.HughesPJClass.Pretty Text.PrettyPrint.HughesPJ.Doc instance Text.PrettyPrint.HughesPJClass.Pretty a => Text.PrettyPrint.HughesPJClass.Pretty (Data.Set.Internal.Set a) instance Text.PrettyPrint.HughesPJClass.Pretty Twee.Term.Core.Var instance (Text.PrettyPrint.HughesPJClass.Pretty k, Text.PrettyPrint.HughesPJClass.Pretty v) => Text.PrettyPrint.HughesPJClass.Pretty (Data.Map.Internal.Map k v) instance (GHC.Classes.Eq a, GHC.Real.Integral a, Text.PrettyPrint.HughesPJClass.Pretty a) => Text.PrettyPrint.HughesPJClass.Pretty (GHC.Real.Ratio a) instance Text.PrettyPrint.HughesPJClass.Pretty f => Text.PrettyPrint.HughesPJClass.Pretty (Twee.Term.Core.Fun f) -- | Miscellaneous utility functions. module Twee.Utils repeatM :: Monad m => m a -> m [a] partitionBy :: Ord b => (a -> b) -> [a] -> [[a]] collate :: Ord a => ([b] -> c) -> [(a, b)] -> [(a, c)] isSorted :: Ord a => [a] -> Bool isSortedBy :: Ord b => (a -> b) -> [a] -> Bool usort :: Ord a => [a] -> [a] usortBy :: (a -> a -> Ordering) -> [a] -> [a] sortBy' :: Ord b => (a -> b) -> [a] -> [a] usortBy' :: Ord b => (a -> b) -> [a] -> [a] orElse :: Ordering -> Ordering -> Ordering unbuffered :: IO a -> IO a newtype Max a Max :: Maybe a -> Max a [getMax] :: Max a -> Maybe a getMaxWith :: Ord a => a -> Max a -> a newtype Min a Min :: Maybe a -> Min a [getMin] :: Min a -> Maybe a getMinWith :: Ord a => a -> Min a -> a labelM :: Monad m => (a -> m b) -> [a] -> m [(a, b)] fixpoint :: Eq a => (a -> a) -> a -> a intMin :: Int -> Int -> Int intMax :: Int -> Int -> Int splitInterval :: Integral a => a -> (a, a) -> [(a, a)] instance GHC.Classes.Ord a => GHC.Base.Monoid (Twee.Utils.Min a) instance GHC.Classes.Ord a => GHC.Base.Monoid (Twee.Utils.Max a) -- | A queue of passive critical pairs, using a memory-efficient -- representation. module Twee.PassiveQueue -- | A datatype representing all the type parameters of the queue. class (Eq (Id params), Integral (Id params), Ord (Score params), Unbox (PackedScore params), Unbox (PackedId params)) => Params params where { type family Score params; type family Id params; type family PackedScore params; type family PackedId params; } -- | Pack a Score. packScore :: Params params => proxy params -> Score params -> PackedScore params -- | Unpack a PackedScore. unpackScore :: Params params => proxy params -> PackedScore params -> Score params -- | Pack an Id. packId :: Params params => proxy params -> Id params -> PackedId params -- | Unpack a PackedId. unpackId :: Params params => proxy params -> PackedId params -> Id params -- | A critical pair queue. data Queue params -- | A queued critical pair. data Passive params Passive :: !(Score params) -> !(Id params) -> !(Id params) -> {-# UNPACK #-} !Int -> Passive params -- | The score of this critical pair. [passive_score] :: Passive params -> !(Score params) -- | The rule which does the outermost rewrite in this critical pair. [passive_rule1] :: Passive params -> !(Id params) -- | The rule which does the innermost rewrite in this critical pair. [passive_rule2] :: Passive params -> !(Id params) -- | The position of the overlap. See overlap_pos. [passive_pos] :: Passive params -> {-# UNPACK #-} !Int -- | The empty queue. empty :: Queue params -- | Add a set of Passives to the queue. insert :: Params params => Id params -> [Passive params] -> Queue params -> Queue params -- | Remove the minimum Passive from the queue. removeMin :: Params params => Queue params -> Maybe (Passive params, Queue params) -- | Map a function over all Passives. mapMaybe :: Params params => (Passive params -> Maybe (Passive params)) -> Queue params -> Queue params instance Twee.PassiveQueue.Params params => GHC.Classes.Eq (Twee.PassiveQueue.PassiveSet params) instance Twee.PassiveQueue.Params params => GHC.Classes.Ord (Twee.PassiveQueue.PassiveSet params) instance Twee.PassiveQueue.Params params => GHC.Classes.Eq (Twee.PassiveQueue.Passive params) instance Twee.PassiveQueue.Params params => GHC.Classes.Ord (Twee.PassiveQueue.Passive params) -- | Solving constraints on variable ordering. module Twee.Constraints data Atom f Constant :: (Fun f) -> Atom f Variable :: Var -> Atom f atoms :: Term f -> [Atom f] toTerm :: Atom f -> Term f fromTerm :: Term f -> Maybe (Atom f) data Formula f Less :: (Atom f) -> (Atom f) -> Formula f LessEq :: (Atom f) -> (Atom f) -> Formula f And :: [Formula f] -> Formula f Or :: [Formula f] -> Formula f negateFormula :: Formula f -> Formula f conj :: Foldable t => t Formula f -> Formula f disj :: Foldable t => t Formula f -> Formula f (&&&) :: () => Formula f -> Formula f -> Formula f (|||) :: () => Formula f -> Formula f -> Formula f true :: () => Formula f false :: () => Formula f data Branch f Branch :: [Fun f] -> [(Atom f, Atom f)] -> [(Atom f, Atom f)] -> Branch f [funs] :: Branch f -> [Fun f] [less] :: Branch f -> [(Atom f, Atom f)] [equals] :: Branch f -> [(Atom f, Atom f)] trueBranch :: Branch f norm :: Eq f => Branch f -> Atom f -> Atom f contradictory :: (Minimal f, Ord f) => Branch f -> Bool formAnd :: (Minimal f, Ordered f) => Formula f -> [Branch f] -> [Branch f] branches :: (Minimal f, Ordered f) => Formula f -> [Branch f] addLess :: (Minimal f, Ordered f) => Atom f -> Atom f -> Branch f -> [Branch f] addEquals :: (Minimal f, Ordered f) => Atom f -> Atom f -> Branch f -> [Branch f] addTerm :: (Minimal f, Ordered f) => Atom f -> Branch f -> Branch f newtype Model f Model :: (Map (Atom f) (Int, Int)) -> Model f modelToLiterals :: Model f -> [Formula f] modelFromOrder :: (Minimal f, Ord f) => [Atom f] -> Model f weakenModel :: Model f -> [Model f] varInModel :: (Minimal f, Ord f) => Model f -> Var -> Bool varGroups :: (Minimal f, Ord f) => Model f -> [(Fun f, [Var], Maybe (Fun f))] class Minimal f minimal :: Minimal f => Fun f lessEqInModel :: (Minimal f, Ordered f) => Model f -> Atom f -> Atom f -> Maybe Strictness solve :: (Minimal f, Ordered f, PrettyTerm f) => [Atom f] -> Branch f -> Either (Model f) (Subst f) class Ord f => Ordered f -- | Return True if the first term is less than or equal to the -- second, in the term ordering. lessEq :: Ordered f => Term f -> Term f -> Bool -- | Check if the first term is less than or equal to the second in the -- given model, and decide whether the inequality is strict or nonstrict. lessIn :: Ordered f => Model f -> Term f -> Term f -> Maybe Strictness -- | Describes whether an inequality is strict or nonstrict. data Strictness -- | The first term is strictly less than the second. Strict :: Strictness -- | The first term is less than or equal to the second. Nonstrict :: Strictness -- | Return True if the first argument is strictly less than the -- second, in the term ordering. lessThan :: Ordered f => Term f -> Term f -> Bool -- | Return the direction in which the terms are oriented according to the -- term ordering, or Nothing if they cannot be oriented. A result -- of Just LT means that the first term is less -- than or equal to the second. orientTerms :: Ordered f => Term f -> Term f -> Maybe Ordering instance GHC.Show.Show Twee.Constraints.Strictness instance GHC.Classes.Eq Twee.Constraints.Strictness instance GHC.Show.Show (Twee.Constraints.Model f) instance GHC.Classes.Eq (Twee.Constraints.Model f) instance GHC.Classes.Ord (Twee.Constraints.Branch f) instance GHC.Classes.Eq (Twee.Constraints.Branch f) instance GHC.Show.Show (Twee.Constraints.Formula f) instance GHC.Classes.Ord (Twee.Constraints.Formula f) instance GHC.Classes.Eq (Twee.Constraints.Formula f) instance GHC.Classes.Ord (Twee.Constraints.Atom f) instance GHC.Classes.Eq (Twee.Constraints.Atom f) instance GHC.Show.Show (Twee.Constraints.Atom f) instance Twee.Pretty.PrettyTerm f => Text.PrettyPrint.HughesPJClass.Pretty (Twee.Constraints.Model f) instance Twee.Pretty.PrettyTerm f => Text.PrettyPrint.HughesPJClass.Pretty (Twee.Constraints.Branch f) instance Twee.Pretty.PrettyTerm f => Text.PrettyPrint.HughesPJClass.Pretty (Twee.Constraints.Formula f) instance Twee.Pretty.PrettyTerm f => Text.PrettyPrint.HughesPJClass.Pretty (Twee.Constraints.Atom f) -- | Useful operations on terms and similar. Also re-exports some generally -- useful modules such as Term and Pretty. module Twee.Base -- | Generalisation of term functionality to things that contain terms -- (e.g., rewrite rules and equations). class Symbolic a where { type family ConstantOf a; } -- | Compute a DList of all terms which appear in the argument (used -- for e.g. computing free variables). See also terms. termsDL :: Symbolic a => a -> DList (TermListOf a) -- | Apply a substitution. When using the Symbolic type class, you -- can use subst instead. subst_ :: Symbolic a => (Var -> BuilderOf a) -> a -> a -- | Apply a substitution. subst :: (Symbolic a, Substitution s, SubstFun s ~ ConstantOf a) => s -> a -> a -- | Find all terms occuring in the argument. terms :: Symbolic a => a -> [TermListOf a] -- | A term compatible with a given Symbolic. type TermOf a = Term (ConstantOf a) -- | A termlist compatible with a given Symbolic. type TermListOf a = TermList (ConstantOf a) -- | A substitution compatible with a given Symbolic. type SubstOf a = Subst (ConstantOf a) -- | A triangle substitution compatible with a given Symbolic. type TriangleSubstOf a = TriangleSubst (ConstantOf a) -- | A builder compatible with a given Symbolic. type BuilderOf a = Builder (ConstantOf a) -- | The underlying type of function symbols of a given Symbolic. type FunOf a = Fun (ConstantOf a) -- | Find the variables occurring in the argument. vars :: Symbolic a => a -> [Var] -- | Test if the argument is ground. isGround :: Symbolic a => a -> Bool -- | Find the function symbols occurring in the argument. funs :: Symbolic a => a -> [FunOf a] -- | Count how many times a function symbol occurs in the argument. occ :: Symbolic a => FunOf a -> a -> Int -- | Count how many times a variable occurs in the argument. occVar :: Symbolic a => Var -> a -> Int -- | Rename the argument so that variables are introduced in a canonical -- order (starting with V0, then V1 and so on). canonicalise :: Symbolic a => a -> a -- | Rename the second argument so that it does not mention any variable -- which occurs in the first. renameAvoiding :: (Symbolic a, Symbolic b) => a -> b -> b -- | Represents a unique identifier (e.g., for a rule). newtype Id Id :: Int32 -> Id [unId] :: Id -> Int32 -- | An instance Has a b indicates that a value of type -- a contains a value of type b which is somehow part -- of the meaning of the a. -- -- A number of functions use Has constraints to work in a more -- general setting. For example, the functions in CP operate on -- rewrite rules, but actually accept any a satisfying -- Has a (Rule f). -- -- Use taste when definining Has instances; don't do it -- willy-nilly. class Has a b -- | Get at the thing. the :: Has a b => a -> b class Minimal f minimal :: Minimal f => Fun f -- | Build the minimal constant as a term. minimalTerm :: Minimal f => Term f -- | Check if a term is the minimal constant. isMinimal :: Minimal f => Term f -> Bool -- | Erase a given set of variables from the argument, replacing them with -- the minimal constant. erase :: (Symbolic a, ConstantOf a ~ f, Minimal f) => [Var] -> a -> a -- | Construction of Skolem constants. class Skolem f -- | Turn a variable into a Skolem constant. skolem :: Skolem f => Var -> Fun f -- | For types which have a notion of arity. class Arity f -- | Measure the arity. arity :: Arity f => f -> Int -- | For types which have a notion of size. class Sized a -- | Compute the size. size :: Sized a => a -> Int class Ord f => Ordered f -- | Return True if the first term is less than or equal to the -- second, in the term ordering. lessEq :: Ordered f => Term f -> Term f -> Bool -- | Check if the first term is less than or equal to the second in the -- given model, and decide whether the inequality is strict or nonstrict. lessIn :: Ordered f => Model f -> Term f -> Term f -> Maybe Strictness -- | Return True if the first argument is strictly less than the -- second, in the term ordering. lessThan :: Ordered f => Term f -> Term f -> Bool -- | Return the direction in which the terms are oriented according to the -- term ordering, or Nothing if they cannot be oriented. A result -- of Just LT means that the first term is less -- than or equal to the second. orientTerms :: Ordered f => Term f -> Term f -> Maybe Ordering -- | A hack for encoding Horn clauses. See Score. The default -- implementation of hasEqualsBonus should work OK. class EqualsBonus f hasEqualsBonus :: EqualsBonus f => f -> Bool isEquals, isTrue, isFalse :: EqualsBonus f => f -> Bool isEquals, isTrue, isFalse :: EqualsBonus f => f -> Bool isEquals, isTrue, isFalse :: EqualsBonus f => f -> Bool -- | Describes whether an inequality is strict or nonstrict. data Strictness -- | The first term is strictly less than the second. Strict :: Strictness -- | The first term is less than or equal to the second. Nonstrict :: Strictness -- | The collection of constraints which the type of function symbols must -- satisfy in order to be used by twee. type Function f = (Ordered f, Arity f, Sized f, Minimal f, Skolem f, PrettyTerm f, EqualsBonus f) -- | A function symbol extended with a minimal constant and Skolem -- functions. Comes equipped with Minimal and Skolem -- instances. data Extended f -- | The minimal constant. Minimal :: Extended f -- | A Skolem function. Skolem :: Var -> Extended f -- | An ordinary function symbol. Function :: f -> Extended f instance GHC.Base.Functor Twee.Base.Extended instance GHC.Show.Show f => GHC.Show.Show (Twee.Base.Extended f) instance GHC.Classes.Ord f => GHC.Classes.Ord (Twee.Base.Extended f) instance GHC.Classes.Eq f => GHC.Classes.Eq (Twee.Base.Extended f) instance GHC.Real.Integral Twee.Base.Id instance GHC.Real.Real Twee.Base.Id instance GHC.Num.Num Twee.Base.Id instance GHC.Enum.Bounded Twee.Base.Id instance GHC.Enum.Enum Twee.Base.Id instance GHC.Show.Show Twee.Base.Id instance GHC.Classes.Ord Twee.Base.Id instance GHC.Classes.Eq Twee.Base.Id instance Text.PrettyPrint.HughesPJClass.Pretty f => Text.PrettyPrint.HughesPJClass.Pretty (Twee.Base.Extended f) instance Twee.Pretty.PrettyTerm f => Twee.Pretty.PrettyTerm (Twee.Base.Extended f) instance Twee.Base.Sized f => Twee.Base.Sized (Twee.Base.Extended f) instance Twee.Base.Arity f => Twee.Base.Arity (Twee.Base.Extended f) instance (Data.Typeable.Internal.Typeable f, GHC.Classes.Ord f) => Twee.Constraints.Minimal (Twee.Base.Extended f) instance (Data.Typeable.Internal.Typeable f, GHC.Classes.Ord f) => Twee.Base.Skolem (Twee.Base.Extended f) instance Twee.Base.EqualsBonus f => Twee.Base.EqualsBonus (Twee.Base.Extended f) instance Twee.Base.EqualsBonus f => Twee.Base.EqualsBonus (Twee.Term.Core.Fun f) instance Twee.Base.Sized f => Twee.Base.Sized (Twee.Term.Core.Fun f) instance Twee.Base.Sized f => Twee.Base.Sized (Twee.Term.Core.TermList f) instance Twee.Base.Sized f => Twee.Base.Sized (Twee.Term.Core.Term f) instance Twee.Base.Arity f => Twee.Base.Arity (Twee.Term.Core.Fun f) instance Twee.Base.Has a a instance Twee.Base.Symbolic (Twee.Term.Core.Term f) instance Twee.Base.Symbolic (Twee.Term.Core.TermList f) instance Twee.Base.Symbolic (Twee.Term.Subst f) instance (Twee.Base.ConstantOf a ~ Twee.Base.ConstantOf b, Twee.Base.Symbolic a, Twee.Base.Symbolic b) => Twee.Base.Symbolic (a, b) instance (Twee.Base.ConstantOf a ~ Twee.Base.ConstantOf b, Twee.Base.ConstantOf a ~ Twee.Base.ConstantOf c, Twee.Base.Symbolic a, Twee.Base.Symbolic b, Twee.Base.Symbolic c) => Twee.Base.Symbolic (a, b, c) instance Twee.Base.Symbolic a => Twee.Base.Symbolic [a] instance Twee.Base.Symbolic a => Twee.Base.Symbolic (GHC.Base.Maybe a) instance Text.PrettyPrint.HughesPJClass.Pretty Twee.Base.Id -- | An implementation of Knuth-Bendix ordering. module Twee.KBO -- | Check if one term is less than another in KBO. lessEq :: Function f => Term f -> Term f -> Bool -- | Check if one term is less than another in a given model. lessIn :: Function f => Model f -> Term f -> Term f -> Maybe Strictness -- | A term index to accelerate matching. An index is a multimap from terms -- to arbitrary values. -- -- The type of query supported is: given a search term, find all keys -- such that the search term is an instance of the key, and return the -- corresponding values. module Twee.Index -- | A term index: a multimap from Term f to a. data Index f a -- | An empty index. empty :: Index f a -- | Is the index empty? null :: Index f a -> Bool -- | An index with one entry. singleton :: Term f -> a -> Index f a -- | Insert an entry into the index. insert :: Term f -> a -> Index f a -> Index f a -- | Delete an entry from the index. delete :: Eq a => Term f -> a -> Index f a -> Index f a -- | Look up a term in the index. Finds all key-value such that the search -- term is an instance of the key, and returns an instance of the the -- value which makes the search term exactly equal to the key. lookup :: (Has a b, Symbolic b, Has b (TermOf b)) => TermOf b -> Index (ConstantOf b) a -> [b] -- | Look up a term in the index. Like lookup, but returns the exact -- value that was inserted into the index, not an instance. Also returns -- a substitution which when applied to the value gives you the matching -- instance. matches :: Has a (Term f) => Term f -> Index f a -> [(Subst f, a)] -- | Look up a term in the index, possibly returning spurious extra -- results. approxMatches :: Term f -> Index f a -> [a] -- | Return all elements of the index. elems :: Index f a -> [a] instance GHC.Show.Show a => GHC.Show.Show (Twee.Index.Index f a) instance Data.DynamicArray.Default (Twee.Index.Index f a) -- | Equations. module Twee.Equation data Equation f (:=:) :: {-# UNPACK #-} !(Term f) -> {-# UNPACK #-} !(Term f) -> Equation f [eqn_lhs] :: Equation f -> {-# UNPACK #-} !(Term f) [eqn_rhs] :: Equation f -> {-# UNPACK #-} !(Term f) type EquationOf a = Equation (ConstantOf a) -- | Order an equation roughly left-to-right. However, there is no -- guarantee that the result is oriented. order :: Function f => Equation f -> Equation f -- | Apply a function to both sides of an equation. bothSides :: (Term f -> Term f') -> Equation f -> Equation f' -- | Is an equation of the form t = t? trivial :: Eq f => Equation f -> Bool simplerThan :: Function f => Equation f -> Equation f -> Bool instance GHC.Show.Show (Twee.Equation.Equation f) instance GHC.Classes.Ord (Twee.Equation.Equation f) instance GHC.Classes.Eq (Twee.Equation.Equation f) instance Twee.Base.Symbolic (Twee.Equation.Equation f) instance Twee.Pretty.PrettyTerm f => Text.PrettyPrint.HughesPJClass.Pretty (Twee.Equation.Equation f) instance Twee.Base.Sized f => Twee.Base.Sized (Twee.Equation.Equation f) -- | Equational proofs which are checked for correctedness. module Twee.Proof -- | A checked proof. If you have a value of type Proof f, it -- should jolly well represent a valid proof! -- -- The only way to construct a Proof f is by using -- certify. data Proof f -- | A derivation is an unchecked proof. It might be wrong! The way to -- check it is to call certify to turn it into a Proof. data Derivation f -- | Apply an existing rule (with proof!) to the root of a term UseLemma :: {-# UNPACK #-} !(Lemma f) -> !(Subst f) -> Derivation f -- | Apply an axiom to the root of a term UseAxiom :: {-# UNPACK #-} !(Axiom f) -> !(Subst f) -> Derivation f -- | Reflexivity. Refl t proves t = t. Refl :: !(Term f) -> Derivation f -- | Symmetry Symm :: !(Derivation f) -> Derivation f -- | Transivitity Trans :: !(Derivation f) -> !(Derivation f) -> Derivation f -- | Congruence. Parallel, i.e., takes a function symbol and one derivation -- for each argument of that function. Cong :: {-# UNPACK #-} !(Fun f) -> ![Derivation f] -> Derivation f -- | A lemma, which includes a proof. data Lemma f Lemma :: {-# UNPACK #-} !Id -> !(Proof f) -> Lemma f -- | The id number of the lemma. Has no semantic meaning; for convenience -- only. [lemma_id] :: Lemma f -> {-# UNPACK #-} !Id -- | A proof of the lemma. [lemma_proof] :: Lemma f -> !(Proof f) data Axiom f Axiom :: {-# UNPACK #-} !Int -> !String -> !(Equation f) -> Axiom f -- | The number of the axiom. Has no semantic meaning; for convenience -- only. [axiom_number] :: Axiom f -> {-# UNPACK #-} !Int -- | A description of the axiom. Has no semantic meaning; for convenience -- only. [axiom_name] :: Axiom f -> !String -- | The equation which the axiom asserts. [axiom_eqn] :: Axiom f -> !(Equation f) -- | Checks a Derivation and, if it is correct, returns a certified -- Proof. -- -- If the Derivation is incorrect, throws an exception. certify :: PrettyTerm f => Derivation f -> Proof f equation :: Proof f -> (Equation f) derivation :: Proof f -> (Derivation f) lemma :: Lemma f -> Subst f -> Derivation f axiom :: Axiom f -> Derivation f symm :: Derivation f -> Derivation f trans :: Derivation f -> Derivation f -> Derivation f cong :: Fun f -> [Derivation f] -> Derivation f -- | Applies a derivation at a particular path in a term. congPath :: [Int] -> Term f -> Derivation f -> Derivation f -- | Simplify a derivation. -- -- After simplification, a derivation has the following properties: -- --