<?xml version="1.0" encoding="utf-8"?> 
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
 <title type="text">λk.(k blog): Posts tagged 'notes'</title>
 <link rel="self" href="https://www.williamjbowman.com/feeds/notes.atom.xml" />
 <link href="https://www.williamjbowman.com/tags/notes.html" />
 <id>urn:https-www-williamjbowman-com:-tags-notes-html</id>
 <updated>2025-06-02T21:56:43Z</updated>
 <entry>
  <title type="text">What's higher-order about so-called higher-order references?</title>
  <link rel="alternate" href="https://www.williamjbowman.com/blog/2025/06/02/what-s-higher-order-about-so-called-higher-order-references/" />
  <id>urn:https-www-williamjbowman-com:-blog-2025-06-02-what-s-higher-order-about-so-called-higher-order-references</id>
  <published>2025-06-02T21:56:43Z</published>
  <updated>2025-06-02T21:56:43Z</updated>
  <author>
   <name>William J. Bowman</name></author>
  <content type="html">
&lt;p&gt;A reviewer, in one of those off-hand little low-level comments they leave, which one is sometimes tempted to ignore as one works on a revision because they&amp;rsquo;re not &lt;em&gt;strictly&lt;/em&gt; actionable, has absolutely nerd-sniped me.&lt;/p&gt;

&lt;p&gt;What does &amp;ldquo;higher-order&amp;rdquo; in &amp;ldquo;higher-order references&amp;rdquo; mean? (References as in &lt;a href="https://doi.org/10.1145/362349.362364"&gt;Reynolds 1970&lt;/a&gt;.)&lt;/p&gt;
&lt;!-- more--&gt;

&lt;p&gt;We appear to have inherited the phrase &amp;ldquo;higher-order&amp;rdquo; from higher-order logic, which it refers to the union of first-order logic, and second-order logic, and third-order logic, and so on. Here, &amp;ldquo;order&amp;rdquo; refers to what quantifiers can quantify over. For example, zeroth-order logic has no quantifiers. First-order logic can quantify individuals. Second-order logic can quantify over things that quantify over individuals (sets). &lt;em&gt;Etc.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So what is a higher-order function? Well, a function that can quantify over functions that can quantify over functions, &lt;em&gt;etc&lt;/em&gt;. Really, we could perhaps generalize to higher-order values to make a closer analogy to higher-order logic. A zeroth-order value cannot quantify over other values&amp;mdash;values such as naturals and booleans. These are sometimes called ground values. A function cannot be a zeroth-order value, since it quantifies over other values. A first-order value can quantify over zeroth-order values. A fairly restricted function would be a first-order value. A second-order value could quantify over values that quantify over values, so for example a function of type &lt;code&gt;(A -&amp;gt; B) -&amp;gt; C&lt;/code&gt;, where &lt;code&gt;A&lt;/code&gt;, &lt;code&gt;B&lt;/code&gt;, and &lt;code&gt;C&lt;/code&gt; are ground values, would be second order.&lt;/p&gt;

&lt;p&gt;So far all this makes sense.&lt;/p&gt;

&lt;p&gt;What is a higher-order reference?&lt;/p&gt;

&lt;p&gt;Well&amp;hellip; that is a surprisingly complicated question.&lt;/p&gt;

&lt;p&gt;Of late, &amp;ldquo;higher-order reference&amp;rdquo; seems to mean &amp;ldquo;reference to a higher-order, effectful function&amp;rdquo;. The phrase appears in this sense at least as early as 1998 (&lt;a href="https://doi.org/10.1109/LICS.1998.705669"&gt;Abramsky &lt;em&gt;et al.&lt;/em&gt;&lt;/a&gt;), in which Abramsky &lt;em&gt;et al&lt;/em&gt;. use &amp;ldquo;higher-order reference&amp;rdquo; to refer to references that contain higher-order functions that can, when called, modify the heap. But this use of &amp;ldquo;higher-order&amp;rdquo; is at odds with most other uses of &amp;ldquo;higher-order&amp;rdquo;. It&amp;rsquo;s not used to mean that the reference merely quantifies over other references. Instead, it&amp;rsquo;s used to mean references that quantify over &lt;em&gt;higher-order, effectful functions&lt;/em&gt;, a different class of values. That is, this use of &amp;ldquo;higher-order&amp;rdquo; refers not to the order of the reference, but the order of the values the reference contains. If we were to use &amp;ldquo;higher-order reference&amp;rdquo; more consistently with &amp;ldquo;higher-order logic&amp;rdquo;, it should mean references to references to references &lt;em&gt;etc.&lt;/em&gt; to values.&lt;/p&gt;

&lt;p&gt;The phrase &amp;ldquo;general references&amp;rdquo; avoids the problem, but does not solve it. This phrase is often used, including by &lt;em&gt;op. cit.&lt;/em&gt;, to include other forms of higher quantification in references, such as cyclic references and references to existential types, &lt;em&gt;etc.&lt;/em&gt;, as well as references to higher-order, effectful functions. To quote:&lt;/p&gt;

&lt;blockquote&gt;
 &lt;p&gt;By general references we mean references which can store not only values of ground types (integers, booleans, etc.) but also those of higher types (procedures, higher-order functions, or references themselves).&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://www.cs.princeton.edu/techreports/2004/713.pdf"&gt;Ahmed (2004)&lt;/a&gt; uses similar phrasing:&lt;/p&gt;

&lt;blockquote&gt;
 &lt;p&gt;general references — that is, mutable cells that can hold values of any closed type including other references, functions, recursive types, and impredicative quantified types.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;The emphasis is on their &lt;em&gt;generality&lt;/em&gt;, which distracts from a key semantic issues (higher-order, effectful functions &lt;em&gt;in particular&lt;/em&gt; are responsible for interesting semantics questions).&lt;/p&gt;

&lt;p&gt;The situation is worse if we look at the phrase &amp;ldquo;first-order references&amp;rdquo;, which also appears in &lt;a href="https://doi.org/10.1109/LICS.1998.705669"&gt;Abramsky &lt;em&gt;et al.&lt;/em&gt;&lt;/a&gt;. This appears to refer to references to ground values, &lt;em&gt;i.e.&lt;/em&gt;, references to zeroth-order values. So a first-order reference is indeed a first-order value, in that it quantifies over zeroth-order values. But that means &amp;ldquo;first-order&amp;rdquo; in &amp;ldquo;first-order reference&amp;rdquo; is used in a difference sense than &amp;ldquo;higher-order&amp;rdquo; in &amp;ldquo;higher-order references&amp;rdquo;: it refers to the order of quantification of the reference itself, and not to the order of the quantification of the contents of the reference.&lt;/p&gt;

&lt;p&gt;Even more frustratingly, it seems the phrase &amp;ldquo;higher-order reference&amp;rdquo; &lt;em&gt;used&lt;/em&gt; to use &amp;ldquo;higher-order&amp;rdquo; in the original sense. &lt;a href="https://doi.org/10.1007/3-540-08342-1_22"&gt;Janssen &lt;em&gt;et al.&lt;/em&gt; (1977)&lt;/a&gt; use &amp;ldquo;higher order reference&amp;rdquo; to refer to references that quantify over references! Readings over some of the related papers around that time, it seems the semantics of such references were quite interesting. It&amp;rsquo;s unclear to me when exactly the phrase took on the new sense of &amp;ldquo;higher-order&amp;rdquo;.&lt;/p&gt;

&lt;p&gt;So how do I concisely, and pedantically, refer to those references that can contain higher-order (effectful) functions (but not necessarily other non-first-order values)? My student Sean Bocirnea proposed &amp;ldquo;higher-order value references&amp;rdquo; (HOVR; pronounced &amp;ldquo;hoover&amp;rdquo;). Perhaps we&amp;rsquo;d use &amp;ldquo;higher-order function reference&amp;rdquo; (HOFR; &amp;ldquo;hoofer&amp;rdquo;) to speak of those only required to contain higher-order functions. These are less verbose than any alterantive I&amp;rsquo;ve come up with, but have bad mouth-feel.&lt;/p&gt;

&lt;p&gt;Given the phrase has had a new sense for at least almost 30-years old at this point, I&amp;rsquo;m a a little reluctant to be inventing new phrases. Perhaps I should just leave it at this, with this note serving as a historical marker of this accident of language. But I&amp;rsquo;m also insufferably pedantic, and the phrase &lt;em&gt;does&lt;/em&gt; have two meanings, so perhaps I should create a new phrase.&lt;/p&gt;</content></entry>
 <entry>
  <title type="text">What is a model?</title>
  <link rel="alternate" href="https://www.williamjbowman.com/blog/2023/06/15/what-is-a-model/" />
  <id>urn:https-www-williamjbowman-com:-blog-2023-06-15-what-is-a-model</id>
  <published>2023-06-15T20:25:25Z</published>
  <updated>2023-06-15T20:25:25Z</updated>
  <author>
   <name>William J. Bowman</name></author>
  <content type="html">
