Question: My solution is probably the longest lean4 code I've ever written. That suggests I've missed a trick. I'd welcome feedback.
My Approach: I did this pen-n-paper first, and took a different approach to the two parts of the proof.
The first part can be done algebraically by considering n = 3*k in cases where k is even and odd.. That is, n = 3*(2j) and n=3*(2j+1).The algebra leads to n^2 ≡ 0 or 3 mod 6.
The second part I couldn't do with the same algebraic approach so had to do by cases on c where n=2*c. This means testing all 6 cases, which feels like I've missed something.
spoiler MoP Exercise 9.2 ex 7
example:{n:ℤ|3∣n}∪{n:ℤ|2∣n}⊆{n:ℤ|n^2≡1[ZMOD6]}ᶜ:=bydsimp[Set.subset_def]introxhxobtainha|hb:=hx·-- 3 | xdsimp[·∣·]at*obtain⟨m,hm⟩:=haobtainga|gb:=Int.even_or_oddm·obtain⟨k,hk⟩:=gahavehh:=calcx^2=(3*m)^2:=byrw[hm]_=9*m^2:=byring_=9*(2*k)^2:=byrw[hk]_=0+6*(6*k^2):=byring_≡0[ZMOD6]:=byextraby_contragxhavegx2:=calc0≡x^2[ZMOD6]:=byrel[hh]_≡1[ZMOD6]:=byrel[gx]numbersatgx2·obtain⟨k,hk⟩:=gbhavehh:=calcx^2=(3*m)^2:=byrw[hm]_=9*m^2:=byring_=9*(2*k+1)^2:=byrw[hk]_=9*(4*k^2+4*k+1):=byring_=36*(k^2+k)+9:=byring_=3+6*(6*(k^2+k)+1):=byring_≡3[ZMOD6]:=byextraby_contragxhavegx2:=calc3≡x^2[ZMOD6]:=byrel[hh]_≡1[ZMOD6]:=byrel[gx]numbersatgx2·-- 2 | xdsimp[·∣·]at*obtain⟨c,hc⟩:=hbhavehc2:=calcx^2=(2*c)^2:=byrw[hc]_=4*c^2:=byringmod_caseshx:c%6·-- c ≡ 0 mod 6havehy:=calcx^2=4*c^2:=byrw[hc2]_≡4*(0)^2[ZMOD6]:=byrel[hx]_=0:=bynorm_num_≡0[ZMOD6]:=byextraby_contragxhavexx:=calc0≡x^2[ZMOD6]:=byrel[hy]_≡1[ZMOD6]:=byrel[gx]numbersatxx·-- c ≡ 1 mod 6havehy:=calcx^2=4*c^2:=byrw[hc2]_≡4*(1)^2[ZMOD6]:=byrel[hx]_=4:=bynorm_num_≡4[ZMOD6]:=byextraby_contragxhavexx:=calc4≡x^2[ZMOD6]:=byrel[hy]_≡1[ZMOD6]:=byrel[gx]numbersatxx·-- c ≡ 2 mod 6havehy:=calcx^2=4*c^2:=byrw[hc2]_≡4*(2)^2[ZMOD6]:=byrel[hx]_=4+6*2:=bynorm_num_≡4[ZMOD6]:=byextraby_contragxhavexx:=calc4≡x^2[ZMOD6]:=byrel[hy]_≡1[ZMOD6]:=byrel[gx]numbersatxx·-- c ≡ 3 mod 6havehy:=calcx^2=4*c^2:=byrw[hc2]_≡4*(3)^2[ZMOD6]:=byrel[hx]_=0+6*6:=bynorm_num_≡0[ZMOD6]:=byextraby_contragxhavexx:=calc0≡x^2[ZMOD6]:=byrel[hy]_≡1[ZMOD6]:=byrel[gx]numbersatxx·-- c ≡ 4 mod 6havehy:=calcx^2=4*c^2:=byrw[hc2]_≡4*(4)^2[ZMOD6]:=byrel[hx]_=4+6*10:=bynorm_num_≡4[ZMOD6]:=byextraby_contragxhavexx:=calc4≡x^2[ZMOD6]:=byrel[hy]_≡1[ZMOD6]:=byrel[gx]numbersatxx·-- c ≡ 5 mod 6havehy:=calcx^2=4*c^2:=byrw[hc2]_≡4*(5)^2[ZMOD6]:=byrel[hx]_=4+6*16:=bynorm_num_≡4[ZMOD6]:=byextraby_contragxhavexx:=calc4≡x^2[ZMOD6]:=byrel[hy]_≡1[ZMOD6]:=byrel[gx]numbersatxx
example:{n:ℤ|3∣n}∪{n:ℤ|2∣n}⊆{n:ℤ|n^2≡1[ZMOD6]}ᶜ:=bysimponly[Int.modEq_iff_dvd,Set.union_subset_iff]constructor<;>·intronhn-- can merge this and the next line with `rintro n ⟨n', rfl⟩`obtain⟨n',rfl⟩:=hnsimp[mul_pow]omega
When I'd been writing Lean 3 for a few months I remember producing a monstrously large proof that 3 was irrational (perhaps even longer than the code snippet above). I was triumphant when I got it compiling. I then #printed the proof, captured it as an image, ray-traced it, imported it into blender and then one of my kids thickened it up, coloured it in, bent it around and added a little character who could jump on the code so the proof became a platformer with the goal being to jump from one end of the proof to the other (I don't think anyone ever succeeded, the proof was that long). We then took a screenshot of the result, and a year or two later when I was asked by the London Maths Society to write something about Lean I sent them the image and they put it on the front page of their newsletter https://www.lms.ac.uk/sites/lms.ac.uk/files/files/NLMS_484-forweb2.pdf . Maybe there's a moral there somewhere.