T URING MACHINES ( PROS ) easy to imagine easy to explain de-facto - - PowerPoint PPT Presentation

t uring machines pros
SMART_READER_LITE
LIVE PREVIEW

T URING MACHINES ( PROS ) easy to imagine easy to explain de-facto - - PowerPoint PPT Presentation

T HE STRONG INVARIANCE THESIS FOR A - CALCULUS LOLA WORKSHOP 2017 Yannick Forster 1 Fabian Kunze 1,2 Marc Roth 1,3 1 S AARLAND U NIVERSITY 2 M AX P LANCK I NSTITUTE FOR I NFORMATICS 3 C LUSTER OF E XCELLENCE (MMCI) saarland university computer


slide-1
SLIDE 1

THE STRONG INVARIANCE THESIS

FOR A λ-CALCULUS

LOLA WORKSHOP 2017 Yannick Forster 1 Fabian Kunze 1,2 Marc Roth 1,3

1SAARLAND UNIVERSITY 2MAX PLANCK INSTITUTE FOR INFORMATICS 3CLUSTER OF EXCELLENCE (MMCI)

computer science

saarland

university

slide-2
SLIDE 2

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

TURING MACHINES

computer science

saarland

university 2

slide-3
SLIDE 3

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

TURING MACHINES (PROS)

computer science

saarland

university ◮ easy to imagine ◮ easy to explain ◮ de-facto the standard model of computation for

computation theory and complexity theory

3

slide-4
SLIDE 4

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

TURING MACHINES (CONS)

computer science

saarland

university

Notoriously hard to reason about (in a formally precise way):

◮ not compositional ◮ tedious encodings ◮ no nice abstractions for verification (e.g. no separation

logic)

◮ Formalisation of Computability Theory is out of reach ◮ Formalisation of Complexity Theory is even further away 4

slide-5
SLIDE 5

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXEMPLARY RELATED WORK

computer science

saarland

university

Ugo Dal Lago and Simone Martini The Weak Lambda Calculus as a Reasonable Machine Theoretical Computer Science, 2008 Beniamino Accattoli and Ugo Dal Lago (Leftmost-Outermost) Beta Reduction is Invariant, Indeed Logical Methods in Computer Science, 2016

5

slide-6
SLIDE 6

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXEMPLARY RELATED WORK

computer science

saarland

university

Ugo Dal Lago and Simone Martini The Weak Lambda Calculus as a Reasonable Machine Theoretical Computer Science, 2008 Beniamino Accattoli and Ugo Dal Lago (Leftmost-Outermost) Beta Reduction is Invariant, Indeed Logical Methods in Computer Science, 2016 Andrea Asperti and Wilmer Ricciotti A formalization of multi-tape Turing machines Theoretical Computer Science, 2015

5

slide-7
SLIDE 7

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

ANOTHER MODEL OF COMPUTATION

computer science

saarland

university

A certain flavour of λ-calculus called L

◮ compositional ◮ straightforward encodings of data types ◮ equational reasoning for verification ◮ Formalisation for Computability theory

Yannick Forster and Gert Smolka Weak Call-by-Value Lambda Calculus as a Model of Computation in Coq ITP 2017

◮ Reasonable with respect to time [Dal Lago, Martini (2008)] ◮ Reasonable with respect to space? 6

slide-8
SLIDE 8

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

THE INVARIANCE THESIS

computer science

saarland

university

(Strong) Invariance Thesis

‘Reasonable’ machines can simulate each other within a polynomially bounded overhead in time and a constant-factor overhead in space.

7 [Slot, van Emde Boas (1998)]

slide-9
SLIDE 9

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

THE INVARIANCE THESIS

computer science

saarland

university

(Strong) Invariance Thesis

‘Reasonable’ machines can simulate each other within a polynomially bounded overhead in time and a constant-factor overhead in space. Ensures consistency w.r.t classes closed under poly-time/constant-space reductions.

7 [Slot, van Emde Boas (1998)]

slide-10
SLIDE 10

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

CONTRIBUTION

computer science

saarland

university ◮ Simple time and space measures for L ◮ substitution-based interpreter with constant-factor

  • verhead in space

