MIEC CS172(Prolog)

本文介绍了Prolog编程中的事实、规则、查询以及知识库的概念,包括如何表达并列、复杂术语、不同谓词的参数数量,以及逻辑推理、真值表、有效推论、逻辑等价和集合操作。后续章节探讨了逻辑表达的转换和标准形式,如DNF和CNF,以及图书馆和集合操作的应用。
摘要由CSDN通过智能技术生成

Chapter 1 and 2

Fact

Facts: Facts are statements that areassumed to be true.
The dot ‘.’ character must come at the end of a fact.
Example: We want to tell “John likes Mary” : English interpretation
The standard form of fact in Prolog Likes (john, mary).

Rules

Rules: Rules are logical statements that describe the relationships between different facts.
在这里插入图片描述

Queries

Queries: That is, this query essentially asks something to Prolog:
在这里插入图片描述

Knowledge base 1 (example)

The facts and rules contained in a knowledge base are called clauses.
The end of a clause is marked with a full stop.
在这里插入图片描述

Expressing Conjunction

在这里插入图片描述
The comma “,” expresses conjunction (and) in Prolog
So, this rule says: ``Vincent plays air guitar if he listens to music and he is happy
在这里插入图片描述

Knowledge base 5

KB5 contains four facts about the loves relation and one rule.
在这里插入图片描述

Prolog terms

在这里插入图片描述

Variable

在这里插入图片描述
“;” means “or” here , so this query means: are there any more women?

Atoms

在这里插入图片描述

complex terms

在这里插入图片描述

Arity(参数数量)

We can define two predicates with the same functor but with different arityProlog would treat this as two different predicates!
In Prolog documentation, arity of a predicate is usually indicated with the suffix “/” followed by a number to indicate the arity
for example:
在这里插入图片描述

Chapter 3 and 4

Truth table

在这里插入图片描述

Valuations

In propositional logic, a valuation corresponds to a single rowin the truth table.
在这里插入图片描述

Valid Inference

The inference from a finite set of premises p1, p2. . . pn-1, pn, to a conclusion q is a valid inference if for each valuation V with V(p1) = . . . = V(pn) = 1, also has that V(q) = 1.
在这里插入图片描述
在这里插入图片描述
Some famous valid inference:

  1. Modus Ponens: the way that affirms.
    (p → q), p |= q.
  2. Modus Tollens: the way that denies.
    (p → q), ¬q |= ¬p.
More commonly used logical laws

在这里插入图片描述

Logical equivalence

在这里插入图片描述

在这里插入图片描述

  • example
  • 第二个用到上面的lagical laws在这里插入图片描述

Chapter5

操作符之间的转换

  • (p ↔q) is equivalence t o (p → q) ∧(q → p).
  • (p → q ) is equivalence t o (¬p ∨q)
  • (p ∧q ) is equivalence t o ¬(¬p ∨¬q)
  • (p ∨q ) is equivalence to ¬(¬p ∧¬q)

a new operator (NAND)

   **p | q ↔¬(p ∧q).**

在这里插入图片描述

Canonical Normal Forms

DNF(Disjunctive Normal Form)

在这里插入图片描述

CNF(Conjunctive Normal Form)

在这里插入图片描述

Chapter6

Library

在这里插入图片描述

sets
  • definition:‘A set is a collection of definite objects or numbers.”
  • what can we do with sets?
  1. we can ask :" is x an element in the set of S?"
  2. we can’t ask:
    Where is x in S (at the front, back, top, …)
    How many times does x occur in S,…
  • the way to define Set

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
点后是返回值
Comparing of sets:
在这里插入图片描述
在这里插入图片描述
Some examples:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值