Linearity in the non-deterministic
               call-by-value setting


     Alejandro Díaz-Caro                                Barbara Petit
LIPN, Université Paris 13, Sorbonne Paris Cité   Focus (INRIA) – Università di Bologna




                                        19th WoLLIC
                           Buenos Aires, September 3–6, 2012
Non-determinism (or parallelism)
        t + u: non-deterministic superposition between t and u
               (it may run t or u, non-deterministically)




             Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting   1 / 20
Non-determinism (or parallelism)
        t + u: non-deterministic superposition between t and u
               (it may run t or u, non-deterministically)
                      (t + u)s may run ts or us.




             Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting   1 / 20
Non-determinism (or parallelism)
        t + u: non-deterministic superposition between t and u
               (it may run t or u, non-deterministically)
                      (t + u)s may run ts or us.
                      Hence (t + u)s → ts + us




             Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting   1 / 20
Non-determinism (or parallelism)
            t + u: non-deterministic superposition between t and u
                    (it may run t or u, non-deterministically)
                           (t + u)s may run ts or us.
                           Hence (t + u)s → ts + us
                  Sum of functions: (f + g)(x) = f(x) + g(x)
    (this is the interpretation of the algebraic calculi [Vaux, Arrighi-Dowek])




                 Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting   1 / 20
Non-determinism (or parallelism)
            t + u: non-deterministic superposition between t and u
                    (it may run t or u, non-deterministically)
                           (t + u)s may run ts or us.
                           Hence (t + u)s → ts + us
                  Sum of functions: (f + g)(x) = f(x) + g(x)
    (this is the interpretation of the algebraic calculi [Vaux, Arrighi-Dowek])
                                               t(u + s)

             (λx.t)(u + s) → t[(u + s)/x]                                                (CBN)
             (λx.t)(u + s) → (λx.t)u + (λx.t)s                                           (CBV)

                   Generically in CBV t(u + s) → tu + ts




                 Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting   1 / 20
Non-determinism (or parallelism)
            t + u: non-deterministic superposition between t and u
                    (it may run t or u, non-deterministically)
                           (t + u)s may run ts or us.
                           Hence (t + u)s → ts + us
                  Sum of functions: (f + g)(x) = f(x) + g(x)
    (this is the interpretation of the algebraic calculi [Vaux, Arrighi-Dowek])
                                               t(u + s)

             (λx.t)(u + s) → t[(u + s)/x]                                                (CBN)
             (λx.t)(u + s) → (λx.t)u + (λx.t)s                                           (CBV)

                  Generically in CBV t(u + s) → tu + ts
         In algebraic terms, functions are treated as linear in CBV:
                           f(x + y ) = f(x) + f(y )



                 Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting   1 / 20
Non-determinism (or parallelism)
            t + u: non-deterministic superposition between t and u
                    (it may run t or u, non-deterministically)
                           (t + u)s may run ts or us.
                           Hence (t + u)s → ts + us
                  Sum of functions: (f + g)(x) = f(x) + g(x)
    (this is the interpretation of the algebraic calculi [Vaux, Arrighi-Dowek])
                                               t(u + s)

             (λx.t)(u + s) → t[(u + s)/x]                                                (CBN)
             (λx.t)(u + s) → (λx.t)u + (λx.t)s                                           (CBV)

                  Generically in CBV t(u + s) → tu + ts
         In algebraic terms, functions are treated as linear in CBV:
                           f(x + y ) = f(x) + f(y )

                  We want to understand this ‘linearity’

                 Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting   1 / 20
Outline




     The untyped calculus



     The Additive type system capturing the CBV behaviour of +



     Logical interpretation: translation into System F with pairs




               Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting   2 / 20
The untyped CBV non-deterministic λ-calculus

                              t, u, s ::= v | tu | t + u | 0
                                      v ::= x | λx.t
  Intuitions
  t + u = non-deterministic superposition between t and u
  0 = impossible computation




                Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting   3 / 20
The untyped CBV non-deterministic λ-calculus

                              t, u, s ::= v | tu | t + u | 0
                                      v ::= x | λx.t
  Intuitions
  t + u = non-deterministic superposition between t and u
  0 = impossible computation

                Hence, t + 0 → t because 0 is impossible!




                Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting   3 / 20
The untyped CBV non-deterministic λ-calculus

                              t, u, s ::= v | tu | t + u | 0
                                      v ::= x | λx.t
  Intuitions
  t + u = non-deterministic superposition between t and u
  0 = impossible computation

                Hence, t + 0 → t because 0 is impossible!
  Also     0t → 0      t0 → 0
  Because non of them reduces (0 not a value) and there is an impossible
  computation




                Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting   3 / 20
The untyped CBV non-deterministic λ-calculus

                               t, u, s ::= v | tu | t + u | 0
                                       v ::= x | λx.t
  Intuitions
  t + u = non-deterministic superposition between t and u
  0 = impossible computation

                Hence, t + 0 → t because 0 is impossible!
  Also     0t → 0      t0 → 0
  Because non of them reduces (0 not a value) and there is an impossible
  computation

                               Running t or u non-deterministically, is the
  Finally t + u = u + t
                               same as running u or t non-deterministically
  Also t + (u + s) = (t + u) + s



                 Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting   3 / 20
The untyped CBV non-deterministic λ-calculus

                                t, u, s ::= v | tu | t + u | 0
                                        v ::= x | λx.t

                                           βv -reduction
                                         (λx.t)v → t[v/x]


  Distributivity rules                                            Zero rules
          (t + u)s → ts + us                                                t+0→t
          t(u + s) → tu + ts                                                     0t → 0
                                                                                 t0 → 0

  with + associative and commutative

  Remark: in the algebraic case, 0 is the sum of zero terms


                  Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting   3 / 20
The Additive type system
  Objective: capture as much as possible the behaviour of +




                Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting   4 / 20
The Additive type system
  Objective: capture as much as possible the behaviour of +

   Γ       t:T   Γ     s:S
       Γ    t+s :T +S                            Γ     0:¯
                                                         0




                 Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting   4 / 20
The Additive type system
  Objective: capture as much as possible the behaviour of +

   Γ       t:T   Γ     s:S                                                       Γ       t:T                T ≡S
       Γ    t+s :T +S                            Γ     0:¯
                                                         0                                    Γ      t:S



  T +R ≡ R +T            ;          T +(R +S) ≡ (T +R)+S                                  ;           T +¯ ≡ T
                                                                                                         0




                 Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting    4 / 20
The Additive type system
  Objective: capture as much as possible the behaviour of +

   Γ       t:T   Γ     s:S                                                       Γ       t:T                T ≡S
       Γ    t+s :T +S                            Γ     0:¯
                                                         0                                    Γ      t:S



  T +R ≡ R +T            ;          T +(R +S) ≡ (T +R)+S                                  ;           T +¯ ≡ T
                                                                                                         0


  T → R: functions from T to R




                 Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting    4 / 20
The Additive type system
  Objective: capture as much as possible the behaviour of +

   Γ       t:T    Γ     s:S                                                       Γ       t:T                T ≡S
       Γ    t+s :T +S                             Γ     0:¯
                                                          0                                    Γ      t:S



  T +R ≡ R +T             ;          T +(R +S) ≡ (T +R)+S                                  ;           T +¯ ≡ T
                                                                                                          0


  T → R: functions from T to R
                      But (T + R) → S does not exists
  there is no function taking a non-deterministic superposition as argument
  Recall t(v1 + v2 ) → tv1 + tv2
  If v1 : T and v2 : R then t needs to be both T → S1 and R → S2



                  Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting    4 / 20
