109
离散678章选讲 张华枫 计研111 [email protected] 1

离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Embed Size (px)

Citation preview

Page 1: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

离散6、7、8章选讲

张华枫

计研111

[email protected]

1

Page 2: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

图灵机

递归函数

哥德尔不完备性定理

2

Page 3: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

图灵机背景介绍

欧几里得(Euclid)

希尔伯特(Hilbert)

图灵(Turing)

3

Page 4: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Euclid

Elements 《几何原本》4

Page 5: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

How Euclid’s ‘Elements’ work

Definitions

Postulates(公设)

Axioms(公理)

Agreed Method

Each step in the proof is an

application of one of the above.

5

Page 6: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Hilbert’s question (1900)

Is there, or could there possibly be, a definite method that could decide whether a particular mathematical expression is true?

What exactly do we mean by a definite method?

Turing’s answer - mechanical –algorithmic - the Turing machine

6

Page 7: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Theory Hall of Fame

Alan Turing

1912 – 1954

b. London, England.

PhD – Princeton (1938)

Research

Cambridge and Manchester U.

National Physical Lab, UK

Creator of the Turing Test

8

Page 8: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

More about Turing

“Breaking the Code” Movie about the personal life of Alan Turing

Death was by cyanide poisoning (some say suicide)

Turing worked as a code breaker for the Allies during WWII.

Turing eventually tried to build his machine and apply it to mathematics, code breaking, and games (chess).

Was beat to the punch by vonNeumann

9

Page 9: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

The Turing Machine

Some history

Created in response to Kurt Godel’s 1931 proof that formal mathematics was incomplete

There exists logical statements that cannot be proven by using formal deduction from a set of rules

Good Reading: “Godel, Escher, Bach” by Hofstadter

Turing set out to define a process by which it can be decided whether a given mathematical statement can be proven or not.

10

Page 10: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Theory Hall of Fame

Kurt Godel

1906 – 1978

b. Brünn, AustriaHungary

PhD – University of Vienna (1929)

Research

Princeton University

Godel’s Incompleteness Theorem

11

Page 11: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

The Turing Machine

• Motivating idea

Build a theoretical “human computer”

Likened to a human with a paper and pencil that can solve problems in an algorithmic way

The theoretical machine provides a means to determine:

If an algorithm or procedure exists for a given problem

What that algorithm or procedure looks like

How long would it take to run this algorithm or procedure.

12

Page 12: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

The Church-Turing Thesis (1936)

Any algorithmic procedure that can be carried out by a human or group of humans can be carried out by some Turing Machine

Equating algorithm with running on a TM

Turing Machine is still a valid computational model for most modern computers.

13

Page 13: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Theory Hall of Fame

Alonso Church

1903 – 1995

b. Washington D.C.

PhD – Princeton (1927)

Mathematics Prof (1927 – 1967)

Advisor to both Turing and Kleene

14

Page 14: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Turing’s Concept

A machine

With a finite set of states

Unrestricted input and output

Unlimited storage space

Simplest possible operations

01 00 1 11 1 10 0 0

Read/write head

Infinite tape

15

Page 15: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Basic operations of the machine

Read

Read the symbol on the current square

Change the inner state of the machine

Write

Change the symbol on the current square

Change the inner state of the machine

Move

Tape can move any distance left or right

01 00 1 11 1 10 0 0

Read/write head

Infinite tape

16

Page 16: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Turing Machine

A Machine consists of:

A state machine

An input tape

A movable r/w tape head

A move of a Turning Machine

Read the character on the tape at the current position of the tape head

Change the character on the tape at the current position of the tape head

Move the tape head

Change the state of the machine based on current state and character read

17

Page 17: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Turing Machine

Tape that holds character string

Movable tape head that reads and writes character

Machine that changes state based on what is read in

Input tape (input/memory)

State Machine

(program)

Read head

18

Page 18: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Turing Machine

In the original Turing Machine

In the original Turing Machine

The read tape was infinite in both directions

We describe a semi-infinite TM where

The tape is bounded on the left and infinite on the right

It can be shown that the semi-infinite TM is equivalent to the basic TM.

19

