Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 7dcaee1

Browse files
lackerPatrickMassot
andcommitted
feat(archive/imo): formalize IMO 1962 problem 4 (#4518)
The problem statement: Solve the equation `cos x ^ 2 + cos (2 * x) ^ 2 + cos (3 * x) ^ 2 = 1`. There are a bunch of trig formulas I proved along the way; there are sort of an infinite number of trig formulas so I'm open to feedback on whether some should go in the core libraries. Also possibly some of them have a shorter proof that would render the lemma unnecessary. For what it's worth, the actual method of solution is not how a human would do it; a more intuitive human method is to simplify in terms of `cos x` and then solve, but I think this is simpler in Lean because it doesn't rely on solving `cos x = y` for several different `y`. Co-authored-by: Patrick Massot <patrickmassot@free.fr>
1 parent b231d8e commit 7dcaee1

File tree

2 files changed

+197
-11
lines changed

2 files changed

+197
-11
lines changed

archive/imo/imo1962_q4.lean

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/-
2+
Copyright (c) 2020 Kevin Lacker. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Kevin Lacker
5+
-/
6+
7+
import analysis.special_functions.trigonometric
8+
9+
/-!
10+
# IMO 1962 Q4
11+
12+
Solve the equation `cos x ^ 2 + cos (2 * x) ^ 2 + cos (3 * x) ^ 2 = 1`.
13+
14+
Since Lean does not have a concept of "simplest form", we just express what is
15+
in fact the simplest form of the set of solutions, and then prove it equals the set of solutions.
16+
-/
17+
18+
open real
19+
open_locale real
20+
noncomputable theory
21+
22+
def problem_equation (x : ℝ) : Prop := cos x ^ 2 + cos (2 * x) ^ 2 + cos (3 * x) ^ 2 = 1
23+
24+
def solution_set : set ℝ :=
25+
{ x : ℝ | ∃ k : ℤ, x = (2 * ↑k + 1) * π / 4 ∨ x = (2 * ↑k + 1) * π / 6 }
26+
27+
/-
28+
The key to solving this problem simply is that we can rewrite the equation as
29+
a product of terms, shown in `alt_formula`, being equal to zero.
30+
-/
31+
32+
def alt_formula (x : ℝ) : ℝ := cos x * (cos x ^ 2 - 1/2) * cos (3 * x)
33+
34+
lemma cos_sum_equiv {x : ℝ} :
35+
(cos x ^ 2 + cos (2 * x) ^ 2 + cos (3 * x) ^ 2 - 1) / 4 = alt_formula x :=
36+
begin
37+
simp only [real.cos_two_mul, cos_three_mul, alt_formula],
38+
ring
39+
end
40+
41+
lemma alt_equiv {x : ℝ} : problem_equation x ↔ alt_formula x = 0 :=
42+
begin
43+
rw [ problem_equation, ← cos_sum_equiv, div_eq_zero_iff, sub_eq_zero],
44+
norm_num,
45+
end
46+
47+
lemma finding_zeros {x : ℝ} :
48+
alt_formula x = 0 ↔ cos x ^ 2 = 1/2 ∨ cos (3 * x) = 0 :=
49+
begin
50+
simp only [alt_formula, mul_assoc, mul_eq_zero, sub_eq_zero],
51+
split,
52+
{ rintro (h1|h2),
53+
{ right,
54+
rw [cos_three_mul, h1],
55+
ring },
56+
{ exact h2 } },
57+
{ exact or.inr }
58+
end
59+
60+
/-
61+
Now we can solve for `x` using basic-ish trigonometry.
62+
-/
63+
64+
lemma solve_cos2_half {x : ℝ} : cos x ^ 2 = 1/2 ↔ ∃ k : ℤ, x = (2 * ↑k + 1) * π / 4 :=
65+
begin
66+
rw cos_square,
67+
simp only [add_right_eq_self, div_eq_zero_iff],
68+
norm_num,
69+
rw cos_eq_zero_iff,
70+
split;
71+
{ rintro ⟨k, h⟩,
72+
use k,
73+
linarith },
74+
end
75+
76+
lemma solve_cos3x_0 {x : ℝ} : cos (3 * x) = 0 ↔ ∃ k : ℤ, x = (2 * ↑k + 1) * π / 6 :=
77+
begin
78+
rw cos_eq_zero_iff,
79+
apply exists_congr,
80+
intro k,
81+
split; intro; linarith
82+
end
83+
84+
/-
85+
The final theorem is now just gluing together our lemmas.
86+
-/
87+
88+
theorem imo1962_q4 {x : ℝ} : problem_equation x ↔ x ∈ solution_set :=
89+
begin
90+
rw [alt_equiv, finding_zeros, solve_cos3x_0, solve_cos2_half],
91+
exact exists_or_distrib.symm
92+
end
93+

src/data/complex/exponential.lean

Lines changed: 104 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import data.complex.basic
1010
# Exponential, trigonometric and hyperbolic trigonometric functions
1111
1212
This file contains the definitions of the real and complex exponential, sine, cosine, tangent,
13-
hyperbolic sine, hypebolic cosine, and hyperbolic tangent functions.
13+
hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions.
1414
1515
-/
1616
local notation `abs'` := _root_.abs
@@ -609,6 +609,47 @@ by rw [← mul_right_inj' (@two_ne_zero' ℂ _ _ _), mul_sub,
609609
lemma cosh_sq_sub_sinh_sq : cosh x ^ 2 - sinh x ^ 2 = 1 :=
610610
by rw [sq_sub_sq, cosh_add_sinh, cosh_sub_sinh, ← exp_add, add_neg_self, exp_zero]
611611

612+
lemma cosh_square : cosh x ^ 2 = sinh x ^ 2 + 1 :=
613+
begin
614+
rw ← cosh_sq_sub_sinh_sq x,
615+
ring
616+
end
617+
618+
lemma sinh_square : sinh x ^ 2 = cosh x ^ 2 - 1 :=
619+
begin
620+
rw ← cosh_sq_sub_sinh_sq x,
621+
ring
622+
end
623+
624+
lemma cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 :=
625+
by rw [two_mul, cosh_add, pow_two, pow_two]
626+
627+
lemma sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x :=
628+
begin
629+
rw [two_mul, sinh_add],
630+
ring
631+
end
632+
633+
lemma cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x :=
634+
begin
635+
have h1 : x + 2 * x = 3 * x, by ring,
636+
rw [← h1, cosh_add x (2 * x)],
637+
simp only [cosh_two_mul, sinh_two_mul],
638+
have h2 : sinh x * (2 * sinh x * cosh x) = 2 * cosh x * sinh x ^ 2, by ring,
639+
rw [h2, sinh_square],
640+
ring
641+
end
642+
643+
lemma sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x :=
644+
begin
645+
have h1 : x + 2 * x = 3 * x, by ring,
646+
rw [← h1, sinh_add x (2 * x)],
647+
simp only [cosh_two_mul, sinh_two_mul],
648+
have h2 : cosh x * (2 * sinh x * cosh x) = 2 * sinh x * cosh x ^ 2, by ring,
649+
rw [h2, cosh_square],
650+
ring,
651+
end
652+
612653
@[simp] lemma sin_zero : sin 0 = 0 := by simp [sin]
613654

614655
@[simp] lemma sin_neg : sin (-x) = -sin x :=
@@ -729,9 +770,32 @@ by rw [two_mul, sin_add, two_mul, add_mul, mul_comm]
729770
lemma cos_square : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 :=
730771
by simp [cos_two_mul, div_add_div_same, mul_div_cancel_left, two_ne_zero', -one_div]
731772

773+
lemma cos_square' : cos x ^ 2 = 1 - sin x ^ 2 :=
774+
by { rw [←sin_sq_add_cos_sq x], simp }
775+
732776
lemma sin_square : sin x ^ 2 = 1 - cos x ^ 2 :=
733777
by { rw [←sin_sq_add_cos_sq x], simp }
734778

779+
lemma cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x :=
780+
begin
781+
have h1 : x + 2 * x = 3 * x, by ring,
782+
rw [← h1, cos_add x (2 * x)],
783+
simp only [cos_two_mul, sin_two_mul, mul_add, mul_sub, mul_one, pow_two],
784+
have h2 : 4 * cos x ^ 3 = 2 * cos x * cos x * cos x + 2 * cos x * cos x ^ 2, by ring,
785+
rw [h2, cos_square'],
786+
ring
787+
end
788+
789+
lemma sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 :=
790+
begin
791+
have h1 : x + 2 * x = 3 * x, by ring,
792+
rw [← h1, sin_add x (2 * x)],
793+
simp only [cos_two_mul, sin_two_mul, cos_square'],
794+
have h2 : cos x * (2 * sin x * cos x) = 2 * sin x * cos x ^ 2, by ring,
795+
rw [h2, cos_square'],
796+
ring
797+
end
798+
735799
lemma exp_mul_I : exp (x * I) = cos x + sin x * I :=
736800
(cos_add_sin_I _).symm
737801

@@ -853,15 +917,27 @@ lemma neg_one_le_cos : -1 ≤ cos x :=
853917
lemma cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 :=
854918
by rw ← of_real_inj; simp [cos_two_mul]
855919

920+
lemma cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 :=
921+
by rw ← of_real_inj; simp [cos_two_mul']
922+
856923
lemma sin_two_mul : sin (2 * x) = 2 * sin x * cos x :=
857924
by rw ← of_real_inj; simp [sin_two_mul]
858925

859926
lemma cos_square : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 :=
860927
of_real_inj.1 $ by simpa using cos_square x
861928

929+
lemma cos_square' : cos x ^ 2 = 1 - sin x ^ 2 :=
930+
by { rw [←sin_sq_add_cos_sq x], simp }
931+
862932
lemma sin_square : sin x ^ 2 = 1 - cos x ^ 2 :=
863933
eq_sub_iff_add_eq.2 $ sin_sq_add_cos_sq _
864934

935+
lemma cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x :=
936+
by rw ← of_real_inj; simp [cos_three_mul]
937+
938+
lemma sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 :=
939+
by rw ← of_real_inj; simp [sin_three_mul]
940+
865941
/-- The definition of `sinh` in terms of `exp`. -/
866942
lemma sinh_eq (x : ℝ) : sinh x = (exp x - exp (-x)) / 2 :=
867943
eq_div_of_mul_eq two_ne_zero $ by rw [sinh, exp, exp, complex.of_real_neg, complex.sinh, mul_two,
@@ -894,23 +970,40 @@ by simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg]
894970
lemma cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y :=
895971
by simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg]
896972

897-
lemma cosh_sq_sub_sinh_sq (x : ℝ) : cosh x ^ 2 - sinh x ^ 2 = 1 :=
898-
begin
899-
rw [sinh, cosh],
900-
have := congr_arg complex.re (complex.cosh_sq_sub_sinh_sq x),
901-
rw [pow_two, pow_two] at this,
902-
change (⟨_, _⟩ : ℂ).re - (⟨_, _⟩ : ℂ).re = 1 at this,
903-
rw [complex.cosh_of_real_im x, complex.sinh_of_real_im x, mul_zero, sub_zero, sub_zero] at this,
904-
rwa [pow_two, pow_two],
905-
end
906-
907973
lemma tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x :=
908974
of_real_inj.1 $ by simp [tanh_eq_sinh_div_cosh]
909975

910976
@[simp] lemma tanh_zero : tanh 0 = 0 := by simp [tanh]
911977

912978
@[simp] lemma tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div]
913979

980+
lemma cosh_add_sinh : cosh x + sinh x = exp x :=
981+
by rw ← of_real_inj; simp [cosh_add_sinh]
982+
983+
lemma sinh_add_cosh : sinh x + cosh x = exp x :=
984+
by rw ← of_real_inj; simp [sinh_add_cosh]
985+
986+
lemma cosh_sq_sub_sinh_sq (x : ℝ) : cosh x ^ 2 - sinh x ^ 2 = 1 :=
987+
by rw ← of_real_inj; simp [cosh_sq_sub_sinh_sq]
988+
989+
lemma cosh_square : cosh x ^ 2 = sinh x ^ 2 + 1 :=
990+
by rw ← of_real_inj; simp [cosh_square]
991+
992+
lemma sinh_square : sinh x ^ 2 = cosh x ^ 2 - 1 :=
993+
by rw ← of_real_inj; simp [sinh_square]
994+
995+
lemma cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 :=
996+
by rw ← of_real_inj; simp [cosh_two_mul]
997+
998+
lemma sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x :=
999+
by rw ← of_real_inj; simp [sinh_two_mul]
1000+
1001+
lemma cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x :=
1002+
by rw ← of_real_inj; simp [cosh_three_mul]
1003+
1004+
lemma sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x :=
1005+
by rw ← of_real_inj; simp [sinh_three_mul]
1006+
9141007
open is_absolute_value
9151008

9161009
/- TODO make this private and prove ∀ x -/

0 commit comments

Comments
 (0)