Built with Alectryon, running Coq+SerAPI v8.20.0+0.20.0. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑Ctrl+↓ to navigate, Ctrl+🖱️ to focus. On Mac, use ⌘ instead of Ctrl.
[Loading ML file ssrmatching_plugin.cmxs (using legacy method) ... done]
[Loading ML file ssreflect_plugin.cmxs (using legacy method) ... done]
[Loading ML file ring_plugin.cmxs (using legacy method) ... done]
Serlib plugin: coq-elpi.elpi is not available: serlib support is missing.
Incremental checking for commands in this plugin will be impacted.
[Loading ML file coq-elpi.elpi ... done]
(** * Computation of a Sequence's Supremum *)(** This module provides a simple function [supremum] for the computation of a maximal element of a sequence, according to any given relation [R]. If the relation [R] is reflexive, total, and transitive, the result of [supremum] is indeed the supremum of the set of items in the sequence. *)SectionSelectSupremum.(** Consider any type of elements with decidable equality... *)Context {T : eqType}.(** ...and any given relation [R]. *)VariableR : rel T.(** We first define a help function [choose_superior] that, given an element [x] and maybe a second element [y], picks [x] if [R x y] holds, and [y] otherwise. *)Definitionchoose_superior (x : T) (maybe_y : option T) : option T :=
match maybe_y with
| Some y => if R x y then Some x else Some y
| None => Some x
end.(** The supremum of a given sequence [s] can then be computed by simply folding [s] with [choose_superior]. *)Definitionsupremum (s : seq T) : option T := foldr choose_superior None s.(** Next, we establish that [supremum] satisfies its specification. To this end, we first establish a few simple helper lemmas. *)(** We start with observing how [supremum] can be unrolled one step. *)
supremum (head :: tail) =
choose_superior head (supremum tail)
byrewrite [LHS]/supremum /foldr -/(foldr choose_superior None tail) -/(supremum tail).Qed.(** Next, we observe that [supremum] returns a result for any non-empty list. *)
T: eqType R: rel T
forall (x : T) (s : seq_predType T),
x \in s -> supremum s != None
T: eqType R: rel T
forall (x : T) (s : seq_predType T),
x \in s -> supremum s != None
T: eqType R: rel T x: T s: seq_predType T IN: x \in s
supremum s != None
T: eqType R: rel T x: T
forall (a : T) (l : seq T),
(x \in l -> supremum l != None) ->
x \in a :: l -> supremum (a :: l) != None
T: eqType R: rel T x, a: T l: seq T
supremum (a :: l) != None
T: eqType R: rel T x, a: T l: seq T
choose_superior a (supremum l) != None
T: eqType R: rel T x, a: T l: seq T s: T
(if R a s then Some a else Some s) != None
bydestruct (R a s).Qed.(** Conversely, if [supremum] finds nothing, then the list is empty. *)
T: eqType R: rel T
foralls : seq T, supremum s = None -> s = [::]
T: eqType R: rel T
foralls : seq T, supremum s = None -> s = [::]
T: eqType R: rel T s: seq T
supremum s = None -> s = [::]
T: eqType R: rel T
forall (a : T) (l : seq T),
(supremum l = None -> l = [::]) ->
supremum (a :: l) = None -> a :: l = [::]
T: eqType R: rel T a: T l: seq T IH: supremum l = None -> l = [::]
supremum (a :: l) = None -> a :: l = [::]
T: eqType R: rel T a: T l: seq T IH: supremum l = None -> l = [::]
match supremum l with
| Some y => if R a y then Some a else Some y
| None => Some a
end = None -> a :: l = [::]
bydestruct (supremum l) as [s|]; trydestruct (R a s).Qed.(** Next, we observe that the value found by [supremum] comes indeed from the list that it was given. *)
T: eqType R: rel T
forall (x : T) (s : seq T),
supremum s = Some x -> x \in s
T: eqType R: rel T
forall (x : T) (s : seq T),
supremum s = Some x -> x \in s
T: eqType R: rel T x: T
foralls : seq T, supremum s = Some x -> x \in s
T: eqType R: rel T x, a: T l: seq T IN_TAIL: supremum l = Some x -> x \in l IN: supremum (a :: l) = Some x
x \in a :: l
T: eqType R: rel T x, a: T l: seq T IN_TAIL: supremum l = Some x -> x \in l IN: supremum (a :: l) = Some x
x == a \/ x \in l
T: eqType R: rel T x, a: T l: seq T IN_TAIL: supremum l = Some x -> x \in l
choose_superior a (supremum l) = Some x ->
x == a \/ x \in l
T: eqType R: rel T x, a: T l: seq T s: T IN_TAIL: Some s = Some x -> x \in l
(if R a s then Some a else Some s) = Some x ->
x == a \/ x \in l
T: eqType R: rel T x, a: T l: seq T IN_TAIL: None = Some x -> x \in l
Some a = Some x -> x == a \/ x \in l
T: eqType R: rel T x, a: T l: seq T s: T IN_TAIL: Some s = Some x -> x \in l
(if R a s then Some a else Some s) = Some x ->
x == a \/ x \in l
T: eqType R: rel T x, a: T l: seq T s: T IN_TAIL: Some s = Some x -> x \in l EQ: Some a = Some x
x == a \/ x \in l
T: eqType R: rel T x, a: T l: seq T s: T IN_TAIL: Some s = Some x -> x \in l EQ: Some s = Some x
x == a \/ x \in l
T: eqType R: rel T x, a: T l: seq T s: T IN_TAIL: Some s = Some x -> x \in l EQ: Some a = Some x
x == a \/ x \in l
T: eqType R: rel T x, a: T l: seq T s: T IN_TAIL: Some s = Some x -> x \in l EQ: Some s = Some x
x == a \/ x \in l
T: eqType R: rel T x, a: T l: seq T s: T IN_TAIL: Some s = Some x -> x \in l EQ: Some a = Some x
x = a
T: eqType R: rel T x, a: T l: seq T s: T IN_TAIL: Some s = Some x -> x \in l EQ: Some s = Some x
x == a \/ x \in l
T: eqType R: rel T x, a: T l: seq T s: T IN_TAIL: Some s = Some x -> x \in l EQ: Some s = Some x
x == a \/ x \in l
T: eqType R: rel T x, a: T l: seq T s: T IN_TAIL: Some s = Some x -> x \in l EQ: Some s = Some x
x == a \/ x \in l
right; byapply IN_TAIL.
T: eqType R: rel T x, a: T l: seq T IN_TAIL: None = Some x -> x \in l
Some a = Some x -> x == a \/ x \in l
T: eqType R: rel T x, a: T l: seq T IN_TAIL: None = Some x -> x \in l
Some a = Some x -> x == a \/ x \in l
T: eqType R: rel T x, a: T l: seq T IN_TAIL: None = Some x -> x \in l IN: Some a = Some x
x == a
T: eqType R: rel T x, a: T l: seq T IN_TAIL: None = Some x -> x \in l IN: Some a = Some x
x = a
byinjection IN.}Qed.(** To prove that [supremum] indeed computes the given sequence's supremum, we need to make additional assumptions on [R]. *)(** (1) [R] is reflexive. *)HypothesisH_R_reflexive: reflexive R.(** (2) [R] is total. *)HypothesisH_R_total: total R.(** (3) [R] is transitive. *)HypothesisH_R_transitive: transitive R.(** Based on these assumptions, we show that the function [supremum] indeed computes an upper bound on all elements in the given sequence. *)
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R
forall (x : T) (s : seq T),
supremum s = Some x -> forally : T, y \in s -> R x y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R
forall (x : T) (s : seq T),
supremum s = Some x -> forally : T, y \in s -> R x y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R x: T s: seq T SOME_x: supremum s = Some x
forally : T, y \in s -> R x y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s: seq T
forallx : T,
supremum s = Some x ->
x \in s -> forally : T, y \in s -> R x y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R
forall (a : T) (l : seq T),
(forallx : T,
supremum l = Some x ->
x \in l -> forally : T, y \in l -> R x y) ->
forallx : T,
supremum (a :: l) = Some x ->
x \in a :: l -> forally : T, y \in a :: l -> R x y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T IH: forallx : T,
supremum sn = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T SOME_z: supremum (s1 :: sn) = Some z IN_z_s: z \in s1 :: sn y: T
y \in s1 :: sn -> R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T IH: forallx : T,
supremum sn = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T
supremum (s1 :: sn) = Some z ->
y \in s1 :: sn -> R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T IH: forallx : T,
supremum sn = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: match supremum sn with
| Some y =>
if R s1 y then Some s1 else Some y
| None => Some s1
end = Some z
y \in s1 :: sn -> R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T SUPR: supremum sn = None IH: forallx : T,
None = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: Some s1 = Some z
y \in s1 :: sn -> R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z
y \in s1 :: sn -> R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T SUPR: supremum sn = None IH: forallx : T,
None = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: Some s1 = Some z
y \in s1 :: sn -> R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T IH: forallx : T,
None = Some x ->
x \in [::] -> forally : T, y \in [::] -> R x y z: T IN_z_s: z \in [:: s1] y: T SOME_z: Some s1 = Some z
y \in [:: s1] -> R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T IH: forallx : T,
None = Some x ->
x \in [::] -> forally : T, y \in [::] -> R x y z: T IN_z_s: z \in [:: s1] y: T SOME_z: Some s1 = Some z
R z s1
byinjection SOME_z => ->.
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z
y \in s1 :: sn -> R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z
y \in s1 :: sn -> R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z INy: y \in sn
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z EQy: y = s1
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z INy: y \in sn
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z EQy: y = s1
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z INy: y \in sn R_by: R b y
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z EQy: y = s1
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z INy: y \in sn
R z b
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z EQy: y = s1
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z EQy: y = s1
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z: T IN_z_s: z \in s1 :: sn y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z EQy: y = s1
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z, y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z EQy: y = s1 INz: z \in sn
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z, y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z EQy: y = s1 INz: z \in sn R_s1b: R s1 b
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z, y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z EQy: y = s1 INz: z \in sn R_bs1: R b s1
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z, y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z EQy: y = s1 INz: z \in sn R_s1b: R s1 b
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z, y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z EQy: y = s1 INz: z \in sn R_bs1: R b s1
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z, y: T EQy: y = s1 INz: z \in sn R_s1b: R s1 b
(if R s1 b then Some s1 else Some b) = Some z -> R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z, y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z EQy: y = s1 INz: z \in sn R_bs1: R b s1
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z, y: T EQy: y = s1 INz: z \in sn R_s1b: R s1 b SOME_z: Some s1 = Some z
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z, y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z EQy: y = s1 INz: z \in sn R_bs1: R b s1
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z, y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z EQy: y = s1 INz: z \in sn R_bs1: R b s1
R z y
T: eqType R: rel T H_R_reflexive: reflexive (T:=T) R H_R_total: total (T:=T) R H_R_transitive: transitive (T:=T) R s1: T sn: seq T b: T SUPR: supremum sn = Some b IH: forallx : T,
Some b = Some x ->
x \in sn -> forally : T, y \in sn -> R x y z, y: T SOME_z: (if R s1 b then Some s1 else Some b) = Some z EQy: y = s1 INz: z \in sn R_bs1: R b s1