Changeset 12760
- Timestamp:
- 30.10.2009 15:04:24 (3 weeks ago)
- Location:
- trunk
- Files:
-
- 4 modified
- 1 moved
-
CASL/Project.hs (modified) (2 diffs)
-
CASL/Sign.hs (modified) (3 diffs)
-
Comorphisms/CASL2PCFOL.hs (modified) (1 diff)
-
Comorphisms/CASL2SubCFOL.hs (moved) (moved from trunk/Comorphisms/CASL2SubCFOL.inline.hs) (12 diffs)
-
Makefile (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/CASL/Project.hs
r11201 r12760 48 48 botTok = genToken "bottom" 49 49 50 bottom :: Id51 bottom = mkId [botTok]52 53 50 uniqueBotName :: OP_TYPE -> Id 54 51 uniqueBotName t = case t of … … 58 55 projectUnique :: OpKind -> Range -> TERM f -> SORT -> TERM f 59 56 projectUnique = makeInjOrProj uniqueProjName 60 61 rename :: OP_SYMB -> OP_SYMB62 rename o = case o of63 Qual_op_name i t r -> Qual_op_name64 (if i == injName then uniqueInjName t65 else if i == projName then uniqueProjName t66 else if i == bottom then uniqueBotName t67 else i) t r68 _ -> o69 70 renameRecord :: (f -> f) -> Record f (FORMULA f) (TERM f)71 renameRecord mf = (mapRecord mf)72 { foldApplication = \ _ o args r -> Application (rename o) args r }73 74 renameTerm :: (f -> f) -> TERM f -> TERM f75 renameTerm = foldTerm . renameRecord76 77 renameFormula :: (f -> f) -> FORMULA f -> FORMULA f78 renameFormula = foldFormula . renameRecord -
trunk/CASL/Sign.hs
r12699 r12760 471 471 mkExEq f f' = Existl_equation f f' nullRange 472 472 473 mkStEq :: TERM f -> TERM f -> FORMULA f 474 mkStEq u v = Strong_equation u v nullRange 475 476 mkEqv :: FORMULA f -> FORMULA f -> FORMULA f 477 mkEqv u v = Equivalence u v nullRange 478 473 479 mkAppl :: OP_SYMB -> [TERM f] -> TERM f 474 480 mkAppl op_symb fs = Application op_symb fs nullRange … … 485 491 conjunct :: [FORMULA f] -> FORMULA f 486 492 conjunct fs = case fs of 487 [] -> False_atom nullRange493 [] -> True_atom nullRange 488 494 [phi] -> phi 489 495 _ -> Conjunction fs nullRange … … 491 497 mkVarDeclStr :: String -> SORT -> VAR_DECL 492 498 mkVarDeclStr = mkVarDecl . mkSimpleId 499 500 mkAxName :: String -> SORT -> SORT -> String 501 mkAxName str s s' = "ga_" ++ str ++ "_" ++ show s ++ "_to_" ++ show s' -
trunk/Comorphisms/CASL2PCFOL.hs
r12758 r12760 94 94 injOpMap setprojOptype 95 95 -- membership predicates are coded out 96 97 mkAxName :: String -> SORT -> SORT -> String98 mkAxName str s s' = "ga_" ++ str ++ "_" ++ show s ++ "_to_" ++ show s'99 96 100 97 -- | Make the name for the embedding or projecton injectivity axiom -
trunk/Comorphisms/CASL2SubCFOL.hs
r12013 r12760 2 2 Module : $Header$ 3 3 Description : coding out partiality 4 Copyright : (c) Zicheng Wang, C.Maeder Uni Bremen 2002-200 64 Copyright : (c) Zicheng Wang, C.Maeder Uni Bremen 2002-2009 5 5 License : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt 6 6 … … 37 37 import Common.ProofUtils 38 38 import Common.ProofTree 39 40 import Data.List (zip) 39 import Common.Utils 41 40 42 41 -- | determine the need for bottom constants 43 data FormulaTreatment = NoMembershipOrCast | FormulaDependent | SubsortBottoms | AllSortBottoms 42 data FormulaTreatment = 43 NoMembershipOrCast 44 | FormulaDependent 45 | SubsortBottoms 46 | AllSortBottoms 44 47 deriving Show 45 48 … … 141 144 ( \ t -> opKind t == Partial)) ops 142 145 collect given = 143 let more = allSortsWithBottom $ 144 Set.unions $ map (Set.map opRes . 145 Set.filter ( \ t -> any 146 (flip Set.member given) $ opArgs t)) ops 146 let more = allSortsWithBottom $ Set.unions $ map 147 (Set.map opRes . Set.filter 148 (any (flip Set.member given) . opArgs)) ops 147 149 in if Set.isSubsetOf more given then given 148 150 else collect $ Set.union more given … … 152 154 defPred = genName "defined" 153 155 154 defined :: Set.Set SORT -> TERM f -> SORT ->Range -> FORMULA f155 defined bsorts t s ps =156 defined :: Set.Set SORT -> TERM f -> Range -> FORMULA f 157 defined bsorts t ps = let s = sortOfTerm t in 156 158 if Set.member s bsorts then Predication 157 159 (Qual_pred_name defPred (Pred_type [s] nullRange) nullRange) [t] ps … … 159 161 160 162 defVards :: Set.Set SORT -> [VAR_DECL] -> FORMULA f 161 defVards bs [vs@(Var_decl [_] _ _)] = head $ defVars bs vs 162 defVards bs vs = Conjunction (concatMap (defVars bs) vs) nullRange 163 defVards bs = conjunct . concatMap (defVars bs) 163 164 164 165 defVars :: Set.Set SORT -> VAR_DECL -> [FORMULA f] … … 166 167 167 168 defVar :: Set.Set SORT -> SORT -> Token -> FORMULA f 168 defVar bs s v = defined bs (Qual_var v s nullRange) snullRange169 defVar bs s v = defined bs (Qual_var v s nullRange) nullRange 169 170 170 171 totalizeOpSymb :: OP_SYMB -> OP_SYMB … … 189 190 c { opSymbs = map ( \ (o, is) -> (totalizeOpSymb o, is)) $ opSymbs c } 190 191 192 botType :: SORT -> OpType 193 botType x = OpType {opKind = Total, opArgs = [], opRes = x } 194 191 195 -- | Add projections to the signature 192 196 encodeSig :: Set.Set SORT -> Sign f e -> Sign f e … … 194 198 sig { opMap = projOpMap, predMap = newpredMap } where 195 199 newTotalMap = Map.map (Set.map $ makeTotal Total) $ opMap sig 196 botType x = OpType {opKind = Total, opArgs = [], opRes = x }197 200 botOpMap = Set.fold (\ bt -> addOpTo (uniqueBotName $ toOP_TYPE bt) bt) 198 201 newTotalMap $ Set.map botType bsorts … … 208 211 209 212 generateAxioms :: Bool -> Set.Set SORT -> Sign f e -> [Named (FORMULA ())] 210 generateAxioms b bsorts sig = filter (not . is_True_atom . sentence) $ 211 map (mapNamed $ simplifyFormula id . rmDefs bsorts id) $ 212 map (mapNamed $ renameFormula id) $ concat $ 213 [inlineAxioms CASL 214 " sort s < s' \ 215 \ op pr : s'->s \ 216 \ pred d:s \ 217 \ forall x,y:s'. d(pr(x)) /\\ d(pr(y)) /\\ pr(x)=pr(y) => x=y \ 218 \ %(ga_projection_injectivity)% " 219 ++ inlineAxioms CASL 220 " sort s < s' \ 221 \ op pr : s'->s \ 222 \ pred d:s \ 223 \ forall x:s . d(x) => pr(x)=x %(ga_projection)% " 224 | s <- sortList, let y = mkSimpleId "y", 225 s' <- minSupers s] 226 ++ [inlineAxioms CASL 227 " sort s \ 228 \ pred d:s \ 229 \ . exists x:s.d(x) %(ga_nonEmpty)%" ++ 230 (if b then 231 inlineAxioms CASL 232 " sort s \ 233 \ op bottom:s \ 234 \ pred d:s \ 235 \ . forall x:s . not d(x) <=> x=bottom %(ga_notDefBottom)%" 236 else 237 inlineAxioms CASL 238 " sort s \ 239 \ op bottom:s \ 240 \ pred d:s \ 241 \ . not d(bottom) %(ga_notDefBottom)%") 242 | s <- sortList ] ++ 243 [inlineAxioms CASL 244 " sort t \ 245 \ sorts s_i \ 246 \ op f:s_i->t \ 247 \ forall y_k:s_i . def f(y_k) <=> def y_k /\\ def y_k %(ga_totality)%" 248 | (f,typ) <- opList, opKind typ == Total, 249 let s=opArgs typ; t=opRes typ; y= mkVars (length s) ] ++ 250 [inlineAxioms CASL 251 " sort t \ 252 \ sorts s_i \ 253 \ op f:s_i->t \ 254 \ forall y_k:s_i . def f(y_k) => def y_k /\\ def y_k %(ga_strictness)%" 255 | (f,typ) <- opList, opKind typ == Partial, 256 let s=opArgs typ; t=opRes typ; y= mkVars (length s) ] ++ 257 [inlineAxioms CASL 258 " sorts s_i \ 259 \ pred p:s_i \ 260 \ forall y_k:s_i . p(y_k) => def y_k /\\ def y_k \ 261 \ %(ga_predicate_strictness)%" 262 | (p,typ) <- predList, let s=predArgs typ; y=mkVars (length s) ] 213 generateAxioms uniqBot bsorts sig = concatMap (\ s -> let 214 vx = mkVarDeclStr "x" s 215 xt = toQualVar vx 216 hasBot = Set.member s bsorts 217 prj z = projectUnique Total nullRange z s 218 df z = defined bsorts z nullRange 219 in concatMap (\ s' -> 220 [makeNamed (mkAxName "projection_injectivity" s' s) 221 $ let xv = mkVarDeclStr "x" s' 222 yv = mkVarDeclStr "y" s' 223 tx = toQualVar xv 224 ty = toQualVar yv 225 px = prj tx 226 py = prj ty 227 epxy = mkStEq px py 228 -- forall x,y:s' . d(pr(x)) /\\ d(pr(y)) /\\ pr(x)=pr(y) => x=y 229 in mkForall [xv, yv] 230 (mkImpl (if hasBot then conjunct [df px, df py, epxy] 231 else epxy) $ mkStEq tx ty) 232 nullRange 233 -- forall x:s . d(x) => pr(x)=x 234 , makeNamed (mkAxName "projection" s' s) 235 $ let eq = mkStEq (prj $ Sorted_term xt s' nullRange) xt 236 in mkForall [vx] 237 (if hasBot then mkImpl (df xt) eq else eq) 238 nullRange]) (minSupers s) 239 -- exists x:s . d(x) 240 ++ [makeNamed ("ga_nonEmpty_" ++ show s) 241 $ Quantification Existential [vx] (df xt) nullRange 242 | hasBot] 243 ++ [makeNamed ("ga_notDefBottom_" ++ show s) 244 $ let bty = toOP_TYPE $ botType s 245 bt = mkAppl (Qual_op_name (uniqueBotName bty) bty nullRange) [] 246 in if uniqBot then 247 -- forall x:s . not d(x) <=> x=bottom 248 mkForall [vx] 249 (mkEqv (Negation (df xt) nullRange) 250 $ mkStEq xt bt) nullRange 251 else Negation (df bt) nullRange -- not d(bottom) 252 | hasBot]) sortList 253 ++ filter (not . is_True_atom . sentence) 254 (map (mapNamed $ simplifyFormula id) 255 $ map (\ (f, typ) -> 256 let vs = map (\ (s, i) -> mkVarDeclStr ("x_" ++ show i) s) 257 $ number $ opArgs typ 258 in makeNamed ("ga_totality_" ++ show f) 259 -- forall x_i:s_i . d f(x_1, ..., x_n) {<}=> d x_1 /\\ ... /\\ d x_n 260 $ mkForall vs 261 ((if opKind typ == Total then mkEqv else mkImpl) 262 (defined bsorts (mkAppl (Qual_op_name f (toOP_TYPE typ) nullRange) 263 $ map toQualVar vs) nullRange) 264 $ defVards bsorts vs) nullRange) opList 265 ++ map (\ (p, typ) -> 266 let vs = map (\ (s, i) -> mkVarDeclStr ("x_" ++ show i) s) 267 $ number $ predArgs typ 268 in makeNamed ("ga_predicate_strictness_" ++ show p) 269 -- forall x_i:s_i . p(x_1, ..., x_n) => d x_1 /\\ ... /\\ d x_n 270 $ mkForall vs 271 (mkImpl 272 (Predication (Qual_pred_name p (toPRED_TYPE typ) nullRange) 273 (map toQualVar vs) nullRange) 274 $ defVards bsorts vs) nullRange) predList) 263 275 where 264 x = mkSimpleId "x"265 pr = projName266 276 minSupers so = keepMinimals sig id $ Set.toList $ Set.delete so 267 277 $ supersortsOf so sig 268 d = defPred269 278 sortList = Set.toList bsorts 270 279 opList = [(f,t) | (f,types) <- Map.toList $ opMap sig, … … 272 281 predList = [(p,t) | (p,types) <- Map.toList $ predMap sig, 273 282 t <- Set.toList types ] 274 mkVars n = [mkSimpleId ("x_"++show i) | i<-[1..n]]275 283 276 284 codeRecord :: Bool -> Set.Set SORT -> (f -> f) -> Record f (FORMULA f) (TERM f) … … 281 289 Quantification q vs (Implication (defVards bsrts vs) qf True ps) ps 282 290 _ -> Quantification q vs (Conjunction [defVards bsrts vs, qf] ps) ps 283 , foldDefinedness = \ _ t ps -> defined bsrts t (sortOfTerm t) ps291 , foldDefinedness = const $ defined bsrts 284 292 , foldExistl_equation = \ _ t1 t2 ps -> 285 293 Conjunction[Strong_equation t1 t2 ps, 286 defined bsrts t1 (sortOfTerm t1)ps] ps294 defined bsrts t1 ps] ps 287 295 , foldMembership = \ _ t s ps -> 288 defined bsrts (projectUnique Total ps t s) sps296 defined bsrts (projectUnique Total ps t s) ps 289 297 , foldSort_gen_ax = \ _ cs b -> if uniBot then 290 Sort_gen_ax (map (totalizeConstraint bsrts) cs) $291 if not uniBot ||Set.null (Set.intersection bsrts292 $ Set.fromList $ map newSort cs) then b else False298 Sort_gen_ax (map (totalizeConstraint bsrts) cs) 299 $ Set.null (Set.intersection bsrts 300 $ Set.fromList $ map newSort cs) && b 293 301 else error "SubPFOL2SubFOL: unexpected Sort_gen_ax" 294 , foldApplication = \ _ o args ps -> Application (totalizeOpSymb o) args ps302 , foldApplication = const $ Application . totalizeOpSymb 295 303 , foldCast = \ _ t s ps -> projectUnique Total ps t s } 296 304 … … 300 308 codeTerm :: Bool -> Set.Set SORT -> TERM () -> TERM () 301 309 codeTerm b bsorts = foldTerm (codeRecord b bsorts $ error "CASL2SubCFol") 302 303 rmDefsRecord :: Set.Set SORT -> (f -> f) -> Record f (FORMULA f) (TERM f)304 rmDefsRecord bsrts mf = (mapRecord mf)305 { foldDefinedness = \ _ t ps -> defined bsrts t (sortOfTerm t) ps }306 307 rmDefs :: Set.Set SORT -> (f -> f) -> FORMULA f -> FORMULA f308 rmDefs bsrts = foldFormula . rmDefsRecord bsrts309 310 310 311 -- | find sorts that need a bottom in membership formulas and casts -
trunk/Makefile
r12753 r12760 363 363 364 364 # files to be processed by utils/InlineAxioms 365 inline_axiom_files = Comorphisms/Modal2CASL.hs \ 366 Comorphisms/CASL2SubCFOL.hs CASL_DL/PredefinedSign.hs 365 inline_axiom_files = Comorphisms/Modal2CASL.hs CASL_DL/PredefinedSign.hs 367 366 368 367 gen_inline_axiom_files = $(patsubst %.hs,%.inline.hs, $(inline_axiom_files))