From Undecidability.Shared.Libs.PSL Require Import Vectors.
From Undecidability.L Require Import L LTactics L_facts Functions.Eval Functions.Decoding Functions.Encoding.
From Undecidability.L.Datatypes Require Import LBool Lists LVector List.List_fold.
From Undecidability.L.Complexity.LinDecode Require Import LTDbool LTDlist LTDnat.
From Undecidability.TM.L.CompilerBoolFuns Require Import Compiler_spec NaryApp ClosedLAdmissible Compiler_facts.
(* Section Fix_X. Variable (X:Type). Context {intX : registered X}.  Global Instance term_repeat: computable (@repeat X). Proof using intX. extract. Qed.  Global Instance term_length: computable (@length X). Proof using intX. extract. Qed.  End Fix_X. *)
Fixpoint gen_list {k} {X} {Hr : registered X} (v : Vector.t nat k) : term :=
match v with
| [] => ext (@nil X)
| n :: v => ext (@Datatypes.cons X) (var n) (@gen_list _ X Hr v)
end.
Definition validate (l : list (list bool)) := forallb (forallb (fun x => x)) l.
Definition idbool := (fun x : bool => x).
Definition forallb' := @forallb bool.
Definition alltrue x :=  idbool x.
Definition forallb'' := @forallb (list bool).
Local Instance term_forallb' : computable forallb' | 0.
Local Instance term_forallb'' : computable forallb'' | 0.
Instance term_idbool : computable idbool.
Instance term_alltrue : computable alltrue.
Remove Hints term_forallb : typeclass_instances.
Instance term_validate : computable validate.

Lemma L_computable_to_L_bool_computable k (R : Vector.t nat k -> nat -> Prop) :
L_computable R -> L_bool_computable (fun v m => exists v' m', v = Vector.map (List.repeat true) v' /\ m = List.repeat true m' /\ R v' m').