◮ heap-based interpreter with polynomially bounded

  • verhead in time

◮ hybrid interpreter fulfilling the strong invariance thesis 8

slide-11
SLIDE 11

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

CONTRIBUTION

computer science

saarland

university

Theorem (Strong Invariance Thesis for L)

L and Turing Machines can simulate each other within a polynomially bounded overhead in time and a constant-factor

  • verhead in space for decision functions with non-sublinear

running time.

9

slide-12
SLIDE 12

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

L: WEAK CALL-BY-VALUE λ-CALCULUS

computer science

saarland

university

s, t ::= x | λx.s | s t (λx.s)(λy.t) ≻ s[x := λy.t] s ≻ s′ st ≻ s′t t ≻ t′ st ≻ st′

◮ uniformly confluent (reductions to normal forms have the

same length)

◮ data represented by abstractions (Scott encoding) ◮ recursion using fixed-point combinator 10 [Dal Lago, Martini (2008)]

slide-13
SLIDE 13

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

TIME MEASURE

computer science

saarland

university

If s = s0 ≻ s1 ≻ · · · ≻ sk then Time(s) := k i.e. the number of β-reduction steps

11

slide-14
SLIDE 14

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

SPACE MEASURE

computer science

saarland

university

Space(s) := max

{si|s≻∗si} |si|

i.e. size of the largest intermediate term of the reduction for |x| = de Bruijn index of x |st| = 1 + |s| + |t| |λx.s| = 1 + |s|

12

slide-15
SLIDE 15

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

DEFINITION OF TURING MACHINE

computer science

saarland

university ◮ a finite type of states Q ◮ a transition function δ : Q × Σn+1 → Q × Σn+1 × {L, N, R} ◮ a start state s : Q ◮ a halting function Q → B

Semantics: Loop δ until a halting state is reached.

13 [Asperti, Ricciotti (2015)], [Dal Lago, Martini (2008)]

slide-16
SLIDE 16

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

DEFINITION OF TURING MACHINE

computer science

saarland

university ◮ a finite type of states Q ◮ a transition function δ : Q × Σn+1 → Q × Σn+1 × {L, N, R} ◮ a start state s : Q ◮ a halting function Q → B

Semantics: Loop δ until a halting state is reached. Encode δ and halting function using Scott encodings (linear size, polynomial operations) and loop.

13 [Asperti, Ricciotti (2015)], [Dal Lago, Martini (2008)]

slide-17
SLIDE 17

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

DEFINITION OF TURING MACHINE

computer science

saarland

university ◮ a finite type of states Q ◮ a transition function δ : Q × Σn+1 → Q × Σn+1 × {L, N, R} ◮ a start state s : Q ◮ a halting function Q → B

Semantics: Loop δ until a halting state is reached. Encode δ and halting function using Scott encodings (linear size, polynomial operations) and loop.

In Coq:

Generation and verification of L-code from functional specification is automatic with our framework. Time-complexity of the extract is semi-automatic. Space-complexity has to be done by hand.

13 [Asperti, Ricciotti (2015)], [Dal Lago, Martini (2008)]

slide-18
SLIDE 18

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

computer science

saarland

university

Theorem (Invariance thesis part I)

L can simulate Turing machines with a polynomially bounded

  • verhead in time and a constant-factor overhead in space.

14

slide-19
SLIDE 19

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING BY SUBSTITUTION

computer science

saarland

university

Let I := λx.x: (λxy.x x) I ((λxy.x x)II)

15

slide-20
SLIDE 20

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING BY SUBSTITUTION

computer science

saarland

university

Let I := λx.x: (λxy.x x) I ((λxy.x x)II)≻ (λy.I I) ((λxy.x x)II)

15

slide-21
SLIDE 21

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING BY SUBSTITUTION

computer science

saarland

university

Let I := λx.x: (λxy.x x) I ((λxy.x x)II)≻ (λy.I I) ((λxy.x x)II) ≻ (λy.I I) ((λy.II)I)

15

slide-22
SLIDE 22

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING BY SUBSTITUTION

computer science

saarland

university

