• 沒有找到結果。

Truth Assignments

N/A
N/A
Protected

Academic year: 2022

Share "Truth Assignments"

Copied!
53
0
0

加載中.... (立即查看全文)

全文

(1)

Boolean Logic

(2)

Both of us had said the very same thing.

Did we both speak the truth

—or one of us did

—or neither?

— Joseph Conrad (1857–1924), Lord Jim (1900)

(3)

Boolean Logic

a

Boolean variables: x1, x2, . . ..

Literals: xi, ¬xi.

Boolean connectives: ∨, ∧, ¬.

Boolean expressions: Boolean variables, ¬φ (negation), φ1 ∨ φ2 (disjunction), φ1 ∧ φ2 (conjunction).

n

i=1 φi stands for φ1 ∨ φ2 ∨ · · · ∨ φn.

n

i=1 φi stands for φ1 ∧ φ2 ∧ · · · ∧ φn.

Implications: φ1 ⇒ φ2 is a shorthand for ¬φ1 ∨ φ2.

Biconditionals: φ1 ⇔ φ2 is a shorthand for 1 ⇒ φ2) ∧ (φ2 ⇒ φ1).

aGeorge Boole (1815–1864) in 1847.

(4)

Truth Assignments

• A truth assignment T is a mapping from boolean variables to truth values true and false.

• A truth assignment is appropriate to boolean expression φ if it defines the truth value for every variable in φ.

{ x1 = true, x2 = false } is appropriate to x1 ∨ x2. { x2 = true, x3 = false } is not appropriate to

x1 ∨ x2.

(5)

Satisfaction

• T |= φ means boolean expression φ is true under T ; in other words, T satisfies φ.

• φ1 and φ2 are equivalent, written φ1 ≡ φ2,

if for any truth assignment T appropriate to both of them, T |= φ1 if and only if T |= φ2.

(6)

Truth Tables

• Suppose φ has n boolean variables.

• A truth table contains 2n rows.

• Each row corresponds to one truth assignment of the n variables and records the truth value of φ under it.

• A truth table can be used to prove if two boolean expressions are equivalent.

– Just check if they give identical truth values under all appropriate truth assignments.

(7)

A Truth Table

p q p ∧ q

0 0 0

0 1 0

1 0 0

1 1 1

(8)

A Second Truth Table

p q p ∨ q

0 0 0

0 1 1

1 0 1

1 1 1

(9)

A Third Truth Table

p ¬p

0 1

1 0

(10)

Proof of Equivalency by the Truth Table:

p ⇒ q ≡ ¬q ⇒ ¬p

p q p ⇒ q ¬q ⇒ ¬p

0 0 1 1

0 1 1 1

1 0 0 0

1 1 1 1

(11)

De Morgan’s Laws

a

• De Morgan’s laws state that

¬(φ1 ∧ φ2) ≡ ¬φ1 ∨ ¬φ2,

¬(φ1 ∨ φ2) ≡ ¬φ1 ∧ ¬φ2.

• Here is a proof of the first law:

φ1 φ2 ¬(φ1 ∧ φ2) ¬φ1 ∨ ¬φ2

0 0 1 1

0 1 1 1

1 0 1 1

1 1 0 0

