The Beta Cube a 1 , 2 Pablo Nogueira 2 us Gallego Arias 2 Alvaro - - PowerPoint PPT Presentation

the beta cube
SMART_READER_LITE
LIVE PREVIEW

The Beta Cube a 1 , 2 Pablo Nogueira 2 us Gallego Arias 2 Alvaro - - PowerPoint PPT Presentation

The Beta Cube a 1 , 2 Pablo Nogueira 2 us Gallego Arias 2 Alvaro Garc Emilio Jes 1 IMDEA Software Institute 2 Babel Research Group, Universidad Polit ecnica de Madrid ITU 2011, Kobenham 1 / 29 Context Reduction strategies for


slide-1
SLIDE 1

The Beta Cube

´ Alvaro Garc´ ıa1,2 Pablo Nogueira2 Emilio Jes´ us Gallego Arias2

1IMDEA Software Institute 2Babel Research Group, Universidad Polit´

ecnica de Madrid

ITU 2011, Kobenham

1 / 29

slide-2
SLIDE 2

Context

◮ Reduction strategies for the pure (untyped) lambda calculus. . .

2 / 29

slide-3
SLIDE 3

Context

◮ Reduction strategies for the pure (untyped) lambda calculus. . .

◮ Normal Order, Applicative (Standard) Order [Barendregt 1984]. 2 / 29

slide-4
SLIDE 4

Context

◮ Reduction strategies for the pure (untyped) lambda calculus. . .

◮ Normal Order, Applicative (Standard) Order [Barendregt 1984]. ◮ Call-by-name, Call-by-value [Plotkin 1975] [Sestoft 2002]. 2 / 29

slide-5
SLIDE 5

Context

◮ Reduction strategies for the pure (untyped) lambda calculus. . .

◮ Normal Order, Applicative (Standard) Order [Barendregt 1984]. ◮ Call-by-name, Call-by-value [Plotkin 1975] [Sestoft 2002]. ◮ Head spine (he) [Sestoft 2002] (headNF in [Paulson 1996]). 2 / 29

slide-6
SLIDE 6

Context

◮ Reduction strategies for the pure (untyped) lambda calculus. . .

◮ Normal Order, Applicative (Standard) Order [Barendregt 1984]. ◮ Call-by-name, Call-by-value [Plotkin 1975] [Sestoft 2002]. ◮ Head spine (he) [Sestoft 2002] (headNF in [Paulson 1996]). ◮ Hybrid applicative order (ha) [Sestoft 2002]. 2 / 29

slide-7
SLIDE 7

Context

◮ Reduction strategies for the pure (untyped) lambda calculus. . .

◮ Normal Order, Applicative (Standard) Order [Barendregt 1984]. ◮ Call-by-name, Call-by-value [Plotkin 1975] [Sestoft 2002]. ◮ Head spine (he) [Sestoft 2002] (headNF in [Paulson 1996]). ◮ Hybrid applicative order (ha) [Sestoft 2002]. ◮ Hybrid normal order (hn) [Sestoft 2002]. 2 / 29

slide-8
SLIDE 8

Context

◮ Reduction strategies for the pure (untyped) lambda calculus. . .

◮ Normal Order, Applicative (Standard) Order [Barendregt 1984]. ◮ Call-by-name, Call-by-value [Plotkin 1975] [Sestoft 2002]. ◮ Head spine (he) [Sestoft 2002] (headNF in [Paulson 1996]). ◮ Hybrid applicative order (ha) [Sestoft 2002]. ◮ Hybrid normal order (hn) [Sestoft 2002]. ◮ Head reduction (hr) [Barendregt 1984]. 2 / 29

slide-9
SLIDE 9

Context

◮ Reduction strategies for the pure (untyped) lambda calculus. . .

◮ Normal Order, Applicative (Standard) Order [Barendregt 1984]. ◮ Call-by-name, Call-by-value [Plotkin 1975] [Sestoft 2002]. ◮ Head spine (he) [Sestoft 2002] (headNF in [Paulson 1996]). ◮ Hybrid applicative order (ha) [Sestoft 2002]. ◮ Hybrid normal order (hn) [Sestoft 2002]. ◮ Head reduction (hr) [Barendregt 1984]. ◮ . . . 2 / 29

slide-10
SLIDE 10

Context

◮ Reduction strategies for the pure (untyped) lambda calculus. . .

◮ Normal Order, Applicative (Standard) Order [Barendregt 1984]. ◮ Call-by-name, Call-by-value [Plotkin 1975] [Sestoft 2002]. ◮ Head spine (he) [Sestoft 2002] (headNF in [Paulson 1996]). ◮ Hybrid applicative order (ha) [Sestoft 2002]. ◮ Hybrid normal order (hn) [Sestoft 2002]. ◮ Head reduction (hr) [Barendregt 1984]. ◮ . . .

◮ . . . defined by sets of big-step rules.

2 / 29

slide-11
SLIDE 11

What are strategies useful for?