Page 19: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Turing Machine

About the input tape

Bounded to the left, infinite to the right

All cells on the tape are originally filled with a special “blank” character □

Tape head is read/write

Tape head can not move to the left of the start of the tape

If it tries, the machine “crashes”

20

Page 20: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Turing Machines

Let’s formalize this

A Turing Machine M is a 5-tuple:

M = (Q, Σ, Γ, δ, q0) where

Q = a finite set of states (assumed not to contain the halting state h)

Σ = input alphabet (strings to be used as input)

Γ = tape alphabet (chars that can be written onto the tape. Includes symbols from Σ)

Both Σ and Γ are assumed not to contain the “blank” symbol

δ = transition function

BUT WAIT, SHEN ME GUI?

21

Page 21: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

What is language?

In mathematics, computer science, and linguistics, a formal language is a set of strings of symbols that may be constrained by rules that are specific to it.

A programming language is a formal constructed language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs to control the behavior of a machine or to express algorithms.

22

Page 22: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Formal Languages

Finite Automata

Non Finite Automata

Regular Expressions

Context Free Languages

Pushdown Automata

Turing Machines

23

Page 23: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Programming Languages

24

ALGOLAdaAIMLAssemblyAutoHotkeyBASICBatchfileBCPLCC#C++COBOLCPLDDarkBASICdBASE

F#FORTRANFoxProGoGW BasicHDMLHTMLJavaJavaScriptJCLLISPLive ScriptLOGOMatlabPascalPerlPHPPick

PythonPrologQBasicRRubySGMLSmalltalkSQLTclTrue BASICVHDLVisual BasicVisual FoxProWMLWHTMLXML

Page 24: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Turing Machines

Transition function:

δ: Q x (Γ { Δ }) (Q {h}) x (G { Δ }) x {R, L, S}

Input:

Current state

Tape symbol read at current position of tape head

Output:

State in which to move the machine (can be the halting state)

Tape symbol to write at the current position of the tape head (can be the “blank” symbol)

Direction in which to move the tape head (R = right, L = left, S= stationary)

25

Page 25: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Turing Machines

Transition Function

q0 q1

X / Y, R

Symbol at current tapeHead position

Symbol to write at thecurrent head position

Direction in which to move the tape head

<q0, X> <q1, Y, R>

26

Page 26: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Let Σ = input alphabet = {0, 1}, then transition functions can be shown as a table

Current Input Output Move Next

0 0 1 - 1

0 1 - R 0

1 1 - L 1

1 0 - R Stop

27

1 0 1 00 1 …

1 1 1 00 1 …

q1

q3

δ(q1, 0) = (q3, 1, L)

Page 27: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

A more complicated transition table

Current Input Output Move Next

0 0 0 R 0

0 1 0 R 1

1 0 1 L 10

1 1 1 R 1

10 0 0 R 11

10 1 0 R 100

11 0 1 Stop 0

11 1 1 R 11

100 0 1 L 101

100 1 1 R 100

101 0 1 L 10

101 1 1 L 101

28

Page 28: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Live Demo

https://www.khanacademy.org/computer-programming/double1s/6037171975487488

29

Page 29: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

More Examples

Successor

X+Y

30

Page 30: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

31 Successor Program

Rules:

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

Let’s see how they are carried out on a piece of paper that contains the reverse binary representation of 47:

Page 31: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

32 Successor Program

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

1 1 1 1 0 1

Page 32: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

33 Successor Program

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

0 1 1 1 0 1

Page 33: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

34 Successor Program

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

0 0 1 1 0 1

Page 34: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

35 Successor Program

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

0 0 0 1 0 1

Page 35: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

36 Successor Program

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

0 0 0 0 0 1

Page 36: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

37 Successor Program

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

0 0 0 0 1 1

Page 37: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

38 Successor Program

So the successor’s output on 111101 was 000011 which is the reverse binary representation of 48.

Similarly, the successor of 127 should be 128:

Page 38: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

39 Successor Program

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

1 1 1 1 1 1 1

Page 39: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

40 Successor Program

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

0 1 1 1 1 1 1

Page 40: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

41 Successor Program

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

