AnalysisStructured.hs revision 58b671de3fe578346fef9642ffa3c5a0a0edb3cb
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder Module : $Header$
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian Maeder Copyright : (c) Till Mossakowski and Uni Bremen 2003
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder Licence : similar to LGPL, see HetCATS/LICENCE.txt or LIZENZ.txt
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder Maintainer : hets@tzi.de
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder Stability : provisional
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder Portability : portable
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder Analysis of structured specifications
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder Follows the extended static semantic rules in:
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder T. Mossakowski, S. Autexier, D. Hutter, P. Hoffman:
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder CASL Proof calculus.
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder Available from <http://www.informatik.uni-bremen.de/~till/calculus.ps>
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder To appear in the CASL book.
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder Combine signature fragments into whole signatures
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder Name views in devgraphs?
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder Check that translations and reductions do not effect local env
33a5d53a412ba0a4e5847f7538d6da2e22bd116cChristian Maeder Unions (already in the parser) need unions of logics
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder = suprema in the lattice of default logic inclusions!
e774ab5733a1d673b123b0e63b14dd533e6fd4fcChristian Maeder (also needed by closed specs)
6e39bfd041946fce4982ac89834be73fd1bfb39aChristian Maeder Should we use institution independent analysis over the Grothendieck logic?
6e39bfd041946fce4982ac89834be73fd1bfb39aChristian Maeder abstract syntax + devgraph would have to be changed to homogeneous case
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder logic translations are symbol maps in the Grothendieck logic
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder Problem with this approach: symbol functor goes into rel,
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder and induced_from_morphism gets difficult to implement
6e39bfd041946fce4982ac89834be73fd1bfb39aChristian Maeder Unions need inclusion morphisms. Should these play a special role?
6e39bfd041946fce4982ac89834be73fd1bfb39aChristian Maeder At least we need a function delivering the inclusion morphism
6e39bfd041946fce4982ac89834be73fd1bfb39aChristian Maeder between two (sub)signatures.
6e39bfd041946fce4982ac89834be73fd1bfb39aChristian Maeder In most logics, inclusions could be represented specially, such
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder that composition for them becomes fast.
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder Should we even identify an inclusion subcategory?
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder Then inclusions are represented by pair of signatures
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder (Non-inclusions could be specially displayed in the DG)
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder Treatment of translations and reductions along logic translations
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder (see WADT 02 paper).
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder Open question:
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder may local env be translated, and even reduced, along logic translations?
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder if yes: how is local env linked to signature of resulting spec?
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder (important e.g. for checking that local env is not being renamed?)
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder does signature+comorphism suffice, such that c(local env)\subseteq sig?
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder if no: this means that only closed specs may be translated
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder Revealings without translations: just one arrow
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder Pushouts: only admissible within one logic?
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder Instantiations with formal parameter: add no new internal nodes
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder call extend_morphism
ebcaad207cafc89eeb49d431f40de2ef4c48411cChristian Maeder Optimizations:
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder Union nodes can be extended by a basic spec directly (no new node needed)
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder no new nodes for trivial translations
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder Also: free, cofree nodes
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder Basic specs: if local env node is otherwise unused, overwrite it with
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder local sig+axioms
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder Ensure that just_struct option leads to disabling of various dg operations
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder (show sig, show mor, proving)
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maedermodule Static.AnalysisStructured (ana_SPEC, ana_GENERICITY, ana_VIEW_TYPE, ana_err)
ccf3de3d66b521a260e5c22d335c64a48e3f0195Christian Maederimport Common.Lib.Graph hiding (empty)
2a598ff0c1b7b51c33aee7029b43bc5cfcbea6b8Christian Maederimport qualified Common.Lib.Set as Set
2a598ff0c1b7b51c33aee7029b43bc5cfcbea6b8Christian Maederimport qualified Common.Lib.Map as Map
2a598ff0c1b7b51c33aee7029b43bc5cfcbea6b8Christian Maederimport Data.List hiding (union)
2a598ff0c1b7b51c33aee7029b43bc5cfcbea6b8Christian Maederimport Common.Lib.Parsec.Pos -- for testing purposes
6e39bfd041946fce4982ac89834be73fd1bfb39aChristian Maeder-- | analyze a SPEC
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder-- Parameters: global context, local environment,
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder-- the SIMPLE_ID may be a name if the specification shall be named,
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder-- flag: shall only the structure be analysed?
3c62e6ef442caf092adcbecf6fccd957dcd72689Christian Maederana_SPEC :: LogicGraph -> GlobalContext -> NodeSig -> Maybe SIMPLE_ID ->
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder Bool -> SPEC -> Result (SPEC,NodeSig,DGraph)
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maederana_SPEC lg gctx@(gannos,genv,dg) nsig name just_struct sp =
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder Basic_spec (G_basic_spec lid bspec) ->
62ecb1e7f8fd9573eea8369657de12c7bf9f4f25Christian Maeder do G_sign lid' sigma' <- return (getSig nsig)
6e39bfd041946fce4982ac89834be73fd1bfb39aChristian Maeder sigma <- rcoerce lid' lid (newPos "a" 0 0) sigma'
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder (bspec',sigma_local, sigma_complete, ax) <-
6e39bfd041946fce4982ac89834be73fd1bfb39aChristian Maeder if just_struct
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder then return (bspec,empty_signature lid, empty_signature lid,[])
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder else do b <- maybeToResult (newPos "b" 0 0)
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder ("no basic analysis for logic "
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder ++language_name lid)
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder (basic_analysis lid)
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder b (bspec,sigma,gannos)
836e72a3c413366ba9801726f3b249c7791cb9caChristian Maeder incl <- ginclusion lg
836e72a3c413366ba9801726f3b249c7791cb9caChristian Maeder (G_sign lid sigma) (G_sign lid sigma_complete)
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder let node_contents = DGNode {
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder dgn_name = name,
149e43c4a2705a86a0e5fa301ba849fdf19db32eChristian Maeder dgn_sign = G_sign lid sigma_complete, -- no, not only the delta
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder dgn_sens = G_l_sentence lid ax,
149e43c4a2705a86a0e5fa301ba849fdf19db32eChristian Maeder dgn_origin = DGBasic }
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder [node] = newNodes 0 dg
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder dg' = insNode (node,node_contents) dg
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder link = DGLink {
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder dgl_morphism = incl,
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder dgl_type = GlobalDef,
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder dgl_origin = DGExtension }
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder dg'' = case nsig of
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder EmptyNode _ -> dg'
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder NodeSig (n,_) -> insEdge (n,node,link) dg'
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder return (Basic_spec (G_basic_spec lid bspec'),
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder NodeSig (node,G_sign lid sigma_complete),
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder Translation asp ren ->
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder do let sp1 = item asp
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder (sp1',nsig',dg') <- ana_SPEC lg gctx nsig Nothing just_struct sp1
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder n' <- maybeToResult (newPos "c" 0 0)
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder "Internal error: Translation of empty spec" (getNode nsig')
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder let gsigma = getSig nsig'
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder mor <- ana_RENAMING dg gsigma just_struct ren
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder -- ??? check that mor is identity on local env
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder let gsigma' = cod Grothendieck mor
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder -- ??? too simplistic for non-comorphism inter-logic translations
6e39bfd041946fce4982ac89834be73fd1bfb39aChristian Maeder G_sign lid' _ <- return gsigma'
149e43c4a2705a86a0e5fa301ba849fdf19db32eChristian Maeder let node_contents = DGNode {
149e43c4a2705a86a0e5fa301ba849fdf19db32eChristian Maeder dgn_name = name,
1738d16957389457347bee85075d3d33d002158fChristian Maeder dgn_sign = gsigma',
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder dgn_sens = G_l_sentence lid' [],
6e39bfd041946fce4982ac89834be73fd1bfb39aChristian Maeder dgn_origin = DGTranslation }
33a5d53a412ba0a4e5847f7538d6da2e22bd116cChristian Maeder [node] = newNodes 0 dg'
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder link = (n',node,DGLink {
6e39bfd041946fce4982ac89834be73fd1bfb39aChristian Maeder dgl_morphism = mor,
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder dgl_type = GlobalDef,
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder dgl_origin = DGTranslation })
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder return (Translation (replaceAnnoted sp1' asp) ren,
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder NodeSig(node,gsigma'),
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder insEdge link $
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder insNode (node,node_contents) dg')
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder Reduction asp restr ->
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder do let sp1 = item asp
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder (sp1',nsig',dg') <- ana_SPEC lg gctx nsig Nothing just_struct sp1
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder let gsigma = getSig nsig
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder gsigma' = getSig nsig'
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder n' <- maybeToResult (newPos "d" 0 0)
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder "Internal error: Reduction of empty spec" (getNode nsig')
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder (hmor,tmor) <- ana_RESTRICTION dg gsigma gsigma' just_struct restr
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder -- we treat hiding and revealing differently
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder -- in order to keep the dg as simple as possible
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder do let gsigma'' = dom Grothendieck hmor
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder -- ??? too simplistic for non-comorphism inter-logic reductions
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder G_sign lid' _ <- return gsigma''
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder let node_contents = DGNode {
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder dgn_name = name,
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder dgn_sign = gsigma'', -- G_sign lid' (empty_signature lid'),
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder dgn_sens = G_l_sentence lid' [],
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder dgn_origin = DGHiding }
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder [node] = newNodes 0 dg'
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder link = (n',node,DGLink {
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder dgl_morphism = hmor,
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder dgl_type = HidingDef,
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder dgl_origin = DGHiding })
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder return (Reduction (replaceAnnoted sp1' asp) restr,
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder NodeSig(node,gsigma''),
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder insEdge link $
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder insNode (node,node_contents) dg')
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder Just tmor' ->
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder -- the case with identity translation leads to a simpler dg
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder if tmor' == ide Grothendieck (dom Grothendieck tmor')
(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))