theory Segfault imports "HOL-IMP.Big_Step" "HOL-Library.Extended_Nat" begin inductive big_step_t :: "com \ state \ nat \ state \ bool" ("_ \^/_ _" 55) where Skip: "(SKIP, s) \^1 s" | Assign: "(x ::= a,s) \^1 s(x := aval a s)" | Seq: "\ (c\<^sub>1,s\<^sub>1) \^n\<^sub>1 s\<^sub>2; (c\<^sub>2,s\<^sub>2) \^n\<^sub>2 s\<^sub>3; n\<^sub>1+n\<^sub>2 = n\<^sub>3 \ \ (c\<^sub>1;;c\<^sub>2, s\<^sub>1) \^n\<^sub>3 s\<^sub>3" | IfTrue: "\ bval b s; (c\<^sub>1,s) \^n\<^sub>1 t; n\<^sub>3 = Suc n\<^sub>1 \ \ (IF b THEN c\<^sub>1 ELSE c\<^sub>2, s) \^n\<^sub>3 t" | IfFalse: "\ \bval b s; (c\<^sub>2,s) \^n\<^sub>2 t; n\<^sub>3 = Suc n\<^sub>2 \ \ (IF b THEN c\<^sub>1 ELSE c\<^sub>2, s) \^n\<^sub>3 t" | WhileFalse: "\ \bval b s \ \ (WHILE b DO c, s) \^1 s" | WhileTrue: "\ bval b s\<^sub>1; (c,s\<^sub>1) \^n\<^sub>1 s\<^sub>2; (WHILE b DO c, s\<^sub>2) \^n\<^sub>2 s\<^sub>3; n\<^sub>1+n\<^sub>2+1 = n\<^sub>3 \ \ (WHILE b DO c, s\<^sub>1) \^n\<^sub>3 s\<^sub>3" inductive_cases If_tE[elim!]: "(IF b THEN c\<^sub>1 ELSE c\<^sub>2,s) \^x t" type_synonym qassn = "state \ enat" fun emb :: "bool \ enat" ("\") where "emb False = \" | "emb True = 0" definition hoare_Qvalid :: "qassn \ com \ qassn \ bool" ("\\<^sub>Q {(1_)}/ (_)/ {(1_)}" 50) where "\\<^sub>Q {P} c {Q} \ (\s. P s < \ \ (\t p. ((c,s) \^p t) \ P s \ p + Q t))" theorem If_sound: assumes "\\<^sub>Q {\a. P a + \ (bval b a)} c\<^sub>1 {Q}" and " \\<^sub>Q {\a. P a + \ (\ bval b a)} c\<^sub>2 {Q}" shows "\\<^sub>Q {\a. eSuc (P a)} IF b THEN c\<^sub>1 ELSE c\<^sub>2 {Q}" unfolding hoare_Qvalid_def proof(safe) fix s assume "eSuc (P s) < \" then have Ps_fin: "P s < \" by (metis eSuc_infinity eSuc_mono) show "\t p. ((IF b THEN c\<^sub>1 ELSE c\<^sub>2, s) \^p t) \ enat p + Q t \ eSuc (P s)" proof(cases "bval b s") case True have "P s + \(bval b s) < \ \ (\t p. ((c\<^sub>1, s) \^p t) \ enat p + Q t \ P s + \(bval b s))" using assms(1) unfolding hoare_Qvalid_def by simp then obtain t p where "(c\<^sub>1, s) \^p t" and "enat p + Q t \ eSuc (P s)" using True Ps_fin try sorry then show ?thesis sorry next case False then show ?thesis sorry qed qed end