0 0 1 1 1 1 1

Page 41: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

42 Successor Program

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

0 0 0 1 1 1 1

Page 42: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

43 Successor Program

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

0 0 0 0 1 1 1

Page 43: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

44 Successor Program

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

0 0 0 0 0 1 1

Page 44: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

45 Successor Program

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

0 0 0 0 0 0 1

Page 45: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

46 Successor Program

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

0 0 0 0 0 0 0

Page 46: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

47 Successor Program

If read 1, write 0, go right, repeat.

If read 0, write 1, HALT!

If read □, write 1, HALT!

0 0 0 0 0 0 0 1

Page 47: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

x+y48

Page 48: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

x+y49

Page 49: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

x+y50

Page 50: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Turing Machine

Running a Turing Machine

The execution of a TM can result in 4 possible cases:

The machine “halts” (ends up in the halting state)

The machine has nowhere to go (at a state, reading a symbol where no transition is defined)

The machine “crashes” (tries to move the tape head to before the start of the tape)

The machine goes into an “infinite loop” (never halts)

51

Page 51: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Turing Machine

Accepting a string

A string x is accepted by a TM, if

Starting in the initial configuration

With x on the input tape

The machine eventually ends up in the halting state.

52

Page 52: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Turing Machine

Running a Turing Machine

The execution of a TM can result in 4 possible cases:

The machine “halts” (ACCEPT)

The machine has nowhere to go (REJECT)

The machine “crashes” (REJECT)

The machine goes into an “infinite loop” (REJECT but keeps us guessing!)

53

Page 53: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Turing Machine

Language accepted by a Turing Machine

The language accepted by a TM is the set of all input strings x on which the machine halts.

54

Page 54: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Will a Turing Machine halt?

In computability theory, the halting problemis the problem of determining, from a description of an arbitrary computer program and an input, whether the program will finish running or continue to run forever.

55

Halting Machine (HM)program + inputs

yesorno

Exist?

Page 55: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

The halting problem is not decidable.

56

Page 56: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Halting MachineInverter (HMI)

57

Halting Machine (HM)

program doneHM said yes?

count forever

program can be inputs and codes

yes

no

Page 57: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

58

Halting Machine (HM)

yesorno?

HMI

+

HMI

Yes?

Page 58: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Halting MachineInverter (HMI)

59

Halting Machine (HM)

doneHM said yes?

count forever

yes

noprogram

program can be inputs and codes

Page 59: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

60

Halting Machine (HM)

yesorno?

HMI

+

HMI

No?

Page 60: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Halting MachineInverter (HMI)

61

Halting Machine (HM)

doneHM said yes?

count forever

yes

noprogram

program can be inputs and codes

Page 61: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Pseudocode

int Halt(procedure,Input); // return yes or noint HMI(P){

if (Halt(P,P) == no){return yes;

}

else{while(1){}

}}

Halt(HMI, HMI)?

62

Page 62: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

停机问题的应用

使用类似方法构造其他不可判定问题

63

Page 63: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

是否存在确保无内存泄露的算法?

假设存在算法:boolLeakFree(Program p)

给定邪恶程序:

void Evil(p) {

int a = malloc();

if (LeakFree(p)) return;

else free(a);

}

LeakFree(Evil)产生矛盾:

如果为真,则有泄露

如果为假,则没有泄露

64

Page 64: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

判定问题(Decision Problem):回答是/否的问题

可判定问题(Decidable Problem)是一个判定问题,该问

题存在一个算法,使得对于该问题的每一个实例都能给出是/否的答案。

停机问题是不可判定问题

确定程序有无内存泄露是不可判定问题

65

Page 65: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Church论题

“凡Turing机可作的都是计算

凡Turing机可计算的就叫可计算的。”

66

Page 66: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

递归函数初探

递归函数是数论函数,即以自然数为研究对象,定义域和值域都是自然数。

可以通过把其他类型的数转化为自然数表示,从而使得递归函数可以处理。例如:

-5 -> (1, 5)

−2

5-> (1, 2, 5)

实数可以用自然数序列表示

复数可以由一对自然数序列表示

符号A、B等也可用自然数表示

67