The Additive type system
  Objective: capture as much as possible the behaviour of +

   Γ       t:T    Γ     s:S                                                       Γ       t:T                T ≡S
       Γ    t+s :T +S                             Γ     0:¯
                                                          0                                    Γ      t:S



  T +R ≡ R +T             ;          T +(R +S) ≡ (T +R)+S                                  ;           T +¯ ≡ T
                                                                                                          0


  T → R: functions from T to R
                      But (T + R) → S does not exists
  there is no function taking a non-deterministic superposition as argument
  Recall t(v1 + v2 ) → tv1 + tv2
  If v1 : T and v2 : R then t needs to be both T → S1 and R → S2
             Polymorphism & unit types “U” (atomic types w.r.t. +)
                             Arrows: U → T
                  Alejandro Díaz-Caro & Barbara Petit   Linearity in the non-deterministic call-by-value setting    4 / 20
The Additive type system                                   (cont.)
Examples



                                           Concrete example

                  v1 : U1           ;         v2 : U2           ;           I : ∀X .X → X

            Hence        I (v1 + v2 ) → I v1 + I v2                      has type                 U1 + U2




                                        A more generic example

           v1 : U[W1 /X ]           ;         v2 : U[W2 /X ]                  ;          t : ∀X .U → T

    Hence       t(v1 + v2 ) → tv1 + tv2                     has type                T [W1 /X ] + T [W2 /X ]



                     Alejandro Díaz-Caro & Barbara Petit    Linearity in the non-deterministic call-by-value setting   5 / 20
The Additive type system                                   (cont.)
Examples



                                           Concrete example

                  v1 : U1           ;         v2 : U2           ;           I : ∀X .X → X

            Hence        I (v1 + v2 ) → I v1 + I v2                      has type                 U1 + U2




                                        A more generic example

           v1 : U[W1 /X ]           ;         v2 : U[W2 /X ]                  ;          t : ∀X .U → T

    Hence       t(v1 + v2 ) → tv1 + tv2                     has type                T [W1 /X ] + T [W2 /X ]



                     Alejandro Díaz-Caro & Barbara Petit    Linearity in the non-deterministic call-by-value setting   5 / 20
The Additive type system                                    (cont.)
Examples




                Γ   t : ∀X .U → T                 Γ        v1 + v2 : U[W1 /X ] + U[W2 /X ]
                             Γ     t(v1 + v2 ) : T [W1 /X ] + T [W2 /X ]




                                        A more generic example

           v1 : U[W1 /X ]           ;         v2 : U[W2 /X ]                    ;          t : ∀X .U → T

    Hence       t(v1 + v2 ) → tv1 + tv2                       has type                T [W1 /X ] + T [W2 /X ]



                     Alejandro Díaz-Caro & Barbara Petit      Linearity in the non-deterministic call-by-value setting   5 / 20
The Additive type system                                     (cont.)
Examples



                             t:U→T                       ;          u:V →R

                                        (t + u)v → tv + uv
             Hence U and V needs to “polymorph” to the type of v


       v : U[W1 /X ] = V [W2 /X ]                  t : ∀X .(U → T )                         u : ∀X .(V → R)

              Hence        tv + uv has type                       T [W1 /X ] + R[W2 /X ]




                   Alejandro Díaz-Caro & Barbara Petit        Linearity in the non-deterministic call-by-value setting   6 / 20
The Additive type system                                     (cont.)
Examples



                             t:U→T                       ;          u:V →R

                                        (t + u)v → tv + uv
             Hence U and V needs to “polymorph” to the type of v


       v : U[W1 /X ] = V [W2 /X ]                  t : ∀X .(U → T )                         u : ∀X .(V → R)

              Hence        tv + uv has type                       T [W1 /X ] + R[W2 /X ]




                   Alejandro Díaz-Caro & Barbara Petit        Linearity in the non-deterministic call-by-value setting   6 / 20
The Additive type system                                     (cont.)
Examples



                             t:U→T                       ;          u:V →R

                                        (t + u)v → tv + uv
             Hence U and V needs to “polymorph” to the type of v


       v : U[W1 /X ] = V [W2 /X ]                  t : ∀X .(U → T )                         u : ∀X .(V → R)

              Hence        tv + uv has type                       T [W1 /X ] + R[W2 /X ]



       Γ   t + u : ∀X .(U → T ) + ∀X .(V → R)                          Γ       v : U[W1 /X ] = V [W2 /X ]
                            Γ     (t + u)v : T [W1 /X ] + R[W2 /X ]




                   Alejandro Díaz-Caro & Barbara Petit        Linearity in the non-deterministic call-by-value setting   6 / 20
The Additive type system                                         (cont.)
Arrow elimination
                    Γ   t : ∀X .U → T                Γ         v1 + v2 : U[W1 /X ] + U[W2 /X ]
                                Γ      t(v1 + v2 ) : T [W1 /X ] + T [W2 /X ]

         Γ   t + u : ∀X .(U → T ) + ∀X .(V → R)                             Γ       v : U[W1 /X ] = V [W2 /X ]
                                  Γ     (t + u)v : T [W1 /X ] + R[W2 /X ]

     combined...
     Γ   t + u : ∀X .(U → T ) + ∀X .(U → R)                            Γ      v1 + v2 : U[W1 /X ] + U[W2 /X ]
             Γ   (t + u)(v1 + v2 ) : T [W1 /X ] + T [W2 /X ] + R[W1 /X ] + R[W2 /X ]




                         Alejandro Díaz-Caro & Barbara Petit       Linearity in the non-deterministic call-by-value setting   7 / 20
The Additive type system                                         (cont.)
Arrow elimination
                    Γ   t : ∀X .U → T                Γ         v1 + v2 : U[W1 /X ] + U[W2 /X ]
                                Γ          t(v1 + v2 ) : T [W1 /X ] + T [W2 /X ]

         Γ   t + u : ∀X .(U → T ) + ∀X .(V → R)                               Γ       v : U[W1 /X ] = V [W2 /X ]
                                   Γ        (t + u)v : T [W1 /X ] + R[W2 /X ]

     combined...
     Γ   t + u : ∀X .(U → T ) + ∀X .(U → R)                              Γ      v1 + v2 : U[W1 /X ] + U[W2 /X ]
             Γ   (t + u)(v1 + v2 ) : T [W1 /X ] + T [W2 /X ] + R[W1 /X ] + R[W2 /X ]

     generalising...
                                       n                                               m
                        Γ     t:            ∀X .(U → Ti )               Γ      u:           U[Wj /X ]
                                    i=1                                               j=1
                                                          n      m
                                             Γ   tu :                 Ti [Wj /X ]
                                                         i=1 j=1


                         Alejandro Díaz-Caro & Barbara Petit         Linearity in the non-deterministic call-by-value setting   7 / 20
