Docsity

Cheat Sheet for Propositional Logic and Predicate logic, Cheat Sheet of Logic

Toggle sidebar
bg1
CS2742 final exam study sheet
Propositional logic:
•Propositional statement: expression that has a truth value (true/false). It is a tautology if it is always
true, contradiction if always false.
•Logic connectives: negation (“not”) ¬p, conjunction (“and”) p∧q, disjunction (“or”) p∨q, implication
p→q(equivalent to ¬p∨q), biconditional p↔q(equivalent to (p→q)∧(q→p)). The order of
precedence: ¬strongest, ∧next, ∨next, →and ↔the same, weakest.
•If p→qis an implication, then ¬q→ ¬pis its contrapositive,q→paconverse and ¬p→ ¬q
an inverse. An implication is equivalent to its contrapositive, but not to converse/inverse or their
negations. A negation of an implication p→qis p∧ ¬q(it is not an implication itself!)
•Atruth table has a line for each possible values of propositional variables (2klines if there are k
variables), and a column for each variable and subformula, up to the whole statement. The cells of
the table contain Tand Fdepending whether the (sub)formula is true for the corresponding values
of variables.
•Atruth assignment is a string of values of variables to the formula, usually a row with values of first
several columns in the truth table (number of columns = number of variables). A truth assignment
is satisfying the formula if the value of the formula on these variables is T, otherwise the truth
assignment is falsifying. A truth assignment can be encoded by a formula that is a ∧of variables
and their negations, with negated variables in places that have F in the assignment, and non-negated
that have T. For example, x=T, y =F, z =Fis encoded as (x∧ ¬y∧ ¬z).It is an encoding in a
sense that this formula is true only on this truth assignment and nowhere else.
•Two formulas are logically equivalent if they have the same truth table. The most famous example of
logically equivalent formulas is ¬(p∨q)⇐⇒ (¬p∧¬q) (with a dual version ¬(p∧q)⇐⇒ (¬p∨¬q))
where pand qcan be arbitrary (propositional, here) formulas. These pairs of logically equivalent
formulas are called DeMorgan’s law.
•There are several other important pairs of logically equivalent formulas, called logical identities or
logic laws. We will talk more about them when we talk about Boolean algebras. Here, just remember
that F∧p⇐⇒ p∧ ¬p⇐⇒ F,F∨p⇐⇒ T∧p⇐⇒ pand T∨p⇐⇒ p∨ ¬p⇐⇒ T.
•A set of logic connectives is called complete if it is possible to make a formula with any truth table
out of these connectives. For example, ¬,∧is a complete set of connectives, and so is the Sheffer’s
stroke |(where p|q⇐⇒ ¬(p∧q)), also called NAND for “not-and”. However, ∨,∧is not a complete
set of connectives because it is impossible to express a truth table with 0 when all variables are 1
with them.
•An argument consists of several formulas called premises and a final formula called a conclusion.
If we call premises A1. . . Anand conclusion B, then an argument is valid iff premises imply the
conclusion, that is, A1∧ · · · ∧ An→B. We usually write them in the following format:
Today is either Thursday or Friday
On Thursdays I have to go to a lecture
1
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Cheat Sheet for Propositional Logic and Predicate logic and more Cheat Sheet Logic in PDF only on Docsity!

CS2742 final exam study sheet