Page 67: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Gödel编码定理:

一个非数字系统与自然数间可建立一一对应关系,从而

非数字系统的研究可归结为自然数间函数关系的研究。

68

Page 68: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

递归函数定义

递归函数是由几个初始函数出发,通过代入和递归规则来建立的。

(1)初始函数

零函数 0(x) = 0

射影函数 Imn(x1, …,xn, …, xm) = xn

后继函数 S(x) = x + 1

69

Page 69: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

(2)代入规则

Z = X * Y * Y, Y= U + V

代入 Y/U+V

得到 Z = X * (U+V)*(U+V)

70

Page 70: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

71

Page 71: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

(3)递归规则

N! = 1 if N= 0

N*(N-1)! if N > 0

其中 ! 为需要定义的函数,N是变元

72

Page 72: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

一般来说,可由函数𝛼 𝑡1, … , 𝑡𝑛

𝛽(𝑡1, … , 𝑡𝑛, 𝑡𝑛+1, 𝑡𝑛+2)

来构造新函数𝑓(𝑡1, … , 𝑡𝑛, 𝑥)

规定𝑓 𝑡1, … , 𝑡𝑛, 0 = 𝛼 𝑡1, … , 𝑡𝑛𝑓 𝑡1, … , 𝑡𝑛, 𝑠(𝑥) = 𝛽 𝑡1, … , 𝑡𝑛, 𝑥, 𝑓(𝑡1, … , 𝑡𝑛, 𝑥)

这时,称函数𝑓是由𝛼,𝛽经原始递归规则得到的

73

Page 73: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

𝛼 𝑡1, … , 𝑡𝑛𝛽(𝑡1, … , 𝑡𝑛, 𝑡𝑛+1, 𝑡𝑛+2)𝑓 𝑡1, … , 𝑡𝑛, 0 = 𝛼 𝑡1, … , 𝑡𝑛𝑓 𝑡1, … , 𝑡𝑛, 𝑠(𝑥)= 𝛽 𝑡1, … , 𝑡𝑛, 𝑥, 𝑓(𝑡1, … , 𝑡𝑛, 𝑥)表示阶乘函数

Let 𝛼() = 1, 𝛽(𝑡1, 𝑡2) = 𝑡1∗ 𝑡2, 𝑓 = !

𝑓 0 = 𝛼() = 1𝑓 𝑠(𝑥) = 𝑓 𝑥 + 1 = 𝛽 𝑥, 𝑓(𝑥) = 𝑥 ∗ 𝑓(𝑥)

74

Page 74: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

递归函数定义

由初始函数,经过有限次代入和原始(一般)递归规则所得到的函数叫做原始(一般)递归函数。

75

Page 75: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

原始递归函数举例

𝑓 𝑥, 𝑦 = 𝑥 ∗ 𝑦

可写成𝑓 𝑥, 0 = 0

𝑓 𝑥, 𝑦 + 1 = 𝑓 𝑥, 𝑦 + 𝑥

76

Page 76: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Turing可计算的函数必是递归函数

递归函数必Turing可计算的

77

Page 77: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

第七章 一阶形式理论及模型

一阶语言的理论是19世纪末20世纪初数学形式化

的产物,对计算机的发明有重要影响。一个一阶语言由字符表、形成规则、公式(按照形成规则的字符串)组成。

从形式主义角度看,它们没有任何含义,就像一部按给定规则来摆弄、拼凑字符的机器一样。

78

Page 78: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

大背景

在那个年代,希尔伯特的数学天才就像太阳的光芒一般夺目,在关于数学严格化的大纷争中希尔伯特带领的形式主义派系技压群雄,得到许多当时有名望的数学家的支持。希尔伯特希望借助于形式化的手段,抽掉数学证明中的意义,把数学证明抽象成一堆无意义的符号转换,就连我们人类赖以自豪的逻辑推导,也不过只是一堆堆符号转换而已。这样一来,一个我们日常所谓的,带有直观意义和解释的数学系统就变成了一个纯粹由无意义符号表达的、公理加上推导规则所构成的形式系统,而数学证明呢,只不过是在这个系统内玩的一个文字游戏。

