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

Commit 1cce606

Browse files
committed
feat(analysis/special_functions/trigonometric): some lemmas (#4638)
The following changes: - `sin_sub_sin` and friends (sum-to-product lemmas) moved from `trigonometric` to the earlier file `exponential`. (I think the distinction between the files is that `trigonometric` collects the facts that require either differentiation or the definition `pi`, whereas purely algebraic facts about trigonometry go in `exponential`? For example the double-angle formula is in `exponential`). - rewrite proof of `cos_lt_cos_of_nonneg_of_le_pi_div_two` to avoid dependence on `cos_eq_one_iff_of_lt_of_lt` (but not sure if the result is actually simpler, feel free to propose this be reverted) - some new explicit values of trig functions, `cos (π / 3)` and similar - correct a series of lemmas in the `complex` namespace that were stated for real arguments (presumably the author copy-pasted but forgot to rewrite) - lemmas `sin_eq_zero_iff`, `cos_eq_cos_iff`, `sin_eq_sin_iff`
1 parent e7b8421 commit 1cce606

File tree

2 files changed

+223
-38
lines changed

2 files changed

+223
-38
lines changed

src/analysis/special_functions/trigonometric.lean

Lines changed: 164 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -719,15 +719,6 @@ by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x,
719719
pow_two, pow_two, ← sub_eq_iff_eq_add, sub_self];
720720
exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩
721721

722-
theorem sin_sub_sin (θ ψ : ℝ) : sin θ - sin ψ = 2 * sin((θ - ψ)/2) * cos((θ + ψ)/2) :=
723-
begin
724-
have s1 := sin_add ((θ + ψ) / 2) ((θ - ψ) / 2),
725-
have s2 := sin_sub ((θ + ψ) / 2) ((θ - ψ) / 2),
726-
rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel, add_self_div_two] at s1,
727-
rw [div_sub_div_same, ←sub_add, add_sub_cancel', add_self_div_two] at s2,
728-
rw [s1, s2, ←sub_add, add_sub_cancel', ← two_mul, ← mul_assoc, mul_right_comm]
729-
end
730-
731722
lemma cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x :=
732723
⟨λ h, let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (or.inl h)) in
733724
⟨n / 2, (int.mod_two_eq_zero_or_one n).elim
@@ -751,25 +742,16 @@ lemma cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x <
751742
end,
752743
λ h, by simp [h]⟩
753744

754-
theorem cos_sub_cos (θ ψ : ℝ) : cos θ - cos ψ = -2 * sin((θ + ψ)/2) * sin((θ - ψ)/2) :=
755-
by rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub, sin_sub_sin, sub_sub_sub_cancel_left,
756-
add_sub, sub_add_eq_add_sub, add_halves, sub_sub, sub_div π, cos_pi_div_two_sub,
757-
← neg_sub, neg_div, sin_neg, ← neg_mul_eq_mul_neg, neg_mul_eq_neg_mul, mul_right_comm]
758-
759745
lemma cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) :
760746
cos y < cos x :=
761-
calc cos y = cos x * cos (y - x) - sin x * sin (y - x) :
762-
by rw [← cos_add, add_sub_cancel'_right]
763-
... < (cos x * 1) - sin x * sin (y - x) :
764-
sub_lt_sub_right ((mul_lt_mul_left
765-
(cos_pos_of_mem_Ioo (lt_of_lt_of_le (neg_neg_of_pos pi_div_two_pos) hx₁)
766-
(lt_of_lt_of_le hxy hy₂))).2
767-
(lt_of_le_of_ne (cos_le_one _) (mt (cos_eq_one_iff_of_lt_of_lt
768-
(show -(2 * π) < y - x, by linarith) (show y - x < 2 * π, by linarith)).1
769-
(sub_ne_zero.2 (ne_of_lt hxy).symm)))) _
770-
... ≤ _ : by rw mul_one;
771-
exact sub_le_self _ (mul_nonneg (sin_nonneg_of_nonneg_of_le_pi hx₁ (by linarith))
772-
(sin_nonneg_of_nonneg_of_le_pi (by linarith) (by linarith)))
747+
begin
748+
rw [← sub_lt_zero, cos_sub_cos],
749+
have : 0 < sin ((y + x) / 2),
750+
{ refine sin_pos_of_pos_of_lt_pi _ _; linarith },
751+
have : 0 < sin ((y - x) / 2),
752+
{ refine sin_pos_of_pos_of_lt_pi _ _; linarith },
753+
nlinarith,
754+
end
773755

774756
lemma cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) :
775757
cos y < cos x :=
@@ -999,6 +981,75 @@ by { transitivity cos (pi / 2 ^ 5), congr, norm_num, simp }
999981
lemma sin_pi_div_thirty_two : sin (pi / 32) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
1000982
by { transitivity sin (pi / 2 ^ 5), congr, norm_num, simp }
1001983

