• Nie Znaleziono Wyników

Functions all the way down! Lambda Calculus and Church Encoding

N/A
N/A
Protected

Academic year: 2021

Share "Functions all the way down! Lambda Calculus and Church Encoding"

Copied!
93
0
0

Pełen tekst

(1)

Functions all the way down!

Lambda Calculus and Church Encoding

Ivan Lazar Miljenovic

Maths PhD Journal Club

14 May, 2009

(2)

Outline

1 Introduction

2 Theory of Computing

3 The λ-Calculus

(3)

Introduction

Introduction

1 Introduction

Turtles all the way down...

Programming languages and Functions

Functions all the way down

(4)

Introduction Turtles all the way down...

Turtles all the way down...

From Stephen Hawking’s A Brief History of Time

A well-known scientist (some say it was Bertrand Russell) once gave a public lecture on astronomy. He described how the earth orbits around the sun and how the sun, in turn, orbits around the center of a vast collection of stars called our galaxy.

At the end of the lecture, a little old lady at the back of the room got up and said: “What you have told us is rubbish. The world is really a flat plate supported on the back of a giant tortoise.” The scientist gave a superior smile before replying, “What is the tortoise standing on?” “You’re very clever, young man, very clever,” said the old lady. “But it’s turtles all the way down!”

(5)

Introduction Turtles all the way down...

Turtles all the way down...

From Stephen Hawking’s A Brief History of Time

A well-known scientist (some say it was Bertrand Russell) once gave a public lecture on astronomy. He described how the earth orbits around the sun and how the sun, in turn, orbits around the center of a vast collection of stars called our galaxy.

At the end of the lecture, a little old lady at the back of the room got up and said: “What you have told us is rubbish. The world is really a flat plate supported on the back of a giant tortoise.” The scientist gave a superior smile before replying, “What is the tortoise standing on?” “You’re very clever, young man, very clever,” said the old lady. “But it’s turtles all

(6)

Introduction Programming languages and Functions

Programming languages and Functions

Most “standard” programming languages There is data, and then functions that act on that data.

Functional languages Functions are “first class citizens” (Cristopher Strachey, mid-1960s).

LISP family Everything is data; all data is code.

What about replacing data with functions?

(7)

Introduction Programming languages and Functions

Programming languages and Functions

Most “standard” programming languages There is data, and then functions that act on that data.

Functional languages Functions are “first class citizens” (Cristopher Strachey, mid-1960s).

LISP family Everything is data; all data is code.

What about replacing data with functions?

(8)

Introduction Programming languages and Functions

Programming languages and Functions

Most “standard” programming languages There is data, and then functions that act on that data.

Functional languages Functions are “first class citizens” (Cristopher Strachey, mid-1960s).

LISP family Everything is data; all data is code.

What about replacing data with functions?

(9)

Introduction Programming languages and Functions

Programming languages and Functions

Most “standard” programming languages There is data, and then functions that act on that data.

Functional languages Functions are “first class citizens” (Cristopher Strachey, mid-1960s).

LISP family Everything is data; all data is code.

What about replacing data with functions?

(10)

Introduction Functions all the way down

Functions all the way down

(11)

Theory of Computing

Theory of Computing

2 Theory of Computing

The Entscheidungsproblem

Solutions to the Entscheidungsproblem

(12)

Theory of Computing The Entscheidungsproblem

The Entscheidungsproblem

The decidability problem

Posed by David Hilbert in 1928:

Definition (The Entscheidungsproblem)

Given a description of a formal language and a mathematical statement in that language, determine if the statement is true or false.

Original Statement

Generalisation of his question “Is mathematics decidable”.

(13)

Theory of Computing The Entscheidungsproblem

The Entscheidungsproblem

The decidability problem

Posed by David Hilbert in 1928:

Definition (The Entscheidungsproblem)

Given a description of a formal language and a mathematical statement in that language, determine if the statement is true or false.

Original Statement

Generalisation of his question “Is mathematics decidable”.

(14)

Theory of Computing The Entscheidungsproblem