◮ Program optimization via partial evaluation.

3 / 29

slide-12
SLIDE 12

What are strategies useful for?

◮ Program optimization via partial evaluation. ◮ β-equivalence testers for typing rules in dependent types.

3 / 29

slide-13
SLIDE 13

What are strategies useful for?

◮ Program optimization via partial evaluation. ◮ β-equivalence testers for typing rules in dependent types. ◮ Interpreting universes in structural generic programming with

dependent types.

3 / 29

slide-14
SLIDE 14

What are strategies useful for?

◮ Program optimization via partial evaluation. ◮ β-equivalence testers for typing rules in dependent types. ◮ Interpreting universes in structural generic programming with

dependent types.

◮ . . .

3 / 29

slide-15
SLIDE 15

Pure lambda calculus reduction strategies (big-step)

Call-by-name (cbn): x

cbn

→ x λx.B

cbn

→ λx.B

  • M

cbn

→ M′ ≡ λx.B [N/x]B

cbn

→ S M N

cbn

→ S

  • M

cbn

→ M′ ≡ λx.B M N

cbn

→ M′ N

4 / 29

slide-16
SLIDE 16

Pure lambda calculus reduction strategies (big-step)

Call-by-name (cbn): Normal order (nor): x

cbn

→ x x

nor

→ x λx.B

cbn

→ λx.B B

nor

→ B′ λx.B

nor

→ λx.B′

  • M

cbn

→ M′ ≡ λx.B [N/x]B

cbn

→ S M N

cbn

→ S

  • M

cbn

→ M′ ≡ λx.B [N/x]B

nor

→ S M N

nor

→ S

  • M

cbn

→ M′ ≡ λx.B M N

cbn

→ M′ N

  • M

cbn

→ M′ ≡ λx.B M′ nor → M′′ N

nor

→ N′′ M N

nor

→ M′′ N′′ Subsidiary Hybrid

4 / 29

slide-17
SLIDE 17

Pure lambda calculus reduction strategies (big-step)

Call-by-name (cbn): Normal order (nor): x

cbn

→ x x

nor

→ x λx.B

cbn

→ λx.B B

nor

→ B′ λx.B

nor

→ λx.B′

  • M

cbn

→ M′ ≡ λx.B [N/x]B

cbn

→ S M N

cbn

→ S

  • M

cbn

→ M′ ≡ λx.B [N/x]B

nor

→ S M N

nor

→ S

  • M

cbn

→ M′ ≡ λx.B M N

cbn

→ M′ N

  • M

cbn

→ M′ ≡ λx.B M′ nor → M′′ N

nor

→ N′′ M N

nor

→ M′′ N′′ Subsidiary Hybrid Hybrid reduces in more places than subsidiary!

4 / 29

slide-18
SLIDE 18

Pure lambda calculus reduction strategies (big-step)

Rule Template:

var x

st

→ x

abs

B

la

→ B′ λx.B st → λx.B′

red M op1

→ M′ ≡ λx.B N ar1 → N′ [N′/x]B su → S M N st → S

app M op1

→ M′ ≡ λx.B M′ op2 → M′′ N ar2 → N′ M N st → M′′ N′

5 / 29

slide-19
SLIDE 19

Pure lambda calculus reduction strategies (big-step)

Rule Template:

var x

st

→ x

abs

B

la

→ B′ λx.B st → λx.B′

red M op1

→ M′ ≡ λx.B N ar1 → N′ [N′/x]B su → S M N st → S

app M op1

→ M′ ≡ λx.B M′ op2 → M′′ N ar2 → N′ M N st → M′′ N′

5 / 29

slide-20
SLIDE 20

Pure lambda calculus reduction strategies (big-step)

Rule Template (cbn):

var x cbn

→ x

abs

B id → B λx.B cbn → λx.B

red M cbn

→ M′ ≡ λx.B N id → N [N /x]B cbn → S M N cbn → S

app M cbn

→ M′ ≡ λx.B M′ id → M′ N id → N M N cbn → M′ N

5 / 29

slide-21
SLIDE 21

Pure lambda calculus reduction strategies (big-step)

Rule Template (cbv):

var x cbv

→ x

abs

B id → B λx.B cbv → λx.B

red M cbv

→ M′ ≡ λx.B N cbv → N′ [N′/x]B cbv → S M N cbv → S

app M cbv

→ M′ ≡ λx.B M′ id → M′ N cbv → N′ M N cbv → M′ N′

5 / 29

slide-22
SLIDE 22

Pure lambda calculus reduction strategies (big-step)

Rule Template (aor):

var x aor

→ x

abs

B aor → B′ λx.B aor → λx.B′

red M aor

→ M′ ≡ λx.B N aor → N′ [N′/x]B aor → S M N aor → S

app M aor

→ M′ ≡ λx.B M′ id → M′ N aor → N′ M N aor → M′ N′

5 / 29

slide-23
SLIDE 23

Pure lambda calculus reduction strategies (big-step)

Rule Template (nor):

