Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating...

22
Intro to First-Order Logic

Transcript of Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating...

Page 1: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

Intro to First-Order Logic

Page 2: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

Propositional LogicPropositional 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.

Page 3: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

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.

Page 4: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

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)

Page 5: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

ModelA 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

Page 6: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

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 Problems1. 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?

Page 7: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

Quiz: Valid, Satisfiable, or Unsatisfiable?

1. (a ⇔ b) (a ⇔ c)2. (ab c) (a b c) (a b c)3. aa4. aa

Page 8: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

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. aaUnsatisfiable. If a is true, the sentence is false, and if a is false, the sentence is false.4. aaValid. If a is true, the sentence is true, and if a is false, the sentence is true.

Page 9: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

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?

Page 10: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

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-complete2-SAT is in P.

Page 11: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

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.

Page 12: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

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, waterRelations: 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).

Page 13: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

FOL SyntaxFOL 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.

Page 14: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

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:4. Is_in(Jonny, water) => (swims(Jonny) sinks(Jonny))5. ∀x Is_in(x, water) => (swims(x) sinks(x))6. ∀x,y duck(x) raindrop(y) => dripsOff(y, back(x))

Page 15: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

Quiz: FOL Sentences

Come up with FOL sentences for each of these English descriptions:

1. Simba is cute.2. Arnulfo walked to the store.3. Arnulfo walked to a store.4. Erin despises Madeleine.5. Erin loves all people except for Madeleine.

Page 16: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

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. Arnulfo walked to a store.∃x walkedTo(Arnulfo, x)4. Erin despises Madeleine.

despises(Erin, Madeleine)

5. Erin loves all people except for Madeleine.∀x person(x) =(x, Madeleine) => loves(Erin, x)

Page 17: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

Models in FOLA 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 MaddieMayneErin ErinLawrenceArnulfo ArnulfoArias

Quiz: Is this sentence true, given the model above?∀x person(x) =(x, Madeleine) => loves(Erin, x)

Page 18: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

Answer: Models in FOLA 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 MaddieMayneErin ErinLawrenceArnulfo 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)

Page 19: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

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.

Page 20: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

Quiz: More FOL Questions

Some rules we will assume for models:1. All models must have at least one object2. All models must use the “normal” version of the “=“

relation.Given these rules, determine if the following FOL sentences are valid, satisfiable, or unsatisfiable:3. ∃x, y . x = y4. (∃x . x=x) => (∀y ∃z . y=z)5. ∀x p(x) p(x)6. ∃x p(x)

Page 21: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

Answers: More FOL Questions

Some rules we will assume for models:1. All models must have at least one object2. All models must use the “normal” version of the “=“

relation.Given these rules, determine if the following FOL sentences are valid, satisfiable, or unsatisfiable:3. ∃x, y . x = y: valid4. (∃x . x=x) => (∀y ∃z . y=z): valid5. ∀x p(x) p(x): valid6. ∃x p(x): satisfiable

Page 22: Intro to First-Order Logic. Propositional Logic Propositional Logic is a language for creating functions that take N binary values (true or false) as.

Comparison: PL vs. FOLFOL 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.