Equivalence of Algebraic λ-calculi

 Alejandro Díaz-Caro1           Simon Perdrix12
     Christine Tasson3          Benoît Valiron1
          1 LIG,   Université de Grenoble
                       2 CNRS

               3 CEA-LIST,   MeASI


     HOR • July 14th, 2010 • Edinburgh
Algebraic calculi


               Algebraic ≡ Module structure
                                                              1
                                            (λx.yx +            · λx.y(yx)) λz.z
                                                              2
               Two origins
                       λalg −→ differential calculus
                       λlin −→ quantum computation

               Differences in
                       the encoding of the module structure
                       how the reduction rules apply




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   2 / 25
λalg and λlin

       share the same set of terms

                          M, N, L ::= V | (M ) N | M + N | α · M
                           U, V, W          ::= B | α · B | V + W | 0
                                     B ::= x | λx.M

       closed under associativity and conmutativity

                  M +N =N +M                              (M + N ) + L = M + (N + L)


               base term is either a variable or abstraction
               a value is either 0 or of the form                              αi · Bi ;
               a general term can be anything.


A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi       3 / 25
Rules for λalg
Group E



                      α · 0 =a              0                            0 + M =a      M
               α · (β · M ) =a              (α × β) · M                   0 · M =a     0
                     1 · M =a               M                      α · (M + N ) =a     α·M +α·N


           α·M +β·M                 =a      (α + β) · M
Group F
Group A




              (M + N ) L =a (M ) L + (N ) L
               (α · M ) N =a α · (M ) N
                    (0) M =a 0
Group B




          (λx.M ) N →a M [x := N ]

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi              4 / 25
Rules for λlin
Group E



                      α·0 →                 0                            0+M →         M
               α · (β · M ) →               (α × β) · M                   0·M →        0
                     1·M →                  M                      α · (M + N ) →      α·M +α·N


           α·M +β·M                 →       (α + β) · M
Group F




             α·M +M                 →       (α + 1) · M
               M +M                 →       (1 + 1) · M
Group A




             (M + N ) L → (M ) L + (N ) L (M ) (N + L) → (M ) N + (M ) L
              (α · M ) N → α · (M ) N       (M ) α · N → α · (M ) N
                   (0) M → 0                     (M ) 0 → 0
Group B




          (λx.M ) B →a M [x := B]

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi          5 / 25
Context rules

       Some common rules
                                  M →M                                         M →M
                          (M ) N → (M ) N                             M +N →M +N

                                   N →N                                        M →M
                         M +N →M +N                                      α·M →α·M
       plus one additional rule for λlin

                                                        M→ M
                                                (V ) M → (V ) M




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   6 / 25
Modifications to the original calculi



       The most important

               No reduction under lambda (à la Plotkin)

               λx.M is a base term for any M

                               λx.(α · M + β · N ) = α · λx.M + β · λx.N




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   7 / 25
Confluence

       This system is not trivially confluent
       Example
       Let Yb = (λx.(b + (x) x)) (λx.(b + (x) x)), then

                                     0 ← Yb − Yb → Yb + b − Yb → b

       Several possible solutions
               Type system → strong normalisation
               Take scalars as positive reals
               Restrict some of the reduction rules

       For this talk, we simply assume that confluence holds.



A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   8 / 25
Question




                     Can we simulate λlin with λalg and λalg with λlin ?




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   9 / 25
Simulating λalg with λlin
Thunks

       Idea: encapsulating terms M as B = λf.M . So M ≡ (B) f




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   10 / 25
Simulating λalg with λlin
Thunks

       Idea: encapsulating terms M as B = λf.M . So M ≡ (B) f

                                           (|x|)f         =      (x) f
                                           (|0|)f         =      0
                                     (|λx.M |)f           =      λx.(|M |)f
                                   (|(M ) N |)f           =      ((|M |)f ) λz.(|N |)f
                                  (|M + N |)f             =      (|M |)f + (|N |)f
                                     (|α · M |)f          =      α · (|M |)f

       If the encoding λalg → λlin is denoted with (|−|)f , one could
       expect the result

                               M →∗ N
                                  a                      ⇒            (|M |)f →∗ (|N |)f



