(************************************************************************)
(*         *   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.
Definition ordered_Rlist (l:Rlist) : Prop :=
forall i:nat, (i < pred (Rlength l))%nat -> pos_Rl l i <= pos_Rl l (S i).
Fixpoint insert (l:Rlist) (x:R) : Rlist :=
match l with
| nil => cons x nil
| cons a l' =>
match Rle_dec a x with
| left _ => cons a (insert l' x)
| right _ => cons x l
end
end.
Fixpoint cons_Rlist (l k:Rlist) : Rlist :=
match l with
| nil => k
| cons a l' => cons a (cons_Rlist l' k)
end.
Fixpoint cons_ORlist (k l:Rlist) : Rlist :=
match k with
| nil => l
| cons a k' => cons_ORlist k' (insert l a)
end.
Fixpoint app_Rlist (l:Rlist) (f:R -> R) : Rlist :=
match l with
| nil => nil
| cons a l' => cons (f a) (app_Rlist l' f)
end.
Fixpoint mid_Rlist (l:Rlist) (x:R) : Rlist :=
match l with
| nil => nil
| cons a l' => cons ((x + a) / 2) (mid_Rlist l' a)
end.
Definition Rtail (l:Rlist) : Rlist :=
match l with
| nil => nil
| cons a l' => l'
end.
Definition FF (l:Rlist) (f:R -> R) : Rlist :=
match l with
| nil => nil
| cons a l' => app_Rlist (mid_Rlist l' a) f
end.

Lemma RList_P6 :
forall l:Rlist,
ordered_Rlist l <->
(forall i j:nat,
(i <= j)%nat -> (j < Rlength l)%nat -> pos_Rl l i <= pos_Rl l j).