{"canonical":{"contextual-embeddings.claim-isomorphism":[51,32141,32220]},"families":[{"id":"first-order-representation","name":"First-order representation","named":true,"part":0,"topics":["types-contexts","de-bruijn-indices","first-order-terms"]},{"id":"contextual-representation","name":"Contextual representation","named":true,"part":0,"topics":["singleton-variables","context-extension","contextual-terms"]},{"id":"conversion","name":"Conversion between representations","named":true,"part":0,"topics":["contextualisation","unembedding","variable-conversion"]},{"id":"isomorphism","name":"Isomorphism and its assumptions","named":true,"part":0,"topics":["term-round-trips","index-round-trips","closed-world-assumption"]}],"layer":"phrases","meaning":"Each tie is a pointer that landed. Whether the paper and the Lean say the same thing is a reading.","parts":[{"end_byte":107029,"name":"","start_byte":0}],"passages":[[18575,44131,["contextual-embeddings.claim-isomorphism"],"sec-3"]],"segments":[[12602,12649,[0]],[12716,12808,[1]],[12936,12986,[2]],[13602,13628,[3]],[13629,13658,[4]],[13699,13724,[5]],[13727,13773,[6]],[13829,13859,[7]],[13862,13919,[8]],[13922,13991,[9]],[13994,14014,[10]],[14160,14232,[11]],[20579,20660,[12]],[20673,20749,[13]],[20755,20881,[14]],[23424,23511,[15]],[23524,23594,[16]],[23726,23771,[17]],[23851,23874,[18]],[23880,24010,[19]],[24011,24056,[20]],[24216,24255,[21]],[25330,25427,[22]],[26672,26732,[23]],[26735,26815,[24]],[26818,26879,[25]],[26882,26906,[26]],[26912,27111,[27]],[28660,28692,[28]],[28693,28740,[29]],[28741,28795,[30]],[28796,28816,[31]],[28876,28908,[32]],[28964,29045,[33]],[29046,29072,[34]],[29197,29298,[35]],[29412,29570,[36]],[29976,30052,[37]],[30104,30146,[38]],[30778,30855,[39]],[30868,30945,[40]],[31096,31158,[41]],[31207,31229,[42]],[31286,31336,[43]],[31337,31381,[44]],[31442,31472,[45]],[31478,31603,[46]],[31604,31663,[47]],[31804,31942,[48]],[32019,32045,[49]],[32099,32127,[50]],[32141,32220,[51]],[32377,32472,[52]],[32540,32617,[53]],[32618,32695,[54]],[32739,32798,[55]],[32799,32856,[56]],[32857,32986,[57]],[32988,33129,[58]],[33653,33789,[59]],[33790,33918,[60]],[33919,34055,[61]],[34133,34181,[62]],[34185,34234,[63]],[34241,34304,[64]],[43696,43857,[65]]],"ties":[{"anchor":"sec-2","at":"b12602-12649","from_record":false,"lean":true,"lines":[1,4],"module":"CE","name":"Ty","origin":"ai","part":0,"phrase":"ty","plain":"Unit and function types","record":null,"relation":"defines","role":"definition","rows":[{"end_line":4,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition gives exactly the guest types named here: Unit and function types, with no additional base types.","fidelity_source":"ai","line":1,"lines":[1,4],"module":"CE","name":"Ty","note":"","plain":"Unit and function types","relation":"defines","annotation":"Here “guest” means the calculus being represented. For example, `Ty.Fun Ty.Unit Ty.Unit` is a piece of guest type syntax. An embedded identity term can have that guest type while its Lean type also records the context in which it is valid."}],"tone":0,"topic":"types-contexts"},{"anchor":"sec-2","at":"b12716-12808","from_record":false,"lean":true,"lines":[10,13],"module":"CE","name":"Ctx","origin":"ai","part":0,"phrase":"ctx","plain":"Contexts as snoc lists","record":null,"relation":"defines","role":"definition","rows":[{"end_line":13,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition gives the empty context and extension by one type at the right, matching the paper’s snoc lists.","fidelity_source":"ai","line":10,"lines":[10,13],"module":"CE","name":"Ctx","note":"","plain":"Contexts as snoc lists","relation":"defines","annotation":"“Snoc” appends on the right. In `Ctx.Empty :/: a :/: b`, the rightmost entry $b$ is the newest binding. The same ordering lets an index recover the binding position by counting past entries from the right."}],"tone":0,"topic":"types-contexts"},{"anchor":"sec-2","at":"b12936-12986","from_record":false,"lean":true,"lines":[17,20],"module":"CE","name":"Index","origin":"ai","part":0,"phrase":"index","plain":"Typed de Bruijn indices","record":null,"relation":"defines","role":"definition","rows":[{"end_line":20,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition represents typed de Bruijn indices: Top selects the newest variable, and Pop crosses one later context entry while preserving the selected variable’s type.","fidelity_source":"ai","line":17,"lines":[17,20],"module":"CE","name":"Index","note":"","plain":"Typed de Bruijn indices","relation":"defines","annotation":"Read `Index ts t` as a position in the list `ts` whose entry has type `t`. In the context $[a,b]$, the newest position has type $b$, and one step back reaches type $a$. Even when $a=b$, those positions denote different variables."}],"tone":1,"topic":"de-bruijn-indices"},{"anchor":"sec-2","at":"b13602-13628","from_record":false,"lean":true,"lines":[1,4],"module":"CE","name":"Ty","origin":"ai","part":0,"phrase":"code-ty","plain":"Unit and function types","record":null,"relation":"states","role":"statement","rows":[{"end_line":4,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition has exactly the two alternatives shown in the code: the unit type and a function type formed from two guest types.","fidelity_source":"ai","line":1,"lines":[1,4],"module":"CE","name":"Ty","note":"","plain":"Unit and function types","relation":"states","annotation":"The two occurrences of `Ty` in the Haskell function alternative become the two arguments of Lean's `Ty.Fun`. The notation `:->` associates to the right, so `a :-> b :-> c` means a function taking an $a$ and returning a function from $b$ to $c$."}],"tone":0,"topic":"types-contexts"},{"anchor":"sec-2","at":"b13629-13658","from_record":false,"lean":true,"lines":[10,13],"module":"CE","name":"Ctx","origin":"ai","part":0,"phrase":"code-ctx","plain":"Contexts as snoc lists","record":null,"relation":"states","role":"statement","rows":[{"end_line":13,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition has exactly the empty context and right extension by one guest type, matching the two alternatives shown here.","fidelity_source":"ai","line":10,"lines":[10,13],"module":"CE","name":"Ctx","note":"","plain":"Contexts as snoc lists","relation":"states","annotation":"In Lean, `ts :/: t` is notation for `Ctx.Snoc ts t`. Its first argument is the entire earlier context. Thus `(ts :/: a) :/: b` records two binders in order, with $a$ introduced before $b$."}],"tone":0,"topic":"types-contexts"},{"anchor":"sec-2","at":"b13699-13724","from_record":false,"lean":true,"lines":[17,20],"module":"CE","name":"Index","origin":"ai","part":0,"phrase":"code-top","plain":"Typed de Bruijn indices","record":null,"relation":"states","role":"statement","rows":[{"end_line":20,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal Top constructor selects a variable of type $t$ from a context ending in $t$, matching this constructor signature.","fidelity_source":"ai","line":17,"lines":[17,20],"module":"CE","name":"Index","note":"","plain":"Typed de Bruijn indices","relation":"states","annotation":"The return type of `Index.Top` repeats `t` as the last context entry and the selected type. This is how Lean checks that the newest variable really has the requested type. There is no `Index.Top` in the empty context."}],"tone":1,"topic":"de-bruijn-indices"},{"anchor":"sec-2","at":"b13727-13773","from_record":false,"lean":true,"lines":[17,20],"module":"CE","name":"Index","origin":"ai","part":0,"phrase":"code-pop","plain":"Typed de Bruijn indices","record":null,"relation":"states","role":"statement","rows":[{"end_line":20,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal Pop constructor preserves a variable’s type while extending its context by an arbitrary later type, matching this constructor signature.","fidelity_source":"ai","line":17,"lines":[17,20],"module":"CE","name":"Index","note":"","plain":"Typed de Bruijn indices","relation":"states","annotation":"The input selects an occurrence of `t` in `ts`. After appending `t'`, the same occurrence is one position farther from the end, so `Index.Pop` changes only the context index. The types `t` and `t'` may coincide."}],"tone":1,"topic":"de-bruijn-indices"},{"anchor":"sec-2","at":"b13829-13859","from_record":false,"lean":true,"lines":[24,29],"module":"CE","name":"STLC","origin":"ai","part":0,"phrase":"code-var","plain":"Simply typed terms with de Bruijn indices","record":null,"relation":"states","role":"statement","rows":[{"end_line":29,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal variable constructor turns a typed de Bruijn index into a first-order term with the same context and guest type.","fidelity_source":"ai","line":24,"lines":[24,29],"module":"CE","name":"STLC","note":"","plain":"Simply typed terms with de Bruijn indices","relation":"states","annotation":"A de Bruijn index supplies the evidence for the variable typing rule: it already identifies a place with the requested type. `STLC.Var` turns that evidence into a term with the same indices, so the constructor requires no separate context lookup."}],"tone":2,"topic":"first-order-terms"},{"anchor":"sec-2","at":"b13862-13919","from_record":false,"lean":true,"lines":[24,29],"module":"CE","name":"STLC","origin":"ai","part":0,"phrase":"code-lam","plain":"Simply typed terms with de Bruijn indices","record":null,"relation":"states","role":"statement","rows":[{"end_line":29,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal abstraction constructor turns a body of type $t_2$ in a context extended by $t_1$ into a function of type $t_1\\to t_2$ in the original context.","fidelity_source":"ai","line":24,"lines":[24,29],"module":"CE","name":"STLC","note":"","plain":"Simply typed terms with de Bruijn indices","relation":"states","annotation":"The paper's `Lam` is `STLC.Lambda` in Lean. The body may refer to the new rightmost entry of type `t1`. The outer term binds that entry and has type `t1 :-> t2` in the original context."}],"tone":2,"topic":"first-order-terms"},{"anchor":"sec-2","at":"b13922-13991","from_record":false,"lean":true,"lines":[24,29],"module":"CE","name":"STLC","origin":"ai","part":0,"phrase":"code-app","plain":"Simply typed terms with de Bruijn indices","record":null,"relation":"states","role":"statement","rows":[{"end_line":29,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal application constructor combines a function of type $t_1\\to t_2$ with an argument of type $t_1$ in the same context, producing a term of type $t_2$.","fidelity_source":"ai","line":24,"lines":[24,29],"module":"CE","name":"STLC","note":"","plain":"Simply typed terms with de Bruijn indices","relation":"states","annotation":"Lean calls the constructor `STLC.Apply`. The first argument's domain and the second argument's type are the same `t1`, while both terms share `ts`. The constructor can therefore eliminate the arrow without changing which free variables are in scope."}],"tone":2,"topic":"first-order-terms"},{"anchor":"sec-2","at":"b13994-14014","from_record":false,"lean":true,"lines":[24,29],"module":"CE","name":"STLC","origin":"ai","part":0,"phrase":"code-star","plain":"Simply typed terms with de Bruijn indices","record":null,"relation":"states","role":"statement","rows":[{"end_line":29,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal unit constructor gives a term of type Unit in any context, matching the paper’s Star constructor.","fidelity_source":"ai","line":24,"lines":[24,29],"module":"CE","name":"STLC","note":"","plain":"Simply typed terms with de Bruijn indices","relation":"states","annotation":"The unit term `STLC.Star` requires no index lookup. Its context is arbitrary, so the same constructor can supply a closed term in the empty context or a body that ignores a newly bound variable."}],"tone":2,"topic":"first-order-terms"},{"anchor":"sec-2","at":"b14160-14232","from_record":false,"lean":true,"lines":[24,29],"module":"CE","name":"STLC","origin":"ai","part":0,"phrase":"stlc","plain":"Simply typed terms with de Bruijn indices","record":null,"relation":"part","role":"explanation","rows":[{"end_line":29,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition is the simply typed lambda calculus with variables, abstraction, application and the unit term; every term has the context and type prescribed by the paper.","fidelity_source":"ai","line":24,"lines":[24,29],"module":"CE","name":"STLC","note":"","plain":"Simply typed terms with de Bruijn indices","relation":"part","annotation":"A first-order abstraction stores a syntax tree for its body. For $\\lambda x.\\lambda y.x$, that tree ends in `STLC.Var (Index.Pop Index.Top)`. The two lambda constructors determine the context in which this occurrence is checked."}],"tone":2,"topic":"first-order-terms"},{"anchor":"sec-3","at":"b20579-20660","from_record":false,"lean":true,"lines":[33,35],"module":"CE","name":"ProxyTop","origin":"ai","part":0,"phrase":"proxytop","plain":"Proxy for the most recently bound variable","record":null,"relation":"part","role":"explanation","rows":[{"end_line":35,"exact_lines":false,"fidelity":"different","fidelity_note":"The passage claims exclusion of exotic terms; the formal definition supplies a singleton marker for the newest variable. This removes the illustrated choice between Top and Pop, but the declaration itself states no general theorem about all contextual terms.","fidelity_source":"ai","line":33,"lines":[33,35],"module":"CE","name":"ProxyTop","note":"","plain":"Proxy for the most recently bound variable","relation":"part","annotation":"The `exotic` example inspects an index to choose a different body in the `Index.Top` and `Index.Pop` cases. Frohlich, Foster, Kavvos and Wang give the host function a marker with only the `ProxyTop.PTop` constructor, so there is no older-variable case on which it can branch.","annotation_references":[{"start":4,"end":12,"key":"example:exotic"}]}],"tone":3,"topic":"singleton-variables"},{"anchor":"sec-3","at":"b20673-20749","from_record":false,"lean":true,"lines":[33,35],"module":"CE","name":"ProxyTop","origin":"ai","part":0,"phrase":"code-proxytop","plain":"Proxy for the most recently bound variable","record":null,"relation":"states","role":"statement","rows":[{"end_line":35,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition has one marker for the last entry of a nonempty context, and that entry determines the marker’s guest type, matching the displayed definition.","fidelity_source":"ai","line":33,"lines":[33,35],"module":"CE","name":"ProxyTop","note":"","plain":"Proxy for the most recently bound variable","relation":"states","annotation":"The Haskell constructor has the same name as its type. Lean uses `ProxyTop.PTop`. Its result type records the entire context at binding and requires its last entry to have the marked variable's type."}],"tone":3,"topic":"singleton-variables"},{"anchor":"sec-3","at":"b20755-20881","from_record":false,"lean":true,"lines":[33,35],"module":"CE","name":"ProxyTop","origin":"ai","part":0,"phrase":"proxytop-only-top","plain":"Proxy for the most recently bound variable","record":null,"relation":"part","role":"explanation","rows":[{"end_line":35,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition has one constructor, available only when the context ends in the selected variable’s type; it offers no operation for selecting an earlier variable.","fidelity_source":"ai","line":33,"lines":[33,35],"module":"CE","name":"ProxyTop","note":"","plain":"Proxy for the most recently bound variable","relation":"part","annotation":"In a two-binder context $[a,b]$, a marker for the new variable has type `ProxyTop (Ctx.Empty :/: a :/: b) b`. The marker for the earlier variable keeps its original context $[a]$. To use it under the second binder, the construction needs a `ReifyIndex` instance that turns the saved marker into an index in the larger context.","annotation_references":[{"start":240,"end":252,"key":"definition:reifyindex"}]}],"tone":3,"topic":"singleton-variables"},{"anchor":"sec-3","at":"b23424-23511","from_record":false,"lean":true,"lines":[38,39],"module":"CE","name":"ReifyIndex","origin":"ai","part":0,"phrase":"reify-class","plain":"Reifying a binder proxy as an index in its use context","record":null,"relation":"defines","role":"definition","rows":[{"end_line":39,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition supplies reify from a saved top-variable marker in the binding context to a typed index in the use context, as described in the paper.","fidelity_source":"ai","line":38,"lines":[38,39],"module":"CE","name":"ReifyIndex","note":"","plain":"Reifying a binder proxy as an index in its use context","relation":"defines","annotation":"The earlier `ExtE` version passed evidence of context extension explicitly. Here `ReifyIndex` is a type class that supplies the conversion as a field. A variable occurrence can ask instance search to fill that argument using its binding and use contexts.","annotation_references":[{"start":12,"end":18,"key":"definition:exte"}]}],"tone":4,"topic":"context-extension"},{"anchor":"sec-3","at":"b23524-23594","from_record":false,"lean":true,"lines":[38,39],"module":"CE","name":"ReifyIndex","origin":"ai","part":0,"phrase":"code-reify-class","plain":"Reifying a binder proxy as an index in its use context","record":null,"relation":"states","role":"statement","rows":[{"end_line":39,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition gives reify for any guest type, taking a top-variable marker in the binding context to an index of that same type in the use context.","fidelity_source":"ai","line":38,"lines":[38,39],"module":"CE","name":"ReifyIndex","note":"","plain":"Reifying a binder proxy as an index in its use context","relation":"states","annotation":"Read `ReifyIndex ts ts'` with the binding context first and the use context second. The same field `ReifyIndex.reify` works for any marked type `t`. That type is preserved even if all the entries appended after binding have other types."}],"tone":4,"topic":"context-extension"},{"anchor":"sec-3","at":"b23726-23771","from_record":false,"lean":true,"lines":[42,44],"module":"CE","name":"instReifyIndexRefl","origin":"ai","part":0,"phrase":"code-refl","plain":"The newest binder has index zero in its binding context","record":null,"relation":"states","role":"statement","rows":[{"end_line":44,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal identity-context reification sends the unique top-variable marker to Top, exactly as in the displayed equation.","fidelity_source":"ai","line":42,"lines":[42,44],"module":"CE","name":"instReifyIndexRefl","note":"","plain":"The newest binder has index zero in its binding context","relation":"states","annotation":"With no new entries between binding and use, the unique marker still points to the newest variable. The Lean match on `ProxyTop.PTop` exposes the final type of that context and makes `Index.Top` type check."}],"tone":4,"topic":"context-extension"},{"anchor":"sec-3","at":"b23851-23874","from_record":false,"lean":true,"lines":[46,47],"module":"CE","name":"instReifyIndexSnoc","origin":"ai","part":0,"phrase":"code-snoc","plain":"Appending a binder adds one to the de Bruijn index","record":null,"relation":"states","role":"statement","rows":[{"end_line":47,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal instance has the same equation: reifying into the extended context applies Pop to the reification into the smaller context. The Haskell instance also states the context shape as a separate equality constraint, which the formal instance places in its head instead.","fidelity_source":"ai","line":46,"lines":[46,47],"module":"CE","name":"instReifyIndexSnoc","note":"","plain":"Appending a binder adds one to the de Bruijn index","relation":"states","annotation":"The inner call converts the marker into an index in the shorter use context. The outer `Index.Pop` moves that index past the added entry. Lean expresses the shorter context in the instance head. Haskell obtains it from the equality constraint."}],"tone":4,"topic":"context-extension"},{"anchor":"sec-3","at":"b23880-24010","from_record":false,"lean":true,"lines":[42,44],"module":"CE","name":"instReifyIndexRefl","origin":"ai","part":0,"phrase":"instance-refl","plain":"The newest binder has index zero in its binding context","record":null,"relation":"part","role":"explanation","rows":[{"end_line":44,"exact_lines":false,"fidelity":"same","fidelity_note":"For equal binding and use contexts, the formal definition sends the saved top-variable marker to Top, exactly as the passage describes.","fidelity_source":"ai","line":42,"lines":[42,44],"module":"CE","name":"instReifyIndexRefl","note":"","plain":"The newest binder has index zero in its binding context","relation":"part","annotation":"Here reflexive means the two complete context lists are equal. The selected type may also occur earlier in the list, but this instance uses the binding site's most recent entry, which is still the most recent at use."}],"tone":4,"topic":"context-extension"},{"anchor":"sec-3","at":"b24011-24056","from_record":false,"lean":true,"lines":[46,47],"module":"CE","name":"instReifyIndexSnoc","origin":"ai","part":0,"phrase":"instance-step","plain":"Appending a binder adds one to the de Bruijn index","record":null,"relation":"part","role":"explanation","rows":[{"end_line":47,"exact_lines":false,"fidelity":"same","fidelity_note":"Given reification into a context, the formal definition reifies into that context extended by one type by adding one Pop to the result.","fidelity_source":"ai","line":46,"lines":[46,47],"module":"CE","name":"instReifyIndexSnoc","note":"","plain":"Appending a binder adds one to the de Bruijn index","relation":"part","annotation":"Each recursive call removes one entry from the right of the use context and leaves the binding context fixed. On return it adds one `Index.Pop`, so the value produced by reification records exactly the steps taken by instance search."}],"tone":4,"topic":"context-extension"},{"anchor":"sec-3","at":"b24216-24255","from_record":false,"lean":true,"lines":[46,47],"module":"CE","name":"instReifyIndexSnoc","origin":"ai","part":0,"phrase":"snoc-pop","plain":"Appending a binder adds one to the de Bruijn index","record":null,"relation":"part","role":"explanation","rows":[{"end_line":47,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal instance turns a conversion into one context into a conversion into that context extended by one type, adding one Pop to its result. Each extension of the context therefore contributes one Pop.","fidelity_source":"ai","line":46,"lines":[46,47],"module":"CE","name":"instReifyIndexSnoc","note":"","plain":"Appending a binder adds one to the de Bruijn index","relation":"part","annotation":"For a variable saved in $[a]$ and used in $[a,b,c]$, the two extension instances remove $c$ and $b$ before reaching the reflexive case. Their reification returns `Index.Pop (Index.Pop Index.Top)`."}],"tone":4,"topic":"context-extension"},{"anchor":"sec-3","at":"b25330-25427","from_record":false,"lean":true,"lines":[46,47],"module":"CE","name":"instReifyIndexSnoc","origin":"ai","part":0,"phrase":"defer-snoc","plain":"Appending a binder adds one to the de Bruijn index","record":null,"relation":"states","role":"mention","rows":[{"end_line":47,"exact_lines":false,"fidelity":"different","fidelity_note":"The paper postpones the context-shape equality until after Haskell selects the recursive instance. The formal definition instead places the extended context directly in the instance head, so it does not implement that selection strategy.","fidelity_source":"ai","line":46,"lines":[46,47],"module":"CE","name":"instReifyIndexSnoc","note":"","plain":"Appending a binder adds one to the de Bruijn index","relation":"states","annotation":"In the Haskell example the recursive head is general enough to match equal contexts too. The more specific reflexive head wins there. When the recursive head wins, the equality constraint checks the final snoc shape. Lean puts that shape in the head of `instReifyIndexSnoc` itself."}],"tone":4,"topic":"context-extension"},{"anchor":"sec-3","at":"b26672-26732","from_record":false,"lean":true,"lines":[49,53],"module":"CE","name":"STLCCtx","origin":"ai","part":0,"phrase":"code-cvar","plain":"Simply typed terms with contextual variables","record":null,"relation":"states","role":"statement","rows":[{"end_line":53,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal contextual-variable constructor combines a saved marker with reification from its binding context into its use context, preserving the guest type.","fidelity_source":"ai","line":49,"lines":[49,53],"module":"CE","name":"STLCCtx","note":"","plain":"Simply typed terms with contextual variables","relation":"states","annotation":"The result of `STLCCtx.CVar` shows the use context `ts'`. The marker can come from a different context `ts`, which the constructor keeps with the instance. Thus an occurrence of $x$ beneath a later binder has the larger context even though its saved marker has the smaller one."}],"tone":5,"topic":"contextual-terms"},{"anchor":"sec-3","at":"b26735-26815","from_record":false,"lean":true,"lines":[49,53],"module":"CE","name":"STLCCtx","origin":"ai","part":0,"phrase":"code-clam","plain":"Simply typed terms with contextual variables","record":null,"relation":"states","role":"statement","rows":[{"end_line":53,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal contextual-abstraction constructor receives a function from the newest variable’s marker to a body in the extended context, yielding a function term in the original context.","fidelity_source":"ai","line":49,"lines":[49,53],"module":"CE","name":"STLCCtx","note":"","plain":"Simply typed terms with contextual variables","relation":"states","annotation":"Both the marker argument and the result of the host function refer to the extended context `ts :/: a`. The function can name the new variable through its argument, and its result is a guest body of type `b`. The outer constructor binds that variable."}],"tone":5,"topic":"contextual-terms"},{"anchor":"sec-3","at":"b26818-26879","from_record":false,"lean":true,"lines":[49,53],"module":"CE","name":"STLCCtx","origin":"ai","part":0,"phrase":"code-capp","plain":"Simply typed terms with contextual variables","record":null,"relation":"states","role":"statement","rows":[{"end_line":53,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal contextual-application constructor applies a contextual function to an argument in the same context and returns the function’s result type.","fidelity_source":"ai","line":49,"lines":[49,53],"module":"CE","name":"STLCCtx","note":"","plain":"Simply typed terms with contextual variables","relation":"states","annotation":"Function and argument are both written at use context `ts`, so they can be combined directly. Either subterm can contain variables from earlier binding sites. Those variables carry their own reification inside their `STLCCtx.CVar` constructors."}],"tone":5,"topic":"contextual-terms"},{"anchor":"sec-3","at":"b26882-26906","from_record":false,"lean":true,"lines":[49,53],"module":"CE","name":"STLCCtx","origin":"ai","part":0,"phrase":"code-cstar","plain":"Simply typed terms with contextual variables","record":null,"relation":"states","role":"statement","rows":[{"end_line":53,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal contextual unit constructor produces a term of type Unit in any context, matching CStar.","fidelity_source":"ai","line":49,"lines":[49,53],"module":"CE","name":"STLCCtx","note":"","plain":"Simply typed terms with contextual variables","relation":"states","annotation":"A unit term uses no variable. `STLCCtx.CStar` therefore leaves the context arbitrary and takes no marker or reification instance, even if it appears inside a host function that binds a variable."}],"tone":5,"topic":"contextual-terms"},{"anchor":"sec-3","at":"b26912-27111","from_record":false,"lean":true,"lines":[49,53],"module":"CE","name":"STLCCtx","origin":"ai","part":0,"phrase":"contextual-embedding","plain":"Simply typed terms with contextual variables","record":null,"relation":"part","role":"explanation","rows":[{"end_line":53,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition gives contextual terms whose abstractions receive a singleton marker for the binding context and whose variables carry reification into their use context, matching the described construction.","fidelity_source":"ai","line":49,"lines":[49,53],"module":"CE","name":"STLCCtx","note":"","plain":"Simply typed terms with contextual variables","relation":"part","annotation":"For $\\lambda x.\\lambda y.x$, the host binder names $x$ while its marker keeps the context at the first lambda. The occurrence beneath the second lambda needs one extension instance. Unembedding will read that instance to recover the single `Index.Pop` in the first-order `tt` example.","annotation_references":[{"start":271,"end":275,"key":"example:tt-first-order"}]}],"tone":5,"topic":"contextual-terms"},{"anchor":"sec-3","at":"b28660-28692","from_record":false,"lean":true,"lines":[60,64],"module":"CE","name":"unembed","origin":"ai","part":0,"phrase":"fig2-cvar","plain":"Contextual terms to first-order terms","record":null,"relation":"states","role":"statement","rows":[{"end_line":64,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal conversion of a contextual variable reifies its saved marker and uses that index as the first-order variable, exactly as in this equation.","fidelity_source":"ai","line":60,"lines":[60,64],"module":"CE","name":"unembed","note":"","plain":"Contextual terms to first-order terms","relation":"states","annotation":"The instance is part of the matched `STLCCtx.CVar`. Applying its reification to the marker gives an index at the occurrence's context, which is what `STLC.Var` expects. The binding context can disappear from the result."}],"tone":7,"topic":"unembedding"},{"anchor":"sec-3","at":"b28693-28740","from_record":false,"lean":true,"lines":[60,64],"module":"CE","name":"unembed","origin":"ai","part":0,"phrase":"fig2-clam","plain":"Contextual terms to first-order terms","record":null,"relation":"states","role":"statement","rows":[{"end_line":64,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal conversion of an abstraction supplies the unique top-variable marker to its body, recursively unembeds the result, and forms a first-order abstraction.","fidelity_source":"ai","line":60,"lines":[60,64],"module":"CE","name":"unembed","note":"","plain":"Contextual terms to first-order terms","relation":"states","annotation":"Apply the stored host function to `ProxyTop.PTop` to obtain its body in the extended context. Unembedding that body gives the input needed by `STLC.Lambda`, whose result binds the new entry and lives in the original context."}],"tone":7,"topic":"unembedding"},{"anchor":"sec-3","at":"b28741-28795","from_record":false,"lean":true,"lines":[60,64],"module":"CE","name":"unembed","origin":"ai","part":0,"phrase":"fig2-capp","plain":"Contextual terms to first-order terms","record":null,"relation":"states","role":"statement","rows":[{"end_line":64,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal conversion of an application recursively unembeds its function and argument, then forms the corresponding first-order application.","fidelity_source":"ai","line":60,"lines":[60,64],"module":"CE","name":"unembed","note":"","plain":"Contextual terms to first-order terms","relation":"states","annotation":"The recursive calls preserve each operand's context and guest type. The translated function is still an arrow from the translated argument's type, so `STLC.Apply` type checks with the two recursive results."}],"tone":7,"topic":"unembedding"},{"anchor":"sec-3","at":"b28796-28816","from_record":false,"lean":true,"lines":[60,64],"module":"CE","name":"unembed","origin":"ai","part":0,"phrase":"fig2-cstar","plain":"Contextual terms to first-order terms","record":null,"relation":"states","role":"statement","rows":[{"end_line":64,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal conversion sends the contextual unit term to the first-order unit term, exactly as in this equation.","fidelity_source":"ai","line":60,"lines":[60,64],"module":"CE","name":"unembed","note":"","plain":"Contextual terms to first-order terms","relation":"states","annotation":"This branch changes the syntax constructor from `STLCCtx.CStar` to `STLC.Star`. Since `unembed` preserves the context and unit type here, the branch closes by the constructor equation when proving the round trip."}],"tone":7,"topic":"unembedding"},{"anchor":"sec-3","at":"b28876-28908","from_record":false,"lean":true,"lines":[90,94],"module":"CE","name":"contextualise","origin":"ai","part":0,"phrase":"fig2-var","plain":"First-order terms to contextual terms","record":null,"relation":"states","role":"statement","rows":[{"end_line":94,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal conversion sends a first-order variable to the contextual variable obtained by converting its de Bruijn index.","fidelity_source":"ai","line":90,"lines":[90,94],"module":"CE","name":"contextualise","note":"","plain":"First-order terms to contextual terms","relation":"states","annotation":"The variable still has its de Bruijn position when this branch runs. `toCVar` turns each skipped entry into a reification step and the final top position into a marker, recovering exactly the information the contextual constructor needs.","annotation_references":[{"start":69,"end":77,"key":"definition:tocvar"}]}],"tone":6,"topic":"contextualisation"},{"anchor":"sec-3","at":"b28964-29045","from_record":false,"lean":true,"lines":[90,94],"module":"CE","name":"contextualise","origin":"ai","part":0,"phrase":"fig2-app","plain":"First-order terms to contextual terms","record":null,"relation":"states","role":"statement","rows":[{"end_line":94,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal conversion recursively contextualises the function and argument of an application and then forms their contextual application.","fidelity_source":"ai","line":90,"lines":[90,94],"module":"CE","name":"contextualise","note":"","plain":"First-order terms to contextual terms","relation":"states","annotation":"This branch translates the operator and operand independently. Each recursive result retains its original guest type and the same outer context, so no extra bookkeeping is needed at the application node."}],"tone":6,"topic":"contextualisation"},{"anchor":"sec-3","at":"b29046-29072","from_record":false,"lean":true,"lines":[90,94],"module":"CE","name":"contextualise","origin":"ai","part":0,"phrase":"fig2-star","plain":"First-order terms to contextual terms","record":null,"relation":"states","role":"statement","rows":[{"end_line":94,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal conversion sends the first-order unit term to the contextual unit term, exactly as in this equation.","fidelity_source":"ai","line":90,"lines":[90,94],"module":"CE","name":"contextualise","note":"","plain":"First-order terms to contextual terms","relation":"states","annotation":"The result can be `STLCCtx.CStar` immediately because the input supplies no variable information. In the round trip the two unit branches compose to the identity by reducing their definitions."}],"tone":6,"topic":"contextualisation"},{"anchor":"sec-3","at":"b29197-29298","from_record":false,"lean":true,"lines":[60,64],"module":"CE","name":"unembed","origin":"ai","part":0,"phrase":"unembed","plain":"Contextual terms to first-order terms","record":null,"relation":"states","role":"mention","rows":[{"end_line":64,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition translates every contextual term to a first-order term with the same context and guest type. This is the type-safe conversion claimed here; its existence does not require the closed world assumption.","fidelity_source":"ai","line":60,"lines":[60,64],"module":"CE","name":"unembed","note":"","plain":"Contextual terms to first-order terms","relation":"states","annotation":"Both sides of the `unembed` signature in Figure 2 use the same `ts` and `t`. For instance, an open contextual term can be translated without assigning values to its free variables. The types ensure this preservation even for a custom reification instance. Recovering that same instance on a round trip requires more.","annotation_references":[{"start":18,"end":27,"key":"figure:2"}]}],"tone":7,"topic":"unembedding"},{"anchor":"sec-3","at":"b29412-29570","from_record":false,"lean":true,"lines":[60,64],"module":"CE","name":"unembed","origin":"ai","part":0,"phrase":"cvar-case","plain":"Contextual terms to first-order terms","record":null,"relation":"part","role":"explanation","rows":[{"end_line":64,"exact_lines":false,"fidelity":"same","fidelity_note":"For a contextual variable, the formal definition applies its stored reification to its saved marker and constructs a first-order variable from the resulting index.","fidelity_source":"ai","line":60,"lines":[60,64],"module":"CE","name":"unembed","note":"","plain":"Contextual terms to first-order terms","relation":"part","annotation":"For an occurrence of the outer variable under one more lambda, the saved instance contains one extension of reflexive reification. The variable clause applies it to the marker to get `Index.Pop Index.Top` and then wraps that index in `STLC.Var`."}],"tone":7,"topic":"unembedding"},{"anchor":"sec-3","at":"b29976-30052","from_record":false,"lean":true,"lines":[90,94],"module":"CE","name":"contextualise","origin":"ai","part":0,"phrase":"contextualise","plain":"First-order terms to contextual terms","record":null,"relation":"part","role":"explanation","rows":[{"end_line":94,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition translates each first-order term to a contextual term in the same context and of the same guest type, case by case as in Fig. 2. That the two translations are mutually inverse is stated by the separate round-trip theorems.","fidelity_source":"ai","line":90,"lines":[90,94],"module":"CE","name":"contextualise","note":"","plain":"First-order terms to contextual terms","relation":"part","annotation":"This translation builds the contextual representation of each term while retaining its original context and guest type. On variables it reconstructs the data for the binding site from the index. The reverse variable round trip (`indexIsoR`) asks whether that reconstruction recovers an arbitrary original instance.","annotation_references":[{"start":228,"end":239,"key":"lemma:indexisor"}]}],"tone":6,"topic":"contextualisation"},{"anchor":"sec-3","at":"b30104-30146","from_record":false,"lean":true,"lines":[90,94],"module":"CE","name":"contextualise","origin":"ai","part":0,"phrase":"lam-ignores","plain":"First-order terms to contextual terms","record":null,"relation":"part","role":"explanation","rows":[{"end_line":94,"exact_lines":false,"fidelity":"same","fidelity_note":"In the abstraction case, the formal definition builds a contextual abstraction whose function ignores its marker argument and recursively translates the first-order body.","fidelity_source":"ai","line":90,"lines":[90,94],"module":"CE","name":"contextualise","note":"","plain":"First-order terms to contextual terms","relation":"part","annotation":"An input `STLC.Lambda` already has a body with all its variable positions encoded as indices. The function inside the resulting `STLCCtx.CLam` ignores its marker argument because the recursive translation can recover every marker from those positions."}],"tone":6,"topic":"contextualisation"},{"anchor":"sec-3","at":"b30778-30855","from_record":false,"lean":true,"lines":[70,72],"module":"CE","name":"ProxyVar","origin":"ai","part":0,"phrase":"existential","plain":"A binder proxy with an index reifier","record":null,"relation":"defines","role":"definition","rows":[{"end_line":72,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition packages a hidden binding context, its top-variable marker, and reification into the fixed use context, matching the existential variable package described here.","fidelity_source":"ai","line":70,"lines":[70,72],"module":"CE","name":"ProxyVar","note":"","plain":"A binder proxy with an index reifier","relation":"defines","annotation":"An occurrence's exposed context and type leave its binding site unspecified. The package contains some binding context `ts`, a marker there, and an instance relating it to the fixed use context `ts'`. Pattern matching opens the package and gives access to all three together."}],"tone":8,"topic":"variable-conversion"},{"anchor":"sec-3","at":"b30868-30945","from_record":false,"lean":true,"lines":[70,72],"module":"CE","name":"ProxyVar","origin":"ai","part":0,"phrase":"code-proxyvar","plain":"A binder proxy with an index reifier","record":null,"relation":"states","role":"statement","rows":[{"end_line":72,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition packages a hidden binding context, a marker at that context, and reification into the given use context, exactly as the displayed existential variable definition does.","fidelity_source":"ai","line":70,"lines":[70,72],"module":"CE","name":"ProxyVar","note":"","plain":"A binder proxy with an index reifier","relation":"states","annotation":"The paper names this package `Var` and its constructor `MkVar`. In Lean they are `ProxyVar` and `ProxyVar.PVar`. The hidden `ts` links the marker to the input of reification, and the result type exposes only `ts'` and `t`."}],"tone":8,"topic":"variable-conversion"},{"anchor":"sec-3","at":"b31096-31158","from_record":false,"lean":true,"lines":[83,85],"module":"CE","name":"fromIndex","origin":"ai","part":0,"phrase":"workhorse","plain":"A packaged variable from a de Bruijn index","record":null,"relation":"states","role":"mention","rows":[{"end_line":85,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition converts a typed de Bruijn index into the existential variable package, creating the newest variable at Top and extending its use context at each Pop.","fidelity_source":"ai","line":83,"lines":[83,85],"module":"CE","name":"fromIndex","note":"","plain":"A packaged variable from a de Bruijn index","relation":"states","annotation":"Read an index from its outermost `Index.Pop` down to `Index.Top`. The base gives the binding marker. Each return from the recursion adds the skipped entry back to the use context and extends the stored reification by one step."}],"tone":8,"topic":"variable-conversion"},{"anchor":"sec-3","at":"b31207-31229","from_record":false,"lean":true,"lines":[83,85],"module":"CE","name":"fromIndex","origin":"ai","part":0,"phrase":"code-fromindex-top","plain":"A packaged variable from a de Bruijn index","record":null,"relation":"states","role":"statement","rows":[{"end_line":85,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal Top branch returns the predefined package for the newest variable, matching this equation.","fidelity_source":"ai","line":83,"lines":[83,85],"module":"CE","name":"fromIndex","note":"","plain":"A packaged variable from a de Bruijn index","relation":"states","annotation":"In the `Index.Top` branch the binding and use contexts already coincide. `varTop` records that fact in the package by using reflexive reification, so there is no context extension to reconstruct."}],"tone":8,"topic":"variable-conversion"},{"anchor":"sec-3","at":"b31286-31336","from_record":false,"lean":true,"lines":[78,78],"module":"CE","name":"varTop","origin":"ai","part":0,"phrase":"code-vartop","plain":"The most recent binder packaged as a contextual variable","record":null,"relation":"states","role":"statement","rows":[{"end_line":78,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition packages the newest-variable marker at the extended context with identity-context reification, matching varTop in the paper.","fidelity_source":"ai","line":78,"lines":[78,78],"module":"CE","name":"varTop","note":"","plain":"The most recent binder packaged as a contextual variable","relation":"states","annotation":"The explicit arguments in `@PTop ts t` fix the hidden binding context to `ts :/: t`. That is also the package's use context, so Lean can fill the instance argument with `instReifyIndexRefl`."}],"tone":8,"topic":"variable-conversion"},{"anchor":"sec-3","at":"b31337-31381","from_record":false,"lean":true,"lines":[83,85],"module":"CE","name":"fromIndex","origin":"ai","part":0,"phrase":"code-fromindex-pop","plain":"A packaged variable from a de Bruijn index","record":null,"relation":"states","role":"statement","rows":[{"end_line":85,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal Pop branch first converts the smaller index and then extends the package’s use context by one entry, matching this equation.","fidelity_source":"ai","line":83,"lines":[83,85],"module":"CE","name":"fromIndex","note":"","plain":"A packaged variable from a de Bruijn index","relation":"states","annotation":"For `Index.Pop i`, first construct a package in the shorter context using `fromIndex i`. The step `weakenPVar` then adds the same last entry that `Index.Pop` skipped. The binding marker stays attached to its original context."}],"tone":8,"topic":"variable-conversion"},{"anchor":"sec-3","at":"b31442-31472","from_record":false,"lean":true,"lines":[75,76],"module":"CE","name":"weakenPVar","origin":"ai","part":0,"phrase":"code-weaken","plain":"A packaged variable in a context extended by one binder","record":null,"relation":"states","role":"statement","rows":[{"end_line":76,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition keeps the saved marker and binding context while extending the use context and its reification by one entry; the unchanged-looking package in the paper has exactly this effect.","fidelity_source":"ai","line":75,"lines":[75,76],"module":"CE","name":"weakenPVar","note":"","plain":"A packaged variable in a context extended by one binder","relation":"states","annotation":"The two sides of `PVar i => PVar i` use the same marker. The constructor on the right expects a reification with an extended target context, so Lean wraps the old instance with `instReifyIndexSnoc`. The source prints the same constructor even though its implicit argument has changed."}],"tone":8,"topic":"variable-conversion"},{"anchor":"sec-3","at":"b31478-31603","from_record":false,"lean":true,"lines":[83,85],"module":"CE","name":"fromIndex","origin":"ai","part":0,"phrase":"weaken","plain":"A packaged variable from a de Bruijn index","record":null,"relation":"part","role":"explanation","rows":[{"end_line":85,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition handles each Pop by converting the remaining index and then extending the resulting variable package’s use context by one entry.","fidelity_source":"ai","line":83,"lines":[83,85],"module":"CE","name":"fromIndex","note":"","plain":"A packaged variable from a de Bruijn index","relation":"part","annotation":"For `Index.Pop (Index.Pop Index.Top)`, `fromIndex` calls `weakenPVar` twice on the package for the oldest of three entries. Its use context therefore contains all three, while its binding context ends at the first entry."},{"end_line":76,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition extends a variable package’s use context by one entry and supplies the corresponding recursive reification, preserving its saved binding context and marker. This is the weakening used for each Pop.","fidelity_source":"ai","line":75,"lines":[75,76],"module":"CE","name":"weakenPVar","note":"","plain":"A packaged variable in a context extended by one binder","relation":"part","annotation":"Here weakening allows one more variable to be in scope without changing which variable is meant. The updated instance crosses the added entry when asked to reify, so the new index has one more `Index.Pop` than the old one."}],"tone":8,"topic":"variable-conversion"},{"anchor":"sec-3","at":"b31604-31663","from_record":false,"lean":true,"lines":[83,85],"module":"CE","name":"fromIndex","origin":"ai","part":0,"phrase":"top-case","plain":"A packaged variable from a de Bruijn index","record":null,"relation":"part","role":"explanation","rows":[{"end_line":85,"exact_lines":false,"fidelity":"same","fidelity_note":"The Top case of the formal definition returns the package for the newest variable, exactly as the quoted conversion step requires.","fidelity_source":"ai","line":83,"lines":[83,85],"module":"CE","name":"fromIndex","note":"","plain":"A packaged variable from a de Bruijn index","relation":"part","annotation":"The conversion stops when it reaches `Index.Top`, even if an earlier entry has the same type. The end of the index specifies the binding position. That is why the base package begins at the current context rather than searching by type."},{"end_line":78,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition packages the top-variable marker with reification from a context to itself, yielding the newest variable in that context.","fidelity_source":"ai","line":78,"lines":[78,78],"module":"CE","name":"varTop","note":"","plain":"The most recent binder packaged as a contextual variable","relation":"part","annotation":"The marker supplied by this package names the newest entry at its binding site. Reifying it with the stored reflexive instance produces `Index.Top`. Later weakening will change how that same marker is reified at use."}],"tone":8,"topic":"variable-conversion"},{"anchor":"sec-3","at":"b31804-31942","from_record":false,"lean":true,"lines":[80,81],"module":"CE","name":"fromVar","origin":"ai","part":0,"phrase":"inject","plain":"A contextual term from a packaged variable","record":null,"relation":"part","role":"explanation","rows":[{"end_line":81,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition is the injection mentioned in the passage: it turns an existential variable package into a contextual variable term without changing its context or guest type.","fidelity_source":"ai","line":80,"lines":[80,81],"module":"CE","name":"fromVar","note":"","plain":"A contextual term from a packaged variable","relation":"part","annotation":"The package and `STLCCtx.CVar` store the same two pieces of data. `fromVar` changes the outer constructor so the package can appear inside a full term, keeping its marker and the same instance."},{"end_line":88,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition composes conversion of an index to a variable package with injection of that package into a contextual term, exactly as the passage says.","fidelity_source":"ai","line":87,"lines":[87,88],"module":"CE","name":"toCVar","note":"","plain":"A contextual variable term from a de Bruijn index","relation":"part","annotation":"This is the variable branch of the term translation. To work out what it does on a particular occurrence, apply `fromIndex` to recover the binding marker and its reification first, then use `fromVar` to put that data inside the contextual term."}],"tone":8,"topic":"variable-conversion"},{"anchor":"sec-3","at":"b32019-32045","from_record":false,"lean":true,"lines":[80,81],"module":"CE","name":"fromVar","origin":"ai","part":0,"phrase":"code-fromvar","plain":"A contextual term from a packaged variable","record":null,"relation":"states","role":"statement","rows":[{"end_line":81,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition turns the existential variable package into a contextual variable using the same saved marker and reification, matching this equation.","fidelity_source":"ai","line":80,"lines":[80,81],"module":"CE","name":"fromVar","note":"","plain":"A contextual term from a packaged variable","relation":"states","annotation":"The `ProxyVar.PVar` pattern exposes the hidden context and makes its reification instance available. `STLCCtx.CVar` can use both directly. No index is computed until an operation such as `unembed` asks for one."}],"tone":8,"topic":"variable-conversion"},{"anchor":"sec-3","at":"b32099-32127","from_record":false,"lean":true,"lines":[87,88],"module":"CE","name":"toCVar","origin":"ai","part":0,"phrase":"code-tocvar","plain":"A contextual variable term from a de Bruijn index","record":null,"relation":"states","role":"statement","rows":[{"end_line":88,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal definition agrees with the displayed composition $\\operatorname{toCVar}=\\operatorname{fromVar}\\circ\\operatorname{fromIndex}$. It first packages the index and then turns that package into a contextual variable.","fidelity_source":"ai","line":87,"lines":[87,88],"module":"CE","name":"toCVar","note":"","plain":"A contextual variable term from a de Bruijn index","relation":"states","annotation":"The right-hand side runs from right to left. `fromIndex` turns a typed position into a marker and an instance. `fromVar` uses them to make a term of the index's guest type in the index's original context."}],"tone":8,"topic":"variable-conversion"},{"anchor":"sec-3","at":"b32141-32220","from_record":false,"lean":true,"lines":[199,200],"module":"CE","name":"isoL","origin":"ai","part":0,"phrase":"proven","plain":"Unembedding after contextualising recovers the first-order term","record":"contextual-embeddings.claim-isomorphism","relation":"states","role":"statement","rows":[{"end_line":205,"exact_lines":false,"fidelity":"weaker","fidelity_note":"The passage claims an isomorphism; this formal statement proves only that unembedding after contextualisation returns every original first-order term. The reverse equation is supplied by the other cited theorem.","fidelity_source":"ai","line":199,"lines":[199,200],"module":"CE","name":"isoL","note":"","plain":"Unembedding after contextualising recovers the first-order term","proof_lines":[201,205],"relation":"states","annotation":"This direction starts with first-order syntax and uses only instances built during `contextualise`. After `unembed` recovers the original term, it follows that two different first-order terms cannot acquire the same contextual representation. This direction uses no closed-world axiom.","annotation_references":[{"start":266,"end":284,"key":"axiom:closed-world"}]},{"end_line":221,"exact_lines":false,"fidelity":"weaker","fidelity_note":"The passage claims an isomorphism; this formal statement proves only that contextualisation after unembedding returns every original contextual term. Its proof uses the closed world assumption disclosed later in this subsection; the other cited theorem supplies the opposite direction.","fidelity_source":"ai","line":210,"lines":[210,211],"module":"CE","name":"isoR","note":"","plain":"Contextualising after unembedding recovers the term under the reifier axiom","proof_lines":[212,221],"relation":"states","annotation":"This direction starts with an arbitrary contextual term, which can already contain a reification instance. The authors' Lean proof uses `closedWorld` (every supplied reification instance must be reflexive or a recursive extension) to ensure reconstruction from an index recovers that stored instance. Together with `isoL` it supplies the isomorphism under that assumption.","annotation_references":[{"start":136,"end":149,"key":"axiom:closed-world"},{"start":315,"end":321,"key":"theorem:isol"}]}],"tone":9,"topic":"term-round-trips"},{"anchor":"sec-3","at":"b32377-32472","from_record":false,"lean":true,"lines":[120,121],"module":"CE","name":"indexIsoL","origin":"ai","part":0,"phrase":"core","plain":"Reifying the packaged variable recovers its index","record":null,"relation":"part","role":"explanation","rows":[{"end_line":125,"exact_lines":false,"fidelity":"weaker","fidelity_note":"The passage names an isomorphism of variable representations; this formal statement gives one direction: converting any index to a package and reifying it returns that index.","fidelity_source":"ai","line":120,"lines":[120,121],"module":"CE","name":"indexIsoL","note":"","plain":"Reifying the packaged variable recovers its index","proof_lines":[122,125],"relation":"part","annotation":"Starting with a typed position makes the induction straightforward: each `Index.Pop` becomes one stored extension, which in turn reifies to one `Index.Pop`. The first-order round-trip proof (`isoL`) uses this equality at every variable leaf.","annotation_references":[{"start":191,"end":197,"key":"case:isol-var"}]},{"end_line":183,"exact_lines":false,"fidelity":"weaker","fidelity_note":"The passage names an isomorphism of variable representations; this formal statement gives the reverse direction: reifying a package and converting the index back returns the original package. Its proof uses the closed world assumption.","fidelity_source":"ai","line":162,"lines":[162,164],"module":"CE","name":"indexIsoR","note":"","plain":"Reifying and repackaging gives the original variable under the reifier axiom","proof_lines":[165,183],"relation":"part","annotation":"Equality here concerns the whole variable package. Once reification has produced a position, rebuilding its package must recover the binding context and the stored instance as well as the marker. This is where the proof needs `closedWorld`.","annotation_references":[{"start":226,"end":239,"key":"axiom:closed-world"}]}],"tone":10,"topic":"index-round-trips"},{"anchor":"sec-3","at":"b32540-32617","from_record":false,"lean":true,"lines":[199,200],"module":"CE","name":"isoL","origin":"ai","part":0,"phrase":"isoL-statement","plain":"Unembedding after contextualising recovers the first-order term","record":"contextual-embeddings.claim-isomorphism","relation":"states","role":"statement","rows":[{"end_line":205,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal statement is the displayed equation $\\operatorname{unembed}(\\operatorname{contextualise}(e))=e$ for every first-order term, in any context and at any guest type; its proof does not use the closed world assumption.","fidelity_source":"ai","line":199,"lines":[199,200],"module":"CE","name":"isoL","note":"","plain":"Unembedding after contextualising recovers the first-order term","proof_lines":[201,205],"relation":"states","annotation":"Read the expression from the inside out. Convert a first-order term to contextual syntax and read it back as first-order syntax. The equality holds with the same context and guest type, so a free variable's index is recovered along with the rest of the term."}],"tone":9,"topic":"term-round-trips"},{"anchor":"sec-3","at":"b32618-32695","from_record":false,"lean":true,"lines":[210,211],"module":"CE","name":"isoR","origin":"ai","part":0,"phrase":"isoR-statement","plain":"Contextualising after unembedding recovers the term under the reifier axiom","record":"contextual-embeddings.claim-isomorphism","relation":"states","role":"statement","rows":[{"end_line":221,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal statement is the displayed equation $\\operatorname{contextualise}(\\operatorname{unembed}(e))=e$ for every contextual term. Its proof uses the closed world assumption discussed immediately below, so equality of the displayed statements does not mean an assumption-free isomorphism.","fidelity_source":"ai","line":210,"lines":[210,211],"module":"CE","name":"isoR","note":"","plain":"Contextualising after unembedding recovers the term under the reifier axiom","proof_lines":[212,221],"relation":"states","annotation":"Read the expression from the inside out. Turn a contextual term into a first-order tree and rebuild its contextual form. The equality is between contextual terms themselves, including their stored variable data. The proof recovers that data with `indexIsoR`, which uses `closedWorld`.","annotation_references":[{"start":246,"end":257,"key":"lemma:indexisor"},{"start":270,"end":283,"key":"axiom:closed-world"}]}],"tone":9,"topic":"term-round-trips"},{"anchor":"sec-3","at":"b32739-32798","from_record":false,"lean":true,"lines":[120,121],"module":"CE","name":"indexIsoL","origin":"ai","part":0,"phrase":"indexIsoL","plain":"Reifying the packaged variable recovers its index","record":null,"relation":"states","role":"statement","rows":[{"end_line":125,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal statement gives the left-inverse equation discussed under this heading: reifying the variable package produced from any index returns the original index. It does not require the closed world assumption.","fidelity_source":"ai","line":120,"lines":[120,121],"module":"CE","name":"indexIsoL","note":"","plain":"Reifying the packaged variable recovers its index","proof_lines":[122,125],"relation":"states","annotation":"The function `fromIndex` returns a variable package (`Var` in the paper), so the statement extracts its stored instance as field `.2` and its marker as field `.3`. Reifying with precisely that instance returns the original index. Field `.1` is the hidden binding context shared by the other two.","annotation_references":[{"start":53,"end":58,"key":"definition:var-package"}]}],"tone":10,"topic":"index-round-trips"},{"anchor":"sec-3","at":"b32799-32856","from_record":false,"lean":true,"lines":[120,121],"module":"CE","name":"indexIsoL","origin":"ai","part":0,"phrase":"indexIsoL-proof","plain":"Reifying the packaged variable recovers its index","record":null,"relation":"proof","role":"derivation","rows":[{"end_line":125,"exact_lines":false,"fidelity":"different","fidelity_note":"The passage describes proof by induction; the formal statement says that reifying the package produced from an index returns that index. The supplied proof does use induction on the index, but that proof method is not a separate theorem statement.","fidelity_source":"ai","line":120,"lines":[120,121],"module":"CE","name":"indexIsoL","note":"","plain":"Reifying the packaged variable recovers its index","proof_lines":[122,125],"relation":"proof","annotation":"In the `Index.Top` branch the two sides reduce to the same index. In the `Index.Pop` branch unfolding `fromIndex` and `weakenPVar` (`weakenCVar` in the paper) leaves a pop on each side. The induction hypothesis supplies equality of the indices inside those pops.","annotation_references":[{"start":132,"end":144,"key":"definition:weakencvar"}]}],"tone":10,"topic":"index-round-trips"},{"anchor":"sec-3","at":"b32857-32986","from_record":false,"lean":true,"lines":[120,121],"module":"CE","name":"indexIsoL","origin":"ai","part":0,"phrase":"indexIsoL-intuition","plain":"Reifying the packaged variable recovers its index","record":null,"relation":"part","role":"explanation","rows":[{"end_line":125,"exact_lines":false,"fidelity":"different","fidelity_note":"The passage explains how weakening and reification cancel at each Pop; the formal statement gives the resulting equality for the entire index. The supplied inductive proof follows this explanation, rather than stating a separate step-count theorem.","fidelity_source":"ai","line":120,"lines":[120,121],"module":"CE","name":"indexIsoL","note":"","plain":"Reifying the packaged variable recovers its index","proof_lines":[122,125],"relation":"part","annotation":"Think of `Index.Pop Index.Top` as a position one binder back. The conversion saves the older binder and uses one weakening at the current binder. Reification turns that weakening into the single pop again."}],"tone":10,"topic":"index-round-trips"},{"anchor":"sec-3","at":"b32988-33129","from_record":false,"lean":true,"lines":[162,164],"module":"CE","name":"indexIsoR","origin":"ai","part":0,"phrase":"indexIsoR","plain":"Reifying and repackaging gives the original variable under the reifier axiom","record":null,"relation":"part","role":"explanation","rows":[{"end_line":183,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal theorem gives the reverse variable round trip. Reify the saved marker with the package’s stored instance, then convert the resulting index back to recover the original package and its instance. The proof uses the closed world assumption introduced next in the paper.","fidelity_source":"ai","line":162,"lines":[162,164],"module":"CE","name":"indexIsoR","note":"","plain":"Reifying and repackaging gives the original variable under the reifier axiom","proof_lines":[165,183],"relation":"part","annotation":"This order reifies first, using the instance already present, and lets `fromIndex` build a fresh package from the resulting position. A custom instance could have chosen a different position of the same type. The proof invokes `closedWorld` to exclude that possibility and recover the original package.","annotation_references":[{"start":227,"end":240,"key":"axiom:closed-world"}]}],"tone":10,"topic":"index-round-trips"},{"anchor":"sec-3","at":"b33653-33789","from_record":false,"lean":true,"lines":[142,154],"module":"CE","name":"closedWorld","origin":"ai","part":0,"phrase":"closed-world","plain":"Axiom restricting index reifiers to reflexivity and context extension","record":null,"relation":"states","role":"statement","rows":[{"end_line":154,"exact_lines":false,"fidelity":"same","fidelity_note":"The formal assumption says every reification instance is either the identity-context instance or a one-entry extension of another instance. This is the paper’s closed world condition, assumed here rather than derived from instance resolution.","fidelity_source":"ai","line":142,"lines":[142,154],"module":"CE","name":"closedWorld","note":"","plain":"Axiom restricting index reifiers to reflexivity and context extension","relation":"states","annotation":"An instance is a record with a reification function. In a context $[a,a]$, a custom function could send the newest marker to the earlier $a$. `closedWorld` assumes that every supplied instance is the reflexive instance or is built by one application of `instReifyIndexSnoc` to a smaller instance.","annotation_references":[{"start":196,"end":218,"key":"definition:reifyindex-instances"}]}],"tone":11,"topic":"closed-world-assumption"},{"anchor":"sec-3","at":"b33790-33918","from_record":false,"lean":true,"lines":[142,154],"module":"CE","name":"closedWorld","origin":"ai","part":0,"phrase":"closed-world-why","plain":"Axiom restricting index reifiers to reflexivity and context extension","record":null,"relation":"states","role":"mention","rows":[{"end_line":154,"exact_lines":false,"fidelity":"different","fidelity_note":"The passage justifies the assumption by hiding a type class from users; the formal declaration simply assumes the two-case condition for every reification instance. It does not prove that a module boundary enforces that condition.","fidelity_source":"ai","line":142,"lines":[142,154],"module":"CE","name":"closedWorld","note":"","plain":"Axiom restricting index reifiers to reflexivity and context extension","relation":"states","annotation":"Instance search supplies one record of the requested type. A term can already contain an instance of that type, and its type alone leaves the record's identity open. The authors propose hiding `ReifyIndex` so clients cannot supply their own records. The Lean file assumes the classification as an axiom."}],"tone":11,"topic":"closed-world-assumption"},{"anchor":"sec-3","at":"b33919-34055","from_record":false,"lean":true,"lines":[162,164],"module":"CE","name":"indexIsoR","origin":"ai","part":0,"phrase":"case-analysis","plain":"Reifying and repackaging gives the original variable under the reifier axiom","record":null,"relation":"proof","role":"derivation","rows":[{"end_line":183,"exact_lines":false,"fidelity":"different","fidelity_note":"The passage describes the proof: case analysis on the reification instances, made possible by the closed world assumption. The formal statement is the resulting reverse round-trip equation; its proof does split on the two cases that assumption allows and recurses through the extension case.","fidelity_source":"ai","line":162,"lines":[162,164],"module":"CE","name":"indexIsoR","note":"","plain":"Reifying and repackaging gives the original variable under the reifier axiom","proof_lines":[165,183],"relation":"proof","annotation":"After rewriting the instance to the reflexive form, the position is `Index.Top` and the reconstructed package reduces to the original. In the extension case, reification produces a pop, and `fromIndex` applies `weakenPVar` after the recursive round trip on the smaller instance."}],"tone":11,"topic":"closed-world-assumption"},{"anchor":"sec-3","at":"b34133-34181","from_record":false,"lean":true,"lines":[199,200],"module":"CE","name":"isoL","origin":"ai","part":0,"phrase":"isoL-var","plain":"Unembedding after contextualising recovers the first-order term","record":"contextual-embeddings.claim-isomorphism","relation":"proof","role":"derivation","rows":[{"end_line":205,"exact_lines":false,"fidelity":"different","fidelity_note":"The passage names the variable case’s proof dependency; the formal statement gives the first-order term round-trip equation. Its variable case does use the index round-trip result, as the passage says.","fidelity_source":"ai","line":199,"lines":[199,200],"module":"CE","name":"isoL","note":"","plain":"Unembedding after contextualising recovers the first-order term","proof_lines":[201,205],"relation":"proof","annotation":"The variable branch translates by `toCVar`, then applies the stored reification during `unembed`. This is exactly the operation in `indexIsoL`. Once it returns the same index, both sides are `STLC.Var` applied to it.","annotation_references":[{"start":131,"end":142,"key":"lemma:indexisol"}]}],"tone":9,"topic":"term-round-trips"},{"anchor":"sec-3","at":"b34185-34234","from_record":false,"lean":true,"lines":[210,211],"module":"CE","name":"isoR","origin":"ai","part":0,"phrase":"isoR-cvar","plain":"Contextualising after unembedding recovers the term under the reifier axiom","record":"contextual-embeddings.claim-isomorphism","relation":"proof","role":"derivation","rows":[{"end_line":221,"exact_lines":false,"fidelity":"different","fidelity_note":"The passage names the contextual-variable case’s proof dependency; the formal statement gives the contextual term round-trip equation. Its proof uses the reverse variable round trip and therefore the closed world assumption.","fidelity_source":"ai","line":210,"lines":[210,211],"module":"CE","name":"isoR","note":"","plain":"Contextualising after unembedding recovers the term under the reifier axiom","proof_lines":[212,221],"relation":"proof","annotation":"The `STLCCtx.CVar` pattern binds an existing instance. After unembedding, the variable branch of `contextualise` only sees the resulting index. `indexIsoR` shows that its reconstructed package can be used to recover the input constructor with its original data.","annotation_references":[{"start":144,"end":155,"key":"lemma:indexisor"}]}],"tone":9,"topic":"term-round-trips"},{"anchor":"sec-3","at":"b34241-34304","from_record":false,"lean":true,"lines":[210,211],"module":"CE","name":"isoR","origin":"ai","part":0,"phrase":"isoR-clam","plain":"Contextualising after unembedding recovers the term under the reifier axiom","record":"contextual-embeddings.claim-isomorphism","relation":"proof","role":"derivation","rows":[{"end_line":221,"exact_lines":false,"fidelity":"different","fidelity_note":"The passage describes the abstraction case’s use of function extensionality; the formal statement gives the contextual term round-trip equation. The supplied proof uses extensionality and the singleton marker to establish equality of the abstraction bodies.","fidelity_source":"ai","line":210,"lines":[210,211],"module":"CE","name":"isoR","note":"","plain":"Contextualising after unembedding recovers the term under the reifier axiom","proof_lines":[212,221],"relation":"proof","annotation":"The two abstractions contain host functions, so `funext` asks for equality on any input marker. The induction hypothesis recovers the original body at `ProxyTop.PTop`. Every input marker has that constructor, so the rebuilt function gives the original result at each input.","annotation_references":[{"start":151,"end":166,"key":"definition:proxytop"}]}],"tone":9,"topic":"term-round-trips"},{"anchor":"sec-3","at":"b43696-43857","from_record":false,"lean":true,"lines":[199,200],"module":"CE","name":"isoL","origin":"ai","part":0,"phrase":"provability-closed-world","plain":"Unembedding after contextualising recovers the first-order term","record":"contextual-embeddings.claim-isomorphism","relation":"states","role":"mention","rows":[{"end_line":205,"exact_lines":false,"fidelity":"different","fidelity_note":"The passage says that transferring proofs between the two representations relies on the round-trip results and so on the closed world assumption. This direction, unembedding after contextualisation returns the first-order term, is proved without that assumption; only the reverse direction uses it.","fidelity_source":"ai","line":199,"lines":[199,200],"module":"CE","name":"isoL","note":"","plain":"Unembedding after contextualising recovers the first-order term","proof_lines":[201,205],"relation":"states","annotation":"When a proof is carried out on the first-order term, `isoL` guarantees that displaying it in contextual syntax and translating back does not change the first-order object. This direction uses the instances created by the forward conversion and needs no closed-world axiom.","annotation_references":[{"start":53,"end":59,"key":"theorem:isol"},{"start":253,"end":271,"key":"axiom:closed-world"}]},{"end_line":221,"exact_lines":false,"fidelity":"different","fidelity_note":"The formal statement says that contextualising after unembedding returns the original contextual term, and its proof does use the closed world assumption, as the passage says. The passage concerns how proofs transfer between representations, which no formal statement here expresses.","fidelity_source":"ai","line":210,"lines":[210,211],"module":"CE","name":"isoR","note":"","plain":"Contextualising after unembedding recovers the term under the reifier axiom","proof_lines":[212,221],"relation":"states","annotation":"Suppose a theorem starts with a contextual term $e$. A proof about its rebuilt form yields a proof about $e$ by rewriting with `isoR`, which uses `closedWorld` (the restriction to the two defined reification instance forms). This lets the metatheoretic proof use induction on first-order syntax and return to the contextual statement.","annotation_references":[{"start":127,"end":133,"key":"theorem:isor"},{"start":146,"end":159,"key":"axiom:closed-world"}]}],"tone":11,"topic":"closed-world-assumption"}],"topics":[{"dark":"oklch(0.566 0.209 5.9)","description":"Guest types and snoc contexts specify the types and available variables of the simply typed lambda calculus.","family":"first-order-representation","id":"types-contexts","light":"oklch(0.406 0.163 5.9)","name":"Types and contexts","part":0,"tone":0},{"dark":"oklch(0.690 0.190 18.5)","description":"Top and Pop locate a variable of a given type within its context.","family":"first-order-representation","id":"de-bruijn-indices","light":"oklch(0.530 0.190 18.5)","name":"Typed de Bruijn indices","part":0,"tone":1},{"dark":"oklch(0.814 0.105 31.1)","description":"Variables, abstraction, application and the unit term form the first-order embedding.","family":"first-order-representation","id":"first-order-terms","light":"oklch(0.654 0.171 31.1)","name":"First-order terms","part":0,"tone":2},{"dark":"oklch(0.536 0.114 105.9)","description":"A singleton marker saves the context and type of the most recently introduced variable.","family":"contextual-representation","id":"singleton-variables","light":"oklch(0.376 0.080 105.9)","name":"Singleton variable markers","part":0,"tone":3},{"dark":"oklch(0.660 0.154 118.5)","description":"The identity and extension instances recover a de Bruijn index from the binding and use contexts.","family":"contextual-representation","id":"context-extension","light":"oklch(0.500 0.117 118.5)","name":"Context extension","part":0,"tone":4},{"dark":"oklch(0.784 0.171 131.1)","description":"Contextual terms use host functions for abstraction and reification for variable occurrences.","family":"contextual-representation","id":"contextual-terms","light":"oklch(0.624 0.170 131.1)","name":"Contextual terms","part":0,"tone":5},{"dark":"oklch(0.536 0.098 178.4)","description":"Contextualisation translates first-order syntax back to contextual syntax.","family":"conversion","id":"contextualisation","light":"oklch(0.376 0.069 178.4)","name":"Contextualising first-order terms","part":0,"tone":6},{"dark":"oklch(0.660 0.113 191.0)","description":"Unembedding translates contextual syntax to first-order syntax while preserving context and guest type.","family":"conversion","id":"unembedding","light":"oklch(0.500 0.086 191.0)","name":"Unembedding contextual terms","part":0,"tone":7},{"dark":"oklch(0.784 0.133 203.6)","description":"An existential variable package separates conversion of indices from conversion of whole terms.","family":"conversion","id":"variable-conversion","light":"oklch(0.624 0.106 203.6)","name":"Converting individual variables","part":0,"tone":8},{"dark":"oklch(0.561 0.209 264.4)","description":"The two term equations express recovery of the original representation after both conversions.","family":"isomorphism","id":"term-round-trips","light":"oklch(0.401 0.209 264.4)","name":"Term round trips","part":0,"tone":9},{"dark":"oklch(0.685 0.167 277.0)","description":"The variable equations relate de Bruijn indices to their existential packages and support the term equations.","family":"isomorphism","id":"index-round-trips","light":"oklch(0.525 0.190 277.0)","name":"Index round trips","part":0,"tone":10},{"dark":"oklch(0.809 0.102 289.6)","description":"The reverse conversion relies on the assumption that reification uses only the identity and context-extension instances.","family":"isomorphism","id":"closed-world-assumption","light":"oklch(0.649 0.171 289.6)","name":"Closed world assumption","part":0,"tone":11}]}