程序验证(一):命题逻辑

   日期:2020-05-31     浏览:252    评论:0    
核心提示:程序验证(一):命题逻辑概念命题逻辑例如P∨¬Q→RP\\vee \\neg Q \\to RP∨¬Q→R一个原子(atom)是一个或为真或为假的判断。一个文字(literal)是一个原子或它的非。命题公式(propositional formulas)由文字和逻辑连接符组成。合式公式合式公式(well-formed formulas) 由以下语法得到:⟨atom⟩\\langle atom\\rangle⟨atom⟩ ::= ⊤(true)∣⊥(false)∣P,Q,...(命题变量)\\to

程序验证(一):命题逻辑

概念

命题逻辑

例如 P ∨ ¬ Q → R P\vee \neg Q \to R P¬QR

  • 一个原子(atom)是一个或为真或为假的判断。
  • 一个文字(literal)是一个原子或它的非。
  • 命题公式(propositional formulas)由文字和逻辑连接符组成。

合式公式

合式公式(well-formed formulas) 由以下语法得到:

  • a t o m \langle atom\rangle atom ::= ⊤ ( t r u e ) ∣ ⊥ ( f a l s e ) ∣ P , Q , . . . ( 命 题 变 量 ) \top (true) | \bot (false)|P,Q, ... (命题变量) (true)(false)P,Q,...()
  • l i t e r a l \langle literal\rangle literal::= a t o m \langle atom\rangle atom| ¬ \neg ¬ a t o m \langle atom\rangle atom(非)
  • f o r m u l a \langle formula\rangle formula::= l i t e r a l \langle literal\rangle literal
    | ¬ \neg ¬ f o r m u l a \langle formula\rangle formula (negation)
    | f o r m u l a \langle formula\rangle formula ∧ \wedge f o r m u l a \langle formula\rangle formula (conjunction)
    | f o r m u l a \langle formula\rangle formula ∨ \vee f o r m u l a \langle formula\rangle formula (disjunction)
    | f o r m u l a \langle formula\rangle formula → \to f o r m u l a \langle formula\rangle formula (implication)
    | f o r m u l a \langle formula\rangle formula ↔ \leftrightarrow f o r m u l a \langle formula\rangle formula (equivalence)

举例:

公式 是否为合式公式
⊤ \top
P ∧ ( Q ∨ R → P ) P\wedge (Q \vee R\to P) P(QRP)
P P P
P ⇒ Q P\Rightarrow Q PQ

语义

目的:给命题逻辑赋予涵义
把布尔值赋值给(公式,解释)对

F o r m u l a : F + I n t e r p r e t a t i o n : I = T r u t h V a l u e ( t r u e , f a l s e ) Formula: F + Interpretation: I=TruthValue(true, false) Formula:F+Interpretation:I=TruthValue(true,false)
什么是解释?
对于一个命题公式 F F F,一个解释 I I I F F F中每个命题变元映射为一个布尔值,也就是说:
I = P ↦ t r u e , Q ↦ f a l s e , R ↦ f a l s e , . . . I={P\mapsto true, Q\mapsto false, R\mapsto false,...} I=Ptrue,Qfalse,Rfalse,...
满足解释:
如果命题公式在解释 I I I下值为真,那么说 I I I F F F的满足解释(satisfying interpretation),记作:
I ⊨ F I \models F IF
不满足解释:
如果命题公式在解释 I I I下值为假,那么说 I I I F F F的不满足解释(falsifying interpretation),记作:
I ⊭ F I \not \models F IF
语义的归纳定义:
首先定义原子的涵义,然后根据这些定义,定义每个逻辑连接的涵义。
举例:
F : P ∧ Q → P ∨ ¬ Q F: P\wedge Q \to P\vee \neg Q F:PQP¬Q
I : { P ↦ t r u e , Q ↦ f a l s e } I:\{P\mapsto true,Q\mapsto false\} I:{Ptrue,Qfalse}

Step No. Step Reason
(1) I ⊨ P I\models P IP I [ P ] = t r u e I[P]=true I[P]=true
(2) I ⊭ Q I\not\models Q IQ I [ Q ] = f a l s e I[Q]=false I[Q]=false
(3) I ⊨ ¬ Q I\models\neg Q I¬Q ( 2 ) a n d ¬ (2) and \neg (2)and¬
(4) I ⊭ P ∧ Q I\not\models P\wedge Q IPQ ( 2 ) a n d ∧ (2) and \wedge (2)and
(5) I ⊨ P ∧ Q → P ∨ ¬ Q I\models P\wedge Q\to P\vee \neg Q IPQP¬Q ( 4 ) a n d → (4) and \to (4)and

可满足性与永真性

