Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Isabelle/Archive-of-Formal-Proofs/thys/Hoare_Time/   (Sammlung formaler Beweise Version 2026-5©)  Datei vom 31.4.2026 mit Größe 16 kB image not shown  

Quelle  DiscussionO.thy

  Sprache: Isabelle
 

subsection Relation between the Hoare logics in big-O style
theory DiscussionOsubsection  in big-O style
imports
begin


(* here we compare quantitative Hoare logic with constant with Nielson's Hoare logic *)

subsubsection<openRelation toRightarrowNielson_Hoare.assn2" where "emN P = (λl s. P s < )"
  
  
definition emN :: "qassn ==> Nielson_Hoare.assn2" where "emN  <lambda>l s. P s < 
 
(* quanthoare can be simulated by Nielson  *)  
lemma assumes s: ">1{ emN P'} c { %s. (THE e. enat e = P' s - Q' (THE t. (n. (c, s) ==> t ) )) 1{ ?PP c{?e <Down>Q }"
  shows quantNielson: " quan: "2java.lang.NullPointerException
proof -
  from s obtain k where k: "k>0" and qd: " P' l s ==>t p. (c, s) ==> t k * ?e s emN Q' t)"
    unfolding hoare1_valid_def by blast 
    
  show ?thesis unfolding QuantK_Hoare.hoare2o_valid_def
    apply(rule exI[where x=k])
    apply safe apply fact
  proof -
    fix s
    assume P': "P' s < "
    then have "(emN P') (λ_. 0) s" unfolding  emN_def by auto
    with qd obtain p t where i: "(c, s) ==> p t" and p: "p k * ?e s" and e: "emN Q' (λ_. 0) t"
       java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
    have t: ":i auto
      
    from P' obtain pre where pre: "P' s = enat pre" by fastforce
    from e have "Q  <>" unfldin m_e y auto
    then obtain post where post: "Q' t = enat post" t \infinity unf emN_def by auto
      
    have ">"using i bigstep_progress by auto
      
    thm enat.inject idiff_e
    ave k: "(THE e.enate = P s -Q'(THE.  n 
      unfolding t pre
       using e enatP Q ( t existsn. (c, s) ==> t)) = pre - post
    with p have ieq: "p \unfoldingest pl(rule teequaalit)
    then havee" * post k * pre" using
      using diff_mult_distr by auto
       then
    have ii: " p +k  Q' \le k*P's" unfolding post pre by  simp                           
    from i ii show "(\<exists>t p. (c, s) \<Rightarrow> p \<Down> t \<and> enat p + k * Q' t \<le> k * P' s)" by auto
  qed 
qed
 
  
  
(* Nielson can be simulated by quanthoare *)  
lemma assumess:"\Turnstile\^sub>2l. P l s) + enat (e s) } c { %s. emb (\<>l' { ?P } c { ?Q }")
    and sP: "l t. P l t ==>
    and sQ: " =)
  shows  NielsonQuant: "1 { P } c { e Q }" 