var x nor

→ x

abs

B nor → B′ λx.B nor → λx.B′

red M cbn

→ M′ ≡ λx.B N id → N [N /x]B nor → S M N nor → S

app M cbn

→ M′ ≡ λx.B M′ nor → M′′ N nor → N′ M N nor → M′′ N′ Use of op1 and op2 to accomodate hybrid strategies!

5 / 29

slide-24
SLIDE 24

The Beta Cube

Parameters la, ar1 and ar2 are either recursive calls or identity. Interpreted as boolean switches:

6 / 29

slide-25
SLIDE 25

The Beta Cube

Parameters la, ar1 and ar2 are either recursive calls or identity. Interpreted as boolean switches: (⊑)

AOR CBV

  • 1 0 1
  • 0 0 1
  • 1 1 0
  • 0 1 0
  • HE
  • CBN
  • la
  • ar1
  • ar2
  • 6 / 29
slide-26
SLIDE 26

The Beta Cube

Parameters la, ar1 and ar2 are either recursive calls or identity. Interpreted as boolean switches: (⊑)

AOR CBV

  • 1 0 1
  • 0 0 1
  • 1 1 0
  • 0 1 0
  • HE
  • CBN
  • la
  • 0 weakness

1 strength ar1

  • 0 non-strictness

1 strictness ar2

  • 0 headness

1 non-headness

6 / 29

slide-27
SLIDE 27

The Beta Cube

Parameters la, ar1 and ar2 are either recursive calls or identity. Interpreted as boolean switches: (⊑)

AOR CBV

  • 1 0 1
  • 0 0 1
  • 1 1 0
  • 0 1 0
  • HE
  • CBN
  • la
  • 0 weakness

1 strength ar1

  • 0 non-strictness

1 strictness ar2

  • 0 headness

1 non-headness

nf wnf

  • hnf
  • whnf
  • 6 / 29
slide-28
SLIDE 28

Axis of eval

var x cbn

→ x

abs λx.B cbn

→ λx.B

red M cbn

→ M′ ≡ λx.B [N /x]B cbn → S M N cbn → S

app M cbn

→ M′ ≡ λx.B M N cbn → M′ N

AOR CBV

  • 1 0 1
  • 0 0 1
  • 1 1 0
  • 0 1 0
  • HE
  • CBN
  • la
  • strength

ar1

  • strictness

ar2

  • non-headness

7 / 29

slide-29
SLIDE 29

Axis of eval

var x cbv

→ x

abs λx.B cbv

→ λx.B

red M cbv

→ M′ ≡ λx.B N cbv → N′ [N′/x]B cbv → S M N cbv → S

app M cbv

→ M′ ≡ λx.B N cbv → N′ M N cbv → M′ N′

AOR

  • CBV
  • 1 0 1
  • 0 0 1
  • 1 1 0
  • 0 1 0
  • HE
  • CBN
  • la
  • strength

ar1

  • strictness

ar2

  • non-headness

7 / 29

slide-30
SLIDE 30

Axis of eval

var x aor

→ x

abs

B aor → B′ λx.B aor → λx.B′

red M aor

→ M′ ≡ λx.B N aor → N′ [N′/x]B aor → S M N aor → S

app M aor

→ M′ ≡ λx.B N aor → N′ M N aor → M′ N′

  • AOR
  • CBV
  • 1 0 1
  • 0 0 1
  • 1 1 0
  • 0 1 0
  • HE
  • CBN
  • la
  • strength

ar1

  • strictness

ar2

  • non-headness

7 / 29

slide-31
SLIDE 31

Absorption

◮ Applying s2 before applying s1 doesn’t change the result of s1:

s1 absorpts s2 iff s1(t) =α s1(s2(t)).

8 / 29

slide-32
SLIDE 32

Absorption

◮ Applying s2 before applying s1 doesn’t change the result of s1:

s1 absorpts s2 iff s1(t) =α s1(s2(t)).

◮ s1 absorpts s2 iff s2 is a left identity of s1.

t

s1

→ t′ iff t

s2

→ t′′ s1 → t′ t

s1

  • iff

     t

s2

  • r

t

s2

→ t′′ s1

  • 8 / 29
slide-33
SLIDE 33

Absorption among uniform strategies

◮ We analyse the pairs of strategies in the order relation.

9 / 29

slide-34
SLIDE 34

Absorption among uniform strategies

◮ We analyse the pairs of strategies in the order relation. ◮ Counterexamples:

9 / 29

slide-35
SLIDE 35

Absorption among uniform strategies

◮ We analyse the pairs of strategies in the order relation. ◮ Counterexamples:

◮ Any strict sts and non-strict st strategies (differing at least in ar1):

(sts ◦ st)((λx.λy.x) x Ω) =α sts((λx.λy.x) x Ω).

9 / 29

slide-36
SLIDE 36

Absorption among uniform strategies

◮ We analyse the pairs of strategies in the order relation. ◮ Counterexamples:

