           (*-------------------------------------------*
            |        CSP-Prover on Isabelle2004         |
            |                  April 2006               |
            |                  March 2007  (modified)   |
            |                October 2009  (modified)   |
            |                                           |
            |        Yoshinao Isobe (AIST JAPAN)        |
            *-------------------------------------------*)

theory CSP_T_law_etc
imports CSP_T_law_aux
begin

(*------------------------*
         |~| --> !!
 *------------------------*)

lemma cspT_Int_choice_to_Rep:
  "(P |~| Q) =T[M,M] (!nat n:{0, (Suc 0)} .. (IF (n = 0) THEN P ELSE Q))"
apply (rule cspT_rw_right)
apply (subgoal_tac
 "(!nat n:{0, (Suc 0)} .. IF (n = 0) THEN P ELSE Q) =T[M,M]
  (!nat n:({0} Un {(Suc 0)}) .. IF (n = 0) THEN P ELSE Q)")
apply (assumption)
apply (rule cspT_decompo)
apply (fast)
apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_Rep_int_choice_union_Int)
apply (rule cspT_decompo)

apply (rule cspT_rw_right)
apply (rule cspT_Rep_int_choice_singleton)
apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_IF)
apply (simp)

apply (rule cspT_rw_right)
apply (rule cspT_Rep_int_choice_singleton)
apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_IF)
apply (simp)
done

(*** cspT_Rep_int_choice_set_input ***)

lemma cspT_Rep_int_choice_sum_set_input:
  "!! c:C .. (!set X:(Xsf c) .. (? :X -> (Pff c)))
   =T[M,M] !set X:(Union {(Xsf c) |c. c : sumset C}) ..
          (? a:X -> (!! c:{c:C. EX X. X:(Xsf c) & a:X}s .. (Pff c a)))"
apply (simp add: cspT_semantics)
apply (rule order_antisym)

(* <= *)
 apply (rule)
 apply (simp add: in_traces)
 apply (elim conjE exE bexE disjE)
 apply (simp_all)
  apply (force)

(* => *)
 apply (rule)
 apply (simp add: in_traces)
 apply (elim conjE exE bexE disjE)
 apply (simp_all)
  apply (rule_tac x="c" in bexI)
  apply (force)
  apply (simp)

  apply (simp)
  apply (rule_tac x="ca" in bexI)
  apply (simp)
  apply (simp)
  apply (fast)
  apply (simp)
done

(*** cspT_Rep_int_choice_set_input ***)

lemma cspT_Rep_int_choice_set_input:
  "!nat n:N .. (!set X:(Xsf n) .. (? :X -> (Pff n)))
   =T[M,M] !set X:(Union {(Xsf n) |n. n : N}) ..
          (? a:X -> (!nat n:{n:N. EX X. X:(Xsf n) & a:X} .. (Pff n a)))"
apply (simp add: Rep_int_choice_nat_def)
apply (rule cspT_rw_left)
apply (rule cspT_Rep_int_choice_sum_set_input)
apply (rule cspT_decompo)
apply (force)
apply (simp)
done

(*** cspT_Rep_int_choice_set_set_DIV ***)

lemma cspT_Rep_int_choice_set_set_DIV:
  "[| Xs ~= {} ; Ys ~= {} |] ==>
   !set X:Xs .. (!set Y:Ys .. (? a:(X Un Y) -> DIV))
   =T[M,M] !set Z:{X Un Y |X Y. X:Xs & Y:Ys} .. (? a:Z -> DIV)"
apply (simp add: cspT_semantics)
apply (rule order_antisym)

(* <= *)
 apply (rule)
 apply (simp add: in_traces)
 apply (elim conjE exE bexE disjE)
 apply (simp_all)
  apply (rule_tac x="X Un Xa" in exI)
  apply (simp)
  apply (rule_tac x="X" in exI)
  apply (rule_tac x="Xa" in exI)
  apply (simp)
  apply (rule_tac x="X Un Xa" in exI)
  apply (simp)
  apply (rule_tac x="X" in exI)
  apply (rule_tac x="Xa" in exI)
  apply (simp)

(* => *)
 apply (rule)
 apply (simp add: in_traces)
 apply (elim conjE exE bexE disjE)
 apply (simp_all)
 apply (force)
done

(*********************************************************
               (P [+] SKIP) |~| (Q [+] SKIP)
 *********************************************************)

(* p.289 *)

lemma cspT_Int_choice_Ext_choice_SKIP:
  "(P [+] SKIP) |~| (Q [+] SKIP) =T[M,M] (P [+] Q [+] SKIP)"
apply (simp add: cspT_semantics)
apply (rule order_antisym)

(* => *)
 apply (rule, simp add: in_traces)
 apply (force)

(* <= *)
 apply (rule, simp add: in_traces)
 apply (force)
done

(*********************************************************
               (P [+] DIV) |~| (Q [+] DIV)
 *********************************************************)

lemma cspT_Int_choice_Ext_choice_DIV:
  "(P [+] DIV) |~| (Q [+] DIV) =T[M,M] (P [+] Q [+] DIV)"
apply (simp add: cspT_semantics)
apply (rule order_antisym)

(* => *)
 apply (rule, simp add: in_traces)
 apply (force)

(* <= *)
 apply (rule, simp add: in_traces)
 apply (force)
done

(*********************************************************
             (P [+] SKIP) |~| (Q [+] DIV)
 *********************************************************)

lemma cspT_Int_choice_Ext_choice_SKIP_DIV:
  "(P [+] SKIP) |~| (Q [+] DIV) =T[M,M] (P [+] Q [+] SKIP)"
apply (simp add: cspT_semantics)
apply (rule order_antisym)
apply (rule, simp add: in_traces, force)+
done

(*********************************************************
             (P [+] DIV) |~| (Q [+] SKIP)
 *********************************************************)

lemma cspT_Int_choice_Ext_choice_DIV_SKIP:
  "(P [+] DIV) |~| (Q [+] SKIP) =T[M,M] (P [+] Q [+] SKIP)"
apply (simp add: cspT_semantics)
apply (rule order_antisym)
apply (rule, simp add: in_traces, force)+
done

(*********************************************************
         (P [+] SKIP or DIV) |~| (Q [+] DIV or SKIP)
 *********************************************************)

lemma cspT_Int_choice_Ext_choice_SKIP_or_DIV:
  "[| P2 = SKIP | P2 = DIV ; Q2 = SKIP | Q2 = DIV |] ==>
   (P1 [+] P2) |~| (Q1 [+] Q2) =T[M,M] (P1 [+] Q1 [+] (P2 |~| Q2))"
apply (elim disjE)
apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_decompo)
apply (rule cspT_reflex)
apply (rule cspT_idem)
apply (simp add: cspT_Int_choice_Ext_choice_SKIP)

apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_decompo)
apply (rule cspT_reflex)
apply (rule cspT_unit)
apply (simp add: cspT_Int_choice_Ext_choice_SKIP_DIV)

apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_decompo)
apply (rule cspT_reflex)
apply (rule cspT_unit)
apply (simp add: cspT_Int_choice_Ext_choice_DIV_SKIP)

apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_decompo)
apply (rule cspT_reflex)
apply (rule cspT_unit)
apply (simp add: cspT_Int_choice_Ext_choice_DIV)
done

(*********************************************************
                    (P [+] DIV) |~| P
 *********************************************************)

lemma cspT_Ext_choice_DIV_Int_choice_Id:
  "(P [+] DIV) |~| P =T[M,M] P"
apply (simp add: cspT_semantics)
apply (rule order_antisym)
 apply (rule, simp add: in_traces)
 apply (force)
 apply (rule, simp add: in_traces)
done

(* =================================================== *
 |             addition for CSP-Prover 5               |
 |                    (renaming)                       |
 * =================================================== *)

