From Undecidability.L Require Import L Tactics.LTactics.
From Undecidability.L.AbstractMachines Require Import FlatPro.Programs.
From Undecidability.L Require Import Tactics.GenEncode.

From Undecidability.L.Datatypes Require Import LNat.

Run TemplateProgram (tmGenEncode "token_enc" Tok).
Hint Resolve token_enc_correct : Lrewrite.

Instance term_varT : computableTime' varT (fun _ _ => (1,tt)).
extract constructor. solverec.
Qed.

Lemma size_Tok_enc_r t: sizeT t <= size (enc t).
Proof.
  destruct t;cbn. 2-4:now cbv.
  unfold enc;cbn. now rewrite <- LNat.size_nat_enc_r.
Qed.

Lemma size_Tok_enc t: size (enc t) =
                        match t with
                        | varT n => 4*n+13
                        | appT => 7
                        | lamT => 6
                        | retT => 5
                        end.
Proof.
  change (enc t) with (token_enc t).
  destruct t;cbn. rewrite size_nat_enc. all:ring_simplify. all:easy.
Qed.