◮ Any strict sts and non-strict st strategies (differing at least in ar1):

(sts ◦ st)((λx.λy.x) x Ω) =α sts((λx.λy.x) x Ω).

◮ Any strong non-head strategy st and its weak or head (or

weak-head) counterpart stwh (differing in la or ar2 or both): (st ◦ stwh)((λk.k Ω) (λx.y)) =α st((λk.k Ω) (λx.y)).

9 / 29

slide-37
SLIDE 37

Absorption among uniform strategies

◮ We analyse the pairs of strategies in the order relation. ◮ Counterexamples:

◮ Any strict sts and non-strict st strategies (differing at least in ar1):

(sts ◦ st)((λx.λy.x) x Ω) =α sts((λx.λy.x) x Ω).

◮ Any strong non-head strategy st and its weak or head (or

weak-head) counterpart stwh (differing in la or ar2 or both): (st ◦ stwh)((λk.k Ω) (λx.y)) =α st((λk.k Ω) (λx.y)).

◮ Any strict strong strategy st and any strict weak strategy stw

(differing at least in la, with ar1 = True): (st ◦ stw)(Z RecF Input d) =α st(Z RecF Input d).

9 / 29

slide-38
SLIDE 38

Absorption among uniform strategies

◮ We analyse the pairs of strategies in the order relation. ◮ Counterexamples:

◮ Any strict sts and non-strict st strategies (differing at least in ar1):

(sts ◦ st)((λx.λy.x) x Ω) =α sts((λx.λy.x) x Ω).

◮ Any strong non-head strategy st and its weak or head (or

weak-head) counterpart stwh (differing in la or ar2 or both): (st ◦ stwh)((λk.k Ω) (λx.y)) =α st((λk.k Ω) (λx.y)).

◮ Any strict strong strategy st and any strict weak strategy stw

(differing at least in la, with ar1 = True): (st ◦ stw)(Z RecF Input d) =α st(Z RecF Input d).

◮ The strategies cbv and 0 1 0 (weak strict strategies differing in ar2):

(cbv ◦ 0 1 0)((λx.λy.x) x (x Ω)) =α cbv((λx.λy.x) x (x Ω))

9 / 29

slide-39
SLIDE 39

Absorption among uniform strategies

◮ We analyse the pairs of strategies in the order relation. ◮ Counterexamples:

◮ Any strict sts and non-strict st strategies (differing at least in ar1):

(sts ◦ st)((λx.λy.x) x Ω) =α sts((λx.λy.x) x Ω).

◮ Any strong non-head strategy st and its weak or head (or

weak-head) counterpart stwh (differing in la or ar2 or both): (st ◦ stwh)((λk.k Ω) (λx.y)) =α st((λk.k Ω) (λx.y)).

◮ Any strict strong strategy st and any strict weak strategy stw

(differing at least in la, with ar1 = True): (st ◦ stw)(Z RecF Input d) =α st(Z RecF Input d).

◮ The strategies cbv and 0 1 0 (weak strict strategies differing in ar2):

(cbv ◦ 0 1 0)((λx.λy.x) x (x Ω)) =α cbv((λx.λy.x) x (x Ω))

◮ Proofs:

9 / 29

slide-40
SLIDE 40

Absorption among uniform strategies

◮ We analyse the pairs of strategies in the order relation. ◮ Counterexamples:

◮ Any strict sts and non-strict st strategies (differing at least in ar1):

(sts ◦ st)((λx.λy.x) x Ω) =α sts((λx.λy.x) x Ω).

◮ Any strong non-head strategy st and its weak or head (or

weak-head) counterpart stwh (differing in la or ar2 or both): (st ◦ stwh)((λk.k Ω) (λx.y)) =α st((λk.k Ω) (λx.y)).

◮ Any strict strong strategy st and any strict weak strategy stw

(differing at least in la, with ar1 = True): (st ◦ stw)(Z RecF Input d) =α st(Z RecF Input d).

◮ The strategies cbv and 0 1 0 (weak strict strategies differing in ar2):

(cbv ◦ 0 1 0)((λx.λy.x) x (x Ω)) =α cbv((λx.λy.x) x (x Ω))

◮ Proofs:

◮ 0 0 1 absorpts cbn. By induction on the structure of the derivations. 9 / 29

slide-41
SLIDE 41

Absorption among uniform strategies

◮ We still don’t know if he absorpts cbn.

10 / 29

slide-42
SLIDE 42

Hybridisation: motivation

◮ Uniform strategies are not normalising (to NF). ◮ Standard reduction is neccesary for normalisation [Curry and Feys

1958]: Never reduce to the left of the residual of an already-reduced redex.

◮ A way to standardise: operators and operands in applications should