Propositional logic:

  • Propositional statement: expression that has a truth value (true/false). It is a tautology if it is always true, contradiction if always false.
  • Logic connectives: negation (“not”) ¬p, conjunction (“and”) p∧q, disjunction (“or”) p∨q, implication p → q (equivalent to ¬p ∨ q), biconditional p ↔ q (equivalent to (p → q) ∧ (q → p)). The order of precedence: ¬ strongest, ∧ next, ∨ next, → and ↔ the same, weakest.
  • If p → q is an implication, then ¬q → ¬p is its contrapositive, q → p a converse and ¬p → ¬q an inverse. An implication is equivalent to its contrapositive, but not to converse/inverse or their negations. A negation of an implication p → q is p ∧ ¬q (it is not an implication itself!)
  • A truth table has a line for each possible values of propositional variables (2k^ lines if there are k variables), and a column for each variable and subformula, up to the whole statement. The cells of the table contain T and F depending whether the (sub)formula is true for the corresponding values of variables.
  • A truth assignment is a string of values of variables to the formula, usually a row with values of first several columns in the truth table (number of columns = number of variables). A truth assignment is satisfying the formula if the value of the formula on these variables is T, otherwise the truth assignment is falsifying. A truth assignment can be encoded by a formula that is a ∧ of variables and their negations, with negated variables in places that have F in the assignment, and non-negated that have T. For example, x = T, y = F, z = F is encoded as (x ∧ ¬y ∧ ¬z).It is an encoding in a sense that this formula is true only on this truth assignment and nowhere else.
  • Two formulas are logically equivalent if they have the same truth table. The most famous example of logically equivalent formulas is ¬(p ∨ q) ⇐⇒ (¬p ∧ ¬q) (with a dual version ¬(p ∧ q) ⇐⇒ (¬p ∨ ¬q)) where p and q can be arbitrary (propositional, here) formulas. These pairs of logically equivalent formulas are called DeMorgan’s law.
  • There are several other important pairs of logically equivalent formulas, called logical identities or logic laws. We will talk more about them when we talk about Boolean algebras. Here, just remember that F ∧ p ⇐⇒ p ∧ ¬p ⇐⇒ F , F ∨ p ⇐⇒ T ∧ p ⇐⇒ p and T ∨ p ⇐⇒ p ∨ ¬p ⇐⇒ T.
  • A set of logic connectives is called complete if it is possible to make a formula with any truth table out of these connectives. For example, ¬, ∧ is a complete set of connectives, and so is the Sheffer’s stroke | (where p|q ⇐⇒ ¬(p ∧ q)), also called NAND for “not-and”. However, ∨, ∧ is not a complete set of connectives because it is impossible to express a truth table with 0 when all variables are 1 with them.
  • An argument consists of several formulas called premises and a final formula called a conclusion. If we call premises A 1... An and conclusion B, then an argument is valid iff premises imply the conclusion, that is, A 1 ∧ · · · ∧ An → B. We usually write them in the following format:

Today is either Thursday or Friday On Thursdays I have to go to a lecture

Today is not Friday (alternatively, On Friday I have to go to the lecture) —————————————————– ∴ I have to go to a lecture today

  • A valid form of argument is called rule of inference. The most prominent such rule is called modus ponens.

