- 3.3 一阶逻辑语言总结
3.3 一阶逻辑语言总结
我们将借此机会重新表述前面的命题逻辑的语法规则,并添加量词的形式化规则;所有这些一起组成一阶逻辑的句法。此外,我们会明确相关表达式的类型。我们将采取约定:〈e<sup>n</sup>, t〉一种由 n 个类型为 e 的参数组成产生一个类型为 t 的表达式的谓词的类型。在这种情况下,我们说 n 是谓词的元数。
- If P is a predicate of type 〈e<sup>n</sup>, t〉, and α<sub>1</sub>, … α<sub>n</sub> are terms of type e, then P(α<sub>1</sub>, … α<sub>n</sub>) is of type t.
- If α and β are both of type e, then (α = β) and (α != β) are of type t.
- If φ is of type t, then so is
-φ.- If φ and ψ are of type t, then so are (φ
&ψ), (φ|ψ), (φ->ψ) and (φ<->ψ).- If φ is of type t, and x is a variable of type e, then
exists x.φ andall x.φ are of type t.
3.1总结了logic模块的新的逻辑常量,以及Expression模块的两个方法。
表 3.1:
一阶逻辑所需的新的逻辑关系和运算符总结,以及Expression类的两个有用的方法。
>>> dom = {'b', 'o', 'c'}
我们使用工具函数Valuation.fromstring()将 symbol => value 形式的字符串序列转换成一个Valuation对象。
>>> v = """... bertie => b... olive => o... cyril => c... boy => {b}... girl => {o}... dog => {c}... walk => {o, c}... see => {(b, o), (c, b), (o, c)}... """>>> val = nltk.Valuation.fromstring(v)>>> print(val){'bertie': 'b','boy': {('b',)},'cyril': 'c','dog': {('c',)},'girl': {('o',)},'olive': 'o','see': {('o', 'c'), ('c', 'b'), ('b', 'o')},'walk': {('c',), ('o',)}}
根据这一估值,see的值是一个元组的集合,包含 Bertie 看到 Olive、Cyril 看到 Bertie 和 Olive 看到 Cyril。
注意
轮到你来:模仿1.2绘制一个图,描述域m和相应的每个一元谓词的集合。
你可能已经注意到,我们的一元谓词(即boy,girl,dog)也是以单个元组的集合而不是个体的集合出现的。这使我们能够方便的统一处理任何元数的关系。一个形式为 P(τ<sub>1</sub>, … τ<sub>n</sub>)的谓词,其中 P 是 n 元的,为真的条件是对应于(τ<sub>1</sub>, … τ<sub>n</sub>) 的值的元组属于 P 的值的元组的集合。
>>> ('o', 'c') in val['see']True>>> ('b',) in val['boy']True
