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

(* If the list is not empty, and every element in the list is greater than start-values [s1] and [s2], then the choice of start-value [s1] or [s2] doesn't matter *)
Lemma max_list_rec_irrelevant (xs : list nat) (s1 s2 : nat) :
xs <> nil ->
(forall x, In x xs -> s1 <= x /\ s2 <= x) ->
max_list_rec s1 xs = max_list_rec s2 xs.