First question done!
I have finally typed up full proofs for Xena, for the first question of M1F sheet 1.
Here are the questions in traditional PDF format: Example Sheet 1.
Here’s a link to a live Lean session containing the [Solutions to all parts of Question 1](https://leanprover.github.io/live/latest/#code=/-%0AM1F 2017-18 Sheet 1 Question 1, solution%0AAuthor : Kevin Buzzard%0A%0ANote: this version of the solution uses integers instead of real numbers.%0AThis is because the real numbers are not currently in Lean's standard library%0Aand I want to make things as easy as possible at this point. This file should%0Awork with any version of lean -- whether you installed it yourself or are%0Arunning the version on https://leanprover.github.io/live/latest/%0A%0ALean does have real numbers -- it's just that you need to install%0Aanother library to get them (the mathlib library).%0A%0ANotes for KMB : If I switch to real numbers, I should also switch to x^2%0A-/%0A%0A-- Here are some solutions to M1F sheet 1 question 1.%0A-- Let me stress that they are basically completely%0A-- unreadable unless you use Lean to read them.%0A-- If you use Lean, then by moving the cursor around%0A-- the proofs, or clicking on them, you will be able%0A-- to see, at each stage, what Xena%0A-- knows and what she is trying to prove.%0A-- This will give you a much better feeling for what%0A-- is going on.%0A%0A-- Before we start, just let me define the power notation,%0A-- which is not in the core lean library (it is in another%0A-- library called mathlib which may not be installed on your machine).%0A-- Don't worry about this bit. I'm defining x^n by recursion on n, which%0A-- is sort of like induction but with definitions instead of proofs.%0A%0A@[reducible] definition pow : int -> nat -> int%0A| _ 0 := (1:int)%0A| x (nat.succ n) := x * (pow x n)%0A%0Anotation x ^ n := pow x n%0A%0A-- Now onto the question.%0A%0A-- M1F Sheet 1 Q1 part (a): this is false.%0A%0Atheorem m1f_sheet01_q01a_is_F : ¬ (∀ x : ℤ, x^2 - 3x + 2 = 0 → x=1) := %0Abegin%0A--%0A-- We're going to prove this by contradiction.%0A-- Let's let H1 be our false hypothesis,%0A-- so H1 is "for all x, x^2-3x+2=0 implies x=1".%0A-- By the way, if you're using lean to read this file, you%0A-- can hover over or click on various lines to see much more%0A-- clearly what is going on.%0A--%0Aintro H1,%0A--%0A-- Now the problems will occur if we let x be 2, %0A-- because x^2-32+2=0 but 2 isn't 1. So let's%0A-- see what we can deduce from H1 if we set x=2.%0A--%0Ahave H2 : (2:ℤ)^2-32+2=0 → (2:ℤ)=1, -- new hypothesis%0A exact (H1 2), -- and there's its proof.%0A-- %0A-- Hypothesis H2 now says that smething which is true,%0A-- implies something which is false. So that's going to%0A-- be our contradiction. But Xena really%0A-- needs to be talked through this. Let's first%0A-- check that 2^2-32+2=0! Let's call this very%0A-- easy hypothesis H3.%0A--%0Ahave H3 : (2:ℤ)^2-32+2=0,%0A trivial, -- Xena can work this proof out herself.%0A--%0A-- From hypotheses H2 and H3 we can deduce that 2=1!%0Ahave H4 : (2:ℤ) = 1,%0A exact (H2 H3),%0A-- H2 applied to H3 tells us that 2=1. But Xena is smart%0A-- enough to know that 2 isn't 1.%0Ahave H5 : (2:ℤ) ≠ 1,%0A cc, -- "cc" is a proof tactic that Xena knows.%0A-- Amongst other things, it solves basic inequalities like this.%0A-- Xena currently knows a few of these tactics,%0A-- and she learns more all the time, as new ones are%0A-- implemented into her brain. It stands for%0A-- "congruence closure", not that this is much help.%0A--%0A-- Anyway, the point is that H4 and H5 now contradict%0A-- each other. So we can finish the proof!%0Acontradiction%0Aend%0A-- End M1F Sheet 1 Q1 part (a)%0A%0A-- M1F Sheet 1 Q1 part (b) is true.%0A%0Atheorem m1f_sheet01_q01b_is_T : ∀ x : ℤ, x=1 → x^2-3x+2=0 :=%0A-- This one is much easier.%0A-- First we assume the hypothesis that x=1.%0Abegin%0Aintros x H1, -- now H1 says that x=1.%0A-- Our goal is to prove that x^2-3x+2=0.%0A--%0A-- First let's simplify our goal using the%0A-- hypothesis H1.%0Asimp [H1],%0A-- our goal is now to prove 1^2-3+2=0, but Xena can do this.%0Atrivial%0Aend%0A-- End M1F Sheet 1 Q1 part (b)%0A%0A-- M1F Sheet 1 Q1 part (c) is false and this follows from part (a)%0A%0Atheorem m1f_sheet01_q01c_is_F : ¬ (∀ x : ℤ, x^2 - 3x + 2 = 0 ↔ x=1) := %0A%0Abegin%0A-- We prove it by contradiction.%0Aintro H, -- H is now the hypothesis that for all x, x^2-3x+2=0 iff x=1%0A-- We could just now copy out the proof of part a now%0A-- but we could also just use part a.%0A-- We first deduce from H that for all x, x^2-3x+2=0 implies x=1.%0Ahave H2: ∀ x : ℤ, (x^2-3x+2=0 → x=1),%0Aexact λ x, iff.elim_left (H x),%0A-- and now we note that this and part a give us our contradiction%0Aapply m1f_sheet01_q01a_is_F,%0Aassumption%0Aend%0A-- End M1F Sheet 1 Q1 part (c)%0A%0A-- M1F Sheet 1 Q1 part (d) is true but the proof is really long.%0A%0Atheorem m1f_sheet01_q01d_is_T : ∀ x : ℤ, x^2 - 3x + 2 = 0 ↔ (x=1 ∨ x=2) := %0Abegin%0A-- Now this one is going to be some work, %0A-- because we need to prove that the only roots of%0A-- the quadratic are x=1 and x=2, but Xena doesn't know%0A-- anything about solving quadratic equations.%0A--%0A-- First let's get x.%0Aintro x,%0A-- Now we have to prove an iff statement, so let's %0A-- break it up into an if and an only if.%0Aapply iff.intro,%0A-- now we have two things to prove so I'll indent.%0A -- Let's do the easy one first. (that weird v sign means "or")%0A show x=1 ∨ x=2 → x^2-3x+2=0,%0A intro H12, -- hypothesis H12 says "x=1 or x=2"%0A apply or.elim H12, -- eliminate the or, %0A intro H1, -- H1 is the hypothesis that x=1.%0A simp [H1], -- now sub in to x^2-3x+2=0,%0A trivial, -- and it's trivial.%0A -- that was x=1, and x=2 is just as easy.%0A intro H2,%0A simp [H2],%0A trivial,%0A -- now we have to do the trickier case.%0A -- %0A -- We have to prove x^2-3x+2=0 implies x=1 or x=2.%0A intro H, -- this is the hypothesis x^2-3x+2=0.%0A -- We will now show that this hypothesis H implies x=1 or x=2%0A -- by slowly introducing new hypotheses H2,H3,H4 of H, with the "have" command,%0A -- and then proving each one,%0A -- until finally we have proved x=1 or x=2.%0A%0A -- First Let's factor.%0A %0A have H2:x^2-3x+2=(x-1)(x-2),%0A -- Aargh! Lean stuggles to do this! Excuse us for a second.%0A unfold pow,%0A change (3:ℤ) with 2+1;simp [mul_add,mul_one,add_left_cancel_iff],%0A -- Done.%0A%0A have H3: (x-1)(x-2)=0, -- This follows from H1 and H2 via a calculation. %0A exact%0A calc %0A (x-1)(x-2) = x^2-3x+2 : eq.symm H2%0A ... = 0 : H%0A ,%0A%0A -- From H3 we can deduce x-1=0 or x-2=0. This is an inbuilt %0A -- fact in Lean -- if ab=0 then either a=0 or b=0. So we apply this fact. %0A have H4: (x-1)=0 ∨ (x-2)=0,%0A apply iff.elim_left mul_eq_zero_iff_eq_zero_or_eq_zero,%0A assumption,%0A%0A -- Now all we have to do is to prove that if x-1=0 then x=1, and if x-2=0 then x=2%0A%0A cases H4 with HX1 HX2,%0A -- x-1=0%0A left, -- prove the left part of "x=1 or x=2"%0A apply iff.elim_left sub_eq_zero_iff_eq HX1,%0A%0A -- x-2=0%0A right,%0A apply iff.elim_left sub_eq_zero_iff_eq HX2,%0A%0A-- QED!%0Aend%0A%0A-- End M1F Sheet 1 Q1 part (d)%0A%0A-- M1F Sheet 1 Q1 part (e) is true, and follows easily from (d)%0A%0Atheorem m1f_sheet01_q01e_is_T : ∀ x : ℤ, x^2 - 3x + 2 = 0 → (x=1 ∨ x=2 ∨ x=3) := %0Abegin%0Aintro x,%0Aintro Hx,%0Ahave H12 : x=1 ∨ x=2, %0A apply (iff.elim_left (m1f_sheet01_q01d_is_T x) Hx),%0A-- H12 is "x=1 or x=2", and goal is now "x=1 or x=2 or x=3", so looking good :-)%0A-- To understand the next lines better it might be good to think of%0A-- it as x=1 or (x=2 or x=3)%0Acases H12, -- next line is x=1, one after is x=2%0A left,assumption, %0A right,left,assumption,%0Aend%0A%0A-- End M1F Sheet 1 Q1 part (e)%0A%0A-- M1F Sheet 1 Q1 part (f) is false%0A%0Atheorem m1f_sheet01_q01f_is_F : ¬ (∀ x : ℤ, (x=1 ∨ x=2 ∨ x=3) → x^2 - 3x + 2 = 0) := %0Abegin%0Aintro H,%0Aspecialize H 3,%0A have H2 : (3:int)=1 ∨ (3:int)=2 ∨ (3:int)=3,%0A right,right,trivial,%0A%0Alet s:=(3:int)^2-33+2,%0A%0A have H3: s=0,%0A exact H H2,%0A%0A-- But it's easy to check s isn't 0:%0A have H4: s ≠ 0,%0A exact dec_trivial,%0A%0A-- H3 and H4 are a contradiction.%0Acontradiction,%0Aend%0A%0A-- End M1F Sheet 1 Q1 part (f)%0A) of this sheet. Click around and see if you can make any sense of it!
If you’d rather look at the questions than see the answers, here is a link to a Lean version of Question 1 from this sheet.