984+
-- This section is also a convenient location for other explicit values of `sin` and `cos`.
985+
986+
/-- The cosine of `π / 3` is `1 / 2`. -/
987+
lemma cos_pi_div_three : cos (π / 3) = 1 / 2 :=
988+
begin
989+
have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0,
990+
{ have : cos (3 * (π / 3)) = cos π := by { congr' 1, ring },
991+
linarith [cos_pi, cos_three_mul (π / 3)] },
992+
cases mul_eq_zero.mp h₁ with h h,
993+
{ linarith [pow_eq_zero h] },
994+
{ have : cos π < cos (π / 3),
995+
{ refine cos_lt_cos_of_nonneg_of_le_pi _ rfl.ge _;
996+
linarith [pi_pos] },
997+
linarith [cos_pi] }
998+
end
999+
1000+
/-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the
1001+
result for cosine itself). -/
1002+
lemma square_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 :=
1003+
begin
1004+
have h1 : cos (π / 6) ^ 2 = 1 / 2 + 1 / 2 / 2,
1005+
{ convert cos_square (π / 6),
1006+
have h2 : 2 * (π / 6) = π / 3 := by cancel_denoms,
1007+
rw [h2, cos_pi_div_three] },
1008+
rw ← sub_eq_zero at h1 ⊢,
1009+
convert h1 using 1,
1010+
ring
1011+
end
1012+
1013+
/-- The cosine of `π / 6` is `√3 / 2`. -/
1014+
lemma cos_pi_div_six : cos (π / 6) = (sqrt 3) / 2 :=
1015+
begin
1016+
suffices : sqrt 3 = cos (π / 6) * 2,
1017+
{ field_simp [(by norm_num : 02)], exact this.symm },
1018+
rw sqrt_eq_iff_sqr_eq,
1019+
{ have h1 := (mul_right_inj' (by norm_num : (4:ℝ) ≠ 0)).mpr square_cos_pi_div_six,
1020+
rw ← sub_eq_zero at h1 ⊢,
1021+
convert h1 using 1,
1022+
ring },
1023+
{ norm_num },
1024+
{ have : 0 < cos (π / 6) := by { apply cos_pos_of_mem_Ioo; linarith [pi_pos] },
1025+
linarith },
1026+
end
1027+
1028+
/-- The sine of `π / 6` is `1 / 2`. -/
1029+
lemma sin_pi_div_six : sin (π / 6) = 1 / 2 :=
1030+
begin
1031+
rw [← cos_pi_div_two_sub, ← cos_pi_div_three],
1032+
congr,
1033+
ring
1034+
end
1035+
1036+
/-- The square of the sine of `π / 3` is `3 / 4` (this is sometimes more convenient than the
1037+
result for cosine itself). -/
1038+
lemma square_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 :=
1039+
begin
1040+
rw [← cos_pi_div_two_sub, ← square_cos_pi_div_six],
1041+
congr,
1042+
ring
1043+
end
1044+
1045+
/-- The sine of `π / 3` is `√3 / 2`. -/
1046+
lemma sin_pi_div_three : sin (π / 3) = (sqrt 3) / 2 :=
1047+
begin
1048+
rw [← cos_pi_div_two_sub, ← cos_pi_div_six],
1049+
congr,
1050+
ring
1051+
end
1052+
10021053
end cos_div_pow_two
10031054

10041055
/-- The type of angles -/
@@ -1659,40 +1710,40 @@ by simp [two_mul, sin_add]
16591710
@[simp] lemma cos_two_pi : cos (2 * π) = 1 :=
16601711
by simp [two_mul, cos_add]
16611712

1662-
lemma sin_add_pi (x : ) : sin (x + π) = -sin x :=
1713+
lemma sin_add_pi (x : ) : sin (x + π) = -sin x :=
16631714
by simp [sin_add]
16641715

1665-
lemma sin_add_two_pi (x : ) : sin (x + 2 * π) = sin x :=
1716+
lemma sin_add_two_pi (x : ) : sin (x + 2 * π) = sin x :=
16661717
by simp [sin_add_pi, sin_add, sin_two_pi, cos_two_pi]
16671718

1668-
lemma cos_add_two_pi (x : ) : cos (x + 2 * π) = cos x :=
1719+
lemma cos_add_two_pi (x : ) : cos (x + 2 * π) = cos x :=
16691720
by simp [cos_add, cos_two_pi, sin_two_pi]
16701721

1671-
lemma sin_pi_sub (x : ) : sin (π - x) = sin x :=
1722+
lemma sin_pi_sub (x : ) : sin (π - x) = sin x :=
16721723
by simp [sub_eq_add_neg, sin_add]
16731724

1674-
lemma cos_add_pi (x : ) : cos (x + π) = -cos x :=
1725+
lemma cos_add_pi (x : ) : cos (x + π) = -cos x :=
16751726
by simp [cos_add]
16761727

1677-
lemma cos_pi_sub (x : ) : cos (π - x) = -cos x :=
1728+
lemma cos_pi_sub (x : ) : cos (π - x) = -cos x :=
16781729
by simp [sub_eq_add_neg, cos_add]
16791730

1680-
lemma sin_add_pi_div_two (x : ) : sin (x + π / 2) = cos x :=
1731+
lemma sin_add_pi_div_two (x : ) : sin (x + π / 2) = cos x :=
16811732
by simp [sin_add]
16821733

1683-
lemma sin_sub_pi_div_two (x : ) : sin (x - π / 2) = -cos x :=
1734+
lemma sin_sub_pi_div_two (x : ) : sin (x - π / 2) = -cos x :=
16841735
by simp [sub_eq_add_neg, sin_add]
16851736

1686-
lemma sin_pi_div_two_sub (x : ) : sin (π / 2 - x) = cos x :=
1737+
lemma sin_pi_div_two_sub (x : ) : sin (π / 2 - x) = cos x :=
16871738
by simp [sub_eq_add_neg, sin_add]
16881739

1689-
lemma cos_add_pi_div_two (x : ) : cos (x + π / 2) = -sin x :=
1740+
lemma cos_add_pi_div_two (x : ) : cos (x + π / 2) = -sin x :=
16901741
by simp [cos_add]
16911742

1692-
lemma cos_sub_pi_div_two (x : ) : cos (x - π / 2) = sin x :=
1743+
lemma cos_sub_pi_div_two (x : ) : cos (x - π / 2) = sin x :=
16931744
by simp [sub_eq_add_neg, cos_add]
16941745

1695-
lemma cos_pi_div_two_sub (x : ) : cos (π / 2 - x) = sin x :=
1746+
lemma cos_pi_div_two_sub (x : ) : cos (π / 2 - x) = sin x :=
16961747
by rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
16971748

16981749
lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
@@ -1733,6 +1784,63 @@ end
17331784
theorem cos_ne_zero_iff {θ : ℂ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 :=
17341785
by rw [← not_exists, not_iff_not, cos_eq_zero_iff]
17351786

1787+
theorem sin_eq_zero_iff {θ : ℂ} : sin θ = 0 ↔ ∃ k : ℤ, θ = k * π :=
1788+
begin
1789+
rw [← complex.cos_sub_pi_div_two, cos_eq_zero_iff],
1790+
split,
1791+
{ rintros ⟨k, hk⟩,
1792+
use k + 1,
1793+
field_simp [eq_add_of_sub_eq hk],
1794+
ring },
1795+
{ rintros ⟨k, rfl⟩,
1796+
use k - 1,
1797+
field_simp,
1798+
ring }
1799+
end
1800+
1801+
theorem sin_ne_zero_iff {θ : ℂ} : sin θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ k * π :=
1802+
by rw [← not_exists, not_iff_not, sin_eq_zero_iff]
1803+
1804+
lemma cos_eq_cos_iff {x y : ℂ} :
1805+
cos x = cos y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x :=
1806+
calc cos x = cos y ↔ cos x - cos y = 0 : sub_eq_zero.symm
1807+
... ↔ -2 * sin((x + y)/2) * sin((x - y)/2) = 0 : by rw cos_sub_cos
1808+
... ↔ sin((x + y)/2) = 0 ∨ sin((x - y)/2) = 0 : by { field_simp [(by norm_num : -(2:ℂ) ≠ 0)] }
1809+
... ↔ sin((x - y)/2) = 0 ∨ sin((x + y)/2) = 0 : or.comm
1810+
... ↔ (∃ k : ℤ, y = 2 * k * π + x) ∨ (∃ k :ℤ, y = 2 * k * π - x) :
1811+
begin
1812+
apply or_congr;
1813+
rw sin_eq_zero_iff;
1814+
field_simp [(by norm_num : -(2:ℂ) ≠ 0)],
1815+
work_on_goal 0 -- material specific to the left of the `or`, when x ≅ y mod 2π
1816+
{ split,
1817+
all_goals
1818+
{ rintros ⟨k, hk⟩,
1819+
refine ⟨-k, eq.symm _⟩ } },
1820+
work_on_goal 2 -- material specific to the right of the `or`, when x ≅ -y mod 2π
1821+
{ refine exists_congr (λ k, ⟨λ hk, _, λ hk, _⟩) },
1822+
all_goals -- joint material for showing two equations differ by a constant
1823+
{ rw ← sub_eq_zero at hk ⊢,
1824+
convert hk using 1,
1825+
try { push_cast },
1826+
ring }
1827+
end
1828+
... ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x : exists_or_distrib.symm
1829+
1830+
lemma sin_eq_sin_iff {x y : ℂ} :
1831+
sin x = sin y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = (2 * k + 1) * π - x :=
1832+
begin
1833+
rw [←complex.cos_sub_pi_div_two, ←complex.cos_sub_pi_div_two, cos_eq_cos_iff],
1834+
simp only [exists_or_distrib],
1835+
apply or_congr;
1836+
refine exists_congr (λ k, ⟨_, _⟩);
1837+
{ intros h,
1838+
rw ← sub_eq_zero at ⊢ h,
1839+
convert h using 1,
1840+
field_simp,
1841+
ring },
1842+
end
1843+
17361844
lemma has_deriv_at_tan {x : ℂ} (h : ∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) :
17371845
has_deriv_at tan (1 / (cos x)^2) x :=
17381846
begin
@@ -1770,6 +1878,24 @@ end
17701878
theorem cos_ne_zero_iff {θ : ℝ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 :=
17711879
by rw [← not_exists, not_iff_not, cos_eq_zero_iff]
17721880

1881+
lemma cos_eq_cos_iff {x y : ℝ} :
1882+
cos x = cos y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x :=
1883+
begin
1884+
have := @complex.cos_eq_cos_iff x y,
1885+
rw [← complex.of_real_cos, ← complex.of_real_cos] at this,
1886+
norm_cast at this,
1887+
simp [this],
1888+
end
1889+
1890+
lemma sin_eq_sin_iff {x y : ℝ} :
1891+
sin x = sin y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = (2 * k + 1) * π - x :=
1892+
begin
1893+
have := @complex.sin_eq_sin_iff x y,
1894+
rw [← complex.of_real_sin, ← complex.of_real_sin] at this,
1895+
norm_cast at this,
1896+
simp [this],
1897+
end
1898+
17731899
lemma has_deriv_at_tan {x : ℝ} (h : ∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) :
17741900
has_deriv_at tan (1 / (cos x)^2) x :=
17751901
begin

src/data/complex/exponential.lean

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,38 @@ by simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg]
695695
lemma cos_sub : cos (x - y) = cos x * cos y + sin x * sin y :=
696696
by simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg]
697697

698+
theorem sin_sub_sin : sin x - sin y = 2 * sin((x - y)/2) * cos((x + y)/2) :=
699+
begin
700+
have s1 := sin_add ((x + y) / 2) ((x - y) / 2),
701+
have s2 := sin_sub ((x + y) / 2) ((x - y) / 2),
702+
rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel, half_add_self] at s1,
703+
rw [div_sub_div_same, ←sub_add, add_sub_cancel', half_add_self] at s2,
704+
rw [s1, s2],
705+
ring
706+
end
707+
708+
theorem cos_sub_cos : cos x - cos y = -2 * sin((x + y)/2) * sin((x - y)/2) :=
709+
begin
710+
have s1 := cos_add ((x + y) / 2) ((x - y) / 2),
711+
have s2 := cos_sub ((x + y) / 2) ((x - y) / 2),
712+
rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel, half_add_self] at s1,
713+
rw [div_sub_div_same, ←sub_add, add_sub_cancel', half_add_self] at s2,
714+
rw [s1, s2],
715+
ring,
716+
end
717+
718+
lemma cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) :=
719+
begin
720+
have h2 : (2:ℂ) ≠ 0 := by norm_num,
721+
calc cos x + cos y = cos ((x + y) / 2 + (x - y) / 2) + cos ((x + y) / 2 - (x - y) / 2) : _
722+
... = (cos ((x + y) / 2) * cos ((x - y) / 2) - sin ((x + y) / 2) * sin ((x - y) / 2))
723+
+ (cos ((x + y) / 2) * cos ((x - y) / 2) + sin ((x + y) / 2) * sin ((x - y) / 2)) : _
724+
... = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) : _,
725+
{ congr; field_simp [h2]; ring },
726+
{ rw [cos_add, cos_sub] },
727+
ring,
728+
end
729+
698730
lemma sin_conj : sin (conj x) = conj (sin x) :=
699731
by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I,
700732
← conj_neg_I, ← conj.map_mul, ← conj.map_mul, sinh_conj,
@@ -873,6 +905,33 @@ by simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg]
873905
lemma cos_sub : cos (x - y) = cos x * cos y + sin x * sin y :=
874906
by simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg]
875907

