(************************************************************************)
(*         *   The Coq Proof Assistant / The Coq Development Team       *)
(*  v      *   INRIA, CNRS and contributors - Copyright 1999-2018       *)
(* <O___,, *       (see CREDITS file for the list of authors)           *)
(*   \VV/  **************************************************************)
(*    //   *    This file is distributed under the terms of the         *)
(*         *     GNU Lesser General Public License Version 2.1          *)
(*         *     (see LICENSE file for the text of the license)         *)
(************************************************************************)
Local Open Scope R_scope.
Inductive Rlist : Type :=
| nil : Rlist
| cons : R -> Rlist -> Rlist.
Fixpoint In (x:R) (l:Rlist) : Prop :=
match l with
| nil => False
| cons a l' => x = a \/ In x l'
end.
Fixpoint Rlength (l:Rlist) : nat :=
match l with
| nil => 0%nat
| cons a l' => S (Rlength l')
end.
Fixpoint MaxRlist (l:Rlist) : R :=
match l with
| nil => 0
| cons a l1 =>
match l1 with
| nil => a
| cons a' l2 => Rmax a (MaxRlist l1)
end
end.
Fixpoint MinRlist (l:Rlist) : R :=
match l with
| nil => 1
| cons a l1 =>
match l1 with
| nil => a
| cons a' l2 => Rmin a (MinRlist l1)
end
end.
Fixpoint AbsList (l:Rlist) (x:R) : Rlist :=
match l with
| nil => nil
| cons a l' => cons (Rabs (a - x) / 2) (AbsList l' x)
end.
Fixpoint pos_Rl (l:Rlist) (i:nat) : R :=
match l with
| nil => 0
| cons a l' => match i with
| O => a
| S i' => pos_Rl l' i'
end
end.

Lemma Rlist_P1 :
forall (l:Rlist) (P:R -> R -> Prop),
(forall x:R, In x l ->  exists y : R, P x y) ->
exists l' : Rlist,
Rlength l = Rlength l' /\
(forall i:nat, (i < Rlength l)%nat -> P (pos_Rl l i) (pos_Rl l' i)).