You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Phase 3a (#224) shipped the retype half of Phase 3 per formal/SUBST-LEMMA-GENERALIZATION-DESIGN.md — is_tfuneff_ty predicate and tfuneff_lambda_retype_l1_m lemma. The substitution-lemma extension was descoped from #224 after structural analysis.
This issue tracks Phase 3b: extend subst_typing_gen_l1_m (or a sibling lemma subst_typing_gen_l1_m_tfuneff_lambda) to cover T1 = TFunEff … lambda substituends, so that Phase 4 can close preservation_l2's T_App_L2_Eff β-case for the TFunEff non-linear T1 case.
The obstacle
Every compound case in subst_typing_gen_l1_m_ground_nonlinear (Phase 2) relies on the retype lemma being fully R-polymorphic (no side condition). For TFunEff lambda values, the retype lemma carries a side condition forall r, In r R' → In r R_in_arg, where R_in_arg is fixed by the value's type TFunEff T1 T2 R_in_arg R_out_arg.
The substitution lemma's compound cases need to retype the substituted value vv at threaded R values R_n arising inside the substitution target e. T_Region_L1 firings inside e introduce fresh regions r ∉ R_outer — and freshness wrt the threaded R does not imply r ∈ R_in_arg.
Concretely: in T_Region_L1's body, the new R is r' :: R_outer where r' is fresh wrt R_outer. To retype vv at r' :: R_outer, we need r' ∈ R_in_arg, but r' is fresh in a way that's unconstrained relative to R_in_arg.
Three candidate solutions
(a) Syntactic side condition on e
Add a Definition regions_introduced_by : expr → list region_name and require forall r, In r (regions_introduced_by e) → In r R_in_arg as a precondition. Each compound case threads the predicate to its sub-expressions (region-introductions in a parent expression contain those of all sub-expressions). T_Region_L1 case discharges r' ∈ R_in_arg directly from the side condition.
Pros: clean to state, syntactically computable. Cons: propagating the predicate through ~28 cases is mechanical churn.
(b) Universal-R Hv_type with per-case side-condition discharge
Replace the simple Hv_type premise with a universal-R version:
(forall R_any,
(forall r, In r R_any → In r R_in_arg) →
has_type_l1 m R_any (remove_at k Gin) vv Tsub R_any (remove_at k Gin))
Each compound case picks the R it needs and discharges the side condition.
Pros: no new Definitions. Cons: still doesn't help in T_Region_L1 (the new R contains a fresh region not necessarily in R_in_arg).
(c) Restrict to region-free terms
Add expr_strictly_free_of_region predicates for the introduced regions. Effectively restricts the lemma to terms without T_Region_L1 firings.
Pros: simple. Cons: very restrictive; may not cover the actual Phase 4 use shape.
Recommendation
Prototype Phase 4 closure of preservation_l2's T_App_L2_Eff β-case first. The actual shape of subst 0 varg ebody (where ebody is vlam's body, typed at R_in_big not R_in_arg) will reveal whether T_Region_L1 firings inside ebody are a real obstacle or an edge case.
If the Phase 4 use shape only ever needs the substitution lemma for ebody with bounded R-flow, option (a) is appropriate. If T_Region_L1 inside ebody is generic, options (a)+(b) compose.
References
formal/SUBST-LEMMA-GENERALIZATION-DESIGN.md — original Phase 3 design.
formal/Semantics_L1.v — subst_typing_gen_l1_m_ground_nonlinear (Phase 2 template) at line 1752.
Context
Phase 3a (#224) shipped the retype half of Phase 3 per
formal/SUBST-LEMMA-GENERALIZATION-DESIGN.md—is_tfuneff_typredicate andtfuneff_lambda_retype_l1_mlemma. The substitution-lemma extension was descoped from #224 after structural analysis.This issue tracks Phase 3b: extend
subst_typing_gen_l1_m(or a sibling lemmasubst_typing_gen_l1_m_tfuneff_lambda) to coverT1 = TFunEff …lambda substituends, so that Phase 4 can closepreservation_l2'sT_App_L2_Effβ-case for the TFunEff non-linear T1 case.The obstacle
Every compound case in
subst_typing_gen_l1_m_ground_nonlinear(Phase 2) relies on the retype lemma being fully R-polymorphic (no side condition). For TFunEff lambda values, the retype lemma carries a side conditionforall r, In r R' → In r R_in_arg, whereR_in_argis fixed by the value's typeTFunEff T1 T2 R_in_arg R_out_arg.The substitution lemma's compound cases need to retype the substituted value
vvat threaded R valuesR_narising inside the substitution targete.T_Region_L1firings insideeintroduce fresh regionsr ∉ R_outer— and freshness wrt the threaded R does not implyr ∈ R_in_arg.Concretely: in
T_Region_L1's body, the new R isr' :: R_outerwherer'is fresh wrt R_outer. To retypevvatr' :: R_outer, we needr' ∈ R_in_arg, butr'is fresh in a way that's unconstrained relative toR_in_arg.Three candidate solutions
(a) Syntactic side condition on
eAdd a Definition
regions_introduced_by : expr → list region_nameand requireforall r, In r (regions_introduced_by e) → In r R_in_argas a precondition. Each compound case threads the predicate to its sub-expressions (region-introductions in a parent expression contain those of all sub-expressions). T_Region_L1 case dischargesr' ∈ R_in_argdirectly from the side condition.Pros: clean to state, syntactically computable.
Cons: propagating the predicate through ~28 cases is mechanical churn.
(b) Universal-R Hv_type with per-case side-condition discharge
Replace the simple
Hv_typepremise with a universal-R version:Each compound case picks the R it needs and discharges the side condition.
Pros: no new Definitions.
Cons: still doesn't help in T_Region_L1 (the new R contains a fresh region not necessarily in R_in_arg).
(c) Restrict to region-free terms
Add
expr_strictly_free_of_regionpredicates for the introduced regions. Effectively restricts the lemma to terms withoutT_Region_L1firings.Pros: simple.
Cons: very restrictive; may not cover the actual Phase 4 use shape.
Recommendation
Prototype Phase 4 closure of
preservation_l2'sT_App_L2_Effβ-case first. The actual shape ofsubst 0 varg ebody(whereebodyisvlam's body, typed atR_in_bignotR_in_arg) will reveal whether T_Region_L1 firings insideebodyare a real obstacle or an edge case.If the Phase 4 use shape only ever needs the substitution lemma for
ebodywith bounded R-flow, option (a) is appropriate. If T_Region_L1 insideebodyis generic, options (a)+(b) compose.References
formal/SUBST-LEMMA-GENERALIZATION-DESIGN.md— original Phase 3 design.formal/Semantics_L1.v—subst_typing_gen_l1_m_ground_nonlinear(Phase 2 template) at line 1752.formal/Semantics_L1.v—tfuneff_lambda_retype_l1_m(Phase 3a, feat(L1): Phase D slice 4 Phase 3a —tfuneff_lambda_retype_l1_m+is_tfuneff_ty#224)..machine_readable/6a2/STATE.a2ml—next_actiondocuments the three candidates.