• Nie Znaleziono Wyników

Cartesian closed categories CCC

N/A
N/A
Protected

Academic year: 2021

Share "Cartesian closed categories CCC"

Copied!
14
0
0

Pełen tekst

(1)

Cartesian closed categories CCC

'

&

$

% '

&

$

% typed

functional

programming catego vs.

ry theo

ry '

&

$

% '

&

$

% typed lamb

da-calculi vs.

catego

ry theo ry

(2)

Cartesian categories

Definition: A category K is Cartesian if it comes equipped with finite products.

Equivalently:

• 1 ∈ |K| — a terminal object

• A × B — a product of A and B, for every A, B ∈ |K|

Examples: Set, Pfn, Cpo, semilattices, Cat, TΣ,Φop , . . .

Recall the definitions of these categories and the constructions of products in each of them

(3)

Cartesian closed categories

Definition: A Cartesian category K is closed if for all B, C ∈ |K| we indicate [B→C] ∈ |K and εB,C : [B→C] × B → C such that for all A ∈ |K| and

f : A × B → C there is a unique Λ(f ) : A → [B→C] satisfying (Λ(f ) × idB);εB,C = f

[B→C]

A

[B→C] × B

A × B

C -

*

6 6

εB,C

∃! Λ(f ) Λ(f ) × idB f

× B -

K K

Examples: Set, Cpo, Cat, . . .

Heyting semilattices (b ⇐ c is such that for all a, a ∧ b ≤ c iff a ≤ (b ⇐ c) Non-examples: Pfn, TΣ,Φop .

(4)

Summing up

A category K is a Cartesian closed category (CCC) if:

• C : K → 1 has a right adjoint C1: 1 → K, yielding 1 ∈ |K|.

• ∆ : K → K × K has a right adjoint × : K × K → K with counit given by πA,B : A × B → A and πA,B0 : A × B → B for A, B ∈ |K|.

• for each B ∈ |K|, × B : K → K has right adjoint [B→ ] : K → K, with counit given by εB,C : [B→C] × B → C, for C ∈ |K|.

(5)

Spelling this out

• 1 ∈ |K|

− for A ∈ |K|: hiA: A → 1 such that hiA = f for all f : A → 1.

• for A, B ∈ |K|, A × B ∈ |K|, πA,B : A × B → A, πA,B0 : A × B → B:

− for C ∈ |K|, for f : C → A, g : C → B: hf, gi : C → A × B such that

− hf, gi;πA,B = f and hf, gi;πA,B0 = g

− for h : C → A × B, h = hh;πA,B, h;πA,B0 i

• for B, C ∈ |K|, [B→C] ∈ |K|, εB,C : [B→C] × B → C:

− for A ∈ |K|, for f : A × B → C: Λ(f ) : A → [B→C] such that

− (Λ(f ) × idB);εB,C = f

− for h : A → [B→C], Λ((h × idB);εB,C) = h.

(6)

Typed λ-calculus with products

Types The set T of types τ ∈ T is such that

• 1 ∈ T

• τ ×τ0 ∈ T , for all τ, τ0 ∈ T

• τ →τ0 ∈ T , for all τ, τ0 ∈ T Note:

T need

not be the least such that.. .

Contexts Contexts Γ are of the form:

• x11, . . . , xnn,

where n ≥ 0, x1, . . . , xn are distinct variables, and τ1, . . . , τn ∈ T

(7)

Typed terms in contexts

Γ ` t : τ

Typing/formation rules coming next Omitting the usual definitions, like:

• free variables FV (M ),

• substitution M [N/x], etc. Same for the usual simple properties, like:

• weakening — context extension;

• subject reduction;

• uniqueness of types;

• removing unused variables from contexts;

etc

(8)

Typing rules

x11, . . . , xnn ` xi: τi x11, . . . , xnn ` M : τ

x11, . . . , xi−1i−1, xi+1i+1, . . . , xnn ` λxii.M : τi→τ Γ ` M : τ →τ0 Γ ` N : τ

Γ ` M N : τ0

Γ ` hi : 1

Γ ` M : τ Γ ` N : τ0 Γ ` hM, N i : τ ×τ0

Γ ` πτ,τ0 : τ ×τ0→τ Γ ` πτ,τ0 0 : τ ×τ0→τ0

(9)

Semantics

Let K be an arbitrary but fixed CCC.

• Types denote objects, [[τ ]] ∈ |K|, satisfying:

− [[1]] = 1

− [[τ ×τ0]] = [[τ ]] × [[τ0]]

− [[τ →τ0]] = [[[τ ]]→[[τ0]]]

• So do contexts:

− [[x11, . . . , xnn]] = [[τ1]] × . . . × [[τn]]

• Terms denote morphisms:

[[M ]] : [[Γ]] → [[τ ]]

defined by induction on the derivation of Γ ` M : τ (coming next).

(10)

Semantics of λ-terms

− [[xi]] = πi: [[Γ]] → [[τi]] for Γ = x11, . . . , xnn, where πi is the obvious projection.

− [[λxii.M ]] = Λ(ρ;[[M ]]) : [[Γ0]] → [[[τi]]→[[τ ]]] for Γ = x11, . . . , xnn, Γ0 = x11, . . . , xi−1i−1, xi+1i+1, . . . , xnn, and Γ ` M : τ, where ρ : [[Γ0]] × [[τi]] → [[Γ]] is the obvious isomorphism.

− [[M N ]] = h[[M ]], [[N ]]i;ε[[τ ]],[[τ0]]: [[Γ]] → [[τ0]] for Γ ` M : τ →τ0 and Γ ` N : τ.

− [[hi]] = hi[[Γ]]: [[Γ]] → 1

− [[hM, N i]] = h[[M ]], [[N ]]i : [[Γ]] → [[τ ]] × [[τ0]] for Γ ` M : τ and Γ ` N : τ0.

− [[πτ,τ0]] = Λ(π[[Γ]],[[τ ]]×[[τ0 0]][[τ ]],[[τ0]]) : [[Γ]] → [[[τ ]] × [[τ0]]→[[τ ]]] and [[πτ,τ0 0]] = Λ(π[[Γ]],[[τ ]]×[[τ0 0]][[τ ]],[[τ0 0]]) : [[Γ]] → [[[τ ]] × [[τ0]]→[[τ0]]]

(11)

Equational β, η-calculus

Judgements:

Γ ` M = N : τ

for τ ∈ T , Γ ` M : τ, Γ ` N : τ Axioms:

(β) Γ ` (λx:τ.M )N = M [N/x] : τ0, for Γ ` λx:τ.M : τ →τ0, Γ ` N : τ (η) Γ ` λx:τ.M x = M : τ →τ0, for Γ ` M : τ →τ0, x 6∈ dom(Γ)

• Γ ` M = hi : 1, for γ ` M : 1

• Γ ` πτ,τ0hM, N i = M : τ and Γ ` πτ,τ0 0hM, N i = N : τ0, for Γ ` M : τ, Γ ` N : τ0

• Γ ` M = hπτ,τ0M, πτ,τ0 0M i : τ ×τ0, for Γ ` M : τ ×τ0 Rules: reflexivity, symmetry, transitivity, congruence.

(12)

Soundness

Given Γ ` M : τ and Γ ` N : τ

if Γ ` M = N : τ then [[M ]] = [[N ]]

Proof: :-)