A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi       10 / 25
Problem



       Example
       (λx.λy.(y) x) I →a λy.(y) I,

          (|(λx.λy.(y) x) I|)f = (λx.λy.((y) f ) (λz.(x) f )) (λz λx.(x) f )
                               →∗ λy.((y) f ) (λz.(λz.λx.(x) f ) f ),
          (|λy.(y) I|)f        = λy.((y) f ) (λz.λx.(x) f )

       “Administrative” redex hidden in the first one




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   11 / 25
Removing administrative redexes

                                   Admin f 0 = 0
                                   Admin f x = x
                    Admin f (λf.M ) f                   = Admin f M
                        Admin f (M ) N                  = (Admin f M ) Admin f N
                           Admin f λx.M                 = λx.Admin f M                 (x = f )
                        Admin f M + N                   = Admin f M + Admin f N
                           Admin f α · M                = α · Admin f M


       Theorem (Simulation)
       For any program (i.e. closed term) M , and value V ,
       if M →∗ V then exists a value W such that
              a

                        (|M |)f →∗ W and Admin f W = Admin f (|V |)f
A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi              12 / 25
First,


                                    M                                      /N

                                       ≡Admin f
                                    M




       Lemma
       If Admin f M = Admin f M and M → N then there exists N
       such that Admin f N = Admin f N and such that M →∗ N .




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   13 / 25
First,


                                    M                                      /N

                                       ≡Admin f                                ≡Admin f
                                    M
                                                                          ∗/   N




       Lemma
       If Admin f M = Admin f M and M → N then there exists N
       such that Admin f N = Admin f N and such that M →∗ N .




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi      13 / 25
Then,


                                      M


                                        ≡Admin f


                                      W

       Lemma
       If W is a value and M a term such that
       Admin f W = Admin f M , then there exists a value V such that
       M →∗ V and Admin f W = Admin f V .




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   14 / 25
Then,


                                      M OOO
                                           OOO
                                              OOO
                                                 OOO
                                                    OOO
                                       ≡Admin f        OOO
                                                          OOO
                                                             OOO
                                                                OO'
                                                                 ∗
                                      W           ≡Admin f          V

       Lemma
       If W is a value and M a term such that
       Admin f W = Admin f M , then there exists a value V such that
       M →∗ V and Admin f W = Admin f V .




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   14 / 25
Finally,



                                     M

                                    a                                     ∗/
                                     N               (|N |)f                    V


       Lemma
       For any program (i.e. closed term) M , if M →a N and
       (|N |)f →∗ V for a value V, then there exists M such that
       (|M |)f →∗ M such that Admin f M = Admin f V .




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   15 / 25
Finally,



                                     M               (|M |)f             / ∗M

                                                                                ≡Admin f
                                    a                                     ∗/
                                     N               (|N |)f                    V


       Lemma
       For any program (i.e. closed term) M , if M →a N and
       (|N |)f →∗ V for a value V, then there exists M such that
       (|M |)f →∗ M such that Admin f M = Admin f V .




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi       15 / 25
Now, we want



                                                                               ∗/
                                            M                                  aV



                                         (|M |)f                               (|V |)f




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi     16 / 25
Now, we want



                                                                               ∗/
                                            M                                  aV



                                         (|M |)f                               (|V |)f
                                                   FF
                                                     FF
                                                       FF                ≡Admin f
                                                         FF ∗
                                                           
                                                               W




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi     16 / 25
Base case




                                          V                    =                       V


                                       (|V |)f                                   (|V |)f

                                              =                                 =
                                                            (|V |)f




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi       17 / 25
Inductive case
                                                                /                             ∗/
                        M                                      aM                             aV



                     (|M |)f                                   (|M |)f                        (|V |)f
                                                                       EE
                                                                         EE
                                                                           EE            ≡Admin f
                                                                             EE ∗
                                                                               
                                                                                   W



                                                                                        Lemma 2
                            Lemma 3                                    M
                                                                           EE
                                          /   ∗                              EE
        M              (|M | f
                           )                      M                              EE
                                                                                   EE
                                                                                     EE
                                                  ≡Admin                 ≡Admin        EE
                                                           f                    f
                                                                                         EE
                                                                                          EE
                                              /
       a
         M              ( |f
                         |M )
                                              ∗
                                                  W                                          EE ∗
                                                                                               
                                                                         W                        W

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi                    18 / 25
Inductive case
                                                                /                                   ∗/
                        M                                      aM                                   aV



                     (|M |)f                                   (|M |)f                              (|V |)f
                                GG                                     EE
                                  GG                                     EE
                                    GG                                     EE
                                      GG                                     EE ∗               ≡Admin f
                                        G# ∗                                   
                                              M                ≡Admin f            W



                                                                                            Lemma 2
                            Lemma 3                                    M
                                                                           EE
                                          /   ∗                              EE
        M              (|M | f
                           )                      M                              EE
                                                                                   EE
                                                                                     EE
                                                  ≡Admin                 ≡Admin        EE
                                                           f                    f
                                                                                         EE
                                                                                          EE
                                              /
       a
         M              ( |f
                         |M )
                                              ∗
                                                  W                                          EE ∗
                                                                                               
                                                                         W             ≡Admin
                                                                                                f     W

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi                          18 / 25
Inductive case
                                                                /                             ∗/
                        M                                      aM                             aV



                     (|M |)f                                   (|M |)f                        (|V |)f
                                GG                                     EE
                                  GG                                     EE
                                    GG                                     EE
                                      GG                                     EE ∗        ≡Admin f
                                        G# ∗                                   
                                              M H      ≡Admin f    W
                                                 HH
                                                   HH
                                                     HH        ≡Admin f
                                                       HH ∗
                                                         #
                                                           W
                                                                                        Lemma 2
                            Lemma 3                                    M
                                                                           EE
                                          /   ∗                              EE
        M              (|M | f
                           )                      M                              EE
                                                                                   EE
                                                                                     EE
                                                  ≡Admin                 ≡Admin        EE
                                                           f                    f
                                                                                         EE
                                                                                          EE
                                              /
       a
         M              ( |f
                         |M )
                                              ∗
                                                  W                                          EE ∗
                                                                                               
                                                                         W                        W

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi                    18 / 25
Simulating λlin with λalg
CPS encoding



       We define [|−|] : λlin → λalg

                                 [|x|]     =      λf. (f ) x
                                 [|0|]     =      0
                          [|λx.M |]        =      λf.(f ) λx.[|M |]
                        [|(M ) N |]        =      λf.([|M |]) λg.([|N |]) λh.((g) h) f
                           [|α · M |]      =      λf.(α · [|M |]) f
                       [|M + N |]          =      λf.([|M |] + [|N |]) f

       Now, given the continuation I = λx.x, if M → V we want
       ([|M |]) I →a W for some W related to [|V |]




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi     19 / 25
The encoding for values


                                        Ψ(x)               =      x,
                                         Ψ(0)              =      0,
                                     Ψ(λx.M )              =      λx.[|M |],
                                     Ψ(α · V )             =      α · Ψ(V ),
                                    Ψ(V + W )              =      Ψ(V ) + Ψ(W ).

               Ψ(V ) is such that [|V |] →∗ Ψ(V ).
                                          a


       Theorem (Simulation)
                          M →∗ V                   ⇒            ([|M |]) λx.x →∗ Ψ(V ).
                                                                               a




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi      20 / 25
An auxiliary definition


       Note that

                          ([|B|]) K = (λf.(f ) Ψ(B)) K →∗ (K) Ψ(B).
                                                        a


               We define the term B : K = (K) Ψ(B).
               We extend this definition to other terms in some
               not-so-easy way due to the algebraic properties of the
               language.
               It is the main difficulty in this proof.




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   21 / 25
The auxiliary definition

       Let (:) : λlin × λalg → λalg :

                           B : K = (K) Ψ(B)
                           (M + N ) : K = M : K + N : K
                           α · M : K = α · (M : K)
                           0:K=0
                           (U ) B : K = ((Ψ(U )) Ψ(B)) K
                           (U ) (V + W ) : K = ((U ) V + (U ) W ) : K
                           (U ) (α · B) : K = α · (U ) B : K
                           (U ) 0 : K = 0
                           (U ) N : K = N : λf.((Ψ(U )) f ) K
                           (M ) N : K = M : λg.([|N |]) λh.((g) h) K




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   22 / 25
Proof




       If M →∗ V ,

                                    ([|M |]) (λx.x)


                                                                       Ψ(V )




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   23 / 25
Proof

       If K is a value:
               For all M , ([|M |]) K →∗ M : K
                                       a
               If M → N then M : K →∗ N : K
                                    a
               If V is a value, V : K →∗ (K) Ψ(V )
                                       a

       If M →∗ V ,

                                    ([|M |]) (λx.x)             →∗ M : λx.x
                                                                 a



                                                                       Ψ(V )




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   23 / 25
Proof

       If K is a value:
               For all M , ([|M |]) K →∗ M : K
                                       a
               If M → N then M : K →∗ N : K
                                    a
               If V is a value, V : K →∗ (K) Ψ(V )
                                       a

       If M →∗ V ,

                                    ([|M |]) (λx.x)             →∗ M : λx.x
                                                                 a
                                                                →∗ V : λx.x
                                                                 a


                                                                       Ψ(V )




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   23 / 25
Proof

       If K is a value:
               For all M , ([|M |]) K →∗ M : K
                                       a
               If M → N then M : K →∗ N : K
                                    a
               If V is a value, V : K →∗ (K) Ψ(V )
                                       a

       If M →∗ V ,

                                    ([|M |]) (λx.x)             →∗ M : λx.x
                                                                 a
                                                                →∗ V : λx.x
                                                                 a
                                                                →∗ (λx.x) Ψ(V )
                                                                 a
                                                                   Ψ(V )




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   23 / 25
Proof

       If K is a value:
               For all M , ([|M |]) K →∗ M : K
                                       a
               If M → N then M : K →∗ N : K
                                    a
               If V is a value, V : K →∗ (K) Ψ(V )
                                       a

       If M →∗ V ,

                                    ([|M |]) (λx.x)             →∗
                                                                 a     M : λx.x
                                                                →∗
                                                                 a     V : λx.x
                                                                →∗
                                                                 a     (λx.x) Ψ(V )
                                                                →a     Ψ(V )




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   23 / 25
Future and ongoing work




       In classical lambda-calculus:
               CPS can also be done to interpret call-by-name in
               call-by-value [Plotkin 75].
               The thunk construction can be related to CPS [Hatcliff and
               Danvy 96].
       Can we relate to these?




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   24 / 25
Future and ongoing work




       Other interesting questions
               The choice between equality and reduction rules seems
               arbitrary.
       Can we exchange them?
       Are the simulations still valid?




