lemma nat_lemma2: "[ b = m*(n::nat) + t; a = s*n + u; t=u; b-a < n ]==> m ≤ s" proof - assume"b = m*(n::nat) + t""a = s*n + u""t=u" hence"(m - s) * n = b - a"by (simp add: diff_mult_distrib) alsoassume"… < n" finallyhave"m - s < 1"by simp thus ?thesis by arith qed
lemma mod_lemma: "[ (c::nat) ≤ a; a < b; b - c < n ]==> b mod n ≠ a mod n" apply(subgoal_tac "b=b div n*n + b mod n" ) prefer2apply (simp add: div_mult_mod_eq [symmetric]) apply(subgoal_tac "a=a div n*n + a mod n") prefer2 apply(simp add: div_mult_mod_eq [symmetric]) apply(subgoal_tac "b - a ≤ b - c") prefer2apply arith apply(drule le_less_trans) back apply assumption apply(frule less_not_refl2) apply(drule less_imp_le) apply (drule_tac m = "a"and k = n in div_le_mono) apply(safe) apply(frule_tac b = "b"and a = "a"and n = "n"in nat_lemma2, assumption, assumption) apply assumption apply(drule order_antisym, assumption) apply(rotate_tac -3) apply(simp) done
subsubsection‹Producer/Consumer Algorithm›
record Producer_consumer =
ins :: nat
outs :: nat
li :: nat
lj :: nat
vx :: nat
vy :: nat
buffer :: "nat list"
b :: "nat list"
text‹The whole proof takes aprox. 4 minutes.›
lemma Producer_consumer: "[INIT= «0<length a ∧ 0<length 🍋buffer ∧ length 🍋b=length a¬ ; I= «(∀k<🍋ins. 🍋outs≤k ⟶ (a ! k) = 🍋buffer ! (k mod (length 🍋buffer))) ∧ 🍋outs≤🍋ins ∧🍋ins-🍋outs≤length 🍋buffer¬ ; I1= «🍋I ∧🍋li≤length a¬ ; p1= «🍋I1 ∧🍋li=🍋ins¬ ; I2 = «🍋I ∧ (∀k<🍋lj. (a ! k)=(🍋b ! k)) ∧🍋lj≤length a¬ ; p2 = «🍋I2 ∧🍋lj=🍋outs¬]==> ∥- {🍋INIT} 🍋ins:=0,, 🍋outs:=0,, 🍋li:=0,, 🍋lj:=0,, COBEGIN {🍋p1 ∧🍋INIT} WHILE 🍋li <length a INV {🍋p1 ∧🍋INIT} DO {🍋p1 ∧🍋INIT ∧🍋li<length a} 🍋vx:= (a ! 🍋li);; {🍋p1 ∧🍋INIT ∧🍋li<length a ∧🍋vx=(a ! 🍋li)} WAIT 🍋ins-🍋outs < length 🍋buffer END;; {🍋p1 ∧🍋INIT ∧🍋li<length a ∧🍋vx=(a ! 🍋li) ∧🍋ins-🍋outs < length 🍋buffer} 🍋buffer:=(list_update 🍋buffer (🍋ins mod (length 🍋buffer)) 🍋vx);; {🍋p1 ∧🍋INIT ∧🍋li<length a ∧ (a ! 🍋li)=(🍋buffer ! (🍋ins mod (length 🍋buffer))) ∧🍋ins-🍋outs <length 🍋buffer} 🍋ins:=🍋ins+1;; {🍋I1 ∧🍋INIT ∧ (🍋li+1)=🍋ins ∧🍋li<length a} 🍋li:=🍋li+1 OD {🍋p1 ∧🍋INIT ∧🍋li=length a} ∥ {🍋p2 ∧🍋INIT} WHILE 🍋lj < length a INV {🍋p2 ∧🍋INIT} DO {🍋p2 ∧🍋lj<length a ∧🍋INIT} WAIT 🍋outs<🍋ins END;; {🍋p2 ∧🍋lj<length a ∧🍋outs<🍋ins ∧🍋INIT} 🍋vy:=(🍋buffer ! (🍋outs mod (length 🍋buffer)));; {🍋p2 ∧🍋lj<length a ∧🍋outs<🍋ins ∧🍋vy=(a ! 🍋lj) ∧🍋INIT} 🍋outs:=🍋outs+1;; {🍋I2 ∧ (🍋lj+1)=🍋outs ∧🍋lj<length a ∧🍋vy=(a ! 🍋lj) ∧🍋INIT} 🍋b:=(list_update 🍋b 🍋lj 🍋vy);; {🍋I2 ∧ (🍋lj+1)=🍋outs ∧🍋lj<length a ∧ (a ! 🍋lj)=(🍋b ! 🍋lj) ∧🍋INIT} 🍋lj:=🍋lj+1 OD {🍋p2 ∧🍋lj=length a ∧🍋INIT} COEND {∀k<length a. (a ! k)=(🍋b ! k)}" apply oghoare
― ‹138 vc› apply(tactic ‹ALLGOALS (clarify_tac 🍋)›)
― ‹112 subgoals left› apply(simp_all (no_asm))
― ‹43 subgoals left› apply(tactic ‹ALLGOALS (conjI_Tac 🍋 (K all_tac))›)
― ‹419 subgoals left› apply(tactic ‹ALLGOALS (clarify_tac 🍋)›)
― ‹99 subgoals left› apply(simp_all only:length_0_conv [THEN sym])
― ‹20 subgoals left› apply (simp_all del:length_0_conv length_greater_0_conv add: nth_list_update mod_lemma)
― ‹9 subgoals left› apply (force simp add:less_Suc_eq) apply(hypsubst_thin, drule sym) apply (force simp add:less_Suc_eq)+ done
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.