The Array container rule and relational foldl transfer #
ParamData.lean lifts Param through ×/Option/List. This module adds the
Array container — the carrier leanprover/hex's computational cores use for
O(1) dense access — and the relational foldl transfer that makes
Array- (or List-) carried folds transfer generically.
Why this is the recursion story #
ParamTransfer's term-level ⟦·⟧ stops at recursors, so a recursive algorithm is
not translated inline. CoqEAL's answer — and this module's — is that recursion is
factored through a small set of combinators, each transferred once. foldlR
is that lemma for the fold combinator: given a step that respects the element and
accumulator relations, a fold over related containers yields related results, at
heterogeneous element and accumulator types (the general parametricity of
foldl, not the encoding-only HigherOrderTransfer.foldl_transfer). Every
structural/bounded algorithm expressed as a fold — HexBareiss, HexRowReduce,
HexGramSchmidt, HexDeterminant — inherits transfer from this one lemma, without
touching the recursor frontier. forIn/do-loops desugar to a fold and ride it
too; the monadic case is Integrations/ParamTripleTransfer's RComp.
What is ported #
R_array PA— the pointwise lift to arrays,List.Forall₂ PA.RontoList(reusing theR_listmachinery), with themap0/map1/map2aforward records andparamArray : Param .map1 .map0 (Array A) (Array A'), mirroringparamList.foldlR_list/foldlR_array— the relational fold transfer. TheArrayversion reduces to theListversion throughArray.foldl_toList.
R_array: two arrays are related when their underlying lists are pointwise
related by the element relation. Reuses List.Forall₂, exactly as R_list
does — the Array rule is the List rule read through Array.toList.
Equations
- Transfer.Param.R_array PA a a' = List.Forall₂ PA.R a.toList a'.toList
Instances For
Map0_array: no structure.
Equations
Instances For
Map1_array: lift the element forward map through Array.map.
Instances For
Map2a_array: the lifted map's graph is included in R_array, reducing to
the List graph-inclusion (Map2a_list) through Array.toList_map.
Instances For
paramArray: from an element relation at forward-map2a, backward-map0,
the annotated relation on Array, forward-map1, backward-map0. The
Array analogue of paramList.
Equations
Instances For
Relational foldl transfer — the combinator lemma #
The parametricity of foldl at heterogeneous element (A/A') and accumulator
(β/β') types: a step respecting both relations sends related seeds and related
containers to related results. This is the atom every fold-shaped algorithm
transfers through.
Relational List.foldl transfer. If the step f/f' maps
Rβ-related accumulators and PA-related elements to Rβ-related
accumulators, then folding over List.Forall₂ PA-related lists from
Rβ-related seeds yields Rβ-related results. The general parametricity of
foldl (heterogeneous carriers), by induction on the Forall₂ derivation
with the accumulators generalized.
Relational Array.foldl transfer. The Array combinator lemma, reduced
to foldlR_list through Array.foldl_toList. A fold over R_array-related
arrays from related seeds yields related results — so any Array-carried
fold of a step that respects the refinement transfers, no recursion
translation needed.
Demos #
The diagonal element input for the Array rule (forward-map2a,
backward-map0), the shape paramArray consumes.