proof
  from obtain wherek: ">0"and\And>s. ?Ps  \infinity  ( p  enat p + enat k * ?Q t 
    unfolding:
    
  show ?thesisqd p  where(s\Rightarrow t" and p: "enat p + enat k * ?Q t  enat k * ?P s"
    apply(rule exI[where x=k])
    
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 9
    fix l s
    assumeQ have "\foralll. Q l t" by auto
    then have aP: "
    thenenat k * ?P s" by auto
    with qd obtain p t where i: "(sRightarrow p  enat k * ?P s"
      by blast
    have t: "java.lang.NullPointerException
       
    from P have Q: "Q l t" using p k
      apply auto
      by (metis (full_types) emb.simps(1) enat_ord_simps(2) imult_is_infinity infinity_ileE not_less_zero plus_enat_simps(3))      
    with have"<forall>l.Q l t" auto
    then have "?Q t = 0" by auto
    with p have "enat p enat k * ?P s" by auto
    with aP have p': "p s: "<Turnstile<3java.lang.NullPointerException
        
    from i Q p' show " p p \Down> t \<> 
  qed
qed



 
subsubsection>Relati SepLogic to quantHoare

definition em :: "qassn ==> bool)" where
  "em P = (%(ps obtain where"P s = enat n"

lemma P have"em P (part s, n) nodn mdfby auo
shows "urnstile2java.lang.NullPointerException
proof
  from s obtain
  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
    fix s
    assume P: "P s < appl (auto s simp: plus_fun_def)
    then obtain n where n: "P s = enat (ule) subgoal v (cases ps") apply auto using orth by (aut simp: sepdisj_fun_def domain_conv) dodone
      by fastforce
    with P have " q z have q  enat QPartial_Evaluation \lambda)<lenatusing
    with s' obtain ps' ps
              and m: "k * n = k * e + e' + m" and Q: "em Q (ps', e)" byblast
        
    from Q have q: "Q (Partia
        
    have z: "(Partial_Evaluation.emb ps' (Partial_Evaluation.emb ps'' (λ_. 0))) = (Partial_Evaluation.emb (pshaveenat  + k QPartial_Evaluation (psps)(\lambda_) \le enat P "unfolding n usigqm
      unfoldingi have (\existst p. (c, s) \<>  enat p + enat k * Q t \le> eena k * P s) to
      apply (rule ext) subgoal for v apply (cases "ps' v") apply auto using or note B=thithis

    (rl x[hr =] ae) aply fact
etis i0_lb multlftt_mno)

    have i: "
                
        
    have ii: "enat m + enat k * Q (Partial_Evaluation.emb (ps'+ps'') (λ
      using enat_ile by fastforce
      
    from i i have "\Downand enat p + enat k * Q t  by auto
  } note B=this
  show ?thesis unfolding QuantK_Hoare  "' { P} c { Q }"
    apply( s  k where"k>0" s: "\Ands. embe P s < t p. (c, s) ==> t enat k * embe P s)"
    apply (fact B) done
qed 

definition embe::"(pst ==> qassn" where
    "embe P = (%s. Inf {enat n|n. P (part s, n)} )"
 
lemma:P psnjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
   e({enat |.  P ps nn)} })=Falseto
proof -
  fromsobtain where k:k>" and s: \Andemb Ps < \infinity \<>  t enat k * embe P s)"
    unfolding QuantK_Hoare.hoare2o_valid_def by auto

  {ps
    let ?s =" s (mono_tgs, litng) Lea_e ininit_leE)
    assume P: P("
    with full haveain where P ?s enat
    then have ps:eqembe enat
    from P have l': "({enat n |n. P (ps, n)} =fhen have l: embe Q <\<>"Inf_enat_def apply safe by simp
    have t: "embe y have "(part t y"nfoldingjava.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
      applycontrusing
      by (metis (mono_tags, lifting) Least_le infinity_ileE)  
    with s obtain t p where c: "(c, ?s) ==> t" and ineqp t *Qt \leat" by blast
    where z: "embe enat z"
      usingauto
    with iobtain y where y: "embe  = enat y"
      using k by fastforce  ineq z y have " p +  k * y<>enat z byauto
    then have l: "embe Q t <
    then have zz: "({enat n|n.  ((part)}{) Falseldingf f_enat_defsafe
    from y have "Q (part t, y)"  unfolding embe_def zzfinallytain where * n  k* +'+" us by(mtis add.so ad.ommue lei_add
       using zz appl have "<exists ps m '.c )==>A m  pss<andps \andk n *ee'+ \and Q (ps', e)"
    
    from full_to_part[OF c] ps have c': "      applye exIherepart]

    have "o_vlid_dfap(rule xI[here x=k, safe))

    from z
      apply auto
      by (metis (mono_tags, lifting) Least_le enat_ord_simps(1))

    from ineq z y have "enat p + enat k * y uto
    then have "p + k * y
    also have "
    inallyobtain  +ing etisssoc   

    have"ps' ps'' m e e'. (c, ps) ==>A m ps' + ps'' ps' ## ps'' k * n = k * e + e' + m Q (ps', e)"
      apply(rule exI[where x="part t"])
      apply(rule "P Q n = (k>0. valid P cQ (k*n"
      apply(rule exI[where x="p"])
      applyewhere
      applyassume"<>' {λs. s.
  }

  show ?thesis unfolding hoare3o_valid_def apply(rule exI[where x=k], safe)
    plyyfact y ac
qed

subsection <infinity>" by auto

  
definition valid where
  "valid P c Q nc \> \Down t" and "enat m + k * \<up> (Q t) \<le k(<>(   enatnbyst

definitionvalid_quantHoaretHoareexistsk>0. valid P c Q (k*n) \<Longrightarrow>Turnstile\<^sub>2\<^sub>' {%s. emb (P s)n>s. emb  
  "validk P c Q n = <>k0(<>.P  \longrightarrow (\existss' m. (c, s) \<Rightarrow> m \<Down> s' \<and> m \<le> k * n \<and> Q s')))"


lemma "validk P c Q n = (\<exists>k>0. valid
  foldingldingalid_defid_defdeffvalidk_defidk_defyimp

subsubsection \                \existsps' ps'' m e e'. (c, ps) \<Rightarrow>\<^ub <> s+ <>' '<>k * na = k * e + e' + m \<and> embP2 Q (ps', e)) " by blast
  
lemma
proof -
  assume valid: "<Turnstile<^sub>2\<^sub>' {\<lambda>s. \<up> (P s) + enat n} c {\<lambda>s. \<up> (Q s)}" 
  then obtain k where val:
    and k: "k>0" unfoldingantK_Hoarere2o_valid_defylastt
  { 
    fix s
    assume Ps: "P s"
    thenIe x=0)
    ruleI x "y 
        c: "(c, s) \<Rightarrow> m \<Down>"dnatm k< (Q t) \<le> k * (\<up> (P s) + enat)ylast
    
    then have "m \<le> k * n \<and> Q t" using k
      using Ps add.commute add.right_neutral emb.simps(1) emb.simps(2) enat_ord_simps(1) infinity_ileE plus_enat_simps(3)
      by (metis (full_types) mult_zero_right not_gr_zero times_enat_simps(1) times_enat_simps(4))
        
    with     c      
    have "(\<exists>s' m. (c, s) \<Rightarrow> m \<Down> s' \<and> m \<le>  k * n \<and> Q s')" by blast
  } note bla=this 
  show "\<exists>k>0. valid P c Q (k*n)" unfolding valid_def apply(rule exI[where x=k]) using bla k by auto