79

Page 79: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

字符表

1. 个体变元 x,y,z,… 或者 x1, x2, x3 , …

2. 常项变元 a,b,c, … 或者 c1, c2,c3, …

3. 函词符号 F1, F2, …, Fn ( 函词符号集可以是一个无穷的集合)

4. 谓词符号 P1,P2,…,Pm (谓词符号集也可以是一个无穷的集合)

5. 特殊谓词 = ( 等号 )

6. 逻辑联结词 ,,,,

7. 量词 ,

8. 括号 ( , )

80

Page 80: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

形成规则

(1) 项的形成规则(i) 任一个体变元 x , 任一常项 c 都是一个项。(ii) 若 F 是一个带 k 个变目的函词,t1,t2,…,tk

是项,则F(t1,t2,…,tk)是一个项。(iii) 只有由定义 (i) ,(ii) 归纳定义得到的字符串

是项。

81

Page 81: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

(2)公式的形成规则

I. F 是一个 k 目函词, t1,t2,…,tk,tk+1是项,则F(t1,t2,…,tk)=tk+1

是一公式。

II. P 是一个 k 目谓词, t1,t2,…,tk是项, P(t1,t2,…,tk)则是一公式。

III. A, B 是公式,则~𝐀,𝐀 ∧ 𝑩, 𝑨 ∨ 𝑩, 𝑨 → 𝑩,𝑨 ↔ 𝑩是公式。

IV. A 是公式,x 是一变元,则∃𝒙𝑨, ∀𝒙𝑨是公式。

仅由 (1) - (iv) 归纳定义得到的字符串是公式。

82

Page 82: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

(3)语句的定义

公式 A 是一个语句,如果 A 中不含任何变元的自由出现。(即,A是一个命题)

(4)给定一阶语言 L , T 是一个一阶理论,如果它包括:

① 谓词演算的所有公理。

② 一个 L 中的语句组成的集合,有穷或者无穷。它们称为非逻辑公理。

③ 谓词演算的所有推理规则

83

Page 83: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

为什么是“一阶”?

变元和常项都是一阶的个体,而非个体的集合

例如 {1, 2} 和 {{}, {1}, {2}, {1,2}}的关系

84

Page 84: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

(5)定理的定义

L 中的一个语句 A 是理论 T 的一个定理,如果 A 是上面的①或 ②语句,或者是以逻辑公理或非逻辑公理为前提,使用 T 的推理规则得到的语句。

85

Page 85: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

结构、赋值及模型

给定一阶语言L,其中的函词及谓词分别为F1,F2,…,Fn;P1,P2,…,Pm

L的结构是一个数学结构M = <U,f1,f2,…,fn,R1,R2,..,Rm>,满足:

U是一个非空集合,有穷或者无穷

对应于L的每一个函词符号Fi,F是k元函词,则fi是A上的一个k元函数

对应于L的每一个谓词符号Pi , Pi 是k元谓词,则 Ri是A上的一个k元关系。

I 为 L 在结构 M 上的一个赋值

86

Page 86: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

对一阶理论T,有序对<M,I>是T的一个模型

如果对所有的T的非逻辑公理A,𝐼 𝐴 = 1,通常记为𝑀| = 𝐴。为表示𝑀在某一赋值下是𝑇的模型,我们也写成𝑀| = 𝑇

87

Page 87: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

示例,群论

𝑳𝑮的函词是𝒙 → 𝒙−𝟏和𝒙, 𝒚 → 𝒙 ⋅ 𝒚,谓词为 =

它的一阶理论𝑻𝑮包含如下公式:

∀𝒙, 𝒚, 𝒛 𝒙 𝒚𝒛 = 𝒙𝒚 𝒛

∀𝒙 𝒙 ⋅ 𝟏 = 𝟏 ⋅ 𝒙 = 𝒙

∀𝒙(𝒙 ⋅ 𝒙−𝟏 = 𝒙−𝟏 ⋅ 𝒙 = 𝟏)

𝑻𝑮的模型就是数学中常研究的各种群结构

88

Page 88: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

理论与模型的基本关系—完全性定理

定义7.3.1(语法定义)

