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.
Definition c__natsizeO := 4.
Definition c__natsizeS := 4.

Lemma size_nat_enc (n:nat) :
size (enc n) = n * c__natsizeS + c__natsizeO.