1/5/2012 Overview of Logic and Set Theory Basics Robert B. France Logic Logic is concerned with mechanized reasoning. Reasoning, as used here, involves determining the ‘truth’ of some statement (the conclusions) based on assumed ‘truths’ of other statements (the premises). Logic is used to determine whether the truth of the conclusion follows necessarily from truth of preceding statements. Logic is used to analyze the form of arguments, not to determine the merits of an argument’s content. 1
1/5/2012 Form vs Content If the program syntax is faulty (p) or if program execution results in division by 0, (q) then an error message will be generated. (r) Therefore, if the computer does not generate an error message, (not r) then the program syntax is correct (not p) and its execution does not result in division by 0. (not q) Logical Form : If p or q, then r. Therefore, if not r, then not p and not q. Propositional logic A proposition is a statement that is true or false but not both. Examples: – The Acorn reactor system is in shut ‐ down mode. – The Company A Employee file has been created. The following are not propositions: – He is a student. (truth varies depending on who “He” is) – You will be a logician at the end of this course. (same as above) 2
1/5/2012 Boolean expressions Boolean expressions are constructed from the constants true and false , boolean variables (e.g. p, q, r, s), and boolean operators (e.g. , , , ). Boolean expressions are used to represent the form of simple and compound propositions. Example: If the mixer is activated and the inlet valve is open, the reactor is working normally. p : the mixer is activated q: the inlet valve is open r : the reactor is working normally Form: (p q) r Model ‐ based semantics for propositional logic A state is an assignment of truth values (true, false) to boolean variables. The value of a boolean expression in a state is determined by truth tables . A boolean expression is satisfied in a state if its value is true in that state. A boolean expression is satisfiable if there is a state in which it is satisfied. A boolean expression is valid if it is satisfied in every state. A valid boolean expression is called a tautology. 3
1/5/2012 Identifying problems in specifications • Formalizing helps identify ambiguities: If the inlet valve is open, then the system is switched to OPEN and the outlet valve is closed if the monitoring system is functioning. Form1: invalveopen (sysfunct open outletclosed) Form2: invalveopen (open (sysfunct outletclose)) • Specifications can help frame questions: Alertstate NormalAlert practice NormalAlert MontitorTyped error1 Practice MonitorTyped error1 Q: If the system is in alert state and the operator typed in MONITOR command, would an error 1 occur? Q: What events cause an error 1? Identifying problems in specifications • Identifying inconsistencies: The system is in alert state only when it is waiting for an intruder and is on practice alert. Alert waiting practice If the system is in teaching mode and is on practice alert, then it is in alert state. The system will be in teaching mode and on practice alert and not waiting for an intruder. teaching practice alert teaching practice ~ waiting Using truth tables one can show that the above statements are contradictory. 4
1/5/2012 Formal logic systems A logic consists of • a set of symbols, • a set of formulas constructed from the symbols, • a set of distinguished formulas called axioms , and • a set of inference rules . H 1 ,H 2 ,…,H n Inference rule form: C Theorems and proofs A formula is a theorem of a logic if: • it is an axiom, or • it can be generated from the axioms and proven theorems using the inference rules. A proof that a formula is a theorem is an argument that shows how the inference rules are used to generate the formula. 5
1/5/2012 A propositional logic system Language: boolean expressions axioms: true q q ~(p q) ~p q p q ~p q … Inference rules: P=Q E[r := P] = E[r :=Q] P=Q, Q=R P = R P P[r := Q] E [r := P] means that the variable r is replaced by the expression P everywhere in the expression E . Consistency of logics A logic is useful only if it makes some distinctions among formulas. A logic is consistent if at least one of its formulas is a theorem, and at least one is not; otherwise the logic is inconsistent . A logic is sound iff every theorem is valid. A logic is complete iff every valid formula is a theorem. 6
1/5/2012 Predicate logic Propositional logic cannot be used to reason about classes of objects. For example, from the statements: All monitoring computers are ready. X12 is a monitoring computer. One cannot infer that X12 is ready. Using propositional logic. Predicate logic provides notation for expressing properties involving classes of objects such as: – Cubes of integers are never even. – Some integer is a prime number. – A student receives a grade for every course in which they enroll. Predicates, functions, and formulas A function maps objects to other objects. Example: + : N x N N The above is called the signature of a funciton. A predicate is a function that returns a true or false value. Example: : N x N boolean Predicate logic formulas include boolean expressions, and formulas of the form: • a : A • P (unrestricted universal quantifier) • a : A | R • P (restricted universal quantifier) • a : A • P (unrestricted existential quantifier) • a : A | R • P (restricted existential quantifier) 7
1/5/2012 A small example Every senior must take one maths course and pass one programming course to graduate. s : student | senior (s) • graduate (s) ( c1, c2 : course | math (c1) prog (c2) • take (s, c1) pass (s, c2)) Predicate logic system The language elements are: • individual variables (representing objects), • boolean expressions (representing propositions), • (uninterpreted) function symbols, and • (uninterpreted) predicate symbols. A theory is obtained by providing interpretations for some of the predicate and function symbols. For example, the theory of integers consists of predicate logic together with axioms characterizing integer arithmetic functions (e.g., +, ‐ , *, , ). 8
1/5/2012 Sets Typed sets: elements in a set must be of the same kind, i.e., elements must come from a previously defined set. Examples: • Set of even natural numbers: {2, 4, 6, …} • Set of cats with black fur. • Set of dogs that bark. Representing sets Two ways of representing sets: Set enumeration : explicitly give elements of set. Example: set of even numbers between 3 and 7 is {4, 6} Set comprehension : elements of set characterized by a predicate. Example set of even numbers between 3 and 7 • {n : N | n > 1 n < 4 • 2 * n } • {n : N | n 3 n 7 ( e : N • n = 2 * e)} The two forms of set comprehension are equivalent: { Declarations | Predicate • Form} {t : T | ( Declarations | Predicate • t = Form) } 9
1/5/2012 More examples {(0,{0}), (1, {1}), (2, {2})} can be written { i : ; s : | s = {i} i < 3 } { x, y, z : | z = x ‐ y } can be written {…,(0,0,0), (2,1,1), (1, ‐ 1,2),…} { n : | n 2 > 4 } can be written {3, 4, 5, 6,…} Set operations : X x X : x S is a predicate that is true iff x is a member of the set S . : X x X X : S = S1 S2 means that S is the union of sets S1 and S2 . : X x X X : S = S1 S2 means that S is the intersection of sets S1 and S2 . : X x X : S1 S2 is a predicate that is true iff S1 is a subset of (or equal to) S2 . : X x X X : S = S1 S2 means that S contains the elements of S1 that are not in S2 . 10
1/5/2012 Cardinality and power sets The cardinality of a set is the number of elements in the set. #S returns the number of elements in set S. Example: # { n : | n < 4 } = 4 S, where S is a set is the set of all subsets of S . Example: { 1, 2 } = { 0, { 1 } , { 2 } , { 1,2 }} Note: S1 S S1 S 11
Recommend
More recommend