a little logic - tu dresdeni propositional logic i satisfiability problems i solving sudokus i...

42
I Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen H¨ olldobler and Emmanuelle-Anna Dietz A Little Logic 1 A Little Logic Steffen H ¨ olldobler and Emmanuelle-Anna Dietz International Center for Computational Logic Technische Universit¨ at Dresden Germany

Upload: others

Post on 13-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

I Propositional Logic

I Satisfiability Problems

I Solving Sudokus

I First Order Logic

I Logic Programming

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 1

A Little Logic

Steffen Holldobler and Emmanuelle-Anna DietzInternational Center for Computational LogicTechnische Universitat DresdenGermany

Page 2: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Propositions

I Atomic propositions (atomic formulas or atoms)

The sun is shiningThe vertex with number 17 is greenTG925 is flying from Munich to BangkokAt the forth position of the DNA strand is the nucleotide C

I Abbreviations for Atoms

p1 the sun is shiningp2 . . .

I Truth values true (>) and false (⊥)

I Interpretation Mapping from the set of propositions to {>,⊥}

p1 7→ > the proposition “the sun is shining” is truep2 7→ ⊥ the proposition “the vertex with number 17 is green” is false

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 2

Page 3: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Complex Propositions

I Complex propositions (sentences or formulas)

The sun is shining p1The sun is not shining ¬p1The sun is shining or the sun is not shining (p1 ∨ ¬p1)The sun is shining and the vertex with number 17 is green (p1 ∧ p2)If the sun is shining then the vertex with number 17 is green (p1 → p2)

I Definition The set of (propositional) formulas is the smallest set satisfying thefollowing conditions

. All atoms are formulas

. If F is a formula then so is ¬F

. If F and G are formulas then so are (F ∨ G), (F ∧ G), and (F → G)

I Example ¬(¬(p1 ∧ p2)→ (p1 ∨ ¬p1))

I Notation We sometimes omit “p” and denote atoms by natural numbers

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 3

Page 4: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Subformulas

I Definition Let F be a propositional formula. The set of subformulas of F is thesmallest set of formulas satisfying the following conditions

. F is a subformula of F

. If ¬G is a subformula of F then so is G

. If (G1 ◦G2) is a subformula of F then so are G1 and G2, where ◦ ∈ {∧,∨,→}

I Example The set of subformulas of F = ¬((p1 → p2) ∨ p1) is

{¬((p1 → p2) ∨ p1), ((p1 → p2) ∨ p1), (p1 → p2), p1, p2}

The set of variables occurring in F is {p1, p2}

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 4

Page 5: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Interpretations and Models

I Rememberinterpretations are mappings from the set of propositions into {>,⊥}

I How are complex propositions interpreted?

F ¬F> ⊥⊥ >

F G (F ∨ G) (F ∧ G) (F → G)

> > > > >⊥ > > ⊥ >> ⊥ > ⊥ ⊥⊥ ⊥ ⊥ ⊥ >

I Example Consider an interpretation I with 1 7→ > and 2 7→ ⊥ then

I(¬(¬(1 ∧ 2)→ (1 ∨ ¬1))) = ⊥

I Definition An interpretation assigning> to a formula F is called model for F

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 5

Page 6: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Satisfiability and other Relations

I Definition Let F be a formula

. F is satisfiable if there is an interpretation I with I(F ) = >

. F is valid if for all interpretations I we find I(F ) = >

. F is falsifiable if there is an interpretation I with I(F ) = ⊥

. F is unsatisfiable if for all interpretations I we find I(F ) = ⊥

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 6

Page 7: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Truth Tables

I How can we compute the value of a formula Funder all possible interpretations?

I Computing a truth table

1 Let m be the number of subformulas of F

2 Let n be the number of variables occurring in F

3 Form a table with 2n rows and m columns,where the first n columns are marked bythe n propositional variables occurring in F ,the last column is marked by F , andthe remaining columns are marked by the other subformulas of F

4 Fill in the first n columns with> und⊥ as follows:In the first column fill in alternating downwards>⊥>⊥ . . .,in the second column>>⊥⊥ . . .,in the third column>>>>⊥⊥⊥⊥ . . ., etc

5 Calculate the values in the remaining columns usingthe known functions on the set of truth values

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 7

Page 8: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Working with Truth Tables

I Let F be a formula and T (F ) a corresponding truth table

. F is satisfiable iff T (F ) contains a row with> in the last column

. F is valid iff all rows in T (F ) have> in the last column

. F is falsifiable iff T (F ) contains a row with⊥ in the final column