Let I := λx.x: (λxy.x x) I ((λxy.x x)II)≻ (λy.I I) ((λxy.x x)II) ≻ (λy.I I) ((λy.II)I) ≻ (λy.I I) (I I)

15

slide-23
SLIDE 23

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING BY SUBSTITUTION

computer science

saarland

university

Let I := λx.x: (λxy.x x) I ((λxy.x x)II)≻ (λy.I I) ((λxy.x x)II) ≻ (λy.I I) ((λy.II)I) ≻ (λy.I I) (I I) ≻ (λy.I I)I

15

slide-24
SLIDE 24

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING BY SUBSTITUTION

computer science

saarland

university

Let I := λx.x: (λxy.x x) I ((λxy.x x)II)≻ (λy.I I) ((λxy.x x)II) ≻ (λy.I I) ((λy.II)I) ≻ (λy.I I) (I I) ≻ (λy.I I)I ≻ I I

15

slide-25
SLIDE 25

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING BY SUBSTITUTION

computer science

saarland

university

Let I := λx.x: (λxy.x x) I ((λxy.x x)II)≻ (λy.I I) ((λxy.x x)II) ≻ (λy.I I) ((λy.II)I) ≻ (λy.I I) (I I) ≻ (λy.I I)I ≻ I I ≻ I

15

slide-26
SLIDE 26

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

ENCODING TERMS

computer science

saarland

university ◮ terms: prefix notation with tokens @, λ, ⊲ and |. ◮ Positions: strings with tokens @L, @R, λ

Example

(λxy.x y) (λx.x) ≈ (λλ10) (λ0) is encoded by string @λλ@⊲|⊲λ⊲. In this term, ’1’ occurs at position @Lλλ@L

16

slide-27
SLIDE 27

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

SUBSTITUTION-BASED INTERPRETER

computer science

saarland

university

To compute s ≻ s′ , use tapes pre, funct, arg, post, position: · · ·

  • pre

@λ · · ·

  • funct

λ · · ·

  • arg

· · ·

  • post
  • 1. Find the first β-redex,

◮ copy to pre until @λ is read ◮ copy next complete term to funct (and remember its position

  • n the position tape)

◮ if the next token is λ, copy the next term to arg and

remaining tokens to post

◮ otherwise, move funct onto pre and start from beginning

  • 2. copy funct to pre, replacing variable with arg
  • 3. copy post to pre

17 [Dal Lago, Martini (2008)]

slide-28
SLIDE 28

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

COMPLEXITY ANALYSIS

computer science

saarland

university

Per step for s ≻ s′: O(|s|2) time O(|s| + |s′|) space

18

slide-29
SLIDE 29

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

COMPLEXITY ANALYSIS

computer science

saarland

university

Per step for s ≻ s′: O(|s|2) time O(|s| + |s′|) space In total for s = s0 ≻ s1 ≻ · · · ≻ sk: O(

i |si|2) time

O(maxi |si|) = O(Space(s)) space

18

slide-30
SLIDE 30

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

computer science

saarland

university

Theorem (Invariance thesis part II for space)

Turing machines can simulate L with a constant-factor overhead in space.

19

slide-31
SLIDE 31

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXPLOSIVE TERMS

computer science

saarland

university

