AnalysisStructured.hs revision 242691238a8d1a89581751d782af87ec5d7470c0
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Module : $Header$
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Copyright : (c) Till Mossakowski and Uni Bremen 2003
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu Licence : similar to LGPL, see HetCATS/LICENCE.txt or LIZENZ.txt
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Maintainer : hets@tzi.de
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Stability : provisional
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Portability : portable
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc Analysis of structured specifications
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Follows the verfication semantic rules in Chap. IV:4.7
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder of the CASL Reference Manual.
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Improve efficiency by storing local signature fragments only
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Name views in devgraphs?
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Check that translations and reductions do not effect local env
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder (Implement new semantics for revealing here)
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Unions (already in the parser) need unions of logics
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder = suprema in the lattice of default logic inclusions!
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder (also needed by closed specs)
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Should we use institution independent analysis over the Grothendieck logic?
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder abstract syntax + devgraph would have to be changed to homogeneous case
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder logic translations are symbol maps in the Grothendieck logic
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Problem with this approach: symbol functor goes into rel,
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder and induced_from_morphism gets difficult to implement
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Unions need inclusion morphisms. Should these play a special role?
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder At least we need a function delivering the inclusion morphism
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc between two (sub)signatures.
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder In most logics, inclusions could be represented specially, such
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder that composition for them becomes fast.
7b1111ca3b126f71cce47e60ce4b56e6f92422e9Karl Luc Should we even identify an inclusion subcategory?
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Then inclusions are represented by pair of signatures
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder (Non-inclusions could be specially displayed in the DG)
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Treatment of translations and reductions along logic translations
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder (see WADT 02 paper).
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Open question:
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder may local env be translated, and even reduced, along logic translations?
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder if yes: how is local env linked to signature of resulting spec?
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder (important e.g. for checking that local env is not being renamed?)
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder does signature+comorphism suffice, such that c(local env)\subseteq sig?
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder if no: this means that only closed specs may be translated
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Revealings without translations: just one arrow
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Pushouts: only admissible within one logic?
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Instantiations with formal parameter: add no new internal nodes
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder call extend_morphism
7b1111ca3b126f71cce47e60ce4b56e6f92422e9Karl Luc Optimizations:
7b1111ca3b126f71cce47e60ce4b56e6f92422e9Karl Luc Union nodes can be extended by a basic spec directly (no new node needed)
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder no new nodes for trivial translations
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Also: free, cofree nodes
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Basic specs: if local env node is otherwise unused, overwrite it with
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder local sig+axioms
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Ensure that just_struct option leads to disabling of various dg operations
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder (show sig, show mor, proving)
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder local: better error message for the following
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maederspec GenCardinality [sort Subject,Object;
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder pred predicate : Subject * Object] =
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Set [sort Object fit sort Elem |-> Object]
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder reveal Set[Object], #__, __eps__,
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Nat,0,1,2,3,4,5,6,7,8,9,__@@__,__>=__,__<=__
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder op toSet : Subject -> Set [Object]
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder forall x : Subject; y : Object
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder . predicate (x,y) <=> y eps toSet(x)
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder pred minCardinality(s: Subject;n: Nat) <=>
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder # toSet(s) >= n;
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder maxCardinality(s: Subject;n: Nat) <=>
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder # toSet(s) <= n;
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder cardinality(s: Subject;n: Nat) <=>
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder # toSet(s) = n
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder%%} hide Pos,toSet,Set[Object],#__,__eps__,__<=__,__>=__
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maedermodule Static.AnalysisStructured (ana_SPEC, ana_GENERICITY, ana_VIEW_TYPE, ana_err)
e9e5281899ddaec4778ad14c64800975377630ecChristian Maederimport Common.Lib.Graph hiding (empty)
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksaimport qualified Common.Lib.Set as Set
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maederimport qualified Common.Lib.Map as Map
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maederimport Data.List hiding (union)
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksaimport Common.Lib.Parsec.Pos -- for testing purposes
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa-- | analyze a SPEC
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa-- Parameters: global context, local environment,
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa-- the SIMPLE_ID may be a name if the specification shall be named,
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa-- flag: shall only the structure be analysed?
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksaana_SPEC :: LogicGraph -> GlobalContext -> NodeSig -> Maybe SIMPLE_ID ->
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa Bool -> SPEC -> Result (SPEC,NodeSig,DGraph)
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksaana_SPEC lg gctx@(gannos,genv,dg) nsig name just_struct sp =
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa Basic_spec (G_basic_spec lid bspec) ->
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa do G_sign lid' sigma' <- return (getSig nsig)
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa sigma <- rcoerce lid' lid (newPos "a" 0 0) sigma'
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa (bspec',sigma_local, sigma_complete, ax) <-
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa if just_struct
7b1111ca3b126f71cce47e60ce4b56e6f92422e9Karl Luc then return (bspec,empty_signature lid, empty_signature lid,[])
7b1111ca3b126f71cce47e60ce4b56e6f92422e9Karl Luc else do b <- maybeToResult (newPos "b" 0 0)
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa ("no basic analysis for logic "
7b1111ca3b126f71cce47e60ce4b56e6f92422e9Karl Luc ++language_name lid)
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa (basic_analysis lid)
7b1111ca3b126f71cce47e60ce4b56e6f92422e9Karl Luc b (bspec,sigma,gannos)
7b1111ca3b126f71cce47e60ce4b56e6f92422e9Karl Luc incl <- ginclusion lg
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa (G_sign lid sigma) (G_sign lid sigma_complete)
7b1111ca3b126f71cce47e60ce4b56e6f92422e9Karl Luc let node_contents = DGNode {
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa dgn_name = name,
7b1111ca3b126f71cce47e60ce4b56e6f92422e9Karl Luc dgn_sign = G_sign lid sigma_complete, -- no, not only the delta
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa dgn_sens = G_l_sentence_list lid ax,
7b1111ca3b126f71cce47e60ce4b56e6f92422e9Karl Luc dgn_origin = DGBasic }
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa [node] = newNodes 0 dg
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa dg' = insNode (node,node_contents) dg
7b1111ca3b126f71cce47e60ce4b56e6f92422e9Karl Luc link = DGLink {
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa dgl_morphism = incl,
2c10bceb28a74fc291959697e023f22a66753655Eugen Kuksa dgl_type = GlobalDef,
7b1111ca3b126f71cce47e60ce4b56e6f92422e9Karl Luc dgl_origin = DGExtension }
7b1111ca3b126f71cce47e60ce4b56e6f92422e9Karl Luc dg'' = case nsig of
7b1111ca3b126f71cce47e60ce4b56e6f92422e9Karl Luc EmptyNode _ -> dg'
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder NodeSig (n,_) -> insEdge (n,node,link) dg'
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder return (Basic_spec (G_basic_spec lid bspec'),
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder NodeSig (node,G_sign lid sigma_complete),
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder Translation asp ren ->
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder do let sp1 = item asp
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder (sp1',nsig',dg') <- ana_SPEC lg gctx nsig Nothing just_struct sp1
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder n' <- maybeToResult (newPos "c" 0 0)
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder "Internal error: Translation of empty spec" (getNode nsig')
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder let gsigma = getSig nsig'
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder mor <- ana_RENAMING dg gsigma just_struct ren
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder -- ??? check that mor is identity on local env
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder let gsigma' = cod Grothendieck mor
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder -- ??? too simplistic for non-comorphism inter-logic translations
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder G_sign lid' _ <- return gsigma'
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder let node_contents = DGNode {
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder dgn_name = name,
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder dgn_sign = gsigma',
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder dgn_sens = G_l_sentence_list lid' [],
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder dgn_origin = DGTranslation }
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder [node] = newNodes 0 dg'
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder link = (n',node,DGLink {
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder dgl_morphism = mor,
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder dgl_type = GlobalDef,
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder dgl_origin = DGTranslation })
5096f518ac5380a0834a09b22a8b38fabe247bf5Christian Maeder return (Translation (replaceAnnoted sp1' asp) ren,
(sys1 `Set.difference` sys) sigma2
case Map.lookup spname genv of
dgl_morphism = error "AnalysisStructured.hs:5", -- ??? inclusion
let sys' = Set.filter (\sy -> any (\rsy -> matches lid1 sy rsy) rsys)
mor1 <- generated_sign lid' (sys1 `Set.union` sys'') sigma'
{- if Set.all (\sy -> lookupFM symmap_mor sy == Just sy) symI
case Map.lookup vn genv of
idComponents :: Id -> Set.Set Id -> [Id]
$ map (\id1 -> if id1 `Set.member` ids
Set.image (\id -> (id,idComponents id ids)) ids
case Map.lookup id idmap of
Just ids -> case Set.size ids of
1 -> return $ Set.findMin ids
else return (Map.insert id (Id toks compsnew pos1) m1)
idsB = Set.image (sym_name lid) symsB
idh = Map.foldWithKey
(\sy1 sy2 -> Map.setInsert (sym_name lid sy1) (sym_name lid sy2))
let rIdExt = Map.foldWithKey
(\id1 id2 -> Map.insert (id_to_raw lid id1) (id_to_raw lid id2))
r = rh `Map.union` rIdExt
let illShared = (sym_of lid sigmaA `Set.intersection` sym_of lid sigmaAD )
Set.\\ Map.image h symsP
when (not (Set.isEmpty illShared))
when (not (Set.isEmpty newIdentifications))