一个理论𝑇是协调的,如果对任一语句 𝐴,𝑇 ⊢ 𝐴及𝑇 ⊢ ~𝐴不可能同时成立。

定理7.3.1 (紧致性定理)

𝑇 是协调的,当且仅当 𝑇 的任一有穷子集是协调的。

定义7.3.2(语法定义)

一个理论𝑇是协调的,如果它有一个模型𝑀,𝑀╞ 𝑇.

89

Page 89: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

定理7.3.2

一阶理论𝑇在语法上是协调的,当且仅当𝑇有一个模型。

定理7.3.3 Gödel完全性定理

𝑇是一阶理论,𝐴是任一语句,𝑇 ⊢ 𝐴当且仅当𝐴在所有𝑇的模型中都成立。

90

Page 90: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

库尔特·哥德尔(Kurt Gödel)

20世纪最伟大的数学家、逻辑学家之一

爱因斯坦语录

“我每天会去办公室,因为路上可以和哥德尔聊天”

91

Page 91: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

希尔伯特计划Hilbert’s Program 德国数学家大卫‧希尔伯特在20世纪20年代提出

背景:第三次数学危机

罗素悖论:𝑅={𝑋 | 𝑋∉𝑋},𝑅∈𝑅?

目标:提出一个形式系统,可以覆盖现在所有的数学定理,并且具有如下特点:

完备性:所有真命题都可以被证明

一致性:不可能推出矛盾,即一个命题要么是真,要么是假,不会两者都是

保守性:任何抽象域导出来的具体结论可以直接在具体域中证明

可判断性:存在一个算法来确定任意命题的真假

92

Page 92: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

哥德尔不完备定理Gödel’s Incompleteness Theorem 1931年由哥德尔证明

蕴含皮亚诺算术公里的一致系统是不完备的

皮亚诺算术公理=自然数

0是自然数

每个自然数都有一个后继

0不是任何自然数的后继

如果b,c的后继都是a,则b=c

自然数仅包含0和其任意多次后继

对任意能表示自然数的系统,一定有定理不能被证明

93

Page 93: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

哥德尔不完备定理与图灵机停机问题

主流程序语言的语法+语义=能表示自然数的形式系统

设有表达式 T 不能被证明

f(){while(T); return;} 不能判断是否会终止

94

Page 94: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Gödel不完全性定理

定理7.6.1(Gödel不完全性定理)

若一阶理论𝑍1是协调的,则存在Z的一个语句 A ,在𝑍1中 A 及A 都不可能形式证明

(这个定理的证明较为复杂,需要三个大步)

95

Page 95: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

𝑍1的公理:

课本上有,一共8条

96

Page 96: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

构造𝑍1的一个形式语句A,使用非负整数域N作为𝑍1的模型,使得A的在N中的解释为:A本身是不可证明的。

该语句及其否定,在𝑍1中都不可证明,否则产生矛盾。

97

Page 97: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

1. 给所有𝑍1中的公式编码:公式 ->编码

2. 证明对任意一个公式𝜑(𝑥),存在一个语句𝜓,使得𝜓 ↔ 𝜑( 𝜓 ),其中 𝜓 表示𝜓的编码

3. 令𝜑(𝑥)表示,¬∃𝑧 Pr(𝑧, 𝑥),有一个自由变元x,在N中的解释为“x是不可被证明的”,根据 2. 对于𝜑(𝑥)也存在一个语句𝜓,𝜓 ↔ 𝜑( 𝜓 )。从而语句𝜓就解释为:𝜓自己是不可以被证明的。

98

Page 98: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

编码

编码方案:如何操作

编码方案可以终止,即存在一个可以终止的过程使得一个公式能够变成一个非负整数

利用了递归函数的理论

可以表述:

n是L的一个符号,常项,语句,…

n是一个证明

n是语句m的一个证明Pr(n,m)

99

Page 99: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

编码第(8)条

n是一个形为A(x)的公式,只含x为自由变元,m是一个常项,c是以m置换n中的x得到的公式,即𝑐 = 𝐴(𝑐𝑚) ,其中𝑐𝑚为m所代表的常项,此关系可记为Sub(n,m)=c,这是N上的一个递归关系