2 := λxy.x (x y) can double the size of a term in one step: 2 t ≻ λy.t (t y) So, with I := λx.x: 2 (2 (· · · (2

  • k times

I) . . .) normalizes in k L-steps, but needs Ω(2k) interpretation time

20

slide-32
SLIDE 32

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING WITH A HEAP

computer science

saarland

university

2 := λxy.x (x y) 2(2I)I

21

slide-33
SLIDE 33

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING WITH A HEAP

computer science

saarland

university

2 := λxy.x (x y) 2(2I)I≻ 2(λy.h1(h1y))I h1 := I

21

slide-34
SLIDE 34

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING WITH A HEAP

computer science

saarland

university

2 := λxy.x (x y) 2(2I)I≻ 2(λy.h1(h1y))I h1 := I ≻ (λy.h2(h2y))I h1 := I, h2 := (λy.h1(h1y))

21

slide-35
SLIDE 35

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING WITH A HEAP

computer science

saarland

university

2 := λxy.x (x y) 2(2I)I≻ 2(λy.h1(h1y))I h1 := I ≻ (λy.h2(h2y))I h1 := I, h2 := (λy.h1(h1y)) ≻ h2(h2h3) h1 := I, h2 := λy.h1(h1y), h3 := I

21

slide-36
SLIDE 36

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING WITH A HEAP

computer science

saarland

university

2 := λxy.x (x y) 2(2I)I≻ 2(λy.h1(h1y))I h1 := I ≻ (λy.h2(h2y))I h1 := I, h2 := (λy.h1(h1y)) ≻ h2(h2h3) h1 := I, h2 := λy.h1(h1y), h3 := I ≻2 h2((λy.h1(h1y))I)

21

slide-37
SLIDE 37

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING WITH A HEAP

computer science

saarland

university

2 := λxy.x (x y) 2(2I)I≻ 2(λy.h1(h1y))I h1 := I ≻ (λy.h2(h2y))I h1 := I, h2 := (λy.h1(h1y)) ≻ h2(h2h3) h1 := I, h2 := λy.h1(h1y), h3 := I ≻2 h2((λy.h1(h1y))I) ≻ h2(h1(h1h4)) . . . , h4 := I

21

slide-38
SLIDE 38

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING WITH A HEAP

computer science

saarland

university

2 := λxy.x (x y) 2(2I)I≻ 2(λy.h1(h1y))I h1 := I ≻ (λy.h2(h2y))I h1 := I, h2 := (λy.h1(h1y)) ≻ h2(h2h3) h1 := I, h2 := λy.h1(h1y), h3 := I ≻2 h2((λy.h1(h1y))I) ≻ h2(h1(h1h4)) . . . , h4 := I ≻2 h2(h1(II))

21

slide-39
SLIDE 39

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING WITH A HEAP

computer science

saarland

university

2 := λxy.x (x y) 2(2I)I≻ 2(λy.h1(h1y))I h1 := I ≻ (λy.h2(h2y))I h1 := I, h2 := (λy.h1(h1y)) ≻ h2(h2h3) h1 := I, h2 := λy.h1(h1y), h3 := I ≻2 h2((λy.h1(h1y))I) ≻ h2(h1(h1h4)) . . . , h4 := I ≻2 h2(h1(II)) ≻5 h2I . . . , h5 := I, h6 := I

21

slide-40
SLIDE 40

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING WITH A HEAP

computer science

saarland

university

2 := λxy.x (x y) 2(2I)I≻ 2(λy.h1(h1y))I h1 := I ≻ (λy.h2(h2y))I h1 := I, h2 := (λy.h1(h1y)) ≻ h2(h2h3) h1 := I, h2 := λy.h1(h1y), h3 := I ≻2 h2((λy.h1(h1y))I) ≻ h2(h1(h1h4)) . . . , h4 := I ≻2 h2(h1(II)) ≻5 h2I . . . , h5 := I, h6 := I ≻ h1(h1h7)

21

slide-41
SLIDE 41

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

EXAMPLE: EVALUATING WITH A HEAP

computer science

saarland

university

2 := λxy.x (x y) 2(2I)I≻ 2(λy.h1(h1y))I h1 := I ≻ (λy.h2(h2y))I h1 := I, h2 := (λy.h1(h1y)) ≻ h2(h2h3) h1 := I, h2 := λy.h1(h1y), h3 := I ≻2 h2((λy.h1(h1y))I) ≻ h2(h1(h1h4)) . . . , h4 := I ≻2 h2(h1(II)) ≻5 h2I . . . , h5 := I, h6 := I ≻ h1(h1h7) ≻∗ I

21

slide-42
SLIDE 42

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

HEAP-BASED INTERPRETER

computer science

saarland

university

s = s0 ≻ · · · si ≻ · · · ≻ sk Tapes: main (contains si), heap, hc (heap counter) Invariant: size of heap is always polynomial in k and |s|.

22

slide-43
SLIDE 43

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

HEAP-BASED INTERPRETER

computer science

saarland

university

s = s0 ≻ · · · si ≻ · · · ≻ sk Tapes: main (contains si), heap, hc (heap counter) Invariant: size of heap is always polynomial in k and |s|.

◮ For beta-reduction of (λx.t1)t2: Copy t2 to heap, replace x

in t1 with address

22

slide-44
SLIDE 44

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

HEAP-BASED INTERPRETER

computer science

saarland

university

s = s0 ≻ · · · si ≻ · · · ≻ sk Tapes: main (contains si), heap, hc (heap counter) Invariant: size of heap is always polynomial in k and |s|.

◮ For beta-reduction of (λx.t1)t2: Copy t2 to heap, replace x

in t1 with address (linear in the heap, O(|t1|) many copies

  • f an address linear in the heap)

22

slide-45
SLIDE 45

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

HEAP-BASED INTERPRETER

computer science

saarland

university

s = s0 ≻ · · · si ≻ · · · ≻ sk Tapes: main (contains si), heap, hc (heap counter) Invariant: size of heap is always polynomial in k and |s|.

◮ For beta-reduction of (λx.t1)t2: Copy t2 to heap, replace x

in t1 with address (linear in the heap, O(|t1|) many copies

  • f an address linear in the heap)

◮ For variable-unfolding of x: Find the element associated to

x in the heap

22

slide-46
SLIDE 46

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

HEAP-BASED INTERPRETER

computer science

saarland

university

s = s0 ≻ · · · si ≻ · · · ≻ sk Tapes: main (contains si), heap, hc (heap counter) Invariant: size of heap is always polynomial in k and |s|.

◮ For beta-reduction of (λx.t1)t2: Copy t2 to heap, replace x

in t1 with address (linear in the heap, O(|t1|) many copies

  • f an address linear in the heap)

◮ For variable-unfolding of x: Find the element associated to

x in the heap (linear in the heap)

22

slide-47
SLIDE 47

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

HEAP-BASED INTERPRETER

computer science

saarland

university

s = s0 ≻ · · · si ≻ · · · ≻ sk Tapes: main (contains si), heap, hc (heap counter) Invariant: size of heap is always polynomial in k and |s|.

◮ For beta-reduction of (λx.t1)t2: Copy t2 to heap, replace x

in t1 with address (linear in the heap, O(|t1|) many copies

  • f an address linear in the heap)

◮ For variable-unfolding of x: Find the element associated to

x in the heap (linear in the heap) A bit more complicated for de-Bruijn, but doable.

22

slide-48
SLIDE 48

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

COMPLEXITY ANALYSIS

computer science

saarland

university

Theorem

There is a constant c such that any reduction s = s0 ≻ · · · ≻ sk in L can be simulated by the heap-based Turing machine in time and space O(|s| · kc).

23

slide-49
SLIDE 49

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

computer science

saarland

university

Theorem (Invariance thesis part II for time)

Turing machines can simulate L with a polynomially bounded

  • verhead in time.

24

slide-50
SLIDE 50

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

SUB-LINEAR-LOGARITHMICLY SMALL TERMS

computer science

saarland

university

Let N := (λxy.x x) I, then N (· · · (N

  • k times

I) . . .) ≻k (λy.I I) (· · · ((λy.I I)

  • k times

I) . . .) ≻2k I Needs 3k entries (with addresses of size O(k)) on heap, but definition permits only O(k) space

25

slide-51
SLIDE 51

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

COMPLEXITY OVERVIEW

computer science

saarland

university

s = s0 ≻ s1 ≻ · · · ≻ sk for sk with constant size: substitution-based heap-based time O(

i |si|2)

O(poly(Time(s))) space O(Space(s)) O(|s| · kc)

26

slide-52
SLIDE 52

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

PROBLEM ANALYSIS

computer science

saarland

university

s = s0 ≻ · · · ≻ sk Heap-based interpreter needs O(|s| · kc) space on sublinar-logarithmically reducing terms (in k steps).

27

slide-53
SLIDE 53

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

PROBLEM ANALYSIS

computer science

saarland

university

s = s0 ≻ · · · ≻ sk Heap-based interpreter needs O(|s| · kc) space on sublinar-logarithmically reducing terms (in k steps). Substitution-based interpreter needs more than polynomial time on explosive terms where |si| is asymptotically non-polynomial.

27

slide-54
SLIDE 54

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

PROBLEM ANALYSIS

computer science

saarland

university

s = s0 ≻ · · · ≻ sk Heap-based interpreter needs O(|s| · kc) space on sublinar-logarithmically reducing terms (in k steps). Substitution-based interpreter needs more than polynomial time on explosive terms where |si| is asymptotically non-polynomial. But: Heap-based interpreter works on explosive terms!

27

slide-55
SLIDE 55

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

HYBRID INTERPRETER

computer science

saarland

university

Input: A term s. Set k = 0. Execute the substitution-based interpreter on s for k steps:

◮ If a normal form is reached, output it. ◮ If the space consumption is larger than |s| · kc, abort and

use the heap-based interpreter for k steps.

◮ If no normal form is reached, delete everything except s,

set k := k + 1 and repeat.

28

slide-56
SLIDE 56

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

TIME ANALYSIS

computer science

saarland

university

Running time for fixed s and k: In total: O( )

29

slide-57
SLIDE 57

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

TIME ANALYSIS

computer science

saarland

university

Running time for fixed s and k: heap-based interpreter: |s| · kc In total: O( )

29

slide-58
SLIDE 58

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

TIME ANALYSIS

computer science

saarland

university

Running time for fixed s and k: heap-based interpreter: |s| · kc In total: O(

Time(s)

  • k=0

|s| · kc

heap-based

)

29

slide-59
SLIDE 59

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

TIME ANALYSIS

computer science

saarland

university

Running time for fixed s and k: unfolding the normal form: poly(|s| , Time(s))) In total: O(

Time(s)

  • k=0

|s| · kc

heap-based

)

