src/HOL/UNITY/Extend.ML
changeset 8251 9be357df93d4
parent 8216 e4b3192dfefa
child 8948 b797cfa3548d
equal deleted inserted replaced
8250:f4029c34adef 8251:9be357df93d4
     7   function f (forget)    maps the extended state to the original state
     7   function f (forget)    maps the extended state to the original state
     8   function g (forgotten) maps the extended state to the "extending part"
     8   function g (forgotten) maps the extended state to the "extending part"
     9 *)
     9 *)
    10 
    10 
    11 (** These we prove OUTSIDE the locale. **)
    11 (** These we prove OUTSIDE the locale. **)
       
    12 
       
    13 Goal "f Id = Id ==> insert Id (f``Acts F) = f `` Acts F";
       
    14 by (blast_tac (claset() addIs [sym RS image_eqI]) 1);
       
    15 qed "insert_Id_image_Acts";
    12 
    16 
    13 (*Possibly easier than reasoning about "inv h"*)
    17 (*Possibly easier than reasoning about "inv h"*)
    14 val [surj_h,prem] = 
    18 val [surj_h,prem] = 
    15 Goalw [good_map_def]
    19 Goalw [good_map_def]
    16      "[| surj h; !! x x' y y'. h(x,y) = h(x',y') ==> x=x' |] ==> good_map h";
    20      "[| surj h; !! x x' y y'. h(x,y) = h(x',y') ==> x=x' |] ==> good_map h";
   113 Goalw [extend_set_def] "(extend_set h A <= extend_set h B) = (A <= B)";
   117 Goalw [extend_set_def] "(extend_set h A <= extend_set h B) = (A <= B)";
   114 by (Force_tac 1);
   118 by (Force_tac 1);
   115 qed "extend_set_strict_mono";
   119 qed "extend_set_strict_mono";
   116 AddIffs [extend_set_strict_mono];
   120 AddIffs [extend_set_strict_mono];
   117 
   121 
   118 Goal "{s. P (f s)} = extend_set h {s. P s}";
   122 Goalw [extend_set_def] "extend_set h {} = {}";
   119 by Auto_tac;
   123 by Auto_tac;
   120 qed "Collect_eq_extend_set";
   124 qed "extend_set_empty";
       
   125 Addsimps [extend_set_empty];
       
   126 
       
   127 Goal "extend_set h {s. P s} = {s. P (f s)}";
       
   128 by Auto_tac;
       
   129 qed "extend_set_eq_Collect";
   121 
   130 
   122 Goal "extend_set h {x} = {s. f s = x}";
   131 Goal "extend_set h {x} = {s. f s = x}";
   123 by Auto_tac;
   132 by Auto_tac;
   124 qed "extend_set_sing";
   133 qed "extend_set_sing";
   125 
   134 
   126 Goalw [extend_set_def]
   135 Goalw [extend_set_def] "project_set h (extend_set h C) = C";
   127      "project_set h (extend_set h C) = C";
       
   128 by Auto_tac;
   136 by Auto_tac;
   129 qed "extend_set_inverse";
   137 qed "extend_set_inverse";
   130 Addsimps [extend_set_inverse];
   138 Addsimps [extend_set_inverse];
   131 
   139 
   132 Goalw [extend_set_def]
   140 Goalw [extend_set_def] "C <= extend_set h (project_set h C)";
   133      "C <= extend_set h (project_set h C)";
       
   134 by (auto_tac (claset(), 
   141 by (auto_tac (claset(), 
   135 	      simpset() addsimps [split_extended_all]));
   142 	      simpset() addsimps [split_extended_all]));
   136 by (Blast_tac 1);
   143 by (Blast_tac 1);
   137 qed "extend_set_project_set";
   144 qed "extend_set_project_set";
   138 
   145 
   275      "!!z z'. (z, z') : act ==> (f z, f z') : project_act h act";
   282      "!!z z'. (z, z') : act ==> (f z, f z') : project_act h act";
   276 by (force_tac (claset(), 
   283 by (force_tac (claset(), 
   277               simpset() addsimps [split_extended_all]) 1);
   284               simpset() addsimps [split_extended_all]) 1);
   278 qed "project_act_I";
   285 qed "project_act_I";
   279 
   286 
   280 Goalw [project_act_def]
   287 Goalw [project_act_def] "project_act h Id = Id";
   281     "UNIV <= project_set h C ==> project_act h (Restrict C Id) = Id";
       
   282 by (Force_tac 1);
   288 by (Force_tac 1);
   283 qed "project_act_Id";
   289 qed "project_act_Id";
   284 
   290 
   285 Goalw [project_act_def]
   291 Goalw [project_act_def]
   286   "Domain (project_act h act) = project_set h (Domain act)";
   292   "Domain (project_act h act) = project_set h (Domain act)";
   287 by (force_tac (claset(), 
   293 by (force_tac (claset(), 
   288               simpset() addsimps [split_extended_all]) 1);
   294               simpset() addsimps [split_extended_all]) 1);
   289 qed "Domain_project_act";
   295 qed "Domain_project_act";
   290 
   296 
   291 Addsimps [extend_act_Id, project_act_Id];
   297 Addsimps [extend_act_Id];
   292 
       
   293 Goal "(extend_act h act = Id) = (act = Id)";
       
   294 by Auto_tac;
       
   295 by (rewtac extend_act_def);
       
   296 by (ALLGOALS (blast_tac (claset() addEs [equalityE])));
       
   297 qed "extend_act_Id_iff";
       
   298 
       
   299 Goal "Id : extend_act h `` Acts F";
       
   300 by (auto_tac (claset() addSIs [extend_act_Id RS sym], 
       
   301 	      simpset() addsimps [image_iff]));
       
   302 qed "Id_mem_extend_act";
       
   303 
   298 
   304 
   299 
   305 (**** extend ****)
   300 (**** extend ****)
   306 
   301 
   307 (*** Basic properties ***)
   302 (*** Basic properties ***)
   313 Goalw [project_def] "Init (project h C F) = project_set h (Init F)";
   308 Goalw [project_def] "Init (project h C F) = project_set h (Init F)";
   314 by Auto_tac;
   309 by Auto_tac;
   315 qed "Init_project";
   310 qed "Init_project";
   316 
   311 
   317 Goal "Acts (extend h F) = (extend_act h `` Acts F)";
   312 Goal "Acts (extend h F) = (extend_act h `` Acts F)";
   318 by (auto_tac (claset() addSIs [extend_act_Id RS sym], 
   313 by (simp_tac (simpset() addsimps [extend_def, insert_Id_image_Acts]) 1);
   319 	      simpset() addsimps [extend_def, image_iff]));
       
   320 qed "Acts_extend";
   314 qed "Acts_extend";
   321 
   315 
   322 Goal "Acts (project h C F) = insert Id (project_act h `` Restrict C `` Acts F)";
   316 Goal "Acts(project h C F) = insert Id (project_act h `` Restrict C `` Acts F)";
   323 by (auto_tac (claset(), 
   317 by (auto_tac (claset(), 
   324 	      simpset() addsimps [project_def, image_iff]));
   318 	      simpset() addsimps [project_def, image_iff]));
   325 qed "Acts_project";
   319 qed "Acts_project";
   326 
   320 
   327 Addsimps [Init_extend, Init_project, Acts_extend, Acts_project];
   321 Addsimps [Init_extend, Init_project, Acts_extend, Acts_project];
   338 Addsimps [project_set_UNIV];
   332 Addsimps [project_set_UNIV];
   339 
   333 
   340 Goal "project_set h (Union A) = (UN X:A. project_set h X)";
   334 Goal "project_set h (Union A) = (UN X:A. project_set h X)";
   341 by (Blast_tac 1);
   335 by (Blast_tac 1);
   342 qed "project_set_Union";
   336 qed "project_set_Union";
   343 
       
   344 
   337 
   345 Goal "project h C (extend h F) = \
   338 Goal "project h C (extend h F) = \
   346 \     mk_program (Init F, Restrict (project_set h C) `` Acts F)";
   339 \     mk_program (Init F, Restrict (project_set h C) `` Acts F)";
   347 by (rtac program_equalityI 1);
   340 by (rtac program_equalityI 1);
   348 by (asm_simp_tac (simpset() addsimps [image_eq_UN, 
   341 by (asm_simp_tac (simpset() addsimps [image_eq_UN, 
   375 by (rtac program_equalityI 1);
   368 by (rtac program_equalityI 1);
   376 by (simp_tac (simpset() addsimps [image_UN]) 2);
   369 by (simp_tac (simpset() addsimps [image_UN]) 2);
   377 by (simp_tac (simpset() addsimps [extend_set_INT_distrib]) 1);
   370 by (simp_tac (simpset() addsimps [extend_set_INT_distrib]) 1);
   378 qed "extend_JN";
   371 qed "extend_JN";
   379 Addsimps [extend_JN];
   372 Addsimps [extend_JN];
   380 
       
   381 
   373 
   382 (** These monotonicity results look natural but are UNUSED **)
   374 (** These monotonicity results look natural but are UNUSED **)
   383 
   375 
   384 Goal "F <= G ==> extend h F <= extend h G";
   376 Goal "F <= G ==> extend h F <= extend h G";
   385 by (full_simp_tac (simpset() addsimps [component_eq_subset]) 1);
   377 by (full_simp_tac (simpset() addsimps [component_eq_subset]) 1);
   458 Goal "(extend h F : Always (extend_set h A)) = (F : Always A)";
   450 Goal "(extend h F : Always (extend_set h A)) = (F : Always A)";
   459 by (asm_simp_tac (simpset() addsimps [Always_def, extend_Stable]) 1);
   451 by (asm_simp_tac (simpset() addsimps [Always_def, extend_Stable]) 1);
   460 qed "extend_Always";
   452 qed "extend_Always";
   461 
   453 
   462 
   454 
   463 (** Further lemmas **)
   455 (** Safety and "project" **)
       
   456 
       
   457 (** projection: monotonicity for safety **)
       
   458 
       
   459 Goal "D <= C ==> \
       
   460 \     project_act h (Restrict D act) <= project_act h (Restrict C act)";
       
   461 by (auto_tac (claset(), simpset() addsimps [project_act_def]));
       
   462 qed "project_act_mono";
       
   463 
       
   464 Goal "[| D <= C; project h C F : A co B |] ==> project h D F : A co B";
       
   465 by (auto_tac (claset(), simpset() addsimps [constrains_def]));
       
   466 by (dtac project_act_mono 1);
       
   467 by (Blast_tac 1);
       
   468 qed "project_constrains_mono";
       
   469 
       
   470 Goal "[| D <= C;  project h C F : stable A |] ==> project h D F : stable A";
       
   471 by (asm_full_simp_tac
       
   472     (simpset() addsimps [stable_def, project_constrains_mono]) 1);
       
   473 qed "project_stable_mono";
       
   474 
       
   475 Goalw [constrains_def]
       
   476      "(project h C F : A co B)  =  \
       
   477 \     (F : (C Int extend_set h A) co (extend_set h B) & A <= B)";
       
   478 by (auto_tac (claset() addSIs [project_act_I], simpset() addsimps [ball_Un]));
       
   479 by (force_tac (claset() addSIs [project_act_I] addSDs [subsetD], simpset()) 1);
       
   480 (*the <== direction*)
       
   481 by (rewtac project_act_def);
       
   482 by (force_tac (claset() addSDs [subsetD], simpset()) 1);
       
   483 qed "project_constrains";
       
   484 
       
   485 Goalw [stable_def]
       
   486      "(project h UNIV F : stable A) = (F : stable (extend_set h A))";
       
   487 by (simp_tac (simpset() addsimps [project_constrains]) 1);
       
   488 qed "project_stable";
       
   489 
       
   490 Goal "F : stable (extend_set h A) ==> project h C F : stable A";
       
   491 by (dtac (project_stable RS iffD2) 1);
       
   492 by (blast_tac (claset() addIs [project_stable_mono]) 1);
       
   493 qed "project_stable_I";
   464 
   494 
   465 Goal "A Int extend_set h ((project_set h A) Int B) = A Int extend_set h B";
   495 Goal "A Int extend_set h ((project_set h A) Int B) = A Int extend_set h B";
   466 by (auto_tac (claset(), simpset() addsimps [split_extended_all]));
   496 by (auto_tac (claset(), simpset() addsimps [split_extended_all]));
   467 qed "Int_extend_set_lemma";
   497 qed "Int_extend_set_lemma";
   468 
   498 
   560 \     (F : A leadsTo B)";
   590 \     (F : A leadsTo B)";
   561 by Safe_tac;
   591 by Safe_tac;
   562 by (etac leadsTo_imp_extend_leadsTo 2);
   592 by (etac leadsTo_imp_extend_leadsTo 2);
   563 by (dtac extend_leadsTo_slice 1);
   593 by (dtac extend_leadsTo_slice 1);
   564 by (full_simp_tac (simpset() addsimps [slice_extend_set]) 1);
   594 by (full_simp_tac (simpset() addsimps [slice_extend_set]) 1);
   565 qed "extend_leadsto";
   595 qed "extend_leadsTo";
   566 
   596 
   567 Goal "(extend h F : (extend_set h A) LeadsTo (extend_set h B)) =  \
   597 Goal "(extend h F : (extend_set h A) LeadsTo (extend_set h B)) =  \
   568 \     (F : A LeadsTo B)";
   598 \     (F : A LeadsTo B)";
   569 by (simp_tac
   599 by (simp_tac
   570     (simpset() addsimps [LeadsTo_def, reachable_extend_eq, 
   600     (simpset() addsimps [LeadsTo_def, reachable_extend_eq, 
   571 			 extend_leadsto, extend_set_Int_distrib RS sym]) 1);
   601 			 extend_leadsTo, extend_set_Int_distrib RS sym]) 1);
   572 qed "extend_LeadsTo";
   602 qed "extend_LeadsTo";
       
   603 
       
   604 
       
   605 (*** preserves ***)
       
   606 
       
   607 Goal "G : preserves (v o f) ==> project h C G : preserves v";
       
   608 by (auto_tac (claset(),
       
   609 	      simpset() addsimps [preserves_def, project_stable_I,
       
   610 				  extend_set_eq_Collect]));
       
   611 qed "project_preserves_I";
       
   612 
       
   613 (*to preserve f is to preserve the whole original state*)
       
   614 Goal "G : preserves f ==> project h C G : preserves id";
       
   615 by (asm_simp_tac (simpset() addsimps [project_preserves_I]) 1);
       
   616 qed "project_preserves_id_I";
       
   617 
       
   618 Goal "(extend h G : preserves (v o f)) = (G : preserves v)";
       
   619 by (auto_tac (claset(),
       
   620 	      simpset() addsimps [preserves_def, extend_stable RS sym,
       
   621 				  extend_set_eq_Collect]));
       
   622 qed "extend_preserves";
       
   623 
       
   624 Goal "inj h ==> (extend h G : preserves g)";
       
   625 by (auto_tac (claset(),
       
   626 	      simpset() addsimps [preserves_def, extend_def, extend_act_def, 
       
   627 				  stable_def, constrains_def, g_def]));
       
   628 qed "inj_extend_preserves";
       
   629 
       
   630 
       
   631 (*** Guarantees ***)
       
   632 
       
   633 Goal "project h UNIV ((extend h F) Join G) = F Join (project h UNIV G)";
       
   634 by (rtac program_equalityI 1);
       
   635 by (asm_simp_tac
       
   636     (simpset() addsimps [image_eq_UN, UN_Un, project_act_extend_act]) 2);
       
   637 by (simp_tac (simpset() addsimps [project_set_extend_set_Int]) 1);
       
   638 qed "project_extend_Join";
       
   639 
       
   640 Goal "(extend h F) Join G = extend h H ==> H = F Join (project h UNIV G)";
       
   641 by (dres_inst_tac [("f", "project h UNIV")] arg_cong 1);
       
   642 by (asm_full_simp_tac (simpset() addsimps [project_extend_Join]) 1);
       
   643 qed "extend_Join_eq_extend_D";
       
   644 
       
   645 (** Strong precondition and postcondition; only useful when
       
   646     the old and new state sets are in bijection **)
       
   647 
       
   648 Goal "F : X guarantees[v] Y ==> \
       
   649 \     extend h F : (extend h `` X) guarantees[v o f] (extend h `` Y)";
       
   650 by (rtac guaranteesI 1);
       
   651 by Auto_tac;
       
   652 by (blast_tac (claset() addIs [project_preserves_I]
       
   653 			addDs [extend_Join_eq_extend_D, guaranteesD]) 1);
       
   654 qed "guarantees_imp_extend_guarantees";
       
   655 
       
   656 Goal "extend h F : (extend h `` X) guarantees[v o f] (extend h `` Y) \
       
   657 \     ==> F : X guarantees[v] Y";
       
   658 by (auto_tac (claset(), simpset() addsimps [guar_def]));
       
   659 by (dres_inst_tac [("x", "extend h G")] spec 1);
       
   660 by (asm_full_simp_tac 
       
   661     (simpset() delsimps [extend_Join] 
       
   662            addsimps [extend_Join RS sym, extend_preserves,
       
   663 		     inj_extend RS inj_image_mem_iff]) 1);
       
   664 qed "extend_guarantees_imp_guarantees";
       
   665 
       
   666 Goal "(extend h F : (extend h `` X) guarantees[v o f] (extend h `` Y)) = \
       
   667 \    (F : X guarantees[v] Y)";
       
   668 by (blast_tac (claset() addIs [guarantees_imp_extend_guarantees,
       
   669 			       extend_guarantees_imp_guarantees]) 1);
       
   670 qed "extend_guarantees_eq";
   573 
   671 
   574 
   672 
   575 Close_locale "Extend";
   673 Close_locale "Extend";
   576 
   674 
   577 (*Close_locale should do this!
   675 (*Close_locale should do this!