p → q p ————– ∴ q

  • There are several main types of proofs depending on the types of rules of inference used in the proof. The main ones are proof by contrapositive, by contradiction and by cases.
  • There are two main normal forms for the propositional formulas. One is called Conjunctive normal form (CNF) and is an ∧ of ∨ of either variables or their negations (here, by ∧ and ∨ we mean several formulas with ∧ between each pair, as in (¬x ∨ y ∨ z) ∧ (¬u ∨ y) ∧ x. A literal is a variable or its negation (x or ¬x, for example). A ∨ of (possibly more than 2) literals is called a clause, for example (¬u ∨ z ∨ x), so a CNF is true for some truth assignment whenever this assignment makes each of the clauses is true, that is, each clause has a literal that evaluates to true under this assignment.. A Disjunctive normal form (DNF) is like CNF except the roles of ∧ and ∨ are reversed. A ∧ of literals in a DNF is called a term. To construct a DNF and a CNF, start from a truth table and then for every satisfying truth assignment ∨ its encoding to a DNF, and for every falsifying truth assignment ∧ the negation of its encoding to the CNF, and apply DeMorgan’s law. This may result in a very large CNFs and DNFs, comparable to the size of the truth table itself (2number of variables). Alternatively, a CNF can be constructed from a formula by assigning a new variable vi to every connective and rewriting the formula as a conjunction of v 1 and expressions defining v′ is, each containing just two other variables, and then converting these expressions into small CNFs using truth tables. For example, a formula (x ∨ y) → (¬z) can be converted to a CNF by introducing variables v 1 and v 2 , then writing v 1 ∧ (v 1 ↔ (v 2 → ¬z)) ∧ (v 2 ↔ (x ∨ y)), then replacing each part by a CNF using truth tables.
  • A resolution proof system is used to find a contradiction in a formula (and, similarly, to prove that a formula is a tautology by finding a contradiction in its negation). Resolution starts with a formula in a CNF form, and applies the rule “from clause (C ∨ x) and clause (D ∨ ¬x) derive clause (C ∨ D) until a falsity F (equivalently, empty clause () ) is reached (so in the last step one of the clauses being resolved contains just one variable and another clause being resolved contains just that variable’s negation. Resolution can be used to check the validity of an argument by running it on the ∧ of all premises (converted, each, to a CNF) ∧ together with the negation of the conclusion.
  • Boolean functions are functions which take as argument boolean (ie, propositional) variables and return 1 or 0 (or, the convention here is 1 instead of T, and 0 instead of F). Each Boolean function on n variables can be fully described by its truth table. A size of a truth table of a function on n variables is 2n. Even though we often can have a smaller description of a function, vast majority of Boolean functions cannot be described by anything much smaller. Every Boolean function can be described by a CNF or DNF, using the above construction.

saying that there is at least one registered student, returns true if there is some student who is registered and false otherwise.

  • Reasoning in predicate logic The rule of universal instantiation says that if some property is true of everything in the domain, then it is true for any particular object in the domain. A combination of this rule with modus ponens such as what is used in the “all men are mortal, Socrates is a man ∴ Socrates is mortal” is called universal modus ponens.
  • Normal forms In a first-order formula, it is possible to rename variables under quantifiers so that they all have different names. Then, after pushing negations into the formulas under the quantifiers, the quantifier symbols can be moved to the front of a formula (making their scope the whole formula).
  • Formulas with finite domains If the domain of a formula is finite, it is possible to check its truth value using Resolution method. For that, the formula is converted into a propositional formula (grounding) by changing each ∀x quantifier with a ∧ of the formula on all possible values of x; an ∃ quantifier becomes a ∨. Then terms of the form P (value) (e.g., Even(5)) are treated as propositional variables, and resolution can be used as in the propositional case.
  • Limitations of first-order logic There are concepts that are not expressible by first-order formulas, for example, transitivity (“is there a flight from A to B with arbitrary many legs?” cannot be a database query described by a first-order formula).

Set Theory

  • A set is a well-defined collection of objects, called elements of a set. An object x belongs to set A is denoted x ∈ A (said “x in A” or “x is a member of A”). Usually for every set we consider a bigger “universe” from which its elements come (for example, for a set of even numbers, the universe can be all natural numbers). A set is often constructed using set-builder notation: A = {x inU |P (x)} where U is a universe , and P (x) is a predicate statement; this is read as “x in U such that P (x)” and denotes all elements in the universe for which P (x) holds. Alternatively, for a small set, one can list its elements in curly brackets (e.g., A = { 1 , 2 , 3 , 4 }.)
  • A set A is a subset of set B, denotedA ⊆ B, if ∀x(x ∈ A → x ∈ B). It is a proper subset if ∃x ∈ B such that x /∈ A. Otherwise, if ∀x(x ∈ A ↔ x ∈ B) two sets are equal.
  • Special sets are: empty set ∅, defined as ∀x(x /∈ ∅). Universal set U : all potential elements under consideration at given moment. A power set for a given set A, denoted 2A^ is the set of all subsets of A. If A has n elements, then 2A^ has 2n^ elements (since for every element there are two choices, either it is in, or not). A power set is always larger than the original set, even in the infinite case (use diagonalization to prove that).
  • Basic set operations are a complement A¯, denoting all elements in the universe that are not in A, then union A ∪ B= {x|x ∈ A or x ∈ B}, and intersection A ∩ B= {x|x ∈ A and x ∈ B} and set difference A − B = {x|x ∈ A and x ∈/ B}. Lastly, the Cartesian product of two sets A × B = {(a, b)|a ∈ A and b ∈ B}.
  • To prove that A ⊆ B, show that if you take an arbitrary element of A then it is always an element of B. To prove that two sets are equal, show both A ⊆ B and B ⊆ A. You can also use set-theoretic identities.

Table 1: Laws of boolean algebras, logic and sets Name Logic law Set theory law Boolean algebra law

Double Negation ¬¬p ⇐⇒ p A = A x = x DeMorgan’s laws ¬(p ∨ q) ⇐⇒ (¬p ∧ ¬q) A ∪ B = A ∩ B x + y = x · y ¬(p ∧ q) ⇐⇒ (¬p ∨ ¬q) A ∩ B = A ∪ B x · y = x + y Associativity (p ∨ q) ∨ r ⇐⇒ p ∨ (q ∨ r) (A ∪ B) ∪ C = A ∪ (B ∪ C) (x + y) + z = x + (y + z) (p ∧ q) ∧ r ⇐⇒ p ∧ (q ∧ r) (A ∩ B) ∩ C = A ∩ (B ∩ C) (x · y) · z = x · (y · z)

Commutativity p ∨ q ⇐⇒ q ∨ p A ∪ B = B ∪ A x + y = y + x p ∧ q ⇐⇒ q ∧ p A ∩ B = B ∩ A x · y = y · x

Distributivity p ∧ (q ∨ r) ⇐⇒ (p ∨ q) ∧ (p ∨ r) A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) x · (y + z) = (x · y) + (x · z) p ∨ (q ∧ r) ⇐⇒ (p ∧ q) ∨ (p ∧ r) A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) x + (y · z) = (x + y) · (x + z) Idempotence (p ∨ p) ⇐⇒ p ⇐⇒ (p ∧ p) A ∪ A = A = A ∩ A x + x = x = x · x Identity p ∨ F ⇐⇒ p ⇐⇒ p ∧ T A ∪ ∅ = A = A ∩ U x + 0 = x = x · 1 Inverse p ∨ ¬p ⇐⇒ T A ∪ A¯ = U x + ¯x = 1 p ∧ ¬p ⇐⇒ F A ∩ A¯ = ∅ x · x¯ = 0 Domination p ∨ T ⇐⇒ T A ∪ U = U x + 1 = 1 p ∧ F ⇐⇒ F A ∩ ∅ = ∅ x · 0 = 0

  • A cardinality of a set is the number of elements in it. Two sets have the same cardinality if there is a bijection between them. If the cardinality of a set is the same as the cardinality of N, the set is called countable. If it is greater, then uncountable.
  • Principle of inclusion-exclusion: The number of elements in A ∪ B, |A ∪ B| = |A| + |B| − |A ∩ B|. In general, add all odd-sized intersections and subtract all even-sized intersections.
  • Boolean algebra: A set B with three operations +, · and¯, and special elements 0 and 1 such that 0 6 = 1, and axioms of identity, complement, associativity and distributivity. Logic is a boolean algebra with F being 0, T being 1, and¯, +, · being ¬, ∨, ∧,respectively. Set theory is a boolean algebra with ∅ for 0, U for 1, and¯, ∪, ∩ for¯, +, ·. Boolean algebra is sound and complete: anything true is provable (completeness) and anything provable is true (soundness). To see that it is sound, use the fact that the axioms are true in the language of first-order logic or set theory, and the rules of inference are x = x, x = y → y = x and x = y ∧ y = z → y = z, which preserve soundness. For completeness, show that every formula in Boolean algebra can be simplified and then extended to its “normal form” DNF obtained from its truth table.