29

slide-60
SLIDE 60

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

TIME ANALYSIS

computer science

saarland

university

Running time for fixed s and k: unfolding the normal form: poly(|s| , Time(s))) In total: O( poly(|t| , Time(s))

  • unfolding the normal form t

+

Time(s)

  • k=0

|s| · kc

heap-based

)

29

slide-61
SLIDE 61

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

TIME ANALYSIS

computer science

saarland

university

Running time for fixed s and k: substitution-based interpreter: O(k

i=1 |si|2)

In total: O( poly(|t| , Time(s))

  • unfolding the normal form t

+

Time(s)

  • k=0

|s| · kc

heap-based

)

29

slide-62
SLIDE 62

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

TIME ANALYSIS

computer science

saarland

university

Running time for fixed s and k: substitution-based interpreter: O(k

i=1 |si|2)

In total: O( poly(|t| , Time(s))

  • unfolding the normal form t

+

Time(s)

  • k=0

|s| · kc

heap-based

+

k

  • i=1

|si|2

substitution-based

)

29

slide-63
SLIDE 63

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

TIME ANALYSIS

computer science

saarland

university

Running time for fixed s and k: because of the space bound: |si| ≤ |s| · kc In total: O( poly(|t| , Time(s))

  • unfolding the normal form t

+

Time(s)

  • k=0

|s| · kc

heap-based

+

k

  • i=1

|si|2

substitution-based

)

