TermFormula.hs revision 2a5b885d9350ec6dd8bc4992ee91d2f68aa592f4
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannModule : $Header$
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannDescription : auxiliary functions on terms and formulas
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannCopyright : (c) Mingyi Liu and Till Mossakowski and Uni Bremen 2004-2005
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannLicense : GPLv2 or higher, see LICENSE.txt
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannMaintainer : xinga@informatik.uni-bremen.de
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannStability : provisional
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannPortability : portable
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannAuxiliary functions on terms and formulas
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport CASL.Sign(OpMap, Sign(sortRel), toOP_TYPE, toOpType)
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport Common.Id(Token(tokStr), Id(Id), Range, GetRange(..), nullRange)
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport qualified Common.Lib.MapSet as MapSet
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport qualified Common.Lib.Rel as Rel
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport qualified Data.Map as Map
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport qualified Data.Set as Set
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | the sorted term is always ignored
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannterm :: TERM f -> TERM f
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannterm t = case t of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Sorted_term t' _ _ -> term t'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | the quantifier of term is always ignored
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannquanti :: FORMULA f -> FORMULA f
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannquanti f = case f of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Quantification _ _ f' _ -> quanti f'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | check whether it exist a (unique)existent quantification
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisExQuanti :: FORMULA f -> Bool
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisExQuanti f =
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Quantification Existential _ _ _ -> True
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Quantification Unique_existential _ _ _ -> True
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Quantification _ _ f' _ -> isExQuanti f'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Implication f1 f2 _ _ -> isExQuanti f1 || isExQuanti f2
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Equivalence f1 f2 _ -> isExQuanti f1 || isExQuanti f2
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Negation f' _ -> isExQuanti f'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | get the constraint from a sort generated axiom
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannconstraintOfAxiom :: FORMULA f -> [Constraint]
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannconstraintOfAxiom f =
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Sort_gen_ax constrs _ -> constrs
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | determine whether a formula is a sort generation constraint
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisSortGen :: FORMULA a -> Bool
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisSortGen (Sort_gen_ax _ _) = True
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisSortGen _ = False
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | check whether it contains a membership formula
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisMembership :: FORMULA f -> Bool
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisMembership f =
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Quantification _ _ f' _ -> isMembership f'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Conjunction fs _ -> any isMembership fs
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Disjunction fs _ -> any isMembership fs
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Negation f' _ -> isMembership f'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Implication f1 f2 _ _ -> isMembership f1 || isMembership f2
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Equivalence f1 f2 _ -> isMembership f1 || isMembership f2
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Membership _ _ _ -> True
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | check whether a sort is free generated
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisFreeGenSort :: SORT -> [FORMULA f] -> Maybe Bool
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisFreeGenSort _ [] = Nothing
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisFreeGenSort s (f:fs) =
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Sort_gen_ax csts isFree | any ((== s) . newSort) csts -> Just isFree
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann _ -> isFreeGenSort s fs
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | check whether it is the domain of a partial function
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisDomain :: FORMULA f -> Bool
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisDomain f = case (quanti f) of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Equivalence (Definedness _ _) f' _ -> not (containDef f')
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Definedness _ _ -> True
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | check whether it contains a definedness formula
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmanncontainDef :: FORMULA f -> Bool
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmanncontainDef f = case f of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Quantification _ _ f' _ -> containDef f'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Conjunction fs _ -> any containDef fs
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Disjunction fs _ -> any containDef fs
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Implication f1 f2 _ _ -> containDef f1 || containDef f2
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Equivalence f1 f2 _ -> containDef f1 || containDef f2
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Negation f' _ -> containDef f'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Definedness _ _ -> True
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | check whether it contains a negation
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmanncontainNeg :: FORMULA f -> Bool
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmanncontainNeg f = case f of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Quantification _ _ f' _ -> containNeg f'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Implication _ f' _ _ -> containNeg f'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Equivalence f' _ _ -> containNeg f'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Negation _ _ -> True
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | check whether it contains a definedness formula in correct form
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmanncorrectDef :: FORMULA f -> Bool
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmanncorrectDef f = case (quanti f) of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Implication _ (Definedness _ _) _ _ -> False
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Implication (Definedness _ _) _ _ _ -> True
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Equivalence (Definedness _ _) f' _ -> not (containDef f')
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Negation (Definedness _ _) _ -> True
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Definedness _ _ -> True
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | extract all partial function symbols, their domains are defined
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmanndomainOpSymbs :: [FORMULA f] -> [OP_SYMB]
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmanndomainOpSymbs fs = concatMap domOpS fs
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann where domOpS f = case (quanti f) of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Equivalence (Definedness t _) _ _ -> [opSymbOfTerm t]
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | check whether a formula gives the domain of a partial function
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmanndomainOs :: FORMULA f -> OP_SYMB -> Bool
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmanndomainOs f os = case (quanti f) of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Equivalence (Definedness t _) _ _ -> opSymbOfTerm t == os
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | extract the domain-list of partial functions
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmanndomainList :: [FORMULA f] -> [(TERM f,FORMULA f)]
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmanndomainList fs = concatMap dm fs
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann where dm f = case (quanti f) of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Equivalence (Definedness t _) f' _ -> [(t,f')]
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | check whether it is a application term
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisApp :: TERM t -> Bool
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisApp t = case t of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Application _ _ _ -> True
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Sorted_term t' _ _ -> isApp t'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Cast t' _ _ -> isApp t'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | check whether it is a Variable
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisVar :: TERM t -> Bool
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannisVar t = case t of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Qual_var _ _ _ -> True
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Sorted_term t' _ _ -> isVar t'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Cast t' _ _ -> isVar t'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | extract the operation symbol from a term
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannopSymbOfTerm :: TERM f -> OP_SYMB
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannopSymbOfTerm t = case term t of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Application os _ _ -> os
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Sorted_term t' _ _ -> opSymbOfTerm t'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Conditional t' _ _ _ -> opSymbOfTerm t'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann _ -> error "CASL.CCC.TermFormula.<opSymbOfTerm>"
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | extract all variables of a term
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannvarOfTerm :: Ord f => TERM f -> [TERM f]
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannvarOfTerm t = case t of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Qual_var _ _ _ -> [t]
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Sorted_term t' _ _ -> varOfTerm t'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Application _ ts _ -> if null ts then []
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann else nubOrd $ concatMap varOfTerm ts
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | extract all arguments of a term
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannarguOfTerm :: TERM f-> [TERM f]
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannarguOfTerm t = case t of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Qual_var _ _ _ -> [t]
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Application _ ts _ -> ts
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Sorted_term t' _ _ -> arguOfTerm t'
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | extract all arguments of a predication
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannarguOfPred :: FORMULA f -> [TERM f]
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannarguOfPred f = case quanti f of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Negation f1 _ -> arguOfPred f1
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Predication _ ts _ -> ts
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | extract all variables of a axiom
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannvarOfAxiom :: FORMULA f -> [VAR]
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannvarOfAxiom f =
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Quantification Universal v_d _ _ ->
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann concatMap (\(Var_decl vs _ _)-> vs) v_d
_ -> error "CASL.CCC.TermFormula<extractLeadingSymb>"
where sM = Rel.toMap $ sortRel sig
slist = case Map.lookup s2 sM of
_ -> error "CASL.CCC.TermFormula<varD>"
sortOfV _ = error "CASL.CCC.TermFormula<sortOfV>"
varOfV _ = error "CASL.CCC.TermFormula<varOfV>"