Documentation

CslibFrontier.Languages.CombinatoryLogic.PartialCombinatoryAlgebra

Partial combinatory algebras #

A partial combinatory algebra (pca) is a set A with a partial binary application, written a ⬝ b, and two elements k and s such that, for all a, b and c, k ⬝ a ⬝ b = a, s ⬝ a ⬝ b is defined, and s ⬝ a ⬝ b ⬝ c ≃ (a ⬝ c) ⬝ (b ⬝ c), where ≃ is Kleene equality: one side is defined exactly when the other is, and then they are equal. Application associates to the left, and an application is defined only when its two arguments are. Pcas are the models of realizability: Kleene's first model on the natural numbers (indices of partial recursive functions) and his second model on Baire space are the standard examples.

Application is a function A → A → Part A, and Kleene equality is equality in Part A. The application of two partial values, ap app x y, is defined when x and y are and app is defined at their values.

The main property is combinatory completeness: every term built from variables, constants and application can be abstracted over its last variable. PartialCombinatoryAlgebra.abs is the bracket abstraction, and PartialCombinatoryAlgebra.dom_eval_abs and PartialCombinatoryAlgebra.ap_eval_abs say that the abstraction always denotes, and that applying it to a evaluates the term with a in place of the last variable.

Main definitions #

Main results #

Implementation notes #

A pca is a structure on its carrier rather than a class, because realizability uses many pcas on one carrier: Kleene's first model relative to each oracle lives on ℕ, and sub-pcas share the application of the ambient pca. The axioms follow the definition in [vO08], Chapter 1, §1.1, which (unlike some sources) does not require k ≠ s.

Cslib.SKI.Polynomial.toSKI in cslib is bracket abstraction for the closed SKI calculus. It cannot be used here: a pca's terms have constants from the carrier, and its abstraction theorem is a Kleene equality, in which definedness of either side gives definedness of the other, rather than a reduction.

References #

def Cslib.PartialCombinatoryAlgebra.ap {A : Type u_1} (app : A → A → Part A) (x y : Part A) :

Application of partial values: ap app x y is defined when x and y are defined, with values a and b, and app a b is defined; its value is then that of app a b.

@[simp]
theorem Cslib.PartialCombinatoryAlgebra.ap_some_some {A : Type u_1} (app : A → A → Part A) (a b : A) :
ap app (Part.some a) (Part.some b) = app a b
theorem Cslib.PartialCombinatoryAlgebra.app_get_eq_ap {A : Type u_1} (app : A → A → Part A) {x : Part A} (h : x.Dom) (b : A) :
app (x.get h) b = ap app x (Part.some b)

Applying the value of a defined partial value x is applying x.

structure Cslib.PartialCombinatoryAlgebra (A : Type u_1) :
Type u_1

A partial combinatory algebra on the carrier A: a partial application app with combinators k and s satisfying k ⬝ a ⬝ b = a, s ⬝ a ⬝ b defined and s ⬝ a ⬝ b ⬝ c ≃ (a ⬝ c) ⬝ (b ⬝ c) ([vO08], §1.1).

k ⬝ a is defined.

The identity combinator i, the value of s ⬝ k ⬝ k.

@[simp]

i ⬝ a = a.

inductive Cslib.PartialCombinatoryAlgebra.Term (A : Type u_2) (n : ℕ) :
Type u_2

Terms over the carrier A with variables in Fin n: variables, constants and application.

  • var {A : Type u_2} {n : ℕ} : Fin n → Term A n

    The variable xᵢ.

  • const {A : Type u_2} {n : ℕ} : A → Term A n

    A constant of the carrier.

  • app {A : Type u_2} {n : ℕ} : Term A n → Term A n → Term A n

    Application of terms.

def Cslib.PartialCombinatoryAlgebra.eval {A : Type u_1} (P : PartialCombinatoryAlgebra A) {n : ℕ} :
Term A n → (Fin n → A) → Part A

The partial value of a term when the variables take the values ρ.

noncomputable def Cslib.PartialCombinatoryAlgebra.abs {A : Type u_1} (P : PartialCombinatoryAlgebra A) {n : ℕ} :
Term A (n + 1) → Term A n

Bracket abstraction of the last variable xₙ of a term: xₙ becomes i, another variable or a constant t becomes k ⬝ t, and an application t ⬝ u becomes s ⬝ ⟨xₙ⟩t ⬝ ⟨xₙ⟩u.

theorem Cslib.PartialCombinatoryAlgebra.dom_eval_abs {A : Type u_1} (P : PartialCombinatoryAlgebra A) {n : ℕ} (t : Term A (n + 1)) (ρ : Fin n → A) :
(P.eval (P.abs t) ρ).Dom

Combinatory completeness, definedness: the bracket abstraction of a term always has a value ([vO08], §1.1).

theorem Cslib.PartialCombinatoryAlgebra.ap_eval_abs {A : Type u_1} (P : PartialCombinatoryAlgebra A) {n : ℕ} (t : Term A (n + 1)) (ρ : Fin n → A) (a : A) :
ap P.app (P.eval (P.abs t) ρ) (Part.some a) = P.eval t (Fin.snoc ρ a)

Combinatory completeness: applying the bracket abstraction ⟨xₙ⟩t of a term to a is Kleene equal to evaluating t with a for its last variable ([vO08], §1.1).

Sub-pcas #

def Cslib.PartialCombinatoryAlgebra.sub {A : Type u_1} (P : PartialCombinatoryAlgebra A) (S : A → Prop) (hk : S P.k) (hs : S P.s) (happ : ∀ (a b c : A), S a → S b → c ∈ P.app a b → S c) :

The sub-pca of P on the elements satisfying S, when S contains k and s and is closed under application. Its application is that of P (map_val_sub_app).

@[simp]
theorem Cslib.PartialCombinatoryAlgebra.map_val_sub_app {A : Type u_1} (P : PartialCombinatoryAlgebra A) (S : A → Prop) (hk : S P.k) (hs : S P.s) (happ : ∀ (a b c : A), S a → S b → c ∈ P.app a b → S c) (a b : Subtype S) :
Part.map Subtype.val ((P.sub S hk hs happ).app a b) = P.app ↑a ↑b

Application in a sub-pca is application in the ambient pca.