The Additive type system                                           (cont.)
Examples


                          V1 = U[W1 /X ]                       ;          V2 = U[W2 /X ]

        Γ    λx.t + λy .u : ∀X .(U → T ) + ∀X .(U → R)                                      Γ       v1 + v2 : V1 + V2
    Γ       (λx.t + λy .u)(v1 + v2 ) : T [W1 /X ] + T [W2 /X ] + R[W1 /X ] + R[W2 /X ]


                          
     (λx.t)v1 + (λx.t)v2 + (λy .u)v1 + (λy .u)v2
        T [W1 /X ]   T [W2 /X ]        R[W1 /X ]              R[W2 /X ]




                        Alejandro Díaz-Caro  Barbara Petit         Linearity in the non-deterministic call-by-value setting   8 / 20
The Additive type system                                           (cont.)
Examples


                           V1 = U[W1 /X ]                      ;          V2 = U[W2 /X ]

        Γ    λx.t + λy .u : ∀X .(U → T ) + ∀X .(U → R)                                      Γ       v1 + v2 : V1 + V2
    Γ       (λx.t + λy .u)(v1 + v2 ) : T [W1 /X ] + T [W2 /X ] + R[W1 /X ] + R[W2 /X ]


                          
     (λx.t)v1 + (λx.t)v2 + (λy .u)v1 + (λy .u)v2
        T [W1 /X ]   T [W2 /X ]        R[W1 /X ]              R[W2 /X ]




    Simpler example
                       Γ      λx.x : ∀X .X → X                           Γ       v1 + v2 : U + V
                           Γ (λx.x)(v1 + v2 ) : U + V
    without simultaneous arrow/forall elimination it is not possible to type it!
                        Alejandro Díaz-Caro  Barbara Petit         Linearity in the non-deterministic call-by-value setting   8 / 20
The Additive type system                                                     (cont.)
Summarising



                       T , R, S := U | T + R | ¯
                                               0                                                       general types
                      U, V , W := X | U → T | ∀X .U                                                    unit types
    T +¯ ≡ T
       0                        ;          T +R ≡ R +T                                ;            T +(R +S) ≡ (T +R)+S

                                               ax                                         Γ        t:T            Γ       u:R
                                                                            ax¯
                                                                              0                                                 +I
                     Γ, x : U       x :U                     Γ    0:¯
                                                                    0                          Γ    t+u:T +R
                      n                                               m
        Γ       t:         ∀X .(U → Ti )                 Γ       u:         U[Wj /X ]
                     i=1                                              j=1                                        Γ, x : U     t:T
                                                                                              →E                                         →I
                                           n        m
                                                                                                             Γ        λx.t : U → T
                            Γ       tu :                Ti [Wj /X ]
                                           i=1 j=1
            Γ    t : ∀X .U                      Γ       t:U            X ∈ FV (Γ)
                                                                         /                               Γ        t:T           T ≡R
                                    ∀E                                                        ∀I                                             ≡
         Γ      t : U[V /X ]                                 Γ    t : ∀X .U                                           Γ   t:R

    • Strong normalisation
    • Subject reduction

                                Alejandro Díaz-Caro  Barbara Petit               Linearity in the non-deterministic call-by-value setting       9 / 20
Outline



     The untyped calculus



     The Additive type system capturing the CBV behaviour of +



     Logical interpretation: translation into System F with pairs




               Alejandro Díaz-Caro  Barbara Petit   Linearity in the non-deterministic call-by-value setting   10 / 20
System F with pairs


             t, u ::= x | λx.t | tu |               | t, u | π1 (t) | π2 (t)
            A, B ::= X | A ⇒ B | ∀X .A | 1 | A × B



     (λx.t)u → t[u/x]                      π1 ( t1 , t2 ) → t1                 π2 ( t1 , t2 ) → t2




                   Additive                    System F with pairs
                      X                                   X
                   U→T                              |U| ⇒ |T |
                    ∀X .U                             ∀X .|U|
                      ¯
                      0                                   1
                    T +S                             |T | × |S|

              Alejandro Díaz-Caro  Barbara Petit   Linearity in the non-deterministic call-by-value setting   11 / 20
Sums as Pairs
                  +, ¯
                     0                                                 ×, 1


           T +S ≡ S +T                                   A×B = B ×A
     T + (S + R) ≡ (T + S) + R                     A × (B × C ) = (A × B) × C
           T +¯ ≡ T
               0                                         A×1 = A




             Alejandro Díaz-Caro  Barbara Petit   Linearity in the non-deterministic call-by-value setting   12 / 20
Sums as Pairs
                     +, ¯
                        0                                                 ×, 1


             T +S ≡ S +T                                    A×B = B ×A
       T + (S + R) ≡ (T + S) + R                      A × (B × C ) = (A × B) × C
             T +¯ ≡ T
                 0                                          A×1 = A
                         T , R, S ::= U | T + R | ¯ 0
                        U, V , W ::= X | U → T | ∀X .U
                       Type      Binary tree (leaf: U or ¯
                                                         0)


  Example:
  T = (U1 + U2 ) + ¯
                   0                                                                   ¯
                                                                                       0
  T [r → ¯ lr → U2 , ll → U1 ]
         0,
                                                         U1                 U2

                           We keep structured sum types

                Alejandro Díaz-Caro  Barbara Petit   Linearity in the non-deterministic call-by-value setting   12 / 20
Structured Arrow-elimination
          n                                      m
Γ   t:         ∀X .(U → Ti )          Γ   u:           U[Wj /X ]
         i=1                                    j=1
                           n   m
                Γ   tu :             Ti [Wj /X ]
                           i=1 j=1
                                                   Γ    t : T [ → ∀X .(U → T )]                    Γ      u : T [ → U[W /X ]]
                                                                     Γ    tu : T ◦ T [             → T [W /X ]]

                                                                                   tu:
     t:                                        u:




                                                U[W1 /X ]        U[W2 /X ]
         ∀X .U→T1           ∀X .U→T2

                                                                                     T1 [W1 /X ]   T1 [W2 /X ] T2 [W1 /X ]      T2 [W2 /X ]




                               Alejandro Díaz-Caro  Barbara Petit       Linearity in the non-deterministic call-by-value setting             13 / 20
Structured Arrow-elimination
An example


 t = (t1 + t2 ) + 0                       tu →∗ t1 u1 + (u2 + u3 ) +
                                                t2 u1 + (u2 + u3 ) + 0
                                             →∗ t1 u1 + (t1 u2 + t1 u3 )+
                                                t2 u1 + (t2 u2 + t2 u3 ) + 0
                           ¯
                           0

    U → T1 U → T2
                                                                                                       ¯
                                                                                                       0
 u = u1 + (u2 + u3 )



      U                                                       T1                      T2


             U         U                                           T1 T1                  T2 T2


                      Alejandro Díaz-Caro  Barbara Petit   Linearity in the non-deterministic call-by-value setting   14 / 20
Equivalence in System F

  What about associativity, commutativity and neutral element
  in system F with pairs?

  Lemma
                        T ≡T                  implies                |T | ↔ |T |



  Where A ↔ B means

                 F   εA,B : A ⇒ B                  and                   F   εB,A : B ⇒ A

  for some terms εA,B , εB,A s.t.

               εA,B ◦ εB,A ≈ idA                       and           εB,A ◦ εA,B ≈ idB



                 Alejandro Díaz-Caro  Barbara Petit         Linearity in the non-deterministic call-by-value setting   15 / 20