Just check that the axioms and rules of the equational β, η-calculus are sound w.r.t.

the semantics in any CCC. For example:

(η) for Γ ` M : τ →τ0, x 6∈ dom(Γ), given the isomorphism ρ : [[Γ]] × [[τ ]] → [[Γ, x:τ ]]:

[[λx:τ.M x]] = Λ(ρ;[[M x]]) = Λ(ρ;(h[[M ]], [[x]]i;ε[[τ ]],[[τ0]])) =

Λ(hρ;[[M ]], ρ;[[x]]i;ε[[τ ]],[[τ0]]) = Λ(([[M ]] × id[[τ ]]);ε[[τ ]],[[τ0]]) = [[M ]].

Warning: The “real work” is in the proof of soundess for (β), where induction on the structure of terms is needed.

(13)

Completeness

Given Γ ` M : τ and Γ ` N : τ,

if in every CCC, [[M ]] = [[N ]] then Γ ` M = N : τ

Proof: It is enough to prove this for terms in the empty context.

Define a CCC λλ:

• Category λλ:

− objects are all types: |λλ| = T

− morphisms are λ-terms modulo equality: λλ(τ, τ0) = {M | ` M : τ →τ0}/≈, where M ≈ N iff ` M = N : τ0→τ

− composition: [M ];[N ] = [λx:τ.N (M x)], for ` M : τ →τ0, ` N : τ0→τ00

− identities: idτ = [λx:τ.x].

(14)

• Products in λλ:

− terminal object 1 ∈ |λλ|, with hiτ = [λx:τ.hi]

− binary product τ ×τ0, with πτ,τ0 = [πτ,τ0], πτ,τ0 0 = [πτ,τ0 0] and pairing h[M ], [N ]i = [hM, N i] for ` M : τ, ` N : τ0.

• Exponent in λλ: τ →τ0, with ετ,τ0 = [λx:(τ →τ0)×τ .(πτ →τ0x)(πτ →τ0 0x)] and Λ([M ]) = [λx:τ.λy:τ0.M hx, yi], for ` M : τ ×τ0→τ00.

Now: if in every CCC, [[M ]] = [[N ]], then this holds in particular in λλ, and so Γ ` M = N : τ.

To wrap this up: add constants of arbitrary types

SUMMING UP:

CCCs coincide with λ-calculi

Cytaty

Powiązane dokumenty

Warning: The “real work” is in the proof of soundess for (β), where induction on the!. structure of terms

Naast de basis functionaliteit zijn een aantal speciale effecten geïmplementeerd (zie figuur 3): Supersampling anti-aliasing (voor scherpere beelden), niet-horizontale

To support navigation in the traffic network affected by moving obstacles, in this paper, we provide a spatio-temporal data model to structure the information of traffic conditions

Konceptyzm jako postawa wobec prezentowanego świata (związana z zamysłem prezentacji, z tym, co wybrać do przedstawienia oraz z jakiego punktu wi- dzenia tej prezentacji dokonać),

However, the change in grammatical status associated with weak verb for- mation is signalled not just by the syntax of the form, and possibly the presence of certain

Nie należy jednak pomijać kluczowej roli spółki cywilnej w nowoczesnych systemach prawa jako punktu odniesienia dla rozmaitych form kooperacji, które z uwagi na element dążenia do

Dla duszpasterzy ważna jest także wiedza, na ile podejmowana przez nich problematyka życia małżeńskiego i rodzinnego w ramach przygotowania jest przy- swajana przez narzeczonych

Sentences containing ‘God’ have a particular status: one cannot simply state that they have a mean- ing (since a complete description and with it a complete representation is