From Undecidability.Shared.Libs.PSL Require Import FinTypes Base.
From Undecidability.Shared.Libs.PSL Require Import Bijection.
(* Require Import Vector. *)
(* Definition vector X Y := Vector.t Y (|elem X|). *)
Definition finfunc_table (A : finType) (B: Type) (f: A -> B) :=
List.map (fun x => (x, f x)) (elem A).
(* Now we prove that the tranformation of a function of finite domain to a table is correct *)
Definition lookup (A : eqType) (B : Type) (l : list (A * B)) (a : A) (def : B) : B :=
match (filter (fun p => Dec (fst p = a)) l) with
List.nil => def
| p :: _ => snd p
end.
(* Now we can prove that the transformation of the function table into another type is correct as long as the conversion is injective *)

Lemma finfunc_conv (A: finType) (cA : eqType) (B cB : Type) (f: A -> B) (mA : A -> cA) (mB : B -> cB) a def:
injective mA -> lookup (List.map (fun x => (mA (fst x), mB (snd x))) (finfunc_table f))  (mA a) def = mB (f a).