-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the companion of https://github.com/fajb/coq/tree/tify - Update the reflexive proof verifier for lia,lra etc. - Define instances for the [rify] tactic (Require Import Rify)
- Loading branch information
Showing
27 changed files
with
4,782 additions
and
1,910 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
Require Import Rbase Rify isZ Lra Zfloor. | ||
Local Open Scope R_scope. | ||
|
||
Lemma up0 : up 0%R = 1%Z. | ||
Proof. intros. rify. lra. Qed. | ||
|
||
Lemma up_succ r : up (r + 1)%R = (up r + 1)%Z. | ||
Proof. intros. rify. lra. Qed. | ||
|
||
Lemma up_IZR z : up (IZR z) = (z + 1)%Z. | ||
Proof. | ||
rify. lra. | ||
Qed. | ||
|
||
Lemma up_shiftz r z : up (r + IZR z)%R = (up r + z)%Z. | ||
Proof. | ||
rify. lra. | ||
Qed. | ||
|
||
|
||
Lemma up_succ2 r n : Zfloor (r + IZR n) = (Zfloor r + n)%Z. | ||
Proof. | ||
rify. lra. | ||
Qed. | ||
|
||
Goal forall x1 x2 x3 x5 x6 | ||
(H: -x2 > 0) | ||
(H0: x3 >= 0) | ||
(H1: -x1 + x5 + x6 = 0) | ||
(H2: x1 + -x5 + x6 = 0) | ||
(H4: -x1 > 0) | ||
(H6: x2 + -x3 = 0) | ||
(H7: 3 + 3*x1 = 0), | ||
False. | ||
Proof. | ||
intros. | ||
lra. | ||
Qed. | ||
|
||
|
||
Lemma spurious_isZ : forall | ||
(x l X : R) | ||
(delta : R) | ||
(iZ1 : isZ x) | ||
(H13 : - (X - l) <= 0) | ||
(iZ2 : isZ X) | ||
(H4 : l > 0) | ||
(iZ2 : isZ X) | ||
(H9 : delta / 2 <> 0) | ||
(iZ2 : isZ X) | ||
(H11 : 0 < delta / 2) | ||
(iZ1 : isZ x) | ||
(H10 : (X <= 0)), | ||
False. | ||
Proof. | ||
intros. | ||
lra. | ||
Qed. | ||
|
||
Goal forall (k x:R) (P:Prop) | ||
(Hyp : 0 <= k < 1) | ||
(H2 : k < x < 1 /\ P) | ||
(H3 : k < x < 1), | ||
0 < x. | ||
Proof. | ||
intros. | ||
lra. | ||
Qed. | ||
|
||
|
||
Ltac cnf := match goal with | ||
| |- Tauto.cnf_checker _ ?F _ = true => | ||
let f:= fresh "f" in | ||
set(f:=F); compute in f; unfold f;clear f | ||
end. | ||
|
||
Ltac collect := | ||
match goal with | ||
| |- context [ RMicromega.xcollect_isZ ?A ?B ?F] => | ||
let f := fresh "f" in | ||
set (f:= RMicromega.xcollect_isZ A B F) ; compute in f ; unfold f; clear f | ||
end. | ||
|
||
|
||
Goal forall (x y:R) | ||
(H : x <= y) | ||
(Hlt : x < y), | ||
y - x = 0 -> False. | ||
Proof. | ||
intros. | ||
lra. | ||
Qed. | ||
|
||
Lemma two_x_1 : forall (x:R) | ||
(IZ : isZ x) | ||
(H : 2 * x + 1 = 0), | ||
False. | ||
Proof. | ||
intros. | ||
lra. | ||
Qed. | ||
|
||
Goal forall x1 x2 x3 x4, | ||
isZ x1 -> | ||
isZ x2 -> | ||
isZ x3 -> | ||
isZ x4 -> | ||
- x1 + x2 - x3 + x4 >= 0 -> | ||
x1 - x2 + x3 - x4 + 1 > 0 -> | ||
- x1 + x2 - x3 + x4 > 0 -> | ||
False. | ||
Proof. | ||
intros. lra. | ||
Qed. | ||
|
||
|
||
|
||
Goal forall z1 z2 z3, Zfloor (IZR z1 - IZR z2 + IZR z3)%R = (z1 - z2 + z3)%Z. | ||
Proof. | ||
intros. | ||
rify. | ||
(** Now, some work over isZ *) | ||
lra. | ||
Qed. | ||
|
||
Goal forall (z : Z) x, IZR z <= x -> (z <= Zfloor x)%Z. | ||
Proof. | ||
rify. | ||
lra. | ||
Qed. | ||
|
||
|
||
|
||
Goal forall (z : Z) x, IZR z <= x < IZR z + 1 -> Zfloor x = z. | ||
Proof. | ||
intros. | ||
rify. | ||
lra. | ||
Qed. | ||
|
||
|
||
Goal R1 + (R1 + R1) = 3. | ||
Proof. | ||
intros. | ||
rify. | ||
reflexivity. | ||
Qed. | ||
|
||
Goal forall x, | ||
x * 3 = 1 -> | ||
False. | ||
Proof. | ||
intros. | ||
Fail lra. | ||
Abort. | ||
|
||
Goal forall x, | ||
isZ x -> | ||
x * 3 = 1 -> | ||
False. | ||
Proof. | ||
intros. | ||
lra. | ||
Qed. | ||
|
||
|
||
|
||
Require Import Rfunctions R_sqrt. | ||
|
||
Goal forall e x | ||
(He : 0 < e) | ||
(ef := Rmin (e / (3 * (Rabs (x) + 1))) (sqrt (e / 3)) : R) | ||
(H : sqrt (e / 3) > 0) | ||
(H0 : 3 * (Rabs ( x) + 1) >= 1), | ||
0 < ef. | ||
Proof. | ||
intros. | ||
rify. nra. | ||
Qed. | ||
|
||
|
||
Goal forall x v, | ||
v * (3 * x) = 1 -> | ||
x >= 1 -> | ||
v = 1 / (3 * x). | ||
Proof. | ||
intros. | ||
rify. nra. | ||
Qed. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
From Stdlib Require Import Reals. | ||
From Stdlib Require Import ZArith. | ||
From Stdlib Require Import ZifyClasses Tify. | ||
|
||
(* Inject nat -> Z *) | ||
|
||
Instance Inj_nat_Z : InjTyp nat Z. | ||
Proof. | ||
apply (mkinj _ _ Z.of_nat (fun x => (0 <= x)%Z)). | ||
apply Nat2Z.is_nonneg. | ||
Defined. | ||
Add Tify InjTyp Inj_nat_Z. | ||
|
||
Instance Op_nat_add_Z : BinOp Nat.add. | ||
Proof. | ||
apply mkbop with (TBOp := Z.add). | ||
simpl. apply Nat2Z.inj_add. | ||
Defined. | ||
Add Tify BinOp Op_nat_add_Z. | ||
|
||
Instance Op_eq_nat_eq_Z : BinRel (@eq nat). | ||
Proof. | ||
apply mkbrel with (TR := @eq Z). | ||
simpl. split. congruence. | ||
apply Nat2Z.inj. | ||
Defined. | ||
Add Tify BinRel Op_eq_nat_eq_Z. | ||
|
||
|
||
(** Inject nat -> R *) | ||
|
||
Definition isZ (r:R) := IZR (Zfloor r) = r. | ||
|
||
Instance Inj_nat_R : InjTyp nat R. | ||
Proof. | ||
apply (mkinj _ _ INR (fun r => isZ r /\ 0 <= r)). | ||
- intros. split. unfold isZ. | ||
rewrite INR_IZR_INZ. | ||
rewrite ZfloorZ. reflexivity. | ||
apply pos_INR. | ||
Defined. | ||
Add Tify InjTyp Inj_nat_R. | ||
|
||
Instance Op_add_R : BinOp Nat.add. | ||
Proof. | ||
apply mkbop with (TBOp := Rplus). | ||
simpl. intros. apply plus_INR. | ||
Defined. | ||
Add Tify BinOp Op_add_R. | ||
|
||
Instance Op_eq_nat_eq_R : BinRel (@eq nat). | ||
Proof. | ||
apply mkbrel with (TR := @eq R). | ||
simpl. split; intro. congruence. | ||
apply INR_eq; auto. | ||
Defined. | ||
Add Tify BinRel Op_eq_nat_eq_R. | ||
|
||
|
||
(* tify selects the right injection *) | ||
|
||
Goal forall (x y:nat), (x + y = y + x)%nat. | ||
Proof. | ||
intros. | ||
tify R. | ||
apply Rplus_comm. | ||
Qed. | ||
|
||
Goal forall (x y:nat), (x + y = y + x)%nat. | ||
Proof. | ||
intros. | ||
tify Z. | ||
apply Zplus_comm. | ||
Qed. | ||
|
||
(* The R instances do not break lia. *) | ||
From Stdlib Require Import Lia. | ||
Goal forall (x y:nat), (x + y = y + x)%nat. | ||
Proof. | ||
intros. | ||
lia. | ||
Qed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.