lemma cspT_Ext_pre_choice_Renaming_fun_step:
  "(? x:X -> Pf x)[[<rel> f]] =T[M,M]
   (? y:(f ` X) -> (! x:{x:X. y = f x} .. (Pf x[[<rel> f]])))"
apply (rule cspT_rw_left)
apply (rule cspT_step)

apply (rule cspT_decompo)
apply (simp add: fun_to_rel_def)
apply (force)

apply (rule cspT_decompo)
apply (simp add: fun_to_rel_def)
apply (force)
done

(* Act prefix event *)

lemma cspT_Act_prefix_Renaming_fun_step:
  "(a -> P)[[<rel> f]] =T[M,M] f(a) -> P[[<rel> f]]"
apply (rule cspT_rw_left)
apply (rule cspT_decompo)
apply (simp)
apply (rule cspT_step)

apply (rule cspT_rw_left)
apply (rule cspT_Ext_pre_choice_Renaming_fun_step)

apply (rule cspT_rw_right)
apply (rule cspT_step)

apply (rule cspT_decompo)
apply (simp)

apply (simp)
apply (subgoal_tac
  "{x. x = a & f a = f x}={a}")
apply (simp)
apply (rule cspT_rw_left)
apply (rule cspT_Rep_int_choice_const_com_rule)
apply (auto)
apply (rule cspT_rw_left)
apply (rule cspT_IF_split)
apply (auto)
done

lemmas cspT_Renaming_fun_step
     = cspT_Ext_pre_choice_Renaming_fun_step
       cspT_Act_prefix_Renaming_fun_step

(* -------- event -------- *)

lemma cspT_Act_prefix_Renaming1_event1_step_in:
  "(a -> P)[[a<-->b]] =T[M,M] b -> P[[a<-->b]]"
apply (simp add: Renaming_event_def Renaming_event_fun_def)
by (rule cspT_rw_left, rule cspT_Act_prefix_Renaming_fun_step, auto)

lemma cspT_Act_prefix_Renaming1_event2_step_in:
  "(a -> P)[[b<-->a]] =T[M,M] b -> P[[b<-->a]]"
by (simp add: cspT_Act_prefix_Renaming1_event1_step_in Renaming_commut)

lemma cspT_Act_prefix_Renaming1_event_step_notin:
  "[| a ~= c ; b ~= c |] ==> (c -> P)[[a<-->b]] =T[M,M] c -> P[[a<-->b]]"
apply (simp add: Renaming_event_def Renaming_event_fun_def)
by (rule cspT_rw_left, rule cspT_Act_prefix_Renaming_fun_step, auto)

lemmas cspT_Act_prefix_Renaming1_event_step =
       cspT_Act_prefix_Renaming1_event1_step_in
       cspT_Act_prefix_Renaming1_event2_step_in
       cspT_Act_prefix_Renaming1_event_step_notin

lemma cspT_Act_prefix_Renaming2_set_event_step_in:
  "a:A ==> (a -> P)[[A<<-b]] =T[M,M] b -> P[[A<<-b]]"
apply (simp add: Renaming_event_def Renaming_event_fun_def)
by (rule cspT_rw_left, rule cspT_Act_prefix_Renaming_fun_step, auto)

lemma cspT_Act_prefix_Renaming2_set_event_step_notin:
  "c~:A ==> (c -> P)[[A<<-b]] =T[M,M] c -> P[[A<<-b]]"
apply (simp add: Renaming_event_def Renaming_event_fun_def)
by (rule cspT_rw_left, rule cspT_Act_prefix_Renaming_fun_step, auto)

lemma cspT_Act_prefix_Renaming2_set_event_step:
  "(a -> P)[[A<<-b]] =T[M,M]
   IF (a:A) THEN (b -> P[[A<<-b]])
            ELSE (a -> P[[A<<-b]])"
apply (case_tac "a:A")
apply (rule cspT_rw_left)
apply (rule cspT_Act_prefix_Renaming2_set_event_step_in)
apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_IF_split)
apply (simp)
apply (rule cspT_rw_left)
apply (rule cspT_Act_prefix_Renaming2_set_event_step_notin)
apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_IF_split)
apply (simp)
done

lemmas cspT_Act_prefix_Renaming2_set_event_steps =
       cspT_Act_prefix_Renaming2_set_event_step_in
       cspT_Act_prefix_Renaming2_set_event_step_notin

(* sinlge *)

lemma cspT_Act_prefix_Renaming2_event_step_in:
  "(a -> P)[[a<--b]] =T[M,M] b -> P[[a<--b]]"
by (simp add: cspT_Act_prefix_Renaming2_set_event_step_in)

lemma cspT_Act_prefix_Renaming2_event_step_notin:
  "c~=a ==> (c -> P)[[a<--b]] =T[M,M] c -> P[[a<--b]]"
by (simp add: cspT_Act_prefix_Renaming2_set_event_step_notin)

lemmas cspT_Act_prefix_Renaming2_event_step =
       cspT_Act_prefix_Renaming2_event_step_in
       cspT_Act_prefix_Renaming2_event_step_notin

lemmas cspT_Act_prefix_Renaming_event_step =
       cspT_Act_prefix_Renaming1_event_step
       cspT_Act_prefix_Renaming2_event_step

(* -------- channel -------- *)

(* Act prefix channel *)

lemma cspT_Act_prefix_Renaming1_channel1_step_in:
  "[| inj f ; ALL x y. f x ~= g y |]
   ==> (f v -> P)[[f<==>g]] =T[M,M] g v -> P[[f<==>g]]"
apply (simp add: Renaming_channel_fun_def Renaming_channel_def)
by (rule cspT_rw_left, rule cspT_Act_prefix_Renaming_fun_step, auto)

lemma cspT_Act_prefix_Renaming1_channel2_step_in:
  "[| inj f ; ALL x y. f x ~= g y |]
   ==> (f v -> P)[[g<==>f]] =T[M,M] g v -> P[[g<==>f]]"
by (simp add: Renaming_commut cspT_Act_prefix_Renaming1_channel1_step_in)

lemma cspT_Act_prefix_Renaming1_channel_step_notin:
  "[| (ALL x. a ~= f x) | a ~: range f ;
      (ALL x. a ~= g x) | a ~: range g |]
   ==> (a -> P)[[f<==>g]] =T[M,M] a -> P[[f<==>g]]"
apply (simp add: Renaming_channel_fun_def Renaming_channel_def)
by (rule cspT_rw_left, rule cspT_Act_prefix_Renaming_fun_step, auto)

lemmas cspT_Act_prefix_Renaming1_channel_step =
       cspT_Act_prefix_Renaming1_channel1_step_in
       cspT_Act_prefix_Renaming1_channel2_step_in
       cspT_Act_prefix_Renaming1_channel_step_notin

lemma cspT_Act_prefix_Renaming2_channel_step_in:
  "[| inj f ; ALL x y. f x ~= g y |]
   ==> (f v -> P)[[f<==g]] =T[M,M] g v -> P[[f<==g]]"
apply (simp add: Renaming_channel_fun_def Renaming_channel_def)
by (rule cspT_rw_left, rule cspT_Act_prefix_Renaming_fun_step, auto)

lemma cspT_Act_prefix_Renaming2_channel_step_notin:
  "[| (ALL x. a ~= f x) | a ~: range f |]
   ==> (a -> P)[[f<==g]] =T[M,M] a -> P[[f<==g]]"
apply (simp add: Renaming_channel_fun_def Renaming_channel_def)
by (rule cspT_rw_left, rule cspT_Act_prefix_Renaming_fun_step, auto)

lemmas cspT_Act_prefix_Renaming2_channel_step =
       cspT_Act_prefix_Renaming2_channel_step_in
       cspT_Act_prefix_Renaming2_channel_step_notin

lemmas cspT_Act_prefix_Renaming_channel_step =
       cspT_Act_prefix_Renaming1_channel_step
       cspT_Act_prefix_Renaming2_channel_step

(* -------*)

lemmas cspT_Act_prefix_Renaming_step =
       cspT_Act_prefix_Renaming_fun_step
       cspT_Act_prefix_Renaming_event_step
       cspT_Act_prefix_Renaming_channel_step

(* --- Ext_pre_choice_Renaming_even --- *)

(* <--> *)

lemma cspT_Ext_pre_choice_Renaming1_event1_step:
  "a ~= b ==>
     (? x:X -> Pf x)[[a<-->b]] =T[M,M]
     (IF (a:X) THEN (b -> (Pf a)[[a<-->b]]) ELSE STOP) [+]
     (IF (b:X) THEN (a -> (Pf b)[[a<-->b]]) ELSE STOP) [+]
      (? x:(X - {a,b}) -> (Pf x)[[a<-->b]])"
apply (rule cspT_rw_left)
apply (simp add: Renaming_event_def)
apply (rule cspT_Renaming_fun_step)
apply (fold Renaming_event_def)

apply (case_tac "a:X")
 apply (case_tac "b:X")
  apply (simp)
  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_decompo)
  apply (rule cspT_IF_split)
  apply (rule cspT_IF_split)
  apply (rule cspT_reflex)
  apply (simp)

  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_decompo)
  apply (rule cspT_step)
  apply (rule cspT_step)
  apply (rule cspT_reflex)

  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_step)
  apply (rule cspT_reflex)

  apply (rule cspT_rw_right)
  apply (rule cspT_step)
  apply (simp)

  apply (rule cspT_decompo)
  apply (simp add: image_def Renaming_event_fun_def)
  apply (force)

  apply (simp)

   apply (case_tac "aa = a")
   apply (simp)
   apply ((rule cspT_rw_right, rule cspT_IF_split | rule cspT_decompo)| simp)+
   apply (simp add: image_def Renaming_event_fun_def)
   apply (rule cspT_rw_left)
   apply (rule cspT_Rep_int_choice_singleton)
   apply (simp)

   apply (case_tac "aa = b")
   apply (simp)
   apply ((rule cspT_rw_right, rule cspT_IF_split | rule cspT_decompo)| simp)+
   apply (simp add: image_def Renaming_event_fun_def)
   apply (subgoal_tac "{x. x ~= b & (x ~= b --> x = a)}={a}")
   apply (simp)
   apply (rule cspT_Rep_int_choice_singleton)
   apply (force)

   (* etc *)
   apply (simp)
   apply ((rule cspT_rw_right, rule cspT_IF_split | rule cspT_decompo)| simp)+
   apply (simp add: image_def Renaming_event_fun_def)
   apply (subgoal_tac
     "{x. x ~= b & (x ~= b --> x ~= a & (x ~= a --> x : X & aa = x))}={aa}")
   apply (simp)
   apply (rule cspT_Rep_int_choice_singleton)
   apply (force)

 (* b~:X *)
  apply (simp)
  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_decompo)
  apply (rule cspT_IF_split)
  apply (rule cspT_IF_split)
  apply (rule cspT_reflex)
  apply (simp)

  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_decompo)
  apply (rule cspT_step)
  apply (rule cspT_step)
  apply (rule cspT_reflex)

  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_step)
  apply (rule cspT_reflex)
  apply (simp)

  apply (rule cspT_rw_right)
  apply (rule cspT_step)
  apply (simp)

  apply (rule cspT_decompo)
  apply (simp add: image_def Renaming_event_fun_def)
  apply (force)

  apply (simp)

   apply (case_tac "aa = b")
   apply (simp)
   apply ((rule cspT_rw_right, rule cspT_IF_split | rule cspT_decompo)| simp)+
   apply (simp add: image_def Renaming_event_fun_def)
   apply (subgoal_tac "{x. x ~= b & (x ~= b --> x = a)}={a}")
   apply (simp)
   apply (rule cspT_Rep_int_choice_singleton)
   apply (force)

   apply (simp)
   apply ((rule cspT_rw_right, rule cspT_IF_split | rule cspT_decompo)| simp)+
   apply (simp add: image_def Renaming_event_fun_def)
   apply (subgoal_tac
   "{x. x ~= b & (x ~= b --> x ~= a & (x ~= a --> x : X & aa = x))} = {aa}")
   apply (simp)
   apply (rule cspT_Rep_int_choice_singleton)
   apply (force)

(* a~:X *)
 apply (case_tac "b:X")

  apply (simp)
  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_decompo)
  apply (rule cspT_IF_split)
  apply (rule cspT_IF_split)
  apply (rule cspT_reflex)
  apply (simp)

  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_decompo)
  apply (rule cspT_step)
  apply (rule cspT_step)
  apply (rule cspT_reflex)

  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_step)
  apply (rule cspT_reflex)
  apply (simp)

  apply (rule cspT_rw_right)
  apply (rule cspT_step)
  apply (simp)

  apply (rule cspT_decompo)
  apply (simp add: image_def Renaming_event_fun_def)
  apply (force)

  apply (simp)

   apply (case_tac "aa = a")
   apply (simp)
   apply ((rule cspT_rw_right, rule cspT_IF_split | rule cspT_decompo)| simp)+
   apply (simp add: image_def Renaming_event_fun_def)
   apply (rule cspT_Rep_int_choice_singleton)

   apply (simp)
   apply ((rule cspT_rw_right, rule cspT_IF_split | rule cspT_decompo)| simp)+
   apply (simp add: image_def Renaming_event_fun_def)
   apply (subgoal_tac
   "{x. x ~= b & (x ~= b --> x ~= a & (x ~= a --> x : X & aa = x))} = {aa}")
   apply (simp)
   apply (rule cspT_Rep_int_choice_singleton)
   apply (force)

 (* b~:X *)
  apply (simp)
  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_decompo)
  apply (rule cspT_IF_split)
  apply (rule cspT_IF_split)
  apply (rule cspT_reflex)
  apply (simp)

  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_decompo)
  apply (rule cspT_step)
  apply (rule cspT_step)
  apply (rule cspT_reflex)

  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_step)
  apply (rule cspT_reflex)
  apply (simp)

  apply (rule cspT_rw_right)
  apply (rule cspT_step)
  apply (simp)

  apply (rule cspT_decompo)
  apply (simp add: image_def Renaming_event_fun_def)
  apply (force)

   apply ((rule cspT_rw_right, rule cspT_IF_split | rule cspT_decompo)| simp)+
   apply (simp add: image_def Renaming_event_fun_def)
   apply (subgoal_tac
   "{x. x ~= b & (x ~= b --> x ~= a & (x ~= a --> x : X & aa = x))} = {aa}")
   apply (simp)
   apply (rule cspT_Rep_int_choice_singleton)
   apply (force)
done

lemma cspT_Ext_pre_choice_Renaming1_event2_step:
  "a = b ==>
     (? x:X -> Pf x)[[a<-->b]] =T[M,M]
     (IF (a:X) THEN (b -> (Pf a)[[a<-->b]]) ELSE STOP) [+]
     (IF (b:X) THEN (a -> (Pf b)[[a<-->b]]) ELSE STOP) [+]
      (? x:(X - {a,b}) -> (Pf x)[[a<-->b]])"
apply (simp)
apply (rule cspT_rw_left)
apply (simp add: Renaming_event_def)
apply (rule cspT_Renaming_fun_step)
apply (fold Renaming_event_def)

apply (rule cspT_rw_right)
apply (rule cspT_decompo)
apply (rule cspT_idem)
apply (rule cspT_reflex)

 apply (case_tac "b:X")
  apply (simp)
  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_IF_split)
  apply (rule cspT_reflex)
  apply (simp)

  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_step)
  apply (rule cspT_reflex)

  apply (rule cspT_rw_right)
  apply (rule cspT_step)
  apply (simp)

  apply (rule cspT_decompo)
  apply (simp add: image_def Renaming_event_fun_def)
  apply (force)

  apply (simp)

   apply (case_tac "aa = b")
   apply (simp)
   apply ((rule cspT_rw_right, rule cspT_IF_split | rule cspT_decompo)| simp)+
   apply (simp add: image_def Renaming_event_fun_def)
   apply (rule cspT_Rep_int_choice_singleton)

   apply (simp)
   apply ((rule cspT_rw_right, rule cspT_IF_split | rule cspT_decompo)| simp)+
   apply (simp add: image_def Renaming_event_fun_def)
   apply (subgoal_tac
     "{x. x ~= b & (x ~= b --> x ~= a & (x ~= a --> x : X & aa = x))}={aa}")
   apply (simp)
   apply (rule cspT_Rep_int_choice_singleton)
   apply (force)

 (* b~:X *)
  apply (simp)
  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_IF_split)
  apply (rule cspT_reflex)
  apply (simp)

  apply (rule cspT_rw_right)
  apply (rule cspT_decompo)
  apply (rule cspT_step)
  apply (rule cspT_reflex)

  apply (rule cspT_rw_right)
  apply (rule cspT_step)
  apply (simp)

  apply (rule cspT_decompo)
  apply (simp add: image_def Renaming_event_fun_def)
  apply (force)

   apply ((rule cspT_rw_right, rule cspT_IF_split | rule cspT_decompo)| simp)+
   apply (simp add: image_def Renaming_event_fun_def)
   apply (subgoal_tac
   "{x. x ~= b & (x ~= b --> x ~= a & (x ~= a --> x : X & aa = x))} = {aa}")
   apply (simp)
   apply (rule cspT_Rep_int_choice_singleton)
   apply (force)
done

lemma cspT_Ext_pre_choice_Renaming1_event_step:
  "(? x:X -> Pf x)[[a<-->b]] =T[M,M]
     (IF (a:X) THEN (b -> (Pf a)[[a<-->b]]) ELSE STOP) [+]
     (IF (b:X) THEN (a -> (Pf b)[[a<-->b]]) ELSE STOP) [+]
      (? x:(X - {a,b}) -> (Pf x)[[a<-->b]])"
apply (case_tac "a=b")
apply (rule cspT_Ext_pre_choice_Renaming1_event2_step)
apply (simp_all)
apply (rule cspT_Ext_pre_choice_Renaming1_event1_step)
apply (simp_all)
done

(* <<- *)

lemma cspT_Ext_pre_choice_Renaming2_set_event_step_in:
  "X Int A ~= {} ==>
     (? x:X -> Pf x)[[A<<-a]] =T[M,M]
      a -> (! x:(X Int A) .. (Pf x)[[A<<-a]])
     [+] ? x:(X-A) -> (Pf x)[[A<<-a]]"
apply (rule cspT_rw_left)
apply (simp add: Renaming_event_def)
apply (rule cspT_Renaming_fun_step)
apply (fold Renaming_event_def)
apply (simp add: image_def)

apply (rule cspT_rw_right)
apply (rule cspT_decompo)
apply (rule cspT_step)
apply (rule cspT_reflex)
apply (rule cspT_rw_right)
apply (rule cspT_step)

apply (rule cspT_decompo)
apply (simp add: Renaming_event_fun_def)
apply (blast)

apply (simp)

apply (case_tac "aa = a")
 apply (simp)
 apply (case_tac "a : X & a ~: A")
  apply (simp)
  apply (rule cspT_rw_right)
  apply (rule cspT_IF_split)
  apply (simp)
  apply (rule cspT_ref_eq)

  (* <= *)
  apply (rule cspT_Int_choice_right)
   apply (rule cspT_Rep_int_choice_right)
   apply (simp)
   apply (rule cspT_Rep_int_choice_left)
   apply (rule_tac x="aaa" in exI)
   apply (simp)
   apply (simp add: Renaming_event_fun_def)

   apply (rule cspT_Rep_int_choice_left)
   apply (rule_tac x="a" in exI)
   apply (simp)
   apply (simp add: Renaming_event_fun_def)

  (* => *)
   apply (rule cspT_Rep_int_choice_right)
   apply (simp)
   apply (elim conjE bexE)
   apply (simp add: Renaming_event_fun_def)
   apply (case_tac "aaa : A")

    apply (simp)
    apply (rule cspT_Int_choice_left1)
    apply (rule cspT_Rep_int_choice_left)
    apply (simp)
    apply (rule_tac x="aaa" in exI)
    apply (simp)

    apply (simp)
    apply (rule cspT_Int_choice_left2)
    apply (simp)

 (* ~(a : X & a ~: A) *)
  apply (simp (no_asm_simp))
  apply (rule cspT_rw_right)
  apply (rule cspT_IF_split)
  apply (simp)
  apply (rule cspT_rw_right)
  apply (rule cspT_IF_split)
  apply (simp)

  apply (rule cspT_decompo)
  apply (simp add: Renaming_event_fun_def)
  apply (fast)
  apply (simp)

(* aa ~= a *)
 apply (simp)
 apply (rule cspT_rw_right)
 apply (rule cspT_IF_split)
 apply (simp)
 apply (rule cspT_rw_right)
 apply (rule cspT_IF_split)
 apply (simp)
 apply (simp add: Renaming_event_fun_def)
 apply (subgoal_tac "{x. x ~: A & (x ~: A --> x : X & aa = x)}={aa}")
 apply (simp)
 apply (rule cspT_Rep_int_choice_singleton)
 apply (force)
done

lemma cspT_Ext_pre_choice_Renaming2_set_event_step_notin:
  "[| X Int A = {} |] ==>
     (? x:X -> Pf x)[[A<<-b]] =T[M,M] ? x:X -> (Pf x)[[A<<-b]]"
apply (simp add: Renaming_event_def)
apply (rule cspT_rw_left)
apply (rule cspT_Renaming_fun_step)
apply (fold Renaming_event_def)

apply (rule cspT_decompo)
apply (simp add: Image_def image_def)
apply (simp add: Renaming_event_fun_def)
apply (force)
apply (simp add: Renaming_event_fun_def)
apply (subgoal_tac
  "{x. (x : A --> x : X & a = b) & (x ~: A --> x : X & a = x)} = {a}")
apply (simp)
apply (rule cspT_Rep_int_choice_singleton)
apply (force)
done

lemma cspT_Ext_pre_choice_Renaming2_set_event_step:
  "(? x:X -> Pf x)[[A<<-a]] =T[M,M]
  IF (X Int A ~= {})
  THEN (a -> (! x:(X Int A) .. (Pf x)[[A<<-a]])
        [+] ? x:(X-A) -> (Pf x)[[A<<-a]])
  ELSE (? x:X -> (Pf x)[[A<<-a]])"
apply (case_tac "X Int A ~= {}")
apply (rule cspT_rw_left)
apply (rule cspT_Ext_pre_choice_Renaming2_set_event_step_in)
apply (simp)
apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_IF_split)
apply (simp)
apply (rule cspT_rw_left)
apply (rule cspT_Ext_pre_choice_Renaming2_set_event_step_notin)
apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_IF_split)
apply (simp)
done

(* <-- *)

lemma cspT_Ext_pre_choice_Renaming2_event_step:
  "(? x:X -> Pf x)[[a<--b]] =T[M,M]
  IF (a : X)
  THEN (b -> (Pf a)[[a<--b]]
        [+] ? x:(X-{a}) -> (Pf x)[[a<--b]])
  ELSE (? x:X -> (Pf x)[[a<--b]])"
apply (rule cspT_rw_left)
apply (rule cspT_Ext_pre_choice_Renaming2_set_event_step)
apply (case_tac "a:X")

 apply (rule cspT_decompo)
 apply (simp)
 apply (rule cspT_decompo)
 apply (rule cspT_decompo)
 apply (simp)
 apply (subgoal_tac "X Int {a} = {a}")
 apply (simp)
 apply (rule cspT_Rep_int_choice_singleton)
 apply (force)
 apply (simp)
 apply (simp)

 apply (simp)
 apply (rule cspT_rw_right)
 apply (rule cspT_IF_split)
 apply (simp)
 apply (rule cspT_rw_left)
 apply (rule cspT_IF_split)
 apply (simp)
done

lemmas cspT_Ext_pre_choice_Renaming_event_step =
       cspT_Ext_pre_choice_Renaming1_event_step
       cspT_Ext_pre_choice_Renaming2_set_event_step
       cspT_Ext_pre_choice_Renaming2_event_step

(* sending -- event -- *)

lemma cspT_Send_prefix_Renaming1_event1_step_in:
  "inj f ==> (f!v -> P)[[a<-->f v]] =T[M,M] a -> P[[a<-->f v]]"
apply (simp add: csp_prefix_ss_def)
apply (simp add: cspT_Act_prefix_Renaming_step)
done

lemma cspT_Send_prefix_Renaming1_event2_step_in:
  "inj f ==> (f!v -> P)[[f v<-->a]] =T[M,M] a -> P[[f v<-->a]]"
by (simp add: Renaming_commut cspT_Send_prefix_Renaming1_event1_step_in)

lemma cspT_Send_prefix_Renaming1_event_step_notin:
  "[| a ~= f v | f v ~= a ; b ~= f v | f v ~= b |]
   ==> (f!v -> P)[[a<-->b]] =T[M,M] f!v -> P[[a<-->b]]"
apply (simp add: csp_prefix_ss_def)
apply (simp add: cspT_Act_prefix_Renaming_step)
done

lemmas cspT_Send_prefix_Renaming1_event_step =
       cspT_Send_prefix_Renaming1_event1_step_in
       cspT_Send_prefix_Renaming1_event2_step_in
       cspT_Send_prefix_Renaming1_event_step_notin

(* <<- *)

lemma cspT_Send_prefix_Renaming2_set_event_step_in:
  "f v : A ==> (f!v -> P)[[A<<-a]] =T[M,M] a -> P[[A<<-a]]"
apply (simp add: csp_prefix_ss_def)
apply (simp add: cspT_Act_prefix_Renaming2_set_event_step_in)
done

lemma cspT_Send_prefix_Renaming2_set_event_step_notin:
  "f v ~: A
   ==> (f!v -> P)[[A<<-b]] =T[M,M] f!v -> P[[A<<-b]]"
apply (simp add: csp_prefix_ss_def)
apply (simp add: cspT_Act_prefix_Renaming2_set_event_step_notin)
done

lemma cspT_Send_prefix_Renaming2_set_event_step:
  "(f!v -> P)[[A<<-a]] =T[M,M]
   IF (f v : A) THEN (a -> P[[A<<-a]]) ELSE (f!v -> P[[A<<-a]])"
apply (case_tac "f v : A")
apply (rule cspT_rw_left)
apply (rule cspT_Send_prefix_Renaming2_set_event_step_in)
apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_IF_split)
apply (simp)
apply (rule cspT_rw_left)
apply (rule cspT_Send_prefix_Renaming2_set_event_step_notin)
apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_IF_split)
apply (simp)
done

(* <-- *)

lemma cspT_Send_prefix_Renaming2_event_step_in:
  "(f!v -> P)[[f v<--a]] =T[M,M] a -> P[[f v<--a]]"
by (simp add: cspT_Send_prefix_Renaming2_set_event_step_in)

lemma cspT_Send_prefix_Renaming2_event_step_notin:
  "[| a ~= f v | f v ~= a |]
   ==> (f!v -> P)[[a<--b]] =T[M,M] f!v -> P[[a<--b]]"
by (simp add: cspT_Send_prefix_Renaming2_set_event_step_notin)

lemmas cspT_Send_prefix_Renaming2_event_step =
       cspT_Send_prefix_Renaming2_event_step_in
       cspT_Send_prefix_Renaming2_event_step_notin

lemmas cspT_Send_prefix_Renaming_event_step =
       cspT_Send_prefix_Renaming1_event_step
       cspT_Send_prefix_Renaming2_event_step

(* sending -- channel -- *)

lemma cspT_Send_prefix_Renaming1_channel1_step_in:
  "[| inj f ; ALL x y. f x ~= g y |]
   ==> (f!v -> P)[[f<==>g]] =T[M,M] g!v -> P[[f<==>g]]"
apply (simp add: csp_prefix_ss_def)
apply (simp add: cspT_Act_prefix_Renaming_step)
done

lemma cspT_Send_prefix_Renaming1_channel2_step_in:
  "[| inj f ; ALL x y. f x ~= g y |]
   ==> (f!v -> P)[[g<==>f]] =T[M,M] g!v -> P[[g<==>f]]"
by (simp add: Renaming_commut cspT_Send_prefix_Renaming1_channel1_step_in)

lemma cspT_Send_prefix_Renaming1_channel_step_notin:
  "[| (ALL x. h v ~= f x) | h v ~: range f ;
      (ALL x. h v ~= g x) | h v ~: range g |]
    ==> (h!v -> P)[[f<==>g]] =T[M,M] h!v -> P[[f<==>g]]"
apply (simp add: csp_prefix_ss_def)
apply (simp add: cspT_Act_prefix_Renaming_step)
done

lemmas cspT_Send_prefix_Renaming1_channel_step =
       cspT_Send_prefix_Renaming1_channel1_step_in
       cspT_Send_prefix_Renaming1_channel2_step_in
       cspT_Send_prefix_Renaming1_channel_step_notin

lemma cspT_Send_prefix_Renaming2_channel_step_in:
  "[| inj f ; ALL x y. f x ~= g y |]
   ==> (f!v -> P)[[f<==g]] =T[M,M] g!v -> P[[f<==g]]"
apply (simp add: csp_prefix_ss_def)
apply (simp add: cspT_Act_prefix_Renaming_step)
done

lemma cspT_Send_prefix_Renaming2_channel_step_notin:
  "[| (ALL x. h v ~= f x) | h v ~: range f |]
    ==> (h!v -> P)[[f<==g]] =T[M,M] h!v -> P[[f<==g]]"
apply (simp add: csp_prefix_ss_def)
apply (simp add: cspT_Act_prefix_Renaming_step)
done

lemmas cspT_Send_prefix_Renaming2_channel_step =
       cspT_Send_prefix_Renaming2_channel_step_in
       cspT_Send_prefix_Renaming2_channel_step_notin

lemmas cspT_Send_prefix_Renaming_channel_step =
       cspT_Send_prefix_Renaming1_channel_step
       cspT_Send_prefix_Renaming2_channel_step

lemmas cspT_Send_prefix_Renaming_step =
       cspT_Send_prefix_Renaming_event_step
       cspT_Send_prefix_Renaming_channel_step

(* --- Rec_prefix_Renaming_even --- *)

(* <--> *)

lemma cspT_Rec_prefix_Renaming1_event1_step_in:
  "[| inj f ; v:X ; ALL x:X. a ~= f x |] ==>
     (f ? x:X -> Pf x)[[a<-->f v]] =T[M,M]
     (a -> (Pf v)[[a<-->f v]]) [+] f ? x:(X-{v}) -> (Pf x)[[a<-->f v]]"
apply (simp add: csp_prefix_ss_def)
apply (rule cspT_rw_left)
apply (simp add: Renaming_event_def)
apply (rule cspT_Renaming_fun_step)
apply (fold Renaming_event_def)

apply (rule cspT_rw_right)
apply (rule cspT_decompo)
apply (rule cspT_step)
apply (rule cspT_reflex)
apply (rule cspT_rw_right)
apply (rule cspT_step)

apply (rule cspT_decompo)
apply (simp add: inj_on_def)
apply (simp add: Image_def image_def)
apply (simp add: Renaming_event_fun_def)
apply (blast)

apply (simp)
apply (rule cspT_ref_eq)

(* <= *)
apply (case_tac "aa = a")

 (* aa = a *)
 apply (simp)
 apply (case_tac "a : f ` (X - {v})")
  apply (simp add: image_iff)

  (* a ~: f ` (X - {v})" *)
  apply (simp)
  apply (rule cspT_rw_right)
  apply (rule cspT_IF_split)
  apply (simp)
  apply (rule cspT_rw_right)
  apply (rule cspT_IF_split)
  apply (simp)
  apply (rule cspT_Rep_int_choice_left)
  apply (rule_tac x="f v" in exI)
  apply (simp add: Renaming_event_fun_def)

 (* aa ~= a *)
 apply (simp)

 apply (rule cspT_rw_right)
 apply (rule cspT_IF_split)
 apply (simp)
 apply (rule cspT_rw_right)
 apply (rule cspT_IF_split)
 apply (simp)

 apply (rule cspT_Rep_int_choice_left)
 apply (rule_tac x="aa" in exI)
 apply (simp)

 apply (simp add: image_iff)
 apply (erule bexE)
 apply (simp add: inj_on_def)
 apply (simp add: Renaming_event_fun_def)
 apply (force)

(* => *)
apply (simp add: Renaming_event_fun_def)
apply (case_tac "aa = a")

 (* aa = a *)
 apply (simp)
 apply (case_tac "a : f ` (X - {v})")

  apply (simp add: image_iff)

  (* a ~: f ` (X - {v})" *)
  apply (simp)
  apply (rule cspT_rw_left)
  apply (rule cspT_IF_split)
  apply (simp)
  apply (rule cspT_rw_left)
  apply (rule cspT_IF_split)
  apply (simp)
  apply (rule cspT_Rep_int_choice_right)
  apply (force)

 (* aa ~= a *)
 apply (simp)

 apply (rule cspT_rw_left)
 apply (rule cspT_IF_split)
 apply (simp)
 apply (rule cspT_rw_left)
 apply (rule cspT_IF_split)
 apply (simp)

 apply (rule cspT_Rep_int_choice_right)
 apply (auto)
done

lemma cspT_Rec_prefix_Renaming1_event2_step_in:
  "[| inj f ; v:X ; ALL x:X. a ~= f x |] ==>
     (f ? x:X -> Pf x)[[f v<-->a]] =T[M,M]
     (a -> (Pf v)[[f v<-->a]]) [+] f ? x:(X-{v}) -> (Pf x)[[f v<-->a]]"
apply (simp add: Renaming_commut)
apply (simp add: cspT_Rec_prefix_Renaming1_event1_step_in)
done

lemma cspT_Rec_prefix_Renaming1_event_step_notin:
  "[| (ALL x:X. a ~= f x) | a ~: f ` X ;
      (ALL x:X. b ~= f x) | b ~: f ` X |] ==>
     (f ? x:X -> Pf x)[[a<-->b]] =T[M,M] f ? x:X -> (Pf x)[[a<-->b]]"
apply (simp add: csp_prefix_ss_def)
apply (simp add: Renaming_event_def)
apply (rule cspT_rw_left)
apply (rule cspT_Renaming_fun_step)
apply (fold Renaming_event_def)

apply (rule cspT_decompo)
apply (simp add: Image_def image_def)
apply (simp add: Renaming_event_fun_def)
apply (force)
apply (subgoal_tac
  "{x : f ` X. aa = Renaming1_event_fun a b x} = {aa}")
apply (simp)
apply (rule cspT_Rep_int_choice_singleton)

apply (simp add: Renaming_event_fun_def)
apply (force)
done

lemmas cspT_Rec_prefix_Renaming1_event_step =
       cspT_Rec_prefix_Renaming1_event1_step_in
       cspT_Rec_prefix_Renaming1_event2_step_in
       cspT_Rec_prefix_Renaming1_event_step_notin

(* <<- *)

lemma cspT_Rec_prefix_Renaming2_set_event_step_in:
  "[| inj f ; EX x:X. f x : A |] ==>
     (f ? x:X -> Pf x)[[A<<-a]] =T[M,M]
      a -> (!<f> x:{x:X. f x : A} .. (Pf x)[[A<<-a]])
     [+] f ? x:(X-{x. f x : A}) -> (Pf x)[[A<<-a]]"
apply (simp add: csp_prefix_ss_def)
apply (rule cspT_rw_left)
apply (simp add: Renaming_event_def)
apply (rule cspT_Renaming_fun_step)
apply (fold Renaming_event_def)
apply (simp add: image_def)

apply (rule cspT_rw_right)
apply (rule cspT_decompo)
apply (rule cspT_step)
apply (rule cspT_reflex)
apply (rule cspT_rw_right)
apply (rule cspT_step)

apply (rule cspT_decompo)
apply (simp add: Renaming_event_fun_def)
apply (blast)

apply (simp)

apply (case_tac "aa = a")
 apply (simp)
 apply (case_tac "EX x:X - {x. f x : A}. a = f x")
  apply (simp add: image_iff)
  apply (rule cspT_rw_right)
  apply (rule cspT_IF_split)
  apply (elim conjE bexE)
  apply (simp)

  apply (rule cspT_ref_eq)

  (* <= *)
  apply (rule cspT_Int_choice_right)
   apply (rule cspT_Rep_int_choice_right)
   apply (simp)
   apply (simp)
   apply (rule cspT_Rep_int_choice_left)
   apply (rule_tac x="f aaa" in exI)
   apply (simp)
   apply (simp add: Renaming_event_fun_def)
   apply (fast)

   apply (rule cspT_Rep_int_choice_left)
   apply (rule_tac x="a" in exI)
   apply (simp)
   apply (rule conjI)
    apply (blast)
   apply (simp add: Renaming_event_fun_def)

  (* => *)
   apply (rule cspT_Rep_int_choice_right)
   apply (simp)
   apply (elim conjE bexE)
   apply (simp add: Renaming_event_fun_def)
   apply (case_tac "f xb : A")

    apply (simp)
    apply (rule cspT_Int_choice_left1)
    apply (rule cspT_Rep_int_choice_left)
    apply (simp)
    apply (rule_tac x="xb" in exI)
    apply (simp)

    apply (simp)
    apply (rule cspT_Int_choice_left2)
    apply (simp add: inj_on_def)
    apply (force)

 (* ~(EX x:X - {x. f x : A}. a = f x) *)
  apply (simp)
  apply (rule cspT_rw_right)
  apply (rule cspT_IF_split)
  apply (simp)
  apply (rule cspT_rw_right)
  apply (rule cspT_IF_split)
  apply (simp)

  apply (rule cspT_ref_eq)

  (* <= *)
   apply (rule cspT_Rep_int_choice_right)
   apply (simp)
   apply (simp)
   apply (rule cspT_Rep_int_choice_left)
   apply (rule_tac x="f aaa" in exI)
   apply (simp)
   apply (simp add: Renaming_event_fun_def)
   apply (fast)

  (* => *)
   apply (rule cspT_Rep_int_choice_right)
   apply (simp)
   apply (rule cspT_Rep_int_choice_left)
   apply (simp)
   apply (elim conjE bexE)
   apply (simp add: Renaming_event_fun_def)
   apply (case_tac "f xa : A")

    apply (simp)
    apply (rule_tac x="xa" in exI)
    apply (simp)
    apply (simp)

 (* aa ~= a *)
 apply (simp)

 apply (rule cspT_rw_right)
 apply (rule cspT_IF_split)
 apply (simp)
 apply (rule cspT_rw_right)
 apply (rule cspT_IF_split)
 apply (simp)
 apply (rule cspT_ref_eq)

  (* => *)
  apply (rule cspT_Rep_int_choice_left)
  apply (rule_tac x="aa" in exI)
  apply (simp)
  apply (erule bexE)
  apply (simp add: inj_on_def)
  apply (simp add: Renaming_event_fun_def)
  apply (force)

 (* <= *)
  apply (rule cspT_Rep_int_choice_right)
  apply (simp)
  apply (elim conjE bexE)
  apply (simp add: Renaming_event_fun_def)
   apply (case_tac "f xb : A")
   apply (simp)
   apply (simp add: inj_on_def)
   apply (force)
done

lemma cspT_Rec_prefix_Renaming2_set_event_step_notin:
  "[| (ALL x:X. f x ~: A) | A Int f ` X = {} |] ==>
     (f ? x:X -> Pf x)[[A<<-b]] =T[M,M] f ? x:X -> (Pf x)[[A<<-b]]"
apply (simp add: csp_prefix_ss_def)
apply (simp add: Renaming_event_def)
apply (rule cspT_rw_left)
apply (rule cspT_Renaming_fun_step)
apply (fold Renaming_event_def)

apply (rule cspT_decompo)
apply (simp add: Image_def image_def)
apply (simp add: Renaming_event_fun_def)
apply (force)
apply (subgoal_tac
  "{x : f ` X. a = Renaming2_event_fun A b x} = {a}")
apply (simp)
apply (rule cspT_Rep_int_choice_singleton)

apply (simp add: Renaming_event_fun_def)
apply (force)
done

lemma cspT_Rec_prefix_Renaming2_set_event_step:
  "inj f ==>
  (f ? x:X -> Pf x)[[A<<-a]] =T[M,M]
  IF (EX x:X. f x : A)
  THEN (a -> (!<f> x:{x:X. f x : A} .. (Pf x)[[A<<-a]])
       [+] f ? x:(X-{x. f x : A}) -> (Pf x)[[A<<-a]])
  ELSE (f ? x:X -> (Pf x)[[A<<-a]])"
apply (case_tac "EX x:X. f x : A")
apply (rule cspT_rw_left)
apply (rule cspT_Rec_prefix_Renaming2_set_event_step_in)
apply (simp)
apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_IF_split)
apply (simp)
apply (rule cspT_rw_left)
apply (rule cspT_Rec_prefix_Renaming2_set_event_step_notin)
apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_IF_split)
apply (simp)
done

(* <-- *)

lemma cspT_Rec_prefix_Renaming2_event_step_in:
  "[| inj f ; v:X |] ==>
     (f ? x:X -> Pf x)[[f v<--a]] =T[M,M]
     (a -> (Pf v)[[f v<--a]]) [+] f ? x:(X-{v}) -> (Pf x)[[f v<--a]]"
apply (rule cspT_rw_left)
apply (rule cspT_Rec_prefix_Renaming2_set_event_step_in)
apply (simp)
apply (simp)
apply (force)
apply (simp)

apply (rule cspT_decompo)
 apply (rule cspT_decompo)
 apply (simp)
 apply (subgoal_tac "{x : X. f x = f v}={v}")
 apply (simp)
 apply (rule cspT_rw_left)
 apply (rule cspT_Rep_int_choice_singleton)
 apply (simp)
 apply (simp)
 apply (simp add: inj_on_def)
 apply (force)

 apply (subgoal_tac "{x. f x = f v}={v}")
 apply (simp)
 apply (simp add: inj_on_def)
 apply (force)
done

lemma cspT_Rec_prefix_Renaming2_event_step_notin:
  "[| (ALL x:X. a ~= f x) | a ~: f ` X |] ==>
     (f ? x:X -> Pf x)[[a<--b]] =T[M,M] f ? x:X -> (Pf x)[[a<--b]]"
apply (rule cspT_rw_left)
apply (rule cspT_Rec_prefix_Renaming2_set_event_step_notin)
apply (simp)
apply (force)
apply (simp)
done

lemmas cspT_Rec_prefix_Renaming2_event_step =
       cspT_Rec_prefix_Renaming2_event_step_in
       cspT_Rec_prefix_Renaming2_event_step_notin

lemmas cspT_Rec_prefix_Renaming_event_step =
       cspT_Rec_prefix_Renaming1_event_step
       cspT_Rec_prefix_Renaming2_event_step

(* ------ *)

(* <==> *)

lemma cspT_Rec_prefix_Renaming1_channel1_step_in:
  "[| inj f ; inj g ; ALL x y. f x ~= g y |] ==>
     (f ? x:X -> Pf x)[[f<==>g]] =T[M,M] g ? x:X -> (Pf x)[[f<==>g]]"
apply (simp add: Renaming_channel_def)
apply (simp add: csp_prefix_ss_def)
apply (rule cspT_rw_left)
apply (rule cspT_Renaming_fun_step)
apply (rule cspT_decompo)
apply (simp add: Renaming_channel_fun_simp)
apply (simp add: image_iff)
apply (erule bexE)
apply (simp)
apply (subgoal_tac
  "{xa. (EX x:X. xa = f x) & g x = Renaming1_channel_fun f g xa} = {f x}")
apply (simp)
apply (rule cspT_rw_left)
apply (rule cspT_Rep_int_choice_singleton)
apply (simp)

apply (auto)
apply (simp add: Renaming_channel_fun_simp)
apply (simp add: inj_on_def)
apply (force)
apply (simp add: Renaming_channel_fun_simp)
done

lemma cspT_Rec_prefix_Renaming1_channel2_step_in:
  "[| inj f ; inj g ; ALL x y. f x ~= g y |] ==>
     (f ? x:X -> Pf x)[[g<==>f]] =T[M,M] g ? x:X -> (Pf x)[[g<==>f]]"
apply (simp add: Renaming_commut)
apply (simp add: cspT_Rec_prefix_Renaming1_channel1_step_in)
done

(*
lemma Renaming_channel_fun_h:
   "[| ALL x y. f x ~= g y ; ALL x y. f x ~= h y ; ALL x y. g x ~= h y |]
    ==> Renaming_channel_fun f g (h x) = h x"
by (auto simp add: Renaming_channel_fun_def)

lemma Renaming_channel_fun_map_h:
   "[| (ALL x y. f x ~= h y) ;
       (ALL x y. g x ~= h y) ;
       ALL x y. f x ~= g y |]
    ==> Renaming_channel_fun f g ` h ` X = h ` X"
apply (simp add: image_def)
apply (auto simp add: Renaming_channel_fun_h)
done
*)

lemma cspT_Rec_prefix_Renaming1_channel_step_notin:
  "[| inj h;
      (ALL x y. f x ~= h y) | range f Int range h = {} ;
      (ALL x y. g x ~= h y) | range g Int range h = {} ;
       ALL x y. f x ~= g y |] ==>
    (h ? x:X -> Pf x)[[f<==>g]] =T[M,M] h ? x:X -> (Pf x)[[f<==>g]]"
apply (subgoal_tac "(ALL x y. f x ~= h y) & (ALL x y. g x ~= h y)")
apply (simp add: Renaming_channel_def)
apply (simp add: csp_prefix_ss_def)
apply (rule cspT_rw_left)
apply (rule cspT_Renaming_fun_step)
apply (rule cspT_decompo)
apply (simp add: Renaming_channel_fun_simp)

apply (simp add: image_iff)
apply (erule bexE)
apply (simp)
apply (subgoal_tac
  "{xa. (EX x:X. xa = h x) & h x = Renaming1_channel_fun f g xa} = {h x}")
apply (simp)
apply (rule cspT_rw_left)
apply (rule cspT_Rep_int_choice_singleton)
apply (simp)

apply (auto)
apply (simp add: Renaming_channel_fun_simp)
apply (simp add: Renaming_channel_fun_simp)
apply (blast)+
done

lemmas cspT_Rec_prefix_Renaming1_channel_step =
       cspT_Rec_prefix_Renaming1_channel1_step_in
       cspT_Rec_prefix_Renaming1_channel2_step_in
       cspT_Rec_prefix_Renaming1_channel_step_notin

(* <== *)

lemma cspT_Rec_prefix_Renaming2_channel_step_in:
  "[| inj f ; inj g ; ALL x y. f x ~= g y |] ==>
     (f ? x:X -> Pf x)[[f<==g]] =T[M,M] g ? x:X -> (Pf x)[[f<==g]]"
apply (simp add: Renaming_channel_def)
apply (simp add: csp_prefix_ss_def)
apply (rule cspT_rw_left)
apply (rule cspT_Renaming_fun_step)
apply (rule cspT_decompo)
apply (simp add: Renaming_channel_fun_simp)
apply (simp add: image_iff)
apply (erule bexE)
apply (simp)
apply (subgoal_tac
  "{xa. (EX x:X. xa = f x) & g x = Renaming2_channel_fun f g xa} = {f x}")
apply (simp)
apply (rule cspT_rw_left)
apply (rule cspT_Rep_int_choice_singleton)
apply (simp)

apply (auto)
apply (simp add: Renaming_channel_fun_simp)
apply (simp add: inj_on_def)
apply (force)
apply (simp add: Renaming_channel_fun_simp)
done

lemma cspT_Rec_prefix_Renaming2_channel_step_notin:
  "[| inj h;
      (ALL x y. f x ~= h y) | range f Int range h = {} ;
       ALL x y. f x ~= g y |] ==>
    (h ? x:X -> Pf x)[[f<==g]] =T[M,M] h ? x:X -> (Pf x)[[f<==g]]"
apply (subgoal_tac "(ALL x y. f x ~= h y)")
apply (simp add: Renaming_channel_def)
apply (simp add: csp_prefix_ss_def)
apply (rule cspT_rw_left)
apply (rule cspT_Renaming_fun_step)
apply (rule cspT_decompo)
apply (simp add: Renaming_channel_fun_simp)

apply (simp add: image_iff)
apply (erule bexE)
apply (simp)
apply (subgoal_tac
  "{xa. (EX x:X. xa = h x) & h x = Renaming2_channel_fun f g xa} = {h x}")
apply (simp)
apply (rule cspT_rw_left)
apply (rule cspT_Rep_int_choice_singleton)
apply (simp)

apply (auto)
apply (simp add: Renaming_channel_fun_simp)
apply (simp add: Renaming_channel_fun_simp)
apply (blast)+
done

lemmas cspT_Rec_prefix_Renaming2_channel_step =
       cspT_Rec_prefix_Renaming2_channel_step_in
       cspT_Rec_prefix_Renaming2_channel_step_notin

lemmas cspT_Rec_prefix_Renaming_channel_step =
       cspT_Rec_prefix_Renaming1_channel_step
       cspT_Rec_prefix_Renaming2_channel_step

lemmas cspT_Rec_prefix_Renaming_step =
       cspT_Rec_prefix_Renaming_event_step
       cspT_Rec_prefix_Renaming_channel_step

(* Nondet Sending *)

(* <--> *)

lemma cspT_Nondet_send_prefix_Renaming1_event1_step_in:
  "[| inj f ; v:X ; ALL x. a ~= f x |] ==>
     (f !? x:X -> Pf x)[[a<-->f v]] =T[M,M]
     (a -> (Pf v)[[a<-->f v]]) |~| f !? x:(X-{v}) -> (Pf x)[[a<-->f v]]"
apply (simp add: csp_prefix_ss_def)
apply (rule cspT_rw_left)
apply (rule cspT_Dist)
apply (subgoal_tac "(f ` X) = {f v} Un (f ` (X - {v}))")
apply (simp del: Un_insert_left)
apply (rule cspT_rw_left)
apply (rule cspT_Rep_int_choice_com_union_Int)
apply (rule cspT_decompo)

 (* 1 *)
 apply (rule cspT_rw_left)
 apply (rule cspT_Rep_int_choice_singleton)
 apply (simp add: cspT_Act_prefix_Renaming_event_step)

 (* 2 *)
 apply (rule cspT_decompo)
 apply (simp)
 apply (rule cspT_rw_left)
 apply (rule cspT_Act_prefix_Renaming_event_step)
 apply (auto)
 apply (simp add: inj_on_def)
done

lemma cspT_Nondet_send_prefix_Renaming1_event2_step_in:
  "[| inj f ; v:X ; ALL x. a ~= f x |] ==>
     (f !? x:X -> Pf x)[[f v<-->a]] =T[M,M]
     (a -> (Pf v)[[f v<-->a]]) |~| f !? x:(X-{v}) -> (Pf x)[[f v<-->a]]"
apply (simp add: Renaming_commut)
apply (simp add: cspT_Nondet_send_prefix_Renaming1_event1_step_in)
done

lemma cspT_Nondet_send_prefix_Renaming1_event_step_notin:
  "[| (ALL x. a ~= f x) | a ~: range f ;
      (ALL x. b ~= f x) | b ~: range f |] ==>
   (f !? x:X -> Pf x)[[a<-->b]] =T[M,M] f !? x:X -> (Pf x)[[a<-->b]]"
apply (simp add: csp_prefix_ss_def)
apply (rule cspT_rw_left)
apply (rule cspT_Dist)
apply (rule cspT_decompo)
apply (simp)
 apply (rule cspT_rw_left)
 apply (rule cspT_Act_prefix_Renaming_event_step)
 apply (auto)
done

lemmas cspT_Nondet_send_prefix_Renaming1_event_step =
       cspT_Nondet_send_prefix_Renaming1_event1_step_in
       cspT_Nondet_send_prefix_Renaming1_event2_step_in
       cspT_Nondet_send_prefix_Renaming1_event_step_notin

(* <<- *)

lemma cspT_Nondet_send_prefix_Renaming2_set_event_step_in:
  "[| inj f ; EX x:X. f x : A |] ==>
     (f !? x:X -> Pf x)[[A<<-a]] =T[M,M]
      a -> (!<f> x:{x:X. f x : A} .. (Pf x)[[A<<-a]])
     |~| f !? x:(X-{x. f x : A}) -> (Pf x)[[A<<-a]]"
apply (simp add: csp_prefix_ss_def)
apply (rule cspT_rw_left)
apply (rule cspT_Dist)
apply (rule cspT_rw_left)
apply (rule cspT_decompo)
apply (simp)
apply (rule cspT_decompo)
apply (simp)
apply (rule cspT_step)

apply (rule cspT_rw_left)
apply (rule cspT_decompo)
apply (simp)
apply (rule cspT_step)

apply (subgoal_tac "(f ` X) = (f ` {x : X. f x : A}) Un (f ` (X - {x. f x : A}))") (* 1 *)
 apply (simp del: Un_insert_left)
 apply (rule cspT_rw_left)
 apply (rule cspT_Rep_int_choice_com_union_Int)
 apply (rule cspT_decompo)

 (* left *)
 apply (subgoal_tac
  "a -> (!<f> x:{x : X. f x : A} .. Pf x [[A<<-a]])
   =T[M,M] !<f> x:{x : X. f x : A} .. a -> Pf x [[A<<-a]]")  (* 2 *)

  apply (rule cspT_rw_right)
  apply (assumption)
  apply (simp add: Rep_int_choice_f_def)
  apply (rule cspT_decompo)
  apply (simp)
  apply (simp add: image_iff)
  apply (elim conjE exE bexE)
  apply (simp)

  apply (rule cspT_rw_right)
  apply (rule cspT_step)
  apply (rule cspT_decompo)
  apply (simp add: Renaming_event_def)
  apply (simp add: Renaming_event_fun_def)
  apply (simp add: fun_to_rel_def)
  apply (force)

  apply (rule cspT_ref_eq)

   (* <= *)
   apply (rule cspT_Rep_int_choice_left)
   apply (simp add: Renaming_event_def)
   apply (simp add: Renaming_event_fun_def)
   apply (simp add: fun_to_rel_def)
   (* => *)
   apply (rule cspT_Rep_int_choice_right)
   apply (simp)

 (* 2 *)
  apply (rule cspT_rw_right)
  apply (rule cspT_choice_delay)
  apply (simp)
  apply (subgoal_tac "~(ALL x. x : X --> f x ~: A)")
   apply (simp (no_asm_simp))
   apply (rule cspT_rw_right)
   apply (rule cspT_IF_split)
   apply (simp)
  apply (force)

 (* right *)
 apply (rule cspT_decompo)
 apply (simp)

 apply (rule cspT_rw_right)
 apply (rule cspT_step)
 apply (rule cspT_decompo)
  apply (simp add: Renaming_event_def)
  apply (simp add: Renaming_event_fun_def)
  apply (simp add: fun_to_rel_def)
  apply (force)

 apply (simp)
 apply (rule cspT_ref_eq)

  (* <= *)
  apply (rule cspT_Rep_int_choice_left)
  apply (simp add: Renaming_event_def)
  apply (simp add: Renaming_event_fun_def)
  apply (simp add: fun_to_rel_def)
  apply (force)

  (* => *)
  apply (rule cspT_Rep_int_choice_right)
  apply (simp)

(* 1 *)
apply (auto)
done

lemma cspT_Nondet_send_prefix_Renaming2_set_event_step_notin:
  "[| (ALL x:X. f x ~: A) | A Int f ` X = {} |] ==>
     (f !? x:X -> Pf x)[[A<<-a]] =T[M,M]
      f !? x:X -> (Pf x)[[A<<-a]]"
apply (simp add: csp_prefix_ss_def)
apply (rule cspT_rw_left)
apply (rule cspT_Dist)
apply (rule cspT_decompo)
apply (simp)

apply (rule cspT_rw_left)
apply (rule cspT_decompo)
apply (simp)
apply (rule cspT_step)

apply (rule cspT_rw_left)
apply (rule cspT_step)

apply (rule cspT_rw_right)
apply (rule cspT_step)

apply (rule cspT_decompo)
 apply (simp add: Renaming_event_def)
 apply (simp add: Renaming_event_fun_def)
 apply (simp add: fun_to_rel_def)
 apply (force)

apply (simp)
 apply (rule cspT_ref_eq)

  (* <= *)
  apply (rule cspT_Rep_int_choice_left)
  apply (simp add: Renaming_event_def)
  apply (simp add: Renaming_event_fun_def)
  apply (simp add: fun_to_rel_def)
  apply (force)

  (* => *)
  apply (rule cspT_Rep_int_choice_right)
  apply (simp)
done

lemma cspT_Nondet_send_prefix_Renaming2_set_event_step:
  "inj f ==>
  (f !? x:X -> Pf x)[[A<<-a]] =T[M,M]
   IF (EX x:X. f x : A)
   THEN (a -> (!<f> x:{x:X. f x : A} .. (Pf x)[[A<<-a]])
         |~| f !? x:(X-{x. f x : A}) -> (Pf x)[[A<<-a]])
   ELSE (f !? x:X -> (Pf x)[[A<<-a]])"
apply (case_tac "EX x:X. f x : A")
apply (rule cspT_rw_left)
apply (rule cspT_Nondet_send_prefix_Renaming2_set_event_step_in)
apply (simp)
apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_IF_split)
apply (simp)
apply (rule cspT_rw_left)
apply (rule cspT_Nondet_send_prefix_Renaming2_set_event_step_notin)
apply (simp)
apply (simp)
apply (rule cspT_rw_right)
apply (rule cspT_IF_split)
apply (simp)
done

