(* * 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.

(* To conclude, either the maximum is euqal to the start value (and s is a strict upper bound), or the maximum is actually in the list *)
Corollary max_list_rec_In (xs : list nat) (s : nat) :
(max_list_rec s xs = s /\ forall x, In x xs -> x < s) \/
In (max_list_rec s xs) xs.