section‹Introduction to IMP2-VCG, based on IMP› theory IMP2_from_IMP imports"../IMP2" begin
text‹This document briefly introduces the extensions of IMP2 over IMP.›
subsection‹Fancy Syntax›
text‹Standard Syntax› definition"exp_count_up1 ≡ ''a'' ::= N 1;; ''c'' ::= N 0;; WHILE Cmpop (<) (V ''c'') (V ''n'') DO ( ''a'' ::= Binop (*) (N 2) (V ''a'');; ''c'' ::= Binop (+) (V ''c'') (N 1))"
(* Type \ < ^ imp > \open \close , without the spaces. for\<open>\<dots>\<close>,thereisanautocompletionifyoutypeaquote(") for\<comment>\<open>\<close>,type\commentanduseautocompletion
*) text‹Fancy Syntax› definition"exp_count_up2 ≡🚫‹ ― ‹Initialization› a = 1; c = 0; while (c<n) { ― ‹Iterate until ‹c› has reached ‹n›› a=2*a; ― ‹Double ‹a›› c=c+1 ― ‹Increment ‹c›› } ›"
lemma‹Assign ''x'' v = AssignIdx ''x'' (N 0) v› .. ― ‹Shortcut for assignment to index ‹0›› term‹''x'' ::= v›term‹🚫‹x = v+1››
text‹Note: In fancy syntax, assignment between variables is always parsed as array copy.
This is no problem unless a variable is used as both, array and plain value,
which should be avoided anyway. ›
term‹ArrayCpy ''d'' ''s''› ― ‹Copy whole array. Both operands are variable names.› term‹''d''[] ::= ''s''›term‹🚫‹d = s››
term‹ArrayClear ''a''› ― ‹Initialize array to all zeroes.› term‹CLEAR ''a''[]›term‹🚫‹clear a[]››
text‹Semantics of these is straightforward› thm big_step.AssignIdx big_step.ArrayCpy big_step.ArrayClear
subsection‹Local and Global Variables› term‹is_global›term‹is_local› ― ‹Partitions variable names› term‹<s\1|s2>› ― ‹State with locals from ‹s1› and globals from ‹s2››
term‹SCOPE c›term‹🚫‹scope { skip }›› ― ‹Execute ‹c› with fresh set of local variables› thm big_step.Scope
subsubsection‹Parameter Passing› text‹Parameters and return values by global variables: This is syntactic sugar only:› contextfixes f :: com begin term‹🚫‹ (r1,r2) = f(x1,x2,x3)›› end
lemma"s0 ''n'' 0 ≥ 0 ==> wlp π exp_count_up1 (λs. s ''a'' 0 = 2^nat (s0 ''n'' 0)) s0" unfolding exp_count_up1_def apply (subst annotate_whileI[where
I="λs. s ''n'' 0 = s0 ''n'' 0 ∧ s ''a'' 0 = 2 ^ nat (s ''c'' 0) ∧ 0 ≤ s ''c'' 0 ∧ s ''c'' 0 ≤ s0 ''n'' 0"
]) apply (i_vcg_preprocess; i_vcg_gen; clarsimp) text‹The postprocessor converts from states applied to string names to actual variables› apply i_vcg_postprocess by (auto simp: algebra_simps nat_distribs)
lemma"s0 ''n'' 0 ≥ 0 ==> wlp π exp_count_up1 (λs. s ''a'' 0 = 2^nat (s0 ''n'' 0)) s0" unfolding exp_count_up1_def apply (subst annotate_whileI[where
I="λs. s ''n'' 0 = s0 ''n'' 0 ∧ s ''a'' 0 = 2 ^ nat (s ''c'' 0) ∧ 0 ≤ s ''c'' 0 ∧ s ''c'' 0 ≤ s0 ''n'' 0"
]) text‹The postprocessor is invoked by default› apply vcg oops
subsection‹Specification Commands›
text‹IMP2 provides a set of commands to simplify specification and annotation of programs.›
text‹Old way of proving a specification: › lemma"let n = s0 ''n'' 0 in n ≥ 0 ==> wlp π exp_count_up1 (λs. let a = s ''a'' 0; n0 = s0 ''n'' 0 in a = 2^nat (n0)) s0" unfolding exp_count_up1_def apply (subst annotate_whileI[where
I="λs. s ''n'' 0 = s0 ''n'' 0 ∧ s ''a'' 0 = 2 ^ nat (s ''c'' 0) ∧ 0 ≤ s ''c'' 0 ∧ s ''c'' 0 ≤ s0 ''n'' 0" (* Similar for invar! *)
]) apply vcg apply (auto simp: algebra_simps nat_distribs) done
lemma"VAR (s x) P = (let v=s x in P v)"unfolding VAR_def by simp
text‹IMP2 specification commands›
program_spec (partial) exp_count_up assumes"0≤n" ― ‹Precondition. Use variable names of program.›
ensures "a = 2^nat n0" ― ‹Postcondition. Use variable names of programs.
Suffix with ‹⋅0› to refer to initial state› defines ― ‹Program› ‹
a = 1;
c = 0;
while (c<n)
@invariant ‹n=n0∧ a=2^nat c ∧ 0≤c ∧ c≤n› ― ‹
Invar annotation. Variable names and suffix ‹⋅0› for variables from initial state.›
{
a=2*a;
c=c+1
} › apply vcg by (auto simp: algebra_simps nat_distribs)
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.