Translation of terms
What happens with the distributivity?




                                    t+u                              [t], [u]

           (t1 + t2 )(u1 + u2 ) →∗                      but       t1 , t2 r1 , r2
            t1 u1 + t1 u2 + t2 u1 + t2 u2                           t1 r1 , t1 r2 , t2 r1 , t2 r2
                         No distributivity in System F with pairs




                      Alejandro Díaz-Caro  Barbara Petit     Linearity in the non-deterministic call-by-value setting   16 / 20
Translation of terms
What happens with the distributivity?




                                    t+u                              [t], [u]

           (t1 + t2 )(u1 + u2 ) →∗                      but       t1 , t2 r1 , r2
            t1 u1 + t1 u2 + t2 u1 + t2 u2                           t1 r1 , t1 r2 , t2 r1 , t2 r2
                         No distributivity in System F with pairs

     Main ideas:
          The sum is distributed during the translation of application
              [tr] = [t1 ][u1 ], [t1 ][u2 ] , [t2 ][u1 ], [t2 ][u2 ]
                                                               if t = t1 + t2 and u = u1 + u2




                      Alejandro Díaz-Caro  Barbara Petit     Linearity in the non-deterministic call-by-value setting   16 / 20
Translation of terms
What happens with the distributivity?




                                    t+u                              [t], [u]

           (t1 + t2 )(u1 + u2 ) →∗                      but       t1 , t2 r1 , r2
            t1 u1 + t1 u2 + t2 u1 + t2 u2                           t1 r1 , t1 r2 , t2 r1 , t2 r2
                         No distributivity in System F with pairs

     Main ideas:
          The sum is distributed during the translation of application
              [tr] = [t1 ][u1 ], [t1 ][u2 ] , [t2 ][u1 ], [t2 ][u2 ]
                                                               if t = t1 + t2 and u = u1 + u2
          The “sum structure” of a term is known thanks to its type
          Γ t : (T1 + T2 ) + T3           t ∼ (t1 + t2 ) + t3
                                                                                          with Γ          ti : Ti



                      Alejandro Díaz-Caro  Barbara Petit     Linearity in the non-deterministic call-by-value setting   16 / 20
Translation of terms


              Γ         t:T                         |Γ|        F    [t]D : |T |

         Γ, x : T x : T                                               [x]D = x
             Γ 0:¯0                                                   [0]D =




            Alejandro Díaz-Caro  Barbara Petit   Linearity in the non-deterministic call-by-value setting   17 / 20
Translation of terms


              Γ         t:T                         |Γ|        F    [t]D : |T |

         Γ, x : T x : T                                               [x]D = x
             Γ 0:¯0                                                   [0]D =
        Γ t:T T ≡T
                                                            [t]D = ε|T |,|T | [t]D
             Γ t:T




            Alejandro Díaz-Caro  Barbara Petit   Linearity in the non-deterministic call-by-value setting   17 / 20
Translation of terms


                   Γ         t:T                         |Γ|        F    [t]D : |T |

         Γ, x : T x : T                                                    [x]D = x
             Γ 0:¯0                                                        [0]D =
        Γ t:T T ≡T
                                                                 [t]D = ε|T |,|T | [t]D
             Γ t:T
        Γ       t:T Γ u:S
                                                              [t+r]D = [t]D1 , [u]D2
            Γ    t+u:T +S
          Γ, x : U t : T
                                                                  [λx.t]D = λx.[t]D
         Γ λx.t : U → T




                 Alejandro Díaz-Caro  Barbara Petit   Linearity in the non-deterministic call-by-value setting   17 / 20
Translation of terms


                     Γ         t:T                         |Γ|        F    [t]D : |T |

            Γ, x : T x : T                                                   [x]D = x
                Γ 0:¯0                                                       [0]D =
           Γ t:T T ≡T
                                                                   [t]D = ε|T |,|T | [t]D
                Γ t:T
          Γ       t:T Γ u:S
                                                                [t+r]D = [t]D1 , [u]D2
              Γ    t+u:T +S
               Γ, x : U t : T
                                             [λx.t]D = λx.[t]D
              Γ λx.t : U → T
   Γ   t : T [ →∀X .(U→T )] Γ u : T [ →U[W /X ]]
             Γ tu : T ◦ T [ →T [W /X ]]
                                      [tu]D = T ◦ T [ →π ([t]D1 )π                                              ([u]D2 )]




                   Alejandro Díaz-Caro  Barbara Petit   Linearity in the non-deterministic call-by-value setting           17 / 20
Translation of terms
An example



        Γ    t : (U → T1 ) + (U → T2 )                     + (U → T3 )                       Γ       u:U +U

                 Γ      tu : (T1 + T1 ) + (T2 + T2 ) + (T3 + T3 )

                                                                           t1 =π11 ([t]);t2 =π12 ([t]);t3 =π2 ([t]);
                                                                                             r1 =π1 ([u]);r2 =π2 ([u]);

    tu :                                              [tu]D =



                      T3          T3
     T1 T1T2 T2                                                                                t3 r1           t3 r2

                                                       t1 r1 t1 r2              t2 r1 t2 r2

                     Alejandro Díaz-Caro  Barbara Petit    Linearity in the non-deterministic call-by-value setting      18 / 20
Correctness


  Theorem (Correctness w.r.t. typing)
  Γ     t:T        implies               |Γ|       F   [t]D : |T |


  We provide a partial inverse translation (| · |) and prove

  Theorem (Inverse translation)
  Γ     t:T        =           (||Γ||)         F   (|[t]D |) : (||T ||)



  Theorem (Reduction preservation)
  Γ     t : T and t → t                implies              [t]D →+ [t ]D                      for some D
                                                                                     (except for t + 0 → t)



                 Alejandro Díaz-Caro  Barbara Petit      Linearity in the non-deterministic call-by-value setting   19 / 20
Summarising and concluding

     + “like linear functions”:              f(x + y ) = f(x) + f(y )
     Additive type system tight to the behaviour of +
     Typed system translate to System F with pairs




                Alejandro Díaz-Caro  Barbara Petit   Linearity in the non-deterministic call-by-value setting   20 / 20
Summarising and concluding

     + “like linear functions”:              f(x + y ) = f(x) + f(y )
     Additive type system tight to the behaviour of +
     Typed system translate to System F with pairs

    System F with pairs correspond to the non-linear fragment of
                               IMELL




                Alejandro Díaz-Caro  Barbara Petit   Linearity in the non-deterministic call-by-value setting   20 / 20
Summarising and concluding

       + “like linear functions”:              f(x + y ) = f(x) + f(y )
       Additive type system tight to the behaviour of +
       Typed system translate to System F with pairs

     System F with pairs correspond to the non-linear fragment of
                                IMELL

   Linear Logic                                         CBV nd/alg
   Force unique use of the argument                     Ban sum terms substitutions
   e.g.                                                 e.g.

           f(x) = x 2 no linear                                  f(x + y ) → f(x) + f(y )
           f(x) = x + 1 linear


   In the CBV non-deterministic setting (or algebraic) it is enough to treat
   functions as linear, even if they are not. (In LL all functions are linear).

                  Alejandro Díaz-Caro  Barbara Petit   Linearity in the non-deterministic call-by-value setting   20 / 20

