|
| 1 | +(* SPDX-License-Identifier: MPL-2.0 *) |
| 2 | +(* SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell *) |
| 3 | + |
| 4 | +(** * Counterexample — [preservation_l1] is FALSE as stated. |
| 5 | +
|
| 6 | + (Experiment 3b of the choreographic series — the completion of |
| 7 | + [Counterexample_StepPop.v]. Regression witness in the tradition of |
| 8 | + [Counterexample.v], which did the same for the LEGACY preservation.) |
| 9 | +
|
| 10 | + The Admitted capstone [preservation_l1] ([Semantics_L1.v]) claims: |
| 11 | +
|
| 12 | + step (mu,R,e) (mu',R',e') -> |
| 13 | + has_type_l1 m R G e T R_final G' -> |
| 14 | + has_type_l1 m R' G e' T R_final G'. |
| 15 | +
|
| 16 | + This file exhibits a configuration that types (in BOTH modalities), |
| 17 | + steps, and whose post-state is UNTYPABLE at the same indices — [Qed], |
| 18 | + zero axioms. Together with [Counterexample_StepPop.v]: BOTH remaining |
| 19 | + L1 Admitted markers were hiding falsehoods, not unfinished proofs. |
| 20 | +
|
| 21 | + ** The witness (value-anchored — closes the StepPop file's open door) |
| 22 | +
|
| 23 | + e = EStringConcat (ELoc 0 rv) |
| 24 | + (ESnd (EPair (ERegion rv (EI32 0)) (EVar 0))) |
| 25 | + R = [rv] G = [(TString rv, false)] T = TString rv |
| 26 | +
|
| 27 | + - The LEFT operand is an [ELoc] VALUE. Its one typing rule |
| 28 | + [T_Loc_L1] demands [In rv R] — satisfied pre-step ([R = [rv]]). |
| 29 | + - The RIGHT operand evaluates [ERegion rv (EI32 0)] under |
| 30 | + [ESnd (EPair _ (EVar 0))]; the pair's second component supplies |
| 31 | + the [TString rv] the concat needs, typed by [T_Var_Lin_L1] at the |
| 32 | + already-popped env (no [In rv R] premise). |
| 33 | + - Stepping: [S_StringConcat_Step2] -> [S_Snd_Step] -> [S_Pair_Step1] |
| 34 | + -> [S_Region_Exit] pops the ONLY [rv]: [R' = []]. |
| 35 | + - Post-state: the anchor [ELoc 0 rv] must retype at [R' = []], and |
| 36 | + [T_Loc_L1] demands [In rv []] — no derivation exists |
| 37 | + ([wit2_post_untypable], by double inversion). |
| 38 | +
|
| 39 | + [Counterexample_StepPop.v] suggested a value-anchored RESTRICTION of |
| 40 | + step_pop "may be provable" because its refuting sibling was a |
| 41 | + variable. This witness closes that door: the dangling dependence |
| 42 | + here IS a value ([ELoc]), living one congruence away from the popped |
| 43 | + region. The hole is not variable-typing alone; it is that the |
| 44 | + snapshot judgment lets ONE operand's evaluation consume an ambient |
| 45 | + region a SIBLING's value-typing depends on — region-liveness- |
| 46 | + through-reduction, the one invariant behind all four historical L1 |
| 47 | + admit faces (per the 2026-06 audit), now [Qed]-fatal to the capstone |
| 48 | + as stated. |
| 49 | +
|
| 50 | + ** What this forces (experiment 3 verdict, completed) |
| 51 | +
|
| 52 | + The L1 redesign closed the LEGACY counterexample ([Counterexample.v] |
| 53 | + still proves [bad_input_untypable_l1]: that configuration is |
| 54 | + REJECTED at typing). This file shows the post-L2-hybrid judgment |
| 55 | + still admits a configuration in the same semantic class through a |
| 56 | + different door. Preservation for L1 is NOT provable by more lemmas; |
| 57 | + it requires the judgment to carry the missing temporal invariant: |
| 58 | +
|
| 59 | + - either typing-level: region-liveness / trace-coherence as a |
| 60 | + judgment input (the choreographic-foundational route — now |
| 61 | + provably MANDATORY, not merely preferred), per |
| 62 | + [L1ChoreoExperiment2.v]'s model + [L1-ELIMINATOR-FORK.md] §3-§7; |
| 63 | + - or rule-level: strengthen the leaves ([T_Var_*_L1], and the |
| 64 | + interplay of [T_Loc_L1] with sibling threading) so the witness |
| 65 | + is rejected at typing, and re-derive — the A'/path-3 family, |
| 66 | + whose earlier failure analyses should be revisited IN LIGHT OF |
| 67 | + this witness (the failure probes predate it). |
| 68 | +
|
| 69 | + Direction choice is the owner's (PRESERVATION-DESIGN.md is the |
| 70 | + canonical place for the decision record). Fences respected: this |
| 71 | + file only ADDS a witness; [Semantics_L1.v] is untouched and its |
| 72 | + Admitted markers stand until the reformulation is ratified. *) |
| 73 | + |
| 74 | +Require Import Coq.Lists.List. |
| 75 | +Import ListNotations. |
| 76 | +Require Import Coq.Strings.String. |
| 77 | +Open Scope string_scope. |
| 78 | + |
| 79 | +From Ephapax Require Import Syntax. |
| 80 | +From Ephapax Require Import Modality. |
| 81 | +From Ephapax Require Import Typing. |
| 82 | +From Ephapax Require Import TypingL1. |
| 83 | +From Ephapax Require Import Semantics. |
| 84 | +From Ephapax Require Import Semantics_L1. |
| 85 | + |
| 86 | +Definition rv : region_name := "rv". |
| 87 | +Definition anchor : expr := ELoc 0 rv. |
| 88 | +Definition popper : expr := ESnd (EPair (ERegion rv (EI32 0)) (EVar 0)). |
| 89 | +Definition wit2 : expr := EStringConcat anchor popper. |
| 90 | +Definition wit2_G : ctx := [(TString rv, false)]. |
| 91 | + |
| 92 | +(** Pre-state types — in BOTH modalities: both operands [TString rv], |
| 93 | + region env threading [rv] -> []. *) |
| 94 | +Lemma wit2_types : forall m, |
| 95 | + has_type_l1 m [rv] wit2_G wit2 (TString rv) [] (ctx_mark_used wit2_G 0). |
| 96 | +Proof. |
| 97 | + intro m. |
| 98 | + unfold wit2, anchor, popper. |
| 99 | + eapply T_StringConcat_L1 with (R1 := [rv]). |
| 100 | + - apply T_Loc_L1. simpl; auto. |
| 101 | + - eapply T_Snd_L1 with (T1 := TBase TI32). |
| 102 | + + eapply T_Pair_L1 with (R1 := remove_first_L1 rv [rv]). |
| 103 | + * eapply T_Region_Active_L1. |
| 104 | + -- simpl; auto. |
| 105 | + -- simpl. intro Hin. exact Hin. |
| 106 | + -- simpl; auto. |
| 107 | + -- apply T_I32_L1. |
| 108 | + * simpl. eapply T_Var_Lin_L1; reflexivity. |
| 109 | + + reflexivity. |
| 110 | +Qed. |
| 111 | + |
| 112 | +(** The step: concat's Step2 congruence -> snd congruence -> pair |
| 113 | + congruence -> region exit. [R] goes [[rv]] -> [[]]. *) |
| 114 | +Lemma wit2_steps : forall mu, |
| 115 | + step (mu, [rv], wit2) |
| 116 | + (mem_free_region mu rv, [], |
| 117 | + EStringConcat anchor (ESnd (EPair (EI32 0) (EVar 0)))). |
| 118 | +Proof. |
| 119 | + intro mu. |
| 120 | + unfold wit2, anchor, popper. |
| 121 | + replace ([] : region_env) with (remove_first rv [rv]). |
| 122 | + 2: { simpl. destruct (string_dec rv rv); [reflexivity | congruence]. } |
| 123 | + apply S_StringConcat_Step2; [constructor|]. |
| 124 | + apply S_Snd_Step. |
| 125 | + apply S_Pair_Step1. |
| 126 | + apply S_Region_Exit. |
| 127 | + - constructor. |
| 128 | + - simpl. left. reflexivity. |
| 129 | + - simpl. exact I. |
| 130 | +Qed. |
| 131 | + |
| 132 | +(** Post-state is UNTYPABLE at the same indices: the anchor [ELoc]'s |
| 133 | + only rule demands [In rv []]. *) |
| 134 | +Lemma wit2_post_untypable : |
| 135 | + ~ has_type_l1 Linear [] wit2_G |
| 136 | + (EStringConcat anchor (ESnd (EPair (EI32 0) (EVar 0)))) |
| 137 | + (TString rv) [] (ctx_mark_used wit2_G 0). |
| 138 | +Proof. |
| 139 | + intro H. |
| 140 | + inversion H; subst. |
| 141 | + match goal with |
| 142 | + | Ha : has_type_l1 _ [] _ anchor _ _ _ |- _ => |
| 143 | + inversion Ha; subst |
| 144 | + end. |
| 145 | + match goal with |
| 146 | + | Hin : In rv [] |- _ => exact Hin |
| 147 | + end. |
| 148 | +Qed. |
| 149 | + |
| 150 | +(** ** THE REFUTATION *) |
| 151 | +Theorem preservation_l1_FALSE : |
| 152 | + ~ (forall m mu R e mu' R' e', |
| 153 | + step (mu, R, e) (mu', R', e') -> |
| 154 | + forall G T R_final G', |
| 155 | + has_type_l1 m R G e T R_final G' -> |
| 156 | + has_type_l1 m R' G e' T R_final G'). |
| 157 | +Proof. |
| 158 | + intro H. |
| 159 | + apply wit2_post_untypable. |
| 160 | + eapply (H Linear [] [rv] wit2). |
| 161 | + - apply wit2_steps. |
| 162 | + - apply wit2_types. |
| 163 | +Qed. |
| 164 | + |
| 165 | +Print Assumptions preservation_l1_FALSE. |
0 commit comments