Commit 0afa9b92 authored by Robbert Krebbers's avatar Robbert Krebbers
Browse files

Define shorthand EqDecision A := (∀ x y : A, Decision (x = y)).

parent 2d1cd803
......@@ -9,7 +9,7 @@ From iris.prelude Require Export base decidable option.
Open Scope nat_scope.
Coercion Z.of_nat : nat >-> Z.
Instance comparison_eq_dec (c1 c2 : comparison) : Decision (c1 = c2).
Instance comparison_eq_dec : EqDecision comparison.
Proof. solve_decision. Defined.
(** * Notations and properties of [nat] *)
......@@ -35,13 +35,13 @@ Infix "`mod`" := Nat.modulo (at level 35) : nat_scope.
Infix "`max`" := Nat.max (at level 35) : nat_scope.
Infix "`min`" := Nat.min (at level 35) : nat_scope.
Instance nat_eq_dec: x y : nat, Decision (x = y) := eq_nat_dec.
Instance nat_eq_dec: EqDecision nat := eq_nat_dec.
Instance nat_le_dec: x y : nat, Decision (x y) := le_dec.
Instance nat_lt_dec: x y : nat, Decision (x < y) := lt_dec.
Instance nat_inhabited: Inhabited nat := populate 0%nat.
Instance: Inj (=) (=) S.
Instance S_inj: Inj (=) (=) S.
Proof. by injection 1. Qed.
Instance: PartialOrder ().
Instance nat_le_po: PartialOrder ().
Proof. repeat split; repeat intro; auto with lia. Qed.
Instance nat_le_pi: x y : nat, ProofIrrel (x y).
......@@ -116,7 +116,7 @@ Notation "(~1)" := xI (only parsing) : positive_scope.
Arguments Pos.of_nat : simpl never.
Arguments Pmult : simpl never.
Instance positive_eq_dec: x y : positive, Decision (x = y) := Pos.eq_dec.
Instance positive_eq_dec: EqDecision positive := Pos.eq_dec.
Instance positive_inhabited: Inhabited positive := populate 1.
Instance maybe_xO : Maybe xO := λ p, match p with p~0 => Some p | _ => None end.
......@@ -198,7 +198,7 @@ Arguments N.add _ _ : simpl never.
Instance: Inj (=) (=) Npos.
Proof. by injection 1. Qed.
Instance N_eq_dec: x y : N, Decision (x = y) := N.eq_dec.
Instance N_eq_dec: EqDecision N := N.eq_dec.
Program Instance N_le_dec (x y : N) : Decision (x y)%N :=
match Ncompare x y with Gt => right _ | _ => left _ end.
Solve Obligations with naive_solver.
......@@ -206,7 +206,7 @@ Program Instance N_lt_dec (x y : N) : Decision (x < y)%N :=
match Ncompare x y with Lt => left _ | _ => right _ end.
Solve Obligations with naive_solver.
Instance N_inhabited: Inhabited N := populate 1%N.
Instance: PartialOrder ()%N.
Instance N_le_po: PartialOrder ()%N.
Proof.
repeat split; red. apply N.le_refl. apply N.le_trans. apply N.le_antisymm.
Qed.
......@@ -239,11 +239,11 @@ Proof. by injection 1. Qed.
Instance Z_of_nat_inj : Inj (=) (=) Z.of_nat.
Proof. intros n1 n2. apply Nat2Z.inj. Qed.
Instance Z_eq_dec: x y : Z, Decision (x = y) := Z.eq_dec.
Instance Z_eq_dec: EqDecision Z := Z.eq_dec.
Instance Z_le_dec: x y : Z, Decision (x y) := Z_le_dec.
Instance Z_lt_dec: x y : Z, Decision (x < y) := Z_lt_dec.
Instance Z_inhabited: Inhabited Z := populate 1.
Instance Z_le_order : PartialOrder ().
Instance Z_le_po : PartialOrder ().
Proof.
repeat split; red. apply Z.le_refl. apply Z.le_trans. apply Z.le_antisymm.
Qed.
......@@ -345,7 +345,7 @@ Notation "(<)" := Qclt (only parsing) : Qc_scope.
Hint Extern 1 (_ _) => reflexivity || discriminate.
Arguments Qred _ : simpl never.
Instance Qc_eq_dec: x y : Qc, Decision (x = y) := Qc_eq_dec.
Instance Qc_eq_dec: EqDecision Qc := Qc_eq_dec.
Program Instance Qc_le_dec (x y : Qc) : Decision (x y) :=
if Qclt_le_dec y x then right _ else left _.
Next Obligation. intros x y; apply Qclt_not_le. Qed.
......
......@@ -148,14 +148,13 @@ Instance option_eq_None_dec {A} (mx : option A) : Decision (mx = None) :=
match mx with Some _ => right (Some_ne_None _) | None => left eq_refl end.
Instance option_None_eq_dec {A} (mx : option A) : Decision (None = mx) :=
match mx with Some _ => right (None_ne_Some _) | None => left eq_refl end.
Instance option_eq_dec {A} {dec : x y : A, Decision (x = y)}
(mx my : option A) : Decision (mx = my).
Instance option_eq_dec `{dec : EqDecision A} : EqDecision (option A).
Proof.
refine
refine (λ mx my,
match mx, my with
| Some x, Some y => cast_if (decide (x = y))
| None, None => left _ | _, _ => right _
end; clear dec; abstract congruence.
end); clear dec; abstract congruence.
Defined.
(** * Monadic operations *)
......
......@@ -48,10 +48,9 @@ Section orders.
- intros [? HYX]. split. done. by intros <-.
- intros [? HXY]. split. done. by contradict HXY; apply (anti_symm R).
Qed.
Lemma po_eq_dec `{!PartialOrder R, X Y, Decision (X Y)} (X Y : A) :
Decision (X = Y).
Lemma po_eq_dec `{!PartialOrder R, X Y, Decision (X Y)} : EqDecision A.
Proof.
refine (cast_if_and (decide (X Y)) (decide (Y X)));
refine (λ X Y, cast_if_and (decide (X Y)) (decide (Y X)));
abstract (rewrite anti_symm_iff; tauto).
Defined.
Lemma total_not `{!Total R} X Y : X Y Y X.
......
......@@ -26,8 +26,7 @@ Inductive Pmap_raw (A : Type) : Type :=
Arguments PLeaf {_}.
Arguments PNode {_} _ _ _.
Instance Pmap_raw_eq_dec `{ x y : A, Decision (x = y)} (x y : Pmap_raw A) :
Decision (x = y).
Instance Pmap_raw_eq_dec `{EqDecision A} : EqDecision (Pmap_raw A).
Proof. solve_decision. Defined.
Fixpoint Pmap_wf {A} (t : Pmap_raw A) : bool :=
......@@ -266,8 +265,7 @@ Proof.
split; [by intros ->|intros]; destruct m1 as [t1 ?], m2 as [t2 ?].
simplify_eq/=; f_equal; apply proof_irrel.
Qed.
Instance Pmap_eq_dec `{ x y : A, Decision (x = y)}
(m1 m2 : Pmap A) : Decision (m1 = m2) :=
Instance Pmap_eq_dec `{EqDecision A} : EqDecision (Pmap A) := λ m1 m2,
match Pmap_raw_eq_dec (pmap_car m1) (pmap_car m2) with
| left H => left (proj2 (Pmap_eq m1 m2) H)
| right H => right (H proj1 (Pmap_eq m1 m2))
......
......@@ -16,10 +16,10 @@ Infix "+:+" := String.append (at level 60, right associativity) : C_scope.
Arguments String.append _ _ : simpl never.
(** * Decision of equality *)
Instance assci_eq_dec : a1 a2, Decision (a1 = a2) := ascii_dec.
Instance string_eq_dec (s1 s2 : string) : Decision (s1 = s2).
Instance assci_eq_dec : EqDecision ascii := ascii_dec.
Instance string_eq_dec : EqDecision string.
Proof. solve_decision. Defined.
Instance: Inj (=) (=) (String.append s1).
Instance string_app_inj : Inj (=) (=) (String.append s1).
Proof. intros s1 ???. induction s1; simplify_eq/=; f_equal/=; auto. Qed.
(* Reverse *)
......
......@@ -35,7 +35,7 @@ Coercion fin_to_nat : fin >-> nat.
Notation fin_of_nat := Fin.of_nat_lt.
Notation fin_rect2 := Fin.rect2.
Instance fin_dec {n} : i j : fin n, Decision (i = j).
Instance fin_dec {n} : EqDecision (fin n).
Proof.
refine (fin_rect2
(λ n (i j : fin n), { i = j } + { i j })
......@@ -163,8 +163,7 @@ Proof.
- apply IH. intros i. apply (Hi (FS i)).
Qed.
Instance vec_dec {A} {dec : x y : A, Decision (x = y)} {n} :
v w : vec A n, Decision (v = w).
Instance vec_dec {A} {dec : EqDecision A} {n} : EqDecision (vec A n).
Proof.
refine (vec_rect2
(λ n (v w : vec A n), { v = w } + { v w })
......
......@@ -13,14 +13,13 @@ Arguments Zmap_pos {_} _.
Arguments Zmap_neg {_} _.
Arguments ZMap {_} _ _ _.
Instance Zmap_eq_dec `{ x y : A, Decision (x = y)} (t1 t2 : Zmap A) :
Decision (t1 = t2).
Instance Zmap_eq_dec `{EqDecision A} : EqDecision (Zmap A).
Proof.
refine
refine (λ t1 t2,
match t1, t2 with
| ZMap x t1 t1', ZMap y t2 t2' =>
cast_if_and3 (decide (x = y)) (decide (t1 = t2)) (decide (t1' = t2'))
end; abstract congruence.
end); abstract congruence.
Defined.
Instance Zempty {A} : Empty (Zmap A) := ZMap None .
Instance Zlookup {A} : Lookup Z A (Zmap A) := λ i t,
......
......@@ -2,7 +2,7 @@ From iris.prelude Require Export countable coPset.
From iris.algebra Require Export base.
Definition namespace := list positive.
Instance namespace_dec (N1 N2 : namespace) : Decision (N1 = N2) := _.
Instance namespace_eq_dec : EqDecision namespace := _.
Instance namespace_countable : Countable namespace := _.
Typeclasses Opaque namespace.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment