Theory Design_generated

theory Design_generated imports "../Toy_Library"   "../Toy_Library_Static"   "../embedding/Generator_dynamic_sequential" begin

(* 1 ************************************ 0 + 1 *)
text ‹
  For certain concepts like classes and class-types, only a generic
  definition for its resulting semantics can be given. Generic means,
  there is a function outside HOL that ``compiles'' a concrete,
  closed-world class diagram into a ``theory'' of this data model,
  consisting of a bunch of definitions for classes, accessors, method,
  casts, and tests for actual types, as well as proofs for the
  fundamental properties of these operations in this concrete data
  model. ›

(* 2 ************************************ 1 + 1 *)
text ‹
   Our data universe  consists in the concrete class diagram just of node's,
and implicitly of the class object. Each class implies the existence of a class
type defined for the corresponding object representations as follows: ›

(* 3 ************************************ 2 + 10 *)
datatype tyℰ𝒳𝒯Atom = mkℰ𝒳𝒯Atom "oid" "oid list option" "int option" "bool option" "nat option" "unit option"
datatype tyAtom = mkAtom "tyℰ𝒳𝒯Atom" "int option"
datatype tyℰ𝒳𝒯Molecule = mkℰ𝒳𝒯Molecule_Atom "tyAtom"
                        | mkℰ𝒳𝒯Molecule "oid" "oid list option" "int option" "bool option" "nat option" "unit option"
datatype tyMolecule = mkMolecule "tyℰ𝒳𝒯Molecule"
datatype tyℰ𝒳𝒯Person = mkℰ𝒳𝒯Person_Molecule "tyMolecule"
                        | mkℰ𝒳𝒯Person_Atom "tyAtom"
                        | mkℰ𝒳𝒯Person "oid" "nat option" "unit option"
datatype tyPerson = mkPerson "tyℰ𝒳𝒯Person" "oid list option" "int option" "bool option"
datatype tyℰ𝒳𝒯Galaxy = mkℰ𝒳𝒯Galaxy_Person "tyPerson"
                        | mkℰ𝒳𝒯Galaxy_Molecule "tyMolecule"
                        | mkℰ𝒳𝒯Galaxy_Atom "tyAtom"
                        | mkℰ𝒳𝒯Galaxy "oid"
datatype tyGalaxy = mkGalaxy "tyℰ𝒳𝒯Galaxy" "nat option" "unit option"
datatype tyℰ𝒳𝒯ToyAny = mkℰ𝒳𝒯ToyAny_Galaxy "tyGalaxy"
                        | mkℰ𝒳𝒯ToyAny_Person "tyPerson"
                        | mkℰ𝒳𝒯ToyAny_Molecule "tyMolecule"
                        | mkℰ𝒳𝒯ToyAny_Atom "tyAtom"
                        | mkℰ𝒳𝒯ToyAny "oid"
datatype tyToyAny = mkToyAny "tyℰ𝒳𝒯ToyAny"

(* 4 ************************************ 12 + 1 *)
text ‹
   Now, we construct a concrete ``universe of ToyAny types'' by injection into a
sum type containing the class types. This type of ToyAny will be used as instance
for all respective type-variables. ›

(* 5 ************************************ 13 + 1 *)
datatype 𝔄 = inAtom "tyAtom"
                        | inMolecule "tyMolecule"
                        | inPerson "tyPerson"
                        | inGalaxy "tyGalaxy"
                        | inToyAny "tyToyAny"

(* 6 ************************************ 14 + 1 *)
text ‹
   Having fixed the object universe, we can introduce type synonyms that exactly correspond
to Toy types. Again, we exploit that our representation of Toy is a ``shallow embedding'' with a
one-to-one correspondance of Toy-types to types of the meta-language HOL. ›

(* 7 ************************************ 15 + 5 *)
type_synonym Atom = "tyAtom"
type_synonym Molecule = "tyMolecule"
type_synonym Person = "tyPerson"
type_synonym Galaxy = "tyGalaxy"
type_synonym ToyAny = "tyToyAny"

(* 8 ************************************ 20 + 3 *)
definition "oidAtom_0___boss = 0"
definition "oidMolecule_0___boss = 0"
definition "oidPerson_0___boss = 0"

(* 9 ************************************ 23 + 2 *)
definition "switch2_01 = (λ [x0 , x1]  (x0 , x1))"
definition "switch2_10 = (λ [x0 , x1]  (x1 , x0))"