Relations and Functions

  1. A k-ary relation R is a subset of Cartesian product of k sets A 1 × · · · × Ak. We call elements of such R “k-tuples”. A binary relation is a subset of a Cartesian product of two sets, so it is a set of pairs of elements. E.g., R ⊂ { 2 , 3 , 4 }×{ 4 , 6 , 12 }, where R = {(2, 4), (2, 6), (2, 12), (3, 6), (3, 12), (4, 4), (4, 12)} is a binary relation consisting of pairs of numbers such that the first number in the pair divides the second.
  • A total function f : A → B is onto if the range of f is all of B, that is, for every element in B there is some element in A that maps to it. For example, f (x) = 2x is onto when f: N → Even, where Even is the set of all even numbers, but not onto N.
  • A total function that is both one-to-one and onto is called a bijection.
  • A function f (x) = x is called the identity function. It has the property that f −^1 (x) = f (x). A function f (x) = c for some fixed constant c (e.g., f (x) = 3) is called a constant function.
  1. Comparing set sizes Two sets A and B have the same cardinality if exists f that is a bijection from A to B. If a set has the same cardinality as N, we call it a countable set. If it has cardinality larger than the cardinality of N, we call it uncountable. If it has k elements for some k ∈ N, we call it finite, otherwise infinite (so countable and uncountable sets are infinite). E.g: N, Z, Q, Even, set of all finite strings, Java programs, or algorithms are all countable, and R, C, power set of N, are all uncountable. E.g., to show that Z is countable, we prove that there is a bijection f : Z → N:

take f (x) =

2 x x ≥ 0 1 − 2 x x < 0

. It is one-to-one because f (x) = f (y) only if x = y, and it is onto