The Entscheidungsproblem

The decidability problem

Posed by David Hilbert in 1928:

Definition (The Entscheidungsproblem)

Given a description of a formal language and a mathematical statement in that language, determine if the statement is true or false.

Original Statement

Generalisation of his question “Is mathematics decidable”.

(15)

Theory of Computing Solutions to the Entscheidungsproblem

Solutions to the Entscheidungsproblem

The Halting Problem

15 April, 1936

An Unsolvable Problem of Elementary Number Theory by Alonzo Church

January, 1937

On Computable Numbers, with an Application to the Entscheidungsproblem by Alan Turing

Theorem (Church-Turing Thesis)

Every effectively calculable function is a computable function. λ-Calculus, Turing machines, etc. are equivalent.

(16)

Theory of Computing Solutions to the Entscheidungsproblem

Solutions to the Entscheidungsproblem

The Halting Problem

15 April, 1936

An Unsolvable Problem of Elementary Number Theory by Alonzo Church

January, 1937

On Computable Numbers, with an Application to the Entscheidungsproblem by Alan Turing

Theorem (Church-Turing Thesis)

Every effectively calculable function is a computable function. λ-Calculus, Turing machines, etc. are equivalent.

(17)

Theory of Computing Solutions to the Entscheidungsproblem

Solutions to the Entscheidungsproblem

The Halting Problem

15 April, 1936

An Unsolvable Problem of Elementary Number Theory by Alonzo Church

January, 1937

On Computable Numbers, with an Application to the Entscheidungsproblem by Alan Turing

Every effectively calculable function is a computable function. λ-Calculus, Turing machines, etc. are equivalent.

(18)

Theory of Computing Solutions to the Entscheidungsproblem

Solutions to the Entscheidungsproblem

The Halting Problem

15 April, 1936

An Unsolvable Problem of Elementary Number Theory by Alonzo Church

January, 1937

On Computable Numbers, with an Application to the Entscheidungsproblem by Alan Turing

λ-Calculus, Turing machines, etc. are equivalent.

(19)

Theory of Computing Solutions to the Entscheidungsproblem

Solutions to the Entscheidungsproblem

The Halting Problem

15 April, 1936

An Unsolvable Problem of Elementary Number Theory by Alonzo Church

January, 1937

On Computable Numbers, with an Application to the Entscheidungsproblem by Alan Turing

(20)

The λ-Calculus

The λ-Calculus

3 The λ-Calculus

What is the λ-Calculus?

Definition of the λ-Calculus Informal Examples

Usage of the λ-Calculus

(21)

The λ-Calculus What is the λ-Calculus?

What is the λ-Calculus?

Types and Programming Languages

“. . . a formal system invented in the 1920s by Alonzo Church, in which all computation is reduced to the basic operations of function definition and application.”

“Its importance arises from the fact that it can be viewed simultaneously as a simple programming language in which

computations can be described and as a mathematical object about which rigorous statements can be proved.”

(22)

The λ-Calculus What is the λ-Calculus?

What is the λ-Calculus?

Types and Programming Languages

“. . . a formal system invented in the 1920s by Alonzo Church, in which all computation is reduced to the basic operations of function definition and application.”

“Its importance arises from the fact that it can be viewed simultaneously as a simple programming language in which

computations can be described and as a mathematical object about which rigorous statements can be proved.”

(23)

The λ-Calculus What is the λ-Calculus?

What is the λ-Calculus?

Types and Programming Languages

“. . . a formal system invented in the 1920s by Alonzo Church, in which all computation is reduced to the basic operations of function definition and application.”

“Its importance arises from the fact that it can be viewed simultaneously as a simple programming language in which

computations can be described and as a mathematical object about which rigorous statements can be proved.”

(24)

The λ-Calculus What is the λ-Calculus?

What is the λ-Calculus?

A Brief, Incomplete, and Mostly Wrong History of Programming Languages

1936 Alonzo Church also invents every language that will ever be but does it better. His lambda calculus is ignored because it is insufficiently C-like. This criticism occurs in spite of the fact that C has not yet been invented.

