(**************************************************************)
(*   Copyright Dominique Larchey-Wendling [*]                 *)
(*                                                            *)
(*                             [*] Affiliation LORIA -- CNRS  *)
(**************************************************************)
(*      This file is distributed under the terms of the       *)
(*         CeCILL v2 FREE SOFTWARE LICENSE AGREEMENT          *)
(**************************************************************)
(* ** Reification for bounded quantification *)
Set Implicit Arguments.
(* A nat indexed finite number of conjunctions *)
Definition fmap_reifier_t X (Q : nat -> X -> Prop) k :
(forall i, i < k -> sig (Q i))
-> { f : forall i, i < k -> X | forall i Hi, Q i (f i Hi) }.
Proof with try lia.
intros [ u ].
revert P; induction n as [ | n IHn ]; intros P HP.
+ exists (fun _ => u); intros...
+ destruct (IHn (fun i => P (S i))) as (f & Hf).
{ intros; apply HP... }
destruct (HP 0) as (x & Hx)...
exists (fun i => match i with 0 => x | S i => f i end).
intros [|] ?; auto; apply Hf...
Qed.

Theorem fmap_reifer_bound n P :
(forall x, x < n -> ex (P x))
-> exists m f, forall x, x < n -> f x < m /\ P x (f x).