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 stack res s k:
loopSum (sizeTR'_fuel s + k) sizeTR' (s::stack,res)
= loopSum k sizeTR' (stack,size s + res).