一个公式 F F F是可满足的(satisfiable)当且仅当存在一个解释 I I I使得 I ⊨ F I\models F IF
一个公式 F F F是永真的(valid)当且仅当对于所有解释 I I I I ⊨ F I\models F IF
注意:可满足性与永真性是成对的(dual)符号,即 F F F是永真的当且仅当 ¬ F \neg F ¬F是不可满足的。
如何证明可满足性?

  • 真值表穷举:蛮力搜索复杂度为 2 n 2^n 2n,其中 n n n为变元的数量
  • 演绎推理:语义讨论
  1. 假定 F F F为非永真的,即存在 I I I I ⊭ F I\not \models F IF
  2. 应用推理规则
  3. 如果每一分支都得到矛盾,那么 F F F是永真的
  4. 如果没有矛盾,且不能进一步应用推理规则,那么 F F F是非永真的

语义规则

公式

I ⊨ ¬ F I ⊭ F \frac{I\models \neg F}{I\not \models F} IFI¬F
I ⊭ ¬ F I ⊨ F \frac{I\not \models \neg F}{I\models F} IFI¬F
I ⊨ F ∧ G I ⊨ F   I ⊨ G \frac{I\models F\wedge G}{I\models F ~ I\models G} IF IGIFG
I ⊭ F ∧ G I ⊭ F ∣ I ⊭ G \frac{I\not\models F\wedge G}{I\not \models F | I\not\models G} IFIGIFG这个规则产生了分支
I ⊨ F ∨ G I ⊨ F ∣ I ⊨ G \frac{I\models F\vee G}{I\models F | I\models G} IFIGIFG
I ⊭ F ∨ G I ⊭ F   I ⊭ G \frac{I\not\models F\vee G}{I\not\models F~I\not \models G} IF IGIFG
I ⊨ F → G I ⊭ F ∣ I ⊨ G \frac{I\models F\to G}{I\not\models F | I\models G} IFIGIFG
I ⊭ F → G I ⊨ F   I ⊭ G \frac{I\not\models F\to G}{I\models F~I\not\models G} IF IGIFG
I ⊨ F ↔ G I ⊨ F ∧ G ∣ I ⊨ ¬ F ∧ ¬ G \frac{I\models F\leftrightarrow G}{I\models F\wedge G|I\models \neg F\wedge \neg G} IFGI¬F¬GIFG
I ⊭ F ↔ G I ⊨ F ∧ ¬ G ∣ I ⊨ ¬ F ∧ G \frac{I\not \models F\leftrightarrow G}{I\models F\wedge \neg G|I\models \neg F\wedge G} IF¬GI¬FGIFG

举例

  1. F : P ∧ Q F: P\wedge Q F:PQ
步骤 推理 备注
1 I ⊭ P ∧ Q I\not\models P\wedge Q IPQ assumption
2 $I\not\models P 1 and ∧ \wedge , case A
3 $I\not\models Q 1 and ∧ \wedge , case B
  1. F : P ∧ Q → P ∨ ¬ Q F: P\wedge Q \to P\vee \neg Q F:PQP¬Q
步骤 推理 备注
1 $I\not \models F assum.
2 I ⊨ P ∧ Q I\models P\wedge Q IPQ 1 and → \to
3 $I\not\models P\vee\neg Q 1 and → \to
4 $I\models P 2 and ∧ \wedge
5 I ⊭ P I\not\models P IP 3 and ∨ \vee
6 $\bot 4 and 5

发现矛盾,所以 F F F是永真的。

注意: ⇒ \Rightarrow 这样的双线箭头不属于命题逻辑的符号集。

范式(Normal Forms)

概念

一种逻辑的范式,应当:

  • 限制公式的语法(Restricts the syntax of formulas)
  • 对于此逻辑中的任意公式,范式具有等价的表达能力(Has equivalent representation for any formula in the logic)

三种主要范式

Negation Normal Form (NNF)

只包含 ∧ \wedge ∨ \vee ¬ \neg ¬三个符号,且 ¬ \neg ¬只能用于文字(literal)

Disjunctive Normal Form (DNF)

合取子句的析取

Conjunctive Normal Form (CNF)

析取子句的合取
举例:

命题 是否正确
¬ P ∧ ¬ ( P ∨ Q ) \neg P\wedge\neg(P\vee Q) ¬P¬(PQ)是NNF
¬ P ∧ ¬ Q ∨ R \neg P\wedge\neg Q\vee R ¬P¬QR是DNF
( ¬ P ∨ Q ) ∧ ( P → R ) (\neg P\vee Q)\wedge (P\to R) (¬PQ)(PR)是CNF
¬ P ∧ P \neg P\wedge P ¬PP是CNF

范式转化

由于主流的SAT solver(就是一个程序,输入一个公式,输出这个公式是否是可满足的,例子见一个简单的DPLL实现)一般接受CNF为输入,所以面对一个一般的公式,我们需要先把它转化为一个CNF。如何实现?等价的转换比较困难,但是我们可以采用一种逻辑上更弱的方法,即进行可满足性等价(equisatisfiability)转换。也就是说,我不要求转换后的CNF与原来的公式在所有的解释下真值都一样,我只要求若CNF可满足,则原公式可满足;若原公式可满足,则CNF可满足。
转换的方法,可采用Tseitin 算法.

 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
更多>相关资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服