908+
lemma sin_sub_sin : sin x - sin y = 2 * sin((x - y)/2) * cos((x + y)/2) :=
909+
begin
910+
rw ← of_real_inj,
911+
simp only [sin, cos, of_real_sin_of_real_re, of_real_sub, of_real_add, of_real_div, of_real_mul,
912+
of_real_one, of_real_bit0],
913+
convert sin_sub_sin _ _;
914+
norm_cast
915+
end
916+
917+
theorem cos_sub_cos : cos x - cos y = -2 * sin((x + y)/2) * sin((x - y)/2) :=
918+
begin
919+
rw ← of_real_inj,
920+
simp only [cos, neg_mul_eq_neg_mul_symm, of_real_sin, of_real_sub, of_real_add,
921+
of_real_cos_of_real_re, of_real_div, of_real_mul, of_real_one, of_real_neg, of_real_bit0],
922+
convert cos_sub_cos _ _,
923+
ring,
924+
end
925+
926+
lemma cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) :=
927+
begin
928+
rw ← of_real_inj,
929+
simp only [cos, of_real_sub, of_real_add, of_real_cos_of_real_re, of_real_div, of_real_mul,
930+
of_real_one, of_real_bit0],
931+
convert cos_add_cos _ _;
932+
norm_cast,
933+
end
934+
876935
lemma tan_eq_sin_div_cos : tan x = sin x / cos x :=
877936
if h : complex.cos x = 0 then by simp [sin, cos, tan, *, complex.tan, div_eq_mul_inv] at *
878937
else

0 commit comments

Comments
 (0)