. F is unsatisfiable iff all rows T (F ) have⊥ in the final column

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 8

Page 9: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Logical Consequences

I Definition A formula F is a logical consequence of a set of propositionalformulas G, in symbols G |= F , iff for every interpretation I we find:if I(H) = > for all H ∈ G then I(F ) = >

I Theorem Let F , F1, . . . , Fn be formulas.{F1, . . . , Fn} |= F holds iff ((F1 ∧ . . . ∧ Fn)→ F ) is valid

I Examples

{p, (p → q)}?|= q

{p, (¬q → ¬p)}?|= q

{p,¬p}?|= q

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 9

Page 10: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Satisfiability Problems

I RememberA formula F is satisfiable if there is an interpretation I with I(F ) = >

I Definition A satisfiability problem consists of a formula Fand is the question whether F is satisfiable

I Example Is F = ¬(¬(1 ∧ 2)→ (1 ∨ ¬1)) satisfiable?

interpretations formula1 2 F> > ⊥⊥ > ⊥> ⊥ ⊥⊥ ⊥ ⊥

I Observation If a formula contains n different atomsthen there are 2n different interpretations

I RemarkThe complexity theory was developed having the satisfiability problem in mind!

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 10

Page 11: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Applications

I Termination of programs

I Planning and scheduling

I Biocomputing

I Verification of hard- and software

I Cryptoanalysis

I Verification of signal systems

I Answer set programming

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 11

Page 12: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

The Graph Coloring Problem

I Given A finite graph and a finite set of colors

I Goal An assignment of colors to verticessuch that neighboring vertices have different colors

I Formally. At least one color is assigned to each vertex

. At most one color is assigned to each vertex

. Neighboring vertices have different colors

1

2 3

4

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 12

Page 13: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Naive Encoding of the Graph Coloring Problem (1)

I Task For a given graph coloring program G find a propositional formula Fsuch that each model for F is a solution for G

I Example We consider the set {1, 2, 3, 4} of colors and the graph

1

2 3

4

I Naive encoding of an assignment of colors to vertices

11 color 1 is assigned to vertex 112 color 2 is assigned to vertex 113 color 3 is assigned to vertex 1...

...44 color 4 is assigned to vertex 4

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 13

Page 14: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Naive Encoding of the Graph Coloring Problem (2)

I At least one color is assigned to each vertex

(11 ∨ 12 ∨ 13 ∨ 14) ∧ . . . ∧ (41 ∨ 42 ∨ 43 ∨ 44)

I At most one color is assigned to each vertex

¬(11 ∧ 12) ∧ ¬(11 ∧ 13) ∧ ¬(11 ∧ 14) ∧ . . . ∧ ¬(43 ∧ 44)

I Neighboring vertices have different colors

¬(11 ∧ 21) ∧ ¬(12 ∧ 22) ∧ ¬(13 ∧ 23) ∧ . . . ∧ ¬(34 ∧ 44)

I Claim Let F be the conjunction of these formulasEach model for F represents a solution to the graph coloring problem

I Example The interpretation mapping 11, 22, 33, and 44 to>and all other atoms to⊥ is a model fur F

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 14

Page 15: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Some Observations

I The formulas are quite large

I 107 different atoms and 108 conjuncts may appear easily in applications

I Hence, the size of the search space is 2107!

I The formulas are difficult to understand

I We need help by machines

I This help is provided by SAT solver

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 15

Page 16: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

A Better Encoding of the Graph Coloring Problem (1)

I Idea We order the colors: 1 < 2 < 3 < 4

I Encoding of an assignment of colors to vertices

11 a color greater equal 1 is assigned to vertex 112 a color greater equal 2 is assigned to vertex 1...

...44 a color greater equal 4 is assigned to vertex 4

11 ∧ ¬12 vertex 1 has color 112 ∧ ¬13 vertex 1 has color 213 ∧ ¬14 vertex 1 has color 314 vertex 1 has color 4...

...44 vertex 4 has color 4

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 16

Page 17: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

A Better Encoding of the Graph Coloring Problem (2)

I At least one color is assigned to each vertex

11 ∧ 21 ∧ 31 ∧ 41

I At most one color is assigned to each vertex

(¬11→ ¬12) ∧ (¬12→ ¬13) ∧ (¬13→ ¬14) ∧ . . . ∧ (¬43→ ¬44)

I Neighboring vertices have different colors

¬(11 ∧ ¬12 ∧ 21 ∧ ¬22) ∧ . . . ∧ ¬(34 ∧ 44)