(* 10 ************************************ 25 + 3 *)
definition "oid1 = 1"
definition "oid2 = 2"
definition "inst_assoc1 = (λoid_class to_from oid. ((case (deref_assocs_list ((to_from::oid list list  oid list × oid list)) ((oid::oid)) ((drop ((((map_of_list ([(oidPerson_0___boss , (List.map ((λ(x , y). [x , y]) o switch2_01) ([[[oid1] , [oid2]]])))]))) ((oid_class::oid))))))) of Nil  None
    | l  (Some (l)))::oid list option))"

(* 11 ************************************ 28 + 0 *)

(* 12 ************************************ 28 + 2 *)
definition "oid3 = 3"
definition "inst_assoc3 = (λoid_class to_from oid. ((case (deref_assocs_list ((to_from::oid list list  oid list × oid list)) ((oid::oid)) ((drop ((((map_of_list ([]))) ((oid_class::oid))))))) of Nil  None
    | l  (Some (l)))::oid list option))"

(* 13 ************************************ 30 + 0 *)

(* 14 ************************************ 30 + 4 *)
generation_syntax [ shallow (generation_semantics [ design ]) ]
setup (Generation_mode.update_compiler_config ((K (let open META in Compiler_env_config_ext (true, NONE, Oids ((Code_Numeral.natural_of_integer 0), (Code_Numeral.natural_of_integer 1), (Code_Numeral.natural_of_integer 4)), I ((Code_Numeral.natural_of_integer 0), (Code_Numeral.natural_of_integer 0)), Gen_only_design, SOME (ToyClass ((META.SS_base (META.ST "ToyAny")), nil, uncurry cons (ToyClass ((META.SS_base (META.ST "Galaxy")), uncurry cons (I ((META.SS_base (META.ST "wormhole")), ToyTy_base_unlimitednatural), uncurry cons (I ((META.SS_base (META.ST "is_sound")), ToyTy_base_void), nil)), uncurry cons (ToyClass ((META.SS_base (META.ST "Person")), uncurry cons (I ((META.SS_base (META.ST "boss")), ToyTy_object (ToyTyObj (ToyTyCore (Toy_ty_class_ext ((META.SS_base (META.ST "oid")), (Code_Numeral.natural_of_integer 0), (Code_Numeral.natural_of_integer 2), Toy_ty_class_node_ext ((Code_Numeral.natural_of_integer 0), Toy_multiplicity_ext (uncurry cons (I (Mult_star, NONE), nil), NONE, uncurry cons (Set, nil), ()), (META.SS_base (META.ST "Person")), ()), Toy_ty_class_node_ext ((Code_Numeral.natural_of_integer 1), Toy_multiplicity_ext (uncurry cons (I (Mult_nat ((Code_Numeral.natural_of_integer 0)), SOME (Mult_nat ((Code_Numeral.natural_of_integer 1)))), nil), SOME ((META.SS_base (META.ST "boss"))), uncurry cons (Set, nil), ()), (META.SS_base (META.ST "Person")), ()), ())), nil))), uncurry cons (I ((META.SS_base (META.ST "salary")), ToyTy_base_integer), uncurry cons (I ((META.SS_base (META.ST "is_meta_thinking")), ToyTy_base_boolean), nil))), uncurry cons (ToyClass ((META.SS_base (META.ST "Molecule")), nil, uncurry cons (ToyClass ((META.SS_base (META.ST "Atom")), uncurry cons (I ((META.SS_base (META.ST "size")), ToyTy_base_integer), nil), nil), nil)), nil)), nil)), nil))), uncurry cons (META_instance (ToyInstance (uncurry cons (Toy_instance_single_ext (SOME ((META.SS_base (META.ST "XPerson3"))), SOME ((META.SS_base (META.ST "Person"))), ToyAttrNoCast (uncurry cons (I (NONE, I ((META.SS_base (META.ST "salary")), ShallB_term (ToyDefInteger ((META.SS_base (META.ST "1")))))), nil)), ()), nil))), uncurry cons (META_instance (ToyInstance (uncurry cons (Toy_instance_single_ext (SOME ((META.SS_base (META.ST "XPerson1"))), SOME ((META.SS_base (META.ST "Person"))), ToyAttrNoCast (uncurry cons (I (NONE, I ((META.SS_base (META.ST "salary")), ShallB_term (ToyDefInteger ((META.SS_base (META.ST "1300")))))), uncurry cons (I (NONE, I ((META.SS_base (META.ST "boss")), ShallB_str ((META.SS_base (META.ST "XPerson2"))))), nil))), ()), uncurry cons (Toy_instance_single_ext (SOME ((META.SS_base (META.ST "XPerson2"))), SOME ((META.SS_base (META.ST "Person"))), ToyAttrNoCast (uncurry cons (I (NONE, I ((META.SS_base (META.ST "salary")), ShallB_term (ToyDefInteger ((META.SS_base (META.ST "1800")))))), nil)), ()), nil)))), uncurry cons (META_class_raw (Floor1, Toy_class_raw_ext (ToyTyObj (ToyTyCore_pre ((META.SS_base (META.ST "Person"))), uncurry cons (uncurry cons (ToyTyCore_pre ((META.SS_base (META.ST "Galaxy"))), nil), nil)), uncurry cons (I ((META.SS_base (META.ST "salary")), ToyTy_base_integer), uncurry cons (I ((META.SS_base (META.ST "boss")), ToyTy_object (ToyTyObj (ToyTyCore_pre ((META.SS_base (META.ST "Person"))), nil))), uncurry cons (I ((META.SS_base (META.ST "is_meta_thinking")), ToyTy_base_boolean), nil))), nil, false, ())), uncurry cons (META_class_raw (Floor1, Toy_class_raw_ext (ToyTyObj (ToyTyCore_pre ((META.SS_base (META.ST "Galaxy"))), nil), uncurry cons (I ((META.SS_base (META.ST "wormhole")), ToyTy_base_unlimitednatural), uncurry cons (I ((META.SS_base (META.ST "is_sound")), ToyTy_base_void), nil)), nil, false, ())), uncurry cons (META_class_raw (Floor1, Toy_class_raw_ext (ToyTyObj (ToyTyCore_pre ((META.SS_base (META.ST "Molecule"))), uncurry cons (uncurry cons (ToyTyCore_pre ((META.SS_base (META.ST "Person"))), nil), nil)), nil, nil, false, ())), uncurry cons (META_class_raw (Floor1, Toy_class_raw_ext (ToyTyObj (ToyTyCore_pre ((META.SS_base (META.ST "Atom"))), uncurry cons (uncurry cons (ToyTyCore_pre ((META.SS_base (META.ST "Molecule"))), nil), nil)), uncurry cons (I ((META.SS_base (META.ST "size")), ToyTy_base_integer), nil), nil, false, ())), nil)))))), uncurry cons (I ((META.ST "XPerson3"), I (Toy_instance_single_ext (SOME ((META.SS_base (META.ST "XPerson3"))), SOME ((META.SS_base (META.ST "Person"))), ToyAttrNoCast (uncurry cons (I (NONE, I ((META.SS_base (META.ST "salary")), ShallB_term (ToyDefInteger ((META.SS_base (META.ST "1")))))), nil)), ()), Oids ((Code_Numeral.natural_of_integer 0), (Code_Numeral.natural_of_integer 1), (Code_Numeral.natural_of_integer 3)))), uncurry cons (I ((META.ST "XPerson2"), I (Toy_instance_single_ext (SOME ((META.SS_base (META.ST "XPerson2"))), SOME ((META.SS_base (META.ST "Person"))), ToyAttrNoCast (uncurry cons (I (NONE, I ((META.SS_base (META.ST "salary")), ShallB_term (ToyDefInteger ((META.SS_base (META.ST "1800")))))), nil)), ()), Oids ((Code_Numeral.natural_of_integer 0), (Code_Numeral.natural_of_integer 1), (Code_Numeral.natural_of_integer 2)))), uncurry cons (I ((META.ST "XPerson1"), I (Toy_instance_single_ext (SOME ((META.SS_base (META.ST "XPerson1"))), SOME ((META.SS_base (META.ST "Person"))), ToyAttrNoCast (uncurry cons (I (NONE, I ((META.SS_base (META.ST "salary")), ShallB_term (ToyDefInteger ((META.SS_base (META.ST "1300")))))), uncurry cons (I (NONE, I ((META.SS_base (META.ST "boss")), ShallB_str ((META.SS_base (META.ST "XPerson2"))))), nil))), ()), Oids ((Code_Numeral.natural_of_integer 0), (Code_Numeral.natural_of_integer 1), (Code_Numeral.natural_of_integer 1)))), nil))), nil, false, false, I (nil, nil), nil, I (NONE, false), ()) end))))
Instance σ1_object0 :: Person = [ "salary" = 1000, "boss" = self 1 ]
     and σ1_object1 :: Person = [ "salary" = 1200 ]
     and σ1_object2 :: Person = [ "salary" = 2600, "boss" = XPerson1 ]
     and σ1_object4 :: Person = [ "salary" = 2300, "boss" = self 2 ]
(* Fails because of modified map update syntax priorities
State[shallow] σ1 = [ σ1_object0, σ1_object1, σ1_object2, XPerson1, σ1_object4, XPerson2 ]

(* 15 ************************************ 34 + 1 *)
State[shallow] σ1' = [ XPerson1, XPerson2, XPerson3 ]

(* 16 ************************************ 35 + 1 *)
PrePost[shallow] σ1 σ1'
*)
end