qed  
 
lemma valid_quantHoare: "\<exists>k>0. valid P c Q (k*n) \<Longrightarrow> \<Turnstile>\<^sub>2\<^sub>' {%s. emb (P s)  + enat n} c { \<lambda>s. emb (Q s)  }"
proof -
  assume  "\<exists>k>0. valid P c Q (k*n)" 
  then obtain k where valid: "valid P c Q (k*n)" and k: "k>0" by blast
  { 
    fix s
    assume "(%s. emb (P s)  + enat n) s < \<infinity>"
    then have Ps: "P s" apply auto
      by (metis emb.elims enat.distinct(2) enat.simps(5) enat_defs(4)) 
    with valid[unfolded valid_def] obtain t m where
        c: "(c, s) \<Rightarrow> m \<Down> t" and "m \<le> k * n" "Q t" by blast    
    then have "enat m +  k * \<up> (Q t) \<le>  k * (\<up> (P s) + enat n)" using Ps by simp
    with     c      
    have "(\<exists>s' m. (c, s) \<Rightarrow> m \<Down> s' \<and> enat m + enat k * \<up> (Q s') \<le> enat k * (\<up> (P s) + enat n))" by blast
  } note funk=this
  show "\<Turnstile>\<^sub>2\<^sub>' {%s.  emb (P s)  + enat n} c { \<lambda>s. emb (Q s)  }" unfolding QuantK_Hoare.hoare2o_valid_def
    apply(rule exI[where x=k]) using funk k by auto
qed  



subsubsection \<open>Relation between valid predicate and Hoare Logic based on Separation Logic\<close>
    
  
  

definition "embP2 P = (%(ps,n). \<forall>s.  P (Partial_Evaluation.emb ps s) \<and> n = 0)"
definition "embP3 P = (%(ps,n). dom ps = UNIV \<and> (\<forall>s.  P (Partial_Evaluation.emb ps s)) \<and> n = 0)"
  
    
lemma emp: "a + Map.empty = a"
  by (simp add: plus_fun_conv) 
  