aAugustus DeMorgan (1806–1871) or William of Ockham (1288–

(12)

Conjunctive Normal Forms

• A boolean expression φ is in conjunctive normal form (CNF) if

φ =

n i=1

Ci,

where each clause Ci is the disjunction of zero or more literals.a

– For example,

(x1 ∨ x2) ∧ (x1 ∨ ¬x2) ∧ (x2 ∨ x3).

• Convention: An empty CNF is satisfiable, but a CNF containing an empty clause is not.

aImproved by Mr. Aufbu Huang (R95922070) on October 5, 2006.

(13)

Disjunctive Normal Forms

• A boolean expression φ is in disjunctive normal form (DNF) if

φ =

n i=1

Di,

where each implicanta or simply term Di is the conjunction of zero or more literals.

– For example,

(x1 ∧ x2) ∨ (x1 ∧ ¬x2) ∨ (x2 ∧ x3).

aDi implies φ, thus the term.

(14)

Clauses and Implicants

• The 

of clauses yields a clause.

– For example,

(x1 ∨ x2) ∨ (x1 ∨ ¬x2) ∨ (x2 ∨ x3)

= x1 ∨ x2 ∨ x1 ∨ ¬x2 ∨ x2 ∨ x3.

• The 

of implicants yields an implicant.

– For example,

(x1 ∧ x2) ∧ (x1 ∧ ¬x2) ∧ (x2 ∧ x3)

= x1 ∧ x2 ∧ x1 ∧ ¬x2 ∧ x2 ∧ x3.

(15)

Any Expression φ Can Be Converted into CNFs and DNFs φ = xj:

• This is trivially true.

φ = ¬φ1 and a CNF is sought:

• Turn φ1 into a DNF.

• Apply de Morgan’s laws to make a CNF for φ.

φ = ¬φ1 and a DNF is sought:

• Turn φ1 into a CNF.

• Apply de Morgan’s laws to make a DNF for φ.

(16)

Any Expression φ Can Be Converted into CNFs and DNFs (continued)

φ = φ1 ∨ φ2 and a DNF is sought:

• Make φ1 and φ2 DNFs.

φ = φ1 ∨ φ2 and a CNF is sought:

• Turn φ1 and φ2 into CNFs,a φ1 =

n1



i=1

Ai, φ2 =

n2



j=1

Bj.

• Set

φ =

n1



i=1 n2



j=1

(Ai ∨ Bj).

aCorrected by Mr. Chun-Jie Yang (R99922150) on November 9, 2010.

(17)

Any Expression φ Can Be Converted into CNFs and DNFs (concluded)

φ = φ1 ∧ φ2 and a CNF is sought:

• Make φ1 and φ2 CNFs.

φ = φ1 ∧ φ2 and a DNF is sought:

• Turn φ1 and φ2 into DNFs, φ1 =

n1



i=1

Ai, φ2 =

n2



j=1

Bj.

• Set

φ =

n1



i=1 n2



j=1

(Ai ∧ Bj).

(18)

An Example: Turn ¬((a ∧ y) ∨ (z ∨ w)) into a DNF

¬((a ∧ y) ∨ (z ∨ w))

¬(CNF∨CNF)

= ¬(((a) ∧ (y)) ∨ ((z ∨ w)))

¬(CNF)

= ¬((a ∨ z ∨ w) ∧ (y ∨ z ∨ w))

de Morgan

= ¬(a ∨ z ∨ w) ∨ ¬(y ∨ z ∨ w)

de Morgan

= (¬a ∧ ¬z ∧ ¬w) ∨ (¬y ∧ ¬z ∧ ¬w).

(19)

Functional Completeness

• A set of logical connectives is called functionally

complete if every boolean expression is equivalent to one involving only these connectives.

• The set { ¬, ∨, ∧ } is functionally complete.

– Every boolean expression can be turned into a CNF, which involves only ¬, ∨, and ∧.

• The sets { ¬, ∨ } and { ¬, ∧ } are functionally complete.

– By the above result and de Morgan’s laws.

• { nand } and { nor } are functionally complete.a

aPeirce (c. 1880); Sheffer (1913).

(20)

Satisfiability

• A boolean expression φ is satisfiable if there is a truth assignment T appropriate to it such that T |= φ.

• φ is valid or a tautology,a written |= φ, if T |= φ for all T appropriate to φ.

aWittgenstein (1922). Wittgenstein is one of the most important philosophers of all time. Russell (1919), “The importance of ‘tautology’

for a definition of mathematics was pointed out to me by my former pupil Ludwig Wittgenstein, who was working on the problem. I do not know whether he has solved it, or even whether he is alive or dead.”

“God has arrived,” the great economist Keynes (1883–1946) said of him on January 18, 1928, “I met him on the 5:15 train.”

(21)

Satisfiability (concluded)

• φ is unsatisfiable or a contradiction if φ is false under all appropriate truth assignments.

– Or, equivalently, if ¬φ is valid (prove it).

• φ is a contingency if φ is neither a tautology nor a contradiction.

(22)

Ludwig Wittgenstein (1889–1951)

Wittgenstein (1922),

“Whereof one cannot speak, thereof one must be silent.”

(23)

satisfiability (sat)

• The length of a boolean expression is the length of the string encoding it.

• satisfiability (sat): Given a CNF φ, is it satisfiable?

• Solvable in exponential time on a TM by the truth table method.

• Solvable in polynomial time on an NTM, hence in NP (p. 117).

• A most important problem in settling the “P = NP”? problem (p. 313).

(24)

unsatisfiability (unsat or sat complement) and validity

• unsat (sat complement): Given a boolean expression φ, is it unsatisfiable?

• validity: Given a boolean expression φ, is it valid?

φ is valid if and only if ¬φ is unsatisfiable.

φ and ¬φ are basically of the same length.

– So unsat and validity have the same complexity.

• Both are solvable in exponential time on a TM by the truth table method.

(25)

Relations among sat, unsat, and validity

Contingent

Valid Unsatisfiable

• The negation of an unsatisfiable expression is a valid expression.

• None of the three problems—satisfiability,

unsatisfiability, validity—are known to be in P.

(26)

Boolean Functions

• An n-ary boolean function is a function

f : { true, false }n → { true, false }.

• It can be represented by a truth table.

• There are 22n such boolean functions.

– We can assign true or false to f for each of the 2n truth assignments.

(27)

Boolean Functions (continued)

Assignment Truth value 1 true or false 2 true or false

... ...

2n true or false

• A boolean expression expresses a boolean function.

– Think of its truth values under all possible truth assignments.

(28)

Boolean Functions (continued)

• A boolean function expresses a boolean expression.



T |= φ, literal yi is true in “row” T (y1 ∧ · · · ∧ yn).

∗ The implicant y1 ∧ · · · ∧ yn is called the minterm over { x1, . . . , xn } for T .a

– The sizeb is ≤ n2n ≤ 22n.

– This DNF is optimal for the parity function, for example.c

aSimilar to programmable logic array.

bWe count only the literals here.

cDu & Ko (2000).

(29)

Boolean Functions (continued)

x1 x2 f(x1, x2)

0 0 1

0 1 1

1 0 0

1 1 1

The corresponding boolean expression:

(¬x1 ∧ ¬x2) ∨ (¬x1 ∧ x2) ∨ (x1 ∧ x2).

(30)

Boolean Functions (concluded)

Corollary 15 Every n-ary boolean function can be expressed by a boolean expression of size O(n2n).

• In general, the exponential length in n cannot be avoided (p. 207).

• The size of the truth table is also O(n2n).a

aThere are 2n n-bit strings.

(31)

Boolean Circuits

• A boolean circuit is a graph C whose nodes are the gates.

• There are no cycles in C.

• All nodes have indegree (number of incoming edges) equal to 0, 1, or 2.

• Each gate has a sort from

{ true, false, ∨, ∧, ¬, x1, x2, . . . }.

– There are n + 5 sorts.

(32)

Boolean Circuits (concluded)

• Gates with a sort from { true, false, x1, x2, . . . } are the inputs of C and have an indegree of zero.

• The output gate(s) has no outgoing edges.

• A boolean circuit computes a boolean function.

• A boolean function can be realized by infinitely many equivalent boolean circuits.

(33)

Boolean Circuits and Expressions

• They are equivalent representations.

• One can construct one from the other:

¬ [L ¬

[L

[L ∨ [M

[L [M

[L ∧ [M

[L [M

(34)

An Example

((x1 x2 ) (x3 x4)) (x3 x4))

x1 x2 x3 x4

• Circuits are more economical because of the possibility of “sharing.”

(35)

circuit sat and circuit value

circuit sat: Given a circuit, is there a truth assignment such that the circuit outputs true?

• circuit sat ∈ NP: Guess a truth assignment and then evaluate the circuit.a

circuit value: The same as circuit sat except that the circuit has no variable gates.

• circuit value ∈ P: Evaluate the circuit from the input gates gradually towards the output gate.

aEssentially the same algorithm as the one on p. 117.

(36)

Some

a

Boolean Functions Need Exponential Circuits

b

Theorem 16 For any n ≥ 2, there is an n-ary boolean function f such that no boolean circuits with 2n/(2n) or fewer gates can compute it.

• There are 22n different n-ary boolean functions (p. 197).

• So it suffices to prove that the number of boolean circuits with 2n/(2n) or fewer gates is less than 22n.

aCan be strengthened to “Almost all.”

bRiordan & Shannon (1942); Shannon (1949).

(37)

The Proof (concluded)

• There are at most ((n + 5) × m2)m boolean circuits with m or fewer gates (see next page).

• But ((n + 5) × m2)m < 22n when m = 2n/(2n):

m log2((n + 5) × m2)

= 2n



1 log2 n+54n2 2n



< 2n for n ≥ 2.

(38)

m choices

n+5 choices

m choices

(39)

Claude Elwood Shannon (1916–2001)

Howard Gardner (1987), “[Shan- non’s master’s thesis is] possibly the most important, and also the most famous, master’s thesis of the cen- tury.”

(40)

Comments

• The lower bound 2n/(2n) is rather tight because an upper bound is n2n (p. 199).

• The proof counted the number of circuits.

– Some circuits may not be valid at all.

– Different circuits may also compute the same function.

• Both are fine because we only need an upper bound on the number of circuits.

• We do not need to consider the outgoing edges because they have been counted as incoming edges.a

aIf you prove it by considering outgoing edges, the bound will not be good. (Try it!)

(41)

Relations between Complexity Classes

(42)

It is, I own, not uncommon to be wrong in theory and right in practice.

— Edmund Burke (1729–1797), A Philosophical Enquiry into the Origin of Our Ideas of the Sublime and Beautiful (1757) The problem with QE is it works in practice, but it doesn’t work in theory.

— Ben Bernanke (2014)

(43)

Proper (Complexity) Functions

• We say that f : N → N is a proper (complexity) function if the following hold:

f is nondecreasing.

– There is a k-string TM Mf such that Mf(x) = f(| x |) for any x.a

Mf halts after O(| x | + f(| x |)) steps.

Mf uses O(f (| x |)) space besides its input x.

• Mf’s behavior depends only on | x | not x’s contents.

• Mf’s running time is bounded by f (n).

aThe textbook calls “” the quasi-blank symbol. The use of Mf(x) will become clear in Proposition 17 (p. 217).

(44)

Examples of Proper Functions

• Most “reasonable” functions are proper: c, log n , polynomials of n, 2n, √n , n!, etc.

• If f and g are proper, then so are f + g, fg, and 2g.a

• Nonproper functions when serving as the time bounds for complexity classes spoil “theory building.”

– For example, TIME(f (n)) = TIME(2f(n)) for some recursive function f (the gap theorem).b

• Only proper functions f will be used in TIME(f(n)), SPACE(f (n)), NTIME(f (n)), and NSPACE(f (n)).

aFor f (g(n)), we need to add f (n) ≥ n.

bTrakhtenbrot (1964); Borodin (1972). Theorem 7.3 on p. 145 of the textbook proves it.

(45)

Precise Turing Machines

• A TM M is precise if there are functions f and g such that for every n ∈ N, for every x of length n, and for every computation path of M ,

M halts after precisely f(n) steps, and

– All of its strings are of length precisely g(n) at halting.

∗ Recall that if M is a TM with input and output, we exclude the first and last strings.

• M can be deterministic or nondeterministic.

(46)

Precise TMs Are General

Proposition 17 Suppose a TMa M decides L within time (space) f (n), where f is proper. Then there is a precise TM M which decides L in time O(n + f (n)) (space O(f (n)), respectively).

• M on input x first simulates the TM Mf associated with the proper function f on x.

• Mf’s output, of length f (| x |), will serve as a

“yardstick” or an “alarm clock.”

aIt can be deterministic or nondeterministic.

(47)

The Proof (continued)

• Then M simulates M (x).

• M(x) halts when and only when the alarm clock runs out—even if M halts earlier.

• If f is a time bound:

– The simulation of each step of M on x is matched by advancing the cursor on the “clock” string.

– Because M stops at the moment the “clock” string is exhausted—even if M (x) stops earlier, it is precise.

– The time bound is therefore O(| x | + f(| x |)).

(48)

The Proof (concluded)

• If f is a space bound (sketch):

M simulates M on the quasi-blanks of Mf’s output string.a

– The total space, not counting the input string, is O(f(n)).

– But we still need a way to make sure there is no infinite loop.b

aThis is to make sure the space bound is precise.

bSee the proof of Theorem 24 (p. 235).

(49)

Important Complexity Classes

• We write expressions like nk to denote the union of all complexity classes, one for each value of k.

• For example,

NTIME(nk) =Δ 

j>0

NTIME(nj).

(50)

Important Complexity Classes (concluded)

P =Δ TIME(nk), NP =Δ NTIME(nk), PSPACE =Δ SPACE(nk), NPSPACE =Δ NSPACE(nk),

E =Δ TIME(2kn), EXP =Δ TIME(2nk),

L =Δ SPACE(log n), NL =Δ NSPACE(log n).

(51)

Complements of Nondeterministic Classes

• Recall that the complement of L, or ¯L, is the language Σ − L.

– sat complement is the set of unsatisfiable boolean expressions.

• R, RE, and coRE are distinct (p. 156).

– Again, coRE contains the complements of languages in RE, not languages that are not in RE.

• How about coC when C is a complexity class?

(52)

The Co-Classes

• For any complexity class C, coC denotes the class { L : ¯L ∈ C }.

• Clearly, if C is a deterministic time or space complexity class, then C = coC.

– They are said to be closed under complement.

– A deterministic TM deciding L can be converted to one that decides ¯L within the same time or space bound by reversing the “yes” and “no” states.a

• Whether nondeterministic classes for time are closed under complement is not known (see p. 109).

aSee p. 153.

(53)

Comments

• As

coC = { L : ¯L ∈ C }, L ∈ C if and only if ¯L ∈ coC.

• But it is not true that L ∈ C if and only if L ∈ coC.

– coC is not defined as ¯C.

• For example, suppose C = {{ 2, 4, 6, 8, 10, . . . }, . . . }.

• Then coC = {{ 1, 3, 5, 7, 9, . . . }, . . . }.

• But ¯C = 2{ 1,2,3,... } − {{ 2, 4, 6, 8, 10, . . . }, . . . }.

參考文獻

相關文件

[r]

The PROM is a combinational programmable logic device (PLD) – an integrated circuit with programmable gates divided into an AND array and an OR array to provide an

The design of a sequential circuit with flip-flops other than the D type flip-flop is complicated by the fact that the input equations for the circuit must be derived indirectly

Graph Algorithms Euler Circuit Hamilton Circuit.. for Sprout 2014 by Chin

Graph Algorithms Euler Circuit Hamilton Circuit.. for Sprout 2014 by Chin

„ There is no Hamilton circuit in G2 (this can be seen by nothing that any circuit containing every vertex must contain the edge {a,b} twice), but G2 does have a Hamilton

 If SAT can be solved in deterministic polynomial time, then so can any NP problems  SAT ∈ NP-hard..  If A is an NP-hard problem and B can be reduced from A, then B is an

• If we know how to generate a solution, we can solve the corresponding decision problem. – If you can find a satisfying truth assignment efficiently, then sat is