chapter \Exercise Sheet -- Week 4\ theory Exercise04 imports Main begin section \Exercise 1 -- 2 points\ fun factorial :: "nat \ nat" where "factorial 0 = 1" | "factorial (Suc n) = Suc n * factorial n" fun fact_it :: "nat \ nat \ nat" where "fact_it r 0 = r" | "fact_it r (Suc n) = fact_it (r * Suc n) n" fun factorial_it :: "nat \ nat" where "factorial_it n = fact_it 1 n" text \Prove that both implementations of the factorial function are equivalent. Note that @{thm [source] algebra_simps} contains distributive laws.\ lemma "factorial_it n = factorial n" 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)" proof - assume x1: "x \ 1" show ?thesis sorry qed section \Exercise 3 -- 4 points\ text \Prove the following lemma about the factorial function.\ 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" proof (induction n) case (Suc n) show ?case sorry qed auto end