lemma oneway: "\<Turnstile>\<^sub>3\<^sub>' {embP3 P ** $n} c {embP2 Q} \<Longrightarrow> validk P c Q n"
proof -
  assume partial_true: "\<Turnstile>\<^sub>3\<^sub>' {embP3 P ** $n} c {embP2 Q}" 
  from partial_true[unfolded hoare3o_valid_def] obtain k where k: "k>0" and
   q : "\<forall>ps na. (embP3 P \<and>* $ n) (ps, na) \<longrightarrow>
                (\<exists>ps' ps'' m e e'. (c, ps) \<Rightarrow>\<^sub>A m \<Down> ps' + ps'' \<and> ps' ## ps'' \<and> k * na = k * e + e' + m \<and> embP2 Q (ps', e)) " by blast
  { fix s
    assume "P s"
    then have g: " (embP3 P \<and>* $ n) (part s, n)"
      unfolding embP3_def dollar_def sep_conj_def by auto
    from q  g
    obtain ps' ps'' m e e' where pbig: "(c, part s) \<Rightarrow>\<^sub>A m \<Down> ps' + ps''" and orth: "ps' ## ps''"
        and ii: "k * n = k * e + e' + m" and erg: "embP2 Q (ps', e)" by blast
    
    have ii': "m \<le> k * n" using ii by auto    
        
    from part_to_full'[OF pbig] have i: "(c, s ) \<Rightarrow> m \<Down> Partial_Evaluation.emb (ps' + ps'') s" by simp
    
    from erg have z2: "\<And>s. Q (Partial_Evaluation.emb ps' s)" unfolding embP2_def by auto   
    have "Partial_Evaluation.emb (ps' + ps'') s = Partial_Evaluation.emb (ps'' + ps') s"
      using orth  by (simp add: sep_add_commute)
    also have "Partial_Evaluation.emb (ps'' + ps') s = Partial_Evaluation.emb (ps') (Partial_Evaluation.emb (ps'') s)"
      apply rule 
      unfolding emb_def plus_fun_conv map_add_def
      by (metis option.case_eq_if option.simps(5)) 
    finally have z: "Partial_Evaluation.emb (ps' + ps'') s = Partial_Evaluation.emb (ps') (Partial_Evaluation.emb (ps'') s)" .
    have iii: "Q (Partial_Evaluation.emb (ps' + ps'') s)" unfolding z apply (fact) . 
        
    from i ii' iii
      have "\<exists>s' m. (c, s) \<Rightarrow> m \<Down> s' \<and> m \<le> k * n \<and> Q s'" by auto
    }
    with k show "validk P c Q n" unfolding validk_def by blast
qed
   
  
lemma theother: "validk P c Q n \<Longrightarrow> \<Turnstile>\<^sub>3\<^sub>' {embP3 P ** $n} c {embP2 Q }"
proof -
  assume valid: "validk P c Q n" 
  then obtain k where k : "k>0" and v: "(\<forall>s. P s \<longrightarrow> (\<exists>s' m. (c, s) \<Rightarrow> m \<Down> s' \<and> m \<le> k * n \<and> Q s'))"
   unfolding validk_def by blast
  
  { fix ps na
    assume an: "(embP3 P \<and>* $ n) (ps, na)" 
    have dom: "dom ps = UNIV" and Pps: "\<And>s. P (Partial_Evaluation.emb ps s)" and nan: "na = n" using an unfolding sep_conj_def
        by (auto simp: embP3_def dollar_def)
        
    from v Pps
      obtain s' m where big: "(c, (Partial_Evaluation.emb ps (%_. 0))) \<Rightarrow> m \<Down> s'" and ii: "m \<le> k * n" and erg: "Q s'" by blast
                    
          
    have "part (Partial_Evaluation.emb ps (\<lambda>_. 0)) = ps " using dom by simp
    with full_to_part[OF big] have i: "(c, ps) \<Rightarrow>\<^sub>A m \<Down> part s'" by auto 
    
       
    have iii: "embP2 Q (part s', 0)" 
      unfolding embP2_def apply auto by fact 
         
    have "k * na = k * n - m + m" using ii k nan by simp  
        
    have "(\<exists>ps' ps'' m e e'. (c, ps) \<Rightarrow>\<^sub>A m \<Down> ps' + ps'' \<and> ps' ## ps'' \<and> k * na = k * e + e' + m \<and> embP2 Q (ps', e))"
      apply(rule exI[where x="part s'"])
      apply(rule exI[where x="0"])
      apply(rule exI[where x="m"])
      apply(rule exI[where x="0"])
      apply(rule exI[where x="k * n - m"]) apply auto
      by fact+         
    }
    with k show "\<Turnstile>\<^sub>3\<^sub>' {embP3 P ** $n} c {embP2 Q }" unfolding hoare3o_valid_def by blast
qed
  
  
lemma "validk P c Q n \<longleftrightarrow> \<Turnstile>\<^sub>3\<^sub>' {embP3 P ** $n} c {embP2 Q }"
using oneway and theother by metis



end

Messung V0.5 in Prozent
C=62 H=97 G=81

¤ Dauer der Verarbeitung: 0.13 Sekunden  (vorverarbeitet am  2026-06-10) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.