<p>The relationship that you're looking for is indeed well-defined, but IMO it's not quite the right thing to look at. For example:</p>

<ol>
<li>Type checking for terms in the simply-typed lambda calculus is linear time, but normalizing terms in the STLC exceeds any fixed tower of exponentials (i.e., $O(2^{2^{2^{\ldots n}}})$.</li>
<li>Type <em>checking</em> for System F is linear time, but normalization takes as long as any function definable in second-order arithmetic.</li>
<li>For $F^\omega$, typechecking exceeds any tower of exponentials (since you have to normalize simply-typed lambda-terms to do typechecking), but normalization is complete for <em>higher-order</em> arithmetic.</li>
<li>Type <em>inference</em> for rank-1 types (basically, ML-style types) is EXPTIME-complete, but normalization time is somewhere in between the STLC and System 
F. </li>
<li>Type inference for intersection types is undecidable (because they characterize halting). </li>
</ol>

<p>What's going on here is that once you add enough type annotations, typechecking gets easy. If you have to do inference, then the problem gets much harder. This hints that there's a connection between program analysis and evaluation, and the ability of intersection type disciplines to characterize normalization further hints that the key place to look is linear logic. </p>

<ul>
<li><p>A good place to get an intuition is from David Van Horn and Harry Mairson's papers <a href="http://www.cs.brandeis.edu/~mairson/Papers/sas08.pdf" rel="noreferrer"><em>Flow Analysis, Linearity, and PTIME</em></a> and <a href="http://www.cs.brandeis.edu/~mairson/Papers/icfp07.pdf" rel="noreferrer"><em>Relating complexity and precision in control flow analysis</em></a>. </p>

<p>These papers show that for a linear calculus, program analysis and evaluation coincide, because linearity makes the approximation of flow analysis exact. </p></li>
<li><p>So by taking a linear calculus and then carefully controlling how much contraction you have via intersection types, you can gain a rather fine control over the complexity of normalization. As you might expect, there is an <strong>awful lot</strong> of work in this space from the intersection types community. </p>

<p>So rather than trying to summarize it all and missing important references, I'll pick out one line of work I particularly like  (and thereby miss important references on purpose :). This is the work of <a href="http://www-lipn.univ-paris13.fr/~mazza" rel="noreferrer">Damiano Mazza</a> on redoing classical complexity theory in a higher-order implicit complexity framework. Here are three papers I particularly like:</p>

<ol>
<li><a href="http://www-lipn.univ-paris13.fr/~mazza/papers/ChurchCookLevin.pdf" rel="noreferrer"><em>Church meets Cook and Levin</em></a>. This re-does the famous Cook-Levin proof (that SAT is NP-complete) in an implicit complexity style. The key idea is that you can use affine lambda terms as a kind of "higher-order circuit", and then approximate regular lambda-terms using them.</li>
<li>This idea is explored further in <a href="http://www-lipn.univ-paris13.fr/~mazza/papers/LambdaMetrics-TLCA2013.pdf" rel="noreferrer"><em>Non-linearity as the Metric Completion of Linearity</em></a>, which focuses just on this idea (apparently implicit in Girard). </li>
<li>Most recently at POPL this year, Mazza (with Luc Pellissier and Pierre Vial) showed how most linear intersection type systems arise from a general framework for refinement types introduced by Noam Zeilberger and Paul-André Melliès, in their paper <a href="http://www-lipn.univ-paris13.fr/~mazza/papers/IntersectionTypes.pdf" rel="noreferrer"><em>Polyadic Approximations, Fibrations and Intersection Types</em></a>.</li>
</ol></li>
</ul>

<p>I want to emphasize that this is not comprehensive -- chase the references in these papers! </p>

CC BY-SA 4.0
2018-08-14T02:31:55.630Z
Neel, the references you gave are excellent!
Łukasz Lew
CC BY-SA 4.0
2018-08-14T02:40:11.880Z
Would you also be able to comment more on the opposite end of the spectrum? Why System F jump [linear -> second order arithmetic] is so big? Perhaps it is the biggest jump possible in some sense? I've read all kinds of related arguments demonstrating impredicativity, but I'm looking for something that would demonstrate how the number of contractions is controlled.
Łukasz Lew
CC BY-SA 4.0
2018-08-13T14:44:18.140Z
2018-08-13T14:44:18.140Z
Neel Krishnaswami
<p>In order to verify that a terminating program terminates, one thing that can be done is to actually run the program. That may take a lot of time. If the program is typed in a total type-system, we can instead just type-check the program. That will take some time too, sometimes "a lot" too.</p>

<p>I'm looking for results that formalize the relation of the complexity of type-checking to the complexity of normalization for a various type-systems, i.e. possible speedup ratios. Is that relation always well defined? I'm not sure.</p>

<p>But we can give some lower bounds by demonstrating families of typed terms.</p>

<p>I'm interested mostly in any of the well known type systems such as System F, predicative variants of system F, including 'Rank 1' variant and Calculus of constructions.  'Intersection types' are particularly interesting case since they characterize the family of normalizing lambda terms.</p>

<complexity-classes><computability><type-theory><type-systems><calculus-of-constructions>
Complexity of type-checking in relation to complexity of normalization
Łukasz Lew
# Complexity of type-checking in relation to complexity of normalization

(Asked by: username_0 on 2018-08-13)

In order to verify that a terminating program terminates, one thing that can be done is to actually run the program. That may take a lot of time. If the program is typed in a total type-system, we can instead just type-check the program. That will take some time too, sometimes "a lot" too.

I'm looking for results that formalize the relation of the complexity of type-checking to the complexity of normalization for a various type-systems, i.e. possible speedup ratios. Is that relation always well defined? I'm not sure.

But we can give some lower bounds by demonstrating families of typed terms.

I'm interested mostly in any of the well known type systems such as System F, predicative variants of system F, including 'Rank 1' variant and Calculus of constructions. 'Intersection types' are particularly interesting case since they characterize the family of normalizing lambda terms.

**Tags:** complexity-classes, computability, type-theory, type-systems, calculus-of-constructions

---

## 1 answers

### Answer by username_1 on 2018-08-13. Score: 6 | Accepted answer

The relationship that you're looking for is indeed well-defined, but IMO it's not quite the right thing to look at. For example:

1. Type checking for terms in the simply-typed lambda calculus is linear time, but normalizing terms in the STLC exceeds any fixed tower of exponentials (i.e., $O(2^{2^{2^{\ldots n}}})$.
2. Type *checking* for System F is linear time, but normalization takes as long as any function definable in second-order arithmetic.
3. For $F^\omega$, typechecking exceeds any tower of exponentials (since you have to normalize simply-typed lambda-terms to do typechecking), but normalization is complete for *higher-order* arithmetic.
4. Type *inference* for rank-1 types (basically, ML-style types) is EXPTIME-complete, but normalization time is somewhere in between the STLC and System
   F.
5. Type inference for intersection types is undecidable (because they characterize halting).

What's going on here is that once you add enough type annotations, typechecking gets easy. If you have to do inference, then the problem gets much harder. This hints that there's a connection between program analysis and evaluation, and the ability of intersection type disciplines to characterize normalization further hints that the key place to look is linear logic.

* A good place to get an intuition is from David Van Horn and Harry Mairson's papers [*Flow Analysis, Linearity, and PTIME*](http://www.cs.brandeis.edu/~mairson/Papers/sas08.pdf) and [*Relating complexity and precision in control flow analysis*](http://www.cs.brandeis.edu/~mairson/Papers/icfp07.pdf).

  These papers show that for a linear calculus, program analysis and evaluation coincide, because linearity makes the approximation of flow analysis exact.
* So by taking a linear calculus and then carefully controlling how much contraction you have via intersection types, you can gain a rather fine control over the complexity of normalization. As you might expect, there is an **awful lot** of work in this space from the intersection types community.

  So rather than trying to summarize it all and missing important references, I'll pick out one line of work I particularly like (and thereby miss important references on purpose :). This is the work of [Damiano Mazza](http://www-lipn.univ-paris13.fr/~mazza) on redoing classical complexity theory in a higher-order implicit complexity framework. Here are three papers I particularly like:

  1. [*Church meets Cook and Levin*](http://www-lipn.univ-paris13.fr/~mazza/papers/ChurchCookLevin.pdf). This re-does the famous Cook-Levin proof (that SAT is NP-complete) in an implicit complexity style. The key idea is that you can use affine lambda terms as a kind of "higher-order circuit", and then approximate regular lambda-terms using them.
  2. This idea is explored further in [*Non-linearity as the Metric Completion of Linearity*](http://www-lipn.univ-paris13.fr/~mazza/papers/LambdaMetrics-TLCA2013.pdf), which focuses just on this idea (apparently implicit in Girard).
  3. Most recently at POPL this year, Mazza (with Luc Pellissier and Pierre Vial) showed how most linear intersection type systems arise from a general framework for refinement types introduced by Noam Zeilberger and Paul-André Melliès, in their paper [*Polyadic Approximations, Fibrations and Intersection Types*](http://www-lipn.univ-paris13.fr/~mazza/papers/IntersectionTypes.pdf).

I want to emphasize that this is not comprehensive -- chase the references in these papers!

> **Comments:**
> **username_0**: Neel, the references you gave are excellent!  
> **username_0**: Would you also be able to comment more on the opposite end of the spectrum? Why System F jump [linear -> second order arithmetic] is so big? Perhaps it is the biggest jump possible in some sense? I've read all kinds of related arguments demonstrating impredicativity, but I'm looking for something that would demonstrate how the number of contractions is controlled.  

---

