[人工智能-logic agent]Propositional Logic& First order Logic
Propositional Logic
一些术语
Knowledge Base(KB):已经确认为真的事情,可以理解为解题时的题目条件
world:真值表里的每一行都是一个world

entailment:区别于imply,虽然和imply有相同的真值表,但是entails表示对于任何model,(A entails B)如果A正确那么B也正确。而imply仅仅只对一个model而言
sound algorithm and complete algorithm
An algorithm is sound if, anytime it returns an answer, that answer is true. An algorithm is complete if it guarantees to return a correct answer for any arbitrary input
两种证明方式

伪代码
function PL-TRUE?(a,model) returns true or false
if a is a symbol then return Lookup(a, model)
if Op(a) = ¬ then return not(PL-TRUE?(Arg1(a),model))
if Op(a) = Ù then return and(PL-TRUE?(Arg1(a),model),
PL-TRUE?(Arg2(a),model))
etc.
构建expression
def sentence1():
"""Returns a Expr instance that encodes that the following expressions are all true.
A or B
(not A) if and only if ((not B) or C)
(not A) or (not B) or C
"""
A = Expr('A')
B = Expr('B')
C = Expr('C')
a_or_b = A | B
not_b_or_c = ~B | C
second = ~A % not_b_or_c
third = disjoin(~A,~B,C)
return conjoin(a_or_b, second, third)
CNF(合取范式)
形如 ( or )and ( or )
In Boolean logic, a formula is in conjunctive normal form (CNF)
or clausal normal form if it is a conjunction of one or
more clauses, where a clause is a disjunction of literals;
otherwise put, it is a product of sums or an AND of ORs.
REFERENCE:https://en.wikipedia.org/wiki/Conjunctive_normal_form
e.g.
A
A OR B
(A OR B) AND (C OR D)
CNF与正常人的想法有一些不同,我们平时思考用的是DNF,就是把各种情况枚举出来,但是实际上要将DNF转化成CNF还是很容易的
DNF 转 CNF 技巧
我们考虑否命题,列出所有情况,再取逆,注意到 NOT (A OR B) = (NOT A AND NOT B),把NOT放进去这样就直接转成CNF了
SAT solver
DPLL算法
1.early termination
如果所有clause都可以被满足或者任意一个clause不可以被满足则结束返回
2.pure literals
如果在所有未被满足的clause内,某一个symbol的sign相同,那么将能使剩余clause为True的值赋给那个symbol
3. unit clause
如果某个clause只剩下一个literal没有被赋值,那么将这个对应的symbol赋值是的该clause为True
e.g. 如果A为False,那么(A or B)and (A or not C) 变为 (B)and (not C)那么B和C 就可以直接赋值{B:T,C:F}
伪代码
function DPLL(clauses,symbols,model) returns true or false
if every clause in clauses is true in model then return true
if some clause in clauses is false in model then return false
P,value ←FIND-PURE-SYMBOL(symbols,clauses,model)
if P is non-null then return DPLL(clauses, symbols–P, model∪{
P=value})
P,value ←FIND-UNIT-CLAUSE(clauses,model)
if P is non-null then return DPLL(clauses, symbols–P, model∪{
P=value})
P ← First(symbols); rest ← Rest(symbols)
return or(DPLL(clauses,rest,model∪{
P=true})

本文深入探讨了命题逻辑和第一阶逻辑,包括知识库、模型、蕴含和合取范式(CNF)的概念。介绍了两种证明方法、DPLL算法以及SAT求解器的工作原理。同时,展示了如何构建和转换逻辑表达式,并通过具体的伪代码解释了算法的执行流程。此外,文章还讨论了在迷宫问题中应用逻辑代理进行路径规划的方法。
最低0.47元/天 解锁文章
1544

被折叠的 条评论
为什么被折叠?