&lt;p&gt;What is a model, particularly of a programming language? I&amp;rsquo;ve been struggling with this question a bit for some time. The word &amp;ldquo;model&amp;rdquo; is used a lot in my research area, and although I have successfully (by some metrics) read papers whose topic is models, used other peoples&amp;rsquo; research on models, built models, and trained others to do all of this, I don&amp;rsquo;t really understand what a model is.&lt;/p&gt;

&lt;p&gt;Before I get into a philosophical digression on what it even means to understand something, let&amp;rsquo;s ignore all that and try to discover what a model is from first principles.&lt;/p&gt;
&lt;!-- more--&gt;

&lt;h2 id="definitions-of-model"&gt;Definitions of &amp;ldquo;model&amp;rdquo;&lt;/h2&gt;

&lt;p&gt;The apparent place to start to understand the meaning of a word is to read its definition. This is actually no help at all. There are lots of uses of the word &amp;ldquo;model&amp;rdquo;, with several definitions. Here are some.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definition 0&lt;/strong&gt; In science and engineering, a model is &amp;ldquo;an abstract description of a concrete system using mathematical concepts and language&amp;rdquo;. See &lt;a href="https://en.wikipedia.org/wiki/Mathematical_model" title="Mathematical model"&gt;Wikipedia&lt;/a&gt; provides a nice introduction to this kind of model, and the &lt;a href="https://plato.stanford.edu/entries/model-theory/#Modelling" title="Models and Modelling"&gt;Standard Encylopedia of Philosophy&lt;/a&gt; provides a nice explanation in the context of model theory, which will be relevant later in this post.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definition 1&lt;/strong&gt; A &lt;em&gt;syntactic model&lt;/em&gt; (of a type theory) is defined by &lt;a href="https://doi.org/10.1145/3018610.3018620" title="The Next 700 Syntactical Models of Type Theory"&gt;Boulier, Pédrot, and Tabareau&lt;/a&gt; as a translation from one type theory into another that preserves typing, the definition of false, and definitional equivalence. This syntactic model enables the source type theory to inherit properties of the target type theory&amp;mdash;such as consistency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definition 2&lt;/strong&gt; A &lt;em&gt;model&lt;/em&gt; (of a &lt;em&gt;vocabulary&lt;/em&gt; also called a &lt;em&gt;language&lt;/em&gt; \(\sigma\)) in the sense of model theory (as defined by &lt;a href="https://doi.org/10.1007/978-3-662-07003-1" title="Elements of Finite Model Theory"&gt;Elements of Finite Model Theory&lt;/a&gt;) is a &lt;em&gt;\(\sigma\)-structure&lt;/em&gt; (&amp;ldquo;also called a &lt;em&gt;model&lt;/em&gt;&amp;rdquo;) defining a set &lt;em&gt;A&lt;/em&gt; along with 3 sets providing interpretations of that vocabulary. These sets are \(Ic_A\), which interprets each constant in \(\sigma\) as an element of \(A\), \(IP_A\), which interprets each n-ary predicate symbol or relation symbol from \(\sigma\) as an n-ary (set-theoretic) relation between elements of \(A\), and \(If_A\), which interprets each n-ary function symbol in \(\sigma\) as a (set-theoretic) function from n elements of \(A\) to an element of \(A\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definition 3&lt;/strong&gt; The above definition is confusing, since it conflates &lt;em&gt;structure&lt;/em&gt; and &lt;em&gt;model&lt;/em&gt;, which the text later distinguishes with the following separate definition. A &lt;em&gt;model&lt;/em&gt; (of a &lt;em&gt;theory&lt;/em&gt; (over a vocabulary \(\sigma\))) is a &lt;em&gt;structure&lt;/em&gt; (&amp;ldquo;also called a &lt;em&gt;model&lt;/em&gt;&amp;rdquo;) of &lt;em&gt;vocabulary&lt;/em&gt; \(\sigma\) such that every sentence in the theory is interpreted in the structure to make the sentence true. (A &lt;em&gt;theory&lt;/em&gt; is a set of sentences drawn from a vocabulary.) My rephrasing of the definition of model is intentionally confusing and difficult to parse, to make apparent the inherit confusingness created by the several layers of definitions and one definition that defines &amp;ldquo;model&amp;rdquo; using a second definition of &amp;ldquo;model&amp;rdquo;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definition 4&lt;/strong&gt; &lt;a href="https://ncatlab.org/nlab/show/structure+in+model+theory#Definition" title="Definition of 'structure' in model theory"&gt;Nlab hosts an article&lt;/a&gt; with a much clarified definition, which distinguishes &lt;em&gt;language&lt;/em&gt;, &lt;em&gt;theory&lt;/em&gt;, &lt;em&gt;structure&lt;/em&gt;, and &lt;em&gt;model&lt;/em&gt; carefully. In particular, it is careful to only call &lt;em&gt;structure&lt;/em&gt; the interpretation of the &lt;em&gt;language&lt;/em&gt; (call &lt;em&gt;vocabulary&lt;/em&gt; above), and only call &lt;em&gt;model&lt;/em&gt; an interpretation that makes true the &lt;em&gt;axioms&lt;/em&gt; composing the &lt;em&gt;theory&lt;/em&gt; of the &lt;em&gt;language&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definition 5&lt;/strong&gt; &lt;a href="https://twitter.com/carloangiuli/status/1640421574733078528?s=20"&gt;Carlo Anguli once gave me the following definition of model&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
 &lt;p&gt;A collection of interpretation functions that interpret every syntactic category in such that the original relationship is respected.&lt;/p&gt;
 &lt;p&gt;e.g., 
  &lt;br /&gt; - interpret every context as a set, 
  &lt;br /&gt; - interpret every (non-dependent) type as a set, and 
  &lt;br /&gt; - interpret every term-of-a-type indexed-by-a-context as an element-of-the-interpretation-of-that-type indexed-by-elements-of-the-interpretation-of-that-context.&lt;/p&gt;
 &lt;p&gt;Implicit in this definition is that the interpretations must respect equality &amp;mdash; because if you don&amp;rsquo;t respect equality of arguments then you&amp;rsquo;re not a function!&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;This definition seems to be close to &lt;strong&gt;Definition 2&lt;/strong&gt;, as it doesn&amp;rsquo;t mention axioms and their interpretation. However, it might be &lt;strong&gt;Definition 3&lt;/strong&gt; instead, as there could be implicit in the definition of &lt;a href="https://www.williamjbowman.com/blog/2023/06/07/what-is-syntax/" title="What is syntax?"&gt;syntax&lt;/a&gt; an inclusion of all judgements of the programming language, and therefore in the phrase &amp;ldquo;such that the original relationship is respected&amp;rdquo; a requirement that axioms of those judgements become true.&lt;/p&gt;

&lt;p&gt;Also implicit in this definition of model is what it is a model &lt;em&gt;of&lt;/em&gt;. Perhaps a programming language, but it again depends on what &lt;a href="https://www.williamjbowman.com/blog/2023/06/07/what-is-syntax/" title="What is syntax?"&gt;syntax&lt;/a&gt; means and thus what &amp;ldquo;every syntactic category&amp;rdquo; refers to.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;m interested in the requirement that the interpretation is a collection of &lt;em&gt;functions&lt;/em&gt;, which seems to be missing or only implied in some model theory definitions of &amp;ldquo;model&amp;rdquo;.&lt;/p&gt;

&lt;h2 id="so-what-is-a-model"&gt;So what &lt;em&gt;is&lt;/em&gt; a model?&lt;/h2&gt;

&lt;p&gt;One of the first thing that jumps out to me after reviewing the above definitions is that to understand each definition, you &lt;em&gt;have&lt;/em&gt; to reframe the definition of &lt;em&gt;model&lt;/em&gt; into &lt;em&gt;model [of what]&lt;/em&gt;. It really never makes sense to give a definition of merely &amp;ldquo;model&amp;rdquo;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definition 0&lt;/strong&gt; defines a &lt;em&gt;model of a system [of the real world]&lt;/em&gt;. &lt;strong&gt;Definition 1&lt;/strong&gt; defines a &lt;em&gt;model of a type theory&lt;/em&gt;. &lt;strong&gt;Definitions 2&lt;/strong&gt; and &lt;strong&gt;3&lt;/strong&gt; give definitions of a &lt;em&gt;model&lt;/em&gt;, in the sense of model theory, but of two different objects: &lt;em&gt;model of a vocabulary (or language)&lt;/em&gt;, which is more often called a structure, and &lt;em&gt;model of a theory&lt;/em&gt; (which everyone seems to agree is a &amp;ldquo;model&amp;rdquo;). &lt;strong&gt;Definition 4&lt;/strong&gt; makes this distinction very clear. &lt;strong&gt;Definition 5&lt;/strong&gt; seems to use &amp;ldquo;model&amp;rdquo; in the model-theoretic sense, but has abstracted a bit away from a particular notion of &lt;em&gt;theory&lt;/em&gt; and generalized to &lt;a href="https://www.williamjbowman.com/blog/2023/06/07/what-is-syntax/" title="What is syntax?"&gt;&lt;em&gt;syntax&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id="what-is-a-model-of-a-programming-language"&gt;What is a model &lt;em&gt;of&lt;/em&gt; a programming language?&lt;/h2&gt;

&lt;p&gt;I&amp;rsquo;ve had two problems understanding the word &amp;ldquo;model&amp;rdquo; in the context of programming languages.&lt;/p&gt;

&lt;p&gt;First, we use &amp;ldquo;model&amp;rdquo; in three different senses, and I have neither understood that nor understood the relationships between them.&lt;/p&gt;

&lt;ol&gt;
 &lt;li&gt;Model in the sense of an abstract description of a system. This is &lt;strong&gt;Definition 0&lt;/strong&gt;. This sense of &amp;ldquo;model&amp;rdquo; means something like &amp;ldquo;mathematical description&amp;rdquo;. What we want is a description in which we can work using math, so we can make predictions about the real world. Ideally, the predictions we make will be true.&lt;/li&gt;
 &lt;li&gt;Model in the strict sense of model theory. These are &lt;strong&gt;Definitions 2, 3, and 4&lt;/strong&gt;. This sense of &amp;ldquo;model&amp;rdquo; is the closet to having a strict definition. It often carries a set-theoretic connotation, asking for a set defining the domain of values, and three interpretation functions that interpret specifics parts of a theory in specific ways.&lt;/li&gt;
 &lt;li&gt;Model in the generalized sense, inheriting from or related to model theory. I hesitate to even call this distinct from the second sense, but I will anyway. I also hesitate to speculate about history&amp;mdash;perhaps this sense actually predates model theory. But I distinguish it from the second sense, because it frequently generalizes away from the strict 3 category &amp;ldquo;constant symbol&amp;rdquo;, &amp;ldquo;predicate symbol&amp;rdquo;, &amp;ldquo;function symbol&amp;rdquo; specification and doesn&amp;rsquo;t seem beholden to set theory. &lt;strong&gt;Definitions 1 and 5&lt;/strong&gt; use &amp;ldquo;model&amp;rdquo; in this sense.&lt;/li&gt;&lt;/ol&gt;

&lt;p&gt;In the second sense of &amp;ldquo;model&amp;rdquo;, the first sense of the word remains&amp;mdash;we&amp;rsquo;re still interested in a description of some system (the &lt;em&gt;theory&lt;/em&gt;), and of using the model to make predictions or reason. However, since the theory is also mathematical, we can be more rigid about our reasoning requirements&amp;mdash;axioms of the theory &lt;em&gt;must&lt;/em&gt; be true of the model, and relationships &lt;em&gt;must&lt;/em&gt; be preserved in the model. This is rarely true of a model of the real world; &lt;em&gt;e.g.&lt;/em&gt;, the Newtonian model of gravity works pretty well, until it doesn&amp;rsquo;t, so it&amp;rsquo;s a model that doesn&amp;rsquo;t &lt;em&gt;quite&lt;/em&gt; make all axioms true or preserve all relationships.&lt;/p&gt;

&lt;p&gt;The third sense seems closer to the idea of &lt;a href="https://en.wikipedia.org/wiki/Semantics_of_logic" title="Semantics of Logic"&gt;&lt;em&gt;semantics&lt;/em&gt;&lt;/a&gt;, in the mathematical logic sense of the word as assigning meaning or interpretation to &lt;a href="https://www.williamjbowman.com/blog/2023/06/07/what-is-syntax/" title="What is syntax?"&gt;syntax&lt;/a&gt;. In this sense, the word &amp;ldquo;model&amp;rdquo; frequently avoid committing to set theory as a formal foundation, generalizes away from the three interpretation functions, and focuses instead on the &lt;em&gt;relationships&lt;/em&gt; between uninterpreted &lt;a href="https://www.williamjbowman.com/blog/2023/06/07/what-is-syntax/" title="What is syntax?"&gt;syntax&lt;/a&gt; being preserved by the interpretation. For example, in &lt;strong&gt;Definition 1&lt;/strong&gt;, the relationships of interest are well-typedness, definitional equivalence, and falsehood, and the formal foundation is type theory. Category theory seems to come closest to a complete formalization of this sense of the word &amp;ldquo;model&amp;rdquo;, although I&amp;rsquo;ve had a hell of a time understanding that. Nlab articles don&amp;rsquo;t say this explicitly, but reading between the lines in articles linked to from &lt;a href="https://ncatlab.org/nlab/show/model+theory" title="Nlab Article on Model Theory"&gt;the Nlab article on model theory&lt;/a&gt; for the words &lt;a href="https://ncatlab.org/nlab/show/internal+language" title="Nlab Article linked from 'syntax'"&gt;syntax&lt;/a&gt; and &lt;a href="https://ncatlab.org/nlab/show/structure" title="Nlab Article linked from 'semantics'"&gt;semantics&lt;/a&gt; implies that the &lt;a href="https://www.williamjbowman.com/blog/2023/06/07/what-is-syntax/" title="What is syntax?"&gt;idea of syntax&lt;/a&gt;, &lt;em&gt;i.e.&lt;/em&gt;, uninterpreted symbols with relationships between themselves and judgements about them, can be formalized in category theory, and then so can the idea of semantics, &lt;em&gt;i.e.&lt;/em&gt;, providing an interpretation in some other domain of those uninterpreted symbols; a domain in which one can use all the power of the other domain to reason about the judgements one wishes to make about the uninterpreted symbols.&lt;/p&gt;

&lt;p&gt;The second problem with the word &amp;ldquo;model&amp;rdquo; is that we frequently work with two senses simultaneously.&lt;/p&gt;

&lt;p&gt;When I write down a programming language, I&amp;rsquo;m often trying to &lt;em&gt;model&lt;/em&gt; (in the first sense) a real programming language (or some feature of it), one actual software developers use to make real things happen in the real world. I am not merely describing a mathematical object for study. (Okay, sometimes I do that, but usually to the first end, eventually.) When I write down such a model, I may describe the abstract syntax, the typing judgement, and an abstract machines or reduction rules. These form a pretty good mathematical description of how a real language behaves. A compiler will reject syntactically invalid expressions. It may then type check the abstract syntax tree, and reject some possibly semantically invalid expressions. If judged well typed, the compiler may transform the tree into something that runs, and that run-time behaviour can be predicted using the reduction rules.&lt;/p&gt;

&lt;p&gt;However, for much programming languages work, I&amp;rsquo;m not interested in merely predicting the behaviour of a single program. I might want to predict behaviour or properties of the entire language, or its typing judgement, etc. To reason about single programs, the &lt;em&gt;model&lt;/em&gt; (in the first sense) may work well. But it might not work well for, say, trying to decide whether certain types can even be inhabited. To solve this, we might build a &lt;em&gt;model&lt;/em&gt; (in the second or third sense). We interpret the abstract syntax tree and typing judgement in some other domain. That is, the AST and the typing judgement, being a &lt;em&gt;model&lt;/em&gt; in the first sense, form a &lt;em&gt;theory&lt;/em&gt; in the model theoretic sense. We can then construct a model (in the second sense) of a model (in the first sense). The Standard Encyclopedia of Philosophy &lt;a href="https://plato.stanford.edu/entries/model-theory/#Modelling" title="Models and Modelling"&gt;article on model theory&lt;/a&gt; goes into this in detail in the context of model theory, which is great.&lt;/p&gt;

&lt;p&gt;What&amp;rsquo;s more interesting is how these two senses of model interact in programming languages. If one is interested in a model, in the second sense, it may inform how one develops a model (in the first sense). If I know I will want to construct a model (in the second sense) to reason about the typing judgement, I may decide that single-step reduction rules are actually irrelevant; I only care that certain program equivalences hold, really, and any implementation that has those equivalences suffices. So rather than create a model (in the first sense) with an abstract machine or small-step operational semantics, I&amp;rsquo;ll specify an equivalence judgement. This might give less predictive power about a real world implementation, but allow the predictions I do make to apply to many implementations.&lt;/p&gt;

&lt;p&gt;If you see these patterns, you may have some insight into how the author is approaching their work, and in what senses they are using the word &amp;ldquo;model&amp;rdquo;.&lt;/p&gt;
&lt;!-- ## References--&gt;</content></entry>
 <entry>
  <title type="text">What is syntax?</title>
  <link rel="alternate" href="https://www.williamjbowman.com/blog/2023/06/07/what-is-syntax/" />
  <id>urn:https-www-williamjbowman-com:-blog-2023-06-07-what-is-syntax</id>
  <published>2023-06-07T20:58:46Z</published>
  <updated>2023-06-07T20:58:46Z</updated>
  <author>
   <name>William J. Bowman</name></author>
  <content type="html">
&lt;p&gt;I&amp;rsquo;m in the middle of confronting my lack of knowledge about denotational semantics. One of the things that has confused me for so long about denotational semantics, which I didn&amp;rsquo;t even realize was confusing me, was the use of the word &amp;ldquo;syntax&amp;rdquo; (and, consequently, &amp;ldquo;semantics&amp;rdquo;).&lt;/p&gt;

&lt;p&gt;For context, the contents of this note will be obvious to perhaps half of programming languages (PL) researchers. Perhaps half enter PL through math. That is not how I entered PL. I entered PL through software engineering. I was very interested in building beautiful software and systems; I still am. Until recently, I ran my own cloud infrastructure&amp;mdash;mail, calendars, reminders, contacts, file syncing, remote git syncing. I still run some of it. I run secondary spam filtering over university email for people in my department, because out department&amp;rsquo;s email system is garbage. I am &lt;em&gt;way&lt;/em&gt; better at building systems and writing software than math, but I&amp;rsquo;m interested in PL and logic and math nonetheless. Unfortunately, I lack lot of background and constantly struggle with a huge part, perhaps half, of PL research. The most advanced math course I took was Calculus 1. (well, I took a graduate recursion theory course too, but I think I passed that course because it was a grad course, not because I did well.)&lt;/p&gt;

&lt;p&gt;So when I hear &amp;ldquo;syntax&amp;rdquo;, I think &amp;ldquo;oh sure. I know what that is. It&amp;rsquo;s the grammar of a programming language. The string, or more often the tree structure, used to represent the program text.&amp;rdquo;. And that led me to misunderstand half of programming languages research.&lt;/p&gt;
&lt;!-- more--&gt;

&lt;h2 id="the-first-meaning-of-syntax"&gt;The First Meaning of Syntax&lt;/h2&gt;

&lt;p&gt;Syntax has two meanings in programming languages, and both meanings can frequently be found in the same paper.&lt;/p&gt;

&lt;p&gt;The first meaning is the one I gave above. I could give a definition of the syntax (in the first sense) of the lambda-calculus as follows.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;e ::= x | (lambda (x) e) | (e e)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Ah. Beautiful syntax.&lt;/p&gt;

&lt;p&gt;If we were following a standard text, such as &lt;a href="http://www.cs.cmu.edu/~rwh/pfpl/2nded.pdf"&gt;Harper&amp;rsquo;s &lt;em&gt;Practical Foundation for Programming Languages (2nd ed)&lt;/em&gt;&lt;/a&gt;, we might next define the &amp;ldquo;semantics&amp;rdquo; of this &amp;ldquo;syntax&amp;rdquo;. We might define the &amp;ldquo;static semantics&amp;rdquo;, &lt;em&gt;i.e.&lt;/em&gt;, the type system or binding rules, then the &amp;ldquo;dynamic semantics&amp;rdquo;, &lt;em&gt;i.e.&lt;/em&gt;, the rules governing the evaluation behaviour of the syntax. For example, I might write the following small-step operational semantics.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;((lambda (x) e) e') -&amp;gt; e[x := e']&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Ah. Beautiful semantics.&lt;/p&gt;

&lt;p&gt;Except, everything I wrote above, reduction rule included, is also &lt;em&gt;syntax&lt;/em&gt; and &lt;em&gt;not semantics&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id="historical-interlude"&gt;Historical Interlude&lt;/h2&gt;

&lt;p&gt;The words &amp;ldquo;syntax&amp;rdquo; and &amp;ldquo;semantics&amp;rdquo; come from mathematical logic.&lt;/p&gt;

&lt;p&gt;In that context, &amp;ldquo;syntax&amp;rdquo; describes sentences, statements, symbols, formulas, etc, without respect to any meaning. You can write down a logical formula say as "∀ X.P(X, A)" (where &amp;ldquo;A&amp;rdquo; is a logical constant, &amp;ldquo;X&amp;rdquo; is a variable, &amp;ldquo;P&amp;rdquo; is a proposition), and it has no meaning; it&amp;rsquo;s mere syntax. It might be true, or might be false, depending on its interpretation of &amp;ldquo;P&amp;rdquo;, &amp;ldquo;A&amp;rdquo;, and "∀". I could say that it means &amp;ldquo;all leaves are green&amp;rdquo;, which would be false. A more relevant example for PL might be the syntax &lt;code&gt;((lambda (x) x+1) 2) = 3&lt;/code&gt;, which I would certainly like to be true, but it very much depends on what I mean. If &lt;code&gt;+&lt;/code&gt; means string append as in JavaScript, then the statement is false since &lt;code&gt;''.concat(1, 2) = '12'&lt;/code&gt;. Wikipedia is a good start for trying to understand this history of the word &amp;ldquo;syntax&amp;rdquo;: &lt;a href="https://en.wikipedia.org/wiki/Syntax_(logic)"&gt;https://en.wikipedia.org/wiki/Syntax_(logic)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By contrast, in that same context, &amp;ldquo;semantics&amp;rdquo; is the means by which syntax is given an interpretation. Perhaps the most widely used approach to providing an interpretation of syntax is model theory, which I never learned. In model theory, we start with a &amp;ldquo;syntax&amp;rdquo; (or &amp;ldquo;theory&amp;rdquo;). This theory is a collection of constants, function symbols, and predicate symbols. A model then is a map from the uninterpreted syntax to some interpretation that preserves relationships. I&amp;rsquo;ll say more of this in a later post, but for now, consider the following example. I might provide a model of our earlier example that interprets &lt;code&gt;+&lt;/code&gt; as &lt;code&gt;''.concat&lt;/code&gt;, and &lt;code&gt;=&lt;/code&gt; is mapped to, say &lt;code&gt;===&lt;/code&gt;. This preserves relationships, if all my constants are mapped to strings. Wikipedia is a good source for this history too: &lt;a href="https://en.wikipedia.org/wiki/Semantics_of_logic"&gt;https://en.wikipedia.org/wiki/Semantics_of_logic&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id="when-semantics-is-the-syntax"&gt;When Semantics is the Syntax&lt;/h2&gt;

&lt;p&gt;What&amp;rsquo;s interesting about this history is how it was adopted in programming languages, and evolved in two different ways. On the one hand, a programming language grammar is &lt;em&gt;syntax&lt;/em&gt;, in the sense of being uninterpreted statements. That syntax can be given a semantics, an interpretation, by using operation semantics (this is the sense in which operational semantics &lt;em&gt;is&lt;/em&gt; a semantics). The operational semantics provides an interpretation to our grammar.&lt;/p&gt;

&lt;p&gt;But, in another sense, the grammar, typing rules, and evaluation rules (the &amp;ldquo;syntax&amp;rdquo;, &amp;ldquo;static semantics&amp;rdquo;, and &amp;ldquo;dynamic semantics&amp;rdquo;) are mere syntax, in the older logical sense. They are a theory, in the model-theoretic sense. To see why, we must understand what the earlier example &lt;code&gt;((lambda (x) x+1) 2) = 3&lt;/code&gt; means. Or in fact, realize that it doesn&amp;rsquo;t mean anything at all.&lt;/p&gt;

&lt;p&gt;To write this down is to write down a proposition about the grammar: that one piece of the grammar is equal to another. Except I didn&amp;rsquo;t write a proposition that the two were equal. I wrote the uninterpreted proposition symbol &lt;code&gt;=&lt;/code&gt;, the syntax &lt;code&gt;=&lt;/code&gt;, next to two pieces of uninterpreted grammar, two other pieces of syntax. Every syntactic judgment about our grammar is itself syntax, in the model theoretic sense. At least, this is true if we follow the tradition of writing them down synthetically, axiomatically, about the grammar, as is done in standard programming languages textbooks such as &lt;a href="https://www.worldcat.org/search?q=bn:0262162091"&gt;&lt;em&gt;Types and Programming Languages&lt;/em&gt;&lt;/a&gt; or &lt;a href="http://www.cs.cmu.edu/~rwh/pfpl/2nded.pdf"&gt;&lt;em&gt;Practical Foundations for Programming Languages&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this view, the typing rules and reduction relations are syntax. This is a bizarre perspective from a software engineering perspective, but makes sense from the mathematical logic perspective.&lt;/p&gt;

&lt;p&gt;With this perspective, it might make sense to call &amp;ldquo;operational semantics&amp;rdquo; &amp;ldquo;syntactic semantics&amp;rdquo;, or to imagine a tower of syntax and semantics where one level&amp;rsquo;s semantics become the next level&amp;rsquo;s syntax. This view finally helped me make sense of why we call &amp;ldquo;syntactic logical relations&amp;rdquo; &lt;em&gt;syntactic&lt;/em&gt;, when they are clearly semantics. (A problem I danced around in &lt;a href="https://www.williamjbowman.com/blog/2023/03/24/what-is-logical-relations/"&gt;my previous post on logical relations&lt;/a&gt;.)&lt;/p&gt;

&lt;p&gt;This perspective is also useful, for two reasons. The first is that reasoning purely syntactically, while very general, prevents you from importing any other reasoning principles from any other domain. By viewing the typing system as syntax, and then building a model of it (and by necessity, the programming language terms) in, say, set theory, we can import all set-theoretic reasoning in our attempts to reason about our type system. But more than that, we can reinterpret the syntax freely, to prove general results. While I might have written a type system using syntax that looks like numbers, I could build a model that interprets that type system as over strings, and know that actually the entire system is safe for strings, too. Appropriately generalized, I wouldn&amp;rsquo;t need to do any additional proofs.&lt;/p&gt;

&lt;p&gt;Unfortunately, this double meaning of the word syntax seems to be completely taken for granted by some. nLab is a good example of this. To quote from the introduction to the nLab model theory page:&lt;/p&gt;

&lt;blockquote&gt;
 &lt;p&gt;On the one hand, there is &lt;a href="https://ncatlab.org/nlab/show/internal+language"&gt;syntax&lt;/a&gt;. On the other hand, there is &lt;a href="https://ncatlab.org/nlab/show/structure"&gt;semantics&lt;/a&gt;. Model theory is (roughly) about the relations between the two: model theory studies classes of &lt;a href="https://ncatlab.org/nlab/show/models"&gt;models&lt;/a&gt; of &lt;a href="https://ncatlab.org/nlab/show/theories"&gt;theories&lt;/a&gt;, hence classes of “&lt;a href="https://ncatlab.org/nlab/show/structures+in+model+theory"&gt;mathematical structures&lt;/a&gt;”.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;What&amp;rsquo;s most interesting about this quote isn&amp;rsquo;t what it says, but what it links to. The link for &amp;ldquo;syntax&amp;rdquo; is to the page on the internal logic of a category. From the software perspective, this is not syntax, but semantics. How on earth could it be syntax? The link for &amp;ldquo;semantics&amp;rdquo; is to the page on structure, the idea of equipping a category with a particular functor. How on earth is that any more semantics than the original abstract nonsense version of syntax?&lt;/p&gt;

&lt;p&gt;Before I understood &amp;ldquo;syntax&amp;rdquo;, I couldn&amp;rsquo;t make any sense of that, but now I&amp;rsquo;m beginning to understand. The internal logic of a category in some sense must be able to express the grammar of a language, and the judgments of a language, but in a purely syntactic way&amp;mdash;in the same way that when I write down the grammar and typing rules of a language, I don&amp;rsquo;t refer to any interpretation of those symbols beyond the way I combine them on the page. Then the semantics or structure is a the particular functor over that category, providing an interpretation, a semantics, of that original category (the syntax).&lt;/p&gt;

&lt;p&gt;Anyway, now I think I&amp;rsquo;m ready to understand what a model is.&lt;/p&gt;</content></entry>
 <entry>
  <title type="text">What is logical relations?</title>
  <link rel="alternate" href="https://www.williamjbowman.com/blog/2023/03/24/what-is-logical-relations/" />
  <id>urn:https-www-williamjbowman-com:-blog-2023-03-24-what-is-logical-relations</id>
  <published>2023-03-24T23:32:03Z</published>
  <updated>2023-03-24T23:32:03Z</updated>
  <author>
   <name>William J. Bowman</name></author>
  <content type="html">
&lt;p&gt;I have long struggled to understand what a logical relation is. This may come as a surprise, since I have used logical relations a bunch in my research, apparently successfully. I am not afraid to admit that despite that success, I didn&amp;rsquo;t really know what I was doing&amp;mdash;I&amp;rsquo;m just good at pattern recognition and replication. I&amp;rsquo;m basically a machine learning algorithm.&lt;/p&gt;

&lt;p&gt;So I finally decided to dive deep and figure it out: what is a logical relation?&lt;/p&gt;

&lt;p&gt;As with my previous note on realizability, this is a copy of my personal notebook on the subject, which is NOT AUTHORITATIVE, but maybe it will help you.&lt;/p&gt;
&lt;!-- more--&gt;

&lt;p&gt;Here&amp;rsquo;s my working definition of a logical relation:&lt;/p&gt;

&lt;ol&gt;
 &lt;li&gt;A realizability semantic model,&lt;/li&gt;
 &lt;li&gt;built of predicates over syntax,&lt;/li&gt;
 &lt;li&gt;that &lt;em&gt;reflects&lt;/em&gt; judgments and structures from semantics to syntax.&lt;/li&gt;&lt;/ol&gt;

&lt;p&gt;Point 1 is subtle; it implies that the logical relation is both a model, and a &lt;a href="/blog/2022/10/05/what-is-realizability/"&gt;realizability semantics&lt;/a&gt;. Unfortunately, I still don&amp;rsquo;t know what a model is, so I&amp;rsquo;m going to have work with the following probably wrong oversimplification: the logical relation must take (syntactically) equal terms to (semantically) equal terms. Which notion of syntactic equality though? I&amp;rsquo;m not sure, and I&amp;rsquo;m going to ignore it for now.&lt;/p&gt;

&lt;p&gt;Point 2 is actually more specific than necessary. We don&amp;rsquo;t need to predicates over syntax specifically, but really over some base model. It&amp;rsquo;s easier for me to think of this as &amp;ldquo;syntax&amp;rdquo;, though.&lt;/p&gt;

&lt;p&gt;Point 3 is quite difficult to make precise without making a lot of this more precise in a mathematical framework. Jon Sterling gave me the following helpful definition:&lt;/p&gt;

&lt;blockquote&gt;
 &lt;p&gt;A logical relation on a model M (viewed as a category) is then a model that is constructed in the following way:&lt;/p&gt;
 &lt;ol&gt;
  &lt;li&gt;
   &lt;p&gt;Choose some functor R : M &amp;mdash;&amp;gt; E where E is a sufficiently structured category (e.g. the category of sets, or something else!). The most basic example of a functor R is the &amp;ldquo;global sections functor&amp;rdquo; M &amp;mdash;&amp;gt; Set, which sends every type in M to the set of &lt;em&gt;closed elements&lt;/em&gt; of that type. This is exactly the usual “non-Kripke logical relations"; to get Kripke logical relations, you replace Set with a functor category (presheaf category) and choose a more interesting functor R.&lt;/p&gt;&lt;/li&gt;
  &lt;li&gt;
   &lt;p&gt;Now define a new category G, as a category whose objects are pairs of an object A of M, together with a subobject of R(A). A morphism in G from (A,A’) to (B, B&amp;rsquo;) is given by a morphism (f : A -&amp;gt; B) that sends elements satisfying A&amp;rsquo; to elements satisfying B&amp;rsquo;.&lt;/p&gt;&lt;/li&gt;
  &lt;li&gt;
   &lt;p&gt;You have to show that the category G is actually a model of your language (e.g. show that it has function spaces, booleans, whatever). Doing so is the FTLR.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
 &lt;p&gt;Note that there are some ways to generalize the situation above, but this is basically what logical relations are.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Point 3 is also is more specific than necessary; &amp;ldquo;syntax&amp;rdquo; can be generalized to be &amp;ldquo;base model&amp;rdquo;.&lt;/p&gt;

&lt;p&gt;Despite the complexity, we can see point 3 in action in some examples below.&lt;/p&gt;
&lt;!-- https://types.pl/@wilbowma/110079663033785019--&gt;

&lt;h2 id="what-are-logical-relations-historically"&gt;What are logical relations, historically?&lt;/h2&gt;

&lt;h3 id="tait1967---intensional-interpretations-of-functionals-of-finite-type-i"&gt;tait1967 - Intensional interpretations of functionals of finite type I&lt;/h3&gt;

&lt;p&gt;Logical relations are sometimes called &amp;ldquo;Tait&amp;rsquo;s Method&amp;rdquo;, dating back to &lt;a href="https://doi.org/10.2307/2271658"&gt;Tait&lt;/a&gt;, as far as I can tell.&lt;/p&gt;

&lt;p&gt;In this paper, Tait proves that System T with bar induction is a conservative extension of intuitionistic analysis U_1, which is intuitionistic arithmetic plus quantification over functions plus the axiom (schema) of choice plus bar induction. This conservative extension property is the semantic property of interest. The proof starts with a proof that T without bar induction is a conservative extension of just intuitionistic arithmetic (no choice or bar induction).&lt;/p&gt;

&lt;p&gt;To do this, Tait develops a type-indexed predicate over System T terms (without bar induction), providing a U_0 term for all T terms of each type. These predicates M_t, C_t, and E_t are (I think) what we refer to as a logical relation. In particular, the C_t relation provides the interpretation of T values of type t, M_t seems to deal with variables, and E_t seems to be a binary relation defining semantics (&amp;ldquo;weak α-definitional equality&amp;rdquo;) of terms.&lt;/p&gt;

&lt;p&gt;Theorem V (page 205) uses this logical relation to prove that, for all semantics values at the same type, (weak α-) definitional equality is decidable: they either are or are not related in E_t. This seems to be the key point: the definitional equality is reflected out of the semantics of terms, so it can apply to the syntax of terms.&lt;/p&gt;

&lt;p&gt;This use of logical relation seems to also be a realizability semantics, since it it assigns syntactic types to a collection of semantics terms, by induction over syntactic types, where the realizers are a subset of all possible semantics terms.&lt;/p&gt;

&lt;p&gt;However, it seems to be more than a realizability semantics, too. What seems very important in this paper is that the semantics preserves structure, namely definitional equality. Perhaps implicitly though, other pieces are important. For example, T functions are interpreted as U functions, although it&amp;rsquo;s not clear to me that this is critical.&lt;/p&gt;

&lt;p&gt;This is in contrast to Kleene&amp;rsquo;s (kleene1945) realizability, which did not seem concerned with structure, but only the existence of the realizers.&lt;/p&gt;

&lt;h3 id="plotkin1973---lambda-definability-and-logical-relations"&gt;plotkin1973 - Lambda-definability and logical relations&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.cl.cam.ac.uk/~nk480/plotkin-logical-relations.pdf"&gt;Plotkin&lt;/a&gt; seems to be responsible for the name, and perhaps rediscovering logical relations in the context of programming languages.&lt;/p&gt;

&lt;p&gt;Plotkin helpfully gives us a definition of &amp;ldquo;logical&amp;rdquo;, as well, and it seems quite importantly related to part 3 of my working definition. Plotkin defines a relation R as logical if it is:&lt;/p&gt;

&lt;ol&gt;
 &lt;li&gt;a subset of any D_k from the carrier any D∞ model (this seems to correspond  to &amp;ldquo;admissible relations&amp;rdquo; in modern logical relations parlance);&lt;/li&gt;
 &lt;li&gt;the relation is preserved by functions in D. That is, the relation holds on a  function f in D_k iff for all arguments x, R(x) implies R (f x)  (extended to the n-ary case for n-ary relations).&lt;/li&gt;&lt;/ol&gt;

&lt;p&gt;This suggests that it is important the logical relation is somehow interpreting syntactic structures as semantic structures, as in the case of Tait&amp;rsquo;s model interpreting syntactic functions as semantic functions. More generally, we likely want this property of all structures in the languages: syntactic pairs are interpreted as semantic pairs, etc. Jon&amp;rsquo;s category theoretical definition seems to generalize Plotkin&amp;rsquo;s definition nicely.&lt;/p&gt;

&lt;p&gt;This denotational logical relation also shows us a logical relation that is not defined over syntax. Instead, it is a relation over some arbitrary non-trivial D∞ model. The author mentions that since they can interpret syntax in a D∞ model, they informally treat the logical relation as over syntax sometimes, which I suppose could be made formal easily enough.&lt;/p&gt;

&lt;h2 id="how-is-logical-relations-used-in-pl"&gt;How is &amp;ldquo;logical relations&amp;rdquo; used in PL?&lt;/h2&gt;

&lt;h3 id="ahmed2006---step-indexed-syntactic-logical-relations-for-recursive-and-quantified-types"&gt;ahmed2006 - Step-Indexed Syntactic Logical Relations for Recursive and Quantified Types&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://doi.org/10.1007/11693024_6"&gt;In this paper&lt;/a&gt;, Ahmed is concerned with &lt;em&gt;syntactic&lt;/em&gt; logical relations for recursive and quantified types, in particular for reasoning about contextual equivalence. Likely due to Ahmed&amp;rsquo;s work, this kind of syntactic logical relation seems to be what most people mean or think when they say &amp;ldquo;logical relation&amp;rdquo;, although that may be changing.&lt;/p&gt;

&lt;p&gt;The desired property of the logical relation then is that two related semantic terms should be contextually equivalent in the syntax. That is, the logical relation reflects (from semantics to syntax) equivalence.&lt;/p&gt;

&lt;p&gt;Strangely (for a realizability model), this particular syntactic logical relation also reflects typing: semantic terms in the relation are also guaranteed to be well-typed in the syntax. In contrast, some uses of &amp;ldquo;logical relations&amp;rdquo; enable semantics terms to be syntactically ill-typed. Such logical relations might be better called realizability models, although they do something reflect some structure, so perhaps reflecting typability is not a critical point of reflecting structure.&lt;/p&gt;

&lt;p&gt;Ahmed in the introduction points out an interesting distinction: that logical relations can be either denotational, or syntactic. Syntactic logical relations model syntax as sets of syntactic values such that some property holds over that syntax. By contrast, denotational logical relations model syntax as some denotational object,  Syntactic logical relations are useful for proving properties of the operational semantics directly. Denotational models instead model syntax as denotational objects, such as, &lt;em&gt;e.g.&lt;/em&gt;, sets of set-theoretic functions over elements of a D∞ model in plotkin1973. This is useful for easily proving meta-theoretical properties by reflecting properties of the denotation into the syntax, but not necessarily about the operational semantics directly.&lt;/p&gt;

&lt;p&gt;For example, Tait uses a &amp;ldquo;denotational logical relation&amp;rdquo; into intuitionistic analysis to prove that definitional equality of System T is decidable&amp;mdash;the definition of definitional equality, in the model, and its proof of decidability, are reflected back into the syntax; this requires no operational semantics at all. Plotkin uses a denotational logical relation, into domain theory, to show that certain λ-calculus constructs are or are not definable&amp;mdash;existence of a term in the logical relation is reflected into the syntax as a definable expression. Neither of these is a syntactic logical relation; the semantic values never mention syntactic values directly.&lt;/p&gt;

&lt;p&gt;Ahmed uses a &amp;ldquo;syntactic logical relation&amp;rdquo; to prove something about the operational semantics, namely, to prove contextual equivalence (an operational notion), indirectly. Direct proofs of contextual equivalence are difficult. So instead, a semantic proof of equivalence is reflected back into the syntax as ta proof of contextual equivalence. This requires structuring the logical relation into a denotation of sets of syntactic terms that evaluate in the operational semantics, so that being in the relation tells us something about evaluation in the operational semantics, which tells us something about contextual equivalence.&lt;/p&gt;

&lt;h3 id="abel2018---decidability-of-conversion-for-type-theory-in-type-theory"&gt;abel2018 - Decidability of conversion for type theory in type theory&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://doi.org/10.1145/3158111"&gt;Abel &lt;em&gt;et al.&lt;/em&gt;&lt;/a&gt; define a syntactic logical relation for typed, reducible (and equivalent) terms, to prove decidability of conversion for type theory. Here, the use of syntactic logical relation is important for proving a particular conversion algorithm over the syntax is decidable.&lt;/p&gt;

&lt;p&gt;The interesting feature of this logical relation is the generalization from a model inductively defined over types, to inductively defined over judgments. This demonstrates a weakness in my working definition of logical relation and realizability, since I defined &amp;ldquo;realizability&amp;rdquo; in terms of models inductively defined over types.&lt;/p&gt;

&lt;h3 id="timany2022---a-logical-approach-to-type-soundness"&gt;timany2022 - A Logical Approach to Type Soundness&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://iris-project.org/pdfs/2022-submitted-logical-type-soundness.pdf"&gt;This paper&lt;/a&gt; is interesting because it uses a syntactic logical relation that intentionally does not reflect typing, as many syntactic logical relations cdo. Semantically valid terms are not necessarily syntactically valid. In other ways, it looks very much like a logical relation: syntactic pairs are semantic pairs, sums sums, functions functions, etc.&lt;/p&gt;

&lt;p&gt;The key property this paper is interested in is type safety: all well-typed terms are well-defined in the operational semantics, i.e., they evaluate to values or well-defined errors or fail to terminate, but importantly, do not get stuck. &amp;ldquo;in &lt;em&gt;the&lt;/em&gt; operational semantics&amp;rdquo; is important to understanding why this is a syntactic logical relation; it must model terms as sets of syntactic values to reason about the operational semantics given in the paper.&lt;/p&gt;

&lt;p&gt;However, one could imagine proving a slightly different form of type safety with a denotational logical relation. Giving a logical relation into an arbitrary model with a well-defined notion of evaluation would be implicitly a proof of type safety: that &lt;em&gt;there exists&lt;/em&gt; a model that is type safe. The ability to reflect from semantics to syntax provides a mechanism for constructing that evaluation over syntax. So while the denotational logical relation provides no direct proof about the operational semantics, it may provide a mechanism for a type-safe-by-construction operational semantics. (This reflecting evaluation out of the semantics seems very related to the idea of normalization-by-evaluation, but I&amp;rsquo;m not clear on this.)&lt;/p&gt;</content></entry>
 <entry>
  <title type="text">What is realizability?</title>
  <link rel="alternate" href="https://www.williamjbowman.com/blog/2022/10/05/what-is-realizability/" />
  <id>urn:https-www-williamjbowman-com:-blog-2022-10-05-what-is-realizability</id>
  <published>2022-10-05T21:54:39Z</published>
  <updated>2022-10-05T21:54:39Z</updated>
  <author>
   <name>William J. Bowman</name></author>
  <content type="html">
&lt;p&gt;I recently decided to confront the fact that I didn&amp;rsquo;t know what &amp;ldquo;realizability&amp;rdquo; meant. I see it in programming languages papers from time to time, and could see little rhyme or reason to how it was used. Any time I tried to look it up, I got some nonsense about constructive mathematics and Heyting arithmetic, which I also knew nothing about, and gave up.&lt;/p&gt;

&lt;p&gt;This blog post is basically a copy of my personal notebook on the subject, which is NOT AUTHORITATIVE, but maybe it will help you.&lt;/p&gt;
&lt;!-- more--&gt;

&lt;p&gt;My best understanding of realizability right now, in programming languages (PL) terms, is:&lt;/p&gt;

&lt;ol&gt;
 &lt;li&gt;A technique for assigning each &lt;em&gt;syntactic type&lt;/em&gt; to a collection of &lt;em&gt;semantic terms&lt;/em&gt;;&lt;/li&gt;
 &lt;li&gt;By &lt;em&gt;induction&lt;/em&gt; over syntactic types;&lt;/li&gt;
 &lt;li&gt;Where the semantic terms that are &lt;em&gt;realizers&lt;/em&gt;&amp;mdash;i.e., included in the collection related to some syntactic type&amp;mdash;are a sub-collection of all possible terms in the semantic domain. That is, there are valid semantic terms not associated with any syntactic type.&lt;/li&gt;&lt;/ol&gt;

&lt;p&gt;I use the word &amp;ldquo;collection&amp;rdquo; rather than &amp;ldquo;set&amp;rdquo; to avoid invoking set theory.&lt;/p&gt;

&lt;p&gt;Graphically, we can represent this as follows:&lt;/p&gt;

&lt;div class="figure"&gt;&lt;img src="/img/realizability.png" alt="" title="Realizability" /&gt;
 &lt;p class="caption"&gt;&lt;/p&gt;&lt;/div&gt;

&lt;p&gt;The point of the technique is that clause 2 gives us a proof technique by induction, and clause 3 means we can relate the collection of terms (or proofs) to some other well-known collection. This yields a proof technique for metatheoretic properties about the collection, such as that there are only terminating terms in the collection of realizers, or there are only recursive functions and therefore some classical things remain unprovable.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;m not entirely sure that clause 2, induction, is necessary, and I can&amp;rsquo;t find anything explicit about clause 3, but they seem to be true historically and in many uses of the term.&lt;/p&gt;

&lt;p&gt;Okay so how did I get to this understanding?&lt;/p&gt;

&lt;h2 id="what-is-realizability-historically"&gt;What is realizability, historically?&lt;/h2&gt;

&lt;h3 id="kleene1945---on-the-interpretation-of-intuitionistic-number-theory"&gt;kleene1945 - On the Interpretation of Intuitionistic Number Theory&lt;/h3&gt;

&lt;p&gt;Realizability seems to come from Kleene&amp;rsquo;s paper &lt;a href="https://doi.org/10.2307/2269016"&gt;&amp;ldquo;On the Interpretation of Intuitionistic Number Theory&amp;rdquo;&lt;/a&gt;. I say &amp;ldquo;seems to&amp;rdquo; as Kleene attributes the &amp;ldquo;detailed investigation of the notion of realizability&amp;rdquo; to David Nelson, attributes several of the results in the paper to Nelson, and claims that the main results of the paper are joint work with Nelson. But the paper only has Kleene&amp;rsquo;s name on it, and Kleene claims in the first footnote that they introduced the idea of realizability to Nelson in a seminar. So anyway, realizability seems to come from Kleene, and this is the canonical paper cited for the technique.&lt;/p&gt;

&lt;p&gt;In this paper, realizability is quite specific. It&amp;rsquo;s a technique that takes an intuitionistic first-order logic formula about Peano arithmetic (Heyting arithmetic) and constructs a natural number from it, representing the (constructive) proof of that formula. Only provable formulas are realized. The point of this exercise is to prove various metatheorems about the realized language: is it consistent, and what are provable/unprovable in the intuitionistic formulae.&lt;/p&gt;

&lt;p&gt;Intuitively, something is unprovable if there exists a formula, but there does not exist a realization of it. This can be shown by connecting the formula to the set of realizers (in this case, natural numbers), but showing that there cannot exist a related natural number (or, more often, function on natural numbers represented by its Gödel number) with the properties required of the realizability interpretation. The simplest example: since &amp;ldquo;false&amp;rdquo; is unprovable (it has no realization, by construction), the intuitionistic logic is consistent.&lt;/p&gt;

&lt;p&gt;This also lets us prove something about the class of all provable statements. Since we have a method for constructing something from any provable (or true) statement, we can say something about the set of all provable statement in relation to the realizers. Kleene mentions one consequence is that the intuitionistic calculus cannot prove the existance of any function other than a general recursive function, since those are the only functions constructed in the realizability interpretation. This tells us, for example, that the intuitionistic calculus is different from classical set theory, which contains other functions.&lt;/p&gt;

&lt;p&gt;An important detail in this paper that clarifies the distinction between the intuitionistic and the classical happens in Clause 6, on page 113. This is the definition of the realizability interpretation for existential quantification ∃x.A(x). This has a realization if, for some &lt;strong&gt;x&lt;/strong&gt;, A(&lt;strong&gt;x&lt;/strong&gt;) has a realization. It&amp;rsquo;s important to notice that this second &amp;ldquo;for some &lt;strong&gt;x&lt;/strong&gt;&amp;rdquo; quantification happens in the metalanguage, namely, classical set theory, and therefore could be choosen by Choice. Kleene discusses this on page 118, where he uses the word &amp;ldquo;classically&amp;rdquo; as a modifier on various quantifiers to remind us that, when working with the quantification and realizers directly, we are working in a classical system in which intuitionistic proofs also exist.&lt;/p&gt;

&lt;p&gt;What seems to be going on here is that the realizers are something like the intuitionistic subset of classical set theory. I think that statement isn&amp;rsquo;t exactly true; Kleene uses classical choice when working with the realizers to show there are unprovable theorems. For example, a realizer parameterized over (classically) &lt;em&gt;all&lt;/em&gt; variables may not correspond to an intuitionistic formula. So it&amp;rsquo;s not that the realizers are only intuitionistic, I think. But any particular realizer is (must be)? The important point may be the realizers are a subset of the whole system, and thus we can prove interesting metatheorems that rely on distinguishing the realizers (and therefore, the formulae they realizer) from all the things in the full system.&lt;/p&gt;

&lt;h3 id="amadio1998---domains-and-lambda-calculi-chapter-15"&gt;amadio1998 - Domains and Lambda-Calculi, Chapter 15&lt;/h3&gt;

&lt;p&gt;Chapter 15 of Amadio and Currien&amp;rsquo;s book &lt;a href="https://doi.org/10.1017/cbo9780511983504"&gt;&amp;ldquo;Domains and Lambda-Calculus&amp;rdquo;&lt;/a&gt; introduces realizability in its historical context. The introduction formalizes Kleene&amp;rsquo;s work as an example, and discusses its use.&lt;/p&gt;

&lt;p&gt;They emphasize two things, which seem to confirm some of my understanding:&lt;/p&gt;

&lt;ol&gt;
 &lt;li&gt;The realizability relation is defined inductively over &lt;em&gt;formulas&lt;/em&gt;, and relates &lt;em&gt;formulas&lt;/em&gt; to &lt;em&gt;proofs&lt;/em&gt;.&lt;/li&gt;
 &lt;li&gt;The use lets us reason about all &lt;em&gt;proofs&lt;/em&gt; in the system.&lt;/li&gt;&lt;/ol&gt;

&lt;p&gt;This is the best definition of realizability I&amp;rsquo;ve seen, and applies both to Kleene&amp;rsquo;s original, but also to uses in PL.&lt;/p&gt;

&lt;p&gt;The authors point out that Kleene&amp;rsquo;s original goal was to prove consistency. They then confirm my above intuitions, that the realizability interpretation also lets us prove metatheorems about what is provable/unprovable in the realized system. However, they note that one application of this is to find &lt;em&gt;unprovable&lt;/em&gt; &lt;em&gt;true&lt;/em&gt; statements, which can be consistently axiomatized back into the original system. There are proofs in the set of realizers, i.e., true statements, that are never constructed by the realizability interpretation. These could be added back to the original system to enrich it.&lt;/p&gt;

&lt;p&gt;This latter use seems to confirm one feature of realizability that isn&amp;rsquo;t explicit stated anywhere, but seems to be true of all realizability interpretations I&amp;rsquo;ve seen: that the realizers are a strict subsystem of some larger formal system.&lt;/p&gt;

&lt;h2 id="how-is-realizability-used-in-pl"&gt;How is &amp;ldquo;realizability&amp;rdquo; used in PL?&lt;/h2&gt;

&lt;p&gt;In programming languages, we&amp;rsquo;re not often concerned with intuitionistic vs classical logic; we&amp;rsquo;re working constructively by default. In fact, many of the uses of &amp;ldquo;realizability&amp;rdquo; in PL don&amp;rsquo;t seem to be related to logic at all, but to modeling well-typed programs. And while, sure, these are related by Curry-Howard, the difference seems important to me. So what does realizability mean in this context?&lt;/p&gt;

&lt;p&gt;In most uses in PL, the important feature seems to be clause 3 in my definition above: the collection of all values is larger than the set of realizers. In PL, this suggests that we&amp;rsquo;re ascribing types to &amp;ldquo;untyped&amp;rdquo; terms, and the realizers are those that are semantically well typed, but not necessarily syntactically well typed. The full collection contains also untyped terms, and we can therefore prove through realizability that the type system rules out ill-typed terms.&lt;/p&gt;

&lt;p&gt;There do seem to be some examples in PL that are explicitly relating classical and intuitionistic ideas, namely those trying to import constructive interpretations of classic logic. I&amp;rsquo;m not really interested in those, and I think the connection to realizability is much more clear in those applications, so I&amp;rsquo;ll ignore that area.&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s look at some examples.&lt;/p&gt;

&lt;h2 id="benton2010---realizability-and-compositional-compiler-correctness-for-a-polymorphic-language"&gt;benton2010 - Realizability and Compositional Compiler Correctness for a Polymorphic Language&lt;/h2&gt;

&lt;p&gt;In &lt;a href="https://nickbenton.name/cccmsrtr.pdf"&gt;&amp;ldquo;Realizability and Compositional Compiler Correctness for a Polymorphic Language&amp;rdquo;&lt;/a&gt;, Benton and Hur define a &amp;ldquo;realizability&amp;rdquo; interpretation of System F types realized by terms in low-level language, for proving some compiler correctness properties. The terms realize the types, and this lets us talk about which low-level programs are valid to link with, without restricting the set of linkable programs to only those generated by the compiler.&lt;/p&gt;

&lt;p&gt;This has lost all connection to intuitionistic vs classical logic, but I suppose it keeps the key features of the technique: types (formula) of one language are realized by terms in another, and there is some concern that the realizers should be a subset of all terms. Not all low-level programs should be valid, but some set of them should be.&lt;/p&gt;

&lt;h2 id="nakano2000---a-modality-for-recursion"&gt;nakano2000 - A Modality for Recursion&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://doi.org/10.1109/LICS.2000.855774"&gt;&amp;ldquo;A Modality for Recursion&amp;rdquo;&lt;/a&gt; was actually the start of my realizability journey. This paper starts by defining a collection of models (β-models) of the untyped λ-calculus. It then defines the class of realizability models, in terms of β-models, for an extrinsically typed λ-calculus with equi-recursive types. A realizability model is parameterized by a β-model, and is a relation inductively defined over types to their realizers, which are values drawn from the β-model.&lt;/p&gt;

&lt;p&gt;So why is this realizability? Well, I don&amp;rsquo;t see anything to do with intuitionistic vs classical. But, the set of all values is larger than the set of realizers, which seems to be important to all uses of &amp;ldquo;realizability&amp;rdquo;, and important for this result in particular. In this paper, this is used to show that the dot modality rules out some valid β-model terms, namely those that would correspond to non-terminating λ terms.&lt;/p&gt;

&lt;p&gt;Later in the paper, they define a &amp;ldquo;realizability interpretation&amp;rdquo;. This seems to be distinct from the collection of all realizability models in that they pick a particular set of realizers? So, it ought to be a realizability model, I guess? But they don&amp;rsquo;t say so explicitly. The interpretation is still quite heavily parameterized, but it does seem to fix or restrict the set of realizers. Anyway, this interpretation includes all the features of my definition above: it&amp;rsquo;s inductively defined over types, relating types to (a semantic model of) untyped λ terms, for the purposes of proving something about the collection of realizers as they related to the collection of all untyped λ terms.&lt;/p&gt;</content></entry>
 <entry>
  <title type="text">Notes on "Ur: Statically-Typed Metaprogramming ..."</title>
  <link rel="alternate" href="https://www.williamjbowman.com/blog/2015/02/14/notes-on-ur-statically-typed-metaprogramming/" />
  <id>urn:https-www-williamjbowman-com:-blog-2015-02-14-notes-on-ur-statically-typed-metaprogramming</id>
  <published>2015-02-14T17:22:11Z</published>
  <updated>2015-02-14T17:22:11Z</updated>
  <author>
   <name>William J. Bowman</name></author>
  <content type="html">
&lt;p&gt;Today I read &lt;a href="http://adam.chlipala.net/papers/UrPLDI10/"&gt;Ur: Statically-Typed Metaprogramming with Type-level Record Computation&lt;/a&gt;. This paper presents the Ur language, a functional programming language based on an extension of System Fω. The novel idea is to use type-level functions as a form of type-safe meta-programming. The paper claims this novel idea enables safe heterogeneous and homogeneous meta-programming in Ur.&lt;/p&gt;

&lt;p&gt;The interesting insight is that type-level computation may be valuable outside of dependently typed languages. The paper quickly and easily makes this case. The type-level computations reduce type annotations by enabling the programmer to compute types rather than manually write them everywhere. This could be a useful form of meta-programming in any typed language.&lt;/p&gt;

&lt;p&gt;The claims about heterogeneous and homogeneous meta-programming seem overstated. Ignoring the novel ability to compute type annotations, type-safe heterogeneous programming could be as easily accomplished in any other type-safe language. I could just as easily (or more easily) write a program in Coq, ML, Haskell, or Typed Racket that generates HTML and SQL queries as I could in Ur. As for homogeneous meta-programming, restricting the meta-programs to record computations at the type-level seems to severely restricts the ability to generate code at compile-time and abstract over syntax, features which are provided by general-purpose meta-programming systems such as Racket&amp;rsquo;s macros or Template Haskell.&lt;/p&gt;</content></entry>
 <entry>
  <title type="text">Beluga and explicit contexts</title>
  <link rel="alternate" href="https://www.williamjbowman.com/blog/2014/09/10/beluga-and-explicit-contexts/" />
  <id>urn:https-www-williamjbowman-com:-blog-2014-09-10-beluga-and-explicit-contexts</id>
  <published>2014-09-11T00:56:44Z</published>
  <updated>2014-09-11T00:56:44Z</updated>
  <author>
   <name>William J. Bowman</name></author>
  <content type="html">
&lt;p&gt;In my recent work, I found it useful to pair a term and its context in order to more easily reason about weakening the context. At the prompting of a colleague, I&amp;rsquo;ve been reading about Beluga, &lt;a href="http://www.cs.mcgill.ca/~complogic/beluga/flops10/flops.pdf" title="Beluga: programming with dependent types, contextual data, and
contexts"&gt;[1]&lt;/a&gt; &lt;a href="http://www.cs.mcgill.ca/~bpientka/papers/ppdp-pientka.pdf" title="Programming with Proofs and Explicit Contexts"&gt;[2]&lt;/a&gt;, and their support for programming with explicit contexts. The idea seems neat, but I&amp;rsquo;m not quite sure I understand the motivations or implications.&lt;/p&gt;

&lt;p&gt;So it seems Beluga has support for describing what a context contains (schemas), describing in which context a type/term is valid, and referring to the variables in a context by name without explicitly worrying about alpha-renaming. This technique supports reasoning about binders with HOAS in more settings, such as in the presence of open data and dependent types. Since HOAS simplifies reasoning about binders by taking advantage of the underlying language&amp;rsquo;s implementation of substitutions, this can greatly simplify formalized meta-theory in the presence of advanced features which previously required formalizing binders using more complicated techniques like De Bruijn indices. By including weakening, meta-variables, and parameter variables, Beluga enables meta-theory proofs involving binders to be much more natural, i.e., closer to pen-and-paper proofs.&lt;/p&gt;

&lt;p&gt;Obviously this is great for formalized meta-theory. While I have seen how HOAS can simplify life for the meta-theorist, and seen how it fails, I don&amp;rsquo;t fully understand the strengths and weakness of this work, or how it compares to techniques such as the &lt;a href="http://www.chargueraud.org/softs/ln/" title="LN: Locally nameless representation"&gt;locally nameless&lt;/a&gt;. I&amp;rsquo;m also not sure if there is more to this work than a better way to handle formalization of binding (which is a fine, useful accomplishment by itself).&lt;/p&gt;

&lt;p&gt;If anyone can elaborate on or correct my understanding, please do.&lt;/p&gt;</content></entry></feed>