(* <-- *)

lemma cspT_Nondet_send_prefix_Renaming2_event_step_in:
  "[| inj f ; v:X ; ALL x. a ~= f x |] ==>
     (f !? x:X -> Pf x)[[f v<--a]] =T[M,M]
     (a -> (Pf v)[[f v<--a]]) |~| f !? x:(X-{v}) -> (Pf x)[[f v<--a]]"
apply (rule cspT_rw_left)
apply (rule cspT_Nondet_send_prefix_Renaming2_set_event_step_in)
apply (simp)
apply (simp)
apply (force)
apply (simp)

apply (rule cspT_decompo)
 apply (rule cspT_decompo)
 apply (simp)
 apply (subgoal_tac "{x : X. f x = f v}={v}")
 apply (simp)
 apply (rule cspT_rw_left)
 apply (rule cspT_Rep_int_choice_singleton)
 apply (simp)
 apply (simp)
 apply (simp add: inj_on_def)
 apply (force)

 apply (subgoal_tac "{x. f x = f v}={v}")
 apply (simp)
 apply (simp add: inj_on_def)
 apply (force)
done

lemma cspT_Nondet_send_prefix_Renaming2_event_step_notin:
  "[| (ALL x. a ~= f x) | a ~: range f |] ==>
   (f !? x:X -> Pf x)[[a<--b]] =T[M,M] f !? x:X -> (Pf x)[[a<--b]]"
