Structural recursion on binary-tree data is primitive recursive
ProvedMIPRE.Cost.Data.primrec_recDThe data of the ambient cost model are binary trees Data, generated by nil and cons. The type Data is in bijection with through Cantor pairing: and (with Mathlib's Nat.pair), which makes Data a Primcodable type in the sense of Mathlib's computability library. Structural recursion on trees is the operator
Let be a primcodable type with a default element, let , and let be primitive recursive as a function of the quadruple, i.e. the map on satisfies Mathlib's Primrec. Then
This is the recursion principle through which the first-order functions on Data used by the formalization are shown primitive recursive: the reading of unary numerals (unaryToNat), the decoding of lists and hence of bit strings (primrec_decode_bitStr), and the step function of the evaluation machine. In the import closure of the recursive compression lemma it is what lets the halting-problem forms of the two compression lemmas (recursive_compression_halting, compressibility_criterion_halting) decode the output of the polynomial-time reduction into a Mathlib-Computable function on Nat.Partrec.Code.
Formalization Note. MIPRE.Cost.Data.recD is the recursor restricted to first-order results; the hypothesis hstep is Primrec of the uncurried step on (Data × Data) × σ × σ, and σ needs [Primcodable σ] [Inhabited σ] (the default element is used for out-of-range list lookups in the proof). The Primcodable Data instance is the one derived from Data.equivNat (Denumerable Data); it is deliberately distinct from the size-faithful SizedEncoding of the cost model, which encodes into Data itself, and it is used only at this interface with Mathlib's computability.
import Mathlib.Algebra.Polynomial.Eval.Defs import Mathlib.Computability.Primrec.List import Mathlib.Data.List.Basic import Mathlib.Data.Nat.Bits import Mathlib.Data.Nat.Notation import Mathlib.Data.Nat.Size import Mathlib.Logic.Denumerable import Definitions.Def_MIPRE_Foundations_Cost_Basic import Definitions.Def_MIPRE_Foundations_Cost_Encoding import Definitions.Def_MIPRE_Foundations_Cost_PolyTime import Definitions.Def_MIPRE_Foundations_Cost_Closure import Definitions.Def_MIPRE_Foundations_Cost_Loops import Definitions.Def_MIPRE_Foundations_Cost_Codable open MIPRE open MIPRE.Cost open MIPRE.Cost.Data
theorem MIPRE.Cost.Data.primrec_recD {σ : Type*} [Primcodable σ] [Inhabited σ] (base : σ)
(step : Data → Data → σ → σ → σ)
(hstep : Primrec fun p : (Data × Data) × σ × σ => step p.1.1 p.1.2 p.2.1 p.2.2) :
Primrec (recD base step) := by sorry