1970 . . . Lambdas are relegated to relative obscurity until Java makes them popular by not having them.

(25)

The λ-Calculus What is the λ-Calculus?

What is the λ-Calculus?

A Brief, Incomplete, and Mostly Wrong History of Programming Languages

1936 Alonzo Church also invents every language that will ever be but does it better. His lambda calculus is ignored because it is insufficiently C-like. This criticism occurs in spite of the fact that C has not yet been invented.

1970 . . . Lambdas are relegated to relative obscurity until Java makes them popular by not having them.

(26)

The λ-Calculus What is the λ-Calculus?

What is the λ-Calculus?

A Brief, Incomplete, and Mostly Wrong History of Programming Languages

1936 Alonzo Church also invents every language that will ever be but does it better. His lambda calculus is ignored because it is insufficiently C-like. This criticism occurs in spite of the fact that C has not yet been invented.

1970 . . . Lambdas are relegated to relative obscurity until Java makes them popular by not having them.

(27)

The λ-Calculus Definition of the λ-Calculus

Definition of the λ-Calculus

A term t in the λ-Calculus is one of three things:

x A variable.

λ x . t The abstraction of a variable x from a term. t t The application of one term to another. Also use parentheses for grouping.

(28)

The λ-Calculus Definition of the λ-Calculus

Definition of the λ-Calculus

A term t in the λ-Calculus is one of three things:

x A variable.

λ x . t The abstraction of a variable x from a term. t t The application of one term to another. Also use parentheses for grouping.

(29)

The λ-Calculus Definition of the λ-Calculus

Definition of the λ-Calculus

A term t in the λ-Calculus is one of three things:

x A variable.

λ x . t The abstraction of a variable x from a term.

t t The application of one term to another. Also use parentheses for grouping.

(30)

The λ-Calculus Definition of the λ-Calculus

Definition of the λ-Calculus

A term t in the λ-Calculus is one of three things:

x A variable.

λ x . t The abstraction of a variable x from a term.

t t The application of one term to another.

Also use parentheses for grouping.

(31)

The λ-Calculus Definition of the λ-Calculus

Definition of the λ-Calculus

A term t in the λ-Calculus is one of three things:

x A variable.

λ x . t The abstraction of a variable x from a term.

t t The application of one term to another.

Also use parentheses for grouping.

(32)

The λ-Calculus Definition of the λ-Calculus

Definition of the λ-Calculus

Functions are:

Anonymous Unary Higher-order Recursive

Left-associative: abc = (ab)c Extend as far right as possible

(33)

The λ-Calculus Definition of the λ-Calculus

Definition of the λ-Calculus

Functions are:

Anonymous

Unary Higher-order Recursive

Left-associative: abc = (ab)c Extend as far right as possible

(34)

The λ-Calculus Definition of the λ-Calculus

Definition of the λ-Calculus

Functions are:

Anonymous Unary

Higher-order Recursive

Left-associative: abc = (ab)c Extend as far right as possible

(35)

The λ-Calculus Definition of the λ-Calculus

Definition of the λ-Calculus

Functions are:

Anonymous Unary Higher-order

Recursive

Left-associative: abc = (ab)c Extend as far right as possible

(36)

The λ-Calculus Definition of the λ-Calculus

Definition of the λ-Calculus

Functions are:

Anonymous Unary Higher-order Recursive

Left-associative: abc = (ab)c Extend as far right as possible

(37)

The λ-Calculus Definition of the λ-Calculus

Definition of the λ-Calculus

Functions are:

Anonymous Unary Higher-order Recursive

Left-associative: abc = (ab)c

Extend as far right as possible

(38)

The λ-Calculus Definition of the λ-Calculus

Definition of the λ-Calculus

Functions are:

Anonymous Unary Higher-order Recursive

Left-associative: abc = (ab)c Extend as far right as possible

(39)

The λ-Calculus Informal Examples

Informal Examples

Identity function:

λ x . x Mathematics:

