Theory Namespace
chapter ‹Generated by Lem from ‹semantics/namespace.lem›.›
theory "Namespace"
imports
Main
"HOL-Library.Datatype_Records"
"LEM.Lem_pervasives"
"LEM.Lem_set_extra"
begin
type_synonym( 'k, 'v) alist0 =" ('k * 'v) list "
datatype( 'm, 'n) id0 =
Short " 'n "
| Long " 'm " " ('m, 'n) id0 "
fun mk_id :: " 'm list ⇒ 'n ⇒('m,'n)id0 " where
" mk_id [] n = ( Short n )"
|" mk_id (mn # mns) n = ( Long mn (mk_id mns n))"
fun id_to_n :: "('m,'n)id0 ⇒ 'n " where
" id_to_n (Short n) = ( n )"
|" id_to_n (Long _ id1) = ( id_to_n id1 )"
fun id_to_mods :: "('m,'n)id0 ⇒ 'm list " where
" id_to_mods (Short _) = ( [])"
|" id_to_mods (Long mn id1) = ( mn # id_to_mods id1 )"
datatype( 'm, 'n, 'v) namespace =
Bind " ('n, 'v) alist0 " " ('m, ( ('m, 'n, 'v)namespace)) alist0 "
fun nsLookup :: "('m,'n,'v)namespace ⇒('m,'n)id0 ⇒ 'v option " where
" nsLookup (Bind v2 m) (Short n) = ( Map.map_of v2 n )"
|" nsLookup (Bind v2 m) (Long mn id1) = (
(case Map.map_of m mn of
None => None
| Some env => nsLookup env id1
))"
fun nsLookupMod :: "('m,'n,'v)namespace ⇒ 'm list ⇒(('m,'n,'v)namespace)option " where
" nsLookupMod e [] = ( Some e )"
|" nsLookupMod (Bind v2 m) (mn # path) = (
(case Map.map_of m mn of
None => None
| Some env => nsLookupMod env path
))"
definition nsEmpty :: "('m,'n,'v)namespace " where
" nsEmpty = ( Bind [] [])"
fun nsAppend :: "('m,'n,'v)namespace ⇒('m,'n,'v)namespace ⇒('m,'n,'v)namespace " where
" nsAppend (Bind v1 m1) (Bind v2 m2) = ( Bind (v1 @ v2) (m1 @ m2))"
definition nsLift :: " 'm ⇒('m,'n,'v)namespace ⇒('m,'n,'v)namespace " where
" nsLift mn env = ( Bind [] [(mn, env)])"
definition alist_to_ns :: "('n*'v)list ⇒('m,'n,'v)namespace " where
" alist_to_ns a = ( Bind a [])"
fun nsBind :: " 'n ⇒ 'v ⇒('m,'n,'v)namespace ⇒('m,'n,'v)namespace " where
" nsBind k x (Bind v2 m) = ( Bind ((k,x)# v2) m )"
definition nsBindList :: "('n*'v)list ⇒('m,'n,'v)namespace ⇒('m,'n,'v)namespace " where
" nsBindList l e = ( List.foldr ( λx .
(case x of (x,v2) => λ e . nsBind x v2 e )) l e )"
fun nsOptBind :: " 'n option ⇒ 'v ⇒('m,'n,'v)namespace ⇒('m,'n,'v)namespace " where
" nsOptBind None x env = ( env )"
|" nsOptBind (Some n') x env = ( nsBind n' x env )"
definition nsSing :: " 'n ⇒ 'v ⇒('m,'n,'v)namespace " where
" nsSing n x = ( Bind ([(n,x)]) [])"
definition nsSub :: "(('m,'n)id0 ⇒ 'v1 ⇒ 'v2 ⇒ bool)⇒('m,'n,'v1)namespace ⇒('m,'n,'v2)namespace ⇒ bool " where
" nsSub r env1 env2 = (
((∀ id0. ∀ v1.
(nsLookup env1 id0 = Some v1)
⟶
((∃ v2. (nsLookup env2 id0 = Some v2) ∧ r id0 v1 v2))))
∧
((∀ path.
(nsLookupMod env2 path = None) ⟶ (nsLookupMod env1 path = None))))"
fun nsAll :: "(('m,'n)id0 ⇒ 'v ⇒ bool)⇒('m,'n,'v)namespace ⇒ bool " where
" nsAll f env = (
((∀ id0. ∀ v1.
(nsLookup env id0 = Some v1)
⟶
f id0 v1)))"
definition nsAll2 :: "(('d,'c)id0 ⇒ 'b ⇒ 'a ⇒ bool)⇒('d,'c,'b)namespace ⇒('d,'c,'a)namespace ⇒ bool " where
" nsAll2 r env1 env2 = (
nsSub r env1 env2 ∧
nsSub (λ x y z . r x z y) env2 env1 )"
definition nsDom :: "('m,'n,'v)namespace ⇒(('m,'n)id0)set " where
" nsDom env = ( (let x2 =
({}) in Finite_Set.fold
(λv2 x2 . Finite_Set.fold
(λn x2 .
if nsLookup env n = Some v2 then Set.insert n x2
else x2) x2 UNIV) x2 UNIV))"
definition nsDomMod :: "('m,'n,'v)namespace ⇒('m list)set " where
" nsDomMod env = ( (let x2 =
({}) in Finite_Set.fold
(λv2 x2 . Finite_Set.fold
(λn x2 .
if nsLookupMod env n = Some v2 then Set.insert n x2
else x2) x2 UNIV) x2 UNIV))"
function (sequential,domintros) nsMap :: "('v ⇒ 'w)⇒('m,'n,'v)namespace ⇒('m,'n,'w)namespace " where
" nsMap f (Bind v2 m) = (
Bind (List.map ( λx .
(case x of (n,x) => (n, f x) )) v2)
(List.map ( λx .
(case x of (mn,e) => (mn, nsMap f e) )) m))"
by pat_completeness auto
end