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. *) Section SelectSupremum. (** Consider any type of elements with decidable equality... *) Context {T : eqType}. (** ...and any given relation [R]. *) Variable R : 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. *) Definition choose_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]. *) Definition supremum (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. *)
T: eqType
R: rel T

forall (head : T) (tail : seq T), supremum (head :: tail) = choose_superior head (supremum tail)
T: eqType
R: rel T

forall (head : T) (tail : seq T), supremum (head :: tail) = choose_superior head (supremum tail)
T: eqType
R: rel T
head: T
tail: seq T

supremum (head :: tail) = choose_superior head (supremum tail)
by rewrite [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
by destruct (R a s). Qed. (** Conversely, if [supremum] finds nothing, then the list is empty. *)
T: eqType
R: rel T

forall s : seq T, supremum s = None -> s = [::]
T: eqType
R: rel T

forall s : 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 = [::]
by destruct (supremum l) as [s|]; try destruct (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

forall s : 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; by apply 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
by injection 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. *) Hypothesis H_R_reflexive: reflexive R. (** (2) [R] is total. *) Hypothesis H_R_total: total R. (** (3) [R] is transitive. *) Hypothesis H_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 -> forall y : 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 -> forall y : 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

forall y : 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

forall x : T, supremum s = Some x -> x \in s -> forall y : 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), (forall x : T, supremum l = Some x -> x \in l -> forall y : T, y \in l -> R x y) -> forall x : T, supremum (a :: l) = Some x -> x \in a :: l -> forall y : 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: forall x : T, supremum sn = Some x -> x \in sn -> forall y : 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: forall x : T, supremum sn = Some x -> x \in sn -> forall y : 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: forall x : T, supremum sn = Some x -> x \in sn -> forall y : 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: forall x : T, None = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, None = Some x -> x \in sn -> forall y : 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: forall x : T, None = Some x -> x \in [::] -> forall y : 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: forall x : T, None = Some x -> x \in [::] -> forall y : 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
by injection 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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: forall x : T, Some b = Some x -> x \in sn -> forall y : 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
by destruct (R s1 b); injection SOME_z => EQ; subst. } Qed. End SelectSupremum.