be reduced to values (` a la Plotkin).

◮ Hybridisation: produce new strategies that modify uniform strategies

  • n this very point.

11 / 29

slide-43
SLIDE 43

Hybridisation template

Hybrid strategy from subsidiary S and base B:

x

sub

→ x B

sub

− − →

S.la B′

λx.B

sub

→ λx.B′

  • M

sub

→ λx.B N

sub

− − − →

S.ar1 N′

[N′/x]B

sub

→ S M N

sub

→ S

  • M

sub

→ M′ ≡ λx.B N

sub

− − − →

S.ar2 N′

M N

sub

→ M′ N′

12 / 29

slide-44
SLIDE 44

Hybridisation template

Hybrid strategy from subsidiary S and base B:

x

sub

→ x B

sub

− − →

S.la B′

λx.B

sub

→ λx.B′

  • M

sub

→ λx.B N

sub

− − − →

S.ar1 N′

[N′/x]B

sub

→ S M N

sub

→ S

  • M

sub

→ M′ ≡ λx.B N

sub

− − − →

S.ar2 N′

M N

sub

→ M′ N′

12 / 29

slide-45
SLIDE 45

Hybridisation template

Hybrid strategy from subsidiary S and base B:

x

sub

→ x x

hyb

→ x B

sub

− − →

S.la B′

λx.B

sub

→ λx.B′ B

hyb

− − →

B.la B′

λx.B

hyb

→ λx.B′

  • M

sub

→ λx.B N

sub

− − − →

S.ar1 N′

[N′/x]B

sub

→ S M N

sub

→ S

  • M

sub

→ λx.B N

sub

− − − →

B.ar1 N′

[N′/x]B

hyb

→ S M N

hyb

→ S

  • M

sub

→ M′ ≡ λx.B N

sub

− − − →

S.ar2 N′

M N

sub

→ M′ N′

  • M

sub

→ M′ ≡ λx.B M′ hyb → M′′ N

hyb

− − − →

B.ar2 N′′

M N

hyb

→ M′′ N′′

12 / 29

slide-46
SLIDE 46

Hybridisation template

Hybrid strategy from subsidiary S and base B:

x

sub

→ x x

hyb

→ x B

sub

− − →

S.la B′

λx.B

sub

→ λx.B′ B

hyb

− − →

B.la B′

λx.B

hyb

→ λx.B′

  • M

sub

→ λx.B N

sub

− − − →

S.ar1 N′

[N′/x]B

sub

→ S M N

sub

→ S

  • M

sub

→ λx.B N

sub

− − − →

B.ar1 N′

[N′/x]B

hyb

→ S M N

hyb

→ S

  • M

sub

→ M′ ≡ λx.B N

sub

− − − →

S.ar2 N′

M N

sub

→ M′ N′

  • M

sub

→ M′ ≡ λx.B M′ hyb → M′′ N

hyb

− − − →

B.ar2 N′′

M N

hyb

→ M′′ N′′

12 / 29

slide-47
SLIDE 47

Hybridisation template

Hybrid strategy from subsidiary S and base B:

x

sub

→ x x

hyb

→ x B

sub

− − →

S.la B′

λx.B

sub

→ λx.B′ B

hyb

− − →

B.la B′

λx.B

hyb

→ λx.B′

  • M

sub

→ λx.B N

sub

− − − →

S.ar1 N′

[N′/x]B

sub

→ S M N

sub

→ S

  • M

sub

→ λx.B N

sub

− − − →

B.ar1 N′

[N′/x]B

hyb

→ S M N

hyb

→ S

  • M

sub

→ M′ ≡ λx.B N

sub

− − − →

S.ar2 N′

M N

sub

→ M′ N′

  • M

sub

→ M′ ≡ λx.B M′ hyb → M′′ N

hyb

− − − →

B.ar2 N′′

M N

hyb

→ M′′ N′′

hyb or sub for the operand?

12 / 29

slide-48
SLIDE 48

Hybridisation template

Hybrid strategy from subsidiary S and base B:

x

sub

→ x x

hyb

→ x B

sub

− − →

S.la B′

λx.B

sub

→ λx.B′ B

hyb

− − →

B.la B′

λx.B

hyb

→ λx.B′

  • M

sub

→ λx.B N

sub

− − − →

S.ar1 N′

[N′/x]B

sub

→ S M N

sub

→ S

  • M

sub

→ λx.B N

sub

− − − →

B.ar1 N′

[N′/x]B

hyb

→ S M N

hyb

→ S

  • M

sub

→ M′ ≡ λx.B N

sub

− − − →

S.ar2 N′

M N

sub

→ M′ N′

  • M

sub

→ M′ ≡ λx.B M′ hyb → M′′ N

hyb

− − − →

B.ar2 N′′

M N

hyb

→ M′′ N′′

hyb or sub for the operand?

◮ Standardisation [Curry and Feys 1958] and absorption [Garcia et al.

2010] issues.

12 / 29

slide-49
SLIDE 49

Hybridisation and the Beta Cube

cbn:

var x cbn

→ x

abs λx.B cbn

→ λx.B

red

  • M

cbn

→ M′ ≡ λx.B [N/x]B cbn → S M N cbn → S

app

  • M

cbn

→ M′ ≡ λx.B M N cbn → M′ N

AOR CBV

  • 1 0 1
  • 0 0 1
  • 1 1 0
  • 0 1 0
  • HE
  • CBN
  • la
  • strength

ar1

  • strictness

ar2

  • non-headness

13 / 29

slide-50
SLIDE 50

Hybridisation and the Beta Cube

nor ≡ hybridise(cbn,1 0 1):

var x nor

→ x

abs

B nor → B′ λx.B nor → λx.B′

red

  • M

cbn

→ M′ ≡ λx.B [N/x]B nor → S M N nor → S

app

  • M

cbn

→ M′ ≡ λx.B M′ nor → M′′ N

nor

→ N′ M N nor → M′′ N′

AOR CBV

  • 1 0 1
  • 0 0 1
  • 1 1 0
  • 0 1 0
  • HE
  • CBN
  • la
  • strength

ar1

  • strictness

ar2

  • non-headness

13 / 29

slide-51
SLIDE 51

Absorption theorem

Theorem

Let S and B be respectively a subsidiary and a base strategy considered as points in the cube which satisfy S ⊑ B and S.ar1 = B.ar1. Let

sub

→ and

hyb

→ be the resulting instantiated strategies. Then (hyb ◦ sub)(t) = hyb(t) for any term t.

Proof.

By induction on the structure of the derivations.

14 / 29

slide-52
SLIDE 52

Sestoft’s hibrydisation

◮ hybridiseSestoft uses hyb for the selection of ar1.

15 / 29

slide-53
SLIDE 53

Sestoft’s hibrydisation

◮ hybridiseSestoft uses hyb for the selection of ar1. ◮ Consider ha = hybridiseSestoft(cbv, aor).

15 / 29

slide-54
SLIDE 54

Sestoft’s hibrydisation

◮ hybridiseSestoft uses hyb for the selection of ar1. ◮ Consider ha = hybridiseSestoft(cbv, aor).

◮ ha reduces to normal form. 15 / 29

slide-55
SLIDE 55

Sestoft’s hibrydisation

◮ hybridiseSestoft uses hyb for the selection of ar1. ◮ Consider ha = hybridiseSestoft(cbv, aor).

◮ ha reduces to normal form. ◮ The operands of applications are reduced to normal forms before

substitution.

15 / 29

slide-56
SLIDE 56

Sestoft’s hibrydisation

◮ hybridiseSestoft uses hyb for the selection of ar1. ◮ Consider ha = hybridiseSestoft(cbv, aor).

◮ ha reduces to normal form. ◮ The operands of applications are reduced to normal forms before

substitution.

◮ Standard reduction: never reduce to the left of the residual of an

already-reduced redex, but. . .

15 / 29

slide-57
SLIDE 57

Sestoft’s hibrydisation

◮ hybridiseSestoft uses hyb for the selection of ar1. ◮ Consider ha = hybridiseSestoft(cbv, aor).

◮ ha reduces to normal form. ◮ The operands of applications are reduced to normal forms before

substitution.

◮ Standard reduction: never reduce to the left of the residual of an

already-reduced redex, but. . . . . . operands are reduced by the hybrid:

15 / 29

slide-58
SLIDE 58

Sestoft’s hibrydisation

◮ hybridiseSestoft uses hyb for the selection of ar1. ◮ Consider ha = hybridiseSestoft(cbv, aor).

◮ ha reduces to normal form. ◮ The operands of applications are reduced to normal forms before

substitution.

◮ Standard reduction: never reduce to the left of the residual of an

already-reduced redex, but. . . . . . operands are reduced by the hybrid:

◮ If the operand is not a value then we still don’t have a redex. 15 / 29

slide-59
SLIDE 59

Sestoft’s hibrydisation

◮ hybridiseSestoft uses hyb for the selection of ar1. ◮ Consider ha = hybridiseSestoft(cbv, aor).

◮ ha reduces to normal form. ◮ The operands of applications are reduced to normal forms before

substitution.

◮ Standard reduction: never reduce to the left of the residual of an

already-reduced redex, but. . . . . . operands are reduced by the hybrid:

◮ If the operand is not a value then we still don’t have a redex. ◮ We reduce the operand to a value. Now the application is a redex. 15 / 29

slide-60
SLIDE 60

Sestoft’s hibrydisation

◮ hybridiseSestoft uses hyb for the selection of ar1. ◮ Consider ha = hybridiseSestoft(cbv, aor).

◮ ha reduces to normal form. ◮ The operands of applications are reduced to normal forms before

substitution.

◮ Standard reduction: never reduce to the left of the residual of an

already-reduced redex, but. . . . . . operands are reduced by the hybrid:

◮ If the operand is not a value then we still don’t have a redex. ◮ We reduce the operand to a value. Now the application is a redex. ◮ We keep reducing the operand up to a normal form.

The value in the operand position is reduced before reducing the redex itself!

15 / 29

slide-61
SLIDE 61

Sestoft’s hibrydisation

◮ hybridiseSestoft uses hyb for the selection of ar1. ◮ Consider ha = hybridiseSestoft(cbv, aor).

◮ ha reduces to normal form. ◮ The operands of applications are reduced to normal forms before

substitution.

◮ Standard reduction: never reduce to the left of the residual of an

already-reduced redex, but. . . . . . operands are reduced by the hybrid:

◮ If the operand is not a value then we still don’t have a redex. ◮ We reduce the operand to a value. Now the application is a redex. ◮ We keep reducing the operand up to a normal form.

The value in the operand position is reduced before reducing the redex itself!

◮ Consequently:

15 / 29

slide-62
SLIDE 62

Sestoft’s hibrydisation

◮ hybridiseSestoft uses hyb for the selection of ar1. ◮ Consider ha = hybridiseSestoft(cbv, aor).

◮ ha reduces to normal form. ◮ The operands of applications are reduced to normal forms before

substitution.

◮ Standard reduction: never reduce to the left of the residual of an

already-reduced redex, but. . . . . . operands are reduced by the hybrid:

◮ If the operand is not a value then we still don’t have a redex. ◮ We reduce the operand to a value. Now the application is a redex. ◮ We keep reducing the operand up to a normal form.

The value in the operand position is reduced before reducing the redex itself!

◮ Consequently:

◮ ha does not absorb cbv [Garcia et al. 2010]. 15 / 29

slide-63
SLIDE 63

Sestoft’s hibrydisation

◮ hybridiseSestoft uses hyb for the selection of ar1. ◮ Consider ha = hybridiseSestoft(cbv, aor).

◮ ha reduces to normal form. ◮ The operands of applications are reduced to normal forms before

substitution.

◮ Standard reduction: never reduce to the left of the residual of an

already-reduced redex, but. . . . . . operands are reduced by the hybrid:

◮ If the operand is not a value then we still don’t have a redex. ◮ We reduce the operand to a value. Now the application is a redex. ◮ We keep reducing the operand up to a normal form.

The value in the operand position is reduced before reducing the redex itself!

◮ Consequently:

◮ ha does not absorb cbv [Garcia et al. 2010]. ◮ ha is not a standard βV -reduction. 15 / 29

slide-64
SLIDE 64

Sestoft’s hibrydisation

◮ hybridiseSestoft uses hyb for the selection of ar1. ◮ Consider ha = hybridiseSestoft(cbv, aor).

◮ ha reduces to normal form. ◮ The operands of applications are reduced to normal forms before

substitution.

◮ Standard reduction: never reduce to the left of the residual of an

already-reduced redex, but. . . . . . operands are reduced by the hybrid:

◮ If the operand is not a value then we still don’t have a redex. ◮ We reduce the operand to a value. Now the application is a redex. ◮ We keep reducing the operand up to a normal form.

The value in the operand position is reduced before reducing the redex itself!

◮ Consequently:

◮ ha does not absorb cbv [Garcia et al. 2010]. ◮ ha is not a standard βV -reduction. ◮ ha is not normalising in λV . 15 / 29

slide-65
SLIDE 65

Implementations in OCaML and Haskell

◮ Rule Template:

◮ Generic reducer: higher-order. ◮ (Haskell) Monadic reducer: strict monads for strict semantics. ◮ Particular strategies are fixed points. 16 / 29

slide-66
SLIDE 66

Implementations in OCaML and Haskell

◮ Rule Template:

◮ Generic reducer: higher-order. ◮ (Haskell) Monadic reducer: strict monads for strict semantics. ◮ Particular strategies are fixed points.

◮ Beta Cube:

◮ Boolean triple. ◮ cube2red delivers a reducer from a point in the cube. 16 / 29

slide-67
SLIDE 67

Implementations in OCaML and Haskell

◮ Rule Template:

◮ Generic reducer: higher-order. ◮ (Haskell) Monadic reducer: strict monads for strict semantics. ◮ Particular strategies are fixed points.

◮ Beta Cube:

◮ Boolean triple. ◮ cube2red delivers a reducer from a point in the cube.

◮ Hybridisation:

16 / 29

slide-68
SLIDE 68

Implementations in OCaML and Haskell

◮ Rule Template:

◮ Generic reducer: higher-order. ◮ (Haskell) Monadic reducer: strict monads for strict semantics. ◮ Particular strategies are fixed points.

◮ Beta Cube:

◮ Boolean triple. ◮ cube2red delivers a reducer from a point in the cube.

◮ Hybridisation:

◮ hybridise delivers a hybrid reducer from subsidiary and base from

the cube.

16 / 29

slide-69
SLIDE 69

Contributions

◮ Rule template generalises pure lambda calculus reduction strategies.

(introducing op1 and op2 to accommodate hybrids)

◮ Beta Cube + Hybridise systematise the strategy space. ◮ Studied absorption among vertices in the lattice. ◮ Hybridisation operator:

  • 1. Operands in applications reduced by hybrid: may not deliver strict

normalising strategies.

  • 2. Operands in applications reduced by subsidiary: may deliver strict

normalising strategies.

◮ Absorption among hybrids and their subsidiaries (Absorption

theorem).

◮ Implementation in OCaML and Haskell.

17 / 29

slide-70
SLIDE 70

Future work

◮ Head strategies: using hnf instead of wnf as the notion of value.

◮ Head thunks (reduction stops at the right of a free variable) 18 / 29

slide-71
SLIDE 71

Future work

◮ Head strategies: using hnf instead of wnf as the notion of value.

◮ Head thunks (reduction stops at the right of a free variable)

◮ Strategies and CPS transformation.

18 / 29

slide-72
SLIDE 72

Future work

◮ Head strategies: using hnf instead of wnf as the notion of value.

◮ Head thunks (reduction stops at the right of a free variable)

◮ Strategies and CPS transformation. ◮ Implementing efficient β-testers for typing rules in dependent types

systems.

18 / 29

slide-73
SLIDE 73

Future work

◮ Head strategies: using hnf instead of wnf as the notion of value.

◮ Head thunks (reduction stops at the right of a free variable)

◮ Strategies and CPS transformation. ◮ Implementing efficient β-testers for typing rules in dependent types

systems.

◮ Strategies to interpret universes in structural generic programming

for dependent types.

18 / 29

slide-74
SLIDE 74

Backup slides

Backup slides

19 / 29

slide-75
SLIDE 75

Generic reducer in OCaML

let genred la op1 ar1 su op2 ar2 = function | Var _ as v

  • > v

| Lam (x, b)

  • > Lam (x, la b)

| App (m, n)

  • > let m’ = op1 m in match m’ with

| Lam (x, b) -> su (subst (ar1 n) x b) | _

  • > App (op2 m’ , ar2 n)

20 / 29

slide-76
SLIDE 76

Strategies are fixed point

(********************** la

  • p1 ar1 su
  • p2 ar2 *)

let rec cbn x = (genred id cbn id cbn id id ) x let rec cbv x = (genred id cbv cbv cbv id cbv) x let rec nor x = (genred nor cbn id nor nor nor) x let rec aor x = (genred aor aor aor aor id aor) x ...

21 / 29

slide-77
SLIDE 77

Beta Cube implementation

let sel p red = if p then red else id let cube2red = function (la, ar1, ar2) -> let rec red x = (genred (sel la red) red (sel ar1 red) red red (sel ar2 red)) x in red

22 / 29

slide-78
SLIDE 78

Hybridisation operator

let hybridise s = function (la, ar1, ar2) -> let sub = cube2red s in let rec hyb x = (genred (sel la hyb) sub (sel ar1 sub) hyb hyb (sel ar2 hyb)) x in hyb

23 / 29

slide-79
SLIDE 79

Sestoft’s hibrydisation

let hybridiseSestoft s = function (la, ar1, ar2) -> let sub = cube2red s in let rec hyb x = (genred (sel la hyb) sub (sel ar1 hyb) hyb hyb (sel ar2 hyb)) x in hyb

24 / 29

slide-80
SLIDE 80

Generic reducer in Haskell

data Term = Var String | Lam String Term | App Term Term type Red = Monad m => Term -> m Term genred :: Red -> Red -> Red -> Red -> Red -> Red -> Red genred la op1 ar1 su op2 ar2 t = case t of v@(Var _) -> return v (Lam x b) -> do b’ <- la b return (Lam x b’) (App m n) -> do m’ <- op1 m case m’ of (Lam x b) -> do n’ <- ar1 n su (subst b n’ x) _

  • > do m’’ <- op2 m’

n’’ <- ar2 n return (App m’’ n’’)

25 / 29

slide-81
SLIDE 81

Strategies are fixed points

la

  • p1 ar1

su

  • p2

ar2 cbn = genred return cbn return cbn return return cbv = genred return cbv cbv cbv return cbv aor = genred aor aor aor aor return aor nor = genred nor cbn return nor nor return ...

26 / 29

slide-82
SLIDE 82

Beta Cube implementation

data BCube = BC Bool Bool Bool cube2red :: Monad m => BCube -> Red m cube2red (BC la ar1 ar2) = let red = genred (sel la red) red (sel ar1 red) red red (sel ar2 red) in red where sel par red = if par then red else return

27 / 29

slide-83
SLIDE 83

Hibrydisation operator

hybridise :: (BetaCube, BetaCube) -> Red hybridise (sub, (BC lab ar1b ar2b)) = let s = cube2red sub h = genred (sel lab h) s (sel ar1b s) h h (sel ar2b h) in h

28 / 29

slide-84
SLIDE 84

Sestoft’s hibrydisation operator

hybridiseSestoft :: (BetaCube, BetaCube) -> Red hybridiseSestoft (sub, (BC lab ar1b ar2b)) = let s = cube2red sub h = genred (sel lab h) s (sel ar1b h) h h (sel ar2b h) in h

29 / 29