because for any y ∈ N, if it is even then its preimage is y/2, if it is odd − y− 2 1. Often it is easier to give instead two one-to-one functions, from the first set to the second and another from the second to the third. Also, often instead of a full description of a function it is enough to show that there is an enumeration such that every element of, say, Z is mapped to a distinct element of N. To show that one finite set is smaller than another, just compare the number of elements. To show that one infinite set is smaller than another, in particular that a set is uncountable, use diagonalization: suppose that a there is an enumeration of elements of a set, say, 2N^ by elements of N. List all elements of 2N^ according to that enumeration. Now, construct a new set which is not in the enumeration by making it differ from the kth^ element of the enumeration in the kth^ place (e.g., if the second set contains element 2, then the diagonal set will not contain the element 2, and vice versa).

Foundations of mathematics

  • Zermelo-Fraenkel set theory The foundations of mathematics, that is, the axioms from which all the mathematics is derived are several axioms about sets called Zermelo-Fraenkel set theory (together with the axiom of choice abbreviated as ZFC). For example, numbers can be defined from sets as follows: 0 is ∅. 1 is {∅}. 2 is {∅, {∅}} and in general n is n − 1 ∪ {n − 1 }. ZFC is carefully constructed to explicitly disallow Russell’s paradox “if a barber shaves everybody who does not shave himself, who shaves the barber?” (in set theoretic terms, if X is a set of sets A such as A /∈ A, is X ∈ X? ) This kind of reasoning is used to prove that halting problem of checking whether a given piece of code contains an infinite loop is not solvable (an alternative way to prove this is diagonalization).
  • A theory is a set of statements, or, in a different view, a set of axioms from which a set of statements can be proven. Here, axioms are statements that are assumed in the theory (for example, ∀x, y x+y = y + x).
  • A model of a theory is a description of a possible world, that is, a set of objects and interpretations of functions and relations, in which axioms are true. There can be several models for the same theory. For example, Euclidean geometry has as a model the geometry on a plane. Without the 5th postulate

about parallel lines, there are other possible models such as geometry on a sphere (where parallel lines intersect).

  • A theory is called complete if it contains (proves) every true (in every model) statement about the objects that can be described in its language (e.g., sets or natural numbers) and sound if every statement provable from the axioms is indeed true.
  • Hilbert’s program: list of problems in mathematics to solve, 1990. Includes problem 2: “prove consistency of arithmetic”, as well as continuum hypothesis and a few others.
  • G¨odel incompleteness theorems say 1) for every (powerful enough and computable) theory of arith- metic efficiently computable theory that can do arithmetic (+ and ∗) there is a true sentence which this theory cannot prove (this is the sentence “I am not provable”): that is, if a theory is consistent, then it is not complete. 2) A (powerful enough and computable) theory of arithmetic cannot prove its own consistency (that is it not contradictory).
  • There are examples of systems of axioms that give complete and consistent theories, but they cannot do full arithmetic: Boolean algebra or Presburger’s arithmetic (which only has +, no ∗).

Mathematical induction, recursive definitions and algorithm analysis.

  1. Mathematical induction Let n 0 , n ∈ N, and P (n) is a predicate with free variable n. Then the mathematical induction principle says:

(P (n 0 ) ∧ ∀n ≥ n 0 (P (n) → P (n + 1))) → ∀n ≥ n 0 P (n)

That is, to prove that a statement is true for all (sufficiently large) n, it is enough to prove that it holds for the smallest n = n 0 (base case) and prove that if it holds for some arbitrary n > n 0 (induction hypothesis) then it also holds for the next value of n, n + 1 (induction step). A strong induction is a variant of induction in which instead of assuming that the statement holds for just one value of n we assume it holds for several: P (k) ∧ P (k + 1) ∧ · · · ∧ P (n) → P (n + 1) instead of just P (n) → P (n + 1). In particular, in complete induction k = n 0 , so we are assuming that the statement holds for all values smaller than n + 1. A well-ordering principle states that every set of natural numbers has the smallest element. It is used to prove statements by counterexample: e.g., “define set of elements for which P (n) does not hold. Take the smallest such n. Show that it is either not the smallest, or P (n) holds for it”. These three principles, Induction, Strong Induction and Well-ordering are equivalent. If you can prove a statement by one of them, you can prove it by the others. The following is the structure of an induction proof.

(a) P (n). State which assertion P (n) you are proving by induction. E.g., P (n): 2n^ < n!. (b) Base case: Prove P (n 0 ) (usually just put n 0 in the expression and check that it works). E.g., P (4): 2^4 < 4! holds because 2^4 = 16 and 4! = 24 and 16 < 24. (c) Induction hypothesis: “assume P (n) for some n > n 0 ”. I like to rewrite the statement for P (n) at this point, just to see what I am using. For example, “Assume 2n^ < n!”.