| 1 |
From Coq Require Import Qround. |
| 2 |
Require Import CoRN.reals.fast.Plot. |
| 3 |
Require Import CoRN.reals.faster.ARArith. |
| 4 |
Require Import CoRN.reals.faster.ARinterval. |
| 5 |
Require Import CoRN.model.metric2.Qmetric. |
| 6 |
|
| 7 |
Local Open Scope uc_scope. |
| 8 |
|
| 9 |
Section PlotPath. |
| 10 |
Context `{AppRationals AQ}. |
| 11 |
|
| 12 |
Variable (from to:Q). |
| 13 |
Hypothesis Hfromto:from<=to. |
| 14 |
|
| 15 |
Variable (l r:Q). |
| 16 |
Hypothesis Hlr : l < r. |
| 17 |
|
| 18 |
Variable (b t:Q). |
| 19 |
Hypothesis Hbt : b < t. |
| 20 |
|
| 21 |
(* Number of pixels on the X-axis. *) |
| 22 |
Variable n : positive. |
| 23 |
|
| 24 |
Lemma wpos : 0 < r - l. |
| 25 |
Proof. |
| 26 |
apply Qlt_minus_iff in Hlr. exact Hlr. |
| 27 |
Qed. |
| 28 |
|
| 29 |
Lemma hpos : 0 < t - b. |
| 30 |
Proof. |
| 31 |
apply Qlt_minus_iff in Hbt. exact Hbt. |
| 32 |
Qed. |
| 33 |
|
| 34 |
(* Compute the number of pixels on the Y-axis to make square pixels. *) |
| 35 |
Let m : positive := Z.to_pos (Qceiling ((t-b) * inject_Z (Z.pos n) / (r-l))). |
| 36 |
|
| 37 |
(** |
| 38 |
Half the error in the Plot example, since we need to approximate twice. |
| 39 |
*) |
| 40 |
Let err := Qpos_max ((1 # 8 * n) * (exist _ _ wpos)) |
| 41 |
((1 # 8 * m) * (exist _ _ hpos)). |
| 42 |
|
| 43 |
Variable path:AQ_as_MetricSpace --> Complete (ProductMS AQ_as_MetricSpace AQ_as_MetricSpace). |
| 44 |
|
| 45 |
(** The actual plot function *) |
| 46 |
Definition PlotPath : positive * positive * Q * sparse_raster n m |
| 47 |
:= (n, m, 2, |
| 48 |
let num := (Z.to_pos |
| 49 |
(Qceiling |
| 50 |
((to - from) / |
| 51 |
(inject_Z 2 * |
| 52 |
((1 # 2) * |
| 53 |
` (FinEnum_map_modulus |
| 54 |
(1 # 1)%Qpos |
| 55 |
(mu path) err)))))) in |
| 56 |
sparse_raster_data n m |
| 57 |
(map |
| 58 |
(λ x : Z, |
| 59 |
rasterize2 n m t l b r |
| 60 |
(let (a, b0) := |
| 61 |
approximate |
| 62 |
(path |
| 63 |
(AppInverse0 |
| 64 |
(from + |
| 65 |
(to - from) * (2 * x + 1 # 1) / |
| 66 |
(2 * |
| 67 |
Z.pos num # 1)) |
| 68 |
((1 # 2)%Qpos * |
| 69 |
FinEnum_map_modulus (1#1)%Qpos (mu path) err)%Qpos)) |
| 70 |
err in |
| 71 |
(AQtoQ a, AQtoQ b0))) (* TODO rasterize2AQ *) |
| 72 |
(Interval.iterateN_succ 0 num))). |
| 73 |
|
| 74 |
Definition PlotPath_slow : positive * positive * Q * sparse_raster n m |
| 75 |
:= (n, m, 2#1, |
| 76 |
sparse_raster_data n m |
| 77 |
(map |
| 78 |
(λ x : AQ_as_MetricSpace, |
| 79 |
rasterize2 n m t l b r |
| 80 |
(let (a, b0) := approximate (path x) err in (AQtoQ a, AQtoQ b0))) |
| 81 |
(approximate (IabCompact from to Hfromto) |
| 82 |
(FinEnum_map_modulus (1 # 1) (mu path) err)))). |
| 83 |
|
| 84 |
Lemma PlotPath_correct : eq PlotPath PlotPath_slow. |
| 85 |
Proof. |
| 86 |
unfold PlotPath_slow. unfold IabCompact, approximate. |
| 87 |
rewrite map_map. |
| 88 |
unfold Interval.UniformPartition. |
| 89 |
rewrite map_map. |
| 90 |
reflexivity. |
| 91 |
Qed. |
| 92 |
|
| 93 |
End PlotPath. |