apply (rule cspT_rw_left)
apply (rule cspT_Nondet_send_prefix_Renaming2_set_event_step_notin)
apply (simp)
apply (force)
apply (simp)
done

lemmas cspT_Nondet_send_prefix_Renaming2_event_step =
       cspT_Nondet_send_prefix_Renaming2_event_step_in
       cspT_Nondet_send_prefix_Renaming2_event_step_notin

lemmas cspT_Nondet_send_prefix_Renaming_event_step =
       cspT_Nondet_send_prefix_Renaming1_event_step
       cspT_Nondet_send_prefix_Renaming2_event_step

(* <==> *)

lemma cspT_Nondet_send_prefix_Renaming1_channel1_step_in:
  "[| inj f ; inj g ; ALL x y. f x ~= g y |] ==>
   (f !? x:X -> Pf x)[[f<==>g]] =T[M,M] g !? x:X -> (Pf x)[[f<==>g]]"
apply (simp add: csp_prefix_ss_def)
apply (rule cspT_rw_left)
apply (rule cspT_Dist)
apply (rule cspT_ref_eq)

(* <= *)
 apply (rule cspT_Rep_int_choice_right)
 apply (simp add: image_iff)
 apply (erule bexE)
 apply (simp)

 apply (rule cspT_Rep_int_choice_left)
 apply (rule_tac x="f x" in exI)
 apply (simp)
 apply (rule cspT_rw_left)
 apply (rule cspT_Act_prefix_Renaming_channel_step)
 apply (simp_all)

