Debian Codegraph @

reals/faster/ARcos.v

raw
1 Require Import CoRN.algebra.RSetoid.
2 Require Import CoRN.metric2.Metric.
3 Require Import CoRN.metric2.UniformContinuity.
4 Require Import CoRN.model.metric2.Qmetric.
5 Require Import
6 MathClasses.misc.workaround_tactics
7 CoRN.reals.fast.CRsin CoRN.reals.fast.CRcos CoRN.metric2.MetricMorphisms
8 CoRN.metric2.Complete CoRN.reals.faster.ARsin
9 MathClasses.interfaces.abstract_algebra.
10 Require Export
11 CoRN.reals.faster.ARArith.
12
13 (**
14 ** Cosine
15 Cosine is defined in terms of Sine. [cos x = 1 - 2*(sin(x/2))^2].
16 But cosine is still first defined on the rational numbers, and lifted
17 to the real numbers. *)
18
19 Section ARcos.
20 Context `{AppRationals AQ}.
21
22 Local Open Scope uc_scope.
23
24 Add Field Q : (dec_fields.stdlib_field_theory Q).
25
26 Definition AQcos_poly_fun (x : AQ) : AQ := 1 - 2 * x ^ (2%mc:N).
27
28 Lemma AQcos_poly_fun_correct (x : AQ) :
29 'AQcos_poly_fun x = cos_poly_fun ('x).
30 Proof.
31 unfold AQcos_poly_fun, cos_poly_fun.
32 rewrite nat_pow.nat_pow_2.
33 rewrite rings.preserves_minus, ?rings.preserves_mult.
34 rewrite rings.preserves_1, rings.preserves_2.
35 now rewrite associativity.
36 Qed.
37
38 Lemma AQcos_poly_uc_correct
39 : forall q : AQ, msp_eq (' AQcos_poly_fun (AQboundAbs_uc 1 q))
40 (cos_poly_fun (QMinMax.Qmax (- (1)) (QMinMax.Qmin 1 (' q)))).
41 Proof.
42 intro q. apply Qball_0.
43 rewrite AQcos_poly_fun_correct.
44 f_equiv.
45 unfold AQboundAbs_uc. simpl.
46 change ('1) with (1:AQ).
47 rewrite ?aq_preserves_max, ?aq_preserves_min.
48 now rewrite ?rings.preserves_negate, ?rings.preserves_1.
49 Qed.
50
51 Definition AQcos_poly_uc
52 := unary_uc (cast AQ Q_as_MetricSpace)
53 (λ x : AQ, AQcos_poly_fun (AQboundAbs_uc 1 x)) cos_poly_uc
54 AQcos_poly_uc_correct.
55
56 Definition ARcos_poly := uc_compose ARcompress (Cmap AQPrelengthSpace AQcos_poly_uc).
57
58 Lemma ARtoCR_preserves_cos_poly x :
59 'ARcos_poly x = cos_poly ('x).
60 Proof.
61 change ('ARcompress (Cmap AQPrelengthSpace AQcos_poly_uc x) = cos_poly ('x)).
62 rewrite ARcompress_correct.
63 now apply preserves_unary_fun.
64 Qed.
65
66 Definition AQcos (x : AQ) : AR := ARcos_poly (AQsin (x ≪ (-1))).
67
68 Lemma AQcos_correct a : 'AQcos a = rational_cos ('a).
69 Proof.
70 unfold AQcos.
71 rewrite ARtoCR_preserves_cos_poly.
72 posed_rewrite AQsin_correct.
73 rewrite aq_shift_opp_1.
74 now apply rational_cos_sin.
75 Qed.
76
77 Definition ARcos_uc : AQ_as_MetricSpace --> AR
78 := unary_complete_uc QPrelengthSpace AQtoQ AQcos cos_uc AQcos_correct.
79
80 Lemma ARcos_uc_eval : forall q : AQ_as_MetricSpace,
81 ARcos_uc q ≡ AQcos q.
82 Proof. reflexivity. Qed.
83
84 Definition ARcos : AR --> AR := Cbind AQPrelengthSpace ARcos_uc.
85
86 Lemma ARtoCR_preserves_cos x : 'ARcos x = cos_slow ('x).
87 Proof. apply preserves_unary_complete_fun. Qed.
88 End ARcos.