From Undecidability.L Require Export Util.L_facts.
From Undecidability.L.Tactics Require Export LTactics GenEncode.
From Undecidability.L Require Import Datatypes.LBool Functions.EqBool Datatypes.LProd.
(* ** Encoding of natural numbers *)
MetaCoq Run (tmGenEncode "nat_enc" nat).
Hint Resolve nat_enc_correct : Lrewrite.
Instance termT_S : computableTime' S (fun _ _ => (1,tt)).
Instance eqbNat_inst : eqbClass Nat.eqb.
Instance eqbComp_nat : eqbCompT nat.
(*Defined.*)
Definition c__min1 := 5.
Definition c__min2 := 15.
Definition min_time x y := (min x y + 1) * c__min2.
Instance termT_nat_min : computableTime' Nat.min (fun x _ => (c__min1, fun y _ => (min_time x y, tt))).
Proof with try solve [Coq.Init.Tactics.easy].
revert n. eapply (size_induction (f := size) (p := (fun t => forall n, nat_unenc t = Some n -> nat_enc n = t))). clear t. intros t IHt n H.
destruct t as [ | | t]. easy. easy.
destruct t as [ | | t]. easy. easy.
destruct t. 3:easy.
-destruct n0. easy. destruct n0. 2:easy. inv H. easy.
-destruct t1. 2-3:easy. destruct n0. 2:easy. simpl in H. destruct (nat_unenc t2) eqn:A.
+apply IHt in A;simpl;try lia. destruct n. inv H. simpl. congruence.
+congruence.
Qed.

Lemma dec_enc t : dec (exists n, t = nat_enc n).