公式 编码

A(x) n

𝑐𝑚 m

𝐴(𝑐𝑚) c

100

Page 100: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

引理7.6.4 对角线定理

令𝜑(𝑥)是𝑍1的语言L的任意一个公式,它的唯一一个自由变元是x,存在语句𝜓,使得𝑍1 ⊢ 𝜓 ↔ 𝜑( 𝜓 )

证明:

令 𝛽 x = 𝜑 𝑆𝑢𝑏 𝑥, 𝑥 = 𝜑 𝑥

令𝑚 = 𝛽 x and 𝜓 = 𝛽 𝑚

在 𝑍1 有𝜓 ↔ 𝛽 𝑚

↔ 𝜑 𝑆𝑢𝑏 𝑚,𝑚

↔ 𝜑(𝑆𝑢𝑏( 𝛽 x ,𝑚))↔ 𝜑( 𝛽 𝑚 )

↔ 𝜑( 𝜓 )

101

Page 101: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

基本上,第一定理的证明是通过在形式公理系统中构造如下命题 p = “此命题是不可证明的” 来完成的。

这样,它可以看成是说谎者悖论的一个现代变种。同时,它的一个弱化形式可以导出图灵机停机问题不可判定的结论。

102

Page 102: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

定理7.6.2 ( Gödel第二不完全性定理)

令 CON(Z) 表示 Z是协调的。通过编码,CON(Z) 可以表达为Z 的一个形式公式。某一 Z的语句Ψ 在 Z中不可证明。

例如:连续统假设

连续统假设(continuum hypothesis),数学上关于连续统势的假设。常记作CH。

该假设是说,无穷集合中,除了整数集的基数,实数集的基数是最小的。

103

Page 103: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

定理7.6.3(广义Gödel不完全性定理)

令 T 是任何一个理论,它的公理是归纳地给出的,同时原始递归函数在 T 中可以定义,那么, 若 T 协调,则

(1) 存在语句 A , A 及A 在 T 中都不可证。(2) CON(T)在 T 中是不可证的。

104

Page 104: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

证明论中的逻辑系统

𝜆-演算

𝜆-演算可以说是最简单、最小的一个形式系统。大约在1930年左右,由美国的逻辑学家Kleen创建。至今,在欧洲得到广泛的发展。

首先,它是函数式程序理论的基础

而后在𝜆-演算基础上发展起来的𝜋-演算、𝜒-演算,成为近年来并发程序的理论工具之一。

105

Page 105: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

𝜆-演算是函数式设计语言的基础,更接近理论

Lisp,Clojure,Scheme,…

Haskell,Scala, Elm

ML,Ocaml,F#

基于 Ocaml 的定理证明语言 Coq 在2004年给出了

四色定理(一张地图最多用四种颜色就足够)的一个证明

106

Page 106: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

图灵机和𝜆-演算的计算能力是等价的

图灵机中的停机问题在𝜆-演算中表述为:不存在一个算法能够判定任意两个lambda函数是否等价

定理 8.1.1 (不动点定理)中构造不动点(Y-combinator)的方法和Gödel不完全性定理引理7.6.4 中寻找𝜓的过程有类似的关系

107

Page 107: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

埃舍尔(M. C. Escher)的名画《瀑布》

108

Page 108: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

Y-Combinator(YC)

作为最成功的孵化器,YC成功孵化出了 Airbnb, Dropbox, OMGpop,Stripe, Heroku, Parse,SocialCam, Xobni,Reddit, Loopt,Parakey, Appjet

109

Page 109: 离散6 8选讲 图灵机 递归函数 哥德尔不完备性定理

推荐书

计算机程序的构造和解释 SCIP (Structure and Interpretation of Computer Programs)

Programming Languages and Lambda Calculi

哥德尔、艾舍尔,巴赫-集异璧之大成 ( Gödel Escher Bach)

推荐语言

函数式语言:Lisp, ML, Haskell,最近比较火爆的Scala

Scala 而今又是更加火爆了

一个链接

http://hyperpolyglot.org/里面是各种编程语言的对比,还比较有意思

110