I Claim Let F be the conjunction of these formulasEach model for F represents a solution to the graph coloring problem

I Observation In experiments the runtimes are reduced by 10% on average

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 17

Page 18: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Conjunctive Normal Form (1)

I Usually, SAT solvers accept formulas only in a particular form

I Definition A literal is an atom or the negation of an atom

I Examples 11, ¬12, ¬13, 14

I Definition A formula is in conjunctive normal form (CNF) if it is of the form

(L11 ∨ . . . ∨ L1n1 ) ∧ . . . ∧ (Lm1 ∨ . . . ∨ Lmnm )

where each Lij is a literal

I Definition Two formulas F and G are equivalent, in symbols F ≡ G,if I(F ) = I(G) holds for all interpretations I

I Examples ¬¬F ≡ F¬(F ∧ G) ≡ (¬F ∨ ¬G)¬(F ∨ G) ≡ (¬F ∧ ¬G)(F → G) ≡ (¬F ∨ G)

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 18

Page 19: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Conjunctive Normal Form (2)

I Theorem For each formula there is an equivalent formula in CNF

I Example

(¬11 ∨ ¬12) ∧ (¬11 ∨ ¬13) ∧ (¬11 ∨ ¬14) . . . ∧ (¬43 ∨ ¬44)

is an equivalent CNF of

¬(11 ∧ 12) ∧ ¬(11 ∧ 13) ∧ ¬(11 ∧ 14) . . . ∧ ¬(43 ∧ 44)

I Observation There are algorithms transforming a given formula into CNF

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 19

Page 20: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

SAT Solvers

I There is a variety of freely available SAT solvers

. MiniSAT

. glucose

. riss

I They solve problems in CNF with up to 107 atoms and 108 conjuncts

I They are applied in industry

I There are yearly competitions for the best SAT solvers

I They are continuously improved

I The improvements concern the whole area of computer sciencefrom theory and applications to soft- and hardware

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 20

Page 21: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Solving the Graph Coloring Problem with Naive Encoding

I Input to a SAT solver p cnf nv nc11 12 13 14 0...41 42 43 44 0-11 -12 0...-43 -44 0-11 -21 0...-34 -44 0

where nv and nc are the numbers of atoms (variables) and conjuncts, resp.

I Possible output of a SAT solver 11 22 33 44

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 21

Page 22: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Sudoku Puzzles

I Let n ∈ N; a Sudoku puzzle

. consists of an n2 × n2 grid

. made up of n × n subgrids called blocks

. with some integers from [1, n2] placed in some cells

. where some of these placements are predefined

I The problem is

. to assign i ∈ [1, n2] to each cell of the grid such that

. each row, column, and block contains exactly one occurrenceof each integer in [1, n2]

I There are more than 6× 1012 3-Sudoku puzzles

I Sudoku puzzles with n > 3 appear to be difficult to solve for humans

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 22

Page 23: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

A Simple 3-Sudoku

+-------+-------+-------+| - - 4 | 2 3 9 | - - - || - 8 - | 5 - 6 | - - - || 9 - - | 8 - 4 | - 6 - |+-------+-------+-------+| 5 7 1 | - - - | 9 4 6 || 8 - - | - - - | - - 3 || 2 3 9 | - - - | 7 8 1 |+-------+-------+-------+| - - - | 4 - 8 | - - 7 || - - 3 | 9 - 7 | - 1 - || - - - | 1 2 3 | 4 - - |+-------+-------+-------+

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 23

Page 24: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Sudoku – Exercise

I For a given 3-Sudoku S, specify a first order logic formula F such that eachmodel for F is a solution for S. In particular, specify formulas for the followingrequirements

. Definedness Each cell contains one element of [1, 9]

. Uniqueness for Cells Each cell has at most one value

. Uniqueness for Rows All numbers in [1, 9] must occur in every row

. Uniqueness for Columns All numbers in [1, 9] must occur in every column

. Uniqueness for Blocks All numbers in [1, 9] must occur in every block

I Specify a propositional formula G corresponding to F

I Turn G into CNF

I Download a SAT solver from the internet

I Solve the given 3-Sudoku with the help of the SAT solver

I Extract the solution

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 24

Page 25: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

First Order Logic

I Sentences like ’for each formula there is an equivalent formula in CNF ’ cannotbe expressed in the language of propositional logic

. The set of formulas is infinite

I Sentences like ’at most one color is assigned to each vertex ’ can be expressedin the language of propositional logic if the set of colors as well as the graph isfinite