29

slide-64
SLIDE 64

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

TIME ANALYSIS

computer science

saarland

university

Running time for fixed s and k: because of the space bound: |si| ≤ |s| · kc thus k

i=1 |si|2 ≤ k · |s|2 · k2c

In total: O( poly(|t| , Time(s))

  • unfolding the normal form t

+

Time(s)

  • k=0

|s| · kc

heap-based

+

k

  • i=1

|si|2

substitution-based

)

29

slide-65
SLIDE 65

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

TIME ANALYSIS

computer science

saarland

university

Running time for fixed s and k: because of the space bound: |si| ≤ |s| · kc thus k

i=1 |si|2 ≤ k · |s|2 · k2c

In total: O( poly(|t| , Time(s))

  • unfolding the normal form t

+

Time(s)

  • k=0

|s| · kc

heap-based

+ k · |s| · k2c

  • substitution-based

)

29

slide-66
SLIDE 66

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

TIME ANALYSIS

computer science

saarland

university

Simplified: O( poly(|t| , Time(s))

  • unfolding the normal form t

+

Time(s)

  • k=0

|s| · kc

heap-based

+ k · |s| · k2c

  • substitution-based

) ⊆ O(poly(|s| , Time(s)) + Time(s)2c+2 · |s|2)

29

slide-67
SLIDE 67

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

