orders.v 3.74 KB
 Robbert Krebbers committed Jan 29, 2019 1 ``````(* Copyright (c) 2012-2019, Coq-std++ developers. *) `````` Robbert Krebbers committed Aug 29, 2012 2 ``````(* This file is distributed under the terms of the BSD license. *) `````` Robbert Krebbers committed Aug 12, 2013 3 4 ``````(** Properties about arbitrary pre-, partial, and total orders. We do not use the relation [⊆] because we often have multiple orders on the same structure *) `````` Robbert Krebbers committed Jul 22, 2016 5 ``````From stdpp Require Export tactics. `````` Ralf Jung committed Jan 31, 2017 6 ``````Set Default Proof Using "Type". `````` Robbert Krebbers committed Jul 22, 2016 7 `````` `````` Robbert Krebbers committed Aug 12, 2013 8 9 10 11 12 13 14 15 16 ``````Section orders. Context {A} {R : relation A}. Implicit Types X Y : A. Infix "⊆" := R. Notation "X ⊈ Y" := (¬X ⊆ Y). Infix "⊂" := (strict R). Lemma reflexive_eq `{!Reflexive R} X Y : X = Y → X ⊆ Y. Proof. by intros <-. Qed. `````` Robbert Krebbers committed Feb 11, 2016 17 18 `````` Lemma anti_symm_iff `{!PartialOrder R} X Y : X = Y ↔ R X Y ∧ R Y X. Proof. split. by intros ->. by intros [??]; apply (anti_symm _). Qed. `````` Robbert Krebbers committed Aug 12, 2013 19 20 21 22 23 24 25 26 27 28 `````` Lemma strict_spec X Y : X ⊂ Y ↔ X ⊆ Y ∧ Y ⊈ X. Proof. done. Qed. Lemma strict_include X Y : X ⊂ Y → X ⊆ Y. Proof. by intros [? _]. Qed. Lemma strict_ne X Y : X ⊂ Y → X ≠ Y. Proof. by intros [??] <-. Qed. Lemma strict_ne_sym X Y : X ⊂ Y → Y ≠ X. Proof. by intros [??] <-. Qed. Lemma strict_transitive_l `{!Transitive R} X Y Z : X ⊂ Y → Y ⊆ Z → X ⊂ Z. Proof. `````` Ralf Jung committed Feb 20, 2016 29 30 `````` intros [? HXY] ?. split; [by trans Y|]. contradict HXY. by trans Z. `````` Robbert Krebbers committed Aug 12, 2013 31 32 33 `````` Qed. Lemma strict_transitive_r `{!Transitive R} X Y Z : X ⊆ Y → Y ⊂ Z → X ⊂ Z. Proof. `````` Ralf Jung committed Feb 20, 2016 34 35 `````` intros ? [? HYZ]. split; [by trans Y|]. contradict HYZ. by trans X. `````` Robbert Krebbers committed Aug 12, 2013 36 37 38 39 40 41 42 43 `````` Qed. Global Instance: Irreflexive (strict R). Proof. firstorder. Qed. Global Instance: Transitive R → StrictOrder (strict R). Proof. split; try apply _. eauto using strict_transitive_r, strict_include. Qed. `````` 44 45 46 `````` Global Instance preorder_subset_dec_slow `{!RelDecision R} : RelDecision (strict R) | 100. Proof. solve_decision. Defined. `````` Robbert Krebbers committed Feb 11, 2016 47 `````` Lemma strict_spec_alt `{!AntiSymm (=) R} X Y : X ⊂ Y ↔ X ⊆ Y ∧ X ≠ Y. `````` Robbert Krebbers committed Aug 12, 2013 48 49 `````` Proof. split. `````` Robbert Krebbers committed Feb 17, 2016 50 51 `````` - intros [? HYX]. split. done. by intros <-. - intros [? HXY]. split. done. by contradict HXY; apply (anti_symm R). `````` Robbert Krebbers committed Aug 12, 2013 52 `````` Qed. `````` 53 `````` Lemma po_eq_dec `{!PartialOrder R, !RelDecision R} : EqDecision A. `````` Robbert Krebbers committed Aug 12, 2013 54 `````` Proof. `````` Robbert Krebbers committed Sep 20, 2016 55 `````` refine (λ X Y, cast_if_and (decide (X ⊆ Y)) (decide (Y ⊆ X))); `````` Robbert Krebbers committed Feb 11, 2016 56 `````` abstract (rewrite anti_symm_iff; tauto). `````` Robbert Krebbers committed Aug 12, 2013 57 58 59 60 61 `````` Defined. Lemma total_not `{!Total R} X Y : X ⊈ Y → Y ⊆ X. Proof. intros. destruct (total R X Y); tauto. Qed. Lemma total_not_strict `{!Total R} X Y : X ⊈ Y → Y ⊂ X. Proof. red; auto using total_not. Qed. `````` Robbert Krebbers committed Sep 09, 2013 62 `````` Global Instance trichotomy_total `````` Robbert Krebbers committed Nov 15, 2014 63 `````` `{!Trichotomy (strict R), !Reflexive R} : Total R. `````` Robbert Krebbers committed Sep 09, 2013 64 65 66 67 68 69 70 71 72 73 74 75 76 `````` Proof. intros X Y. destruct (trichotomy (strict R) X Y) as [[??]|[<-|[??]]]; intuition. Qed. End orders. Section strict_orders. Context {A} {R : relation A}. Implicit Types X Y : A. Infix "⊂" := R. Lemma irreflexive_eq `{!Irreflexive R} X Y : X = Y → ¬X ⊂ Y. Proof. intros ->. apply (irreflexivity R). Qed. `````` Robbert Krebbers committed Feb 11, 2016 77 `````` Lemma strict_anti_symm `{!StrictOrder R} X Y : `````` Robbert Krebbers committed Sep 09, 2013 78 `````` X ⊂ Y → Y ⊂ X → False. `````` Ralf Jung committed Feb 20, 2016 79 `````` Proof. intros. apply (irreflexivity R X). by trans Y. Qed. `````` 80 81 `````` Global Instance trichotomyT_dec `{!TrichotomyT R, !StrictOrder R} : RelDecision R := λ X Y, `````` Robbert Krebbers committed Aug 12, 2013 82 `````` match trichotomyT R X Y with `````` Robbert Krebbers committed Sep 09, 2013 83 84 `````` | inleft (left H) => left H | inleft (right H) => right (irreflexive_eq _ _ H) `````` Robbert Krebbers committed Feb 11, 2016 85 `````` | inright H => right (strict_anti_symm _ _ H) `````` Robbert Krebbers committed Aug 12, 2013 86 87 88 `````` end. Global Instance trichotomyT_trichotomy `{!TrichotomyT R} : Trichotomy R. Proof. intros X Y. destruct (trichotomyT R X Y) as [[|]|]; tauto. Qed. `````` Robbert Krebbers committed Sep 09, 2013 89 ``````End strict_orders. `````` Robbert Krebbers committed Aug 12, 2013 90 91 92 `````` Ltac simplify_order := repeat match goal with `````` Robbert Krebbers committed Feb 17, 2016 93 `````` | _ => progress simplify_eq/= `````` Robbert Krebbers committed Sep 09, 2013 94 `````` | H : ?R ?x ?x |- _ => by destruct (irreflexivity _ _ H) `````` Robbert Krebbers committed Aug 12, 2013 95 96 97 `````` | H1 : ?R ?x ?y |- _ => match goal with | H2 : R y x |- _ => `````` Robbert Krebbers committed Feb 11, 2016 98 `````` assert (x = y) by (by apply (anti_symm R)); clear H1 H2 `````` Robbert Krebbers committed Aug 12, 2013 99 100 `````` | H2 : R y ?z |- _ => unless (R x z) by done; `````` Ralf Jung committed Feb 20, 2016 101 `````` assert (R x z) by (by trans y) `````` Robbert Krebbers committed Aug 12, 2013 102 103 `````` end end.``````