. But the propositional representation is usually difficult to understand

I We need a more expressive language

. First order logic

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 25

Page 26: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Syntax of First Order Logic

I Definition An alphabet of (first order) logic consists of

. a finite or countably infinite set of relation symbols

. a finite or countably infinite set of function symbols

. a countably infinite set of variables

. the set {¬, ∧, ∨, →} of connectives

. the set {∀, ∃} of quantifiers

. the special characters “(”, “)”, and “,”

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 26

Page 27: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Syntax (Continued)

I ∀ is called universal quantifier∃ is called existential quantifier

I An arity n ∈ N is assigned to each function and relation symbol

I Nullary function symbols are called constant symbols

I Notation p, q, . . . relation symbolsg, h, . . . function symbolsa, b, . . . constant symbolsX , Y , . . . variables

I Agreement In the following we assume that the sets of relation symbols,function symbols, and variables are given

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 27

Page 28: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Terms

I DefinitionThe set of terms is the smallest set satisfying the following conditions

1 Every variable is a term

2 If g is an n-ary function symbol and t1, . . . , tn are termsthen g(t1, . . . , tn) is a term as well

A term is closed or ground (instantiated) if it does not contain any variables

I Notation We write g instead of g()

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 28

Page 29: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

First Order Logic Formulas

I Definition The set of atomic formulas (or atoms) is the set of strings of theform p(t1, . . . , tn), where p is an n-ary relation symbol and t1, . . . , tn are terms

I Notation We write p instead of p()

I Definition The set of (first order logic) formulas is the smallest set satisfyingthe following conditions

. Every atom is a formula

. If F is a formula then so is ¬F

. If F and G are formulas then so are (F ∨ G), (F ∧ G), and (F → G)

. If F is a formula, Q a quantifier, and X a variablethen (QX) F is a formula as well

I Notation F ,G,H (possibly indexed) denote formulas

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 29

Page 30: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Free and Bound Occurrences of Variables

I DefinitionThe free occurrences of a variable in a formula are defined as follows

. The free occurrences of a variable in an atomic formula Fare the occurrences of a variable in F

. The free occurrences of a variable in a formula ¬Fare the free occurrences of a variable in F

. The free occurrences of a variable in a formula (F1 ◦ F2)are the free occurrences of a variable in F1together with the free occurrences of a variable in F2, where ◦ ∈ {∧,∨,→}

. The free occurrences of a variable in a formula (QX) Fare the free occurrences of a variable in F without the occurrences of X

The occurrence of a variable is called bound if it is not free

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 30

Page 31: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Closed Terms and Formulas

I Remember A term is closed if it does not contain any occurrence of a variable

I Definition A closed formula (or sentence) is a formula where every occurrenceof a variable is bound

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 31

Page 32: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Substitutions

I Definition A substitution is a mapping from the set of variables into the set ofterms, where only a finite number of variables is not mapped to itself

I Let σ be a substitution

. σ can be represented by a finite set of pairs

{X 7→ σ(X) | X 6= σ(X)}

and vice versa

. If all variables are mapped to themselves, then σ is called empty substitution

. σX = {Y 7→ t ∈ σ | Y 6= X}

. Instead of σ(X) we will write Xσ

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 32

Page 33: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Instances

I Definition A substitution σ is extended to a mapping σ from the set of termsand into the set of terms as follows

tσ =

