CASL2SubCFOL.hs revision 3a2de7e5a3c5da0a96c9563617ab332685a41ced
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk{-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances #-}
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkModule : $Header$
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkDescription : coding out partiality
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkCopyright : (c) Zicheng Wang, C.Maeder Uni Bremen 2002-2009
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkLicense : GPLv2 or higher, see LICENSE.txt
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkMaintainer : Christian.Maeder@dfki.de
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkStability : provisional
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkPortability : non-portable (imports Logic.Comorphism)
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkCoding out partiality (SubPCFOL= -> SubCFOL=) while keeping subsorting.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkWithout unique bottoms sort generation axioms are not allowed.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkThen we have (SubPFOL= -> SubFOL=).
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport CASL.Sublogic as SL hiding (bottom)
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport qualified Data.Map as Map
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport qualified Data.Set as Set
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport qualified Common.Lib.Rel as Rel
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport qualified Common.Lib.MapSet as MapSet
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk-- | determine the need for bottom constants
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkdata FormulaTreatment =
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk NoMembershipOrCast
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk | FormulaDependent
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk | SubsortBottoms
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk | AllSortBottoms
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk deriving Show
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk-- | a case selector for formula treatment
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenktreatFormula :: FormulaTreatment -> a -> a -> a -> a -> a
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenktreatFormula g a b c d = case g of
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk NoMembershipOrCast -> a
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk FormulaDependent -> b
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk SubsortBottoms -> c
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk AllSortBottoms -> d
let fbsrts = Set.unions $ map (botFormulaSorts . sentence) sens
mor { msource = encodeSig (sortsWithBottom m src Set.empty) src
, mtarget = encodeSig (sortsWithBottom m tar Set.empty) tar
, op_map = Map.map (\ (i, _) -> (i, Total)) $ op_map mor }
Set.singleton s { symbType = totalizeSymbType $ symbType s }
let bsrts = treatFormula m Set.empty formBotSrts
(Rel.keysSet $ sortRel sig) (sortSet sig)
ops = MapSet.elems $ opMap sig
allSortsWithBottom . Set.union bsrts
(any (`Set.member` given) . opArgs) ops
in if Set.isSubsetOf more given then given
else collect $ Set.union more given
defined :: TermExtension f => Set.Set SORT -> TERM f -> Range -> FORMULA f
if Set.member s bsorts then Predication
defVards :: TermExtension f => Set.Set SORT -> [VAR_DECL] -> FORMULA f
defVars :: TermExtension f => Set.Set SORT -> VAR_DECL -> [FORMULA f]
defVar :: TermExtension f => Set.Set SORT -> SORT -> Token -> FORMULA f
argSorts :: Constraint -> Set.Set SORT
argSorts c = Set.unions $ map (argsOpSymb . fst) $ opSymbs c
Qual_op_name _ ot _ -> Set.fromList $ args_OP_TYPE ot
totalizeConstraint :: Set.Set SORT -> Constraint -> Constraint
(if Set.member (newSort c) bsrts then addBottomAlt else id)
encodeSig :: Set.Set SORT -> Sign f e -> Sign f e
encodeSig bsorts sig = if Set.null bsorts then sig else
newTotalMap = MapSet.map mkTotal $ opMap sig
botOpMap = Set.fold (\ bt -> addOpTo (uniqueBotName $ toOP_TYPE bt) bt)
newTotalMap $ Set.map botType bsorts
defTypes = Set.map defType bsorts
newpredMap = MapSet.update (const defTypes) defPred $ predMap sig
projOpMap = Set.fold (\ t -> addOpTo (uniqueProjName $ toOP_TYPE t) t)
generateAxioms :: Bool -> Set.Set SORT -> Sign f e -> [Named (FORMULA ())]
hasBot = Set.member s bsorts
rel1 = Rel.transClosure $ sortRel sig
sccs = Rel.sccOfClosure rel1
sortList = Set.toList bsorts
codeRecord :: TermExtension f => Bool -> Set.Set SORT -> (f -> f)
$ Set.fromList $ map newSort cs) && b
codeFormula :: Bool -> Set.Set SORT -> FORMULA () -> FORMULA ()
codeTerm :: Bool -> Set.Set SORT -> TERM () -> TERM ()
{ foldMembership = \ _ _ s _ -> Set.singleton s
, foldCast = \ _ _ s _ -> Set.singleton s }
botFormulaSorts :: FORMULA f -> Set.Set SORT
botFormulaSorts = foldFormula (botSorts $ const Set.empty)
botTermSorts :: TERM f -> Set.Set SORT
botTermSorts = foldTerm (botSorts $ const Set.empty)