A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi   25 / 25

Equivalence of algebraic λ-calculi

  • 1.
    Equivalence of Algebraicλ-calculi Alejandro Díaz-Caro1 Simon Perdrix12 Christine Tasson3 Benoît Valiron1 1 LIG, Université de Grenoble 2 CNRS 3 CEA-LIST, MeASI HOR • July 14th, 2010 • Edinburgh
  • 2.
    Algebraic calculi Algebraic ≡ Module structure 1 (λx.yx + · λx.y(yx)) λz.z 2 Two origins λalg −→ differential calculus λlin −→ quantum computation Differences in the encoding of the module structure how the reduction rules apply A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 2 / 25
  • 3.
    λalg and λlin share the same set of terms M, N, L ::= V | (M ) N | M + N | α · M U, V, W ::= B | α · B | V + W | 0 B ::= x | λx.M closed under associativity and conmutativity M +N =N +M (M + N ) + L = M + (N + L) base term is either a variable or abstraction a value is either 0 or of the form αi · Bi ; a general term can be anything. A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 3 / 25
  • 4.
    Rules for λalg GroupE α · 0 =a 0 0 + M =a M α · (β · M ) =a (α × β) · M 0 · M =a 0 1 · M =a M α · (M + N ) =a α·M +α·N α·M +β·M =a (α + β) · M Group F Group A (M + N ) L =a (M ) L + (N ) L (α · M ) N =a α · (M ) N (0) M =a 0 Group B (λx.M ) N →a M [x := N ] A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 4 / 25
  • 5.
    Rules for λlin GroupE α·0 → 0 0+M → M α · (β · M ) → (α × β) · M 0·M → 0 1·M → M α · (M + N ) → α·M +α·N α·M +β·M → (α + β) · M Group F α·M +M → (α + 1) · M M +M → (1 + 1) · M Group A (M + N ) L → (M ) L + (N ) L (M ) (N + L) → (M ) N + (M ) L (α · M ) N → α · (M ) N (M ) α · N → α · (M ) N (0) M → 0 (M ) 0 → 0 Group B (λx.M ) B →a M [x := B] A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 5 / 25
  • 6.
    Context rules Some common rules M →M M →M (M ) N → (M ) N M +N →M +N N →N M →M M +N →M +N α·M →α·M plus one additional rule for λlin M→ M (V ) M → (V ) M A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 6 / 25
  • 7.
    Modifications to theoriginal calculi The most important No reduction under lambda (à la Plotkin) λx.M is a base term for any M λx.(α · M + β · N ) = α · λx.M + β · λx.N A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 7 / 25
  • 8.
    Confluence This system is not trivially confluent Example Let Yb = (λx.(b + (x) x)) (λx.(b + (x) x)), then 0 ← Yb − Yb → Yb + b − Yb → b Several possible solutions Type system → strong normalisation Take scalars as positive reals Restrict some of the reduction rules For this talk, we simply assume that confluence holds. A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 8 / 25
  • 9.
    Question Can we simulate λlin with λalg and λalg with λlin ? A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 9 / 25
  • 10.
    Simulating λalg withλlin Thunks Idea: encapsulating terms M as B = λf.M . So M ≡ (B) f A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 10 / 25
  • 11.
    Simulating λalg withλlin Thunks Idea: encapsulating terms M as B = λf.M . So M ≡ (B) f (|x|)f = (x) f (|0|)f = 0 (|λx.M |)f = λx.(|M |)f (|(M ) N |)f = ((|M |)f ) λz.(|N |)f (|M + N |)f = (|M |)f + (|N |)f (|α · M |)f = α · (|M |)f If the encoding λalg → λlin is denoted with (|−|)f , one could expect the result M →∗ N a ⇒ (|M |)f →∗ (|N |)f A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 10 / 25
  • 12.
    Problem Example (λx.λy.(y) x) I →a λy.(y) I, (|(λx.λy.(y) x) I|)f = (λx.λy.((y) f ) (λz.(x) f )) (λz λx.(x) f ) →∗ λy.((y) f ) (λz.(λz.λx.(x) f ) f ), (|λy.(y) I|)f = λy.((y) f ) (λz.λx.(x) f ) “Administrative” redex hidden in the first one A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 11 / 25
  • 13.
    Removing administrative redexes Admin f 0 = 0 Admin f x = x Admin f (λf.M ) f = Admin f M Admin f (M ) N = (Admin f M ) Admin f N Admin f λx.M = λx.Admin f M (x = f ) Admin f M + N = Admin f M + Admin f N Admin f α · M = α · Admin f M Theorem (Simulation) For any program (i.e. closed term) M , and value V , if M →∗ V then exists a value W such that a (|M |)f →∗ W and Admin f W = Admin f (|V |)f A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 12 / 25
  • 14.
    First, M /N ≡Admin f M Lemma If Admin f M = Admin f M and M → N then there exists N such that Admin f N = Admin f N and such that M →∗ N . A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 13 / 25
  • 15.
    First, M /N ≡Admin f ≡Admin f M ∗/ N Lemma If Admin f M = Admin f M and M → N then there exists N such that Admin f N = Admin f N and such that M →∗ N . A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 13 / 25
  • 16.
    Then, M ≡Admin f W Lemma If W is a value and M a term such that Admin f W = Admin f M , then there exists a value V such that M →∗ V and Admin f W = Admin f V . A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 14 / 25
  • 17.
    Then, M OOO OOO OOO OOO OOO ≡Admin f OOO OOO OOO OO' ∗ W ≡Admin f V Lemma If W is a value and M a term such that Admin f W = Admin f M , then there exists a value V such that M →∗ V and Admin f W = Admin f V . A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 14 / 25
  • 18.
    Finally, M a ∗/ N (|N |)f V Lemma For any program (i.e. closed term) M , if M →a N and (|N |)f →∗ V for a value V, then there exists M such that (|M |)f →∗ M such that Admin f M = Admin f V . A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 15 / 25
  • 19.
    Finally, M (|M |)f / ∗M ≡Admin f a ∗/ N (|N |)f V Lemma For any program (i.e. closed term) M , if M →a N and (|N |)f →∗ V for a value V, then there exists M such that (|M |)f →∗ M such that Admin f M = Admin f V . A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 15 / 25
  • 20.
    Now, we want ∗/ M aV (|M |)f (|V |)f A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 16 / 25
  • 21.
    Now, we want ∗/ M aV (|M |)f (|V |)f FF FF FF ≡Admin f FF ∗ W A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 16 / 25
  • 22.
    Base case V = V (|V |)f (|V |)f = = (|V |)f A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 17 / 25
  • 23.
    Inductive case / ∗/ M aM aV (|M |)f (|M |)f (|V |)f EE EE EE ≡Admin f EE ∗ W Lemma 2 Lemma 3 M EE / ∗ EE M (|M | f ) M EE EE EE ≡Admin ≡Admin EE f f EE EE / a M ( |f |M ) ∗ W EE ∗ W W A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 18 / 25
  • 24.
    Inductive case / ∗/ M aM aV (|M |)f (|M |)f (|V |)f GG EE GG EE GG EE GG EE ∗ ≡Admin f G# ∗ M ≡Admin f W Lemma 2 Lemma 3 M EE / ∗ EE M (|M | f ) M EE EE EE ≡Admin ≡Admin EE f f EE EE / a M ( |f |M ) ∗ W EE ∗ W ≡Admin f W A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 18 / 25
  • 25.
    Inductive case / ∗/ M aM aV (|M |)f (|M |)f (|V |)f GG EE GG EE GG EE GG EE ∗ ≡Admin f G# ∗ M H ≡Admin f W HH HH HH ≡Admin f HH ∗ # W Lemma 2 Lemma 3 M EE / ∗ EE M (|M | f ) M EE EE EE ≡Admin ≡Admin EE f f EE EE / a M ( |f |M ) ∗ W EE ∗ W W A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 18 / 25
  • 26.
    Simulating λlin withλalg CPS encoding We define [|−|] : λlin → λalg [|x|] = λf. (f ) x [|0|] = 0 [|λx.M |] = λf.(f ) λx.[|M |] [|(M ) N |] = λf.([|M |]) λg.([|N |]) λh.((g) h) f [|α · M |] = λf.(α · [|M |]) f [|M + N |] = λf.([|M |] + [|N |]) f Now, given the continuation I = λx.x, if M → V we want ([|M |]) I →a W for some W related to [|V |] A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 19 / 25
  • 27.
    The encoding forvalues Ψ(x) = x, Ψ(0) = 0, Ψ(λx.M ) = λx.[|M |], Ψ(α · V ) = α · Ψ(V ), Ψ(V + W ) = Ψ(V ) + Ψ(W ). Ψ(V ) is such that [|V |] →∗ Ψ(V ). a Theorem (Simulation) M →∗ V ⇒ ([|M |]) λx.x →∗ Ψ(V ). a A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 20 / 25
  • 28.
    An auxiliary definition Note that ([|B|]) K = (λf.(f ) Ψ(B)) K →∗ (K) Ψ(B). a We define the term B : K = (K) Ψ(B). We extend this definition to other terms in some not-so-easy way due to the algebraic properties of the language. It is the main difficulty in this proof. A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 21 / 25
  • 29.
    The auxiliary definition Let (:) : λlin × λalg → λalg : B : K = (K) Ψ(B) (M + N ) : K = M : K + N : K α · M : K = α · (M : K) 0:K=0 (U ) B : K = ((Ψ(U )) Ψ(B)) K (U ) (V + W ) : K = ((U ) V + (U ) W ) : K (U ) (α · B) : K = α · (U ) B : K (U ) 0 : K = 0 (U ) N : K = N : λf.((Ψ(U )) f ) K (M ) N : K = M : λg.([|N |]) λh.((g) h) K A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 22 / 25
  • 30.
    Proof If M →∗ V , ([|M |]) (λx.x) Ψ(V ) A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 23 / 25
  • 31.
    Proof If K is a value: For all M , ([|M |]) K →∗ M : K a If M → N then M : K →∗ N : K a If V is a value, V : K →∗ (K) Ψ(V ) a If M →∗ V , ([|M |]) (λx.x) →∗ M : λx.x a Ψ(V ) A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 23 / 25
  • 32.
    Proof If K is a value: For all M , ([|M |]) K →∗ M : K a If M → N then M : K →∗ N : K a If V is a value, V : K →∗ (K) Ψ(V ) a If M →∗ V , ([|M |]) (λx.x) →∗ M : λx.x a →∗ V : λx.x a Ψ(V ) A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 23 / 25
  • 33.
    Proof If K is a value: For all M , ([|M |]) K →∗ M : K a If M → N then M : K →∗ N : K a If V is a value, V : K →∗ (K) Ψ(V ) a If M →∗ V , ([|M |]) (λx.x) →∗ M : λx.x a →∗ V : λx.x a →∗ (λx.x) Ψ(V ) a Ψ(V ) A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 23 / 25
  • 34.
    Proof If K is a value: For all M , ([|M |]) K →∗ M : K a If M → N then M : K →∗ N : K a If V is a value, V : K →∗ (K) Ψ(V ) a If M →∗ V , ([|M |]) (λx.x) →∗ a M : λx.x →∗ a V : λx.x →∗ a (λx.x) Ψ(V ) →a Ψ(V ) A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 23 / 25
  • 35.
    Future and ongoingwork In classical lambda-calculus: CPS can also be done to interpret call-by-name in call-by-value [Plotkin 75]. The thunk construction can be related to CPS [Hatcliff and Danvy 96]. Can we relate to these? A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 24 / 25
  • 36.
    Future and ongoingwork Other interesting questions The choice between equality and reduction rules seems arbitrary. Can we exchange them? Are the simulations still valid? A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 25 / 25