610 likes | 786 Views
逻辑. 三个逻辑学家走进酒吧,侍者问:“每个人都要来杯啤酒吗?”第一个逻辑学家说:“我不知道。”第二个说:“我也不知道。”第三个说:“是的!”. 信息系一共就三个班。今天他对我说,你是 3 班的么?我说,原来你是 2 班的啊!他说,原来你是 1 班啊!. 能否设计一套推理系统,判断所有命题? 能否有一门计算机语言,能够描述自身?. 布尔逻辑. 常量:真,假 运算: n 元组到常量的映射 -a= 真 a*b= 真 a*b*c…= 假. 一元运算 相当于 布尔常量到布尔常量的映射 可以理解为一种二元关系。 例如: Not. Not in ES.
E N D
三个逻辑学家走进酒吧,侍者问:“每个人都要来杯啤酒吗?”第一个逻辑学家说:“我不知道。”第二个说:“我也不知道。”第三个说:“是的!”
信息系一共就三个班。今天他对我说,你是3班的么?我说,原来你是2班的啊!他说,原来你是1班啊!信息系一共就三个班。今天他对我说,你是3班的么?我说,原来你是2班的啊!他说,原来你是1班啊!
能否设计一套推理系统,判断所有命题? • 能否有一门计算机语言,能够描述自身?
常量:真,假 • 运算:n元组到常量的映射 • -a=真 • a*b=真 • a*b*c…=假
一元运算 • 相当于 布尔常量到布尔常量的映射 • 可以理解为一种二元关系。 • 例如:Not
Not in ES • In EcmaScript • Logical not is: ! • Bitwise not is:~ alert(!1); //false alert(~1);//-2
Unary Op • 始点集合的每个元素可以指向终点集合的任意元素;每个元素有二种指法。 • 总共有2*2种二元关系 T F T F
BiOp • 二元运算 • 二元组到常量的映射 <F,F> <F,T> <T,F> <T,T> T F
总共有多少这样的二元运算?(? • 每个二元组可以有两种映射方法,总共有4个二元组, • 2^4 <F,F> <F,T> <T,F> <T,T> T F
and alert(true && false); //false //bitwise alert(3 & 2); //2 alert(-3 & -2); //?
or alert(true || false); //true //bitwise alert(-3 | -2); //?
Implication ( if |x|>1,then x>1 ) holds if |x|<=1 x>1 other wise, doesn’t hold
iif A B
People on an island understand English but speak their native language. In Da and ja, one means yes and the other no; but whether da means yes or no is unknown. • If you want to know if KadaKata is in the south, and you’re allowed to ask only one question to a person, what should you ask?
Da means yes K is in the south, right? • If da means yes and k is in the south, • Da • If da means yes and k is not in the south • Ja • If da means no and k is in the south • Da • If da means no and k is not in the south • ja
uttered True Da K is in the south Not uttered (Ja) False K is in the south Da uttered
BiOp’s • …
UnaOp represented by BiOp • 一元元算
n元运算符 • n元函数 • n+1元关系。 • 可以用二元运算表示 • F(x1,x2,…x[n])=F(x1,G(x2,…x[n]))=…
完备组 • 有一些运算可以表达成其它运算的复合 • 比如:a^b= (a||b) && ! (a&&b) • 如果有些运算可以代替所有的运算,则这些运算是完备的 • ! ,||, && • !, || • !, && In most languages such as ES/natural,…
最小完备组 • 如果完备运算组合中,去掉任何一个都不行,则称之为最小的 • ! ,||, && ? • ! ,|| ? • ! , && ?
最小完备组 • 就用一个运算符可能不可能呢? • Nor,或者Nand! • Nor: • Not a=a nor a, a& b=(a nor a) nor (b nor b) • a ||b =(a nor b) nor ( a nor b) • Nand: • Not a=a nand a, a && b=(a nand b) nand (a nand b), a || b= (a nand a) nand (b nand b)
命题逻辑 • 命题: • 陈述句,有对错。真假必居其一, 且只居其一. • 5>3 • 我正在撒谎. —— 悖论,不是命题 • 命题变量 • 有对错,但不知道 • 命题运算仿照bool逻辑
Normal Form • And Form • A and !B and (C or !D) • Or Form • A Or !B or (C and !D)
谓词逻辑 • 带变量的陈述句 • X>3 • 返回值为bool类型的函数 • Arguments 可以任意多个
First Order Logic • Predicate + Quantifier (∀,∃) • ∀x P(x) ∧ Q(x) • P:x>-1, Q x>0
Free and Bound Variables • An occurrence of variable in a sentence is free if it is not in the scope of any quantifier with the same variable. A non-free variable occurrence is bound. • ∀x P(x) ∧ Q(x) both occurrences of x bound by ∀x • (∀x P(x)) ∧ Q(x) first occurrence of x bound by ∀x, second free • ∀x (R(x, z) ∧ ∃y S(x, y)) both occurrences of x bound by ∀x, occurrence of y bound by ∃y, occurrence of z free • A sentence is open if it contains free variables; it is closed otherwise
Some Op/Func can be regarded as predicate • > • == • != • … • Many Theorems/Axioms are represented in First Order Logic alert(3>4); alert(“”==“a”);
Godel’s incomplete theorem • A System cannot be complete if consistent
Example • This sentence is not true
Application • A system cannot be complete, if consistent • A system can only upgraded from outside. • Never expect a self-evolving model • Otherwise it’s like expecting a perpetual motion machine
Never expect a system • Omni-potent
Application • A system can only be described from external, higher order language • Care must be taken to separate standard terms to the terms of the language itselfE.g., • type in C# standard and the Type instance in C# language • function in ES standard and the Function instance in ES lang. • Confusion about the two will make your head spin
Example • LiteralVar • Expression • The rules of expression • Language • Production Rules • Courses About Production Rules • Facts • Statistics • Conclusion • Proposition Logic • First Order Logic • …
Any • Some
The Halting problem • Given a program P, and input I, will the program P ever terminate? • Meaning will P(I) loop forever or halt? • Can a computer program determine this? • Can a human? • First shown by Alan Turing in 1936 • Before digital computers existed!