{tσ if t is a variablef (t1σ, . . . , tnσ) if t is of the form f (t1, . . . , tn)

tσ is called instance of t under σ

If tσ is closed, then tσ is called ground instance of t under σ,and σ is said to be a ground substitution for t

I Notation We usually omit ˆ and simply write σ

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 33

Page 34: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Applications of Substitutions to Formulas

I Definition Let σ be a substitutionThe application of a substitution to a formula is defined as follows

. p(t1, . . . , tn)σ = p(t1σ, . . . , tnσ) for every atom of the form p(t1, . . . , tn)

. (¬F )σ = ¬(Fσ)

. (F1 ◦ F2)σ = (F1σ ◦ F2σ), where ◦ ∈ {∧,∨,→}

. ((QX) F )σ = (QX) (FσX ), where Q ∈ {∀,∃}

If F is a formula and Fσ is closed,then Fσ is called ground instance of F under σ,and σ is said to be a ground substitution for F

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 34

Page 35: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Semantics – Relations and Functions

I Let D be a set

D2 = D × D = {(d1, d2) | d1 ∈ D and d2 ∈ D}Dn = Dn−1 × D = {(t, dn) | t ∈ Dn−1 and dn ∈ D}

=: {(d1, . . . , dn) | di ∈ D, 1 ≤ i ≤ n}, n > 2D1 = D =: {(d) | d ∈ D}D0 = = {( )}

I Relations

R ⊆ D2 R = {(n,m) | n,m ∈ N and n < m}R ⊆ D3 R = {(x, y, z) | x, y, z ∈ N and x2 + y2 = z2}R ⊆ D1 R = {(n) | n ∈ N and n even}R ⊆ D0 R = ∅ or R = {( )}

I Notation Often d is written instead of (d)

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 35

Page 36: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Functions

I Remember Let D be a set

D2 = D × D = {(d1, d2) | d1 ∈ D and d2 ∈ D}Dn = Dn−1 × D = {(t, dn) | t ∈ Dn−1 and dn ∈ D}

=: {(d1, . . . , dn) | di ∈ D, 1 ≤ i ≤ n}, n > 2D1 = D =: {(d) | d ∈ D}D0 = = {( )}

I Functions+ : N2 → N +(2, 3) 7→ 5s : N1 → N s(3) 7→ 40 : N0 → N 0( ) 7→ 0

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 36

Page 37: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Interpretations

I Definition A predicate logic interpretation I consists of a non-empty setDand a mapping ·I satisfying the following conditions

. Every n-ary function symbol g is mapped to an n-ary function gI : Dn → D

. Every n-ary relation symbol p is mapped to an n-ary relation pI ⊆ Dn

D is called domain of the interpretation

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 37

Page 38: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Variable Assignments

I What is the meaning of a variable?

I Definition A variable assignment wrt an interpretation I = (D, ·I )is a mapping Z from the set of variables and into the domainD

. The image of a variable X under Z is denoted by XZ

. Let Z be a variable assignment and d ∈ D.{X 7→ d}Z denotes the variable assignment, where

Y{X 7→d}Z =

{d if Y = XYZ otherwise

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 38

Page 39: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Interpretation of Terms

I DefinitionLet I = (D, ·I ) be an interpretation and Z a variable assignment wrt IThe meaning t I,Z of a term t is defined as follows

. For every variable X we have X I,Z = XZ

. For every term of the form g(t1, . . . , tn) we have

[g(t1, . . . , tn)]I,Z = gI (t I,Z1 , . . . , t I,Z

n )

where g is an n-ary function symbol and t1, . . . , tn are terms

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 39

Page 40: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Example

I Let the set of function symbols consist of a constant symbol a,a unary function symbol h, and a binary function symbol g

I D1 = N with successor function s and addition +

I D2 = Z with predecessor function p and subtraction−

I D3 is set of words over Σ = {o,m} with functions

. addm which appends m to a word at the right

. conc which concatenates two words

a h g XZ g(h(a), h(h(a))) g(h(X), g(h(a), h(X)))

I1 0 s + 4 3 11I2 1 p − 8 1 14I3 o addm conc omo omomm omomomomom

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 40

Page 41: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Interpretation of Formulas

I Definition Let I = (D, ·I ) be an interpretation and Z a variable assignmentwrt I . I and Z assign to every formula F a truth value F I,Z as follows

. [p(t1, . . . , tn)]I,Z = > iff (t I,Z1 , . . . , t I,Z

n ) ∈ pI

. [¬F ]I,Z = ¬(F I,Z)

. [(F1 ◦ F2)]I,Z = (F I,Z1 ◦ F I,Z

2 ), where ◦ ∈ {∧,∨,→}

. [(∀X) F ]I,Z = > iff for all d ∈ D: F I,{X 7→d}Z = >

. [(∃X) F ]I,Z = > iff for some d ∈ D: F I,{X 7→d}Z = >

I Observation If a formula F is closed, then its meaning under an interpretationI is independent of a variable assignment Z and we write F I instead of F I,Z

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 41

Page 42: A Little Logic - TU DresdenI Propositional Logic I Satisfiability Problems I Solving Sudokus I First Order Logic I Logic Programming Steffen Holldobler and Emmanuelle-Anna Dietz¨

Models for Closed Formulas

I DefinitionLet I = (D, ·I ) be an interpretation and F be a closed formulaI is called model for F , in symbols I |= F , if F I = > holds

I Many notions and results known from propositional logic can be extended topredicate logic. For example:

. Validity, satisfiability, falsifiability, unsatisfiability

. Logical consequence

Steffen Holldobler and Emmanuelle-Anna DietzA Little Logic 42