More Related Content

PDF
A type system for the vectorial aspects of the linear-algebraic lambda-calculus
PDF
Matematica (1)edicta orta 1300
PDF
Lesson 5: Continuity (slides)
PDF
11X1 T13 02 sketching polynomials
PDF
Fractional Calculus
PDF
11 X1 T03 02 sketching polynomials (2010)
PDF
Lesson 14: Exponential Functions
PDF
Lesson 14: Exponential Functions
A type system for the vectorial aspects of the linear-algebraic lambda-calculus
Matematica (1)edicta orta 1300
Lesson 5: Continuity (slides)
11X1 T13 02 sketching polynomials
Fractional Calculus
11 X1 T03 02 sketching polynomials (2010)
Lesson 14: Exponential Functions
Lesson 14: Exponential Functions

What's hot (10)

PDF
Lesson 8: Basic Differentiation Rules (Section 21 slides)
KEY
Cue april 24, 2010
PDF
Transfers Principles Revisited with Choquet’s Lemma on Successive Differences
PDF
Lesson 17: Indeterminate forms and l'Hôpital's Rule (slides)
PDF
Profº Marcelo Santos Chaves Cálculo I (limites trigonométricos)
PDF
Lesson 14: Exponential Functions
PDF
Lecture 02
PDF
Slides used during my thesis defense "Du typage vectoriel"
PDF
International conference "QP 34 -- Quantum Probability and Related Topics"
PPTX
Stochastic Assignment Help
Lesson 8: Basic Differentiation Rules (Section 21 slides)
Cue april 24, 2010
Transfers Principles Revisited with Choquet’s Lemma on Successive Differences
Lesson 17: Indeterminate forms and l'Hôpital's Rule (slides)
Profº Marcelo Santos Chaves Cálculo I (limites trigonométricos)
Lesson 14: Exponential Functions
Lecture 02
Slides used during my thesis defense "Du typage vectoriel"
International conference "QP 34 -- Quantum Probability and Related Topics"
Stochastic Assignment Help
Ad

Similar to Linearity in the non-deterministic call-by-value setting (20)

PDF
Parameterized curves in r^3
PDF
Linear Transformations, Matrix Algebra
PDF
Derivatives pricing
DOCX
MATH 200-004 Multivariate Calculus Winter 2014Chapter 12.docx
PDF
torsionbinormalnotes
PDF
Markov Tutorial CDC Shanghai 2009
PDF
Stuff You Must Know Cold for the AP Calculus BC Exam!
PDF
Stochastic Control and Information Theoretic Dualities (Complete Version)
PDF
Test
PDF
linear transformation and rank nullity theorem
PDF
Mesh Processing Course : Active Contours
PPT
12.5. vector valued functions
PDF
conference_poster_5_UCSB
PDF
Linear regression
PDF
Lesson 2: A Catalog of Essential Functions (slides)
PDF
Lesson 2: A Catalog of Essential Functions (slides)
PDF
QMC: Operator Splitting Workshop, Thresholdings, Robustness, and Generalized ...
PDF
Fourier series
PPTX
Signal Processing Homework Help
PDF
smtlecture.5
Parameterized curves in r^3
Linear Transformations, Matrix Algebra
Derivatives pricing
MATH 200-004 Multivariate Calculus Winter 2014Chapter 12.docx
torsionbinormalnotes
Markov Tutorial CDC Shanghai 2009
Stuff You Must Know Cold for the AP Calculus BC Exam!
Stochastic Control and Information Theoretic Dualities (Complete Version)
Test
linear transformation and rank nullity theorem
Mesh Processing Course : Active Contours
12.5. vector valued functions
conference_poster_5_UCSB
Linear regression
Lesson 2: A Catalog of Essential Functions (slides)
Lesson 2: A Catalog of Essential Functions (slides)
QMC: Operator Splitting Workshop, Thresholdings, Robustness, and Generalized ...
Fourier series
Signal Processing Homework Help
smtlecture.5
Ad

More from Alejandro Díaz-Caro (13)

PDF
Typing quantum superpositions and measurement
PDF
A lambda calculus for density matrices with classical and probabilistic controls
PDF
Towards a quantum lambda-calculus with quantum control
PDF
Affine computation and affine automaton
PDF
Simply typed lambda-calculus modulo isomorphisms
PDF
The probability of non-confluent systems
PDF
Vectorial types, non-determinism and probabilistic systems: Towards a computa...
PDF
Quantum computing, non-determinism, probabilistic systems... and the logic be...
PDF
Non determinism through type isomophism
PDF
Call-by-value non-determinism in a linear logic type discipline
PDF
Slides QuAND 2011
PDF
Equivalence of algebraic λ-calculi
PDF
A System F accounting for scalars
Typing quantum superpositions and measurement
A lambda calculus for density matrices with classical and probabilistic controls
Towards a quantum lambda-calculus with quantum control
Affine computation and affine automaton
Simply typed lambda-calculus modulo isomorphisms
The probability of non-confluent systems
Vectorial types, non-determinism and probabilistic systems: Towards a computa...
Quantum computing, non-determinism, probabilistic systems... and the logic be...
Non determinism through type isomophism
Call-by-value non-determinism in a linear logic type discipline
Slides QuAND 2011
Equivalence of algebraic λ-calculi
A System F accounting for scalars

Recently uploaded (20)

PPTX
Modernising the Digital Integration Hub
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Unlock new opportunities with location data.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
Tartificialntelligence_presentation.pptx
PPTX
Chapter 5: Probability Theory and Statistics
PDF
CloudStack 4.21: First Look Webinar slides
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
Hybrid model detection and classification of lung cancer
PDF
August Patch Tuesday
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
DP Operators-handbook-extract for the Mautical Institute
PPT
Geologic Time for studying geology for geologist
Modernising the Digital Integration Hub
A comparative study of natural language inference in Swahili using monolingua...
Unlock new opportunities with location data.pdf
WOOl fibre morphology and structure.pdf for textiles
Tartificialntelligence_presentation.pptx
Chapter 5: Probability Theory and Statistics
CloudStack 4.21: First Look Webinar slides
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Benefits of Physical activity for teenagers.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
O2C Customer Invoices to Receipt V15A.pptx
Hybrid model detection and classification of lung cancer
August Patch Tuesday
NewMind AI Weekly Chronicles – August ’25 Week III
Taming the Chaos: How to Turn Unstructured Data into Decisions
A contest of sentiment analysis: k-nearest neighbor versus neural network
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
DP Operators-handbook-extract for the Mautical Institute
Geologic Time for studying geology for geologist

