Logic and Models in Computer Science Neil D. Jones August 22, 2006
1
Logic
An excellent introduction to logic may be found in [1], a book that is addressed to Computer Scientists. It doesn’t cover too much, but does well and precisely what it does. Further, [1] is oriented towards “model-ch “model-checki ecking”, ng”, an increas increasingly ingly important interface between systems practice and mathematical logic. Model-checking is now increasingly used for verification and debugging of software. wa re. The cov cover er of the book’s first edit edition ion sho shows ws the lau launc nch h of (I thin think) k) Ariane 5. 1 This launch was an expensive failure caused by a software error. Overall, logic is concerned with what we can write in a formal language and the relation between what is written and what actually holds true in a concrete model. Logic concerns relations between a syntactic world of of logical formulas, and a world of formulas are interpreted. The connection mathematical mathematic al meanings meanings , over which such formulas between syntax (what is written) and its meanings (what is expressed) is traditionally called the field of semantics semantics . The central oval concerns mathematical concepts (e.g., F = ma,e = mc2 ) of equality, truth, falsity, etc. that are precisely defined and “live in their own world”.
A disclaimer The ter The term m “m “mode odel” l” has mul ulti tipl plee me meani anings ngs.. As the ter term m is used in logi logic, c, mod model el-checking, etc. it has little to do with modeling as known in the physical sciences. Models as in mathematics, engineering, logic and model-checking. The rightmost oval in Figure 1 concerns logical notations as manipulated by humans and computers. From this viewpoint modeling has has to do with this relation: between what is written and what is mathematically true or false (in the central oval). Thee wo Th work rk of com comput puter er scie scient ntis ists ts and eng engin ineer eerss is synthetic , con concer cerne ned d with with constructing complex but self-defined mathematical systems, and determining (by design des ign)) thei theirr prope propertie rties. s. From this perspecti perspective ve experime experiment ntal al mea measure suremen mentt of an already alr eady-co -constr nstructe ucted d sys system tem is usef useful ul onl only y for debuggi debugging: ng: to see whether whether the constructed system in fact has the properties that its designers intended it to have. Limitations in the designers’ accomplishments arise if their mathematical models, els, e. e.g. g.,, com comput puter er pro progra grams ms,, do not not beh behav avee as the des desig igne ners rs inte intende nded d the them m to 1
The implication is that the bug might have been caught if the control program had been formally checked by computer.
1
Engineering
“model”
The real world
in the
sense of science
World of models, meanings
M
“model” in the
sense of logic
|=
World of logical formulas φ
Figure 1: Two different views on modeling. behave. Such limitations indicate a need to change an implementation by hardware or software, but are not problems with the “real world”. Relations ns betw between een the cen center ter and the righ righttModels as in the natural sciences. Relatio most oval oval concern the natural science sciences. s. In contrast to mathematics, logic etc., the natural sciences sciences are analytical , concerned with finding out what is “out there” in the real physical world. The leftmost arrow is also often called a “model”, but this concerns an attempt to find mathematical properties of the real world and so is quite different from the models on the right. Such a model of the real world is always a hypothesis that that may or may not hold in the long run. For a noteworthy example, Newton’s “laws” were a good model of the real world, but not necessary properties. properties. Still, they survi survived ved long (and still do) since they were sufficiently precise for daily use, until new sets of “laws” were developed with still greater ability to explain observations made by physicists and astronomers, and to predict the outcome of future experiments. Limitations in a model of this sort arise if the model has poor predictive or explanatory power. If so, the model should be changed or scrapped. possibili ility ty of engi engineer neering ing,, comp computer uter and Relations to engin Relations engineerin eering. g. The very possib circui cir cuitt cons construc tructio tion, n, etc. depen depends ds on we wellll-unde understood rstood proper properties ties of the ph physi ysical cal world. wo rld. On the othe otherr hand hand,, one does not need to unde understa rstand nd physi physical cal aspects suc such h as quantum mechanics, electron theory, etc. in order to understand what a circuit accomplishes. The reason is that circuits and other computing devices are carefully designed to to function according to predictable laws of logic. In this important dimension, both engineering and mathematics are synthetic rather than analytic, concerning what can be constructed rather than analysis of 2
“the world out there” as studied in the natural sciences.
1.1 1. 1
Re Rela lati tion onss of in intere terest st in in logi logicc
Two of the ovals and their interrelationships, in more detail: Meanings/models
Syn Syntax tax o off pro proposit position ional al fo form rmula ulass
φ ::= p | T | F | ¬φ | φ1 ∧ φ2 | φ1 ∨ φ2 | φ1 → φ 2 p ::= propositio propositional nal variable ariable,, e.g., A, A, B,C,P,Q, B,C,P,Q, R
Some alternate syntactical notations, commonly used for describing circuits: φ1 · φ2 is the sam samee as φ1 ∧ φ2 or φ1 φ2 samee aass φ1 ∨ φ2 φ1 + φ2 is the sam φ φ ¬ 0 iiss the the same same as as F 1 is the same as T φ1 ≡ φ 2 is the the sa same me as (φ1 → φ 2 ) ∧ (φ2 → φ 1 )
1.2.2 1.2 .2
The Boo Boolea lean n univ univers erse e of mean meaning ings, s, and som some e opera operatio tions ns on it
The Boolean universe is very simple: Bool = { 0, 1}
Following are the truth truth tables tables that define the semantic operations ¬, ∧, ∨, → on boolean values. Each is a function of type Bool → Bool or Bool 2 → Bool .
3
Operations on and relations between meanings
x ¬x
x y x∧y
x y x∨y
x y x → y
0 1
0 0 1 1
0 0 1 1
0 0 1 1
1.2.3 1.2 .3
1 0
0 1 0 1
0 0 0 1
0 1 0 1
0 1 1 1
0 1 0 1
In Inter terpre pretat tation ionss
We distinguish carefully between a Boole Boolean an formula 2 and a Boolean value . Th Ther eree are only two Boolean values, namely 0 and 1, and Bool is the set of all Boolean values. On the other hand a Boolean formula is a “piece of syntax” such as 0 ∨ (0 ∧ ¬0), i.e., a string of symbols. The value of of this formula is the Boolean value 0, the same as the value of another formula 1 ∧ (0 ∧ ¬1). If a Boolean formula φ has no variables, we will write [[ φ]] to denote its value, one of the two elements of Bool . Using the rules just given, for instance, we would expect: [[0 ∨ (0 ∧ ¬0)]] = 0 How should should we evalua evaluate te a propositio propositional nal formul formulaa that has vari variables ables in it? It seems natural, for example, that P ∨ ¬P should evaluate to 1, and that P ∧ ¬P should evaluate to 0, even if P is a Boolean va variab riable. le. But what about form formula ula P ∨ ¬Q? Answer: “it depends” on the values that variables P and Q currently have. An interpretation of of propositional formula φ is a function I : BooleanVariable → Bool
that assigns a value in Bool to every propositional variable in φ. In [[11] I is also called a “model” or an “environment” or a “look-up table.” 1.2.4
Ev Evaluat aluation ion of proposit propositional ional form formulas. ulas.
[of [φ]propositi ]I this is onal defined in the: natural way, using the interpretation l to find the values propositional variables ariables: [[T ]]I [[F ]]I [[P ]]I [[¬φ]]I [[φ1 ∧ φ2 ]]I [[φ1 ∨ φ2 ]]I [[φ1 → φ 2 ]]I
= = = = = = =
1 0 for any propositional variable P I (P ) ¬([ ([[[φ]]I ) [[φ1 ]]I ∧ [[φ2 ]]I [[φ1 ]]I ∨ [[φ2 ]]I ¬[[φ1 ]]I ∨ [[φ2 ]]I
Remarks. Thi Thiss definit definition ion uses syntactic operati operation onss to the left left,, and insi inside de the semantic brackets [[ ]]. On the right sides are their semantic counterparts. counterparts. Thus the ¬ to the left of the “=” is a symbol appearing in Boolean formulas, and the ¬ to the right of the “=” is a function on Boolean values. 2
The term “expression” is sometimes used in place of “formula”, e.g., “Boolean expression”.
4
1 1 0 1
1.2.5 1.2 .5
Som Some e prope properti rties es of pro proposi positio tional nal fo form rmula ulas. s.
Satisfaction: Propositional formula φ is said to be satisfiable if if [[φ]]I = 1 for some interpretation I for φ. For example, this formula φ = (A ∨ ¬B ) ∧ (B ∨ C ) ∧ (¬A ∨ ¬C )
is satisfiable since the interpretation (truth assignment) I = [A → 0 , B → 0 , C → 1]
causes φ to evaluate to 1, i.e., [[ φ]]I = 1. Propositional nal form formula ula φ is said to be a tautology if [[φ]]I = 1 for all Tautology: Propositio interpretations I . For example, the following formulas are tautologies: A ∨ ¬A ¬(A ∨ B ) ≡ ¬A ∧ ¬B ¬(A ∧ B ) ≡ ¬A ∨ ¬B A ∧ (B ∨ C ) ≡ ( A ∧ B ) ∨ (A ∧ C ) since all evaluate to T under any interpretation I at all.
Validity: we write φ1 , . . . , φn |= ψ
in case ψ evaluates to 1 for all interpretations l such that all of φ1 , . . . , φn evaluate to 1. Remark : φ is a tautology if and only if |= φ is true. 1. 1.2. 2.6 6
Pr Proof oof ru rule less
A set of proof rules based on “natural deduction” is found in Huth and Ryan [1]. These define a sequent relation relation between Boolean formulas: φ1 , . . . , φn ψ
Informally, we read this as “ψ is a consequence of φ1 , . . . , φn ” or “conclusion ψ follows from premises φ1 , . . . , φn ”. Examples of sequents: A ∧ B A , and A ∧ B B , and A A ∨ B . 1.2.7 1.2 .7
Sou Soundn ndness ess and com comple pleten teness ess
Completeness theorem (for theorem (for propositional logic). For any formulas φ1 , . . . , φn , ψ 1
n
1
n
φ , . . . , φ ψ if and only if φ , . . . , φ |= ψ
We omit the definition of and the proof for brevity. Still, it is worthwhile pointing out the import of this result: It asserts that there is full equivalence between 5
1. a purely syntactic notion: notion: that of prov provabilit ability y by applying the rules in a system of proof rules; and 2. a purely semantic or model-based noti notion: on: that of ev evalu aluatin atingg to equal equal value aluess under all possible interpretations 1.2. 1. 2.8 8
Co Comp mple lexi xitty
It is well-known that satisfiability is complete is complete for NP . A consequence: SAT SA T ∈ P would imply NP = P
Validity and tautology are co-NP-complete are co-NP-complete,, since an alleged counter-example may be checked in polynomial time.
References [1] M.R.A. M.R.A. Huth, M. D. Ryan. Ryan. Logic in Comput Computer er Scienc Sciencee - modelli modelling ng and reasonin reasoningg about systems (second edition), Cambridge University Press, 2004, 427 pages.