Changeset 12760

Show
Ignore:
Timestamp:
30.10.2009 15:04:24 (3 weeks ago)
Author:
maeder
Message:

removed inline axioms and created axioms directly

Location:
trunk
Files:
4 modified
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/CASL/Project.hs

    r11201 r12760  
    4848botTok = genToken "bottom" 
    4949 
    50 bottom :: Id 
    51 bottom = mkId [botTok] 
    52  
    5350uniqueBotName :: OP_TYPE -> Id 
    5451uniqueBotName t = case t of 
     
    5855projectUnique :: OpKind -> Range -> TERM f -> SORT -> TERM f 
    5956projectUnique = makeInjOrProj uniqueProjName 
    60  
    61 rename :: OP_SYMB -> OP_SYMB 
    62 rename o = case o of 
    63     Qual_op_name i t r -> Qual_op_name 
    64         (if i == injName then uniqueInjName t 
    65          else if i == projName then uniqueProjName t 
    66          else if i == bottom then uniqueBotName t 
    67               else i) t r 
    68     _ -> o 
    69  
    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 f 
    75 renameTerm = foldTerm . renameRecord 
    76  
    77 renameFormula :: (f -> f) -> FORMULA f -> FORMULA f 
    78 renameFormula = foldFormula . renameRecord 
  • trunk/CASL/Sign.hs

    r12699 r12760  
    471471mkExEq f f' = Existl_equation f f' nullRange 
    472472 
     473mkStEq :: TERM f -> TERM f -> FORMULA f 
     474mkStEq u v = Strong_equation u v nullRange 
     475 
     476mkEqv :: FORMULA f -> FORMULA f -> FORMULA f 
     477mkEqv u v = Equivalence u v nullRange 
     478 
    473479mkAppl :: OP_SYMB -> [TERM f] -> TERM f 
    474480mkAppl op_symb fs = Application op_symb fs nullRange 
     
    485491conjunct :: [FORMULA f] -> FORMULA f 
    486492conjunct fs = case fs of 
    487   [] -> False_atom nullRange 
     493  [] -> True_atom nullRange 
    488494  [phi] -> phi 
    489495  _ -> Conjunction fs nullRange 
     
    491497mkVarDeclStr :: String -> SORT -> VAR_DECL 
    492498mkVarDeclStr = mkVarDecl . mkSimpleId 
     499 
     500mkAxName :: String -> SORT -> SORT -> String 
     501mkAxName str s s' = "ga_" ++ str ++ "_" ++ show s ++ "_to_" ++ show s' 
  • trunk/Comorphisms/CASL2PCFOL.hs

    r12758 r12760  
    9494          injOpMap setprojOptype 
    9595    -- membership predicates are coded out 
    96  
    97 mkAxName :: String -> SORT -> SORT -> String 
    98 mkAxName str s s' = "ga_" ++ str ++ "_" ++ show s ++ "_to_" ++ show s' 
    9996 
    10097-- | Make the name for the embedding or projecton injectivity axiom 
  • trunk/Comorphisms/CASL2SubCFOL.hs

    r12013 r12760  
    22Module      :  $Header$ 
    33Description :  coding out partiality 
    4 Copyright   :  (c) Zicheng Wang, C.Maeder Uni Bremen 2002-2006 
     4Copyright   :  (c) Zicheng Wang, C.Maeder Uni Bremen 2002-2009 
    55License     :  similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt 
    66 
     
    3737import Common.ProofUtils 
    3838import Common.ProofTree 
    39  
    40 import Data.List (zip) 
     39import Common.Utils 
    4140 
    4241-- | determine the need for bottom constants 
    43 data FormulaTreatment = NoMembershipOrCast | FormulaDependent | SubsortBottoms | AllSortBottoms 
     42data FormulaTreatment = 
     43    NoMembershipOrCast 
     44  | FormulaDependent 
     45  | SubsortBottoms 
     46  | AllSortBottoms 
    4447    deriving Show 
    4548 
     
    141144                    ( \ t -> opKind t == Partial)) ops 
    142145        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 
    147149            in if Set.isSubsetOf more given then given 
    148150               else collect $ Set.union more given 
     
    152154defPred = genName "defined" 
    153155 
    154 defined :: Set.Set SORT -> TERM f -> SORT -> Range -> FORMULA f 
    155 defined bsorts t s ps = 
     156defined :: Set.Set SORT -> TERM f -> Range -> FORMULA f 
     157defined bsorts t ps = let s = sortOfTerm t in 
    156158  if Set.member s bsorts then Predication 
    157159         (Qual_pred_name defPred (Pred_type [s] nullRange) nullRange) [t] ps 
     
    159161 
    160162defVards :: 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 
     163defVards bs = conjunct . concatMap (defVars bs) 
    163164 
    164165defVars :: Set.Set SORT -> VAR_DECL -> [FORMULA f] 
     
    166167 
    167168defVar :: Set.Set SORT -> SORT -> Token -> FORMULA f 
    168 defVar bs s v = defined bs (Qual_var v s nullRange) s nullRange 
     169defVar bs s v = defined bs (Qual_var v s nullRange) nullRange 
    169170 
    170171totalizeOpSymb :: OP_SYMB -> OP_SYMB 
     
    189190    c { opSymbs = map ( \ (o, is) -> (totalizeOpSymb o, is)) $ opSymbs c } 
    190191 
     192botType :: SORT -> OpType 
     193botType x = OpType {opKind = Total, opArgs = [], opRes = x } 
     194 
    191195-- | Add projections to the signature 
    192196encodeSig :: Set.Set SORT -> Sign f e -> Sign f e 
     
    194198    sig { opMap = projOpMap, predMap = newpredMap } where 
    195199   newTotalMap = Map.map (Set.map $ makeTotal Total) $ opMap sig 
    196    botType x = OpType {opKind = Total, opArgs = [], opRes = x } 
    197200   botOpMap  = Set.fold (\ bt -> addOpTo (uniqueBotName $ toOP_TYPE bt) bt) 
    198201       newTotalMap $ Set.map botType bsorts 
     
    208211 
    209212generateAxioms :: 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) ] 
     213generateAxioms 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) 
    263275    where 
    264         x = mkSimpleId "x" 
    265         pr = projName 
    266276        minSupers so = keepMinimals sig id $ Set.toList $ Set.delete so 
    267277                           $ supersortsOf so sig 
    268         d = defPred 
    269278        sortList = Set.toList bsorts 
    270279        opList = [(f,t) | (f,types) <- Map.toList $ opMap sig, 
     
    272281        predList = [(p,t) | (p,types) <- Map.toList $ predMap sig, 
    273282                    t <- Set.toList types ] 
    274         mkVars n = [mkSimpleId ("x_"++show i) | i<-[1..n]] 
    275283 
    276284codeRecord :: Bool -> Set.Set SORT -> (f -> f) -> Record f (FORMULA f) (TERM f) 
     
    281289          Quantification q vs (Implication (defVards bsrts vs) qf True ps) ps 
    282290      _ -> Quantification q vs (Conjunction [defVards bsrts vs, qf] ps) ps 
    283     , foldDefinedness = \ _ t ps -> defined bsrts t (sortOfTerm t) ps 
     291    , foldDefinedness = const $ defined bsrts 
    284292    , foldExistl_equation = \ _ t1 t2 ps -> 
    285293      Conjunction[Strong_equation t1 t2 ps, 
    286                   defined bsrts t1 (sortOfTerm t1) ps] ps 
     294                  defined bsrts t1 ps] ps 
    287295    , foldMembership = \ _ t s ps -> 
    288           defined bsrts (projectUnique Total ps t s) s ps 
     296          defined bsrts (projectUnique Total ps t s) ps 
    289297    , foldSort_gen_ax = \ _ cs b -> if uniBot then 
    290           Sort_gen_ax (map (totalizeConstraint bsrts) cs) $ 
    291               if not uniBot || Set.null (Set.intersection bsrts 
    292                 $ Set.fromList $ map newSort cs) then b else False 
     298          Sort_gen_ax (map (totalizeConstraint bsrts) cs) 
     299              $ Set.null (Set.intersection bsrts 
     300                $ Set.fromList $ map newSort cs) && b 
    293301          else error "SubPFOL2SubFOL: unexpected Sort_gen_ax" 
    294     , foldApplication = \ _ o args ps -> Application (totalizeOpSymb o) args ps 
     302    , foldApplication = const $ Application . totalizeOpSymb 
    295303    , foldCast = \ _ t s ps -> projectUnique Total ps t s } 
    296304 
     
    300308codeTerm :: Bool -> Set.Set SORT -> TERM () -> TERM () 
    301309codeTerm 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 f 
    308 rmDefs bsrts = foldFormula . rmDefsRecord bsrts 
    309310 
    310311-- | find sorts that need a bottom in membership formulas and casts 
  • trunk/Makefile

    r12753 r12760  
    363363 
    364364# files to be processed by utils/InlineAxioms 
    365 inline_axiom_files = Comorphisms/Modal2CASL.hs \ 
    366     Comorphisms/CASL2SubCFOL.hs CASL_DL/PredefinedSign.hs 
     365inline_axiom_files = Comorphisms/Modal2CASL.hs CASL_DL/PredefinedSign.hs 
    367366 
    368367gen_inline_axiom_files = $(patsubst %.hs,%.inline.hs, $(inline_axiom_files))