README.md 7.46 KB
Newer Older
Guillaume Melquiond's avatar
Guillaume Melquiond committed
1 2 3 4 5 6 7 8 9 10 11
CoqInterval
===========

This library provides vernacular files containing tactics for
simplifying the proofs of inequalities on expressions of real numbers
for the [Coq proof assistant](https://coq.inria.fr/).

This package is free software; you can redistribute it and/or modify it
under the terms of CeCILL-C Free Software License (see the [COPYING](COPYING) file).
Main author is Guillaume Melquiond <guillaume.melquiond@inria.fr>.

Guillaume Melquiond's avatar
Guillaume Melquiond committed
12 13 14 15 16 17 18 19 20 21 22 23 24
See the file [INSTALL.md](INSTALL.md) for installation instructions.


Project Home
------------

Homepage: http://coq-interval.gforge.inria.fr/

Repository: https://gitlab.inria.fr/coqinterval/interval

Bug tracker: https://gitlab.inria.fr/coqinterval/interval/issues


Guillaume Melquiond's avatar
Guillaume Melquiond committed
25 26 27 28
Invocation
----------

In order to use the tactics of the library, one has to import the
29
`Interval.Tactic` file into a Coq proof script. The main tactic is named
Guillaume Melquiond's avatar
Guillaume Melquiond committed
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
`interval`.

The tactic can be applied on a goal of the form `c1 <= e <= c2` with
`e` an expression involving real-valued operators. Sub-expressions that
are not recognized by the tactic should be either terms `t` appearing in
hypothesis inequalities `c3 <= t <= c4` or simple integers. The
bounds `c1`, `c2`, etc are expressions that contain only constant leaves,
e.g., `5 / sqrt (1 + PI)`.

The complete list of recognized goals is as follows:

  - `c1 <= e <= c2`;
  - `e <= c2`;
  - `c1 <= e`;
  - `0 < e`;
  - `e <> 0`;
  - `Rabs e <= c2`, handled as `-c2 <= e <= c2`;
  - `e1 <= e2`, handled as `e1 - e2 <= 0`;
  - `e1 < e2`, handled as `0 < e2 - e1`;
  - `e1 <> e2`, handled as `e1 - e2 <> 0`.

Operators recognized by the tactic are `PI`, `Ropp`, `Rabs`, `Rinv`,
`Rsqr`, `sqrt`, `cos`, `sin`, `tan`, `atan`, `exp`, `ln`, `pow`,
`powerRZ`, `Rplus`, `Rminus`, `Rmult`, `Rdiv`. Operators `Zfloor`,
`Zceil`, `Ztrunc`, `ZnearestE` (composed with `IZR`) are also recognized.
There are some restrictions on the domain of a few functions: `pow` and
`powerRZ` should be written with a numeric exponent; the input of `cos`
and `sin` should be between `-2*PI` and `2*PI`; the input of `tan` should
be between `-PI/2` and `PI/2`.

The tactic also recognizes integral expressions `RInt` whose bounds are
constants and whose integrand is an expression containing only constant
leaves except for the integration variable. Some improper integral
expressions `RInt_gen` are also supported with bounds `(at_right 0)
(at_point _)` or `(at_point _) (Rbar_locally p_infty)`. In the improper
case, the integrand should be of the form `(fun t => f t * g t)` with `g`
one of the following expressions:

  - `exp (- (_ * t))`,
  - `powerRZ t _ * (ln t) ^ _`,
  - `/ (t * (ln t) ^ _)`.

A helper tactic `interval_intro e` is also available. Instead of proving
the current goal, it computes an enclosure of the expression `e` passed
as argument and it introduces the inequalities into the proof context. If
only one bound is needed, the keywords `lower` and `upper` can be passed
to the tactic, so that it does not perform useless computations. For
example, `interval_intro e lower` introduces only a floating-point lower
bound of `e` in the context. Unless one uses `as` followed by an intro
pattern, the `interval_intro` tactic generates a fresh name for the
hypothesis added to the context.


Fine-tuning
-----------

The behavior of the tactics can be tuned by passing an optional set of
parameters `with (param1, param2, ...)`. These parameters are parsed from
left to right. If some parameters are conflicting, the earlier ones are
discarded. Available parameters are as follows (with the type of their
arguments, if any):

  - `i_prec (p:nat)` sets the precision of the floating-point computations;
  - `i_depth (n:nat)` sets the bisection depth (`2^n` sub-intervals at most);
  - `i_bisect (x:R)`      splits input interval on `x` and repeat until proven;
  - `i_bisect_diff (x:R)` same as `i_bisect`, but studies variations
    along `x` too;
  - `i_bisect_taylor (x:R) (d:nat)` same as `i_bisect_diff`, but computes
    degree-`d` Taylor models instead of performing automatic differentiation;
  - `i_integral_prec (p:nat)` sets the target relative accuracy of
    integral expressions to approximately `p` bits;
  - `i_integral_width (p:Z)` sets the target accuracy of integral
    expressions to an interval width of `2^p`;
  - `i_integral_depth (n:nat)` sets the bisection depth for bounding
    integral expressions (`2^n` sub-intervals at most);
  - `i_integral_deg (d:nat)` sets the degree of Taylor models for
    approximating the integrand when bounding integral expressions;
  - `i_native_compute` uses `native_compute` instead of `vm_compute`;
  - `i_delay` delays proof checking till `Qed`, especially useful when
    experimenting with `interval_intro`.

For both tactics, performing a bisection of depth 1 is not much slower
than performing no bisection. If the current goal can be proven by
`interval` with a bisection of depth n, then increasing the depth to n + 1
will not have any noticeable effect. For `interval_intro`, increasing the
depth from n to n + 1 can, however, doubles the computation time.

Performing an `i_bisect_diff` bisection has a much higher cost per
sub-interval, but it can considerably reduce the amount of sub-intervals
considered. As a consequence, unless there is a huge amount of trivial
propositions to prove, one should use this improved bisection.

If the proof process is still too slow, the `i_bisect_taylor` bisection
can be tried instead, as it usually reduces the number of sub-intervals
much further. In some corner cases though, it will not be able to prove
properties for which `i_bisect_diff` would have succeeded.

By default, the precision of the floating-point computations is 30 bits.
If the user enables a bisection, the default depth is 15 for `interval`
and 5 for `interval_intro`. When bounding integral expressions, the
tactics target 10 bits of accuracy by splitting the domain into 2^3
subdomains at most and by using degree-10 Taylor models.


Examples
--------

```coq
Require Import Reals.
139
Require Import Interval.Tactic.
Guillaume Melquiond's avatar
Guillaume Melquiond committed
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

Open Scope R_scope.

Goal
  forall x, -1 <= x <= 1 ->
  sqrt (1 - x) <= 3/2.
Proof.
  intros.
  interval.
Qed.

Goal
  forall x, -1 <= x <= 1 ->
  sqrt (1 - x) <= 141422/100000.
Proof.
  intros.
  interval.
Qed.

Goal
  forall x, -1 <= x <= 1 ->
  sqrt (1 - x) <= 141422/100000.
Proof.
  intros.
  interval_intro (sqrt (1 - x)) upper as H'.
  apply Rle_trans with (1 := H').
  interval.
Qed.

Goal
  forall x, 3/2 <= x <= 2 ->
  forall y, 1 <= y <= 33/32 ->
  Rabs (sqrt(1 + x/sqrt(x+y)) - 144/1000*x - 118/100) <= 71/32768.
Proof.
  intros.
  interval with (i_prec 19, i_bisect x).
Qed.

Goal
  forall x, 1/2 <= x <= 2 ->
  Rabs (sqrt x - (((((122 / 7397 * x + (-1733) / 13547) * x
                   + 529 / 1274) * x + (-767) / 999) * x
                   + 407 / 334) * x + 227 / 925))
    <= 5/65536.
Proof.
  intros.
  interval with (i_bisect_taylor x 3).
Qed.

Goal
  forall x, -1 <= x ->
  x < 1 + powerRZ x 3.
Proof.
  intros.
  interval with (i_bisect_diff x).
Qed.

Require Import Coquelicot.Coquelicot.

Goal
  Rabs (RInt (fun x => atan (sqrt (x*x + 2)) / (sqrt (x*x + 2) * (x*x + 1))) 0 1
        - 5/96*PI*PI) <= 1/1000.
Proof.
  interval with (i_integral_prec 9, i_integral_depth 1, i_integral_deg 5).
Qed.

Goal
  RInt_gen (fun x => 1 * (powerRZ x 3 * ln x^2))
           (at_right 0) (at_point 1) = 1/32.
Proof.
  refine ((fun H => Rle_antisym _ _ (proj2 H) (proj1 H)) _).
  interval.
Qed.

Goal
  Rabs (RInt_gen (fun t => 1/sqrt t * exp (-(1*t)))
                 (at_point 1) (Rbar_locally p_infty)
        - 2788/10000) <= 1/1000.
Proof.
  interval.
Qed.
```