chapter \Exercise Sheet -- Week 4\ theory Exercise04 imports Main begin section \Exercise 1 -- 2 points\ fun add :: "nat \ nat \ nat" where "add x 0 = x" | "add x (Suc y) = Suc (add x y)" fun add_it :: "nat \ nat \ nat" where "add_it x 0 = x" | "add_it x (Suc y) = add_it (Suc x) y" text \Prove the equivalence of @{const add} and @{const add_it}.\ lemma add_it_eq_add: "add_it x y = add x y" sorry section \Exercise 2 -- 4 points\ fun gp :: "'a :: field \ nat \ nat \ 'a" where "gp x m 0 = x^m" | "gp x m (Suc n) = x^m + gp x (Suc m) n" text \The function @{const gp} computes a geometric progression, i.e., @{prop "gp x m n = (\ i \ {m .. m+n}. x^i)"}.\ text \Prove the closed formula for geometric progressions. Hint: don't forget to activate @{thm [source] field_simps} at certain points in the proof, so that division can be handled by the simplifier.\ lemma closed_formula: "x \ 1 \ gp x m n = (x^m - x^(m+n+1)) / (1 - x)" sorry section \Exercise 3 -- 4 points\ fun factorial :: "nat \ nat" where "factorial 0 = 1" | "factorial (Suc n) = Suc n * factorial n" text \Prove the following lemma.\ text \Remarks: \<^item> in the induction case @{term "Suc n"} perform a case analysis on @{prop "n \ 4"}: these cases will then correspond to the standard base/induction-cases that we would perform on paper \<^item> calculational reasoning might be helpful \<^item> don't forget @{command find_theorems}, e.g. to find some lemma that might be useful for proving @{prop "x * y \ z * u"} \<^item> have a look at the simp rules / simpsets on slide 4/16 for the base case \ lemma "n \ 4 \ 2^n < factorial n" sorry end