Built with Alectryon, running Coq+SerAPI v8.10.0+0.7.0. Coq sources are in this panel; goals and messages will appear in the other. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑ Ctrl+↓ to navigate, Ctrl+🖱️ to focus.
(************************************************************************) (* * The Coq Proof Assistant / The Coq Development Team *) (* v * INRIA, CNRS and contributors - Copyright 1999-2018 *) (* <O___,, * (see CREDITS file for the list of authors) *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (* * (see LICENSE file for the text of the license) *) (************************************************************************) Require Import OrderedType.
NB: comparison, defined in Datatypes.v is Eq|Lt|Gt
whereas compare, defined in OrderedType.v is EQ _ | LT _ | GT _
Module Type OrderedTypeAlt. Parameter t : Type. Parameter compare : t -> t -> comparison. Infix "?=" := compare (at level 70, no associativity). Parameter compare_sym : forall x y, (y?=x) = CompOpp (x?=y). Parameter compare_trans : forall c x y z, (x?=y) = c -> (y?=z) = c -> (x?=z) = c. End OrderedTypeAlt.
From this new presentation to the original one.
Module OrderedType_from_Alt (O:OrderedTypeAlt) <: OrderedType. Import O. Definition t := t. Definition eq x y := (x?=y) = Eq. Definition lt x y := (x?=y) = Lt.forall x : O.t, eq x xforall x : O.t, eq x xx:O.teq x xx:O.t(x ?= x) = Eqdestruct (x ?= x); simpl in *; try discriminate; auto. Qed.x:O.tH:(x ?= x) = CompOpp (x ?= x)(x ?= x) = Eqforall x y : O.t, eq x y -> eq y xforall x y : O.t, eq x y -> eq y xx, y:O.tH:(x ?= y) = Eq(y ?= x) = Eqrewrite H; simpl; auto. Qed. Definition eq_trans := (compare_trans Eq). Definition lt_trans := (compare_trans Lt).x, y:O.tH:(x ?= y) = EqCompOpp (x ?= y) = Eqforall x y : O.t, lt x y -> ~ eq x yforall x y : O.t, lt x y -> ~ eq x yrewrite H; discriminate. Qed.x, y:O.tH:(x ?= y) = Lt(x ?= y) <> Eqforall x y : O.t, Compare lt eq x yforall x y : O.t, Compare lt eq x yx, y:O.tCompare lt eq x yx, y:O.tH:(x ?= y) = EqCompare lt eq x yx, y:O.tH:(x ?= y) = LtCompare lt eq x yx, y:O.tH:(x ?= y) = GtCompare lt eq x yx, y:O.tH:(x ?= y) = LtCompare lt eq x yx, y:O.tH:(x ?= y) = GtCompare lt eq x yx, y:O.tH:(x ?= y) = GtCompare lt eq x yrewrite compare_sym; rewrite H; auto. Defined.x, y:O.tH:(x ?= y) = Gt(y ?= x) = Ltforall x y : O.t, {eq x y} + {~ eq x y}forall x y : O.t, {eq x y} + {~ eq x y}case (x ?= y); [ left | right | right ]; auto; discriminate. Defined. End OrderedType_from_Alt.x, y:O.t{(x ?= y) = Eq} + {(x ?= y) <> Eq}
From the original presentation to this alternative one.
Module OrderedType_to_Alt (O:OrderedType) <: OrderedTypeAlt. Import O. Module MO:=OrderedTypeFacts(O). Import MO. Definition t := t. Definition compare x y := match compare x y with | LT _ => Lt | EQ _ => Eq | GT _ => Gt end. Infix "?=" := compare (at level 70, no associativity).forall x y : O.t, (y ?= x) = CompOpp (x ?= y)forall x y : O.t, (y ?= x) = CompOpp (x ?= y)destruct O.compare; elim_comp; simpl; auto. Qed.x, y:O.tmatch O.compare y x with | LT _ => Lt | EQ _ => Eq | GT _ => Gt end = CompOpp match O.compare x y with | LT _ => Lt | EQ _ => Eq | GT _ => Gt endforall (c : comparison) (x y z : O.t), (x ?= y) = c -> (y ?= z) = c -> (x ?= z) = cforall (c : comparison) (x y z : O.t), (x ?= y) = c -> (y ?= z) = c -> (x ?= z) = cdestruct c; unfold compare; do 2 (destruct O.compare; intros; try discriminate); elim_comp; auto. Qed. End OrderedType_to_Alt.c:comparisonx, y, z:O.t(x ?= y) = c -> (y ?= z) = c -> (x ?= z) = c