Linearity in the non-deterministic call-by-value setting

  • 1. Linearity in the non-deterministic call-by-value setting Alejandro Díaz-Caro Barbara Petit LIPN, Université Paris 13, Sorbonne Paris Cité Focus (INRIA) – Università di Bologna 19th WoLLIC Buenos Aires, September 3–6, 2012
  • 2. Non-determinism (or parallelism) t + u: non-deterministic superposition between t and u (it may run t or u, non-deterministically) Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 1 / 20
  • 3. Non-determinism (or parallelism) t + u: non-deterministic superposition between t and u (it may run t or u, non-deterministically) (t + u)s may run ts or us. Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 1 / 20
  • 4. Non-determinism (or parallelism) t + u: non-deterministic superposition between t and u (it may run t or u, non-deterministically) (t + u)s may run ts or us. Hence (t + u)s → ts + us Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 1 / 20
  • 5. Non-determinism (or parallelism) t + u: non-deterministic superposition between t and u (it may run t or u, non-deterministically) (t + u)s may run ts or us. Hence (t + u)s → ts + us Sum of functions: (f + g)(x) = f(x) + g(x) (this is the interpretation of the algebraic calculi [Vaux, Arrighi-Dowek]) Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 1 / 20
  • 6. Non-determinism (or parallelism) t + u: non-deterministic superposition between t and u (it may run t or u, non-deterministically) (t + u)s may run ts or us. Hence (t + u)s → ts + us Sum of functions: (f + g)(x) = f(x) + g(x) (this is the interpretation of the algebraic calculi [Vaux, Arrighi-Dowek]) t(u + s) (λx.t)(u + s) → t[(u + s)/x] (CBN) (λx.t)(u + s) → (λx.t)u + (λx.t)s (CBV) Generically in CBV t(u + s) → tu + ts Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 1 / 20
  • 7. Non-determinism (or parallelism) t + u: non-deterministic superposition between t and u (it may run t or u, non-deterministically) (t + u)s may run ts or us. Hence (t + u)s → ts + us Sum of functions: (f + g)(x) = f(x) + g(x) (this is the interpretation of the algebraic calculi [Vaux, Arrighi-Dowek]) t(u + s) (λx.t)(u + s) → t[(u + s)/x] (CBN) (λx.t)(u + s) → (λx.t)u + (λx.t)s (CBV) Generically in CBV t(u + s) → tu + ts In algebraic terms, functions are treated as linear in CBV: f(x + y ) = f(x) + f(y ) Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 1 / 20
  • 8. Non-determinism (or parallelism) t + u: non-deterministic superposition between t and u (it may run t or u, non-deterministically) (t + u)s may run ts or us. Hence (t + u)s → ts + us Sum of functions: (f + g)(x) = f(x) + g(x) (this is the interpretation of the algebraic calculi [Vaux, Arrighi-Dowek]) t(u + s) (λx.t)(u + s) → t[(u + s)/x] (CBN) (λx.t)(u + s) → (λx.t)u + (λx.t)s (CBV) Generically in CBV t(u + s) → tu + ts In algebraic terms, functions are treated as linear in CBV: f(x + y ) = f(x) + f(y ) We want to understand this ‘linearity’ Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 1 / 20
  • 9. Outline The untyped calculus The Additive type system capturing the CBV behaviour of + Logical interpretation: translation into System F with pairs Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 2 / 20
  • 10. The untyped CBV non-deterministic λ-calculus t, u, s ::= v | tu | t + u | 0 v ::= x | λx.t Intuitions t + u = non-deterministic superposition between t and u 0 = impossible computation Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 3 / 20
  • 11. The untyped CBV non-deterministic λ-calculus t, u, s ::= v | tu | t + u | 0 v ::= x | λx.t Intuitions t + u = non-deterministic superposition between t and u 0 = impossible computation Hence, t + 0 → t because 0 is impossible! Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 3 / 20
  • 12. The untyped CBV non-deterministic λ-calculus t, u, s ::= v | tu | t + u | 0 v ::= x | λx.t Intuitions t + u = non-deterministic superposition between t and u 0 = impossible computation Hence, t + 0 → t because 0 is impossible! Also 0t → 0 t0 → 0 Because non of them reduces (0 not a value) and there is an impossible computation Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 3 / 20
  • 13. The untyped CBV non-deterministic λ-calculus t, u, s ::= v | tu | t + u | 0 v ::= x | λx.t Intuitions t + u = non-deterministic superposition between t and u 0 = impossible computation Hence, t + 0 → t because 0 is impossible! Also 0t → 0 t0 → 0 Because non of them reduces (0 not a value) and there is an impossible computation Running t or u non-deterministically, is the Finally t + u = u + t same as running u or t non-deterministically Also t + (u + s) = (t + u) + s Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 3 / 20
  • 14. The untyped CBV non-deterministic λ-calculus t, u, s ::= v | tu | t + u | 0 v ::= x | λx.t βv -reduction (λx.t)v → t[v/x] Distributivity rules Zero rules (t + u)s → ts + us t+0→t t(u + s) → tu + ts 0t → 0 t0 → 0 with + associative and commutative Remark: in the algebraic case, 0 is the sum of zero terms Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 3 / 20
  • 15. The Additive type system Objective: capture as much as possible the behaviour of + Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 4 / 20
  • 16. The Additive type system Objective: capture as much as possible the behaviour of + Γ t:T Γ s:S Γ t+s :T +S Γ 0:¯ 0 Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 4 / 20
  • 17. The Additive type system Objective: capture as much as possible the behaviour of + Γ t:T Γ s:S Γ t:T T ≡S Γ t+s :T +S Γ 0:¯ 0 Γ t:S T +R ≡ R +T ; T +(R +S) ≡ (T +R)+S ; T +¯ ≡ T 0 Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 4 / 20
  • 18. The Additive type system Objective: capture as much as possible the behaviour of + Γ t:T Γ s:S Γ t:T T ≡S Γ t+s :T +S Γ 0:¯ 0 Γ t:S T +R ≡ R +T ; T +(R +S) ≡ (T +R)+S ; T +¯ ≡ T 0 T → R: functions from T to R Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 4 / 20
  • 19. The Additive type system Objective: capture as much as possible the behaviour of + Γ t:T Γ s:S Γ t:T T ≡S Γ t+s :T +S Γ 0:¯ 0 Γ t:S T +R ≡ R +T ; T +(R +S) ≡ (T +R)+S ; T +¯ ≡ T 0 T → R: functions from T to R But (T + R) → S does not exists there is no function taking a non-deterministic superposition as argument Recall t(v1 + v2 ) → tv1 + tv2 If v1 : T and v2 : R then t needs to be both T → S1 and R → S2 Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 4 / 20
  • 20. The Additive type system Objective: capture as much as possible the behaviour of + Γ t:T Γ s:S Γ t:T T ≡S Γ t+s :T +S Γ 0:¯ 0 Γ t:S T +R ≡ R +T ; T +(R +S) ≡ (T +R)+S ; T +¯ ≡ T 0 T → R: functions from T to R But (T + R) → S does not exists there is no function taking a non-deterministic superposition as argument Recall t(v1 + v2 ) → tv1 + tv2 If v1 : T and v2 : R then t needs to be both T → S1 and R → S2 Polymorphism & unit types “U” (atomic types w.r.t. +) Arrows: U → T Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 4 / 20
  • 21. The Additive type system (cont.) Examples Concrete example v1 : U1 ; v2 : U2 ; I : ∀X .X → X Hence I (v1 + v2 ) → I v1 + I v2 has type U1 + U2 A more generic example v1 : U[W1 /X ] ; v2 : U[W2 /X ] ; t : ∀X .U → T Hence t(v1 + v2 ) → tv1 + tv2 has type T [W1 /X ] + T [W2 /X ] Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 5 / 20
  • 22. The Additive type system (cont.) Examples Concrete example v1 : U1 ; v2 : U2 ; I : ∀X .X → X Hence I (v1 + v2 ) → I v1 + I v2 has type U1 + U2 A more generic example v1 : U[W1 /X ] ; v2 : U[W2 /X ] ; t : ∀X .U → T Hence t(v1 + v2 ) → tv1 + tv2 has type T [W1 /X ] + T [W2 /X ] Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 5 / 20
  • 23. The Additive type system (cont.) Examples Γ t : ∀X .U → T Γ v1 + v2 : U[W1 /X ] + U[W2 /X ] Γ t(v1 + v2 ) : T [W1 /X ] + T [W2 /X ] A more generic example v1 : U[W1 /X ] ; v2 : U[W2 /X ] ; t : ∀X .U → T Hence t(v1 + v2 ) → tv1 + tv2 has type T [W1 /X ] + T [W2 /X ] Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 5 / 20
  • 24. The Additive type system (cont.) Examples t:U→T ; u:V →R (t + u)v → tv + uv Hence U and V needs to “polymorph” to the type of v v : U[W1 /X ] = V [W2 /X ] t : ∀X .(U → T ) u : ∀X .(V → R) Hence tv + uv has type T [W1 /X ] + R[W2 /X ] Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 6 / 20
  • 25. The Additive type system (cont.) Examples t:U→T ; u:V →R (t + u)v → tv + uv Hence U and V needs to “polymorph” to the type of v v : U[W1 /X ] = V [W2 /X ] t : ∀X .(U → T ) u : ∀X .(V → R) Hence tv + uv has type T [W1 /X ] + R[W2 /X ] Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 6 / 20
  • 26. The Additive type system (cont.) Examples t:U→T ; u:V →R (t + u)v → tv + uv Hence U and V needs to “polymorph” to the type of v v : U[W1 /X ] = V [W2 /X ] t : ∀X .(U → T ) u : ∀X .(V → R) Hence tv + uv has type T [W1 /X ] + R[W2 /X ] Γ t + u : ∀X .(U → T ) + ∀X .(V → R) Γ v : U[W1 /X ] = V [W2 /X ] Γ (t + u)v : T [W1 /X ] + R[W2 /X ] Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 6 / 20
  • 27. The Additive type system (cont.) Arrow elimination Γ t : ∀X .U → T Γ v1 + v2 : U[W1 /X ] + U[W2 /X ] Γ t(v1 + v2 ) : T [W1 /X ] + T [W2 /X ] Γ t + u : ∀X .(U → T ) + ∀X .(V → R) Γ v : U[W1 /X ] = V [W2 /X ] Γ (t + u)v : T [W1 /X ] + R[W2 /X ] combined... Γ t + u : ∀X .(U → T ) + ∀X .(U → R) Γ v1 + v2 : U[W1 /X ] + U[W2 /X ] Γ (t + u)(v1 + v2 ) : T [W1 /X ] + T [W2 /X ] + R[W1 /X ] + R[W2 /X ] Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 7 / 20
  • 28. The Additive type system (cont.) Arrow elimination Γ t : ∀X .U → T Γ v1 + v2 : U[W1 /X ] + U[W2 /X ] Γ t(v1 + v2 ) : T [W1 /X ] + T [W2 /X ] Γ t + u : ∀X .(U → T ) + ∀X .(V → R) Γ v : U[W1 /X ] = V [W2 /X ] Γ (t + u)v : T [W1 /X ] + R[W2 /X ] combined... Γ t + u : ∀X .(U → T ) + ∀X .(U → R) Γ v1 + v2 : U[W1 /X ] + U[W2 /X ] Γ (t + u)(v1 + v2 ) : T [W1 /X ] + T [W2 /X ] + R[W1 /X ] + R[W2 /X ] generalising... n m Γ t: ∀X .(U → Ti ) Γ u: U[Wj /X ] i=1 j=1 n m Γ tu : Ti [Wj /X ] i=1 j=1 Alejandro Díaz-Caro & Barbara Petit Linearity in the non-deterministic call-by-value setting 7 / 20
  • 29. The Additive type system (cont.) Examples V1 = U[W1 /X ] ; V2 = U[W2 /X ] Γ λx.t + λy .u : ∀X .(U → T ) + ∀X .(U → R) Γ v1 + v2 : V1 + V2 Γ (λx.t + λy .u)(v1 + v2 ) : T [W1 /X ] + T [W2 /X ] + R[W1 /X ] + R[W2 /X ] (λx.t)v1 + (λx.t)v2 + (λy .u)v1 + (λy .u)v2 T [W1 /X ] T [W2 /X ] R[W1 /X ] R[W2 /X ] Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 8 / 20
  • 30. The Additive type system (cont.) Examples V1 = U[W1 /X ] ; V2 = U[W2 /X ] Γ λx.t + λy .u : ∀X .(U → T ) + ∀X .(U → R) Γ v1 + v2 : V1 + V2 Γ (λx.t + λy .u)(v1 + v2 ) : T [W1 /X ] + T [W2 /X ] + R[W1 /X ] + R[W2 /X ] (λx.t)v1 + (λx.t)v2 + (λy .u)v1 + (λy .u)v2 T [W1 /X ] T [W2 /X ] R[W1 /X ] R[W2 /X ] Simpler example Γ λx.x : ∀X .X → X Γ v1 + v2 : U + V Γ (λx.x)(v1 + v2 ) : U + V without simultaneous arrow/forall elimination it is not possible to type it! Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 8 / 20
  • 31. The Additive type system (cont.) Summarising T , R, S := U | T + R | ¯ 0 general types U, V , W := X | U → T | ∀X .U unit types T +¯ ≡ T 0 ; T +R ≡ R +T ; T +(R +S) ≡ (T +R)+S ax Γ t:T Γ u:R ax¯ 0 +I Γ, x : U x :U Γ 0:¯ 0 Γ t+u:T +R n m Γ t: ∀X .(U → Ti ) Γ u: U[Wj /X ] i=1 j=1 Γ, x : U t:T →E →I n m Γ λx.t : U → T Γ tu : Ti [Wj /X ] i=1 j=1 Γ t : ∀X .U Γ t:U X ∈ FV (Γ) / Γ t:T T ≡R ∀E ∀I ≡ Γ t : U[V /X ] Γ t : ∀X .U Γ t:R • Strong normalisation • Subject reduction Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 9 / 20
  • 32. Outline The untyped calculus The Additive type system capturing the CBV behaviour of + Logical interpretation: translation into System F with pairs Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 10 / 20
  • 33. System F with pairs t, u ::= x | λx.t | tu | | t, u | π1 (t) | π2 (t) A, B ::= X | A ⇒ B | ∀X .A | 1 | A × B (λx.t)u → t[u/x] π1 ( t1 , t2 ) → t1 π2 ( t1 , t2 ) → t2 Additive System F with pairs X X U→T |U| ⇒ |T | ∀X .U ∀X .|U| ¯ 0 1 T +S |T | × |S| Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 11 / 20
  • 34. Sums as Pairs +, ¯ 0 ×, 1 T +S ≡ S +T A×B = B ×A T + (S + R) ≡ (T + S) + R A × (B × C ) = (A × B) × C T +¯ ≡ T 0 A×1 = A Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 12 / 20
  • 35. Sums as Pairs +, ¯ 0 ×, 1 T +S ≡ S +T A×B = B ×A T + (S + R) ≡ (T + S) + R A × (B × C ) = (A × B) × C T +¯ ≡ T 0 A×1 = A T , R, S ::= U | T + R | ¯ 0 U, V , W ::= X | U → T | ∀X .U Type Binary tree (leaf: U or ¯ 0) Example: T = (U1 + U2 ) + ¯ 0 ¯ 0 T [r → ¯ lr → U2 , ll → U1 ] 0, U1 U2 We keep structured sum types Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 12 / 20
  • 36. Structured Arrow-elimination n m Γ t: ∀X .(U → Ti ) Γ u: U[Wj /X ] i=1 j=1 n m Γ tu : Ti [Wj /X ] i=1 j=1 Γ t : T [ → ∀X .(U → T )] Γ u : T [ → U[W /X ]] Γ tu : T ◦ T [ → T [W /X ]] tu: t: u: U[W1 /X ] U[W2 /X ] ∀X .U→T1 ∀X .U→T2 T1 [W1 /X ] T1 [W2 /X ] T2 [W1 /X ] T2 [W2 /X ] Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 13 / 20
  • 37. Structured Arrow-elimination An example t = (t1 + t2 ) + 0 tu →∗ t1 u1 + (u2 + u3 ) + t2 u1 + (u2 + u3 ) + 0 →∗ t1 u1 + (t1 u2 + t1 u3 )+ t2 u1 + (t2 u2 + t2 u3 ) + 0 ¯ 0 U → T1 U → T2 ¯ 0 u = u1 + (u2 + u3 ) U T1 T2 U U T1 T1 T2 T2 Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 14 / 20
  • 38. Equivalence in System F What about associativity, commutativity and neutral element in system F with pairs? Lemma T ≡T implies |T | ↔ |T | Where A ↔ B means F εA,B : A ⇒ B and F εB,A : B ⇒ A for some terms εA,B , εB,A s.t. εA,B ◦ εB,A ≈ idA and εB,A ◦ εA,B ≈ idB Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 15 / 20
  • 39. Translation of terms What happens with the distributivity? t+u [t], [u] (t1 + t2 )(u1 + u2 ) →∗ but t1 , t2 r1 , r2 t1 u1 + t1 u2 + t2 u1 + t2 u2 t1 r1 , t1 r2 , t2 r1 , t2 r2 No distributivity in System F with pairs Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 16 / 20
  • 40. Translation of terms What happens with the distributivity? t+u [t], [u] (t1 + t2 )(u1 + u2 ) →∗ but t1 , t2 r1 , r2 t1 u1 + t1 u2 + t2 u1 + t2 u2 t1 r1 , t1 r2 , t2 r1 , t2 r2 No distributivity in System F with pairs Main ideas: The sum is distributed during the translation of application [tr] = [t1 ][u1 ], [t1 ][u2 ] , [t2 ][u1 ], [t2 ][u2 ] if t = t1 + t2 and u = u1 + u2 Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 16 / 20
  • 41. Translation of terms What happens with the distributivity? t+u [t], [u] (t1 + t2 )(u1 + u2 ) →∗ but t1 , t2 r1 , r2 t1 u1 + t1 u2 + t2 u1 + t2 u2 t1 r1 , t1 r2 , t2 r1 , t2 r2 No distributivity in System F with pairs Main ideas: The sum is distributed during the translation of application [tr] = [t1 ][u1 ], [t1 ][u2 ] , [t2 ][u1 ], [t2 ][u2 ] if t = t1 + t2 and u = u1 + u2 The “sum structure” of a term is known thanks to its type Γ t : (T1 + T2 ) + T3 t ∼ (t1 + t2 ) + t3 with Γ ti : Ti Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 16 / 20
  • 42. Translation of terms Γ t:T |Γ| F [t]D : |T | Γ, x : T x : T [x]D = x Γ 0:¯0 [0]D = Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 17 / 20
  • 43. Translation of terms Γ t:T |Γ| F [t]D : |T | Γ, x : T x : T [x]D = x Γ 0:¯0 [0]D = Γ t:T T ≡T [t]D = ε|T |,|T | [t]D Γ t:T Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 17 / 20
  • 44. Translation of terms Γ t:T |Γ| F [t]D : |T | Γ, x : T x : T [x]D = x Γ 0:¯0 [0]D = Γ t:T T ≡T [t]D = ε|T |,|T | [t]D Γ t:T Γ t:T Γ u:S [t+r]D = [t]D1 , [u]D2 Γ t+u:T +S Γ, x : U t : T [λx.t]D = λx.[t]D Γ λx.t : U → T Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 17 / 20
  • 45. Translation of terms Γ t:T |Γ| F [t]D : |T | Γ, x : T x : T [x]D = x Γ 0:¯0 [0]D = Γ t:T T ≡T [t]D = ε|T |,|T | [t]D Γ t:T Γ t:T Γ u:S [t+r]D = [t]D1 , [u]D2 Γ t+u:T +S Γ, x : U t : T [λx.t]D = λx.[t]D Γ λx.t : U → T Γ t : T [ →∀X .(U→T )] Γ u : T [ →U[W /X ]] Γ tu : T ◦ T [ →T [W /X ]] [tu]D = T ◦ T [ →π ([t]D1 )π ([u]D2 )] Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 17 / 20
  • 46. Translation of terms An example Γ t : (U → T1 ) + (U → T2 ) + (U → T3 ) Γ u:U +U Γ tu : (T1 + T1 ) + (T2 + T2 ) + (T3 + T3 ) t1 =π11 ([t]);t2 =π12 ([t]);t3 =π2 ([t]); r1 =π1 ([u]);r2 =π2 ([u]); tu : [tu]D = T3 T3 T1 T1T2 T2 t3 r1 t3 r2 t1 r1 t1 r2 t2 r1 t2 r2 Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 18 / 20
  • 47. Correctness Theorem (Correctness w.r.t. typing) Γ t:T implies |Γ| F [t]D : |T | We provide a partial inverse translation (| · |) and prove Theorem (Inverse translation) Γ t:T = (||Γ||) F (|[t]D |) : (||T ||) Theorem (Reduction preservation) Γ t : T and t → t implies [t]D →+ [t ]D for some D (except for t + 0 → t) Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 19 / 20
  • 48. Summarising and concluding + “like linear functions”: f(x + y ) = f(x) + f(y ) Additive type system tight to the behaviour of + Typed system translate to System F with pairs Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 20 / 20
  • 49. Summarising and concluding + “like linear functions”: f(x + y ) = f(x) + f(y ) Additive type system tight to the behaviour of + Typed system translate to System F with pairs System F with pairs correspond to the non-linear fragment of IMELL Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 20 / 20
  • 50. Summarising and concluding + “like linear functions”: f(x + y ) = f(x) + f(y ) Additive type system tight to the behaviour of + Typed system translate to System F with pairs System F with pairs correspond to the non-linear fragment of IMELL Linear Logic CBV nd/alg Force unique use of the argument Ban sum terms substitutions e.g. e.g. f(x) = x 2 no linear f(x + y ) → f(x) + f(y ) f(x) = x + 1 linear In the CBV non-deterministic setting (or algebraic) it is enough to treat functions as linear, even if they are not. (In LL all functions are linear). Alejandro Díaz-Caro Barbara Petit Linearity in the non-deterministic call-by-value setting 20 / 20