(λ x . x + 2) 3 Multiple arguments:

λ x . λ y . x + y Factorials:

g = λ f . λ n.

(1 n = 0

n × f (n − 1) n > 0 Y = λ h. (λ x . h (x x )) (λ x . h (x x )) fact = λ n. Y g n

(40)

The λ-Calculus Informal Examples

Informal Examples

Identity function:

λ x . x

Mathematics:

(λ x . x + 2) 3 Multiple arguments:

λ x . λ y . x + y Factorials:

g = λ f . λ n.

(1 n = 0

n × f (n − 1) n > 0 Y = λ h. (λ x . h (x x )) (λ x . h (x x )) fact = λ n. Y g n

(41)

The λ-Calculus Informal Examples

Informal Examples

Identity function:

λ x . x Mathematics:

(λ x . x + 2) 3

Multiple arguments:

λ x . λ y . x + y Factorials:

g = λ f . λ n.

(1 n = 0

n × f (n − 1) n > 0 Y = λ h. (λ x . h (x x )) (λ x . h (x x )) fact = λ n. Y g n

(42)

The λ-Calculus Informal Examples

Informal Examples

Identity function:

λ x . x Mathematics:

(λ x . x + 2) 3 Multiple arguments:

λ x . λ y . x + y

Factorials:

g = λ f . λ n.

(1 n = 0

n × f (n − 1) n > 0 Y = λ h. (λ x . h (x x )) (λ x . h (x x )) fact = λ n. Y g n

(43)

The λ-Calculus Informal Examples

Informal Examples

Identity function:

λ x . x Mathematics:

(λ x . x + 2) 3 Multiple arguments:

λ x . λ y . x + y Factorials:

g = λ f . λ n.

(1 n = 0

n × f (n − 1) n > 0

(44)

The λ-Calculus Usage of the λ-Calculus

Usage of the λ-Calculus

Usage of the λ-Calculus in programming languages:

Functional Languages Based on the λ-Calculus, treat computation as the evaluation of mathematical functions and typically avoids state and mutable data.

LISP family Lisp is the second oldest programming language after FORTRAN; loosely based on the λ-Calculus but technically classed as multi-paradigm.

Anonymous Functions Found in many other languages: C#, C++Ox, Matlab, etc.

(45)

The λ-Calculus Usage of the λ-Calculus

Usage of the λ-Calculus

Usage of the λ-Calculus in programming languages:

Functional Languages Based on the λ-Calculus, treat computation as the evaluation of mathematical functions and typically avoids state and mutable data.

LISP family Lisp is the second oldest programming language after FORTRAN; loosely based on the λ-Calculus but technically classed as multi-paradigm.

Anonymous Functions Found in many other languages: C#, C++Ox, Matlab, etc.

(46)

The λ-Calculus Usage of the λ-Calculus

Usage of the λ-Calculus

Usage of the λ-Calculus in programming languages:

Functional Languages Based on the λ-Calculus, treat computation as the evaluation of mathematical functions and typically avoids state and mutable data.

LISP family Lisp is the second oldest programming language after FORTRAN; loosely based on the λ-Calculus but technically classed as multi-paradigm.

Anonymous Functions Found in many other languages: C#, C++Ox, Matlab, etc.

(47)

The λ-Calculus Usage of the λ-Calculus

Usage of the λ-Calculus

Usage of the λ-Calculus in programming languages:

Functional Languages Based on the λ-Calculus, treat computation as the evaluation of mathematical functions and typically avoids state and mutable data.

LISP family Lisp is the second oldest programming language after FORTRAN; loosely based on the λ-Calculus but technically classed as multi-paradigm.

Anonymous Functions Found in many other languages: C#, C++Ox, Matlab, etc.

(48)

Church Encoding

Church Encoding

4 Church Encoding

What is Church Encoding?

Church Numerals Peano Arithmetic

Isomorphism between Church and Peano

Other operations on Church Numerals

Other Church Encodings

(49)

Church Encoding What is Church Encoding?

What is Church Encoding?

Definition (Church Encoding)

A means of embedding data and operations on them by using the λ-Calculus.

Encodings are available for: Natural numbers Booleans

Pairs Lists

(50)

Church Encoding What is Church Encoding?

What is Church Encoding?

Definition (Church Encoding)

A means of embedding data and operations on them by using the λ-Calculus.

Encodings are available for: Natural numbers Booleans

Pairs Lists

(51)

Church Encoding What is Church Encoding?

What is Church Encoding?

Definition (Church Encoding)

A means of embedding data and operations on them by using the λ-Calculus.

Encodings are available for:

Natural numbers Booleans

Pairs Lists

(52)

Church Encoding What is Church Encoding?

What is Church Encoding?

Definition (Church Encoding)

A means of embedding data and operations on them by using the λ-Calculus.

Encodings are available for:

Natural numbers

Booleans Pairs Lists

(53)

Church Encoding What is Church Encoding?

What is Church Encoding?

Definition (Church Encoding)

A means of embedding data and operations on them by using the λ-Calculus.

Encodings are available for:

Natural numbers Booleans

Pairs Lists

(54)

Church Encoding What is Church Encoding?

What is Church Encoding?

Definition (Church Encoding)

A means of embedding data and operations on them by using the λ-Calculus.

Encodings are available for:

Natural numbers Booleans

Pairs

Lists

(55)

Church Encoding What is Church Encoding?

What is Church Encoding?

Definition (Church Encoding)

A means of embedding data and operations on them by using the λ-Calculus.

Encodings are available for:

Natural numbers Booleans

Pairs Lists

(56)

Church Encoding Church Numerals

Church Numerals

Devised by Alonzo Church in 1941 to represent natural numbers:

Church Numerals

0 ≡ λ f . λ x . x 1 ≡ λ f . λ x . f x 2 ≡ λ f . λ x . f (f x ) 3 ≡ λ f . λ x . f (f (f x )) . . .

n ≡ λ f . λ x . fnx

where f0 = id, fn+1= f · fn.

(57)

Church Encoding Church Numerals

Church Numerals

Devised by Alonzo Church in 1941 to represent natural numbers:

Church Numerals

0 ≡ λ f . λ x . x 1 ≡ λ f . λ x . f x 2 ≡ λ f . λ x . f (f x ) 3 ≡ λ f . λ x . f (f (f x )) . . .

n ≡ λ f . λ x . fnx

(58)

Church Encoding Church Numerals

Church Numerals

Alternatively:

Church Numerals

0 ≡ λ f . id 1 ≡ λ f . f 2 ≡ λ f . f · f 3 ≡ λ f . f · f · f . . .

n ≡ λ f . fn

where f0 = id, fn+1= f · fn.

(59)

Church Encoding Church Numerals

Church Numerals

Alternatively:

Church Numerals

0 ≡ λ f . id 1 ≡ λ f . f 2 ≡ λ f . f · f 3 ≡ λ f . f · f · f . . .

n ≡ λ f . fn

(60)

Church Encoding Church Numerals

Church Numerals

Operations on Church Numerals (due to Rosser):

Successor function: succ n = λ f . f · n f Addition: plus m n = λ f . m f · n f

Multiplication: mult m n = m · n Exponentiation: pow m n = n m

(61)

Church Encoding Church Numerals

Church Numerals

Operations on Church Numerals (due to Rosser):

Successor function: succ n = λ f . f · n f

Addition: plus m n = λ f . m f · n f Multiplication: mult m n = m · n Exponentiation: pow m n = n m

(62)

Church Encoding Church Numerals

Church Numerals

Operations on Church Numerals (due to Rosser):

Successor function: succ n = λ f . f · n f Addition: plus m n = λ f . m f · n f

Multiplication: mult m n = m · n Exponentiation: pow m n = n m

(63)

Church Encoding Church Numerals

Church Numerals

Operations on Church Numerals (due to Rosser):

Successor function: succ n = λ f . f · n f Addition: plus m n = λ f . m f · n f

Multiplication: mult m n = m · n

Exponentiation: pow m n = n m

(64)

Church Encoding Church Numerals

Church Numerals

Operations on Church Numerals (due to Rosser):

Successor function: succ n = λ f . f · n f Addition: plus m n = λ f . m f · n f

Multiplication: mult m n = m · n Exponentiation: pow m n = n m

(65)

Church Encoding Peano Arithmetic

Peano Arithmetic

We can derive the Church Numerals from the unary representation of the natural numbers, also known as the Peano numeral system.

Definition (Peano Numbers)

d a t a Nat = Z e r o | Succ Nat one :: Nat

one = S u c c Z e r o

We can operate on Peano numbers using what is known as a fold function: Definition (Fold on Peano Numbers)

f o l d :: ( a → a ) → a → Nat → a

f o l d s u c c z e r o Z e r o = zero

f o l d s u c c z e r o ( S u c c n ) = s u c c ( f o l d s u c c z e r o n )

(66)

Church Encoding Peano Arithmetic

Peano Arithmetic

We can derive the Church Numerals from the unary representation of the natural numbers, also known as the Peano numeral system.

Definition (Peano Numbers)

d a t a Nat = Z e r o | Succ Nat one :: Nat

one = S u c c Z e r o

We can operate on Peano numbers using what is known as a fold function: Definition (Fold on Peano Numbers)

f o l d :: ( a → a ) → a → Nat → a

f o l d s u c c z e r o Z e r o = zero

f o l d s u c c z e r o ( S u c c n ) = s u c c ( f o l d s u c c z e r o n )

(67)

Church Encoding Peano Arithmetic

Peano Arithmetic

We can derive the Church Numerals from the unary representation of the natural numbers, also known as the Peano numeral system.

Definition (Peano Numbers)

d a t a Nat = Z e r o | Succ Nat one :: Nat

one = S u c c Z e r o

We can operate on Peano numbers using what is known as a fold function:

Definition (Fold on Peano Numbers)

f o l d :: ( a → a ) → a → Nat → a

f o l d s u c c z e r o Z e r o = zero

f o l d s u c c z e r o ( S u c c n ) = s u c c ( f o l d s u c c z e r o n )

(68)

Church Encoding Peano Arithmetic

Peano Arithmetic

We can derive the Church Numerals from the unary representation of the natural numbers, also known as the Peano numeral system.

Definition (Peano Numbers)

d a t a Nat = Z e r o | Succ Nat one :: Nat

one = S u c c Z e r o

We can operate on Peano numbers using what is known as a fold function:

Definition (Fold on Peano Numbers)

(69)

Church Encoding Peano Arithmetic

Peano Arithmetic

Operations on Nat

plus , mult , pow :: Nat → Nat → Nat p l u s m n = f o l d S u c c n m

m u l t m n = f o l d ( add n ) Z e r o m pow m n = f o l d ( m u l t m ) one n

(70)

Church Encoding Peano Arithmetic

Peano Arithmetic

Isomorphism between Church and Peano

We can make an isormorphism between Church Numerals and Peano Numbers:

Converting between the two

t y p e C h u r c h a = ( a → a ) → a → a nat :: C h u r c h Nat → Nat

nat c = c S u c c Z e r o

c h u r c h :: Nat → Church a

c h u r c h n = λ s u c c → λ zero → fold succ zero n

(71)

Church Encoding Peano Arithmetic

Peano Arithmetic

Isomorphism between Church and Peano

We can make an isormorphism between Church Numerals and Peano Numbers:

Converting between the two

t y p e C h u r c h a = ( a → a ) → a → a nat :: C h u r c h Nat → Nat

nat c = c S u c c Z e r o

c h u r c h :: Nat → Church a

c h u r c h n = λ s u c c → λ zero → fold succ zero n

(72)

Church Encoding Peano Arithmetic

Peano Arithmetic

Isomorphism between Church and Peano

This leads to a new formulation for operations on Church Numerals:

Successor function: succ c = λ s. λ z. s (c s z) Addition: plus m n = m succ n

Multiplication: mult m n = m (n+) 0 Exponentiation: pow m n = n (m×) 1 Completely different formulation from before!

(73)

Church Encoding Peano Arithmetic

Peano Arithmetic

Isomorphism between Church and Peano

This leads to a new formulation for operations on Church Numerals:

Successor function: succ c = λ s. λ z. s (c s z)

Addition: plus m n = m succ n

Multiplication: mult m n = m (n+) 0 Exponentiation: pow m n = n (m×) 1 Completely different formulation from before!

(74)

Church Encoding Peano Arithmetic

Peano Arithmetic

Isomorphism between Church and Peano

This leads to a new formulation for operations on Church Numerals:

Successor function: succ c = λ s. λ z. s (c s z) Addition: plus m n = m succ n

Multiplication: mult m n = m (n+) 0 Exponentiation: pow m n = n (m×) 1 Completely different formulation from before!

(75)

Church Encoding Peano Arithmetic

Peano Arithmetic

Isomorphism between Church and Peano

This leads to a new formulation for operations on Church Numerals:

Successor function: succ c = λ s. λ z. s (c s z) Addition: plus m n = m succ n

Multiplication: mult m n = m (n+) 0

Exponentiation: pow m n = n (m×) 1 Completely different formulation from before!

(76)

Church Encoding Peano Arithmetic

Peano Arithmetic

Isomorphism between Church and Peano

This leads to a new formulation for operations on Church Numerals:

Successor function: succ c = λ s. λ z. s (c s z) Addition: plus m n = m succ n

Multiplication: mult m n = m (n+) 0 Exponentiation: pow m n = n (m×) 1

Completely different formulation from before!

(77)

Church Encoding Peano Arithmetic

Peano Arithmetic

Isomorphism between Church and Peano

This leads to a new formulation for operations on Church Numerals:

Successor function: succ c = λ s. λ z. s (c s z) Addition: plus m n = m succ n

Multiplication: mult m n = m (n+) 0 Exponentiation: pow m n = n (m×) 1 Completely different formulation from before!

(78)

Church Encoding Other operations on Church Numerals

Other operations on Church Numerals

We can also define operations such as equal , pred and subtract on Church Numerals . . .

. . . but they get very messy very quickly.

(79)

Church Encoding Other operations on Church Numerals

Other operations on Church Numerals

We can also define operations such as equal , pred and subtract on Church Numerals . . .

. . . but they get very messy very quickly.

(80)

Church Encoding Other Church Encodings

Other Church Encodings

Other Church Encodings of interest:

Church Booleans:

true ≡ λ t. λ f . t false ≡ λ t. λ f . f

Church Pairs:

pair ≡ λ f . λ s. λ b. b f s fst ≡ λ p. p true snd ≡ λ p. p false

Church Lists: Too complicated to define here.

(81)

Church Encoding Other Church Encodings

Other Church Encodings

Other Church Encodings of interest:

Church Booleans:

true ≡ λ t. λ f . t false ≡ λ t. λ f . f

Church Pairs:

pair ≡ λ f . λ s. λ b. b f s fst ≡ λ p. p true snd ≡ λ p. p false

Church Lists: Too complicated to define here.

(82)

Church Encoding Other Church Encodings

Other Church Encodings

Other Church Encodings of interest:

Church Booleans:

true ≡ λ t. λ f . t false ≡ λ t. λ f . f

Church Pairs:

pair ≡ λ f . λ s. λ b. b f s fst ≡ λ p. p true snd ≡ λ p. p false

Church Lists: Too complicated to define here.

(83)

Church Encoding Other Church Encodings

Other Church Encodings

Other Church Encodings of interest:

Church Booleans:

true ≡ λ t. λ f . t false ≡ λ t. λ f . f

Church Pairs:

pair ≡ λ f . λ s. λ b. b f s fst ≡ λ p. p true snd ≡ λ p. p false

(84)

Church Encoding Representation of Church Encodings

Representation of Church Encodings

What do the different Church Encodings represent?

Church Numerals: Apply the function f on z a total of n times. Church Booleans: Selector functions (one-lineifstatement, etc.). Church Pairs: Hard-coded Church Booleans.

Church Lists: Combine elements using a combining function.

(85)

Church Encoding Representation of Church Encodings

Representation of Church Encodings

What do the different Church Encodings represent?

Church Numerals: Apply the function f on z a total of n times.

Church Booleans: Selector functions (one-lineifstatement, etc.). Church Pairs: Hard-coded Church Booleans.

Church Lists: Combine elements using a combining function.

(86)

Church Encoding Representation of Church Encodings

Representation of Church Encodings

What do the different Church Encodings represent?

Church Numerals: Apply the function f on z a total of n times.

Church Booleans: Selector functions (one-lineifstatement, etc.).

Church Pairs: Hard-coded Church Booleans.

Church Lists: Combine elements using a combining function.

(87)

Church Encoding Representation of Church Encodings

Representation of Church Encodings

What do the different Church Encodings represent?

Church Numerals: Apply the function f on z a total of n times.

Church Booleans: Selector functions (one-lineifstatement, etc.).

Church Pairs: Hard-coded Church Booleans.

Church Lists: Combine elements using a combining function.

(88)

Church Encoding Representation of Church Encodings

Representation of Church Encodings

What do the different Church Encodings represent?

Church Numerals: Apply the function f on z a total of n times.

Church Booleans: Selector functions (one-lineifstatement, etc.).

Church Pairs: Hard-coded Church Booleans.

Church Lists: Combine elements using a combining function.

(89)

Church Encoding Are Church Encodings practical?

Are Church Encodings practical?

Not really, as you’re keeping too many functions in memory . . .

But keep them in mind and try to use functions if you don’t need intermediary data.

OK, I lied: some optimizers, etc. internally use Church Encodings . . . but you should really know what you’re doing!

(90)

Church Encoding Are Church Encodings practical?

Are Church Encodings practical?

Not really, as you’re keeping too many functions in memory . . .

But keep them in mind and try to use functions if you don’t need intermediary data.

OK, I lied: some optimizers, etc. internally use Church Encodings . . . but you should really know what you’re doing!

(91)

Church Encoding Are Church Encodings practical?

Are Church Encodings practical?

Not really, as you’re keeping too many functions in memory . . .

But keep them in mind and try to use functions if you don’t need intermediary data.

OK, I lied: some optimizers, etc. internally use Church Encodings . . . but you should really know what you’re doing!

(92)

Church Encoding Are Church Encodings practical?

Are Church Encodings practical?

Not really, as you’re keeping too many functions in memory . . .

But keep them in mind and try to use functions if you don’t need intermediary data.

OK, I lied: some optimizers, etc. internally use Church Encodings . . . but you should really know what you’re doing!

(93)

Conclusion

Conclusion

Cytaty

Powiązane dokumenty

Legal culture sensu stricto is created by legal practices, legal science, and legislation.. Components of

In this paper, we give some evidence that (2) may hold for all positive integers n, by showing in Theorem 2 that the lower density of the set of all integers satisfying (2) is

We will start with a brief discussion of the Weyl correspondence and its abstract realization, leaving for later to discuss the classes of pseudo-differential operators we are going

• Finally, we will derive a general scheme of recursion using fixpoints, which captures the full power of computational recursion (also called µ-recursion). James Power, NUI

Ac- cording to Goodman [3], the boundary of the Koebe domain over ∆ consists of the images of points on the unit circle under infinite-valent functions that are called the

Department of Mathematics Department of Mathematics Government Degree College Faculty of Natural Sciences. Chaubattakhal (Pauri) Jamia Millia Islamia (Central University) Uttrakhand

, On the domain of local univalence and starlikeness in a certain class of holomorphic functions, Demonstr. , Geometric Theory of Functions of a Complex

Poza Im Z\ = Im «2=0 lub «i = «2 badany zbiór jest zwartym obszarem Jordana, który albo jest kołową soczewką albo jego brzeg jest sumą mnogościową co najwyżej