From Undecidability.L Require Import Tactics.LTactics Functions.Encoding Prelim.LoopSum Functions.LoopSum Functions.UnboundIteration.
From Undecidability.L.Datatypes Require Import Lists.
(* ** Extracted size of terms *)
Instance term_size' : computable size'.
Definition sizeTR' '(stack,res) : (list term * nat) + nat :=
match stack with
[] => inr res
| s::stack =>
match s with
var n => inl (stack,S (n + res))
| app s t => inl (s::t::stack,S res)
| lam s => inl (s::stack,S res)
end
end.
Fixpoint sizeTR'_fuel (s:term) : nat :=
match s with
var _ => 1
| app s t => 1 + (sizeTR'_fuel s + sizeTR'_fuel t)
| lam s => 1 + sizeTR'_fuel s
end.

Lemma sizeTR_correct s:
loopSum (sizeTR'_fuel s + 1) sizeTR' ([s],0) = Some (size s).