Debian Codegraph @

reals/fast/CRsign.v

raw
1 (*
2 Copyright © 2006-2008 Russell O’Connor
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this proof and associated documentation files (the "Proof"), to deal in
6 the Proof without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8 the Proof, and to permit persons to whom the Proof is furnished to do so,
9 subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Proof.
13
14 THE PROOF IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE PROOF OR THE USE OR OTHER DEALINGS IN THE PROOF.
20 *)
21
22 Require Import CoRN.algebra.RSetoid.
23 Require Import CoRN.metric2.Metric.
24 Require Import CoRN.metric2.UniformContinuity.
25 Require Export CoRN.reals.fast.CRIR.
26 Require Import CoRN.model.totalorder.QMinMax.
27 Require Import CoRN.model.totalorder.QposMinMax.
28 Require Import CoRN.reals.fast.CRArith.
29
30 (**
31 ** Tactics for Inequalities
32 This module defines tactics for automatically proving inequalities
33 over real numbers.
34 *)
35
36 (** Automatically solve the goal [{e:Qpos | CR_epsilon_sign_dec e x = Gt}]
37 by starting with approximating by e, and halving the allowed error until
38 the problem is solved. (This tactic may not terminate.) *)
39 Ltac CR_solve_pos_loop e :=
40 (exists e;
41 vm_compute;
42 match goal with
43 | |- Gt = Gt => reflexivity
44 | |- Lt = Gt => fail 2 "CR number is negative"
45 end)
46 || CR_solve_pos_loop ((1#2)*e)%Qpos.
47
48 (** This is the main tactic for solving goal of the from [CRpos e].
49 It tries to clear the context to make sure that e is a closed term.
50 Then it applies the helper lemma and runs [CR_solve_pos_loop]. *)
51 Ltac CR_solve_pos e :=
52 repeat (match goal with
53 | H:_ |-_ => clear H
54 end);
55 match goal with
56 | H:_ |-_ => fail 1 "Context cannot be cleared"
57 | |-_ => idtac
58 end;
59 apply CR_epsilon_sign_dec_pos;
60 CR_solve_pos_loop e.
61
62 (** This tactic is used to transform an inequality over IR into an
63 problem bout CRpos over CR. Some fancy work needs to be done because
64 autorewrite will not in CRpos, because it is in Type and not Prop. *)
65 Ltac IR_dec_precompute :=
66 try apply less_leEq;
67 apply CR_less_as_IR;
68 unfold CRltT;
69 match goal with
70 | |- CRpos ?X => let X0 := fresh "IR_dec" in
71 set (X0:=X);
72 let XH := fresh "IR_dec" in
73 assert (XH:(X==X0)%CR) by reflexivity;
74 autorewrite with IRtoCR in XH;
75 autorewrite with CRfast_compute in XH;
76 apply (CRpos_wd XH);
77 clear X0 XH
78 end.
79
80 (** This tactic solves inequalites over IR. It converts the problem
81 into a question about positivity over CR, and then tries to solve it. *)
82 Ltac IR_solve_ineq e :=
83 IR_dec_precompute; CR_solve_pos e.