Intro to First-Order Logic Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as input, and return a single binary value. Syntax: variables (lower-case letters): a, x1, y, z, … logical connectives: ⇔⇒() Functions in propositional logic are called “sentences”. They consist of variables joined together with the logical connectives, like this: (a b) ⇔ (c d) This example is a function that takes four binary inputs and returns a binary output. Each input gets mapped to one of the four variables. Quiz: Propositional Logic Write a function in propositional logic for each of the following descriptions: 1. Create a function that is true if and only if input a has the same value as input b, or input a has the same value as input c. 2. Create a function that is true if and only if exactly one of the three inputs is true. 3. Create a function that is true if and only if there are an even number of true inputs, out of a total of four inputs. Answer: Propositional Logic 1. (a ⇔ b) (a ⇔ c) 2. (ab c) (a b c) (a b c) 3. (a b c d) (a b c d) (a b c d) (a b c d) (a b c d) (a b c d) (a b c d) (a b c d) Model A Model in Propositional Logic is the name for an assignment of values to each of the variables in a sentence. You can also just think of it as binary inputs. For example, here’s a sentence: (a ⇔ b) (a ⇔ c) And here’s a model for it: {at, bf, ct} (sentence returns true) Here’s another model for this sentence: {af, bt, ct} (sentence returns false Computational Problems for Propositional Logic A sentence that is always true is called valid. A sentence that is sometimes true, and sometimes not, is called satisfiable. A sentence that is never true is called unsatisfiable. Computational Problems 1. Validity Testing: Given a sentence in PL, is it always true, no matter what the input? 2. Satisfiability: Given a sentence in PL, is there some input that makes it return true? Quiz: Valid, Satisfiable, or Unsatisfiable? 1. 2. 3. 4. (a ⇔ b) (a ⇔ c) (ab c) (a b c) (a b c) aa aa Answers: Valid, Satisfiable, or Unsatisfiable? 1. (a ⇔ b) (a ⇔ c) Satisfiable. For instance, when a is true and b is true, the function returns true. But when a is true, b is false, and c is false, the function returns false, so it can’t be always true. 2. (ab c) (a b c) (a b c) Satisfiable. A true, b false, c false makes this sentence true. A false, b false, c false makes this sentence false. 3. aa Unsatisfiable. If a is true, the sentence is false, and if a is false, the sentence is false. 4. aa Valid. If a is true, the sentence is true, and if a is false, the sentence is true. Quiz: Properties of the Computational Problems 1. What is the computational complexity of the satisfiability problem? 2. How about validity? 3. Are there any simplifications that are easier? Answers: Properties of the Computational Problems 1. What is the computational complexity of the satisfiability problem? NP-Complete 2. How about validity? co-NP 3. Are there any simplifications that are easier? 3-SAT is also NP-complete 2-SAT is in P. One Motivation for First-Order Logic Here’s another PL sentence: a ⇒ (b c) Let’s make it more interesting by renaming the variables: Jonny_is_in_water => (Jonny_swims Jonny_sinks) This is still a function from binary variables to binary outputs. It’s not a very good description of what’s going on. Intuitively, this should be true for anyone, not just Jonny, but in PL we would need to create a copy with different binary variables to describe each new fact. From Propositional to First-Order Logic Jonny_is_in_water => (Jonny_swims Jonny_sinks) All PL sentences are also FOL sentences. But in FOL we can also add new kinds of syntax. For instance: Is_in(Jonny, water) => (swims(Jonny) sinks(Jonny)) This is a sentence in FOL that is not in PL. It involves some new syntax: Object constants: Jonny, water Relations: Is_in(,); swims(); sinks() The new version of this sentence makes clear that there is an object (called Jonny) that has some properties (if Jonny is in water, he either swims or sinks). FOL Syntax FOL is a language for creating functions that map from input sets of objects to a binary value. The basic elements are: Constants: Jonny, water, Mary Sue, … Variables (lower-case letters): a, x, y, … Relations (variables with parentheses): Is_in(), swims(), greaterThan(), isPresidentOf(), … Functions (variables with parentheses): heightOf(), engagedTo(), bornOnDate(), … Logical connectives: ⇔⇒() Quantifiers: ∃∀ A FOL sentence consists of relations that are connected by the logical connectivies, just like PL variables are connected by logical connectives. One difference is that relations take arguments, either constants, functions, or variables. For each variable used in a sentence, there must be a quantifier. Example FOL Sentences Single-relation sentences: 1. swims(Jonny) 2. presidentOf(BarackObama, USA) 3. ∃x bornInYear(x, 1960) 4. ∀x bornInYear(x, subtract(2013, age(x))) Multi-relation sentences: 1. Is_in(Jonny, water) => (swims(Jonny) sinks(Jonny)) 2. ∀x Is_in(x, water) => (swims(x) sinks(x)) 3. ∀x,y duck(x) raindrop(y) => dripsOff(y, back(x)) Quiz: FOL Sentences Come up with FOL sentences for each of these English descriptions: 1. 2. 3. 4. 5. Simba is cute. Arnulfo walked to the store. Arnulfo walked to a store. Erin despises Madeleine. Erin loves all people except for Madeleine. Answers: FOL Sentences Come up with FOL sentences for each of these English descriptions: 1. Simba is cute. cute(Simba) 2. Arnulfo walked to the store. walkedTo(Arnulfo, Store27) 3. 4. Arnulfo walked to a store. ∃x walkedTo(Arnulfo, x) Erin despises Madeleine. despises(Erin, Madeleine) 5. Erin loves all people except for Madeleine. ∀x person(x) =(x, Madeleine) => loves(Erin, x) Models in FOL A Model in FOL is primarily an assignment of sets of objects to relations (that’s usually the most interesting part). However, a model must also assign objects to the constant symbols, and it must assign “maps between objects” to the function symbols. Here’s an example Model: person {ErinLawrence, MaddieMayne, ArnulfoArias} = {(ErinLawrence,ErinLawrence), (MaddieMayne,MaddieMayne), (ArnulfoArias, ArnulfoArias)} loves {(ErinLawrence,ArnulfoArias), (ArnulfoArias,MaddieMayne)} Madeleine MaddieMayne Erin ErinLawrence Arnulfo ArnulfoArias Quiz: Is this sentence true, given the model above? ∀x person(x) =(x, Madeleine) => loves(Erin, x) Answer: Models in FOL A Model in FOL is primarily an assignment of sets of objects to relations (that’s usually the most interesting part). However, a model must also assign objects to the constant symbols, and it must assign “maps between objects” to the function symbols. Here’s an example Model: person {ErinLawrence, MaddieMayne, ArnulfoArias} = {(ErinLawrence,ErinLawrence), (MaddieMayne,MaddieMayne), (ArnulfoArias, ArnulfoArias)} loves {(ErinLawrence,ArnulfoArias), (ArnulfoArias,MaddieMayne)} Madeleine MaddieMayne Erin ErinLawrence Arnulfo ArnulfoArias Answer: This sentence is NOT true using the model above, since ErinLawrence does not love ErinLawrence in the model. ∀x person(x) =(x, Madeleine) => loves(Erin, x) Intuition for FOL: Describing “Possible Worlds” You can think of each FOL model as being its own “world” with its own objects, and relationships between objects. FOL sentences assign a true or false value to every one of these “possible worlds”. So one way to think about FOL is: It’s a way to describe what “worlds” are actually possible, given everything that I know (or believe). For instance, I believe 2+2=4. So if I write the FOL sentence =(+(2,2), 4), I am describing my belief that all worlds (models) in which 2+2 is not equal to 4 must be false. As another example, I am not sure who will be president of the US in 2017, but let’s say (just to keep it simple) I believe that it will be either Marco Rubio or Hillary Clinton. Then if I write presidentOf(MarcoRubio, US, 2017) presidentOf(HillaryClinton, US, 2017), I am saying that I believe I live in some subset of all possible worlds, but in every one of those possible worlds that I believe I’m in, either Hillary Clinton or Marco Rubio becomes president in 2017. Quiz: More FOL Questions Some rules we will assume for models: 1. All models must have at least one object 2. All models must use the “normal” version of the “=“ relation. Given these rules, determine if the following FOL sentences are valid, satisfiable, or unsatisfiable: 1. ∃x, y . x = y 2. (∃x . x=x) => (∀y ∃z . y=z) 3. ∀x p(x) p(x) 4. ∃x p(x) Answers: More FOL Questions Some rules we will assume for models: 1. All models must have at least one object 2. All models must use the “normal” version of the “=“ relation. Given these rules, determine if the following FOL sentences are valid, satisfiable, or unsatisfiable: 1. ∃x, y . x = y: valid 2. (∃x . x=x) => (∀y ∃z . y=z): valid 3. ∀x p(x) p(x): valid 4. ∃x p(x): satisfiable Comparison: PL vs. FOL FOL allows for more uncertainty. For example, in PL you can say either x or y is true, but you’re not sure which of the two. But in FOL, you can say P(x) is true for some object x, but you’re not sure which out of all objects. FOL allows for more shortcuts. (That is, it allows you to express the same thing as PL in a much more compact form.) For example, in PL you can say Jonny_has_two_eyes Susie_has_two_eyes … Zeb_has_two_eyes. In FOL, you can say ∀x human(x) => hasTwoEyes(x) FOL accepts richer inputs (models). In PL, the input is a set of binary values. In FOL, the input is sets of objects, maps between them, etc.