SPACE ANALYSIS

computer science

saarland

university

Space consumption for fixed s and k: In total: O( max

k≤Space(s)

)

30

slide-68
SLIDE 68

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

SPACE ANALYSIS

computer science

saarland

university

Space consumption for fixed s and k: substitution-based interpreter: maxi∈{0,...,k} |si| In total: O( max

k≤Space(s)

)

30

slide-69
SLIDE 69

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

SPACE ANALYSIS

computer science

saarland

university

Space consumption for fixed s and k: substitution-based interpreter: maxi∈{0,...,k} |si| = O(Spacek(s)) In total: O( max

k≤Space(s)

)

30

slide-70
SLIDE 70

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

SPACE ANALYSIS

computer science

saarland

university

Space consumption for fixed s and k: substitution-based interpreter: maxi∈{0,...,k} |si| = O(Spacek(s)) In total: O( max

k≤Space(s)Spacek(s)

)

30

slide-71
SLIDE 71

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

SPACE ANALYSIS

computer science

saarland

university

Space consumption for fixed s and k: heap-based interpreter: O(|s| · kc) In total: O( max

k≤Space(s)Spacek(s)

)

30

slide-72
SLIDE 72

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

SPACE ANALYSIS

computer science

saarland

university

Space consumption for fixed s and k: heap-based interpreter: O(|s| · kc) In total: O( max

k≤Space(s)Spacek(s)+ |s| · kc) 30

slide-73
SLIDE 73

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

SPACE ANALYSIS

computer science

saarland

university

Space consumption for fixed s and k: because of the space bound: Spacek(s) ≥ |s| · kc In total: O( max

k≤Space(s)Spacek(s)+ |s| · kc) 30

slide-74
SLIDE 74

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

SPACE ANALYSIS

computer science

saarland

university

Space consumption for fixed s and k: because of the space bound: Spacek(s) ≥ |s| · kc In total: O( max

k≤Space(s)Spacek(s)+Spacek(s)) 30

slide-75
SLIDE 75

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

SPACE ANALYSIS

computer science

saarland

university

Simplified: O( max

k≤Space(s)Spacek(s)+Spacek(s))

⊆ O(Space(s))

30

slide-76
SLIDE 76

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

computer science

saarland

university

Theorem (Strong Invariance Thesis for L)

L and Turing Machines can simulate each other within a polynomially bounded overhead in time and a constant-factor

  • verhead in space for decision functions with non-sublinear running

time.

31

slide-77
SLIDE 77

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

WORK IN PROGRESS: FORMALISATION

computer science

saarland

university

spec proof Functional correctness of L-interpreters 1192 1390 L-extraction framework 1316 610 TM-interpreter (no verified complexity analysis) 388 335

32

slide-78
SLIDE 78

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

WORK IN PROGRESS: FORMALISATION

computer science

saarland

university

spec proof Functional correctness of L-interpreters 1192 1390 L-extraction framework 1316 610 TM-interpreter (no verified complexity analysis) 388 335 Missing:

◮ TM implementation and verification of L-interpreters ◮ Time and space analysis of L-interpreters ◮ Time and space analysis of TM-interpreter 32

slide-79
SLIDE 79

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

SUMMARY

computer science

saarland

university

The weak call-by-value λ-calculus L is as reasonable for complexity theory as Turing machines.

33

slide-80
SLIDE 80

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

SUMMARY

computer science

saarland

university

The weak call-by-value λ-calculus L is as reasonable for complexity theory as Turing machines. Future work:

◮ Formalise the complexity analysis ◮ Complexity theory using L: NP, many-one-reductions,

hierarchy theorems, . . .

33

