(* * Maximum element in a list *)
From Undecidability Require Export TM.Util.Prelim TM.Util.ArithPrelim.
(* ** Basic lemmas about upper bounds *)
(* ** Tail Recursive Definition *)
(* Compute the maximum of a list and a start-value tail-recursively *)
Fixpoint max_list_rec (s : nat) (xs : list nat) { struct xs } : nat :=
match xs with
| nil => s
| x :: xs' => max_list_rec (max x s) xs'
end.

(* [max_list_rec] is a lower bound of [z], if every element is smaller than [z]. *)
Lemma max_list_rec_lower_bound (xs : list nat) (s : nat) (z : nat) :
s <= z ->
(forall x, In x xs -> x <= z) ->
max_list_rec s xs <= z.