FreeTypes.hs revision ad602cf9fc48c213018a82f87f6f92575866061e
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski Module : $Header$
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski Copyright : (c) Mingyi Liu and Till Mossakowski and Uni Bremen 2004
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski Licence : similar to LGPL, see HetCATS/LICENCE.txt or LIZENZ.txt
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski Maintainer : hets@tzi.de
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski Stability : provisional
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski Portability : portable
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski add diagnostic messages. Change result type to Result (Maybe Bool) (see Common/Result.hs,
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski function warning, extract pos from FORMULA or TERM, take the head of the list [pos]).
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski i.e. instead of Just False, return
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski warning (Just False) "sort s is not inhabited" pos
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski similarly for Nothing
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski instead of Just True, take
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski return (Just True)
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski extend function checkFreeType by
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski for each axiom, let f be the function/predicate application of the
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski leading symbol on the left hand-side (lhs), and f(t_1,...,t_n) the lhs.
601dc92e4c128d23a726593357c654fb776a63a7Till Mossakowski Check that in the right hand-side, each occurence of f is applied
601dc92e4c128d23a726593357c654fb776a63a7Till Mossakowski only to subterms of f(t_1,...,t_n).
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski for example, f(Cons(x,y)) = f(y)
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowskiimport CASL.Sign -- Sign, OpType
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowskiimport CASL.AS_Basic_CASL -- FORMULA, OP_{NAME,SYMB}, TERM, SORT, VAR
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowskiimport qualified Common.Lib.Map as Map
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowskiimport qualified Common.Lib.Set as Set
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowskiimport qualified Common.Lib.Rel as Rel
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski function checkFreeType:
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski - check if leading symbols are new (not in the image of morphism), if not, return Nothing
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski - the leading terms consist of variables and constructors only, if not, return Nothing
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski - split function leading_Symb into
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski leading_Term_Predication :: FORMULA f -> Maybe(Either Term (Formula f))
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski extract_leading_symb :: Either Term (Formula f) -> Either OP_SYMB PRED_SYMB
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski - collect all operation symbols from recover_Sort_gen_ax fconstrs (= constructors)
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski - no variable occurs twice in a leading term, if not, return Nothing
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski - check that patterns do not overlap, if not, return Nothing This means:
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski in each group of the grouped axioms:
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski all patterns of leading terms/formulas are disjoint
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski this means: either leading symbol is a variable, and there is just one axiom
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski otherwise, group axioms according to leading symbol
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski no symbol may be a variable
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski check recursively the arguments of constructor in each group
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski - return (Just True)
047de69319a752b9c467166b1264f9e121459e2dTill MossakowskicheckFreeType :: (PrettyPrint f, Eq f) => Morphism f e m -> [Named (FORMULA f)]
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski -> Result (Maybe Bool)
047de69319a752b9c467166b1264f9e121459e2dTill MossakowskicheckFreeType m fsn = return $ checkFreeType1 m fsn
047de69319a752b9c467166b1264f9e121459e2dTill MossakowskicheckFreeType1 :: (PrettyPrint f, Eq f) => Morphism f e m -> [Named (FORMULA f)] -> Maybe Bool
047de69319a752b9c467166b1264f9e121459e2dTill MossakowskicheckFreeType1 m fsn
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski | Set.any (\s->not $ elem s srts) newSorts = Nothing
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski | Set.any (\s->not $ elem s f_Inhabited) newSorts = Just False
047de69319a752b9c467166b1264f9e121459e2dTill Mossakowski | elem Nothing l_Syms = Nothing
-- sorts1 = Set.toList $ sortSet sig
-- newSorts2 = Set.toList $ sortSet (mtarget m)
f_Inhabited1 = inhabited (Set.toList oldSorts) fconstrs
find_ot (ident,ot) = case Map.lookup ident oldOpMap of
Just ots -> Set.member ot ots
find_pt (ident,pt) = case Map.lookup ident oldPredMap of
Just pts -> Set.member pt pts