<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dvanhorn @ λ-calcul.us &#187; Linearity</title>
	<atom:link href="http://dvanhorn.lambda-calcul.us/category/linearity/feed/" rel="self" type="application/rss+xml" />
	<link>http://dvanhorn.lambda-calcul.us</link>
	<description>Research weblog for David Van Horn</description>
	<lastBuildDate>Sat, 28 Aug 2010 13:39:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Diss</title>
		<link>http://dvanhorn.lambda-calcul.us/2009/08/14/the-diss/</link>
		<comments>http://dvanhorn.lambda-calcul.us/2009/08/14/the-diss/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 18:21:09 +0000</pubDate>
		<dc:creator>dvanhorn</dc:creator>
				<category><![CDATA[Announce]]></category>
		<category><![CDATA[CFA]]></category>
		<category><![CDATA[Complexity]]></category>
		<category><![CDATA[Linearity]]></category>

		<guid isPermaLink="false">http://dvanhorn.lambda-calcul.us/?p=153</guid>
		<description><![CDATA[The Complexity of Flow Analysis in Higher-Order Languages: Abstract, Dissertation, Slides.
]]></description>
			<content:encoded><![CDATA[<p>The Complexity of Flow Analysis in Higher-Order Languages: <a href="http://www.ccs.neu.edu/home/dvanhorn/abstracts/vanhorn-dissertation.html">Abstract</a>, <a href="http://www.ccs.neu.edu/home/dvanhorn/pubs/vanhorn-dissertation.pdf">Dissertation</a>, <a href="http://www.ccs.neu.edu/home/dvanhorn/talks/vanhorn-phd-defense-2009.pdf">Slides</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://dvanhorn.lambda-calcul.us/2009/08/14/the-diss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Complexity of Flow Analysis in Higher-Order Languages</title>
		<link>http://dvanhorn.lambda-calcul.us/2009/07/14/the-complexity-of-flow-analysis-in-higher-order-languages/</link>
		<comments>http://dvanhorn.lambda-calcul.us/2009/07/14/the-complexity-of-flow-analysis-in-higher-order-languages/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 22:16:08 +0000</pubDate>
		<dc:creator>dvanhorn</dc:creator>
				<category><![CDATA[Announce]]></category>
		<category><![CDATA[CFA]]></category>
		<category><![CDATA[Complexity]]></category>
		<category><![CDATA[Linearity]]></category>

		<guid isPermaLink="false">http://dvanhorn.lambda-calcul.us/?p=140</guid>
		<description><![CDATA[PhD Thesis Defense
Computer Science Department
Brandeis University
Date: Wednesday, July 22, 2009
Time: 2-4pm
Place: Volen 101
The Complexity of Flow Analysis in Higher-Order Languages
David Van Horn
Abstract:
This dissertation proves lower bounds on the inherent difficulty of deciding flow analysis problems in higher-order programming languages. We give exact characterizations of the computational complexity of 0CFA, the kCFA hierarchy, and related analyses. [...]]]></description>
			<content:encoded><![CDATA[<p>PhD Thesis Defense<br />
Computer Science Department<br />
Brandeis University</p>
<p>Date: Wednesday, July 22, 2009<br />
Time: 2-4pm<br />
Place: Volen 101</p>
<p>The Complexity of Flow Analysis in Higher-Order Languages<br />
David Van Horn</p>
<p>Abstract:</p>
<p>This dissertation proves lower bounds on the inherent difficulty of deciding flow analysis problems in higher-order programming languages. We give exact characterizations of the computational complexity of 0CFA, the kCFA hierarchy, and related analyses. In each case, we precisely capture both the expressiveness and feasibility of the analysis, identifying the elements responsible for the trade-off.</p>
<p>0CFA is complete for polynomial time. This result relies on the insight that when a program is linear (each bound variable occurs exactly once), the analysis makes no approximation; abstract and concrete interpretation coincide, and therefore program analysis becomes evaluation under another guise. Moreover, this is true not only for 0CFA, but for a number of further approximations to 0CFA. In each case, we derive polynomial time completeness results.</p>
<p>For any k > 0, kCFA is complete for exponential time. Even when k = 1, the distinction in binding contexts results in a limited form of closures, which do not occur in 0CFA. This theorem validates empirical observations that kCFA is intractably slow for any k > 0. There is, in the worst case&#8212;and plausibly, in practice&#8212;no way to tame the cost of the analysis. Exponential time is required. The empirically observed intractability of this analysis can be understood as being inherent in the approximation problem being solved, rather than reflecting unfortunate gaps in our programming abilities.</p>
]]></content:encoded>
			<wfw:commentRss>http://dvanhorn.lambda-calcul.us/2009/07/14/the-complexity-of-flow-analysis-in-higher-order-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linearity, the Workshop</title>
		<link>http://dvanhorn.lambda-calcul.us/2009/06/08/linearity-the-workshop/</link>
		<comments>http://dvanhorn.lambda-calcul.us/2009/06/08/linearity-the-workshop/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 17:40:21 +0000</pubDate>
		<dc:creator>dvanhorn</dc:creator>
				<category><![CDATA[Linearity]]></category>

		<guid isPermaLink="false">http://dvanhorn.lambda-calcul.us/?p=113</guid>
		<description><![CDATA[CSL&#8217;09 will include a satellite workshop on linearity:
Linearity has been the key feature in several lines of research in both theoretical and practical approaches to computer science. In the theoretical side all the work stemming from linear logic dealing with proof technology, complexity classes and more recently quantum computation. In the practical side work on [...]]]></description>
			<content:encoded><![CDATA[<p>CSL&#8217;09 will include a satellite <a href="http://www.lix.polytechnique.fr/linearity/">workshop on linearity</a>:</p>
<blockquote><p>Linearity has been the key feature in several lines of research in both theoretical and practical approaches to computer science. In the theoretical side all the work stemming from linear logic dealing with proof technology, complexity classes and more recently quantum computation. In the practical side work on program analysis, expressive operational semantics for programming languages, linear programming languages, program transformation, update analysis and efficient implementation techniques. The aim of this workshop is to bring together researchers who are currently developing theory and applications of linear calculi, in order to foster their interaction, to provide a forum for presenting new ideas and work in progress, and to enable newcomers to learn about current activities in this area. LINEARITY 2009 will be a one-day satellite event of CSL 2009.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://dvanhorn.lambda-calcul.us/2009/06/08/linearity-the-workshop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wordle: Linear Logical Approximations</title>
		<link>http://dvanhorn.lambda-calcul.us/2009/05/30/wordle-linear-logical-approximations/</link>
		<comments>http://dvanhorn.lambda-calcul.us/2009/05/30/wordle-linear-logical-approximations/#comments</comments>
		<pubDate>Sun, 31 May 2009 02:20:12 +0000</pubDate>
		<dc:creator>dvanhorn</dc:creator>
				<category><![CDATA[Linearity]]></category>

		<guid isPermaLink="false">http://dvanhorn.lambda-calcul.us/?p=108</guid>
		<description><![CDATA[
 From Robert J. Simmons&#8217; list of a papers is this &#8220;wordle&#8221; for &#8220;Linear Logical Approximations&#8221;, Simmons and Pfenning, PEPM 2008.  If you look closely, you can see I&#8217;ve made a mark (or two).
]]></description>
			<content:encoded><![CDATA[<p><a title="Wordle: Linear Logical Approximations" href="http://www.wordle.net/gallery/wrdl/304992/Linear_Logical_Approximations"><img style="margin-right: 1em; float: left; padding:4px;border:1px solid #ddd" src="http://www.wordle.net/thumb/wrdl/304992/Linear_Logical_Approximations" alt="Wordle: Linear Logical Approximations" /><br />
</a> From Robert J. Simmons&#8217; <a href="http://www.cs.cmu.edu/~rjsimmon/papers.html">list of a papers</a> is this &#8220;wordle&#8221; for &#8220;Linear Logical Approximations&#8221;, Simmons and Pfenning, PEPM 2008.  If you look closely, you can see I&#8217;ve made a mark (or two).</p>
]]></content:encoded>
			<wfw:commentRss>http://dvanhorn.lambda-calcul.us/2009/05/30/wordle-linear-logical-approximations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>To appear: Flow analysis, linearity, and PTIME</title>
		<link>http://dvanhorn.lambda-calcul.us/2008/04/07/to-appear-flow-analysis-linearity-and-ptime/</link>
		<comments>http://dvanhorn.lambda-calcul.us/2008/04/07/to-appear-flow-analysis-linearity-and-ptime/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 23:07:18 +0000</pubDate>
		<dc:creator>dvanhorn</dc:creator>
				<category><![CDATA[CFA]]></category>
		<category><![CDATA[Linearity]]></category>

		<guid isPermaLink="false">http://dvanhorn.lambda-calcul.us/2008/04/07/to-appear-flow-analysis-linearity-and-ptime/</guid>
		<description><![CDATA[Flow analysis, linearity, and PTIME was accepted at this year&#8217;s Static Analysis Symposium (SAS).  An early preprint was announced here, but the presentation has benefitted significantly from the anonymous reviewers&#8217; comments.  Also, the abstract was rewritten to be somewhat comprehensible (thanks to Dave Herman for encouraging the rewrite).
 Flow analysis is a ubiquitous [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cs.brandeis.edu/~dvanhorn/pubs/vanhorn-mairson-sas08.pdf">Flow analysis, linearity, and PTIME</a> was accepted at this year&#8217;s <a href="http://www.dsic.upv.es/~sas2008/">Static Analysis Symposium (SAS)</a>.  An early preprint was announced here, but the presentation has benefitted significantly from the anonymous reviewers&#8217; comments.  Also, the abstract was rewritten to be somewhat comprehensible (thanks to <a href="http://www.ccs.neu.edu/home/dherman/">Dave Herman</a> for encouraging the rewrite).</p>
<blockquote><p> Flow analysis is a ubiquitous and much-studied component of compiler technology—and its variations abound. Amongst the most well known is Shivers&#8217; 0CFA; however, the best known algorithm for 0CFA requires time cubic in the size of the analyzed program and is unlikely to be improved.  Consequently, several analyses have been designed to approximate 0CFA by trading precision for faster computation.  Henglein&#8217;s simple closure analysis, for example, forfeits the notion of directionality in flows and enjoys an &#8220;almost linear&#8221; time algorithm. But in making trade-offs between precision and complexity, what has been given up and what has been gained?  Where do these analyses differ and where do they coincide?</p>
<p>We identify a core language—the linear λ-calculus—where 0CFA, simple closure analysis, and many other known approximations or restrictions to 0CFA are rendered identical. Moreover, for this core language, analysis corresponds with (instrumented) evaluation. Because analysis faithfully captures evaluation, and because the linear λ-calculus is complete for PTIME, we derive PTIME-completeness results for all of these analyses.</p></blockquote>
<p>See you in Valencia!</p>
]]></content:encoded>
			<wfw:commentRss>http://dvanhorn.lambda-calcul.us/2008/04/07/to-appear-flow-analysis-linearity-and-ptime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linear logician&#8217;s bumper sticker</title>
		<link>http://dvanhorn.lambda-calcul.us/2008/03/25/linear-logicians-bumper-sticker/</link>
		<comments>http://dvanhorn.lambda-calcul.us/2008/03/25/linear-logicians-bumper-sticker/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 00:46:35 +0000</pubDate>
		<dc:creator>dvanhorn</dc:creator>
				<category><![CDATA[Linearity]]></category>
		<category><![CDATA[Stupid]]></category>

		<guid isPermaLink="false">http://dvanhorn.lambda-calcul.us/2008/03/25/linear-logicians-bumper-sticker/</guid>
		<description><![CDATA[My other par is a lambda.
]]></description>
			<content:encoded><![CDATA[<p>My other par is a lambda.</p>
]]></content:encoded>
			<wfw:commentRss>http://dvanhorn.lambda-calcul.us/2008/03/25/linear-logicians-bumper-sticker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CMU talk: Linear Logic and the Complexity of Control Flow Analysis</title>
		<link>http://dvanhorn.lambda-calcul.us/2008/02/02/cmu-talk-linear-logic-and-the-complexity-of-control-flow-analysis/</link>
		<comments>http://dvanhorn.lambda-calcul.us/2008/02/02/cmu-talk-linear-logic-and-the-complexity-of-control-flow-analysis/#comments</comments>
		<pubDate>Sat, 02 Feb 2008 15:56:35 +0000</pubDate>
		<dc:creator>dvanhorn</dc:creator>
				<category><![CDATA[CFA]]></category>
		<category><![CDATA[Linearity]]></category>

		<guid isPermaLink="false">http://dvanhorn.lambda-calcul.us/2008/02/02/cmu-talk-linear-logic-and-the-complexity-of-control-flow-analysis/</guid>
		<description><![CDATA[Harry has just returned from CMU after giving a talk on our recent work on the complexity of CFA.  The slides are available here.  As usual, they&#8217;re very funny and insightful.  It summarizes not only our 2007 ICFP paper, but our recent unpublished result showing that for any fixed k &#62; 0, [...]]]></description>
			<content:encoded><![CDATA[<p>Harry has just returned from CMU after giving a <a href="http://www.cs.cmu.edu/afs/.cs.cmu.edu/Web/Groups/pop/seminar/080130.html">talk</a> on our recent work on the complexity of CFA.  The slides are available <a href="http://www.cs.brandeis.edu/~dvanhorn/talks/linear-logic-complexity-cfa-cmu-2008.pdf">here</a>.  As usual, they&#8217;re very funny <em>and</em> insightful.  It summarizes not only our 2007 ICFP paper, but our recent unpublished result showing that for any fixed k &gt; 0, kCFA is complete for exponential time.  The visit at least garnered a <a href="http://lambda-the-ultimate.org/node/2647">notice</a> on <a href="http://lambda-the-ultimate.org/">LtU</a>, which is always appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://dvanhorn.lambda-calcul.us/2008/02/02/cmu-talk-linear-logic-and-the-complexity-of-control-flow-analysis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linearity, flow analysis, and PTIME</title>
		<link>http://dvanhorn.lambda-calcul.us/2008/02/02/linearity-flow-analysis-and-ptime/</link>
		<comments>http://dvanhorn.lambda-calcul.us/2008/02/02/linearity-flow-analysis-and-ptime/#comments</comments>
		<pubDate>Sat, 02 Feb 2008 15:42:02 +0000</pubDate>
		<dc:creator>dvanhorn</dc:creator>
				<category><![CDATA[CFA]]></category>
		<category><![CDATA[Linearity]]></category>

		<guid isPermaLink="false">http://dvanhorn.lambda-calcul.us/2008/02/02/linearity-flow-analysis-and-ptime/</guid>
		<description><![CDATA[A new preprint is available: Linearity, flow analysis, and PTIME.  Harry and I show that not only is 0CFA exact for linear terms, but it remains exact for approximations to and restrictions of 0CFA (this is true for all of the analyses I could find in the literature).  Because of this exactness, normalization [...]]]></description>
			<content:encoded><![CDATA[<p>A new preprint is available: <a href="http://www.cs.brandeis.edu/~dvanhorn/pubs/vanhorn-mairson-08.pdf">Linearity, flow analysis, and PTIME</a>.  Harry and I show that not only is 0CFA exact for linear terms, but it remains exact for approximations to and restrictions of 0CFA (this is true for all of the analyses I could find in the literature).  Because of this exactness, normalization and analysis are really just the same thing, and therefore they&#8217;re all PTIME hard.  And this paper really spells out the connection with evaluation, showing how to read back the result of evaluation from a flow analysis.</p>
<p>Comments are welcomed and appreciated.  This has been submitted to <a href="http://www.dsic.upv.es/~sas2008/">SAS</a>, but there is still plenty of time to revise.</p>
]]></content:encoded>
			<wfw:commentRss>http://dvanhorn.lambda-calcul.us/2008/02/02/linearity-flow-analysis-and-ptime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mairson&#8217;s Boolean encodings in Scheme</title>
		<link>http://dvanhorn.lambda-calcul.us/2007/11/06/mairsons-boolean-encodings-in-scheme/</link>
		<comments>http://dvanhorn.lambda-calcul.us/2007/11/06/mairsons-boolean-encodings-in-scheme/#comments</comments>
		<pubDate>Tue, 06 Nov 2007 15:44:14 +0000</pubDate>
		<dc:creator>dvanhorn</dc:creator>
				<category><![CDATA[Linearity]]></category>
		<category><![CDATA[Scheme]]></category>
		<category><![CDATA[booleans]]></category>
		<category><![CDATA[mairson]]></category>

		<guid isPermaLink="false">http://dvanhorn.lambda-calcul.us/2007/11/06/mairsons-boolean-encodings-in-scheme/</guid>
		<description><![CDATA[Mairson has an encoding of the Booleans in the linear lambda calculus, which improves upon the usual Church encoding which is linear affine.  Typically Mairson&#8217;s encoding is presented in linear ML to take advantage of pattern matching and tuples, but it is easy enough to present the embedding in linear Scheme using only unary [...]]]></description>
			<content:encoded><![CDATA[<p>Mairson has an encoding of the Booleans in the linear lambda calculus, which improves upon the usual Church encoding which is linear affine.  Typically Mairson&#8217;s encoding is presented in linear ML to take advantage of pattern matching and tuples, but it is easy enough to present the embedding in linear Scheme using only unary functions&#8212;and a little sugar will go a long way.</p>
<p>First, we&#8217;ll rely on Church&#8217;s original encoding of pairs.  Here is the constructor for pairs; it&#8217;s like a curried version of cons, where cons cells are represented with procedures:</p>
<pre class="scheme">(<span class="keyword">define</span> <span class="variable">pair</span> (<span class="keyword">λ</span> (<span class="variable">x</span>) (<span class="keyword">λ</span> (<span class="variable">y</span>) (<span class="keyword">λ</span> (<span class="variable">z</span>) ((<span class="variable">z</span> <span class="variable">x</span>) <span class="variable">y</span>)))))</pre>
<p>To destructure a pair <code>p</code>, you apply it to a procedure like:</p>
<pre class="scheme">(<span class="variable">p</span> (<span class="keyword">λ</span> (<span class="variable">x</span>) (<span class="keyword">λ</span> (<span class="variable">y</span>) ... <span class="variable">x</span> ... <span class="variable">y</span> ...)))</pre>
<p>Where <code>x</code> and <code>y</code> will refer to the car and cdr of the pair <code>p</code>, respectively.  We can make this look a little nicer with the following syntactic sugar:</p>
<pre class="scheme">(<span class="keyword">define-syntax</span> <span class="variable">let-pair</span>
  (<span class="keyword">syntax-rules</span> ()
    ((<span class="variable">let-pair</span> ((<span class="variable">x</span> <span class="variable">y</span>) <span class="variable">p</span>) <span class="variable">e</span>)
     (<span class="variable">p</span> (<span class="keyword">λ</span> (<span class="variable">x</span>) (<span class="variable">λ</span> (<span class="variable">y</span>) <span class="variable">e</span>))))))</pre>
<p>Now we add a little bit more sugar for functions on pairs:</p>
<pre class="scheme">(<span class="keyword">define-syntax</span> <span class="variable">λ*</span>
  (<span class="keyword">syntax-rules</span> ()
    ((<span class="variable">λ*</span> (<span class="variable">x</span> <span class="variable">y</span>) <span class="variable">e</span>)
     (<span class="keyword">λ</span> (<span class="variable">p</span>) (<span class="variable">let-pair</span> ((<span class="variable">x</span> <span class="variable">y</span>) <span class="variable">p</span>) <span class="variable">e</span>)))))</pre>
<p>The Booleans are built out of the twist and identity functions on pairs:</p>
<pre class="scheme">(<span class="keyword">define</span> <span class="variable">tt</span> (<span class="variable">λ*</span> (<span class="variable">x</span> <span class="variable">y</span>) ((<span class="variable">pair</span> <span class="variable">x</span>) <span class="variable">y</span>)))
(<span class="keyword">define</span> <span class="variable">ff</span> (<span class="variable">λ*</span> (<span class="variable">x</span> <span class="variable">y</span>) ((<span class="variable">pair</span> <span class="variable">y</span>) <span class="variable">x</span>)))</pre>
<p>The idea is that Boolean values (pairs) carry their &#8220;real&#8221; value in the first component, and their negation in the second component.  So we define True and False as follows:</p>
<pre class="scheme">(<span class="keyword">define</span> <span class="variable">true</span>  ((<span class="variable">pair</span> <span class="variable">tt</span>) <span class="variable">ff</span>))
(<span class="keyword">define</span> <span class="variable">false</span> ((<span class="variable">pair</span> <span class="variable">ff</span>) <span class="variable">tt</span>))</pre>
<p>The Not connective is easy, it is simply an inversion:</p>
<pre class="scheme">(<span class="keyword">define</span> <span class="variable">not</span> (<span class="variable">λ*</span> (<span class="variable">u</span> <span class="variable">v</span>) ((<span class="variable">pair</span> <span class="variable">v</span>) <span class="variable">u</span>)))</pre>
<p>And is not so easy.  Let&#8217;s build it up in pieces.  And takes a pair of Boolean values, each of which is a pair of functions:</p>
<pre class="scheme">(<span class="keyword">define</span> <span class="variable">and</span>
  (<span class="variable">λ*</span> (<span class="variable">a</span> <span class="variable">b</span>)
    (<span class="variable">let-pair</span> ((<span class="variable">p^</span> <span class="variable">p*</span>) <span class="variable">a</span>)
    (<span class="variable">let-pair</span> ((<span class="variable">q^</span> <span class="variable">q*</span>) <span class="variable">b</span>)
       ...))))</pre>
<p>Each of the <code>p</code>s and <code>q</code>s are functions on pairs&#8212;either twist or identity&#8212;and we have the &#8220;real&#8221; value in the first component and the negation in the second component.  So if <code>a</code> is True, then <code>p^</code> is identity, and twist otherwise.  If we apply <code>p^</code> to the pair (<code>q^</code>,<code>ff</code>), we&#8217;ll get (<code>q^</code>,<code>ff</code>) when <code>a</code> is True and (<code>ff</code>,<code>q^</code>), otherwise.  Looking only at the first component of this pair gives us the answer for computing the And of <code>a</code> and <code>b</code>, and we can read it much like the usual reading of Church&#8217;s encodings of the Booleans: &#8220;If <code>p^</code>, then <code>q^</code>, else false (aka, <code>ff</code>).&#8221;</p>
<p>But now what do we do with the negative components of <code>a</code> and <code>b</code>?  We just apply the DeMoorgan dual, namely Or, which reads: &#8220;If <code>p*</code>, then true (aka, <code>tt</code>), else <code>q*</code>.&#8221;  So far we have:</p>
<pre class="scheme">(<span class="keyword">define</span> <span class="variable">and</span>
  (<span class="variable">λ*</span> (<span class="variable">a</span> <span class="variable">b</span>)
    (<span class="variable">let-pair</span> ((<span class="variable">p^</span> <span class="variable">p*</span>) <span class="variable">a</span>)
    (<span class="variable">let-pair</span> ((<span class="variable">q^</span> <span class="variable">q*</span>) <span class="variable">b</span>)
    (<span class="variable">let-pair</span> ((<span class="variable">u^</span> <span class="variable">v^</span>) (<span class="variable">p^</span> ((<span class="variable">pair</span> <span class="variable">q^</span>) <span class="variable">ff</span>)))
    (<span class="variable">let-pair</span> ((<span class="variable">u*</span> <span class="variable">v*</span>) (<span class="variable">p*</span> ((<span class="variable">pair</span> <span class="variable">tt</span>) <span class="variable">q*</span>)))
      ...))))))</pre>
<p>We&#8217;d like to able to return the pair (<code>u^,u*</code>), ie. the first component of computing the And of the first components of <code>a</code> and <code>b</code>, and the first component of computing the Or of their negation.  But this wouldn&#8217;t be linear&#8212;we&#8217;re throwing away the &#8220;junk&#8221; <code>v^,v*</code>.</p>
<p>But we know something important about this junk, namely it&#8217;s symmetric.  If <code>v^</code> is <code>tt</code>, then <code>v*</code> is <code>ff</code>, and if <code>v^</code> is <code>ff</code>, then <code>v*</code> is <code>tt</code>.  One is twist, one is identity, we just don&#8217;t know which is which.  But we don&#8217;t need to.  If we compose <code>v^</code> and <code>v*</code> we&#8217;re guaranteed to get twist.  Compose this with another twist (<code>ff</code>) and we get identity.  Compose this with <code>v*</code> and we get <code>v*</code>&#8212;but now we&#8217;ve used everything and maintained linearity!  So we have:</p>
<pre class="scheme">(<span class="keyword">define</span> <span class="variable">and</span>
  (<span class="variable">λ*</span> (<span class="variable">a</span> <span class="variable">b</span>)
    (<span class="variable">let-pair</span> ((<span class="variable">p^</span> <span class="variable">p*</span>) <span class="variable">a</span>)
    (<span class="variable">let-pair</span> ((<span class="variable">q^</span> <span class="variable">q*</span>) <span class="variable">b</span>)
    (<span class="variable">let-pair</span> ((<span class="variable">u^</span> <span class="variable">v^</span>) (<span class="variable">p^</span> ((<span class="variable">pair</span> <span class="variable">q^</span>) <span class="variable">ff</span>)))
    (<span class="variable">let-pair</span> ((<span class="variable">u*</span> <span class="variable">v*</span>) (<span class="variable">p*</span> ((<span class="variable">pair</span> <span class="variable">tt</span>) <span class="variable">q*</span>)))
      ((<span class="variable">pair</span> <span class="variable">u^</span>)
       (<span class="variable">compose</span> ((<span class="variable">pair</span> <span class="variable">u*</span>)
                 (<span class="variable">compose</span> ((<span class="variable">pair</span> <span class="variable">v^</span>)
                           (<span class="variable">compose</span> ((<span class="variable">pair</span> <span class="variable">v*</span>) <span class="variable">ff</span>)))))))))))))</pre>
<p>Where composition is defined as:</p>
<pre class="scheme">(<span class="keyword">define</span> <span class="variable">compose</span> (<span class="variable">λ*</span> (<span class="variable">f</span> <span class="variable">g</span>) (<span class="variable">λ</span> (<span class="variable">x</span>) (<span class="variable">f</span> (<span class="variable">g</span> <span class="variable">x</span>)))))</pre>
<p>The slogan is: &#8220;Symmetric garbage is self-annihilating&#8221;, and we can build up other logical connectives, like Or, Implies, etc. in exactly this same way.</p>
<p>But what about Boolean formulas that are non-linear, ie. variables occur more than once?  For example, how can we write &#8220;b or not b&#8221;, which is a tautology?  We need an explicit Copy connective that will &#8220;fan out&#8221; a Boolean value.  It seems counter intuitive that we can even write a Copy operation in a linear way.  After all, linearity is all about NOT being able to copy things.  But we&#8217;ll see that it can be done quite easily in this encoding of the Booleans.  Since any Boolean value is a pair of functions on pairs, how can we copy a value?  We just apply these functions to pairs of functions on pairs.   For example, <code>tt</code> applied to (<code>tt,ff</code>) is (<code>tt,ff</code>), which is the encoding of True.  Applying <code>ff</code> to (<code>tt,ff</code>) is (<code>ff,tt</code>), which is the encoding of False.  So if you take a Boolean and apply it&#8217;s first component to True, you get back True whenever the Boolean is True and False whenever the Boolean is False.  What about the second component?  Applying it to False gives you True whenever the Boolean is True (the Boolean has twist in the second component so it takes False to True) and False whenever the Boolean is False.  So if you apply the first component to True and the second component to False, what do you get back?  A pair of Trues or a pair of Falses depending on the value of the Boolean, ie. two copies!  So the Copy connective is:</p>
<pre class="scheme">(<span class="keyword">define</span> <span class="variable">copy</span> (<span class="variable">λ*</span> (<span class="variable">p</span> <span class="variable">q</span>) ((<span class="variable">pair</span> (<span class="variable">p</span> <span class="variable">true</span>)) (<span class="variable">q</span> <span class="variable">false</span>))))</pre>
<p>And now we&#8217;re done.  We&#8217;ve given a nice readable encoding of the Booleans in linear λ-calculus using Scheme&#8212;just as readable as the linear ML counterpart.  And if you were to expand away the syntactic sugar and inline the definitions of the connectives, you&#8217;d be left with a Scheme program that uses only applies and λs (taking exactly one argument)&#8212;no pattern matching or tuples needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://dvanhorn.lambda-calcul.us/2007/11/06/mairsons-boolean-encodings-in-scheme/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Linearity and approximation in kCFA</title>
		<link>http://dvanhorn.lambda-calcul.us/2007/10/17/linearity-and-approximation-in-kcfa/</link>
		<comments>http://dvanhorn.lambda-calcul.us/2007/10/17/linearity-and-approximation-in-kcfa/#comments</comments>
		<pubDate>Wed, 17 Oct 2007 16:39:36 +0000</pubDate>
		<dc:creator>dvanhorn</dc:creator>
				<category><![CDATA[CFA]]></category>
		<category><![CDATA[Linearity]]></category>

		<guid isPermaLink="false">http://dvanhorn.lambda-calcul.us/2007/10/17/linearity-and-approximation-in-kcfa/</guid>
		<description><![CDATA[Linearity is the key to subverting the approximation of any monovariant analysis, like simple typing or 0CFA, and renders the analysis synonymous with normalization.  However, something weird happens in the case of (k &#62; 0)CFA: linear expansion does not preserve the precision of the analysis.  For example, take the program:

(λf.f f (λy.y)) (λx.x)

This [...]]]></description>
			<content:encoded><![CDATA[<p>Linearity is the key to subverting the approximation of any monovariant analysis, like simple typing or 0CFA, and renders the analysis synonymous with normalization.  However, something weird happens in the case of (k &gt; 0)CFA: linear expansion does not preserve the precision of the analysis.  For example, take the program:</p>
<ul>
<li>(λf.f f (λy.y)) (λx.x)</li>
</ul>
<p>This program has an exact 1CFA.  But perform the following linear expansion:</p>
<ul>
<li>apply (λf.f f (λy.y)) (λx.x)</li>
</ul>
<p>Where apply ≡λxλy.xy, then 1CFA is no longer exact.  So inserting a linear term can introduce approximation, whereas this is not the case in 0CFA, and really it <em>shouldn&#8217;t</em> be the case in kCFA.  We need a variant of kCFA that recognizes linear (virtual) reductions and performs them; there clearly is no harm in doing so (the code size cannot blow up), and there is a precision gained at no cost.</p>
<p>I noticed this because these linear expansions are at the heart of two proofs appearing at ICFP this year.  One is mine, where I show that the NP-hardness construction for 1CFA can be adapted to kCFA by inserting linear terms that effectively eat the added precision of going from k to (k+1)CFA.   <a href="http://metacomp.comlab.ox.ac.uk/Members/damien">Damien Sereni</a> uses a similar trick&#8212;with a nicer presentation, by the way&#8212;in proving a separation result about k- and (k+1)-limited CFA.</p>
<p>If you had an analysis that was invariant under linear expansion, these proofs wouldn&#8217;t hold, and moreover, the theorems might not be true!  But beyond aggravating theorists, this is clearly the right thing to do from a pragmatic point of view: why pay for lunch if you&#8217;re not going to eat it?</p>
<ul>
<li>
<div>[2007,inproceedings] <a href="#sereni_icfp07" class="toggle">bibtex</a>  <a href='http://metacomp.comlab.ox.ac.uk/Members/damien/publications/icfp07.pdf' title='Go to document'><img src='http://dvanhorn.lambda-calcul.us/wp-content/plugins/bib2html/external.png' width='10' height='10' alt='Go to document' /></a></div>
<div>D. Sereni, &quot;Termination Analysis and Call Graph Construction for Higher-Order Functional Programs,&quot; in <em>Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming (ICFP 2007)</em>,  2007.</div>
<div class="bibtex" id="sereni_icfp07">
         <code>@INPROCEEDINGS{sereni_icfp07, <br />
 &nbsp;&nbsp;author = {Damien Sereni}, <br />
 &nbsp; title = {Termination Analysis and Call Graph Construction for Higher-Order Functional Programs}, <br />
 &nbsp; booktitle = {Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming (ICFP 2007)}, <br />
 &nbsp; editor = {Norman Ramsey}, <br />
 &nbsp; publisher = {ACM Press}, <br />
 &nbsp; year = {2007}, <br />
 &nbsp; url = {http://metacomp.comlab.ox.ac.uk/Members/damien/publications/icfp07.pdf}, <br />
 &nbsp; }</code>
    </div>
</li>
</ul>
<ul>
<li>
<div>[2007,inproceedings] <a href="#vanhorn_icfp07" class="toggle">bibtex</a>  <a href='http://www.cs.brandeis.edu/~dvanhorn/pubs/vanhorn-mairson-icfp07.pdf' title='Go to document'><img src='http://dvanhorn.lambda-calcul.us/wp-content/plugins/bib2html/external.png' width='10' height='10' alt='Go to document' /></a></div>
<div>D. Van Horn and H. G. Mairson, &quot;Relating Complexity and Precision in Control Flow Analysis,&quot; in <em>Proceedings of the 2007 ACM SIGPLAN International Conference on Functional Programming (ICFP 2007)</em>, New York, NY, USA,  2007, pp. 85-96.</div>
<div class="bibtex" id="vanhorn_icfp07">
         <code>@INPROCEEDINGS{vanhorn_icfp07, <br />
 &nbsp;&nbsp;author = {David {Van Horn} and Harry G. Mairson}, <br />
 &nbsp; title = {Relating Complexity and Precision in Control Flow Analysis}, <br />
 &nbsp; booktitle = {Proceedings of the 2007 ACM SIGPLAN International Conference on Functional Programming (ICFP 2007)}, <br />
 &nbsp; year = {2007}, <br />
 &nbsp; isbn = {978-1-59593-815-2}, <br />
 &nbsp; pages = {85--96}, <br />
 &nbsp; location = {Freiburg, Germany}, <br />
 &nbsp; doi = {http://doi.acm.org/10.1145/1291151.1291166}, <br />
 &nbsp; publisher = {ACM Press}, <br />
 &nbsp; address = {New York, NY, USA}, <br />
 &nbsp; url = {http://www.cs.brandeis.edu/~dvanhorn/pubs/vanhorn-mairson-icfp07.pdf}<br />
}</code>
    </div>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dvanhorn.lambda-calcul.us/2007/10/17/linearity-and-approximation-in-kcfa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