(* => *)
 apply (rule cspT_Rep_int_choice_right)
 apply (simp add: image_iff)
 apply (erule bexE)
 apply (simp)

 apply (rule cspT_Rep_int_choice_left)
 apply (rule_tac x="g x" in exI)
 apply (simp)
 apply (rule cspT_rw_right)
 apply (rule cspT_Act_prefix_Renaming_channel_step)
 apply (simp_all)
done

lemma cspT_Nondet_send_prefix_Renaming1_channel2_step_in:
  "[| inj f ; inj g ; ALL x y. f x ~= g y |] ==>
   (f !? x:X -> Pf x)[[g<==>f]] =T[M,M] g !? x:X -> (Pf x)[[g<==>f]]"
apply (simp add: Renaming_commut)
apply (simp add: cspT_Nondet_send_prefix_Renaming1_channel1_step_in)
done

lemma cspT_Nondet_send_prefix_Renaming1_channel_step_notin:
  "[| (ALL x y. f x ~= h y) | (range f Int range h = {}) ;
      (ALL x y. g x ~= h y) | (range g Int range h = {}) |] ==>
   (h !? x:X -> Pf x)[[f<==>g]] =T[M,M] h !? x:X -> (Pf x)[[f<==>g]]"
apply (simp add: csp_prefix_ss_def)
apply (rule cspT_rw_left)
apply (rule cspT_Dist)
apply (rule cspT_decompo)
apply (simp)

