Theory QuantK_VCG
subsection "Verification Condition Generator"
theory QuantK_VCG
imports QuantK_Hoare
begin
subsubsection "Ceiling integer division on extended natural numbers"
definition "mydiv (a::nat) (k::nat) = (if k dvd a then a div k else (a div k) + 1)"
lemma mydivcode: "k>0 ⟹ D≥k ⟹ mydiv D k = Suc (mydiv (D-k) k)"
unfolding mydiv_def apply (auto simp add: le_div_geq)
using dvd_minus_self by auto
lemma mydivcode1: "mydiv 0 k = 0"
unfolding mydiv_def by auto
lemma mydivcode2: "k>0 ⟹ 0<D ⟹ D<k ⟹ mydiv D k = Suc 0"
unfolding mydiv_def by auto
lemma mydiv_mono: "a≤b ⟹ mydiv a k ≤ mydiv b k" unfolding mydiv_def
apply(cases "k dvd a")
subgoal apply(cases "k dvd b") apply auto apply (auto simp add: div_le_mono)
using div_le_mono le_Suc_eq by blast
subgoal apply(cases "k dvd b") apply auto apply (auto simp add: div_le_mono)
by (metis Suc_leI add.right_neutral div_le_mono div_mult_mod_eq dvd_imp_mod_0 le_add1 le_antisym less_le)
done
lemma mydiv_cancel: "0 < k ⟹ mydiv (k * i) k = i"
unfolding mydiv_def by auto
lemma assumes k: "k>0" and B: "B ≤ k*A"
shows mydiv_le_E: "mydiv B k ≤ A"
proof -
from mydiv_mono[OF B] and k mydiv_cancel show ?thesis
by metis
qed
lemma mydiv_mult_leq: "0 < k ⟹ l≤k ⟹ mydiv (l*A) k ≤ A"
by(simp add: mydiv_le_E)
lemma mydiv_cancel3: "0 < k ⟹ i ≤ k * mydiv i k"
by (auto simp add: mydiv_def dividend_less_times_div le_eq_less_or_eq)
definition "ediv a k = (if a=∞ then ∞ else enat (mydiv (THE i. a=enat i) k))"
lemma ediv_enat[simp]: "ediv (enat a) k = enat (mydiv a k)"
unfolding ediv_def by auto
lemma ediv_mydiv[simp]: "ediv (enat a) k ≤ enat f ⟷ mydiv a k ≤ f"
unfolding ediv_def by auto
lemma ediv_mono: "a≤b ⟹ ediv a k ≤ ediv b k"
unfolding ediv_def by (auto simp add: mydiv_mono)
lemma ediv_cancel2: "k>0 ⟹ ediv (enat k * x) k = x"
unfolding ediv_def apply(cases "x=∞") using mydiv_cancel by auto
lemma ediv_cancel3: "k>0 ⟹ A ≤ enat k * ediv A k"
unfolding ediv_def apply(cases "A=∞") using mydiv_cancel3 by auto
subsubsection "Definition of VCG"