I agree Our site saves small pieces of text information (cookies) on your device in order to deliver better content and for statistical purposes. You can disable the usage of cookies by changing the settings of your browser. By browsing our website without changing the browser settings you grant us permission to store that information on your device.
theory Defs imports Main begin text \<open>Definitions and lemmas from the tutorial\<close> fun snoc :: "'a list \<Rightarrow> 'a \<Rightarrow> 'a list" where "snoc [] x = [x]" | "snoc (y # ys) x = y # (snoc ys x)" fun reverse :: "'a list \<Rightarrow> 'a list" where "reverse [] = []" | "reverse (x # xs) = snoc (reverse xs) x" lemma reverse_snoc: "reverse (snoc xs y) = y # reverse xs" by (induct xs) auto theorem reverse_reverse: "reverse (reverse xs) = xs" by (induct xs) (auto simp add: reverse_snoc) end
theory Submission imports Defs begin fun repeat :: "nat \<Rightarrow> 'a \<Rightarrow> 'a list" where "repeat _ = undefined" value "repeat 5 (0::nat) = [0, 0, 0, 0, 0]" value "repeat 3 (1::nat) = [1, 1, 1]" theorem rep_len: "length (repeat n a) = n" sorry theorem rep_rev: "reverse (repeat n a) = repeat n a" sorry end
theory Check imports Submission begin theorem rep_len: "length (repeat n a) = n" by (rule Submission.rep_len) theorem rep_rev: "reverse (repeat n a) = repeat n a" by (rule Submission.rep_rev) end
theory Defs imports Main begin declare [[names_short]] fun snoc :: "'a list \<Rightarrow> 'a \<Rightarrow> 'a list" where "snoc [] x = [x]" | "snoc (y # ys) x = y # (snoc ys x)" fun reverse :: "'a list \<Rightarrow> 'a list" where "reverse [] = []" | "reverse (x # xs) = snoc (reverse xs) x" consts double :: "'a list \<Rightarrow> 'a list" end
theory Submission imports Defs begin fun double :: "'a list \<Rightarrow> 'a list" where "double _ = undefined" value "double [1,2,(3::nat)] = [1,1,2,2,3,3]" theorem double_len: "length (double xs) = 2 * length xs" sorry theorem reverse_double: "reverse (double xs) = double (reverse xs)" sorry theorem rev_double: "rev (double xs) = double (rev xs)" sorry end
theory Check imports Submission begin theorem double_len: "length (double xs) = 2 * length xs" by (rule Submission.double_len) theorem reverse_double: "reverse (double xs) = double (reverse xs)" by (rule Submission.reverse_double) theorem rev_double: "rev (double xs) = double (rev xs)" by (rule Submission.rev_double) end