Prolog
Chap1 Basic Construct
Goal/Fact/Query
- Goal: 就像plus(0,0,0)这样的,注意后面没有?也没有.
- Fact: plus(0,0,0).
- Query: plus(0,0,0)?
A fact P. states that the goal P is true.
A query P? asks if the goal P is true.
回答一个query的过程,就是判断这个query是不是program的logical sequence. 如何判断呢?就是对最原始的program运用推导规则,最简单的推导规则是identical.
logical variable/substitution/instance
- logical variable: father(abraham, X)?中的X就是逻辑变量。这句话就是在问是否存在一个X的值使得father(abraham,X)成为program的logical sequence.
- term:
- constant和variable是term;
- compound term(或者叫structure)也是term,形如f(t1,t2,…tn);
- 一个compound term由一个functor和若干个参数(也是term)组成,functor就是上面的f,ti就是参数;
- functor是一个atom
- ground: 没有变量的term,如foo(a,b)
- nonground: 含逻辑变量的term,如foo(X)
所以term是可以嵌套的,递归的,下面是一些例子:
s(0), name(john,doe), list(a,list(b,nil)).
逻辑变量与其他语言中变量的区别:代表不确定但单一的实体,但是其他语言中代表内存位置
Definition
A substitution is finite set(possibly empty) of pairs of the form Xi=ti , where Xi is a variable and ti is a term, and Xi≠Xj if i≠j , and for any i and
example: {X=isaac}.
substitution可以被应用到term上,替换 θ