Cookies disclaimer

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.

Homework 1

This is the task corresponding to homework 1.


Download Files

Definitions File

theory Defs
  imports Main

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)

consts repeat :: "nat \<Rightarrow> 'a \<Rightarrow> 'a list"


Template File

theory Submission
  imports Defs

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"

theorem rep_rev: "reverse (repeat n a) = repeat n a"


Check File

theory Check
  imports Submission

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)


Terms and Conditions