Debian Codegraph @

src/Util/Relations.v

raw
1 Require Import Crypto.Util.FixCoqMistakes.
2 Require Import Crypto.Util.Logic.
3 From Coq Require Import Morphisms Setoid.
4
5 Lemma symmetry_iff {T} {R} {Rsym:@Symmetric T R} x y: R x y <-> R y x.
6 epose symmetry; intuition eauto.
7 Qed.
8
9 Lemma and_rewrite_l {A B} {RA RB} {Equivalence_RA:Equivalence RA} {Equivalence_RB:Equivalence RB}
10 (f:A->B) ref P {Proper_P: Proper (RA==>RB==>iff) P} a
11 : (RB (f a) ref /\ P a (f a)) <-> (RB (f a) ref /\ P a ref).
12 Proof.
13 logic; match goal with [H:_|-_] => (rewrite H || rewrite <-H); assumption end.
14 Qed.
15
16 Lemma and_rewriteleft_l {A B} {RA RB} {Equivalence_RA:Equivalence RA} {Equivalence_RB:Equivalence RB}
17 (f:A->B) ref P {Proper_P: Proper (RA==>RB==>iff) P} a
18 : (RB ref (f a) /\ P a (f a)) <-> (RB ref (f a) /\ P a ref).
19 Proof.
20 logic; match goal with [H:_|-_] => (rewrite H || rewrite <-H); assumption end.
21 Qed.
22
23 Lemma exists_and_equiv_r {A} {RA} {Equivalence_RA:Equivalence RA}
24 P {Proper_P: Proper (RA==>iff) P} (ref:A)
25 : (exists a, P a /\ RA a ref) <-> P ref.
26 Proof.
27 logic; try match goal with [H:_|-_] => (rewrite H || rewrite <-H); assumption end.
28 repeat (assumption||reflexivity||econstructor); assumption. (* WHY the last [assumption]?*)
29 Qed.
30
31 Lemma iff_R_R_same_r {T R} {Req:@Equivalence T R} x y ref : R x y -> (R x ref <-> R y ref).
32 Proof.
33 intro Hx; rewrite Hx; clear Hx. reflexivity.
34 Qed.
35
36 Global Instance Equivalence_and {A B RA RB}
37 {Equivalence_RA:@Equivalence A RA}
38 {Equivalence_RB:@Equivalence B RB}
39 : Equivalence (fun ab AB => RA (fst ab) (fst AB) /\ RB (snd ab) (snd AB)).
40 Proof.
41 do 2 match goal with H : Equivalence _ |- _ => destruct H end;
42 cbv in *|-.
43 repeat match goal with
44 | _ => intro
45 | _ => split
46 | [p:prod _ _ |- _ ] => destruct p
47 | [p:and _ _ |- _ ] => destruct p
48 | _ => progress (cbv [fst snd] in * )
49 | _ => solve[eauto]
50 end.
51 Qed.
52
53 Global Instance eq_eta_Reflexive {T} : Reflexive (fun x y : T => x = y) | 1
54 := eq_Reflexive.
55
56 Global Instance Symmetric_not {T:Type} (R:T->T->Prop)
57 {SymmetricR:Symmetric R} : Symmetric (fun a b => not (R a b)).
58 Proof. cbv [Symmetric] in *; repeat intro; eauto. Qed.
59
60 Lemma not_exfalso (P:Prop) (H:P->False) : not P. auto with nocore. Qed.
61
62 Global Instance respectful_subrelation_pointwise {A B} {RA : relation A} {R R' : relation B}
63 : subrelation eq RA -> subrelation R R' -> subrelation (RA ==> R)%signature (pointwise_relation A R') | 100.
64 Proof. cbv; eauto. Qed.
65
66 Global Instance pointwise_subrelation_respectful {A B} {RA : relation A} {R R' : relation B}
67 : subrelation RA eq -> subrelation R' R -> subrelation (pointwise_relation A R') (RA ==> R)%signature | 100.
68 Proof. cbv; firstorder (subst; eauto). Qed.