(* note that IMP2 is not part of the Isabelle distribution, but of the "Archive of Formal Proofs (AFP)"; so to run this theory, - download the AFP from https://www.isa-afp.org - extract it, e.g., to ~/afp/2024 - start Isabelle with isabelle jedit -d ~/afp/2024/thys -l IMP2 Exercise11.thy this will precompile IMP2 once, and then load the demo. *) theory Exercise11 imports IMP2.IMP2 begin procedure_spec (partial) copy_1(x) returns y assumes \x \ 0\ ensures "y = x\<^sub>0" defines \ a = x; y = 0; while (a \ 0) @invariant \True \ adjust_me\ { y = y + 1; a = a - 1 } \ apply vcg apply simp oops procedure_spec copy_2(x) returns y assumes \x \ 0\ ensures "y = x\<^sub>0" defines \ a = x; y = 0; while (a \ 0) @invariant \True \ adjust_me\ @variant \2 * x - 3 * a + 4 * y - 5 + adjust_me_2\ { y = y + 1; a = a - 1 } \ apply vcg apply simp apply simp oops procedure_spec (partial) copy_3(x) returns y assumes \True\ ensures "y = x\<^sub>0" defines \ a = x; y = 0; while (a \ 0) @invariant \True \ adjust_me\ { y = y + 1; a = a - 1 } \ apply vcg apply simp oops procedure_spec (partial) fact_non_term(x) returns y assumes \x < 0\ ensures "True \ adjust_me" defines \ y = 1; while (x \ 0) @invariant \True \ adjust_me\ { y = y * x; x = x - 1 } \ apply vcg apply simp done end