apply (rule cspT_rw_left)
apply (rule cspT_Act_prefix_Renaming_channel_step)
apply (blast)
apply (blast)
apply (simp)
done

lemmas cspT_Nondet_send_prefix_Renaming1_channel_step =
       cspT_Nondet_send_prefix_Renaming1_channel1_step_in
       cspT_Nondet_send_prefix_Renaming1_channel2_step_in
       cspT_Nondet_send_prefix_Renaming1_channel_step_notin

(* <== *)

lemma cspT_Nondet_send_prefix_Renaming2_channel_step_in:
  "[| inj f ; inj g ; ALL x y. f x ~= g y |] ==>
   (f !? x:X -> Pf x)[[f<==g]] =T[M,M] g !? x:X -> (Pf x)[[f<==g]]"
apply (simp add: csp_prefix_ss_def)
apply (rule cspT_rw_left)
apply (rule cspT_Dist)
apply (rule cspT_ref_eq)

(* <= *)
 apply (rule cspT_Rep_int_choice_right)
 apply (simp add: image_iff)
 apply (erule bexE)
 apply (simp)

 apply (rule cspT_Rep_int_choice_left)
 apply (rule_tac x="f x" in exI)
 apply (simp)
 apply (rule cspT_rw_left)
 apply (rule cspT_Act_prefix_Renaming_channel_step)
 apply (simp_all)

(* => *)
 apply (rule cspT_Rep_int_choice_right)
 apply (simp add: image_iff)
 apply (erule bexE)
 apply (simp)

 apply (rule cspT_Rep_int_choice_left)
 apply (rule_tac x="g x" in exI)
 apply (simp)
 apply (rule cspT_rw_right)
 apply (rule cspT_Act_prefix_Renaming_channel_step)
 apply (simp_all)
done

lemma cspT_Nondet_send_prefix_Renaming2_channel_step_notin:
  "[| (ALL x y. f x ~= h y) | (range f Int range h = {}) |] ==>
   (h !? x:X -> Pf x)[[f<==g]] =T[M,M] h !? x:X -> (Pf x)[[f<==g]]"
apply (simp add: csp_prefix_ss_def)
apply (rule cspT_rw_left)
apply (rule cspT_Dist)
apply (rule cspT_decompo)
apply (simp)

apply (rule cspT_rw_left)
apply (rule cspT_Act_prefix_Renaming_channel_step)
apply (blast)
apply (simp)
done

lemmas cspT_Nondet_send_prefix_Renaming2_channel_step =
       cspT_Nondet_send_prefix_Renaming2_channel_step_in
       cspT_Nondet_send_prefix_Renaming2_channel_step_notin

lemmas cspT_Nondet_send_prefix_Renaming_channel_step =
       cspT_Nondet_send_prefix_Renaming1_channel_step
       cspT_Nondet_send_prefix_Renaming2_channel_step

lemmas cspT_Nondet_send_prefix_Renaming_step =
       cspT_Nondet_send_prefix_Renaming_event_step
       cspT_Nondet_send_prefix_Renaming_channel_step

(* ---------------- *
      in or notin
 * ---------------- *)

lemmas cspT_prefix_Renaming_in_step =
       cspT_Act_prefix_Renaming1_event1_step_in
       cspT_Act_prefix_Renaming1_event2_step_in
       cspT_Act_prefix_Renaming1_channel1_step_in
       cspT_Act_prefix_Renaming1_channel2_step_in
       cspT_Send_prefix_Renaming1_event1_step_in
       cspT_Send_prefix_Renaming1_event2_step_in
       cspT_Send_prefix_Renaming1_channel1_step_in
       cspT_Send_prefix_Renaming1_channel2_step_in
       cspT_Rec_prefix_Renaming1_event1_step_in
       cspT_Rec_prefix_Renaming1_event2_step_in
       cspT_Rec_prefix_Renaming1_channel1_step_in
       cspT_Rec_prefix_Renaming1_channel2_step_in
       cspT_Nondet_send_prefix_Renaming1_event1_step_in
       cspT_Nondet_send_prefix_Renaming1_event2_step_in
       cspT_Nondet_send_prefix_Renaming1_channel1_step_in
       cspT_Nondet_send_prefix_Renaming1_channel2_step_in
       cspT_Act_prefix_Renaming2_event_step_in
       cspT_Act_prefix_Renaming2_channel_step_in
       cspT_Send_prefix_Renaming2_event_step_in
       cspT_Send_prefix_Renaming2_channel_step_in
       cspT_Rec_prefix_Renaming2_event_step_in
       cspT_Rec_prefix_Renaming2_channel_step_in
       cspT_Nondet_send_prefix_Renaming2_event_step_in
       cspT_Nondet_send_prefix_Renaming2_channel_step_in

(* notin + <<- + ?X *)

lemmas cspT_prefix_Renaming_notin_step =
       cspT_Act_prefix_Renaming1_event_step_notin
       cspT_Act_prefix_Renaming1_channel_step_notin
       cspT_Send_prefix_Renaming1_event_step_notin
       cspT_Send_prefix_Renaming1_channel_step_notin
       cspT_Rec_prefix_Renaming1_event_step_notin
       cspT_Rec_prefix_Renaming1_channel_step_notin
       cspT_Nondet_send_prefix_Renaming1_event_step_notin
       cspT_Nondet_send_prefix_Renaming1_channel_step_notin
       cspT_Act_prefix_Renaming2_event_step_notin
       cspT_Act_prefix_Renaming2_channel_step_notin
       cspT_Send_prefix_Renaming2_event_step_notin
       cspT_Send_prefix_Renaming2_channel_step_notin
       cspT_Rec_prefix_Renaming2_event_step_notin
       cspT_Rec_prefix_Renaming2_channel_step_notin
       cspT_Nondet_send_prefix_Renaming2_event_step_notin
       cspT_Nondet_send_prefix_Renaming2_channel_step_notin

       cspT_Act_prefix_Renaming2_set_event_step
       cspT_Send_prefix_Renaming2_set_event_step
       cspT_Rec_prefix_Renaming2_set_event_step
       cspT_Nondet_send_prefix_Renaming2_set_event_step

       cspT_Ext_pre_choice_Renaming_event_step

(* ----------------------------------------------------------- *)

end


theory MutualEx
  imports ECMP
begin

definition I :: "scalrValueType" where [simp]:
 "I \<equiv> enum ''CONTROL'' ''I''"

definition T :: "scalrValueType" where [simp]:
 "T \<equiv> enum ''CONTROL'' ''T''"

definition C :: "scalrValueType" where [simp]:
 "C \<equiv> enum ''CONTROL'' ''C''"

definition E :: "scalrValueType" where [simp]:
 "E \<equiv> enum ''CONTROL'' ''E''"

definition true :: "scalrValueType" where [simp]:
 "true \<equiv> boolV True"

definition false :: "scalrValueType" where [simp]:
 "false \<equiv> boolV False"

primrec env :: "nat => envType" where
"env N (Ident n) = (if Ident n = Ident ''Sta.x'' then
  boolType
else
  anyType
)"|
"env N (Para n i) = (if Para n i = Para ''Sta.n'' i \<and> (i \<le> N) then
  enumType
else
  anyType
)"|
"env N dontCareVar = anyType"

lemma env_simp :
             "[|i <= N|]
                 ==> env N (Para ''Sta.n'' i) = enumType"

"
                  env N (Ident ''Sta.x'') = boolType"

"[|i > N|]
                 ==> env N (Para n i) = anyType"

               apply(auto      )

done

definition initSpec0 :: "nat \<Rightarrow> formula" where [simp]:
 "initSpec0 N \<equiv> (\<forall>\<^sub>fi. IVar (Para ''Sta.n'' i) =\<^sub>f Const I) N"

lemma symPreds0 [intro]:
                  "
                  symPredSet' N {initSpec0 N}"
                 unfolding initSpec0_def   apply(rule symPredSetForall)
unfolding symParamForm_def  apply(auto      )

done

lemma deriveFormInitSpec0 [intro]:
                  "[|f : {initSpec0 N}|]
                 ==> deriveForm (env N) f"
                   apply(auto      )

done

definition initSpec1 :: "formula" where [simp]:
 "initSpec1 \<equiv> IVar (Ident ''Sta.x'') =\<^sub>f Const true"

lemma symPreds1 [intro]:
                  "
                  symPredSet' N {initSpec1}"
                   apply(auto      )

done

lemma deriveFormInitSpec1 [intro]:
                  "[|f : {initSpec1}|]
                 ==> deriveForm (env N) f"
                   apply(auto      )

done

definition allInitSpecs :: "nat \<Rightarrow> formula set" where [simp]:
 "allInitSpecs N \<equiv> {initSpec0 N} \<union> {initSpec1}"

lemma symPreds [intro]:
                  "
                  symPredSet' N (allInitSpecs N)"
                 unfolding allInitSpecs_def   apply(rule symPredsUnion)
  apply(blast      )

  apply(blast      )

done

lemma deriveFormAllInitSpec :
                  "[|f : allInitSpecs N|]
                 ==> deriveForm (env N) f"
                  using deriveFormInitSpec0 deriveFormInitSpec1 apply(auto      simp del: initSpec0_def initSpec1_def)

done

definition Try :: "nat \<Rightarrow> rule" where
 "Try i \<equiv>
   IVar (Para ''Sta.n'' i) =\<^sub>f Const I
  \<triangleright>
   assign (Para ''Sta.n'' i, Const T)"

lemma symTry :
             "
                  symParamRule N Try"

"[|i <= N|]
                 ==> wellFormedRule (env N) N (Try i)"

             unfolding Try_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )

unfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )

done

definition Trys :: "nat \<Rightarrow> rule set" where
 "Trys N \<equiv> oneParamCons N Try"

definition Crit :: "nat \<Rightarrow> rule" where
 "Crit i \<equiv>
   IVar (Para ''Sta.n'' i) =\<^sub>f Const T \<and>\<^sub>f
   IVar (Ident ''Sta.x'') =\<^sub>f Const true
  \<triangleright>
   assign (Para ''Sta.n'' i, Const C) ||
   assign (Ident ''Sta.x'', Const false)"

lemma symCrit :
             "
                  symParamRule N Crit"

"[|i <= N|]
                 ==> wellFormedRule (env N) N (Crit i)"

             unfolding Crit_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )

unfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )

done

definition Crits :: "nat \<Rightarrow> rule set" where
 "Crits N \<equiv> oneParamCons N Crit"

definition Exit :: "nat \<Rightarrow> rule" where
 "Exit i \<equiv>
   IVar (Para ''Sta.n'' i) =\<^sub>f Const C
  \<triangleright>
   assign (Para ''Sta.n'' i, Const E)"

lemma symExit :
             "
                  symParamRule N Exit"

