src/HOL/MicroJava/BV/Kildall.thy
changeset 11298 acd83fa66e92
parent 11229 f417841385b7
child 11299 1d3d110c456e
equal deleted inserted replaced
11297:2d73013f3a41 11298:acd83fa66e92
    18 "mono r step n A ==
    18 "mono r step n A ==
    19  !s p t. s : A & p < n & s <=_r t --> step p s <=_r step p t"
    19  !s p t. s : A & p < n & s <=_r t --> step p s <=_r step p t"
    20 
    20 
    21 consts
    21 consts
    22  iter :: "'s binop \<Rightarrow> (nat \<Rightarrow> 's \<Rightarrow> 's) \<Rightarrow> (nat \<Rightarrow> nat list) \<Rightarrow>
    22  iter :: "'s binop \<Rightarrow> (nat \<Rightarrow> 's \<Rightarrow> 's) \<Rightarrow> (nat \<Rightarrow> nat list) \<Rightarrow>
    23           's list \<Rightarrow> nat set \<Rightarrow> 's list"
    23           's list \<Rightarrow> nat set \<Rightarrow> 's list \<times> nat set"
    24  propa :: "'s binop => nat list => 's => 's list => nat set => 's list * nat set"
    24  propa :: "'s binop => nat list => 's => 's list => nat set => 's list * nat set"
    25 
    25 
    26 primrec
    26 primrec
    27 "propa f []     t ss w = (ss,w)"
    27 "propa f []     t ss w = (ss,w)"
    28 "propa f (q#qs) t ss w = (let u = t +_f ss!q;
    28 "propa f (q#qs) t ss w = (let u = t +_f ss!q;
    29                               w' = (if u = ss!q then w else insert q w)
    29                               w' = (if u = ss!q then w else insert q w)
    30                           in propa f qs t (ss[q := u]) w')"
    30                           in propa f qs t (ss[q := u]) w')"
    31 
    31 
    32 defs iter_def:
    32 defs iter_def:
    33 "iter f step succs ss w ==
    33 "iter f step succs ss w ==
    34  fst(while (%(ss,w). w \<noteq> {})
    34  while (%(ss,w). w \<noteq> {})
    35            (%(ss,w). let p = SOME p. p : w
    35        (%(ss,w). let p = SOME p. p : w
    36                      in propa f (succs p) (step p (ss!p)) ss (w-{p}))
    36                  in propa f (succs p) (step p (ss!p)) ss (w-{p}))
    37            (ss,w))"
    37        (ss,w)"
    38 
    38 
    39 constdefs
    39 constdefs
    40  unstables ::
    40  unstables ::
    41  "'s binop => (nat => 's => 's) => (nat => nat list) => 's list => nat set"
    41  "'s ord => (nat => 's => 's) => (nat => nat list) => 's list => nat set"
    42 "unstables f step succs ss ==
    42 "unstables r step succs ss ==
    43  {p. p < size ss & (? q:set(succs p). step p (ss!p) +_f ss!q ~= ss!q)}"
    43  {p. p < size ss & ~stable r step succs ss p}"
    44 
    44 
    45  kildall :: "'s binop => (nat => 's => 's) => (nat => nat list)
    45  kildall :: "'s ord => 's binop => (nat => 's => 's) => (nat => nat list)
    46              => 's list => 's list"
    46              => 's list => 's list"
    47 "kildall f step succs ss == iter f step succs ss (unstables f step succs ss)"
    47 "kildall r f step succs ss == fst(iter f step succs ss (unstables r step succs ss))"
    48 
    48 
    49 consts merges :: "'s binop => 's => nat list => 's list => 's list"
    49 consts merges :: "'s binop => 's => nat list => 's list => 's list"
    50 primrec
    50 primrec
    51 "merges f s []     ss = ss"
    51 "merges f s []     ss = ss"
    52 "merges f s (p#ps) ss = merges f s ps (ss[p := s +_f ss!p])"
    52 "merges f s (p#ps) ss = merges f s ps (ss[p := s +_f ss!p])"
   260    apply (simp cong add: conj_cong add: le_iff_plus_unchanged [symmetric])
   260    apply (simp cong add: conj_cong add: le_iff_plus_unchanged [symmetric])
   261    apply (blast intro!: psubsetI elim: equalityE)
   261    apply (blast intro!: psubsetI elim: equalityE)
   262   apply simp
   262   apply simp
   263   done
   263   done
   264 
   264 
   265 lemma while_properties:
   265 lemma iter_properties[rule_format]:
   266   "\<lbrakk> semilat(A,r,f); acc r ; pres_type step n A; mono r step n A;
   266   "\<lbrakk> semilat(A,r,f); acc r ; pres_type step n A; mono r step n A;
   267      bounded succs n; \<forall>p\<in>w0. p < n; ss0 \<in> list n A;
   267      bounded succs n; \<forall>p\<in>w0. p < n; ss0 \<in> list n A;
   268      \<forall>p<n. p \<notin> w0 \<longrightarrow> stable r step succs ss0 p \<rbrakk> \<Longrightarrow>
   268      \<forall>p<n. p \<notin> w0 \<longrightarrow> stable r step succs ss0 p \<rbrakk> \<Longrightarrow>
   269    ss' = fst(while (%(ss,w). w \<noteq> {})
   269    iter f step succs ss0 w0 = (ss',w')
   270          (%(ss,w). let p = SOME p. p \<in> w
       
   271                    in propa f (succs p) (step p (ss!p)) ss (w-{p})) (ss0,w0))
       
   272    \<longrightarrow>
   270    \<longrightarrow>
   273    ss' \<in> list n A \<and> stables r step succs ss' \<and> ss0 <=[r] ss' \<and>
   271    ss' \<in> list n A \<and> stables r step succs ss' \<and> ss0 <=[r] ss' \<and>
   274    (\<forall>ts\<in>list n A. ss0 <=[r] ts \<and> stables r step succs ts \<longrightarrow> ss' <=[r] ts)"
   272    (\<forall>ts\<in>list n A. ss0 <=[r] ts \<and> stables r step succs ts \<longrightarrow> ss' <=[r] ts)"
   275 apply (unfold stables_def)
   273 apply (unfold iter_def stables_def)
   276 apply (rule_tac P = "%(ss,w).
   274 apply (rule_tac P = "%(ss,w).
   277  ss \<in> list n A \<and> (\<forall>p<n. p \<notin> w \<longrightarrow> stable r step succs ss p) \<and> ss0 <=[r] ss \<and>
   275  ss \<in> list n A \<and> (\<forall>p<n. p \<notin> w \<longrightarrow> stable r step succs ss p) \<and> ss0 <=[r] ss \<and>
   278  (\<forall>ts\<in>list n A. ss0 <=[r] ts \<and> stables r step succs ts \<longrightarrow> ss <=[r] ts) \<and>
   276  (\<forall>ts\<in>list n A. ss0 <=[r] ts \<and> stables r step succs ts \<longrightarrow> ss <=[r] ts) \<and>
   279  (\<forall>p\<in>w. p < n)" and
   277  (\<forall>p\<in>w. p < n)" and
   280  r = "{(ss',ss) . ss <[r] ss'} <*lex*> finite_psubset"
   278  r = "{(ss',ss) . ss <[r] ss'} <*lex*> finite_psubset"
   329 apply (simp del: listE_length
   327 apply (simp del: listE_length
   330     add: lex_prod_def finite_psubset_def decomp_propa termination_lemma
   328     add: lex_prod_def finite_psubset_def decomp_propa termination_lemma
   331          bounded_nat_set_is_finite)
   329          bounded_nat_set_is_finite)
   332 done
   330 done
   333 
   331 
   334 lemma iter_properties:
       
   335   "\<lbrakk> semilat(A,r,f); acc r ; pres_type step n A; mono r step n A;
       
   336      bounded succs n; \<forall>p\<in>w0. p < n; ss0 \<in> list n A;
       
   337      \<forall>p<n. p \<notin> w0 \<longrightarrow> stable r step succs ss0 p \<rbrakk> \<Longrightarrow>
       
   338   iter f step succs ss0 w0 : list n A \<and>
       
   339   stables r step succs (iter f step succs ss0 w0) \<and>
       
   340   ss0 <=[r] iter f step succs ss0 w0 \<and>
       
   341   (\<forall>ts\<in>list n A. ss0 <=[r] ts \<and> stables r step succs ts \<longrightarrow>
       
   342                  iter f step succs ss0 w0 <=[r] ts)"
       
   343 apply(simp add:iter_def del:Let_def)
       
   344 by(rule while_properties[THEN mp,OF _ _ _ _ _ _ _ _ refl])
       
   345 
       
   346 lemma kildall_properties:
   332 lemma kildall_properties:
   347   "\<lbrakk> semilat(A,r,f); acc r; pres_type step n A; mono r step n A;
   333   "\<lbrakk> semilat(A,r,f); acc r; pres_type step n A; mono r step n A;
   348      bounded succs n; ss0 \<in> list n A \<rbrakk> \<Longrightarrow>
   334      bounded succs n; ss0 \<in> list n A \<rbrakk> \<Longrightarrow>
   349   kildall f step succs ss0 : list n A \<and>
   335   kildall r f step succs ss0 : list n A \<and>
   350   stables r step succs (kildall f step succs ss0) \<and>
   336   stables r step succs (kildall r f step succs ss0) \<and>
   351   ss0 <=[r] kildall f step succs ss0 \<and>
   337   ss0 <=[r] kildall r f step succs ss0 \<and>
   352   (\<forall>ts\<in>list n A. ss0 <=[r] ts \<and> stables r step succs ts \<longrightarrow>
   338   (\<forall>ts\<in>list n A. ss0 <=[r] ts \<and> stables r step succs ts \<longrightarrow>
   353                  kildall f step succs ss0 <=[r] ts)";
   339                  kildall r f step succs ss0 <=[r] ts)";
   354 apply (unfold kildall_def)
   340 apply (unfold kildall_def)
       
   341 apply(case_tac "iter f step succs ss0 (unstables r step succs ss0)")
       
   342 apply(simp)
   355 apply (rule iter_properties)
   343 apply (rule iter_properties)
   356 apply (simp_all add: unstables_def stable_def)
   344 apply (simp_all add: unstables_def stable_def)
   357 apply (blast intro!: le_iff_plus_unchanged [THEN iffD2] listE_nth_in
       
   358              dest: boundedD pres_typeD)
       
   359 done
   345 done
   360 
   346 
   361 lemma is_bcv_kildall:
   347 lemma is_bcv_kildall:
   362   "[| semilat(A,r,f); acc r; top r T; 
   348   "[| semilat(A,r,f); acc r; top r T; 
   363       pres_type step n A; bounded succs n; 
   349       pres_type step n A; bounded succs n; 
   364       mono r step n A |]
   350       mono r step n A |]
   365   ==> is_bcv r T step succs n A (kildall f step succs)"
   351   ==> is_bcv r T step succs n A (kildall r f step succs)"
   366 apply(unfold is_bcv_def welltyping_def)
   352 apply(unfold is_bcv_def welltyping_def)
   367 apply(insert kildall_properties[of A])
   353 apply(insert kildall_properties[of A])
   368 apply(simp add:stables_def)
   354 apply(simp add:stables_def)
   369 apply clarify
   355 apply clarify
   370 apply(subgoal_tac "kildall f step succs ss : list n A")
   356 apply(subgoal_tac "kildall r f step succs ss : list n A")
   371  prefer 2 apply (simp(no_asm_simp))
   357  prefer 2 apply (simp(no_asm_simp))
   372 apply (rule iffI)
   358 apply (rule iffI)
   373  apply (rule_tac x = "kildall f step succs ss" in bexI)
   359  apply (rule_tac x = "kildall r f step succs ss" in bexI)
   374   apply (rule conjI)
   360   apply (rule conjI)
   375    apply blast
   361    apply blast
   376   apply (simp  (no_asm_simp))
   362   apply (simp  (no_asm_simp))
   377  apply assumption
   363  apply assumption
   378 apply clarify
   364 apply clarify
   379 apply(subgoal_tac "kildall f step succs ss!p <=_r ts!p")
   365 apply(subgoal_tac "kildall r f step succs ss!p <=_r ts!p")
   380  apply simp
   366  apply simp
   381 apply (blast intro!: le_listD less_lengthI)
   367 apply (blast intro!: le_listD less_lengthI)
   382 done
   368 done
   383 
   369 
   384 end
   370 end