slide-81
SLIDE 81

Introduction The calculus L Simulating TMs Simulating L with substitutions Simulating L with a heap Hybrid Interpreter

SUMMARY

computer science

saarland

university

The weak call-by-value λ-calculus L is as reasonable for complexity theory as Turing machines. Future work:

◮ Formalise the complexity analysis ◮ Complexity theory using L: NP, many-one-reductions,

hierarchy theorems, . . .

Thanks!

33

slide-82
SLIDE 82

THE HEAP-BASED INTERPRETER

computer science

saarland

university

Use environments on a heap to delay substitutions:

◮ call (thunk) c = sE: pair of encoded L-term s and heap-address E ◮ heap H: list of entries (⊥ or c#E′), addressed by position. ◮ call stack CS: list of tuples (@L, c) or (@R, c) (for @R, c fully reduced) ◮ interpreter state: current call CC, CS and H. ◮ initial state: CC = s0, CS = [] and H = [⊥])

Example

The result of (λx.x) ((λxy.x y) (λx.x)) ≻ (λx.x) (λx.x y)y

λx.x is represented by

CC =(λ@ ⊲ |⊲)1 CS =[(@R, (λ⊲)0)] H =[⊥, (λ⊲)0)#0]

34

slide-83
SLIDE 83

THE HEAP-BASED INTERPRETER (2)

computer science

saarland

university

Each step of the interpreter depends on the current call CC = sE:

◮ if s = sL sR: push (@L, sR[E]) on CS and set CC to sRE ◮ if s = x: get new CC by lookup of x in E ◮ if s = λs′:

◮ if CS is empty: the term is fully evaluated ◮ if CS = (@L, cR) :: CS′: set CC := cR and put (@R, CC) on

stack instead.

◮ if CS = (@R, λtE′) :: CS′: store sRE#E′ on heap as ˆ

E and set CC := tˆ E

35

slide-84
SLIDE 84

THE HEAP-BASED INTERPRETER (2)

computer science

saarland

university

Each step of the interpreter depends on the current call CC = sE:

◮ if s = sL sR: push (@L, sR[E]) on CS and set CC to sRE ◮ if s = x: get new CC by lookup of x in E ◮ if s = λs′:

◮ if CS is empty: the term is fully evaluated ◮ if CS = (@L, cR) :: CS′: set CC := cR and put (@R, CC) on

stack instead.

◮ if CS = (@R, λtE′) :: CS′: store sRE#E′ on heap as ˆ

E and set CC := tˆ E

Observations for evaluation s0 ≻ s1 ≻ · · · ≻ sk:

◮ all calls contain subterms of s ◮ Heap contains #H = k + 1 elements, each of size ≤ |s| + 2 · log(#H) ◮ CS & CC representing si have size O(|si|)

⇒ space consumption: O((maxi |si|) + k · (|s| + log(k)))

35

slide-85
SLIDE 85

THE HEAP-BASED INTERPRETER (2)

computer science

saarland

university

Each step of the interpreter depends on the current call CC = sE:

◮ if s = sL sR: push (@L, sR[E]) on CS and set CC to sRE ◮ if s = x: get new CC by lookup of x in E ◮ if s = λs′:

◮ if CS is empty: the term is fully evaluated ◮ if CS = (@L, cR) :: CS′: set CC := cR and put (@R, CC) on

stack instead.

◮ if CS = (@R, λtE′) :: CS′: store sRE#E′ on heap as ˆ

E and set CC := tˆ E

Observations for evaluation s0 ≻ s1 ≻ · · · ≻ sk:

◮ all calls contain subterms of s ◮ Heap contains #H = k + 1 elements, each of size ≤ |s| + 2 · log(#H) ◮ CS & CC representing si have size O(|si|)

⇒ space consumption: O((maxi |si|) + k · (|s| + log(k)))

◮ time per interpreter step: O(|si| · #H + CC + CS) ◮ amortized, poly(|s0|) interpreter-steps per β-reduction.

⇒ time consumption: O(poly(k, |s0|))

35

slide-86
SLIDE 86

LC: L WITH CLOSURES

computer science

saarland

university 36