"[|i <= N|]
                 ==> wellFormedRule (env N) N (Exit i)"

             unfolding Exit_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )

unfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )

done

definition Exits :: "nat \<Rightarrow> rule set" where
 "Exits N \<equiv> oneParamCons N Exit"

definition Idle :: "nat \<Rightarrow> rule" where
 "Idle i \<equiv>
   IVar (Para ''Sta.n'' i) =\<^sub>f Const E
  \<triangleright>
   assign (Para ''Sta.n'' i, Const I) ||
   assign (Ident ''Sta.x'', Const true)"

lemma symIdle :
             "
                  symParamRule N Idle"

"[|i <= N|]
                 ==> wellFormedRule (env N) N (Idle i)"

             unfolding Idle_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )

unfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )

done

definition Idles :: "nat \<Rightarrow> rule set" where
 "Idles N \<equiv> oneParamCons N Idle"

definition MutualExclusion :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> formula" where
 "MutualExclusion N i j \<equiv> \<not>\<^sub>f Const (index i) =\<^sub>f Const (index j) \<longrightarrow>\<^sub>f
  \<not>\<^sub>f (IVar (Para ''Sta.n'' i) =\<^sub>f Const E \<and>\<^sub>f
  IVar (Para ''Sta.n'' j) =\<^sub>f Const E)"

definition ABS_Crit :: "rule" where
 "ABS_Crit \<equiv>
   IVar (Ident ''Sta.x'') =\<^sub>f Const true
  \<triangleright>
   assign (Ident ''Sta.x'', Const false)"

definition ABS_Crits :: "rule set" where
 "ABS_Crits \<equiv> {ABS_Crit}"

definition ABS_Idle :: "nat \<Rightarrow> rule" where
 "ABS_Idle N \<equiv>
   (\<forall>\<^sub>fj. \<not>\<^sub>f IVar (Para ''Sta.n'' j) =\<^sub>f Const C \<and>\<^sub>f
   \<not>\<^sub>f IVar (Para ''Sta.n'' j) =\<^sub>f Const E) N
  \<triangleright>
   assign (Ident ''Sta.x'', Const true)"

definition ABS_Idles :: "nat \<Rightarrow> rule set" where
 "ABS_Idles N \<equiv> {ABS_Idle N}"

definition Lemma_1 :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> formula" where
 "Lemma_1 N p i \<equiv> IVar (Para ''Sta.n'' i) =\<^sub>f Const E \<longrightarrow>\<^sub>f
  forallFormExcl (\<lambda>j. \<not>\<^sub>f IVar (Para ''Sta.n'' j) =\<^sub>f Const C \<and>\<^sub>f
  \<not>\<^sub>f IVar (Para ''Sta.n'' j) =\<^sub>f Const E) i N"

definition rules :: "nat \<Rightarrow> rule set" where
 "rules N = (Trys N \<union> (Crits N \<union> (Exits N \<union> Idles N)))"

lemma deriveAll :
             "[|r : Trys N|]
                 ==> deriveRule (env N) r"

"[|r : Crits N|]
                 ==> deriveRule (env N) r"

"[|r : Exits N|]
                 ==> deriveRule (env N) r"

"[|r : Idles N|]
                 ==> deriveRule (env N) r"

"[|r : ABS_Crits|]
                 ==> deriveRule (env N) r"

"[|r : ABS_Idles N|]
                 ==> deriveRule (env N) r"

             unfolding deriveRule_def deriveForm_def deriveStmt_def Trys_def Try_def Crits_def Crit_def Exits_def Exit_def Idles_def Idle_def ABS_Crits_def ABS_Crit_def ABS_Idles_def ABS_Idle_def  apply(auto      )

done

lemma symProtAll :
             "
                  symProtRules' N (Trys N)"

"
                  symProtRules' N (Crits N)"

"
                  symProtRules' N (Exits N)"

"
                  symProtRules' N (Idles N)"

              using symTry(1) Trys_def symParaRuleInfSymRuleSet symParaRuleInfSymRuleSet2 apply(auto      )[1]

 using symCrit(1) Crits_def symParaRuleInfSymRuleSet symParaRuleInfSymRuleSet2 apply(auto      )[1]

 using symExit(1) Exits_def symParaRuleInfSymRuleSet symParaRuleInfSymRuleSet2 apply(auto      )[1]

 using symIdle(1) Idles_def symParaRuleInfSymRuleSet symParaRuleInfSymRuleSet2 apply(auto      )[1]

done

lemma symMutualExclusion :
                  "
                  symParamForm2 N (MutualExclusion N)"
                 unfolding MutualExclusion_def  apply(auto      )

  apply(intro  symParamForm2Imply symParamFormForallExcl2 )

unfolding symParamForm2_def  apply(auto      )

done

lemma symLemma_1 :
                  "
                  symParamForm2 N (Lemma_1 N)"
                 unfolding Lemma_1_def  apply(auto      )

  apply(intro  symParamForm2Imply symParamFormForallExcl2 )

unfolding symParamForm2_def  apply(auto      )

done

definition lemmasFor_Try :: "nat \<Rightarrow> ((nat \<Rightarrow> nat \<Rightarrow> formula) list)" where
 "lemmasFor_Try N = []"

definition Try_ref :: "nat \<Rightarrow> rule" where
 "Try_ref i \<equiv>
   IVar (Para ''Sta.n'' i) =\<^sub>f Const I
  \<triangleright>
   assign (Para ''Sta.n'' i, Const T)"

lemma symTry_ref :
             "
                  symParamRule N Try_ref"

"[|i <= N|]
                 ==> wellFormedRule (env N) N (Try_ref i)"

             unfolding Try_ref_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )

unfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )

done

definition Try_refs :: "nat \<Rightarrow> rule set" where
 "Try_refs N \<equiv> oneParamCons N Try_ref"

lemma Try_strengthen :
                  "
                  strengthenRuleByFrmL2 (map2' (lemmasFor_Try N) j i) (Try i) = Try_ref i"
                 unfolding lemmasFor_Try_def  Try_def Try_ref_def  apply(auto      )

done

lemma abs_Try_ref :
             "[|M <= N;i <= M|]
                 ==> absTransfRule (env N) M (Try_ref i) = Try_ref i"

"[|M <= N;i > M|]
                 ==> absTransfRule (env N) M (Try_ref i) = skipRule"

             unfolding Try_ref_def Try_ref_def skipRule_def  apply(auto     simp add: Let_def )

done

definition lemmasFor_Crit :: "nat \<Rightarrow> ((nat \<Rightarrow> nat \<Rightarrow> formula) list)" where
 "lemmasFor_Crit N = []"

definition Crit_ref :: "nat \<Rightarrow> rule" where
 "Crit_ref i \<equiv>
   IVar (Para ''Sta.n'' i) =\<^sub>f Const T \<and>\<^sub>f
   IVar (Ident ''Sta.x'') =\<^sub>f Const true
  \<triangleright>
   assign (Para ''Sta.n'' i, Const C) ||
   assign (Ident ''Sta.x'', Const false)"

lemma symCrit_ref :
             "
                  symParamRule N Crit_ref"

"[|i <= N|]
                 ==> wellFormedRule (env N) N (Crit_ref i)"

             unfolding Crit_ref_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )

unfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )

done

definition Crit_refs :: "nat \<Rightarrow> rule set" where
 "Crit_refs N \<equiv> oneParamCons N Crit_ref"

lemma Crit_strengthen :
                  "
                  strengthenRuleByFrmL2 (map2' (lemmasFor_Crit N) j i) (Crit i) = Crit_ref i"
                 unfolding lemmasFor_Crit_def  Crit_def Crit_ref_def  apply(auto      )

done

lemma abs_Crit_ref :
             "[|M <= N;i <= M|]
                 ==> absTransfRule (env N) M (Crit_ref i) = Crit_ref i"

"[|M <= N;i > M|]
                 ==> absTransfRule (env N) M (Crit_ref i) = ABS_Crit"

             unfolding Crit_ref_def Crit_ref_def ABS_Crit_def  apply(auto     simp add: Let_def )

done

definition lemmasFor_Exit :: "nat \<Rightarrow> ((nat \<Rightarrow> nat \<Rightarrow> formula) list)" where
 "lemmasFor_Exit N = []"

definition Exit_ref :: "nat \<Rightarrow> rule" where
 "Exit_ref i \<equiv>
   IVar (Para ''Sta.n'' i) =\<^sub>f Const C
  \<triangleright>
   assign (Para ''Sta.n'' i, Const E)"

lemma symExit_ref :
             "
                  symParamRule N Exit_ref"

"[|i <= N|]
                 ==> wellFormedRule (env N) N (Exit_ref i)"

             unfolding Exit_ref_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )

unfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )

done

definition Exit_refs :: "nat \<Rightarrow> rule set" where
 "Exit_refs N \<equiv> oneParamCons N Exit_ref"

lemma Exit_strengthen :
                  "
                  strengthenRuleByFrmL2 (map2' (lemmasFor_Exit N) j i) (Exit i) = Exit_ref i"
                 unfolding lemmasFor_Exit_def  Exit_def Exit_ref_def  apply(auto      )

done

lemma abs_Exit_ref :
             "[|M <= N;i <= M|]
                 ==> absTransfRule (env N) M (Exit_ref i) = Exit_ref i"

"[|M <= N;i > M|]
                 ==> absTransfRule (env N) M (Exit_ref i) = skipRule"

             unfolding Exit_ref_def Exit_ref_def skipRule_def  apply(auto     simp add: Let_def )

done

definition lemmasFor_Idle :: "nat \<Rightarrow> ((nat \<Rightarrow> nat \<Rightarrow> formula) list)" where
 "lemmasFor_Idle N = [Lemma_1 N]"

definition Idle_ref :: "nat \<Rightarrow> nat \<Rightarrow> rule" where
 "Idle_ref N i \<equiv>
   IVar (Para ''Sta.n'' i) =\<^sub>f Const E \<and>\<^sub>f
   forallFormExcl (\<lambda>j. \<not>\<^sub>f IVar (Para ''Sta.n'' j) =\<^sub>f Const C \<and>\<^sub>f
   \<not>\<^sub>f IVar (Para ''Sta.n'' j) =\<^sub>f Const E) i N
  \<triangleright>
   assign (Para ''Sta.n'' i, Const I) ||
   assign (Ident ''Sta.x'', Const true)"

lemma symIdle_ref :
             "
                  symParamRule N (Idle_ref N)"

"[|i <= N|]
                 ==> wellFormedRule (env N) N (Idle_ref N i)"

             unfolding Idle_ref_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )

unfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )

done

definition Idle_refs :: "nat \<Rightarrow> rule set" where
 "Idle_refs N \<equiv> oneParamCons N (Idle_ref N)"

