/
trigonometric.lean
2123 lines (1688 loc) · 85 KB
/
trigonometric.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import analysis.special_functions.exp_log
import data.set.intervals.infinite
import algebra.quadratic_discriminant
/-!
# Trigonometric functions
## Main definitions
This file contains the following definitions:
* π, arcsin, arccos, arctan
* argument of a complex number
* logarithm on complex numbers
## Main statements
Many basic inequalities on trigonometric functions are established.
The continuity and differentiability of the usual trigonometric functions are proved, and their
derivatives are computed.
## Tags
log, sin, cos, tan, arcsin, arccos, arctan, angle, argument
-/
noncomputable theory
open_locale classical
open set
namespace complex
/-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/
lemma has_deriv_at_sin (x : ℂ) : has_deriv_at sin (cos x) x :=
begin
simp only [cos, div_eq_mul_inv],
convert ((((has_deriv_at_id x).neg.mul_const I).cexp.sub
((has_deriv_at_id x).mul_const I).cexp).mul_const I).mul_const (2:ℂ)⁻¹,
simp only [function.comp, id],
rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc,
I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm]
end
lemma differentiable_sin : differentiable ℂ sin :=
λx, (has_deriv_at_sin x).differentiable_at
lemma differentiable_at_sin {x : ℂ} : differentiable_at ℂ sin x :=
differentiable_sin x
@[simp] lemma deriv_sin : deriv sin = cos :=
funext $ λ x, (has_deriv_at_sin x).deriv
lemma continuous_sin : continuous sin :=
differentiable_sin.continuous
lemma continuous_on_sin {s : set ℂ} : continuous_on sin s := continuous_sin.continuous_on
lemma measurable_sin : measurable sin := continuous_sin.measurable
/-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/
lemma has_deriv_at_cos (x : ℂ) : has_deriv_at cos (-sin x) x :=
begin
simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul],
convert (((has_deriv_at_id x).mul_const I).cexp.add
((has_deriv_at_id x).neg.mul_const I).cexp).mul_const (2:ℂ)⁻¹,
simp only [function.comp, id],
ring
end
lemma differentiable_cos : differentiable ℂ cos :=
λx, (has_deriv_at_cos x).differentiable_at
lemma differentiable_at_cos {x : ℂ} : differentiable_at ℂ cos x :=
differentiable_cos x
lemma deriv_cos {x : ℂ} : deriv cos x = -sin x :=
(has_deriv_at_cos x).deriv
@[simp] lemma deriv_cos' : deriv cos = (λ x, -sin x) :=
funext $ λ x, deriv_cos
lemma continuous_cos : continuous cos :=
differentiable_cos.continuous
lemma continuous_on_cos {s : set ℂ} : continuous_on cos s := continuous_cos.continuous_on
lemma measurable_cos : measurable cos := continuous_cos.measurable
/-- The complex hyperbolic sine function is everywhere differentiable, with the derivative `cosh x`. -/
lemma has_deriv_at_sinh (x : ℂ) : has_deriv_at sinh (cosh x) x :=
begin
simp only [cosh, div_eq_mul_inv],
convert ((has_deriv_at_exp x).sub (has_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹,
rw [id, mul_neg_one, neg_neg]
end
lemma differentiable_sinh : differentiable ℂ sinh :=
λx, (has_deriv_at_sinh x).differentiable_at
lemma differentiable_at_sinh {x : ℂ} : differentiable_at ℂ sinh x :=
differentiable_sinh x
@[simp] lemma deriv_sinh : deriv sinh = cosh :=
funext $ λ x, (has_deriv_at_sinh x).deriv
lemma continuous_sinh : continuous sinh :=
differentiable_sinh.continuous
lemma measurable_sinh : measurable sinh := continuous_sinh.measurable
/-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative `sinh x`. -/
lemma has_deriv_at_cosh (x : ℂ) : has_deriv_at cosh (sinh x) x :=
begin
simp only [sinh, div_eq_mul_inv],
convert ((has_deriv_at_exp x).add (has_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹,
rw [id, mul_neg_one, sub_eq_add_neg]
end
lemma differentiable_cosh : differentiable ℂ cosh :=
λx, (has_deriv_at_cosh x).differentiable_at
lemma differentiable_at_cosh {x : ℂ} : differentiable_at ℂ cos x :=
differentiable_cos x
@[simp] lemma deriv_cosh : deriv cosh = sinh :=
funext $ λ x, (has_deriv_at_cosh x).deriv
lemma continuous_cosh : continuous cosh :=
differentiable_cosh.continuous
lemma measurable_cosh : measurable cosh := continuous_cosh.measurable
end complex
section
/-! Register lemmas for the derivatives of the composition of `complex.cos`, `complex.sin`,
`complex.cosh` and `complex.sinh` with a differentiable function, for standalone use and use with
`simp`. -/
variables {f : ℂ → ℂ} {f' x : ℂ} {s : set ℂ}
/-! `complex.cos`-/
lemma measurable.ccos (hf : measurable f) : measurable (λ x, complex.cos (f x)) :=
complex.measurable_cos.comp hf
lemma has_deriv_at.ccos (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') x :=
(complex.has_deriv_at_cos (f x)).comp x hf
lemma has_deriv_within_at.ccos (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') s x :=
(complex.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.ccos (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.cos (f x)) s x :=
hf.has_deriv_within_at.ccos.differentiable_within_at
@[simp] lemma differentiable_at.ccos (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.cos (f x)) x :=
hc.has_deriv_at.ccos.differentiable_at
lemma differentiable_on.ccos (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.cos (f x)) s :=
λx h, (hc x h).ccos
@[simp] lemma differentiable.ccos (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.cos (f x)) :=
λx, (hc x).ccos
lemma deriv_within_ccos (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.cos (f x)) s x = - complex.sin (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.ccos.deriv_within hxs
@[simp] lemma deriv_ccos (hc : differentiable_at ℂ f x) :
deriv (λx, complex.cos (f x)) x = - complex.sin (f x) * (deriv f x) :=
hc.has_deriv_at.ccos.deriv
/-! `complex.sin`-/
lemma measurable.csin (hf : measurable f) : measurable (λ x, complex.sin (f x)) :=
complex.measurable_sin.comp hf
lemma has_deriv_at.csin (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') x :=
(complex.has_deriv_at_sin (f x)).comp x hf
lemma has_deriv_within_at.csin (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') s x :=
(complex.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.csin (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.sin (f x)) s x :=
hf.has_deriv_within_at.csin.differentiable_within_at
@[simp] lemma differentiable_at.csin (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.sin (f x)) x :=
hc.has_deriv_at.csin.differentiable_at
lemma differentiable_on.csin (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.sin (f x)) s :=
λx h, (hc x h).csin
@[simp] lemma differentiable.csin (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.sin (f x)) :=
λx, (hc x).csin
lemma deriv_within_csin (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.sin (f x)) s x = complex.cos (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.csin.deriv_within hxs
@[simp] lemma deriv_csin (hc : differentiable_at ℂ f x) :
deriv (λx, complex.sin (f x)) x = complex.cos (f x) * (deriv f x) :=
hc.has_deriv_at.csin.deriv
/-! `complex.cosh`-/
lemma measurable.ccosh (hf : measurable f) : measurable (λ x, complex.cosh (f x)) :=
complex.measurable_cosh.comp hf
lemma has_deriv_at.ccosh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') x :=
(complex.has_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_within_at.ccosh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') s x :=
(complex.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.ccosh (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.cosh (f x)) s x :=
hf.has_deriv_within_at.ccosh.differentiable_within_at
@[simp] lemma differentiable_at.ccosh (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.cosh (f x)) x :=
hc.has_deriv_at.ccosh.differentiable_at
lemma differentiable_on.ccosh (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.cosh (f x)) s :=
λx h, (hc x h).ccosh
@[simp] lemma differentiable.ccosh (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.cosh (f x)) :=
λx, (hc x).ccosh
lemma deriv_within_ccosh (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.cosh (f x)) s x = complex.sinh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.ccosh.deriv_within hxs
@[simp] lemma deriv_ccosh (hc : differentiable_at ℂ f x) :
deriv (λx, complex.cosh (f x)) x = complex.sinh (f x) * (deriv f x) :=
hc.has_deriv_at.ccosh.deriv
/-! `complex.sinh`-/
lemma measurable.csinh (hf : measurable f) : measurable (λ x, complex.sinh (f x)) :=
complex.measurable_sinh.comp hf
lemma has_deriv_at.csinh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') x :=
(complex.has_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_within_at.csinh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') s x :=
(complex.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.csinh (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.sinh (f x)) s x :=
hf.has_deriv_within_at.csinh.differentiable_within_at
@[simp] lemma differentiable_at.csinh (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.sinh (f x)) x :=
hc.has_deriv_at.csinh.differentiable_at
lemma differentiable_on.csinh (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.sinh (f x)) s :=
λx h, (hc x h).csinh
@[simp] lemma differentiable.csinh (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.sinh (f x)) :=
λx, (hc x).csinh
lemma deriv_within_csinh (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.sinh (f x)) s x = complex.cosh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.csinh.deriv_within hxs
@[simp] lemma deriv_csinh (hc : differentiable_at ℂ f x) :
deriv (λx, complex.sinh (f x)) x = complex.cosh (f x) * (deriv f x) :=
hc.has_deriv_at.csinh.deriv
end
namespace real
variables {x y z : ℝ}
lemma has_deriv_at_sin (x : ℝ) : has_deriv_at sin (cos x) x :=
has_deriv_at_real_of_complex (complex.has_deriv_at_sin x)
lemma differentiable_sin : differentiable ℝ sin :=
λx, (has_deriv_at_sin x).differentiable_at
lemma differentiable_at_sin : differentiable_at ℝ sin x :=
differentiable_sin x
@[simp] lemma deriv_sin : deriv sin = cos :=
funext $ λ x, (has_deriv_at_sin x).deriv
lemma continuous_sin : continuous sin :=
differentiable_sin.continuous
lemma measurable_sin : measurable sin := continuous_sin.measurable
lemma has_deriv_at_cos (x : ℝ) : has_deriv_at cos (-sin x) x :=
(has_deriv_at_real_of_complex (complex.has_deriv_at_cos x) : _)
lemma differentiable_cos : differentiable ℝ cos :=
λx, (has_deriv_at_cos x).differentiable_at
lemma differentiable_at_cos : differentiable_at ℝ cos x :=
differentiable_cos x
lemma deriv_cos : deriv cos x = - sin x :=
(has_deriv_at_cos x).deriv
@[simp] lemma deriv_cos' : deriv cos = (λ x, - sin x) :=
funext $ λ _, deriv_cos
lemma continuous_cos : continuous cos :=
differentiable_cos.continuous
lemma continuous_on_cos {s} : continuous_on cos s := continuous_cos.continuous_on
lemma measurable_cos : measurable cos := continuous_cos.measurable
lemma has_deriv_at_sinh (x : ℝ) : has_deriv_at sinh (cosh x) x :=
has_deriv_at_real_of_complex (complex.has_deriv_at_sinh x)
lemma differentiable_sinh : differentiable ℝ sinh :=
λx, (has_deriv_at_sinh x).differentiable_at
lemma differentiable_at_sinh : differentiable_at ℝ sinh x :=
differentiable_sinh x
@[simp] lemma deriv_sinh : deriv sinh = cosh :=
funext $ λ x, (has_deriv_at_sinh x).deriv
lemma continuous_sinh : continuous sinh :=
differentiable_sinh.continuous
lemma measurable_sinh : measurable sinh := continuous_sinh.measurable
lemma has_deriv_at_cosh (x : ℝ) : has_deriv_at cosh (sinh x) x :=
has_deriv_at_real_of_complex (complex.has_deriv_at_cosh x)
lemma differentiable_cosh : differentiable ℝ cosh :=
λx, (has_deriv_at_cosh x).differentiable_at
lemma differentiable_at_cosh : differentiable_at ℝ cosh x :=
differentiable_cosh x
@[simp] lemma deriv_cosh : deriv cosh = sinh :=
funext $ λ x, (has_deriv_at_cosh x).deriv
lemma continuous_cosh : continuous cosh :=
differentiable_cosh.continuous
lemma measurable_cosh : measurable cosh := continuous_cosh.measurable
/-- `sinh` is strictly monotone. -/
lemma sinh_strict_mono : strict_mono sinh :=
strict_mono_of_deriv_pos differentiable_sinh (by { rw [real.deriv_sinh], exact cosh_pos })
end real
section
/-! Register lemmas for the derivatives of the composition of `real.exp`, `real.cos`, `real.sin`,
`real.cosh` and `real.sinh` with a differentiable function, for standalone use and use with
`simp`. -/
variables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ}
/-! `real.cos`-/
lemma measurable.cos (hf : measurable f) : measurable (λ x, real.cos (f x)) :=
real.measurable_cos.comp hf
lemma has_deriv_at.cos (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.cos (f x)) (- real.sin (f x) * f') x :=
(real.has_deriv_at_cos (f x)).comp x hf
lemma has_deriv_within_at.cos (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.cos (f x)) (- real.sin (f x) * f') s x :=
(real.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.cos (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.cos (f x)) s x :=
hf.has_deriv_within_at.cos.differentiable_within_at
@[simp] lemma differentiable_at.cos (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.cos (f x)) x :=
hc.has_deriv_at.cos.differentiable_at
lemma differentiable_on.cos (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.cos (f x)) s :=
λx h, (hc x h).cos
@[simp] lemma differentiable.cos (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.cos (f x)) :=
λx, (hc x).cos
lemma deriv_within_cos (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.cos (f x)) s x = - real.sin (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.cos.deriv_within hxs
@[simp] lemma deriv_cos (hc : differentiable_at ℝ f x) :
deriv (λx, real.cos (f x)) x = - real.sin (f x) * (deriv f x) :=
hc.has_deriv_at.cos.deriv
/-! `real.sin`-/
lemma measurable.sin (hf : measurable f) : measurable (λ x, real.sin (f x)) :=
real.measurable_sin.comp hf
lemma has_deriv_at.sin (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.sin (f x)) (real.cos (f x) * f') x :=
(real.has_deriv_at_sin (f x)).comp x hf
lemma has_deriv_within_at.sin (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.sin (f x)) (real.cos (f x) * f') s x :=
(real.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.sin (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.sin (f x)) s x :=
hf.has_deriv_within_at.sin.differentiable_within_at
@[simp] lemma differentiable_at.sin (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.sin (f x)) x :=
hc.has_deriv_at.sin.differentiable_at
lemma differentiable_on.sin (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.sin (f x)) s :=
λx h, (hc x h).sin
@[simp] lemma differentiable.sin (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.sin (f x)) :=
λx, (hc x).sin
lemma deriv_within_sin (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.sin (f x)) s x = real.cos (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.sin.deriv_within hxs
@[simp] lemma deriv_sin (hc : differentiable_at ℝ f x) :
deriv (λx, real.sin (f x)) x = real.cos (f x) * (deriv f x) :=
hc.has_deriv_at.sin.deriv
/-! `real.cosh`-/
lemma measurable.cosh (hf : measurable f) : measurable (λ x, real.cosh (f x)) :=
real.measurable_cosh.comp hf
lemma has_deriv_at.cosh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') x :=
(real.has_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_within_at.cosh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') s x :=
(real.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.cosh (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.cosh (f x)) s x :=
hf.has_deriv_within_at.cosh.differentiable_within_at
@[simp] lemma differentiable_at.cosh (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.cosh (f x)) x :=
hc.has_deriv_at.cosh.differentiable_at
lemma differentiable_on.cosh (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.cosh (f x)) s :=
λx h, (hc x h).cosh
@[simp] lemma differentiable.cosh (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.cosh (f x)) :=
λx, (hc x).cosh
lemma deriv_within_cosh (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.cosh (f x)) s x = real.sinh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.cosh.deriv_within hxs
@[simp] lemma deriv_cosh (hc : differentiable_at ℝ f x) :
deriv (λx, real.cosh (f x)) x = real.sinh (f x) * (deriv f x) :=
hc.has_deriv_at.cosh.deriv
/-! `real.sinh`-/
lemma measurable.sinh (hf : measurable f) : measurable (λ x, real.sinh (f x)) :=
real.measurable_sinh.comp hf
lemma has_deriv_at.sinh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') x :=
(real.has_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_within_at.sinh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') s x :=
(real.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.sinh (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.sinh (f x)) s x :=
hf.has_deriv_within_at.sinh.differentiable_within_at
@[simp] lemma differentiable_at.sinh (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.sinh (f x)) x :=
hc.has_deriv_at.sinh.differentiable_at
lemma differentiable_on.sinh (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.sinh (f x)) s :=
λx h, (hc x h).sinh
@[simp] lemma differentiable.sinh (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.sinh (f x)) :=
λx, (hc x).sinh
lemma deriv_within_sinh (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.sinh (f x)) s x = real.cosh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.sinh.deriv_within hxs
@[simp] lemma deriv_sinh (hc : differentiable_at ℝ f x) :
deriv (λx, real.sinh (f x)) x = real.cosh (f x) * (deriv f x) :=
hc.has_deriv_at.sinh.deriv
end
namespace real
lemma exists_cos_eq_zero : 0 ∈ cos '' Icc (1:ℝ) 2 :=
intermediate_value_Icc' (by norm_num) continuous_on_cos
⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩
/-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from
which one can derive all its properties. For explicit bounds on π, see `data.real.pi`. -/
noncomputable def pi : ℝ := 2 * classical.some exists_cos_eq_zero
localized "notation `π` := real.pi" in real
@[simp] lemma cos_pi_div_two : cos (π / 2) = 0 :=
by rw [pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).2
lemma one_le_pi_div_two : (1 : ℝ) ≤ π / 2 :=
by rw [pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).1.1
lemma pi_div_two_le_two : π / 2 ≤ 2 :=
by rw [pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).1.2
lemma two_le_pi : (2 : ℝ) ≤ π :=
(div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1
(by rw div_self (@two_ne_zero' ℝ _ _ _); exact one_le_pi_div_two)
lemma pi_le_four : π ≤ 4 :=
(div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1
(calc π / 2 ≤ 2 : pi_div_two_le_two
... = 4 / 2 : by norm_num)
lemma pi_pos : 0 < π :=
lt_of_lt_of_le (by norm_num) two_le_pi
lemma pi_ne_zero : pi ≠ 0 :=
ne_of_gt pi_pos
lemma pi_div_two_pos : 0 < π / 2 :=
half_pos pi_pos
lemma two_pi_pos : 0 < 2 * π :=
by linarith [pi_pos]
@[simp] lemma sin_pi : sin π = 0 :=
by rw [← mul_div_cancel_left pi (@two_ne_zero ℝ _), two_mul, add_div,
sin_add, cos_pi_div_two]; simp
@[simp] lemma cos_pi : cos π = -1 :=
by rw [← mul_div_cancel_left pi (@two_ne_zero ℝ _), mul_div_assoc,
cos_two_mul, cos_pi_div_two];
simp [bit0, pow_add]
@[simp] lemma sin_two_pi : sin (2 * π) = 0 :=
by simp [two_mul, sin_add]
@[simp] lemma cos_two_pi : cos (2 * π) = 1 :=
by simp [two_mul, cos_add]
lemma sin_add_pi (x : ℝ) : sin (x + π) = -sin x :=
by simp [sin_add]
lemma sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x :=
by simp [sin_add_pi, sin_add, sin_two_pi, cos_two_pi]
lemma cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x :=
by simp [cos_add, cos_two_pi, sin_two_pi]
lemma sin_pi_sub (x : ℝ) : sin (π - x) = sin x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi (x : ℝ) : cos (x + π) = -cos x :=
by simp [cos_add]
lemma cos_pi_sub (x : ℝ) : cos (π - x) = -cos x :=
by simp [sub_eq_add_neg, cos_add]
lemma sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x :=
if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2
else
have (2 : ℝ) + 2 = 4, from rfl,
have π - x ≤ 2, from sub_le_iff_le_add.2
(le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)),
sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this
lemma sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x :=
match lt_or_eq_of_le h0x with
| or.inl h0x := (lt_or_eq_of_le hxp).elim
(le_of_lt ∘ sin_pos_of_pos_of_lt_pi h0x)
(λ hpx, by simp [hpx])
| or.inr h0x := by simp [h0x.symm]
end
lemma sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 :=
neg_pos.1 $ sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx)
lemma sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 :=
neg_nonneg.1 $ sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx)
@[simp] lemma sin_pi_div_two : sin (π / 2) = 1 :=
have sin (π / 2) = 1 ∨ sin (π / 2) = -1 :=
by simpa [pow_two, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2),
this.resolve_right
(λ h, (show ¬(0 : ℝ) < -1, by norm_num) $
h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos))
lemma sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x :=
by simp [sin_add]
lemma sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x :=
by simp [cos_add]
lemma cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x :=
by simp [sub_eq_add_neg, cos_add]
lemma cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x :=
by rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
lemma cos_pos_of_mem_Ioo
{x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : 0 < cos x :=
sin_add_pi_div_two x ▸ sin_pos_of_pos_of_lt_pi (by linarith) (by linarith)
lemma cos_nonneg_of_mem_Icc
{x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : 0 ≤ cos x :=
match lt_or_eq_of_le hx₁, lt_or_eq_of_le hx₂ with
| or.inl hx₁, or.inl hx₂ := le_of_lt (cos_pos_of_mem_Ioo hx₁ hx₂)
| or.inl hx₁, or.inr hx₂ := by simp [hx₂]
| or.inr hx₁, _ := by simp [hx₁.symm]
end
lemma cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 :=
neg_pos.1 $ cos_pi_sub x ▸
cos_pos_of_mem_Ioo (by linarith) (by linarith)
lemma cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) : cos x ≤ 0 :=
neg_nonneg.1 $ cos_pi_sub x ▸
cos_nonneg_of_mem_Icc (by linarith) (by linarith)
lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
by induction n; simp [add_mul, sin_add, *]
lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi]
lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi]
lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe,
int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg,
(neg_mul_eq_neg_mul _ _).symm, cos_neg]
lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 :=
by simp [cos_add, sin_add, cos_int_mul_two_pi]
lemma sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) :
sin x = 0 ↔ x = 0 :=
⟨λ h, le_antisymm
(le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $
calc 0 < sin x : sin_pos_of_pos_of_lt_pi h0 hx₂
... = 0 : h))
(le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $
calc 0 = sin x : h.symm
... < 0 : sin_neg_of_neg_of_neg_pi_lt h0 hx₁)),
λ h, by simp [h]⟩
lemma sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x :=
⟨λ h, ⟨⌊x / π⌋, le_antisymm (sub_nonneg.1 (sub_floor_div_mul_nonneg _ pi_pos))
(sub_nonpos.1 $ le_of_not_gt $ λ h₃, ne_of_lt (sin_pos_of_pos_of_lt_pi h₃ (sub_floor_div_mul_lt _ pi_pos))
(by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩,
λ ⟨n, hn⟩, hn ▸ sin_int_mul_pi _⟩
lemma sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 :=
by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x,
pow_two, pow_two, ← sub_eq_iff_eq_add, sub_self];
exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩
lemma cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x :=
⟨λ h, let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (or.inl h)) in
⟨n / 2, (int.mod_two_eq_zero_or_one n).elim
(λ hn0, by rwa [← mul_assoc, ← @int.cast_two ℝ, ← int.cast_mul, int.div_mul_cancel
((int.dvd_iff_mod_eq_zero _ _).2 hn0)])
(λ hn1, by rw [← int.mod_add_div n 2, hn1, int.cast_add, int.cast_one, add_mul,
one_mul, add_comm, mul_comm (2 : ℤ), int.cast_mul, mul_assoc, int.cast_two] at hn;
rw [← hn, cos_int_mul_two_pi_add_pi] at h;
exact absurd h (by norm_num))⟩,
λ ⟨n, hn⟩, hn ▸ cos_int_mul_two_pi _⟩
lemma cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) : cos x = 1 ↔ x = 0 :=
⟨λ h, let ⟨n, hn⟩ := (cos_eq_one_iff x).1 h in
begin
clear _let_match,
subst hn,
rw [mul_lt_iff_lt_one_left two_pi_pos, ← int.cast_one, int.cast_lt, ← int.le_sub_one_iff, sub_self] at hx₂,
rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos, neg_lt,
← int.cast_one, ← int.cast_neg, int.cast_lt, ← int.add_one_le_iff, neg_add_self] at hx₁,
exact mul_eq_zero.2 (or.inl (int.cast_eq_zero.2 (le_antisymm hx₂ hx₁))),
end,
λ h, by simp [h]⟩
lemma cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) :
cos y < cos x :=
begin
rw [← sub_lt_zero, cos_sub_cos],
have : 0 < sin ((y + x) / 2),
{ refine sin_pos_of_pos_of_lt_pi _ _; linarith },
have : 0 < sin ((y - x) / 2),
{ refine sin_pos_of_pos_of_lt_pi _ _; linarith },
nlinarith,
end
lemma cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) :
cos y < cos x :=
match (le_total x (π / 2) : x ≤ π / 2 ∨ π / 2 ≤ x), le_total y (π / 2) with
| or.inl hx, or.inl hy := cos_lt_cos_of_nonneg_of_le_pi_div_two hx₁ hy hxy
| or.inl hx, or.inr hy := (lt_or_eq_of_le hx).elim
(λ hx, calc cos y ≤ 0 : cos_nonpos_of_pi_div_two_le_of_le hy (by linarith [pi_pos])
... < cos x : cos_pos_of_mem_Ioo (by linarith) hx)
(λ hx, calc cos y < 0 : cos_neg_of_pi_div_two_lt_of_lt (by linarith) (by linarith [pi_pos])
... = cos x : by rw [hx, cos_pi_div_two])
| or.inr hx, or.inl hy := by linarith
| or.inr hx, or.inr hy := neg_lt_neg_iff.1 (by rw [← cos_pi_sub, ← cos_pi_sub];
apply cos_lt_cos_of_nonneg_of_le_pi_div_two; linarith)
end
lemma cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) :
cos y ≤ cos x :=
(lt_or_eq_of_le hxy).elim
(le_of_lt ∘ cos_lt_cos_of_nonneg_of_le_pi hx₁ hy₂)
(λ h, h ▸ le_refl _)
lemma sin_lt_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x)
(hy₂ : y ≤ π / 2) (hxy : x < y) : sin x < sin y :=
by rw [← cos_sub_pi_div_two, ← cos_sub_pi_div_two, ← cos_neg (x - _), ← cos_neg (y - _)];
apply cos_lt_cos_of_nonneg_of_le_pi; linarith
lemma sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x)
(hy₂ : y ≤ π / 2) (hxy : x ≤ y) : sin x ≤ sin y :=
(lt_or_eq_of_le hxy).elim
(le_of_lt ∘ sin_lt_sin_of_le_of_le_pi_div_two hx₁ hy₂)
(λ h, h ▸ le_refl _)
lemma sin_inj_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) (hy₁ : -(π / 2) ≤ y)
(hy₂ : y ≤ π / 2) (hxy : sin x = sin y) : x = y :=
match lt_trichotomy x y with
| or.inl h := absurd (sin_lt_sin_of_le_of_le_pi_div_two hx₁ hy₂ h) (by rw hxy; exact lt_irrefl _)
| or.inr (or.inl h) := h
| or.inr (or.inr h) := absurd (sin_lt_sin_of_le_of_le_pi_div_two hy₁ hx₂ h) (by rw hxy; exact lt_irrefl _)
end
lemma cos_inj_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) (hy₁ : 0 ≤ y) (hy₂ : y ≤ π)
(hxy : cos x = cos y) : x = y :=
begin
rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub] at hxy,
refine (sub_right_inj).1 (sin_inj_of_le_of_le_pi_div_two _ _ _ _ hxy);
linarith
end
lemma exists_sin_eq : Icc (-1:ℝ) 1 ⊆ sin '' Icc (-(π / 2)) (π / 2) :=
by convert intermediate_value_Icc
(le_trans (neg_nonpos.2 (le_of_lt pi_div_two_pos)) (le_of_lt pi_div_two_pos))
continuous_sin.continuous_on; simp only [sin_neg, sin_pi_div_two]
lemma exists_cos_eq : (Icc (-1) 1 : set ℝ) ⊆ cos '' Icc 0 π :=
by convert intermediate_value_Icc' real.pi_pos.le real.continuous_on_cos;
simp only [real.cos_pi, real.cos_zero]
lemma range_cos : range cos = (Icc (-1) 1 : set ℝ) :=
begin
ext,
split,
{ rintros ⟨y, rfl⟩, exact ⟨y.neg_one_le_cos, y.cos_le_one⟩ },
{ rintros h,
rcases real.exists_cos_eq h with ⟨y, -, hy⟩,
exact ⟨y, hy⟩ }
end
lemma range_sin : range sin = (Icc (-1) 1 : set ℝ) :=
begin
ext,
split,
{ rintros ⟨y, rfl⟩, exact ⟨y.neg_one_le_sin, y.sin_le_one⟩ },
{ rintros h,
rcases real.exists_sin_eq h with ⟨y, -, hy⟩,
exact ⟨y, hy⟩ }
end
lemma range_cos_infinite : (range real.cos).infinite :=
by { rw real.range_cos, exact Icc.infinite (by norm_num) }
lemma range_sin_infinite : (range real.sin).infinite :=
by { rw real.range_sin, exact Icc.infinite (by norm_num) }
lemma sin_lt {x : ℝ} (h : 0 < x) : sin x < x :=
begin
cases le_or_gt x 1 with h' h',
{ have hx : abs x = x := abs_of_nonneg (le_of_lt h),
have : abs x ≤ 1, rwa [hx],
have := sin_bound this, rw [abs_le] at this,
have := this.2, rw [sub_le_iff_le_add', hx] at this,
apply lt_of_le_of_lt this, rw [sub_add], apply lt_of_lt_of_le _ (le_of_eq (sub_zero x)),
apply sub_lt_sub_left, rw sub_pos, apply mul_lt_mul',
{ rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),
rw mul_le_mul_right, exact h', apply pow_pos h },
norm_num, norm_num, apply pow_pos h },
exact lt_of_le_of_lt (sin_le_one x) h'
end
/- note 1: this inequality is not tight, the tighter inequality is sin x > x - x ^ 3 / 6.
note 2: this is also true for x > 1, but it's nontrivial for x just above 1. -/
lemma sin_gt_sub_cube {x : ℝ} (h : 0 < x) (h' : x ≤ 1) : x - x ^ 3 / 4 < sin x :=
begin
have hx : abs x = x := abs_of_nonneg (le_of_lt h),
have : abs x ≤ 1, rwa [hx],
have := sin_bound this, rw [abs_le] at this,
have := this.1, rw [le_sub_iff_add_le, hx] at this,
refine lt_of_lt_of_le _ this,
rw [add_comm, sub_add, sub_neg_eq_add], apply sub_lt_sub_left,
apply add_lt_of_lt_sub_left,
rw (show x ^ 3 / 4 - x ^ 3 / 6 = x ^ 3 / 12,
by simp [div_eq_mul_inv, ← mul_sub]; norm_num),
apply mul_lt_mul',
{ rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),
rw mul_le_mul_right, exact h', apply pow_pos h },
norm_num, norm_num, apply pow_pos h
end
section cos_div_pow_two
variable (x : ℝ)
/-- the series `sqrt_two_add_series x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots,
starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2`
-/
@[simp] noncomputable def sqrt_two_add_series (x : ℝ) : ℕ → ℝ
| 0 := x
| (n+1) := sqrt (2 + sqrt_two_add_series n)
lemma sqrt_two_add_series_zero : sqrt_two_add_series x 0 = x := by simp
lemma sqrt_two_add_series_one : sqrt_two_add_series 0 1 = sqrt 2 := by simp
lemma sqrt_two_add_series_two : sqrt_two_add_series 0 2 = sqrt (2 + sqrt 2) := by simp
lemma sqrt_two_add_series_zero_nonneg : ∀(n : ℕ), 0 ≤ sqrt_two_add_series 0 n
| 0 := le_refl 0
| (n+1) := sqrt_nonneg _
lemma sqrt_two_add_series_nonneg {x : ℝ} (h : 0 ≤ x) : ∀(n : ℕ), 0 ≤ sqrt_two_add_series x n
| 0 := h
| (n+1) := sqrt_nonneg _
lemma sqrt_two_add_series_lt_two : ∀(n : ℕ), sqrt_two_add_series 0 n < 2
| 0 := by norm_num
| (n+1) :=
begin
refine lt_of_lt_of_le _ (le_of_eq $ sqrt_sqr $ le_of_lt zero_lt_two),
rw [sqrt_two_add_series, sqrt_lt],
apply add_lt_of_lt_sub_left,
apply lt_of_lt_of_le (sqrt_two_add_series_lt_two n),
norm_num, apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg, norm_num
end
lemma sqrt_two_add_series_succ (x : ℝ) :
∀(n : ℕ), sqrt_two_add_series x (n+1) = sqrt_two_add_series (sqrt (2 + x)) n
| 0 := rfl
| (n+1) := by rw [sqrt_two_add_series, sqrt_two_add_series_succ, sqrt_two_add_series]
lemma sqrt_two_add_series_monotone_left {x y : ℝ} (h : x ≤ y) :
∀(n : ℕ), sqrt_two_add_series x n ≤ sqrt_two_add_series y n
| 0 := h
| (n+1) :=
begin
rw [sqrt_two_add_series, sqrt_two_add_series],
apply sqrt_le_sqrt, apply add_le_add_left, apply sqrt_two_add_series_monotone_left
end
@[simp] lemma cos_pi_over_two_pow : ∀(n : ℕ), cos (pi / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2
| 0 := by simp
| (n+1) :=
begin
symmetry, rw [div_eq_iff_mul_eq], symmetry,
rw [sqrt_two_add_series, sqrt_eq_iff_sqr_eq, mul_pow, cos_square, ←mul_div_assoc,
nat.add_succ, pow_succ, mul_div_mul_left, cos_pi_over_two_pow, add_mul],
congr, norm_num,
rw [mul_comm, pow_two, mul_assoc, ←mul_div_assoc, mul_div_cancel_left, ←mul_div_assoc,
mul_div_cancel_left],
norm_num, norm_num, norm_num,
apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg, norm_num,
apply le_of_lt, apply cos_pos_of_mem_Ioo,
{ transitivity (0 : ℝ), rw neg_lt_zero, apply pi_div_two_pos,
apply div_pos pi_pos, apply pow_pos, norm_num },
apply div_lt_div' (le_refl pi) _ pi_pos _,
refine lt_of_le_of_lt (le_of_eq (pow_one _).symm) _,
apply pow_lt_pow, norm_num, apply nat.succ_lt_succ, apply nat.succ_pos, all_goals {norm_num}
end
lemma sin_square_pi_over_two_pow (n : ℕ) :
sin (pi / 2 ^ (n+1)) ^ 2 = 1 - (sqrt_two_add_series 0 n / 2) ^ 2 :=
by rw [sin_square, cos_pi_over_two_pow]
lemma sin_square_pi_over_two_pow_succ (n : ℕ) :
sin (pi / 2 ^ (n+2)) ^ 2 = 1 / 2 - sqrt_two_add_series 0 n / 4 :=
begin
rw [sin_square_pi_over_two_pow, sqrt_two_add_series, div_pow, sqr_sqrt, add_div, ←sub_sub],
congr, norm_num, norm_num, apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg,
end
@[simp] lemma sin_pi_over_two_pow_succ (n : ℕ) :
sin (pi / 2 ^ (n+2)) = sqrt (2 - sqrt_two_add_series 0 n) / 2 :=
begin
symmetry, rw [div_eq_iff_mul_eq], symmetry,
rw [sqrt_eq_iff_sqr_eq, mul_pow, sin_square_pi_over_two_pow_succ, sub_mul],
{ congr, norm_num, rw [mul_comm], convert mul_div_cancel' _ _, norm_num, norm_num },
{ rw [sub_nonneg], apply le_of_lt, apply sqrt_two_add_series_lt_two },
apply le_of_lt, apply mul_pos, apply sin_pos_of_pos_of_lt_pi,
{ apply div_pos pi_pos, apply pow_pos, norm_num },
refine lt_of_lt_of_le _ (le_of_eq (div_one _)), rw [div_lt_div_left],
refine lt_of_le_of_lt (le_of_eq (pow_zero 2).symm) _,
apply pow_lt_pow, norm_num, apply nat.succ_pos, apply pi_pos,
apply pow_pos, all_goals {norm_num}
end
lemma cos_pi_div_four : cos (pi / 4) = sqrt 2 / 2 :=
by { transitivity cos (pi / 2 ^ 2), congr, norm_num, simp }
lemma sin_pi_div_four : sin (pi / 4) = sqrt 2 / 2 :=
by { transitivity sin (pi / 2 ^ 2), congr, norm_num, simp }
lemma cos_pi_div_eight : cos (pi / 8) = sqrt (2 + sqrt 2) / 2 :=
by { transitivity cos (pi / 2 ^ 3), congr, norm_num, simp }
lemma sin_pi_div_eight : sin (pi / 8) = sqrt (2 - sqrt 2) / 2 :=
by { transitivity sin (pi / 2 ^ 3), congr, norm_num, simp }
lemma cos_pi_div_sixteen : cos (pi / 16) = sqrt (2 + sqrt (2 + sqrt 2)) / 2 :=
by { transitivity cos (pi / 2 ^ 4), congr, norm_num, simp }
lemma sin_pi_div_sixteen : sin (pi / 16) = sqrt (2 - sqrt (2 + sqrt 2)) / 2 :=
by { transitivity sin (pi / 2 ^ 4), congr, norm_num, simp }
lemma cos_pi_div_thirty_two : cos (pi / 32) = sqrt (2 + sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity cos (pi / 2 ^ 5), congr, norm_num, simp }
lemma sin_pi_div_thirty_two : sin (pi / 32) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity sin (pi / 2 ^ 5), congr, norm_num, simp }
-- This section is also a convenient location for other explicit values of `sin` and `cos`.
/-- The cosine of `π / 3` is `1 / 2`. -/