lemma Idle_strengthen :
                  "
                  strengthenRuleByFrmL2 (map2' (lemmasFor_Idle N) j i) (Idle i) = Idle_ref N i"
                 unfolding lemmasFor_Idle_def Lemma_1_def Idle_def Idle_ref_def  apply(auto      )

done

lemma abs_Idle_ref :
             "[|M <= N;i <= M|]
                 ==> absTransfRule (env N) M (Idle_ref N i) = Idle_ref M i"

"[|M <= N;i > M|]
                 ==> absTransfRule (env N) M (Idle_ref N i) = ABS_Idle M"

             unfolding Idle_ref_def Idle_ref_def ABS_Idle_def  apply(auto     simp add: Let_def )

done

definition InvS :: "nat \<Rightarrow> (((nat \<Rightarrow> nat \<Rightarrow> formula) list) list)" where
 "InvS N = [lemmasFor_Try N, lemmasFor_Crit N, lemmasFor_Exit N, lemmasFor_Idle N]"

definition rule_refs :: "nat \<Rightarrow> rule set" where
 "rule_refs N = (Try_refs N \<union> (Crit_refs N \<union> (Exit_refs N \<union> Idle_refs N)))"

lemma TryStrengthRel :
                  "
                  strengthenRel (Trys N) (set (InvS N)) (Try_refs N) N"
                 unfolding Trys_def Try_refs_def  apply(rule_tac ?lemmasFor_r="lemmasFor_Try" in strengthenExt1)
 using Try_strengthen apply(presburger      )

unfolding InvS_def  apply(auto      )

done

lemma CritStrengthRel :
                  "
                  strengthenRel (Crits N) (set (InvS N)) (Crit_refs N) N"
                 unfolding Crits_def Crit_refs_def  apply(rule_tac ?lemmasFor_r="lemmasFor_Crit" in strengthenExt1)
 using Crit_strengthen apply(presburger      )

unfolding InvS_def  apply(auto      )

done

lemma ExitStrengthRel :
                  "
                  strengthenRel (Exits N) (set (InvS N)) (Exit_refs N) N"
                 unfolding Exits_def Exit_refs_def  apply(rule_tac ?lemmasFor_r="lemmasFor_Exit" in strengthenExt1)
 using Exit_strengthen apply(presburger      )

unfolding InvS_def  apply(auto      )

done

lemma IdleStrengthRel :
                  "
                  strengthenRel (Idles N) (set (InvS N)) (Idle_refs N) N"
                 unfolding Idles_def Idle_refs_def  apply(rule_tac ?lemmasFor_r="lemmasFor_Idle" in strengthenExt1)
 using Idle_strengthen apply(presburger      )

unfolding InvS_def  apply(auto      )

done

lemma deriveAllRef :
             "[|r : Try_refs N|]
                 ==> deriveRule (env N) r"

"[|r : Crit_refs N|]
                 ==> deriveRule (env N) r"

"[|r : Exit_refs N|]
                 ==> deriveRule (env N) r"

"[|r : Idle_refs N|]
                 ==> deriveRule (env N) r"

             unfolding deriveRule_def deriveForm_def deriveStmt_def Try_refs_def Try_ref_def Crit_refs_def Crit_ref_def Exit_refs_def Exit_ref_def Idle_refs_def Idle_ref_def  apply(auto      )

done

lemma symProtAllRef :
             "
                  symProtRules' N (Try_refs N)"

"
                  symProtRules' N (Crit_refs N)"

"
                  symProtRules' N (Exit_refs N)"

"
                  symProtRules' N (Idle_refs N)"

              using symTry_ref(1) Try_refs_def symCrit_ref(1) Crit_refs_def symExit_ref(1) Exit_refs_def symIdle_ref(1) Idle_refs_def symParaRuleInfSymRuleSet symParaRuleInfSymRuleSet2 apply(auto      )

done

lemma StrengthRelRules2Rule_refs :
                  "
                  strengthenRel (rules N) (set (InvS N)) (rule_refs N) N"
                 unfolding rules_def rule_refs_def   apply(rule strenRelUnion)
  apply(blast intro: TryStrengthRel     )

   apply(rule strenRelUnion)
  apply(blast intro: CritStrengthRel     )

   apply(rule strenRelUnion)
  apply(blast intro: ExitStrengthRel     )

  apply(blast intro: IdleStrengthRel     )

done

lemma Abs_Try_refs :
                  "[|M < N|]
                 ==> (absTransfRule (env N) M ` Try_refs N) = (Try_refs M Un {skipRule})"
                 unfolding Try_refs_def   apply(rule absGen)
 using abs_Try_ref apply(auto      )

done

lemma Abs_Crit_refs :
                  "[|M < N|]
                 ==> (absTransfRule (env N) M ` Crit_refs N) = (Crit_refs M Un ABS_Crits)"
                 unfolding Crit_refs_def ABS_Crits_def   apply(rule absGen)
 using abs_Crit_ref apply(auto      )

done

lemma Abs_Exit_refs :
                  "[|M < N|]
                 ==> (absTransfRule (env N) M ` Exit_refs N) = (Exit_refs M Un {skipRule})"
                 unfolding Exit_refs_def   apply(rule absGen)
 using abs_Exit_ref apply(auto      )

done

lemma Abs_Idle_refs :
                  "[|M < N|]
                 ==> (absTransfRule (env N) M ` Idle_refs N) = (Idle_refs M Un ABS_Idles M)"
                 unfolding Idle_refs_def ABS_Idles_def   apply(rule absGen)
 using abs_Idle_ref apply(auto      )

done

definition ABS_rules :: "nat \<Rightarrow> rule set" where [simp]:
 "ABS_rules N = (Try_refs N \<union> (Crit_refs N \<union> (ABS_Crits \<union> (Exit_refs N \<union> (Idle_refs N \<union> (ABS_Idles N \<union> {skipRule}))))))"

definition ABS_rules' :: "nat \<Rightarrow> rule set" where [simp]:
 "ABS_rules' N = ((Try_refs N \<union> {skipRule}) \<union> ((Crit_refs N \<union> ABS_Crits) \<union> ((Exit_refs N \<union> {skipRule}) \<union> (Idle_refs N \<union> ABS_Idles N))))"

lemma ABS_rules_eq_rules' :
                  "
                  ABS_rules M = ABS_rules' M"
                   apply(auto      )

done

lemma ABS_all :
                  "[|M < N|]
                 ==> (absTransfRule (env N) M ` rule_refs N) = ABS_rules M"
                   apply(subst ABS_rules_eq_rules'       )

unfolding rule_refs_def ABS_rules'_def  apply(intro  image_UnI )

  apply(auto     simp add: Abs_Try_refs Abs_Crit_refs Abs_Exit_refs Abs_Idle_refs )

done

definition Lemma_1' :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> formula" where
 "Lemma_1' N i j \<equiv> \<not>\<^sub>f Const (index i) =\<^sub>f Const (index j) \<and>\<^sub>f
  IVar (Para ''Sta.n'' i) =\<^sub>f Const E \<longrightarrow>\<^sub>f
  \<not>\<^sub>f IVar (Para ''Sta.n'' j) =\<^sub>f Const C \<and>\<^sub>f
  \<not>\<^sub>f IVar (Para ''Sta.n'' j) =\<^sub>f Const E"

lemma absTransfLemma_1' :
                  "[|M < N;M = 1;l <= 1|]
                 ==> absTransfForm (env N) M (Lemma_1' N 0 l) = Lemma_1' N 0 l"
                 unfolding Lemma_1'_def  apply(auto      )

done

lemma strengthenVsObsLemma_1 :
                  "
                  strengthenVsObs (Lemma_1 N) (Lemma_1' N) N"
                 unfolding Lemma_1_def Lemma_1'_def   apply(rule strengthenVsObsDiff)
unfolding symParamForm_def  apply(auto      )

done

lemma SafeAndderiveFormLemma_1' :
                  "[|M < N;M = 1;l <= M;k <= M|]
                 ==> safeForm (env N) M (Lemma_1' N k l) & deriveForm (env N) (Lemma_1' N k l)"
                 unfolding Lemma_1'_def  apply(auto      )

done

lemma symInvs :
             "
                  symParamForm2 N (Lemma_1' N)"

             unfolding Lemma_1'_def  apply(auto      )

subgoal    apply(intro  symParamForm2Imply symParamFormForallExcl2 )

  unfolding symParamForm2_def  apply(auto      )
   done

done

definition lemmasFor_Try' :: "nat \<Rightarrow> ((nat \<Rightarrow> nat \<Rightarrow> formula) list)" where
 "lemmasFor_Try' N = []"

lemma strengthenVsObsLs_lemmasFor_Try :
                  "
                  strengthenVsObsLs (lemmasFor_Try N) (lemmasFor_Try' N) N"
                 unfolding strengthenVsObsLs_def lemmasFor_Try_def lemmasFor_Try'_def  apply(auto      )

done

lemma lemmaTry_fitEnv :
                  "[|formEval (pre r) s;fitEnv s (env N);r : Try_refs N|]
                 ==> fitEnv (trans1 (act r) s) (env N)"
                 unfolding Try_refs_def Try_ref_def  apply(auto      )

done

definition lemmasFor_Crit' :: "nat \<Rightarrow> ((nat \<Rightarrow> nat \<Rightarrow> formula) list)" where
 "lemmasFor_Crit' N = []"

lemma strengthenVsObsLs_lemmasFor_Crit :
                  "
                  strengthenVsObsLs (lemmasFor_Crit N) (lemmasFor_Crit' N) N"
                 unfolding strengthenVsObsLs_def lemmasFor_Crit_def lemmasFor_Crit'_def  apply(auto      )

done

lemma lemmaCrit_fitEnv :
                  "[|formEval (pre r) s;fitEnv s (env N);r : Crit_refs N|]
                 ==> fitEnv (trans1 (act r) s) (env N)"
                 unfolding Crit_refs_def Crit_ref_def  apply(auto      )

done

definition lemmasFor_Exit' :: "nat \<Rightarrow> ((nat \<Rightarrow> nat \<Rightarrow> formula) list)" where
 "lemmasFor_Exit' N = []"

lemma strengthenVsObsLs_lemmasFor_Exit :
                  "
                  strengthenVsObsLs (lemmasFor_Exit N) (lemmasFor_Exit' N) N"
                 unfolding strengthenVsObsLs_def lemmasFor_Exit_def lemmasFor_Exit'_def  apply(auto      )

done

lemma lemmaExit_fitEnv :
                  "[|formEval (pre r) s;fitEnv s (env N);r : Exit_refs N|]
                 ==> fitEnv (trans1 (act r) s) (env N)"
                 unfolding Exit_refs_def Exit_ref_def  apply(auto      )

done

definition lemmasFor_Idle' :: "nat \<Rightarrow> ((nat \<Rightarrow> nat \<Rightarrow> formula) list)" where
 "lemmasFor_Idle' N = [Lemma_1' N]"

lemma strengthenVsObsLs_lemmasFor_Idle :
                  "
                  strengthenVsObsLs (lemmasFor_Idle N) (lemmasFor_Idle' N) N"
                 unfolding strengthenVsObsLs_def lemmasFor_Idle_def lemmasFor_Idle'_def  apply(auto intro: strengthenVsObsLemma_1     )

done

lemma lemmaIdle_fitEnv :
                  "[|formEval (pre r) s;fitEnv s (env N);r : Idle_refs N|]
                 ==> fitEnv (trans1 (act r) s) (env N)"
                 unfolding Idle_refs_def Idle_ref_def  apply(auto      )

done

definition InvS' :: "nat \<Rightarrow> (((nat \<Rightarrow> nat \<Rightarrow> formula) list) list)" where
 "InvS' N = [lemmasFor_Try' N, lemmasFor_Crit' N, lemmasFor_Exit' N, lemmasFor_Idle' N]"

lemma wellFormedRule_refs :
                  "[|r : rule_refs N|]
                 ==> wellFormedRule (env N) N r"
                   apply(auto     simp add: rule_refs_def   Try_refs_def Crit_refs_def Exit_refs_def Idle_refs_def symTry_ref symCrit_ref symExit_ref symIdle_ref )

done

lemma SafeAndderiveAll :
                  "[|M < N;M = 1;l <= M;k <= M;pinvL : set (InvS' N);pf : set pinvL|]
                 ==> safeForm (env N) M (pf k l) & deriveForm (env N) (pf k l)"
                 unfolding InvS'_def lemmasFor_Try'_def lemmasFor_Crit'_def lemmasFor_Exit'_def lemmasFor_Idle'_def using SafeAndderiveFormLemma_1' apply(auto      )

done

lemma rulesIsSym :
                  "
                  symProtRules' N (rules N)"
                 unfolding rules_def   apply(rule symProtRulesUnion, blast intro:symProtAll)+
unfolding rules_def  apply(blast intro: symProtAll     )

done

lemma rule_refsIsSym :
                  "
                  symProtRules' N (rule_refs N)"
                 unfolding rule_refs_def   apply(rule symProtRulesUnion, blast intro:symProtAllRef)+
unfolding rule_refs_def  apply(blast intro: symProtAllRef     )

done

lemma rule_refsWellTyped :
                  "[|r : rule_refs N|]
                 ==> deriveRule (env N) r"
                 unfolding rule_refs_def using deriveAllRef apply(auto      )

done

lemma ReachStafitEnv :
                  "[|reachableUpTo (allInitSpecs N) (rule_refs N) k s|]
                 ==> fitEnv s (env N)"
                   apply(erule invIntro1)
subgoal for s0
  unfolding fitEnv_def   apply(rule allI)
     apply(rule impI)
  apply(case_tac   "v")

  subgoal for v x1
    apply(case_tac   "x1 = ''Sta.x''")

    apply(subgoal_tac   "formEval (initSpec1) s0")

      apply(auto      )[1]

      apply(auto      )[1]

      apply(auto      )
     done

  subgoal for v x21 x22
    apply(case_tac   "x21 = ''Sta.n''")

    apply(subgoal_tac   "formEval (initSpec0 N) s0")

      apply(auto      )[1]

      apply(auto      )[1]

      apply(auto      )
     done

    apply(auto      )
   done

subgoal for r sk
  unfolding rule_refs_def  apply(auto intro: Un_iff lemmaTry_fitEnv lemmaCrit_fitEnv lemmaExit_fitEnv lemmaIdle_fitEnv     )
   done

done

lemma absProtSim :
                  "[|M < N;M = 1;isProtObsInvSet (ABS_rules M) (absTransfForm (env N) M ` allInitSpecs N) (set (InvS' N)) M (env N)|]
                 ==> isParamProtInvSet (rules N) (allInitSpecs N) (set (InvS N)) N"
                   apply(rule_tac ?rs2.0 = "rule_refs N" and env="env N" and S="set (InvS N)" and S'="set (InvS' N)" and M=M and absRules="ABS_rules M" in CMP)
subgoal for r
   using wellFormedRule_refs apply(auto      )
   done

subgoal  unfolding InvS'_def lemmasFor_Try'_def lemmasFor_Crit'_def lemmasFor_Exit'_def lemmasFor_Idle'_def using symInvs apply(auto      )
   done

subgoal   using rulesIsSym apply(auto      )
   done

subgoal   using symPreds apply(auto      )
   done

subgoal    apply(auto      )
   done

subgoal    apply(auto      )
   done

subgoal   using SafeAndderiveAll apply(auto      )
   done

subgoal   using StrengthRelRules2Rule_refs apply(auto      )
   done

subgoal   using rule_refsIsSym apply(auto      )
   done

subgoal   using rule_refsWellTyped apply(auto      )
   done

subgoal    apply(auto      )
   done

subgoal   using ReachStafitEnv apply(auto      )
   done

subgoal  unfolding InvS_def InvS'_def  apply(auto      )

  subgoal   using strengthenVsObsLs_lemmasFor_Try apply(auto      )
     done

  subgoal   using strengthenVsObsLs_lemmasFor_Crit apply(auto      )
     done

  subgoal   using strengthenVsObsLs_lemmasFor_Exit apply(auto      )
     done

  subgoal   using strengthenVsObsLs_lemmasFor_Idle apply(auto      )
     done
  done

   apply(rule equivRuleSetReflex)
 using ABS_all  apply(auto      )

done

end