Professor: Stephen Watt (informally Collin Roberts) | Fall: Term 2023

Download PDF

Github

Logic01: Introduction

Logic is the science of reasoning.

Aristotelian Logic: Correctness of an argument depends on form, not content.

All are . is an . is a .

Logic is fundamental to Computer Science and improves one’s general powers of analytical thinking. CS245 will not directly improve your coding skills, it will make you a more effective thinker (which will then improve coding skills).

Propositional Logic

Definition

An argument is a set of statements, one or several premises, and a conclusion. A valid (correct, sound) argument is one in which, whenever the premises are true, the conclusion is also true.

For example,

No pure water is burnable.

Some Cuyahoga River water is burnable.

Therefore, some Cuyahoga River water is not pure.

This argument is valid.

Note, the conclusion being false does not necessarily prove that an argument is invalid.

To see which arguments are correct, and which are not, we abbreviate essential statements by using letters ().

“demand rises”, “companies expand”, “companies hire workers”.

If then .

If then .

If then .

This argument is a hypothetical syllogism.

More important logical arguments:

or

Not

This argument is a disjunctive syllogism.

If then

This argument is called modus ponens.

If then

Not

Not

This argument is called modus tollens.

A proposition is a declarative sentence that is either true (1) or false (0), in some context.

Propositional variables are atomic variables. An atomic proposition is a proposition that cannot be broken down into smaller propositions. A proposition that is not atomic is called compound.

Or, and, not, if-then are referred to as logical connectives.

Let be a proposition, the compound proposition (not ) is true when is false.

Let and be two propositions. The proposition ( and ) is true when both and are true, and false otherwise. Referred to as the conjunction of and .

When writing truth tables, use the convention in decreasing lexicographic ordering.

Let and be two propositions. The proposition is true when either , or , or both and are true, and is false when both and are false. Referred to as the disjunction of and .

The English “or” has two different meanings.

Exclusive or: “You can either have soup or salad” (can have one or the other, but not both).

Inclusive or: “The computer has a bug, or the input is erroneous”.

To avoid ambiguity, translates to the inclusive or.

Let and be two propositions. Then (if , then ) is false when is true and is false, and true otherwise. Referred to as the implication of and .

Means that, whenever is correct, so is . is the antecedent, is the consequent.

If is false, then is vacuously true. This is consistent with everyday speech.

The following are logically equivalent.

If then is sufficient for only if implies if .

Let and be two propositions. Then ( if and only if ) is true whenever and have the same truth values. Referred to as equivalence (or biconditional). We often use iff as an abbreviation for if and only if.

An ambiguous sentence usually has multiple interpretations.

Imprecision arises from the use of qualitative descriptions.

is the only unary connective. All other connectives are binary connectives (require two propositions). They are also symmetric (except for ).

Translations Between English and Propositional Logic

If I feed my fish, and I change my fish’s tank filter, then my fish will be healthy.

I feed my fish, I change my fish’s tank filter, My fish will be healthy.

Logic02: Syntax

With connectives we can combine propositions. To prevent ambiguity we introduce fully parenthesized expressions that can be parsed uniquely.

We construct the propositional language which is the formal language of propositional logic.

The set of formulas in , denoted by Form(), will then be defined by a set of formation rules which produce expressions in belonging to Form().

Strings in comprise three classes of symbols. Propositional symbols, connective symbols, punctuation symbols (, ).

Two expressions and are equal if and only if they are of the same length and have the same symbols in the same order.

Note for any expression .

Set of Formulas of

Definition

Atom() - is the set of expressions of that consist of a proposition symbol only.

Definition

The set Form(), of formulas of , is defined recursively as: Base: Every atom in Atom() is a formula in Form(). Recursion: If and are formulas in Form(), then:

  1. is a formula in Form()
  2. is a formula in Form()
  3. is a formula in Form()
  4. is a formula in Form()
  5. is a formula in Form()

Restriction: No other expressions in are formulas in Form().

Examples:

are atomic formulas in Atom(), and thus formulas in Form().

and are formulas in Form(), but not atomic formulas in Atom().

is an expression in , but it is neither an atomic formula in Atom(), nor a formula in Form().

Example (Generating Formulas).

The expression,

is a formula. Formulation rules are as follows.

  • are in Form() by Definition of Form() (BASE).
  • is in Form() (RECURSION).
  • and are in Form() (RECURSION).
  • is in Form() (RECURSION applied to and ).
  • is in Form() (RECURSION).

We can use parse trees to analyze formulas.

Every formula in has the same number of occurrences of left and right parentheses.

Any non-empty proper initial segment of a formula in has more occurrences of left than right parentheses. Any non-empty proper terminal segment of a formula in has fewer occurrences of left than right parentheses.

Neither a non-empty proper initial segment nor a non-empty proper terminal segment of a formula can itself be a formula of .

Unique Readability Theorem

Every formula of is of exactly one of the six forms: An atom, , or and in each case, it is of that form in exactly one way.

To prove these claims, we will use mathematical induction.

The statement “every natural number has property ” corresponds to a sequence of statements.

where means holds for .

Principle of mathematical induction:

If we establish two things:

  1. has property , and

  2. whenever a natural number has property , then the next natural number also has property .

Then we may conclude that every natural number has property .

Observations:

To talk about something, give it a name (e.g. property , number ).

A formula is a textual object. In this text, we can substitute one symbol or expression for another. For example, we often put in place of .

The induction principle gives a template for a proof:

  • The proof has two parts: Base Case and Inductive Step.
  • In the Inductive Step, hypothesize and prove from it.

Question

How do we prove properties of formulas?

How to prove a statement along the lines of “Every formula in has property “.

A formula is not a natural number, but it suffices to prove any one of the following.

For every natural number , every formula with or fewer symbols has property .

OR

For every natural number , every formula with or fewer connectives has property .

OR

For every natural number , every formula whose parse tree has height less than or equal to has property .

OR

For every natural number , every formula producible with or fewer uses of the formation rules has property .

Alternatively, we can use the fact that Form() is a recursively defined set, and use structural induction to prove properties about formulas in Form().

Recursively Defined Sets

Inductive definition of sets consist of a universe, core set, and operations (functions).

Given any subset and any set of operations (functions for any ), is closed under if, for every , (say is a ary function) and every .

is a minimal set with respect to a property if

  1. satisfies , and
  2. for every set that satisfies .

We can formally define The minimal subset of that contains , and is closed under the operations in .

Example: The set of Natural numbers:

Structural Induction

The strategy to prove a property holds for every element of a set is as follows.

  1. Prove that holds for every in the core set (the base case).

  2. Prove that, for every ary (for any ), and any such that all hold, we also have that holds (the inductive case).

The core objects are the base, recursion (collection of rules indicating how to form new set objects from those already known to be in the set), restriction (a statement that no objects belong to the set other than those coming from base and recursion).

Examples

The set of natural numbers is a recursively defined set with one formation rule (“add 1”).

  1. Base: is a natural number in

  2. Recursion: If is a natural number in , then is a natural number in .

  3. Restriction: No other numbers are in .

Structural Induction applied to Form()

Suppose is a property. If

  • Every atomic formula Atom() satisfies property , and

  • If formulas and in Form() satisfy property , then:

    1. satisfies property ,

    2. satisfies property ,

    3. satisfies property ,

    4. satisfies property ,

    5. satisfies property ,

it follows that every formula in Form() satisfies property .

We shall prove the following.

Lemma

Every formula in Form() has an equal number of left and right parentheses.

Proof:

We use structural induction. The property to prove is : has an equal number of left and right parentheses for every formula in Form().

Base Case:

is an atom.

has zero left and right parentheses, as it is only a proposition symbol. Thus holds. This completes the proof of the Base Case.

Inductive Step:

Define the notation

  • denotes the number of ’(’ symbols in .

  • denotes the number of ’)’ symbols in .

Subcase of :

Assume is .

Inductive Hypothesis: Formula has property (i.e. ).

Then we have

Subcases ()

Inductive Hypothesis: Formulas and both have property .

To prove: Each of the formulas and has property .

Without loss of generality, we consider .

We calculate :

This concludes the proof of the composite inductive step, the inductive proof and thus the example.

Unique Readability Theorem

Theorem: Every formulas is exactly one of: an atom, and, in each case, it is of that form in exactly one way.

Prove this using structural induction

Base Case: Trivial, as every proposition symbol is an atom.

Inductive Step Idea: We will have to consider e.g., formulas of the form (one of the five subcases of the Inductive Step).

An example of an “implication” formula (a formula of the type , where and are formulas) which we have to consider is , which has , and .

Question: Is this the only way to “parse” the formula ? What about parsing the same formulas as a conjunction of two formulas, that is,

where and .

Fortunately, neither nor is a formula.

Question

Does this proof idea always work?

How can we make sure that such a proof for the Inductive Step works for every formula ?

That is, if we have a formula where and are both formulas, and , how can we argue that neither nor can be a formula?

Hint: Can or have an equal number of left and right parentheses.

If not, why not?

To do the proof, we actually need to know more about formulas. This illustrates a common feature of inductive proofs: they often prove more than just the statement given in the theorem.

Proof:

Property :

Every formula containing at most connectives satisfies all three of the following properties:

(a) The first symbol of is either ’(’ or a proposition symbol.

(b) has an equal number of ’(’ and ’)’, and each non-empty proper initial segment of has more ’(’ then ’)‘.

(c) has a unique construction as a formula.

We will prove that the property holds for all , by induction on (the number of connectives).

Base Case: The statement holds for (a formula with connectives is a proposition symbol, it has left and right parentheses, and has no non-empty proper initial/terminal segments).

Inductive Step:

Inductive Hypothesis: holds for some natural number .

To show that holds, let formula have connectives.

The proof of the Inductive Step has five subcases, one for each of the formation rules (connectives) in the recursive definition of Form().

First subcase: , where is the st connective, and the inductive hypothesis is that has properties (a), (b), and (c).

(a): By construction, has Property (a), since it begins with ’(‘.

(b): Since has an equal number of left and right parentheses, so does . For the second part of Property (b), we check the following subcases of every possible non-empty proper initial segment, x, of :

  1. is ”(”: Then has one ”(” symbol, and no ”)” symbols.

  2. is ”(”: Then has one ”(” symbol, and no ”)” symbols.

  3. is ”(”, for some non-empty proper initial segment of : Since by Inductive Hypothesis, has more ”(” than ”)” symbols, so does .

  4. is ”(”: Since has equally many ”(” and ”)” symbols, has more ”)” than ”(” symbols.

In every case, has more ”(” than ”)” symbols. Hence has Property (b).

(c): Because has Property (c), by construction so does .

The other four subcases: Assume that , for some formulas and , where st connective is the binary connective .

Inductive Hypothesis: Both and have properties (a), (b), (c). Verifying properties (a), (b) for is analogous to the case of .

We prove only (c). First, we show that formula cannot be decomposed in two different ways, with two binary connectives, as , for formulas . Equivalently:

If the same formula can be decomposed as , for formulas and and binary connective , then and .

Note: means that and are two different compositions of the same formula (same length and the same sequence of symbols, in the same order).

Recall that .

Case (1): If has the same length as , then they must be the same string (both start at the second symbol of ).

Case (2): is a non-empty proper prefix of . Since and are formulas with at most connectives, the inductive hypothesis applies to them. In particular, they have property (b).

Since has the first half of property (b), should have an equal number of left and right parentheses.

Since has the second half of property (b), and since is a non-empty proper prefix of the formula , it follows that should have strictly more left than right parentheses.

We reached a contradiction, so Case (2) cannot hold.

Case (3): is a non-empty proper prefix of - impossible, using a similar reasoning as in Case (2).

Since Case (2) and Case (3) are impossible, the only case that can hold is Case (1), whereby the two decompositions of the formula must coincide. Thus, has a unique construction, as required by (c).

Second, we show that formula cannot be decomposed in two different ways, once with a binary and once with unary connective, as for formulas .

Assume that . If we delete the first symbol from both and we obtain . Then, the formula starts with , a contradiction with part (a) of the inductive hypothesis. Hence, this second situation cannot hold.

Since these are the only two possibilities for , this proves the unique construction of , as required by Property (c).

We will define the semantics (meaning) of a formula from its syntax (its structure, as determined by the formation rules).

Unique readability ensures unambiguous formulas. How?

Given a formula, determine its subformulas by counting parentheses.

Precedence rules:

has precedence over

has precedence over

has precedence over

has precedence over

Examples:

is to be understood as .

is to be understood as .

And so on.

Suppose .

The scope of the first is and of the second is .

The left and right scopes of are and .

And so on.

Logic03: Semantics

Syntax is concerned with the rules used for constructing the formulas in Form(). This is similar to computer science, where syntax refers to the rules governing the composition of well-formed expressions in a programming language.

Semantics is concerned with meaning. Atoms are intended to express simple propositions (sentences). The connectives take their intended meanings express “not”, “and”, “or”, “if, then”, and “iff”. The meaning of a non-atomic formula, that is, its truth value is derived from the truth values of its constituent atomic formulas, and the meanings of the connectives.

Example:

If you take a class in computers and if you do not understand recursion, you will not pass.

We want to know exactly when this statement is true and when it is false.

Define:

“You take a class in computers.”

“You understand recursion.”

“You pass.”

The statement becomes .

The truth table for is

1110001
1100011
1011100
1001111
0110001
0100011
0011001
0001011

Two propositional formulas and in Form() are called (logically) equivalent (denoted ) if for every truth valuation, . (Equivalently, if and have the same truth table.)

A truth table list the values of a formula under all possible truth valuations.

Fix a set of truth values. We interpret as false and as true.

Definition

Definition. A truth valuation is a function with the set of all proposition symbols as domain and as range.

Convention: For we denote the value that takes under truth valuation .

In practice, we restrict the truth valuation to the set of proposition symbols in the formulas under consideration.

Then, a truth valuation corresponds to a single row in the truth table.

Definition

Let be a truth valuation. The value of a formula in Form() with respect to the given truth valuation is defined recursively as follows:

  1. If the formula is a proposition symbol , then given by the definition of .

Suppose is the formula , and is a truth valuation such that .

Then we have and therefore .

Suppose is another truth valuation, . Then we have and therefore .

If is yet another truth valuation, with and then .

The above example illustrates that, for a particular formula, its value under one truth valuation may (or may not) differ from its value under a different truth valuation.

Definition

We say that a truth valuation satisfies a formula in Form() iff .

We use the capital Greek letter to denote any set of formulas.

Definition

Definition: The value of a set of formulas under truth valuation is defined as:

Definition

A set of formulas Form() is satisfiable if and only if there exists a truth valuation such that . If, in the other hand, there is no truth valuation such that (or, equivalently, if for all truth valuations ), then the set is called unsatisfiable.

Observations:

  1. If for a truth valuation we have that , then is said to satisfy , and is said to be satisfied by (under) t.

  2. Note that means that under the truth valuation , all the formulas of are true.

  3. On the other hand, means that for at least one formula , we have that .

  4. In particular, does not necessarily mean that for every formula in .

Definition

A formula is a tautology if and only if it is true under all possible truth valuations, i.e. iff for any truth valuation , we have that .

Definition

A formula is a contradiction if and only if it is false under all possible truth valuations, i.e. iff for every truth valuation , we have that .

Definition

A formula that is neither a tautology nor a contradiction is called contingent.

The law of excluded middle (“tertium non datur”) states that is a tautology.

If is a tautology that contains the proposition symbol , one can determine a new expression by replacing all instances of by an arbitrary formula. The resulting formula is also a tautology.

For example, is a tautology.

Replace all instances of by any formula we like, say by . The resulting formula is again a tautology.

Theorem

Let be a tautology and let be the proposition symbols of . Suppose that are arbitrary formulas. Then, the formula obtained by replacing by , by by , is a tautology.

Important Contradiction - Law of contradiction: “Nothing can both be, and not be”, that is, is a tautology, equivalently, is a contradiction.

Contradictions and tautologies are related. is a tautology if and only if is a contradiction. Being satisfiable is the negation of being a contradiction.

Logical arguments consist of Premises followed by a Conclusion. Arguments can be Correct (valid, sound) or Incorrect (invalid, unsound).

Definition

Suppose Form() and Form().

is a tautological consequence of (that is, of the formulas in ), written as , for any truth valuation , we have that implies .

Observations:

  • is not a symbol of the formal propositional language and is not a formula.

  • is a statement (in the metalanguage) about and .

  • We write for “not “.

  • If , we say that the formulas in (tauto)logically imply formula .

When is the empty set, we obtain the important special case of tautological consequence, .

By definition, means that the following holds: “For any truth valuation , if then .” where means “For any , if then “.

Because is false, "" is always (vacuously) true. Consequently, means that is always true (is a tautology).

Intuitively speaking, means that the truth of the formulas in is a sufficient condition for the truth of .

Since has no formulas, means that the truth of is unconditional, hence is a tautology.

Let Form() be a set of formulas (premises) and Form() be a formula (conclusion). The following are equivalent.

  • The argument with premises and conclusion is valid.

  • is a tautology.

  • is a contradiction.

  • The formula is not satisfiable.

  • The set is not satisfiable.

  • is a tautological consequence of , i.e. .

Consider an argument with premises and conclusion .

The conclusion is true, if the following two conditions hold:

  • The argument with premises and conclusion is valid (sound, correct),

  • The premises are all true.

The validity of an argument does not guarantee the truth of the conclusion. Only when the argument is valid and the premises are all true, is the conclusion guaranteed to be true.

Definition

For two formulas, we write to denote "" and "".

and are said to be tautologically equivalent (or simply equivalent) if and only if holds.

Tautological equivalence is weaker than equality of formulas. For example, if and then , as can be proved by a truth table, but .

Note that,

if and only if is a tautology.

is a formula, which can be true or false.

means that is a tautology.

if and only if is a tautology.

is a formula, which can be true or false.

means that is a tautology.

To prove that the tautological consequence (prove the validity of the argument with premises and conclusion ) we must show that any truth valuation satisfying also satisfies . One way to show this is by using truth tables.

Example: Show that

The premises are and ; the conclusion is .

The truth valuations in rows 1,5,7,8 (with ) are all the truth valuations which make all premises true, that is, which satisfy . For each of these four truth valuations, the conclusion is also true (is satisfied).

This shows that

This further means that the argument

Premise 1:

Premise 2:

Conclusion:

is a valid argument.

Proving that an argument is not valid

Example: Prove that

Solution: Find at least one row in the truth table in which the premises are true but the conclusion is false.

The row in the truth table that corresponds to the truth valuation which assigns is one such counterexample.

  • Note that several such truth valuations may exist

  • We only need one such truth valuation (that makes all premises true but the conclusion false), in order to prove that an argument is not valid.

Truth tables get large fast. If a formula has proposition symbols and occurrences of connectives, we get rows and columns. We need another method for proving argument validity.

We can prove by contradiction (different than the word “contradiction” in propositional logic).

Example: Show that .

Proof: Assume the contrary, that is,

This means that there is a truth valuation that makes all premises true but the conclusion false, that is,

(4) By (3), we have that and

(5) By (1) and the fact that , we have

From and (2), we deduce , which contradicts (4).

Since we have reached a contradiction, our assumption that the argument was invalid was false, hence the opposite is true: The argument is valid.

To prove we must construct a counterexample. A truth valuation satisfying but not satisfying .

Example: Show that

Let be the truth valuation .

Then we have

We have found a counterexample (truth valuation that makes all premises true but the conclusion false), hence the argument is invalid.

De Morgan’s Law

Consider the following two statements:

It is not true that he is informed and honest.

He is either not informed, or he is not honest.

Intuitively, these two statements are logically equivalent.

The first statement translates to , whereas the second into .

De Morgan’s Law:

Dual De Morgan’s Law:

De Morgan’s Laws are used to negate conjunctions and disjunctions, and show how to distribute over , and over .

To negate a conjunction, take the disjunction of the negations of the conjuncts.

To negate a disjunction, take the conjunction of the negations of the disjuncts.

Definition

Given an implication of the form , the formula is called the contrapositive of , and the formula is called the converse of .

Via truth table, it is obvious that .

We can use this fact in our proofs. Sometimes, it is easier to prove the contrapositive instead of a direct proof.

Note that the converse of an implication is not equivalent to it.

It is also obvious that .

Tautological Equivalences

Lemma: If and , then

Theorem: Replaceability of tautologically equivalent formulas

Let be a formula which contains a subformula . Assume that , and let be the formula obtained by simultaneously replacing in some (but not necessarily all) occurrences of the formula by formula , then .

Theorem: Duality

Suppose is a formula composed only of atoms and the connectives , by the formation rules concerned these three connectives. Suppose results from simultaneously replacing in all occurrences of with , all occurrences of with , and each atom with its negation. Then .

Both of these proofs are by structural induction.

This table is handy.

Not satisfiableContradictionYes
Not satisfiableSatisfiable, not a tautologyYes
Not satisfiableTautologyYes
SatisfiableContradictionNo
SatisfiableSatisfiable, not a tautologyMaybe
SatisfiableTautologyYes

Logic04: Propositional Calculus: Essential Laws, Normal Forms

In standard algebra, expressions in which the variables and constants represent numbers are manipulated. Consider for instance the expression .

This expression yields .

In fact, we are so accustomed to these manipulations we are not aware of what is behind each step.

Here we use the identities:

Consider the formula .

This formula can be simplified in a similar way, except that (tauto)logical equivalences take the place of algebraic identities.

We can now apply these tautological equivalences to conclude

Since the symbolic treatment of and is relatively cumbersome, one usually removes them before performing further formula manipulations.

To remove the connective one uses the logical equivalence

There are two ways to remove the connective :

Example: Remove and from the following formula:

Solution:

Essential Laws for Propositional Calculus

LawName
Excluded Middle Law
Contradiction Law
Identity Laws
Domination Laws
Idempotent Laws
Double-Negation Law
Commutativity Laws

Associativity Laws
Distributivity Laws

De Morgan’s Laws

These laws allow us to simplify formulas, and it is a good idea to apply them whenever possible.

All of these laws can be proved by the truth table method.

With the exception of of the double-negation law, all laws come in pairs (called dual pairs).

The commutativity, associativity and distributivity laws have their equivalents in standard algebra.

We can derive further laws, for example, the absorption laws

Another important law (and its dual):

Definition

A formula is called literal if it is of the form or , where is a proposition symbol. The two formulas and are called complementary literals.

We can simplify conjunctions and disjunctions using certain rules.

If a conjunction contains complementary literals, it is a contradiction. If a disjunction contains complementary literals, or of it contains a 1, it is a tautology.

Example: Simplify the formula

Solution:

Normal Forms

Formulas can be transformed into standard forms so that they can become more convenient for symbolic manipulations and make identification and comparison of two formulas easier.

There are two types of normal forms in propositional calculus: the Disjunctive Normal Form and the Conjunctive Normal Form.

Definition

A disjunction with literals as disjuncts is called a disjunctive clause. A conjunction with literals as conjuncts is called a conjunctive clause.

Examples:

  • is a disjunctive clause

  • is a conjunctive clause

  • or is a (degenerate) disjunctive clause with one disjunct, and a (degenerate) conjunctive clause with one conjunct.

Disjunctive and conjunctive clauses are simply called clauses.

Definition

A disjunction with conjunctive clauses as its disjuncts is said to be in Disjunctive Normal Form (DNF). A conjunction with disjunctive clauses as its conjuncts is said to be in Conjunctive Normal Form (CNF).

Examples:

  • and is in disjunctive normal form.

  • The formula is not in disjunctive normal form.

  • Each of and is in conjunctive normal form.

  • The formula is not in conjunctive normal form.

A formula in Disjunctive Normal Form (DNF) is of the form where and are literals for and . The formulas are the conjunctive clauses of the formula in DNF.

A formula in Conjunctive Normal Form (CNF) is of the form , where and are literals for and . The formulas are the disjunctive clauses of the formula in CNF.

Examples

is an atom, and therefore a literal.

It is a disjunction with only one disjunct.

It is also a conjunction with only one conjunct.

Hence it is a disjunctive or conjunctive clause with one literal.

It is a formula in disjunctive normal form with one conjunctive clause .

It is also a formula in conjunctive normal form with one disjunctive clause .

is a conjunction of three literals, and a formula in conjunctive normal form with three clauses. It is also a conjunctive clause, and a formula in disjunctive normal form, with one conjunctive clause, .

is a formula in conjunctive normal form with three disjunctive clauses, . It is not a formula in disjunctive normal form.

Question

How do we obtain normal forms?

Use the following tautological equivalences:

By the Theorem of Replaceability of Tautologically Equivalent Formulas, we can use the equivalences above to convert any formula into a tautologically equivalent formula in normal form.

Example

Convert the following formula into a conjunctive normal form .

The conjunctive normal form can be found by the following derivations:

Algorithm for Conjunctive Normal Form

  1. Eliminate equivalence and implication, using and .

  2. Use De Morgan and double-negation to obtain an equivalent formula, where each symbol has only an atom as its scope.

  3. Recursive procedure :

    1. If is a literal then return

    2. If is then return

    3. If is then

      • Call and

      • Suppose

      • Suppose

      • Return

      • Note: The last step is similar to using distributivity to expand

Example of Step 3.3 in converting to CNF

  • clauses

  • clauses

  • The resulting CNF will have clauses

  • It can be further simplified

Existence of Normal Forms

Theorem

Any formula Form() is tautologically equivalent to some formula in disjunctive normal form.

Proof

If is a contradiction, then is tautologically equivalent to the DNF being any atom occurring in .

If is not a contradiction, we employ the following method (this is the idea of the proof worked out on an example, not the full proof).

Suppose has three atoms, occurring in , and the value of is 1 if and only if or or are assigned to respectively.

For each of these truth valuations, we form a conjunctive clause with three literals, each being one of the atoms or its negation, according to whether this atom is assigned 1 or 0:

and

Due to the definition of the connective , we have that:

  • has value 1 are assigned to

  • has value 1 are assigned to

  • has value 1 are assigned to

Therefore, the following DNF is tautologically equivalent to A:

Note: If is a tautology, the required DNF may simply be where is any atom occurring in .

Similarly, we have:

Theorem

Any formula Form() is tautologically equivalent to some formula in conjunctive normal form.

Disjunctive Normal Forms from Truth Tables

Obtaining the DNF from truth tables is straight-forward.

Conjunctive Normal Form from Truth Tables

Duality can be used to obtain conjunctive normal forms from truth tables. Recall that, if is a formula containing only the connectives and , then its dual, , is formed by replacing all by all by , and all atoms by their negations.

Example: The dual of the formula is .

Recall that by the Duality Theorem, . Also note that, if a formula is in DNF, then its dual can easily be transformed into an equivalent formula in CNF, using double-negation if necessary.

This idea can be used to find the conjunctive normal form from the truth table of a formula .

CNF of obtained from the truth table of .

  • Determine the disjunctive normal form of .

  • If the resulting DNF formula is , then .

  • Compute , by the Duality Theorem.

  • .

  • is in CNF, or can be changed into CNF by using .

Example

The DNF of , based on the truth table for , is the formula:

The CNF for is equivalent to the dual of formula , namely

Logic05: Adequate Set of Connectives, Logic Gates, Circuit Design, Code Simplification

Connectives

Formulas and are tautologically equivalent. Then is said to be definable in terms of (or reducible to) and . is definable in terms of and , as .

We have mentioned so far one unary, and four binary connectives.

There are many more unary and binary connectives, and also ary connectives, for .

We shall use letters , etc., (with or without subscripts) to denote any connectives. We shall write

for the formula formed by an ary connective connecting formulas .

A connective is defined by its truth table. Two ary connectives, are the same if and only if they have the same truth tables.

Question

How many distinct unary connectives are there?

Note that is the negation of , that is .

How many distinct ary connectives are there?

For an ary connective, the truth table has rows, and the number of possible distinct ary connectives equals the number of possible distinct columns of a truth table with rows, which in turn equals the number of possible binary numbers of length (length of binary number height of truth table column). Thus the answer is .

Adequate Set of Connectives

Definition

Any set of connectives with the capability to express any truth table is said to be adequate.

Emil Post observed in 1921 that the set of five standard connectives , is adequate.

Definition

A set of connectives is called adequate if and only if any ary connective can be defined in terms of the connectives in .

Theorem

The set is an adequate set of connectives.

Proof: Let be an arbitrary ary connective.

We want to find a formula , using only connectives in , such that .

  • Construct the truth table for the connective

  • Use the theorem about the existence of Disjunctive Normal Forms to obtain a formula , in DNF, with .

  • By construction, uses only connectives in .

  • We can show that a new set of connectives is adequate by showing that all connectives in (which we already proved adequate) are definable in terms of the new connectives in .

  • More precisely, given any ary connective , the previous theorem states that is a formula that uses only connectives in .

  • If we can show that there exists a formula , using only connectives in , such that , then we have .

  • The existence of the formula is proved by showing that each of the connectives in is definable in terms of the connectives , and by invoking the Replaceability Theorem.

  • This proves the adequacy of .

Corollary

Corollary: Show that and are adequate.

Proof: We show that is an adequate set of connectives. By the previous theorem, for any ary connective there exists a formula , using only connectives in with .

  • Consider the formula , using the three connectives in .

  • Goal: A formula equivalent to , using only connectives in .

    • in is also a connective in , no change needed to .

    • in is also a connective in , no change needed to .

    • in is not a connective in . Remove all occurrences of in , by using the equivalence . The resulting formula, , uses only connectives in .

  • By the Replaceability Theorem,

  • Thus, contains only connectives in , and we have that .

Peirce Arrow

The binary connective , is also called Peirce arrow, (after C.S. Peirce, 1839-1914), or NOR, and denoted by , is defined as:

Proof that Peirce arrow is adequate.

Since we showed that the set is adequate, to show that is adequate it suffices to prove that one can define each of the three connectives in in terms of the Peirce , as follows:

Thus it follows that the set , consisting of a single binary connective NOR, is adequate.

Note: To express a standard connective in terms of new connectives, we can write the truth table of the standard connective, and try writing formulas using various combinations of the new connectives, until we find a formula that gives the same truth values as the standard connective.

Proof that Sheffer stroke is adequate.

The binary connective also called Sheffer stroke, "", (after H.M Sheffer, 1882-1964), or NAND, is defined by:

One can express the standard connectives in in terms of "", by:

Thus, the set consisting of a single connective, NAND, is also adequate.

Proving Inadequacy

Question

How do we show that a set of connectives is not adequate?

We show that one of the connectives in the adequate set cannot be defined by using the connectives in .

Example

Prove that the set is not adequate.

Proof:

Claim: A formula depending on only one atom , and using only the connective , has the property that its truth value under a truth valuation with is always (proof by induction).

Assume now that were adequate. This implies that we could define the negation in terms of , which implies that we could find a formula depending only on , and using only the connective , such that .

However, due to the Claim, for a truth valuation such that , we have that . This implies that and cannot be tautologically equivalent (since ) - a contradiction.

Let us use the symbol for the ternary connective whose truth table is given by

Note that, for any truth valuation , we have equals if , and equals if .

This is the familiar if-then-else connective from computer science, namely if then else .

This is one of the distinct ternary connectives.

George Boole, author of “An Investigation of the Laws of Thoughts”, has been fundamental in the development of digital electronics.

Definition

A Boolean algebra is a set , together with two binary operations and , and a unary operation . The set contains elements and , is closed under the application of and , and the following properties hold for all in .

  • Identity Laws: and

  • Complement Laws:

  • Associativity Laws: .

  • Commutativity Laws: .

  • Distributivity Laws: and .

The set of formulas in Form(), with the and operators, the operator, 0 and 1, and where is , is a Boolean algebra.

The set of subsets of a universal set , with the union operator , the intersection operator , the set complementation operator , the empty set , and the universal set , is a Boolean algebra.

Note that, using the laws given in the definition of a Boolean algebra, it is possible to prove many other laws that hold for every Boolean algebra.

Thus to establish results about propositional logic, or about sets, we need only prove results about Boolean algebra.

Logical EquivalencesSet Properties


Boolean algebra is used to model the circuitry of electronic devices, including electronic computers.

Such a device has inputs and outputs from the set .

A Boolean variable is a variable that can take values in the set (1/true and 0/false are also called Boolean constants).

An variable Boolean function is a function

An electronic computer is made up of a number of circuits, each of which implements a Boolean function.

The basic elements of circuits are called logic gates, and they implement the three Boolean operators .

A logic gate is an electronic device that operates on a collection of binary digits (bits, in ) and produces on binary output.

Each circuit can be designed using the laws of Boolean algebra.

Logic gates are physically implemented by transistors.

A transistor is simply a switch, it can be in an off state, which does not allow electricity to flow, or in an on state, in which electricity can pass unimpeded.

Each transistor contains three lines: two inputs lines and one output line. The first input line, called the control line, is used to open or close the switch inside the transistor.

ON states is used to represent the binary 1, and the OFF state can be used to represent the binary 0.

This solid-state switching device, the transistor, forms the basis of construction of virtually all computers built today, and it is thus the fundamental building block for all high-level computers.

However, there is no theoretical reason why we must use transistors as our elementary devices when designing computer systems.

In fact, binary computers can be built out of any bistable device.

In principle, it is possible to construct a binary computer using any bistable device that meets the following four conditions:

  • It has two stable energy states.

  • These two states are separated by a large energy barrier.

  • It is possible to sense what state the device is in without permanently destroying the stored value.

  • It is possible to switch from a 0 to a 1 and viceversa by applying a sufficient amount of energy.

Basic Logic Gates

NOT

An inverter, or a NOT gate, is a logic gate that implements negation (). It accepts the value of a Boolean variable as input, and produces the negation of its value as its output.

NOR

To construct the negation of OR, we use two transistors connected in parallel.

If either or both of the liens Input-1 and Input-2 are set to 1, then the corresponding transistor is in the ON state, and the output is connected to the ground, producing an output value of 0.

Only if both input lines are 0, effectively shutting off both transistors, will the output line contain a 1.

This is the definition of the negation of OR, and this gate is called NOR gate.

OR

The OR gate can be implemented using a NOR gate and a NOT gate.

The inputs to this gate are the values of two Boolean variables. The output is the Boolean sum (denoting ) of their values.

NAND

Negation of AND (which we already know).

AND

AND gate can be implemented using a NAND gate and a NOT gate.

In circuit design, we use the following notations:

  • denotes

  • and both denote

  • denotes

  • denotes tautological equivalence

We sometime permit multiple inputs to AND gates (top) and OR gates (bottom), as illustrated below. (see pdf)

Non-standard gates: Toffoli gate

It has a 3-bit input and 3-bit output: If the first two bits are both 1, it inverts the 3rd bit, otherwise all bits stay the same.

Toffoli gates and Quantum Computing

  • The Toffoli gate is a universal, reversible logic gate. It is:

  • (1) Universal: All truth tables are implementable by Toffoli gates

  • (2) Reversible: Given the output, we can uniquely reconstruct the input (e.g., is reversible, but is not)

  • The Toffoli gate can be realized by five 2-qubit quantum gates.

  • This implies that a quantum computer using Toffoli gates can implement all possible classical computations.

  • A quantum-mechanics-based Toffoli gate has been successfully realized in January 2009 at the University of Innsbruck, Austria.

Combinational circuits

  • Combinational logic circuits (sometimes called combinatorial circuits) are memoryless digital logic circuits whose output is a function of the present value of the inputs only.

  • A combinational circuit is implemented as a combination of NOT gates, OR gates, and AND gates. In general such a circuit has inputs and outputs in .

  • In contrast, sequential logic circuits - not described in this course - are basically combinational circuits with the additional properties of storage (to remember past inputs) and feedback.

Example:

Design a circuit that produces the following output.

(1)

(See pdf)

Design a circuit that accomplishes a task

Example 1: A committee of three individuals decides issues for an organization. Each individual votes either “yes” or “no” for each proposal that arises. A proposal is passed if and only if it receives at least two “yes” votes. Design a circuit that determines whether a proposal passes.

Solution: Let if the first individual votes “yes”, and if this individual votes “no”, and similarly for and .

Then a circuit must be designed that produces output 1 (proposal passes) from the inputs if and only if two or more of are 1.

Note that a Boolean function that has these output values is .

Example 2: Sometimes light fixtures are controlled by more than one switch. Circuits need to be designed so that flipping any one of the switches for the fixture turns the light on when it is off, and turns the light off when it is on. Design a circuit that accomplishes this task, when there are three switches.

Solution: The inputs are three Boolean variables , one for each switch. Let if the first switch is closed, and if it is open, and similarly for and .

The output function is defined as if the light is on, and if the light is off.

We can choose to specify that the light be on when all three switches are closed, so that .

This determines all the other values of .

The formula in DNF corresponding to this truth table is

Adders:

  • Logic circuits can be used to carry out addition of two positive integers from their binary expansions.

  • Recall that, e.g., the binary (base 2) expansion/representation of the integer 2 is , of 8 is , of 9 is , etc.

  • We will build up the circuitry to do addition of two positive integers in binary representation, from some component circuits.

  • First we build a circuit that can be used to find when and are each a single bit (0 or 1).

  • The input to our circuit will be two bits, and .

  • The output will consist of two bits, namely and , where is the sum bit and is the carry bit.

  • This circuit is a multiple output circuit.

  • It has two input bits , and it adds them up (in binary), producing two outputs: (the sum bit) and (the carry bit).

  • The circuit we are designing is called the half-adder since it adds two its, without considering a carry from the previous addition

  • From the truth table we see that and

  • If we use this fact that we obtain a circuit with fewer gates (4 instead of 6).

The full-adder is used to add two numbers , and , in their binary representation, for all .

The addition proceeds from right to left. To add to one uses a half-adder. Subsequently, at each step, a full-adder takes three bits as input (, and the carry bit from the previous addition), and it adds them up (in binary) producing two outputs, the sum bit , and the next carry bit (not shown in figure).

Truth table for the full-adder:

Input: Bits and and the carry bit .

Output: The sum bit and the carry bit

Formulas for outputs of the full-adder

From the truth table we obtain the following formulas in DNF, equivalent to and :

Circuit Minimization Through Formula Simplification

Consider the circuit that has output 1 if and only if or and .

The formula corresponding to its truth table is . Simplify: .

is a Boolean expression with fewer operators that represents the circuit, thus the corresponding simplified circuit will have fewer logic gates.

Thus, one can use the essential laws for propositional logic to minimize circuits.

Analyzing and simplifying code through logic formula simplification.

Consider the code fragment:

(see pdf)

where are true/false conditions (formulas in propositional logic), and are sub-fragments of code.

We will prove that is dead code without a truth table.

Dead code is code that is never executed. The condition for to be executed is

Since this condition can never be true, this means that can never be executed. Thus it is dead code.

We can simplify this code (via truth tables or inspection) to get

(see pdf)

Logic06: Formal Deduction in Propositional Logic

Formal Deducibility

We have seen how to prove arguments valid by using truth tables and other semantic methods (tautological consequence, "").

We now want to replace this approach by a purely syntactic one, that is, we give formal rules for deduction which are purely syntactic.

We want to define a relation called formal deducibility (denoted by "") that will allow us to mechanically/syntactically check the correctness of a proof that an argument is valid.

The intuitive meaning of "" is similar to the meaning of "", in that it signifies argument validity. However, the method of proving validity is different.

The word “formal” signifies that we will be concerned only with the syntactic form of formulas. The proofs themselves will not refer to any semantic properties. The correctness of the proof can be checked mechanically.

Formal deducibility is a relation between a set of formulas (called the premises) and a formula (called the conclusion).

We use the symbol "" to denote the relation of formal deducibility and write

to mean that is formally deducible (or provable) from . Note that is semantics; and is syntactic.

For convenience, we will write sets as sequences.

  • If is a set of formulas, then may be written as a sequence, .

  • Since the premises are elements of a set, the order in which premises in are written does not matter.

  • The set , where is a formula, may be written as .

  • If and are sets of formulas, may be written as .

For any formulas, and , and any set of formulas:

(1)(Ref) is a theorem(Reflexivity)
(2)If is a theorem then is a theorem.(Addition of premises)
(3)If is a theorem and is a theorem then is a theorem.( elimination)
(4)If is a theorem and is a theorem then is a theorem.( elimination)
(5)If is a theorem then is a theorem.( introduction)
(6)If is a theorem then is a theorem and is a theorem.( elimination)
(7)If is a theorem and is a theorem then is a theorem.( introduction)
(8)(If is a theorem and is a theorem then is a theorem.( elimination)
(9)If is a theorem then is a theorem and is a theorem( introduction)
(10)If is a theorem and is a theorem, then is a theorem.( elimination)
If is a theorem and is a theorem then is a theorem.
(11)If is a theorem and is a theorem then is a theorem.( introduction)

Note: Each of the above rules is really a template, or scheme, for infinitely many rules. Each of may be any formula; may be any set of formulas.

We can use the 11 rules to prove new theorems.

Example 1: Prove the following theorem, called “membership rule”:

Proof: Suppose and (thus, is ).

  • Step (1) is generated directly by the rule (Ref).
  • Step (2) is generated by the rule (), which is applied to Step (1).
  • At each step, the rule applied, and the preceding steps cited (if any), form a justification for this step, and are written on the right.
  • These steps constitute a formal proof of the last step, .
  • Having been formally proven, () is now a theorem.

Hypothetical Syllogism by Formal Deduction

Example 2: Prove that

The following sequence of 6 steps is a proof.

Each step applies either one of the rules of formal deduction, or a theorem which we have already proved, e.g., ().

On the right are written justifications for the steps.

These six steps form a formal proof of , which is generated at the last step.

The formal rules of deduction do not specify the use of “proved theorems”. Why is this legitimate?

Instead of invoking a proved theorem, we could insert its proof.

For example, in the previous proof, instead of Step (1)

we could write an instance of the proof of :

A demonstrated (that is, for which we have a formal proof) is called a scheme of formal deducibility, or a theorem.

Rules of formal deduction are purely syntactic. For instance, from two (not necessarily consecutive) “lines” in a proof

we can generate the new line , by applying .

Therefore it can be checked mechanically whether the rules of formal deduction are used correctly.

Intuitive meaning of rules:

expresses the method of proof by contradiction. Say we want to prove theorem , that is, prove that from the set of premises we can formally deduce the conclusion .

A “proof by contradiction” would start by assuming that the conclusion does not hold. Formally, this amounts to adding its negation, , to the set of premises.

If the premises in together with this new assumption lead to a contradiction (two formulas and ), that is, if we prove that and , then we can conclude that our assumption was wrong, and that the proposition is deducible from the premises, that is, .

expresses that to prove “If then ” from certain premises , that is, if we want to prove , it is sufficient to prove from the premises together with (that is, it suffices to prove ).

In other words, if the conclusion is an implication, , then the antecedent of the implication, , can be considered to be an additional premise that we can use to prove (both and are assumptions that we make when trying to prove ).

If, together with this additional premise, we can prove the consequent of the implication (that is, if we can prove ), then we can conclude that .

Essentially, states that an assumption (premise) may be converted into the antecedent of a conditional.

Definition of Formal Deducibility ()

A formal deduction system is specified by a set of deduction rules.

A formula is formally deducible from , written as , iff is generated by (a finite number of applications of) the rules of formal deduction.

By the above definition, holds iff there is a finite sequence

such that each term is generated by one rule of formal deduction, and is (that is, and ).

To check whether a sequence of steps is indeed a formal proof of a “scheme of formal deducibility” (theorem), we:

  • Check whether the rules of formal deduction are correctly applied at each step, and
  • Check whether the last term of the formal proof is identical with the desired scheme of formal deducibility (theorem).

In this sense, rules of formal deduction and formal proofs serve to clarify the concepts of inference and proofs from informal reasoning.

The sequence of rules generating is called a formal proof.

A scheme of formal deducibility may have various formal proofs. Perhaps one may not know how to construct a formal proof for it.

It is significant however that any proposed formal proof for a theorem can be checked mechanically to decide whether it is indeed a formal proof of this theorem.

Question

How do we find a proof?

A useful idea is to work in reverse.

If is what we want to prove (hence the last line of its proof), what rule of formal deduction could produce this line, from previous lines?

The rule provides a way to produce an implication such as "".

Recall (): If then . That is, to produce an implication in the conclusion, , we can first prove , and then apply () to it.

Here, take to be , and to be .

Thus, if we could prove , as the 2nd last step of the proof, then one application of , would finish the proof.

Tautological Consequence vs Deducibility

Tautological consequence () and formal deducibility ( are different matters. Former belongs to semantics, latter belongs to syntax.

The connection between and is that is a tautology.

The connection between and is that .

The definition of formal deducibility is a recursive definition of the set of the proved schemes of formal deducibility (theorems):

  • Rule (REF) is the BASE (similar to atoms being formulas in the recursive definition of Form());
  • The other ten rules of formal deduction are the RECURSION (similar to the five formation rules for formulas).

Statements concerning formal deducibility can be proved by structural induction on its structure (of generation).

The BASE CASE of structural induction is to prove that , generated directly by rule (Ref), has a certain property.

The (COMPOSITE) Inductive Step is to prove that the other ten rules preserve the property.

Theorem

Finiteness of premise set

If , then there exists a finite such that .

Proof: By induction on the structure of .

Base Case: The set of premises in , generated by (Ref), is a set of cardinality one, hence finite.

Inductive Step: We distinguish ten cases. For each case, assume that the cited theorems have the property, and prove that the derived theorem has the property.

Case of : “If , and , then “. By the Inductive Hypothesis, the cited theorems have the property, that is, there exist finite sets such that and . By () we have , as well as .

Then by , we have , where is a finite subset of .

Theorem

Transitivity of Deducibility

Let Form(). If and , then .

Proof:

A useful theorem: Double-negation

Theorem

.

Proof:

Note: When applying in step (3), we take:

Theorem

Reductio ad absurdum,

If and , then .

Proof: We will only prove the theorem for the case when is finite.

In case is infinite, the proof is similar, but one has to invoke the Finiteness of Premise Set theorem, similar to the way it is done in the proof of (Tr).

The theorem of reductio ad absurdum is denoted by (). and both formalize the idea of “proof by contradiction”, and are similar in shape but different in strength.

is stronger than in the following sense.

Definition

For two formulas and we write to mean and . (Note the real symbol looks more like \vdash \dashv)

and are said to be syntactically equivalent iff holds.

We write to denote the converse of .

Lemma. If and then

Note the resemblance to analogous results about tautological equivalences , which are semantic.

Theorem

Replaceability of syntactically equivalent formulas (Repl).

Let . For any , let be constructed from by replacing some (not necessarily all) occurrences of by . Then .

Theorem

Theorem

.

When the set of premises is empty we have the special case of formal deducibility.

Obviously, for any .

It has been mentioned before that is said to be formally provable from when holds.

Definition

Definition: If holds, then formula is called formally provable.

The laws of non-contradiction and excluded middle are instances of formally provable formulas, that is, and .

Question

Why do we need formal deduction?

One of the things that sets mathematics/computer science apart from poetry, biology, engineer, etc., is the insistence upon proof.

Our goal with tautological consequence () and formal deducibility () was to define a proof system called formal deduction with which we could prove formally everything that is correct semantically.

This approach is similar to axiomatic geometry, in the sense that we accept as correct only those theorems that have a formal proof, based on the 11 rules.

Consider a system of formal deducibility, defined by a certain number of formal deduction rules.

For this system of formal deduction to be “good”, it has to be connected to informal reasoning in the following sense:

  • It should not be able to formally prove incorrect statements (soundness)
  • It should be able to formally prove every correct statement (completeness)

A system of formal deducibility, denoted by , is defined by listing its formal deduction rules.

Suppose that statement “If then ” is true for any and .

This means that what can be proved formally, by using the system of formal deducibility , also holds in informal reasoning.

In other words, it means that in the system , we cannot prove incorrect statements.

If this property holds for a given system of formal deducibility , then that system is called sound.

The next theorem will prove that the system of formal deduction denoted by , based on the 11 given rules of formal deduction, is sound.

Soundness Theorem

If then , where means the formal deduction based on the 11 given rules.

Proof: Structural induction, on the structure of "".

We only prove the cases of (Ref), and .

Base Case (Ref). If , then . Obvious.

Inductive Step, subcase ().

Assume that the statement of the theorem holds for , and (the IH). We want to prove that

By the IH we have that implies , and implies .

Use “proof by contradiction”. Assume that that is, there is a truth valuation such that and . Then .

Since and , this implies and , which is a contradiction.

Hence , and the proof of subcase () is complete.

Subcase (

Assume that the statement of the theorem holds for and (the IH). We want to prove that

By the IH, we have that implies , and implies .

Let be an arbitrary truth valuation such that and . Then or . Use “proof by cases”.

Case : If , then, by , we have that .

Case : If , then, by , we have that .

Hence , implying . This proves subcase ().

The other subcases are similar, and this completes the proof of the Soundness Theorem.

Completeness of a formal deduction system

Consider a system of formal deducibility, denoted by , defined by certain formal deduction rules.

Suppose that the statement “If then ” is true for any set of formulas and formula .

This means that anything that holds by informal reasoning can be proved using the system of formal deducibility .

In other words, it means that whatever is correct, can be formally proved using the system .

If this property holds for a system of formal deducibility , then that system is called complete.

The next theorem will prove that the system of formal deduction denoted by , based on the 11 given rules for formal deduction is complete.

Completeness Theorem

If then , where means the formal deduction based on the 11 given rules.

Proof in three steps:

  1. If then
  2. If then (every tautology has a formal proof).
  3. If then .

The idea is to prove the required statement for the case (prove that every tautology is formally provable, step (2)), then “convert” from general set of premises to the empty set of premises (step (1)), and “convert back” from to the set of premises (step (3)).

We first prove that the “conversion” works, i.e., prove (1) and (3).

(1) Proof:

By contradiction. Assume there exists a truth valuation such that .

This formula being structured as a series of nested implications, this implies that and .

This contradicts our hypothesis that .

(2) Proof:

Assume that is a tautology, and has atoms.

Construct subproofs of - one for each truth valuation, and then use the Law of Excluded Middle, , the rule , and (Tr.), to put them together.

More precisely:

Let the atoms in be , and let be a truth valuation. Define (relative to ):

Lemma: Let be a formula with atoms and let be a truth valuation. Then

  • if then , and\

  • if then

Claim: Every tautology is formally provable, that is, implies .

Proof: Since all truth valuations make a tautology true, the 1st statement of the Lemma guarantees that, for every possible choice for , we can find a formal proof for , that is, we can prove .

This implies that, for each row of the truth table for , if we can choose when , and when , we can find a proof for , that is, we can prove that .

We then use the rule to combine all the proofs for , into one big proof for , that has as premises (, for all .

Lastly, we use the Law of Excluded Middle, for all atoms , together with the “big proof”, and (Tr.), to obtain . This proves the Claim, and the Completeness Theorem.

The Soundness and Completeness Theorems associate the syntactic notion of formal deduction, based on the 11 rules, with the semantic notion of (tauto)logical consequence, and establish the equivalence between them.

The Soundness and Completeness Theorems say that with formal deduction (as defined by the 11 rules) we can prove

Formal deduction cannot be used to prove that an argument is invalid!

Descartes famously said “I think, therefore I am”. Joke: Descartes goes into a bar and the bartender asks him if he wants another drink. “I think not,” says Descartes, and he vanishes.

The argument roughly translates to:

This is an invalid argument, called the logical fallacy of denying the antecedent.

We can prove that . However we cannot prove that the argument is invalid using formal deduction, .

Another logical fallacy.

”Why are you standing on this street corner, waiving your hands?"

"I am keeping away the elephants."

"But there aren’t any elephants here."

"That’s because I’m here.”

This argument is roughly

This is the fallacy of affirming the consequent.

Formal deduction proof strategies

If the conclusion is an implication, that is, we have to prove , then try using , as follows. Add to the set of premises and try to prove . In other words, prove first. If this is proved, then one application of will result in .

If one of the premises is a disjunction, that is, if we have to prove , then try to use “proof by cases” (). In other words, prove separately (Case 1), then (Case 2), and then put these two proofs together with one application of to obtain .

If we have to prove and the direct proof does not work, try “proving the contrapositive”, that is, try to prove . Then use the “flip-flop” theorem “If then “.

If everything else fails, try “proof by contradiction”, ():

  • If we want to prove and we do not know how, start with modified premises (add a new premise, , to the premise set), and try to reach a contradiction:
  • Prove that , for some formula
  • Prove that , for the same
  • If we succeed in proving both, we reached a contradiction (we proved both and )
  • This means that our assumption, , was incorrect, and its opposite (that is ) holds.
  • Formally, from and , one application of yields .

Note that to prove , sometimes we have to start our proof with a premise set which is (somewhat) different from .

For example, if we want to use to prove , the proof starts with premises (from which we try to prove a contradiction). Or, in the proof for hypothetical syllogism, the premises in the first line of the proof have an extra for the proof to work.

However, while the premises in intermediate lines of the proof for can be different from , one must have a strategy of how to “undo” any such modifications of by the end of the proof. This is because the last line of the proof must coincide exactly with (otherwise, we proved a different theorem).

Note that these are only general formal deduction proof strategies (not algorithms).

A “line” in a proof can be used several times during the proof.

Example:

Here is a formal proof of the above result, in the proof system of Formal Deduction.

Definition

A set of formulas is consistent (w.r.t a system of formal deduction, herein ) if there is no formula , such that and . Otherwise is called inconsistent.

Lemma: A set of formulas is satisfiable iff is consistent.

Proof:

"" is satisfiable, so there exists a truth valuation with . Assume is inconsistent. Then there exists a formula such that and . By the Soundness of formal deduction, this implies and which, since , implies - a contradiction. Thus, is consistent.

"" Conversely, let be a consistent set of formulas. Assume is not satisfiable. Then, for all truth valuations we have . For any logic formulas , we have consequently and (vacuously, since there is no valuation with ). By Completeness, this implies and , which means that is inconsistent - a contradiction. Thus, is satisfiable.

Logic07: Resolution for Propositional Logic

In the field of Artificial Intelligence, there have been many attempts to construct programs that could prove theorems (or verify their proofs) automatically.

Given a set of axioms and a technique for deriving new theorems from old theorems and axioms, would such a program be able to prove a particular theorem?

Early attempts faltered. J.A. Robinson at Syracuse University discovered the technique called resolution.

Resolution theorem proving is a method of formal derivation (formal deduction) that has the following features:

The only formulas allowed in resolution theorem proving are disjunctions of literals, such as .

Recall that such a disjunction of literals is called a (disjunctive) clause. Hence, all formulas involved in resolution theorem proving must be (disjunctive) clauses.

There is only one rule of formal deduction, called resolution.

Question

How does resolution work?

Recall: A set of formulas Form() is consistent iff there is no formula Form() such that and (one cannot derive a contradiction). A set of formulas that is not consistent is called inconsistent.

For the system of formal deduction based on the 11 rules () we proved that a set is satisfiable iff it is consistent. A similar result holds for the proof system based on resolution.

To prove that an argument is valid, we show that the set is not satisfiable, by proving that it is inconsistent.

To prove the latter, we show that from we can formally derive both and , for some formula .

In general, one can convert any formula into one or more disjunctive clauses.

To do this, one first converts the formula into a conjunction of disjunctions; that is, one converts the formula into conjunctive normal form.

Each term of the conjunction is then made into a clause of its own.

Example: Convert into clauses.

Solution:

We first eliminate the by writing .

We then apply the distributivity law to obtain

This yields the two clauses and .

Definition

Resolution is the formal deduction rule where and are disjunctive clauses, and is a literal.

and are parent clauses, and is the resolvent clause. We say that we resolve the two parent clauses over .

Let denote a clause that is always false (a contradiction), hereafter called empty clause. ( is not a formula, but a notation for a contradiction, e.g., )

The resolvent of and is the empty clause, i.e., .

Removal of duplicates of literals in disjunctive clauses is allowed, e.g., .

Commutativity of disjunction is allowed within clauses.

A (resolution) derivation from a set of clauses is a finite sequence of clauses such that each clause is either in or results from previous clauses in the sequence by resolution.

Two comments can be resolved if and only if they contain two complementary literals, say (a positive literal) and (a negative literal).

If the complementary literals are and , one says that we resolve over , or that resolution is on .

The result of resolution on is the resolvent, which is the disjunction of all literals of the parent clauses, except that and are omitted.

In the particular case when the two parent clauses are and , their resolvent is called the empty clause, denoted by .

In the context of resolution, the empty clause is a notation signifying that the contradiction was reached.

By definition, the empty clause is not satisfiable.

Find the resolvent of and .

Solution: The two parent clauses and can be resolved over , because is negative in the first clause and positive in the second.

The resolvent is the disjunction of with , which yields .

To prove that the argument with premises and conclusion is valid, we show that from the set

we can derive, by , the empty clause (a contradiction), as follows:

  • Pre-process the input by transforming each of the formulas in into conjunctive normal form.

  • Make each disjunctive clause a distinct clause. These clauses are the input of the resolution procedure.

  • If the resolution procedure outputs the empty clause, , this implies that the set is inconsistent, hence not satisfiable, and thus the argument is valid.

Resolution Procedure

Input: Set of disjunctive clauses

Repeat, trying to get the empty clause, :

  • Choose two parent clauses, one with and one with
  • Resolve the two parent clauses, and call the resolvent .
  • If then output “empty clause”
  • Else add to

Parent clauses can be reused.

Example: Modus ponens by resolution

Prove that

Proof:

Soundness of resolution formal deduction

Theorem

The resolvent is tautologically implied by its parent clauses, which makes resolution a sound rule of formal deduction.

Proof: Let be a propositional variable, and let and be clauses.

Assume that .

We want to prove that .

() If at least one of or is not empty, then we prove:

Claim: for any clauses , both not empty.

Consider a truth valuation such that

  • If , then , because otherwise .
  • Similarly, if , then , because otherwise

In either situation, , therefore . This proves the Claim.

() If both and are empty then the resolvent of and is the empty clause , which is short for , and always false.

In this case because the premises are contradictory.

In both cases, and , the required tautological consequence holds, and this proves soundness of resolution.

Prove that

Proof: The CNF for is . The CNF for is . The CNF for the negation of the conclusion is .

A common mistake in using resolution is to apply it to more than one literal. This is not correct.

For example, the following is an incorrect use of resolution:

  • \

  • \

  • (from 1,2 resolving over and )

This disagrees with the Soundness of Resolution since

We can prove the invalidity of the argument by noticing that we can satisfy the premises by setting and equal to 1, but cannot satisfy the conclusion (which is short for , hence always false, and thus not satisfiable).

This is not resolution!

When doing resolution automatically, one has to decide in which order to resolve the clauses.

This order can greatly affect the time needed to find a contradiction.

Strategies include: The “Set-of-Support Strategy” and The Davis-Putnam Procedure (DPP)

Set-of-Support Strategy

One partitions all clauses into two sets, the set of support and the auxiliary set.

The auxiliary set is formed in such a way that the formulas in it are not contradictory.

For instance, the premises are usually not contradictory. The contradiction will only arise after one adds the negation of the conclusion.

One often uses the set of premises as the “auxiliary set”, and the negation of the conclusion as the initial “set of support”.

Since one cannot derive any contradiction by resolving clause within the auxiliary set, one avoids such resolutions.

Stated positively, when using the Set-of-Support Strategy, each resolution takes at least one clause from the set of support.

The resolvent is then added to the set of support.

Theorem

Resolution with the set-of-support strategy is complete.

Example

Prove from and by using the set-of-support strategy.

The auxiliary set consists of the clauses obtained from and .

The initial set of support is given by , the negation of the conclusion.

One then performs all the possible resolutions involving , then all possible resolutions involving the resulting resolvents, and so on.

At each step, a resolvent (which has at least one parent in the set of support) gets added to the set of support.

Prove from and , by using the set-of-support strategy.

The Pigeonhole Principle says that one cannot put objects into slots, with distinct objects going into distinct slots.

Example: In any group of 367 people there must be at least two with the same birthday.

Formulate the Pigeonhole Principle as a conjunction of formulas.

Choose propositional variables for .

Define as true iff the th pigeon goes into the th slot.

Construct clauses for:

  1. Each pigeon , goes into some slot for .
  2. Distinct pigeons cannot go into the same slot for

Observe now that any truth valuation that satisfies the conjunction of all the above clauses would map pigeons one-to-one into slots.

Of course, by the Pigeonhole Principle, this cannot be done, so this set of clauses must be unsatisfiable.

Question

What is the Pigeonhole Principle (3 pigeons and 2 slots) as a resolution problem?

Every pigeon in at least one slot: .

No two pigeons per slot:

Slot 1:

Slot 2:

Note: We do not need all possible pairs () for every slot because, e.g.,

Since the set of the 9 clauses is not satisfiable (due to the Pigeonhole Principle), one should be able to derive the empty clause from it.

Davis-Putnam Procedure (DPP)

Any clause corresponds to a set of literals, that is, the literals contained within the clause.

For instance, the clause corresponds to the set and corresponds to the set .

Since the order of the literals in a disjunction is irrelevant, and since the same is true for the multiplicity of the terms (duplicates do not matter), the set associated with the clause completely determines the clause.

For this reason, one frequently treats clauses as sets, which allows one to speak of the union of two clauses.

If clauses are represented as sets, one can write the resolvent, on , of two clauses and , when neither nor is empty, as

In words, the resolvent is the union of all literals in the parent clauses except that the two literals involving are omitted.

In the particular case when and are both empty, the resolvent of and is the empty clause, denoted by (not satisfiable by definition).

Given an input as a nonempty set of clauses in the propositional variables the Davis-Putnam Procedure (DPP) repeats the following steps until there are no variables left:

  • Remove all clauses that have both a literal and its complement in them (a disjunctive clause in which both and appear is a tautology, and will never lead to a contradiction)
  • Choose a variable appearing in one of the clauses
  • Add to the set of clauses all possible resolvents using resolution on (parent clauses containing can be re-used)
  • Discard all (parent) clauses with or in them
  • Discard any duplicate clauses

We refer to this sequence of steps as eliminating the variable

If in some step one resolves and then one obtains the empty clause, , and it will be the only clause at the end of the procedure.

If one never has a pair and to resolve, then all the clauses will be discarded and the output will be no clauses.

Thus, the output of DPP is either the empty clause , or the empty set (no clauses).

DPP

Input: A set of disjunctive clauses, in DPP format, with propositional variables .

  • Let
  • Let
  • LOOP until
  • Discard members of in which a literal and its complement appear, to obtain .
  • Let be the set of parent clauses in in which or appears
  • Let be the set of resolvent clauses obtained by resolving (over ) every pair of clauses and in
  • Set equal to
  • Let be increased by 1
  • ENDLOOP
  • Output

Example:

Apply the Davis-Putnam Procedure to the set of clauses

Eliminating gives (This is and )

Eliminating gives . (This is and )

Eliminating gives . (This is and )

Eliminating gives . (This is )

The output is the empty clause .

If the set of clauses is more complex, before each iteration (elimination of a variable) we give each clause in a numerical identifier.

Then, in the next step (which produces the resolvents in from parent clauses in ) we provide, for each resolvent, the identifiers of the two parent clauses that produced it.

If the output of DPP is the empty clause , then this indicates that both and were produced. This implies that the set of clauses that was obtained by pre-processing the premises and negation of the conclusion of the argument is inconsistent, hence not satisfiable, that is, the argument (theorem) is valid.

If, on the other hand, the output of DPP is not clause, , this means that no contradiction can be found, and the original argument (theorem) is not valid.

Soundness and Completeness of DPP

Theorem

Let be a finite set of clauses. Then is not satisfiable iff the output of DPP on input is the empty clause .

Proof idea:

Resolution propagates satisfiability “forwards”, from parent clauses to resolvent (this follows by the Soundness of Resolution)

Resolution propagates satisfiability “backwards”, from a resolvent to its parent clauses, as follows:

Saw we have a resolution . If is satisfiable, there exists a truth valuation with .

  • If , then extend (define for , which did not occur in or ) to . Then both parent clauses are satisfied by .
  • If , then extend to . Then both parent clauses are satisfied by .
  • Hence, the parent clauses are satisfiable by some extension of .

Proof: ” by DPP” implies ” not satisfiable”

Sketch:

We can use induction on to show that if is any clause in then there is a resolution derivation of from the initial set .

Since the output of DPP is the empty clause, that is, , it would follow that there is a resolution derivation from to .

Since is not satisfiable and resolution preserves satisfiability (by Soundness of Resolution) this implies that is not satisfiable.

This concludes the proof of this implication

Proof of the other implication

not satisfiable” implies ” by DPP”

Proof by contradiction:

Assume that the output of the DPP is not the empty clause , but the empty set (the only other possibility).

We want to show that this would imply that was satisfiable.

If , then is (vacuously) satisfiable.

We will prove that if is satisfiable then is satisfiable.

In other words, satisfiability also propagates “backwards”.

If proved, this would lead to a contradiction with out assumption that was not satisfiable, and complete the proof of this implication.

satisfiable implies satisfiable

has variables .

has variables (one extra variable , which is eliminated in iteration of DPP that constructs from )

Recall that

Assume is satisfied by some truth valuation . Then satisfies both and .

Since , to show that is satisfiable, it suffices to show that is satisfiable, as follows.

is satisfied by a truth valuation obtained by extending to a truth valuation that coincides with on variables , and assigns a suitable value to ( does not occur in )

Note: Clearly, is satisfiable iff is satisfiable (all clauses deleted from to obtain contain complementary literals, and are thus tautologies, hence satisfiable).

Show that (parents with is satisfiable

Assume is satisfied by some truth valuation that assigns some truth values to .

Claim: One of the following two truth valuations satisfy

  • : agrees with on variables and ,
  • : agrees with on variables and .

Assume neither nor satisfies .

Since satisfies all formulas in that contain , it must falsify some clause in . As is not satisfied by , we have that is not satisfied by .

Since satisfies all formulas in that contain , it must falsify some clause . As is not satisfied by , we have that is not satisfied by .

As satisfies neither nor , it follows that it does not satisfy - a contradiction, since and . This concludes the proof of the Claim.

Concluding the proof of the other implication.

Since we assumed that

was satisfiable, and we proved that is satisfied by an extension of one of the truth valuations that satisfies , we have that (and thus ) is also satisfiable by that truth valuation.

Recall that we had assumed (for the sake of contradiction) that , which is vacuously satisfiable.

Working backwards, this implies that is satisfiable, which contradicts the hypothesis of the implication that we have to prove, namely

Since we reached a contradiction, our assumption that "" by DPP was incorrect, and we have ” by DPP”.

The theorem proved that ” by DPP” implies ” not satisfiable”. How does this show the soundness of DPP?

Say we are given an argument to prove, with set of premises , and conclusion .

Taking , if we prove ” by DPP”, then the theorem (implication cited above) implies ” not satisfiable.”

not satisfiable further implies .

Thus, if we prove the validity of an argument formally, by using DPP to obtain the empty clause, then the argument is indeed valid, that is, DPP is sound.

The theorem proved that ” is not satisfiable” implies ” by DPP.” How does this show completeness of DP?

  • Assume we have a valid argument
  • This implies ” not satisfiable”
  • Taking , the theorem (implication cited above) implies ” by DPP”.
  • This means that every valid argument can be formally proved to be correct by the method based on DPP, that is, DPP is complete.

Exercise:

Use the DPP to show that the set of clauses below is not satisfiable. (If the set of clauses would originate from pre-processing the premises and the negation of the conclusion of an argument in propositional logic, the unsatisfiability of the set of clauses would lead us to conclude that the argument was valid.)

Eliminate the variables in the order .

Note: We remove the underlined clauses dynamically on the fly (they are tautologies).

Eliminate :

Eliminate :

Eliminate :

Eliminate :

Eliminate :

(the empty clause)

The outcome of DPP is , the empty clause (indicating that a contradiction was reached, by resolving two complimentary literals).

By DPP Soundness and Completeness, this implies that is not satisfiable.

(If would have originated from pre-processing the set of premises, and the negation of the conclusion, of an argument, this outcome would further imply that the argument was valid.)

Logic10: First-Order Logic

In propositional logic, a simple proposition is an unanalyzed whole which is either true or false.

There are certain arguments that seem to be logical, yet they cannot be expressed using propositional logic.

For analyzing these we introduce first-order logic.

Alternate names: Predicate logic, predicate calculus, elementary logic, restricted predicate calculus, relational calculus, theory of quantification with equality, etc.

Example

  1. All humans are mortal
  2. Socrates is human
  3. Socrates is mortal

This is clearly not a valid argument in propositional logic.

To show that arguments such as the previous one are valid (sound), we must be able to identify individuals together with their properties and relations.

This is the objective of first-order logic.

First-order logic (FoL) is an extension of propositional logic.

Applications in CS:

  • Prolog
  • Automated theorem provers, proof assistants
  • Proving program correctness

First-order logic is used to describe, e.g., mathematical theories. Such a theory comprises certain concepts specific to the structure/theory:

  • A domain of objects (called individuals). Designated individuals in the domain. Variables ranging over the domain.
  • Functions on the domain
  • Relations

In addition, in making statements about individuals in the domain we use first-order logic concepts:

  • Logical connectives
  • Quantifiers
  • Punctuation

To prevent ambiguities we introduce the concept of a domain or universe of discourse.

Definition

The domain (or universe of discourse) is the collection of all persons, ideas, symbols, data structures, and so on, that affect the logical argument under consideration.

Many arguments involve numbers and, in this case, one must stipulate whether the domain is, for example, the set of natural numbers, of integers, of real numbers, or of complex numbers.

The truth of a statement may depend on the domain selected.

Definition

The elements of the domain are called individuals.

An individual can be a person, number, data structure, or anything else one wants to reason about.

To avoid trivial cases, we stipulate that every domain must contain at least one individual.

Instead of the word individual, one sometimes uses the word object.

Another important concept is that of functions whose inputs and outputs are both in the domain (universe of discourse).

For example, may stand for the sum of and .

Each function has an arity, defined as the number of arguments the function takes as input.

The arity of a function is fixed. We can think of individuals as functions of arity .

Relations make true/false statements about individuals in the domain.

Mary and Paul are siblings. Joan is the mother of Mary. Socrates is human. The sum of and is .

In each of these statements, there is a list of individuals, called argument list, together with phrases that describe certain relations among the individuals in the argument list.

Definition

The number of elements in the argument list of a relation is called the arity of the relation.

For instance, the relation “Is the mother of” has arity 2.

The arity of a relation is fixed: A relation cannot have to arguments in one case and three in another.

A one-place relation is called a property.

Often we do not want to associate the arguments of a function or relation with a particular individual. To avoid this, we use variables, that range over the domain.

Variables are frequently chosen from the end of the alphabet; and , with or without subscripts, suggest (bound) variable names, and and , with or without subscripts, suggest (free) variable names. The distinction will be explained later.

Examples:

Human may denote ” is human”,

Mother may denote ” is the mother of “.

If all arguments of a relation are individuals in the domain, then the resulting formula must be either true or false.

This is part of the definition of the relation.

For instance, if the domain consists of Joan, Doug, Mary and Paul, we must know, for each ordered pair of individuals whether or not the relation is the mother of is true.

In a finite domain, one can represent the assignments of relations with arity by dimensional arrays.

Note that the usual mathematical symbols or , , or , or are all relations, namely of arity (binary relations).

These relations are normally used in infix notation.

By infix notation, the binary relation symbol is placed between its two arguments.

Let represent a formula, and let be a variable.

If we want to indicate that is true for all possible values of in the domain, we write .

Here, is called universal quantifier, and is called the scope of the quantifier.

The variable is said to be bound by the quantifier.

Statements containing words like all, for all, for every etc., usually indicate universal quantification.

Translate “Everyone needs a break” into first-order logic.

Let be the set of all people.

We define to mean needs a break. In other words,

Then the translation in first-order logic is: .

If we want to indicate that is true for at least one value in the domain (possibly more than one, but not necessarily) we write .

Here, is called the existential quantifier, and is called the scope of the quantifier.

The variable is said to be bound by the quantifier.

Statements containing phrases as there exists, there is etc., are rephrased as “there is an (in the domain) such that”.

Translate “Some people like their tea iced” in first-order logic.

Let be the set of all people.

Let mean likes their tea iced. In other words, is defined as

Then the translation in first-order logic is .

The variable appearing in the quantifier is said to be bound.

For instance, in the formula , the variable appears three times and each time is a bound variable.

Any variable that is not bound is said to be free.

We can consider the bound variables to be local to the scope of the quantifier just as parameters and locally declared variables in procedural programming languages are local to the procedure in which they are declared.

The analogy to procedural programming languages can be extended further if we consider the variable name in the quantifier as a declaration.

This analogy also suggests that, if several quantifiers use the same bound variable for quantification, then all these variables are local to their scope and they are therefore distinct.

and have to be treated like unary connectives.

The quantifiers are given a higher precedence than all binary connectives.

For instance, to translate “Everything is either living or dead”, where the domain is all creatures, means ” is living”, and means ” is dead”, we write

means “Everything is living, or is dead” (the first is a bound variable, and the second is a free variable).

The variable in a quantifier is just a placeholder, and it can be replaced by any other variable symbol not appearing elsewhere in the formula.

For instance and mean the same thing (they are logically equivalent), so .

Quantifying over a subset of the domain.

Sometimes, quantification is over a subset of the domain.

Suppose, for instance, that the domain is the set of all animals.

Consider the first statement “All dogs are mammals”.

Since the quantifier should be restricted to dogs, one rephrases the statement as “If is a dog, then is a mammal”, which leads to the formula

Conversely, the formula

can be interpreted as “All individuals (in the domain) with property , also have property “.

Consider now the statement “Some dogs are brown”.

This means that there are some animals that are dogs and that are brown.

The statement ” is dog and is brown” can be translated as .

These are some brown dogs can be translated as

Conversely, the formula

can in general be interpreted as “Some individuals (in the domain) with property , have also property “.

If the universal quantifier applies only to a subset of the domain:

  • First we have to define a property (relation) that describes that subset of the domain, and
  • We then use the implication, , to restrict the quantification to the subset of the domain consisting of the individuals with this property.

If we want to restrict application of the existential quantifier to a subset of the domain:

  • First we have to define a property (relation) that describes that subset of the domain, and
  • We then use the conjunction, , to restrict the quantification to the subset of the domain consisting of the individuals with this property.

What not to do!

The domain is the set of all animals.

”All dogs are mammals” cannot be translated using , as in

The above is a stronger statement, which translates as “Every animal is both a mammal and a dog” (a false statement).

”Some dogs are brown” cannot be translated using "", as in

The above is a weaker statement, which is vacuously true (even if no brown dogs would exist), by the definition of , since there exists at least one animal which is not a dog.

Consider statements such as “Only dogs bark”, where the domain is the set of all animals.

This must be first reworded as “It barks only if it is a dog”, its equivalent “If it is not a dog, it does not bark”, or its contrapositive equivalent “If it barks, then it is a dog”.

The translation is thus: .

Negating formulas with quantifiers.

We will often want to consider the negation of a quantified formula.

Consider the negation of the statement:

Every student in the class has taken a course in calculus.

If the domain is the set of all students in this class, this statement can be translated as where is the statement ” has taken a course in calculus”.

The negation of this statement is “It is not the case that every student in this class has taken a course in calculus”.

This is equivalent to “There is a student in the class who has not taken a course in calculus, that is “.

In other words, .

Consider the proposition.

There is a student in this class who has taken a course in calculus.

Which if the domain is the set of all students in this class, can be translated as where is the statement ” has taken a course in calculus”.

The negation of this statement is “It is not the case that there is a student in this class who has taken a course in calculus”.

This is equivalent to “Every student in this class has not taken calculus”, that is, .

In other words, .

Assume the domain is finite,

In this case, the universal quantifier is the same as conjunction: iff .

In this case, the existential quantifier is the same as disjunction: iff .

The English statement Nobody is perfect also includes a quantifier, “nobody” which is the absence of an individual with a certain property.

In first-order logic, the fact that nobody has a property cannot be expressed directly.

If the domain is the set of all people, and if means ” is perfect”, then:

expresses “It is not the case that there is somebody who is perfect”,

expresses “For everyone, it is not the case that they are perfect”.

Thus, both and are correct translations for “Nobody is perfect”.

Nested quantifiers

Example: Translate “There is somebody who knows everyone” into first-order logic, where the domain is the set of all people.

Use to express ” knows “.

.

Let denote "". If the domain is the set of real numbers, what are the truth values of and ?

Solution: The first formula means “There is a real number such that for every real number , we have “. Since there is no real number such that for all real numbers , this statement, and thus the first formula, is false.

The second formula means “For every real number , there is a real number such that “.

Given real number there is indeed a real number such that , namely . Hence, this statement, and thus the second formula, is true.

The order in which quantifiers and appear matters!

In working with qualifications of more than one variable, it is sometimes helpful to think of them in terms of nested loops.

For example, to see whether is true:

We consider and loop through all the values for and, for each , we loop through all the values for :

If we find that is true for all values of and , then we have determined that is true.

If we find that we ever hit a value for which we hit a value for which is false, then we have shown that is false.

Logic11: First-Order Logic Syntax

In propositional logic, formulas are recursively built starting from atoms (proposition symbols), by the five formation rules that describe the use of connectives.

In first-order logic, we add the capacity to refer to individuals, and their properties and relationships (rather than only to true/false propositions). This requires that formulas be more fine-grained, with:

  • A specification of the basic individual, given by a domain.
  • Terms, which are expressions referring to individuals in the domain.
  • Atomic formulas (atoms) which are relations to combine terms, and are the simplest true/false formulas. Atoms play the same role here as proposition symbols do in propositional logic.
  • Formulas which are recursively built starting from atomic formulas, by formation rules that describe the use of connectives and quantifiers.

There is no single “first-order language.” Instead, there is a framework that combines logical elements with non-logical elements that are specific to the mathematical theory/structure we want to describe. In particular, we consider two different kinds of symbols:

Logical symbols: They have a fixed syntactic use and a fixed semantic meaning.

Non-logical symbols: These have a designated syntax, but their semantic meaning is not pre-defined.

is the formal language of first-order logic. may or may not be associated to a mathematical theory/structure.

The word term is used to refer to either an individual or a variable. More generally, a term is anything that can be used in place of an individual. Formally, we have:

Definition

Term is the smallest class of expressions of closed under the following formation rules:

  1. Every individual symbol is a term in Term
  2. Every free variable symbol is a term in Term
  3. If , are terms in Term, and is an ary function symbol, then is a term in Term

Terms containing no free variable symbols are called closed terms.

An “atomic formula”, or “atom”, of is the simplest formula expressing a proposition, that is, a statement for which we can determine whether it is true or false. Formally, we have:

Definition

An expression of is an atom or atomic formula in Atom() iff it is of one of the following two forms:

  1. , where is an ary relation symbol and are terms in Term()
  2. , where are terms in Term().

For example, are atoms.

Formulas of are built recursively, starting from atoms, by defining formation rules that describe the use of connectives and quantifiers.

Definition

Form(), the set of formulas of , is the smallest class of expressions of closed under the following formation rules.

  1. Every atom in Atom() is a formula in Form()
  2. If is a formula in Form(), then is a formula in Form()
  3. If are formulas in Form(), then and are formulas in Form()
  4. If is a formula in Form(), where is a free variable, and is a variable not occurring in , then and are formulas in Form(), where "" denotes the expression formed from by replacing every occurrence of by .

Terms play a similar role in first-order logic as nouns and pronouns do in the English language: They are the expressions which can be interpreted as naming an object in the domain.

Terms are individual symbols, are free variable symbols, or function symbols having as arguments other terms.

Atoms (atomic formulas) are the simplest formulas in Form(), and are built by using exactly one relation symbol applied to terms. They contain neither connectives nor quantifiers.

Formulas are expressions which can be built up from atoms, by using connective symbols and quantifier symbols.

A term or formula is said to be closed if it contains no free variables. A closed formula is also called a sentence.

Example:

1. For every integer , there is an integer which is greater than .

2. is an integer.

3. There is an integer which is greater than .

SymbolMeaning
is an integer
is greater than
for all
there exists

The preceding logical argument can be formalized as:

1.

2.

3.

Theorem

Any term in Term() is of exactly one of three forms: an individual symbol, a free variable symbol, or where is an ary function symbol and are terms, ; and in each case it is of that form in exactly one way.

Theorem

Any formula in Form() is of exactly one of eight forms: an atom (a single relation symbol applied to terms), or ; and in each case it is of that form in exactly one way.

Definition

A sentence or a closed formula in Form() is a formula in Form() in which no free variable symbols occur. The set of sentences of is denoted by Sent().

Logic12: First-Order Logic: Semantics

The language of first-order logic is a purely syntactic object. The formulas in Form(), however, are intended to express statements. This is the subject of semantics.

Semantics for propositional logic formulas in Form() is simple: A truth valuation assigns truth values to proposition symbols, and the truth value of a formula is based on the values of its proposition symbols and the “meaning” of connectives.

The language includes more classes of symbols and therefore the “valuations” are more complex.

A valuation for consists of an interpretation of its non-logical symbols, together with an assignment of values to its free variables.

Informally, a valuation for the first-order language must contain sufficient information to determine whether each formula in Form() is true or false.

The logical symbols of have a fixed semantics (meaning):

The connectives will be interpreted as in propositional logic.

The meaning of quantifiers has been explained intuitively (we will define them precisely).

The equality symbol denotes the relation “equal to”.

The variable symbols will be interpreted as variables ranging over the domain.

Punctuation symbols serve just like ordinary punctuation.

A valuation consists of an interpretation plus an assignment.

An interpretation consists of a non-empty set of individuals (objects) called the domain. A specification, for each individual symbol, relation symbol, and function symbol, of the actual individuals, relations, and functions that each will denote.

An assignment assigns to each free variable a value in the domain.

We need this because, for formulas that contain free variables, in addition to an interpretation we must have an assignment of “values” (individuals in the domain) to the free variables in the formula, in order to determine if the formula is true or false.

Notation: We denote the meaning given by a valuation to a symbol by .

One final step before the formal definitions: sometimes it is convenient to describe relations and functions in terms of sets.

Recall than an ary relation on a set an be thought of as a subset of times), defined as

For example, the equality relation on is the subset of and or alternatively .

Recall that an ary function can be represented by the ary relation

Definition

A valuation for the first-order language consists of:

A domain, often called , which is a non-empty set, and a function, denoted by , with the properties:

  • For each individual symbol , and free variable symbol , we have that .
  • For each ary relation symbol , we have that is an ary relation on , that is, . In particular,
  • For each ary function symbol , we have that is a total ary function of into , that is, .

A function is “total” if it is never undefined.

The definition of a domain requires it to be a non-empty set.

Consider the sentence (closed formula, no free variables)

Consider the valuation (since there are no free variables, the valuation coincides with the interpretation) defined as:

  • The domain is is the set of all ships
  • The symbol is interpreted as the unary relation (over ) defined by , that is, is if is on fire, and is if is not on fire.
  • The symbol is interpreted as the unary relation defined by .
  • The symbol is interpreted as the unary relation defined by .

Under this interpretation, the formula says:

“Every ship that is on fire or has a hole sinks”.

Individuals (constants) vs. free variables

Example: Let be (where is an individual symbol), and let be (where is a free variable).

Consider a valuation with domain that interprets as the number , and as “is even”.

Under this valuation, is evaluated as true, but remains undefined.

To give a value, we must also specify an assignment to the free variable . For example, if we assign value , then becomes false, but if we assign value , then becomes true.

Thus, valuation interpretation (of the individual symbols, relation symbols, function symbols) assignment (to the free variable symbols).

Value of a term

Consider a valuation . This fixes a domain, and the identities of , , and for each non-logical symbol; it also fixes a value for each free variable symbol.

Definition

(Value of a term): The value of a term under valuation over a domain , denoted by , is defined recursively as follows:

  1. If is an individual symbol , then its value is . If is a free variable symbol , then its value is .
  2. If , where is an ary function symbol, and Term (, then

Theorem

If is a valuation over , and Term then .

To evaluate the truth value of a formula (resp. ), we should check whether holds for all (resp. for some) values in the domain.

Question

How do we express this precisely?

Notation: For any valuation , free variable , and individual , we write

to denote a valuation which is exactly the same as except that .

That is, for each free variable ,

Definition

(Value of a quantified formula): Let and , and let be a free variable not occurring in . The values of and under a valuation with domain are given by:

Definition

Let be a valuation with domain . The value of a formula in Form() under is defined recursively as:

  1. ,
  2. ,
  3. if both and ,
  4. if either or (or both),
  5. if either or (or both),
  6. , Otherwise, in each case 1-6, the formula takes value .

Theorem

If is a valuation over and Form(), then .

Definition

A formula Form() is:

  • Satisfiable if there exists a valuation such that .
  • (Universally) valid if for all valuations we have .
  • Unsatisfiable if it is not satisfiable, that is, if for all valuations .

Let be a set of formulas in Form(), and be a valuation over . Define

Definition

Definition: A set Form() is satisfiable if and only if there is some valuation such that .

When we say that satisfies , or that is true under .

Universally valid formulas in Form() are the counterpart of tautologies in Form().

The similarities between them are obvious, but there is one important difference.

To decide whether or not a formula of Form() is a tautology, algorithms can be used (for instance the truth table method).

However, in order to know whether a formula of Form() is universally valid, we have to consider all possible valuations over all possible domains, of all different sizes.

In case of an infinite domain, the procedure is in general not finite.

Given a valuation over an infinite domain, we do not have a method for evaluating the value of or in a finite number of steps, because it presuposes the values of for infinitely many in .

It is sometimes possible to decide for certain formulas in Form() whether they are universally valid or not.

However, in the general case we have the following result.

Theorem

(Church, 1936): There is no algorithm for deciding the (universal) validity or satisfiability of formulas in first-order logic.

In first-order logic, the variables range over individuals from the domain. The quantifiers are interpreted in the familiar way as “for all individuals of the domain”, respectively “there exist some individual of the domain”.

In second-order logic, we also allow as variables subsets of the domain and relations on the domain, as in:

  • Every non-empty subset of natural number has a smallest element.

Here we have to take all subsets of the domain into consideration, and require variables and quantifiers for sets (not only for individuals in the domain). In second-order logic, quantifications over sets, relations, functions are allowed.

In higher-order logic, variables and quantifiers for sets of sets, sets of sets of sets, etc. are also allowed.

Logic13: Logical Consequence

Logical consequence in first-order logic, which are the counterparts of tautological consequences in propositional logic, involve semantics.

The notation for tautological consequences is also used for logical consequences.

Definition

Suppose is a set of formulas in Form() and is a formula in Form(). is a logical consequence of , written as , iff for any valuation with , we have .

The notations and are used in the same sense as in propositional logic.

Two formulas are called logically equivalent (or equivalent for short, if no confusion will arise) iff holds.

Prove that

Proof (by contradiction): Suppose the contrary, that is, suppose that there is some valuation over a domain such that:

By “negating equation (2)”, it follows (from the semantics of first-order logic) that

This implies that (using the simplified notation),

“Negating equation (4)” (namely, ) yields

On the other hand, recall , which states . This implies that, in particular, for the individual that we identified in , we have

We have reached a contradiction ( contradicts ), therefore our assumption was false.

Since our assumption (that the argument was invalid) was false, its opposite is true, that is, the argument is valid (or sound, correct).

Note: Similarly, we can prove , and therefore we have .

Prove that .

Proof: Assume that . This implies that there exists a valuation over a domain such that:

implies : , and : .

If we negate equation , we obtain : .

implies the existence of an individual such that , that is .

Since , we have that in particular, .

From and , we have , which implies . This contradicts , hence the argument is valid.

Prove that .

Proof: It suffices to find a single counter-example (a valuation over a domain that makes the premise true but the conclusion false). Consider and the relations and defined as

Under this valuation, we have

  • since

  • since

Thus, we have : . On the other hand, : , because . From and , we see that the above valuation over makes the premise true but the conclusion false. This implies that the argument is invalid.

Recall that a universally valid formula of Form() is a formula that is satisfied by every possible valuation.

For any formula in Form(), one has if and only if is universally valid.

To demonstrate that a formula is universally valid, we have to show that .

Since is vacuously satisfied by any valuation, to prove that a formula is universally valid we have to show that there is no valuation under which is false.

Show that is universally valid, that is, prove .

Proof: Assume that .

This implies that there exists a valuation over a domain such that

This further implies

Negating equation results in . This implies that there exists an individual such that , further yielding .

implies : , and implies : ; and imply , which contradicts . Hence, the formula is universally valid.

Prove that the formula is not universally valid,

Proof: To prove that the formula is not universally valid, it suffices to find a valuation that makes the antecedent true and the consequent false.

Construct the valuation over domain defined by and .

Then (since , while (since .

This implies that , which further implies that the formula is not universally valid.

Question

Can we always determine whether a formula is universally valid?

No. The problem of proving whether or not a formula in Form() is universally valid is undecidable (Church); that is, there is no generally applicable algorithm that, given an arbitrary formula in Form() as input, can always determine whether or not the formula is universally valid.

This does not mean that we can never determine that a particular formula is universally valid. In fact, there are methods that work in many particular cases.

For instance, first-order logic formulas that arise from propositional logic tautologies, such as (arising from , can be proved to be universally valid.

For other formulas, such as the ones in the previous examples, we are able to prove whether or not they are universally valid.

However there is no general-purpose algorithm that provides an answer in all cases.

Theorem (Replaceability of equivalent formulas in first-order logic).

Let be a formula in Form() which contains a subformula Form(). Assume that , and let be the formula obtained by simultaneously replacing in some (but not necessarily all) occurrences of the formula by formula . Then .

Theorem (Duality in first-order logic).

Suppose is a formula in Form() composed only of atoms in Atom(), the connectives and the quantifiers and , by the formation rules concerned. Suppose results from by simultaneously exchanging connectives for , quantifiers for , and each atom for its negation. Then .

Logic14: First-order-Logic Formal Deduction

The goal of formal deducibility was to define a calculus of reasoning.

We defined a self-contained formal system of reasoning based on rules of formal deduction.

The system of formal deduction gives syntactic procedures to construct new correct theorems from already proven ones. In such a formal deduction system, the correctness of the formal proof of a theorem can be checked mechanically/automatically.

The ultimate goal for a formal deduction system is to be able to prove formally, everything that is correct semantically.

The formal deducibility in first-order logic is an extension of that in propositional logic.

The rules of formal deduction for propositional logic are included in formal deduction for first-order logic, but the formulas occurring in them are now formulas in Form().

We also include additional rules of formal deduction concerning the quantifiers, and the equality symbol.

(12)()If is a theorem then where is any term, is a theorem
(13)()If is a theorem and does not occur in then is a theorem
(14)()If is a theorem and does not occur in or in then is a theorem
(15)()If is a theorem then is a theorem, where results from by replacing some (not necessarily all) occurrences of by .
(16)()If is a theorem and is a theorem then is a theorem, where results from by replacing some (not necessarily all) occurrences of by
(17)( is a theorem

The additional rules of formal deduction for first-order logic are called:

  • elimination for ; introduction for ;
  • elimination for ; introduction for ;
  • elimination for ; introduction for ;

Note: In these rules, is a free variable, and are terms. is an alternative notation for the usual equality relation ”=“.

In , the formula results from by substituting all occurrences of by , and similarly for and .

In , another kind of replacement is employed, which should be distinguished from substitution. This kind of replacement allows us to either substitute all occurrences of by (as usual), or replace only some of the occurrences of t by (and leave the rest as ), as needed. The case of is similar.

The in and may be replaced by (any term). This extends the range of application of these two rules, as the set of terms strictly contains the set of free variables. However, since the formulations - as defined - are sufficient, the replacement of by in the definition of these two rules is not necessary.

The conditions u not occurring in in , and not occurring in or in () are essential.

Explanation for

If and does not occur in then .

The rule means intuitively that from

”Any element of a set has a certain property.” we can deduce that “Every element of the set has this property”.

Example: (Perpendicular Bisector Theorem) Every point on the perpendicular bisector has a segment has the property that it is equidistant from and .

Proof: It is sufficient to prove the theorem for any point on the perpendicular bisector . In other words, the proof would start with “Let be an (arbitrary) point on . We have to show that .” Etc.

At the end of the proof, from the statement

”Any point on is equidistant from and .” we deduce the statement “Every point on is equidistant from and .”

The reasoning above is only sensible if the “any” means an arbitrary element, with no restriction whatsoever.

If “any” means a particular element, such a reasoning would be nonsense.

Here, the arbitrariness of means that the choice of is independent of the premises (hypotheses) of the theorem.

This is expressed syntactically in by ” not occurring in ” (where expresses , and the premises of the theorem).

The explanation is similar for the case of . The value that satisfies is fixed but unknown, and thus as a symbol must be completely independent of all other variables in all formulas.

Comments on - elimination.

Given we should be able to derive for any term .

For instance, if the domain is all people in a given house, and stands for is sleeping, then means “Everyone in the house is sleeping”.

If Dan is in the house, from this statement we can derive that Dan is sleeping.

This is the type of valid reasoning that the -elimination rule is intended to formalize.

Note: can be an individual symbol, a free variable symbol, or a function symbol applied to terms.

Comments on -introduction

If does not appear as a free variable in any premise, one can “generalize” over .

If would appear free in any premise, then would always refer to the same individual, and would be “fixed” in this sense. For example, if would appear in a premise, e.g., in , then would only refer to the particular individual that makes true, and would not be “arbitrary”.

If is fixed, one cannot generalize over . Generalizations from one particular individual towards the entire population are unsound.

If, on the other hand, does not appear in any premise as a free variable, then is assumed to stand for anyone, and the generalization may be applied without restriction.

Comments on -introduction.

If Aunt Cordelia is years old, then there is obviously someone who is years old.

If there is any term for which holds, then one can conclude that some satisfies .

This is the type of valid reasoning that the -introduction rule is intended to formalize.

Definition

Suppose is a set of formulas in Form() and is a formula in Form(). We say that is formally deducible from in first-order logic iff

can be generated by the rules of formal deduction.

Example

Prove that

Solution: Prove the direct implication, .

We can now prove the converse, that is, .

Theorem (Replaceability of equivalent formulas in formal deduction for

first-order logic) Let Form() with . Let result from by substituting some (not necessarily all) occurrences of by . Then .

Theorem (Duality in formal deduction for first-order logic)

Suppose is a formula composed of atoms in Atom(), the connectives , and the two quantifiers and , by the formation rules concerned. Let be the formula obtained from by exchanging and , and , and negating all atoms. Then .

Theorem (Soundness and Completeness)

Let Form() and Form(). Then if and only if .

The theorem states that the formal deduction system for first-order logic defined by the rules of formal deduction is:

  • Sound implies , and
  • Complete implies

Proof strategies for formal deduction

One strategy for figuring out the high-level idea for a proof is to “ignore” the quantifiers, and imagine what the proof would look like if all formulas were in propositional logic.

After we have an idea of the general shape of the proof, we:

  • Remove quantifiers (e.g., by using or )
  • Carry on with the proof with the formulas in propositional logic
  • Introduce quantifiers, as needed (using , or ())

If one of the premises in is an existentially quantified formula, e.g., , the way to remove this , is to:

  • Replace the premise in by , resulting in ,
  • Carry on with the proof, with the modified set of premises ,
  • Use to reintroduce this back, at the very end, when does not appear anymore in the other premises or the conclusion (this step returns the premise set from the modified to the original premise set ).

Logic15: First-order-Logic Resolution

For resolution in first-order logic, and for other purposes, it is often more convenient to deal with formulas in which all quantifiers have been moved to the front of the formula. These types of formulas are said to be in prenex normal form.

Definition

A formula is in prenex normal form if it is of the form

where is or , for , and the expression is quantifier free.

The string is called the prefix and is called the matrix.

Convention: A formula with no quantifiers () is regarded as a trivial case of a prenex normal form.

Algorithm for converting a formula in Form() into prenex normal form.

Any formula in Form() is logically equivalent to (and can be converted into) a formula in prenex normal form (PNF). To find its logically equivalent formula in PNF, the following steps are needed:

  • Eliminate all occurrences of and from the formula.
  • ”Move all negations inward” such that, in the end, negations only appear as part of literals
  • Standardize the variables apart, when necessary.
  • The prenex normal form can now be obtained by “moving” all quantifiers to the front of the formula.

In the following, we will describe the logical equivalences that can be used to accomplish the steps above.

To accomplish Step 1 (eliminate ), make use of the following logical equivalences:

To accomplish step 2 (move all negations inward, such that negations only appear as parts of literals), use the logical equivalences:

  • De Morgan’s Laws
  • Double negation:

Step 3 (Standardize)

Recall that the symbol denoting a bound variable is just a place holder, and two occurrences of a symbol in a formula do not necessarily refer to the same bound variable. For example, in , the first two occurrences of in the formula refer to the variable in the scope of , while the last occurrence of refers to a distinct variable, in the scope of .

Renaming the variables in a formula such that distinct bound variables (variables bound by distinct quantifiers) have distinct names called standardizing the variables apart.

To accomplish Step 3, we use the following theorem, which allows us to rename bound variables.

Theorem (Replaceability of bound variable symbols)

Let be a formula in Form(). Suppose that results from by replacing in some (not necessarily all) occurrences of by , where . Then and .

Example:

becomes

Step 4 (move all quantifiers to the front)

To accomplish Step 4, make use of the following logical equivalences:

  • not occurring in .
  • not occurring in .
  • not occurring in .
  • not occurring in .

These equivalences essentially show that if a formula has a truth value that does not depend on , then one is allowed to quantify it over , using any quantifier.

Example: Find the prenex normal form of

Solution:

Definition

A sentence (formula without free variables) Sent() is said to be in free prenex normal form if it is in prenex normal form and does not contain existential quantifier symbols.

Consider a sentence of the form where , and is an expression, possible involving other quantifiers.

  • Note that generates at least one individual for each tuple in the domain.
  • In other words, the individual generated by is a function of , which can be expressed by using
  • The function is called a Skolem function.
  • The function symbol for a Skolem function is a new function symbol, which must not occur anywhere in .

Skolem functions allow one to remove all existential quantifiers. The skolemized version of is where , and is the expression obtained from by substituting each occurrence of be .

Example: Let the domain be , and consider . Each instance of , say , generates a corresponding that makes the formula true. If we define , we have that the skolemized version of the formula is .

More generally, in , one has a different value of generated, for each value of . The skolemized version of is . Here, is the Skolem function “generating” a value , for each value of .

Note that the sentence obtained by using Skolem functions is not, in general, logically equivalent to the original sentence. This happens because it is possible that there is more than one individual arising from the existential quantifier. However, for our purposes, it is irrelevant how many individuals satisfy in , as long as there exists at least one individual.

It is convenient to consider individual symbols as functions of zero arguments. With this convention, the skolemized sentence remains valid even if an existential quantifier is not preceded by any universal quantifier .

For any sentence in Sent() we can generate a sentence in free prenex normal form by using the following algorithm.

Step 1: Transform the input sentence Sent() into a logically equivalent sentence in prenex normal form. Set .

Step 2: Repeat until all existential quantifiers are removed.

  • Assume is of the form where is an expression, possibly involving quantifiers.
  • If , then is of the form . Then , where is obtained from by replacing all occurrences of by the individual symbol , where is a symbol not occurring in .
  • If , where is the expression obtained from by replacing all occurrences of by , where is a new function symbol.
  • Increase by .

Example: Transform the following sentence into free prenex normal form:

Becomes

which is a formula in free prenex normal form.

Theorem

Given a sentence in Sent(), there is an effective procedure for finding an free prenex normal form formula such that is satisfiable iff is satisfiable.

Notational convention:

  • After all the existential quantifiers have been eliminated through Skolem functions, and the formula is in free prenex normal form, it is customary to “drop” the universal quantifiers.
  • For instance, becomes .
  • The above conventional notation means that, when working with formulas in free prenex normal form (e.g., in resolution for first-order logic), all variables are implicitly considered to be universally quantified.

From formulas in first-order logic to clauses.

Theorem

Given a sentence in free prenex normal form, one can effectively construct a finite set of disjunctive clauses such that is satisfiable iff the set of clauses is satisfiable.

Example: Construct the set of clauses for

First we put the matrix of in Conjunctive Normal Form

Now we can read off the clauses from the conjuncts, that is,

Valid argument & satisfiability of clause set

Theorem

Let be a set of sentences, and be a sentence. The argument is valid iff the set

is not satisfiable.

In other words, an argument in first-order logic is valid (the conclusion is a logical consequence of the premises) iff the set of clauses consisting of the union of:

  • : The sets of clauses obtained from each premise in , and
  • The set of clauses generated by the negation of the conclusion

is not satisfiable.

Let the set of premises of an argument in first-order logic be

and the conclusion of the argument be

Find the set of clauses that is not satisfiable iff the argument is valid.

Solution:

The negation of the conclusion is

Putting in prenex normal form gives

For obtain the formula in free prenex normal form

The premises are already formulas in free prenex normal form.

Thus, the set of clauses consists of

The set of six clauses is not satisfiable iff the argument is valid.

Thus, if we would want to prove that the original argument were valid, we would have to show that the set of clauses is not satisfiable.

For this, we will use resolution for first-order logic.

A last ingredient for resolution: Unification

In resolution we aim to reach the empty clause (symbolizing a contradiction, that is, a formula that is not satisfiable).

In propositional logic, it is impossible to derive a contradiction from a set of formulas, unless the same variable occurs more than once.

For instance, there is no way to derive a contradiction from the two formulas and . The two formulas do not share variables, and the truth of the first has no bearing on the truth of the second.

Similarly, in first-order logic, one cannot derive a contradiction from two formulas and share complementary literals.

To obtain complementary literals, we may have to use a procedure called unification.

Definition

An instantiation is an assignment to a variable of a quasi-term (defined as either an individual symbol, or a variable symbol, or a function symbol applied to individual symbols or variable symbols). We write .

Definition

Two formulas in first-order logic are said to unify if there are instantiations that make the formulas in equation identical. The act of unifying is called unification. The instantiation that unified the formulas in question is called a unifier.

Note: Unification works because in resolution all variables are implicitly universally quantified. Thus, the steps that lead to unification are either variable renamings, or applications of universal instantiation, .

Example: Assume that and are expressions appearing on different lines in a resolution proof. Show that the two expressions unify and give a unifier.

Solution: Since in is a different variable than in , rename in the second formula to become . This means that one must unify with . An instance of is (given by , and an instance of is (given by . Since these two instances are identical, and unify, with unifier is .

Recall that resolution can only be applied to expressions that contain complementary literals.

The idea is now to create complementary literals by means of unification, and then to determine the resolvent.

Example: Find the resolvent of the following two clauses:

Here are individual symbols and are variable symbols.

Solution: To obtain two complementary literals, we unify in the first clause with in the second clause.

Since in the st clause are (implicitly) universally quantified, we can instantiate these variables by any quasi-term.

In particular, we can set , which yields

Similarly, one can instantiate the variables in the nd clause by any quasi-term. We set and obtain

Once the unification is done, the resolvent of the two new clauses

can be found, as

Note that not all expressions can be unified. For example, and cannot be unified, because there is no instantiation that makes individual become individual .

In general, the decision of which expressions to unify is nontrivial. To make a good choice as to which expressions to unify next, one must think about what is to be accomplished.

Automated Theorem Proving

A theorem is a logical argument, in the sense that it has several premises and a conclusion.

To automatically prove that a theorem is correct (that is, prove it is a valid logical argument), we first transform the premises and negation of the conclusion into a set of clauses, as follows:

  • Each formula is converted into Prenex Normal Form.

  • The existential quantifiers are replaced by Skolem functions.

  • The universal quantifiers are dropped (by convention).

  • The resulting quantifier-free sentences are converted into clauses, i.e., their matrices are transformed into Conjunctive Normal Form, with each disjunctive clause becoming a separate clause on its own.

If the set of clauses thus obtained is not satisfiable, then the theorem is correct (it is a valid logical argument).

Theorem

A set of clauses in first-order logic is not satisfiable iff there is a resolution derivation of the empty clause, (a contradiction) from .

Soundness: If resolution with input outputs the empty clause, then the set is not satisfiable.

Completeness: If the set is not satisfiable, then resolution with input outputs the empty clause.

By the Soundness and Completeness Theorem, a set of clauses is not satisfiable iff a contradiction (the empty clause, ) can be derived by resolution.

Resolution can only be applied to formulas that contain complementary literals.

To create complementary literals, we use unification, and then we determine the resolvent.

Any search for a contradiction in a set of clauses can be restricted to formulas that can be unified.

Thus, automated resolution theorem proving uses unification combined with resolution to obtain an efficient refutation method (method for obtaining a contradiction, ).

Example: Prove that everybody has a grandparent, provided everybody has a parent.

Solution: Let the domain be the set of all people, and represent is a parent of . The premise can now be stated as .

From this, we must be able to conclude that there exists a parent of a parent, which can be expressed as .

We must thus prove that

We add the negation of the conclusion to the set of premises, which yields the formulas:

Eliminate the existential quantifiers (obtain the free prenex normal form of the formulas) to obtain:

After dropping the universal quantifiers, this yields the set of clauses

Resolution can now be used to find the empty clause (a contradiction) as follows:

By the Soundness of Resolution, the fact that we obtained the empty clause implies that the original argument is valid.

Comments on resolution.

Any clause can be used multiple times as parent clause.

Any clause with variables can be instantiated multiple times:

  • For example, if is a clause, it can produce the new clause via the instantiation and , as well as the new clause via the instantiation and , if so needed.
  • The intuition behind instantiation is that in resolution for first-order logic, after obtaining formulas in free prenex normal form, all variables are assumed to be implicitly universally quantified and can thus be instantiated by any quasi-terms.

In any given clause, we can remove duplicate literals. For instance, is written as .

Resolutions that result in formulas that are (universally) valid should be avoided, since a formula that is always true can never lead to a contradiction. For example, one should avoid a resolution whose resolvent is .

Logic16a: Logic and Computation

Recall, an argument in first-order logic is valid iff the set of clauses obtained from all premises and the negation of conclusion is not satisfiable.

The Soundness and Completeness for resolution in first-order logic states that a set of clauses is not satisfiable iff there is a derivation of the empty clause , from , by resolution.

Informally, an algorithm is a finite sequence of well-defined computer-implementable instructions, typically to solve a class of problems or perform a computation.

We say that an algorithm solves a problem if, for every input, the algorithm produces the correct output.

There are problems that cannot be solved by computer programs (algorithms), even assuming unlimited time and space.

Halting Problem: Does there exist an algorithm (program) that operates as follows:

We will describe Turing’s proof that no such algorithm exists.

Halting problem examples.

The "" problem

Input: Positive integer

While is not equal to

  • If is even, then
  • Else

Question

Does this halt on all inputs?

No one knows.

Theorem

The Halting Problem is unsolvable.

Proof: By contradiction.

Assume that there is a solution to the Halting Problem, namely a program called that can determine whether or not a program halts, as follows.

takes two inputs, the first being a program , and the second being (an input to the program ).

outputs:

  • The string “halt” (Yes) if the program halts on input , and
  • The string “loops forever” (No) if the program never stops on input

We will now derive a contradiction.

When an algorithm is coded, it is expressed as a string of characters; this string can be interpreted as a sequence of bits.

This means that the program itself can be used as data.

Therefore, a program can be thought of as input for another program, or even for itself.

Hence our hypothetical program can take a program as both its inputs, that is, we could call .

should be able to determine whether will halt when it is given a copy of itself as an input.

Construct a program such that:

  • If outputs “halt”, then goes into an infinite loop, e.g., printing “ha” at each iteration.
  • If outputs “loops forever”, then halts.

In other words, does the opposite of what the output specifies.

Case : If halts then, by definition of , it follows that outputs “halt” then, by construction of (which calls , and does the opposite of what specifies), we have that loops forever - contradiction.

Case : If loops forever then, by definition of , it follows that outputs “loops forever”. But, if outputs “loops forever” then, by construction of (which calls , and does the opposite of what specifies, we have that halts - contradiction.

Since in both cases we reached a contradiction, our assumption of the existence of a “halting program” was incorrect.

Thus, no algorithm exists, that solves the Halting Problem (i.e., for all inputs and , it terminates and answers “Yes” if program stops on input , and “No” otherwise).

A Turing Machine is a simple mathematical model of the notion of algorithm/computation. It consists of:

  • A two-way infinite tape, divided into cells
  • A finite control unit with a read-write head, which can move along the tape, and can be in any state from a finite set of states
  • Read/Write capabilities on the tape, as the finite control unit moves back and forth on the tape, changing states depending on: (a) the tape symbol currently being read, and (b) its current state

A Turing Machine consists of:

  • - a finite set of states,
  • - an input alphabet (finite set of symbols/letters) containing the blank symbol ,
  • - the start state,
  • - a partial function called the transition function, where and stand for the direction “left” and “right.”

To interpret this definition in terms of a machine, consider a control unit and a tape divided into cells, infinite in both directions, having only a finite number of non-blank symbols on it at any given time.

Given a string, to write it on the tape means that we write the consecutive symbols of this string in consecutive cells.

The action of the Turing machine at each step of its operation depends on the value of the transition function for the current state and current tape symbol being read by the control unit.

At each step, the control unit reads the current tape symbol . If the control unit is in state and the partial function is defined for the pair , by , then the control unit:

  1. Enters the state ,
  2. Writes the symbol in the current cell, erasing , and
  3. Moves right (left) by one cell if (respectively )

We write this step as the five-tuple , and call it a transition rule of the TM.

If the transition function is undefined for the pair , then the Turing machine will halt.

At the beginning of its operation a TM is assumed to be in the initial state and to be positioned over the leftmost non-blank symbol on the tape. If the tape is all blank, the control head can be positioned over any cell.

This positioning of the control head in state over the leftmost non-blank tape symbol is the initial position of the machine.

An alphabet is a finite non-empty set of symbols, also called letters. For example is an alphabet.

By we denote the set of all possible strings written with letters from , including the empty string . For example, if then are strings in .

A language over is a subset of . If , then is a string with equally many 0s and 1s is a language over .

TMs can be used to accept / recognize languages.

To do so requires that we define the concept of final state.

Definition

A final state of a Turing machine is any state that is not the first state in any five-tuple in the description of using five-tuples.

Definition

Let be a subset of . A Turing machine accepts (recognizes) a string if and only if , starting in the initial position when is written on the tape, halts in a final state. is said to accept (recognize) a language , if is accepted (recognized) by if and only if belongs to .

Note that to accept a subset of we can use symbols not in . This means that the input alphabet may include symbols not in . These extra symbols are often used as markers.

Question

Question: When does a Turing Machine not accept a string in ?

Answer: A string is not accepted if, when started in the initial position with written on the tape, either

  • does not halt, or
  • halts in a non-final state.

A common way to define a TM is to specify its transition rules as a set of five-tuples of the form . Another way to define a TM is by a transition diagram, where

  • Each state is represented by a node.
  • The start and final states are specified
  • A transition rule ( is symbolized by an arrow between node and the node . This arrow is labelled by the triplet (current-symbol, new-symbol, move).

We saw that Turing machines can be used to accept languages.

A TM can also be thought of as computing a partial function.

  • Suppose that the Turing machine , when given the string as input, halts with the string on its tape.
  • We can then define .
  • The domain of is the set of strings for which halts.
  • is undefined if does not halt when given as input.

Using appropriate encoding of integers in unary notation, the idea above can be used to define TMs that compute (partial or total) functions from integers to integers.

Definition

Definition: A Turing Machine that always halts, on every input is called a decider or a total Turing Machine.

TMs are relatively simple, but they are extremely powerful.

Turing also showed that one can construct a single TM, called Universal Turing Machine (UTM) that can simulate the computations of every TM, when given as input: an encoding of the TM, together with an input for the TM.

The Turing machine is the currently accepted formalization of the informal notion of algorithm/computation, and is the most general model of computation; the total Turing machine is the formalization of the notion of terminating algorithm.

A Universal Turing Machine is the formalization of the notion of a computer (A UTM can do whatever a computer can do).

Clearly we cannot prove that the Turing Machine model is equivalent to our intuitive idea of an algorithm/computation, but there are compelling arguments for this equivalence, which has become known as the Church-Turing Thesis, which states:

It was proved that a Turing Machine is equivalent in computing power to all other, most general, mathematical models of computation. Thus, the Church-Turing Thesis is used as a basis to prove if a given problem is solvable by a computer or not.

Definition: A decision problem is a yes-or-no question on an infinite set of inputs. Each input is an instance of the problem,

Example: Satisfiability for First-Order Logic:

  • Input: A formula in first-order logic.
  • Output: Yes, if is satisfiable, and no otherwise

We can think of a decision problem as the language of all problem instances for which the answer to the corresponding decision problem is “yes”.

Definition

A decision problem for which there exists a terminating algorithm that solves it (a total TM that accepts those and only those problem instances that lead to a “yes” answer), is called decidable (solvable). If no such algorithm exists, the decision problem is called undecidable (unsolvable).

Definition

A (total) function that can be computed by a (total) TM is called computable, otherwise it is called uncomputable.

Turing machines were introduced by Alan Turing. The Halting Problem was proved undecidable by Turing in .

Given a formula in propositional logic, is :

  1. Unsatisfiable?
  2. Satisfiable?
  3. A tautology?
  4. A contradiction?

All the above problems are decidable and we have described several algorithms to solve them during this course.

To show that a problem is undecidable we often use reductions.

A mathematician and an engineer are on a desert island. They find two palm trees with one coconut each.

The engineer climbs up the first tree, gets the coconut, eats.

The mathematician climbs up the second palm tree, gets the coconut, climbs the first palm tree and puts the coconut there:

“Now we’ve reduced it to a previously solved problem.”

Say we know that problem is solvable, and want to solve new problem . If we reduce problem to problem , this implies “If was solvable, then is solvable.”

Conversely, say we know that is unsolvable and want to prove that is also unsolvable. Then we have to use the opposite reduction, that is, reduce the old unsolvable problem to the new problem .

Assume we already proved that another problem is undecidable.

If we have a (terminating) algorithm to convert any instance of the problem into an instance of the problem with the same yes/no answer, we say that “we reduced to “.

Such an algorithm is called a “reduction from to “.

Theorem

Theorem: If Problem is reducible to problem , then “If is undecidable then is undecidable”.

It is a common mistake to try to prove a new problem undecidable by reducing to some old known (undecidable) problem , thus proving the statement “If is decidable, then is decidable”

That statement, although true, is useless, since its hypothesis ” is decidable” is false.

The correct way to prove a new problem undecidable is to reduce another known undecidable problem to our .

This reduction proves that “If were decidable, then would be decidable,” with contrapositive “If is undecidable, then is undecidable.”

Thus, since we know that is undecidable, the antecedent of the latter implication is true and we can deduce that our is also undecidable.

The blank-tape halting problem.

Input: Turing Machine .

Question

Does halt when started with a blank tape?

Theorem

The blank-tape halting problem is undecidable.

Proof: Reduce the halting problem to the blank-tape halting problem (use nested deciders).

A decision problem for which there exists a terminating algorithm that solves it, is called decidable (solvable). If no such algorithm exists, the decision problem is called undecidable (unsolvable).

To show that a decision problem is solvable/decidable, we only need to construct a terminating algorithm that solves it.

To show that a decision problem is unsolvable/undecidable, we need to prove that no such algorithm exists. The fact that we tried to find such an algorithm but failed, does not prove that the problem is unsolvable.

By studying only decision problems, it may seem that we are studying only a small set of problems. However, most problems can be recast as decision problems.

Logic16b: Turing Machines

Example 1: Consider a Turing machine , with set of states , alphabet , start state and (partial) transition function defined by the transition rules:

Recall the five-tuple transition rule notation used to define the values of the transition function: for example, is denoted by the five-tuple , etc.

A Turing machine computation consists of successive applications of transition rules to the tape content.

One computation step (transition step) the application of one transition rule.

Question

What is the output of the computation of the Turing machine , given the input ?

Answer: The output is .

A configuration of a TM is denoted by .

Here is the current state of , and is the string in that consists of the current contents of the tape, starting with the leftmost non-blank symbol and up to the rightmost non-blank symbol, with respect to the read/write head (observe that the blank may occur in ).

The read/write head is assumed to be scanning the leftmost symbol of or, if , it is scanning a blank.

A computation of the TM consists of a succession of configurations, each obtained by applying one transition rule to the previous configuration ( denotes the application of a transition rule, and denotes zero or more rule applications).

With this notation, the computation of with input is

States are represented by nodes in a transition diagram (directed graph). The start state is singled out by an incoming arrow.

A transition rule is represented by an arrow (directed edge) from to , labelled by .

A computation corresponds to a path in the graph.

At the beginning, the TM is in the start state, with the read/write head over the leftmost symbol of the input string.

Example: Construct a Turing machine that recognizes (accepts) the set of bit strings in that have a as their second bit.

We want a TM that, starting at the leftmost non-blank tape cell, moves right and determines whether the nd symbol is a .

If the nd symbol is a , the TM should move into a final state. If the nd symbol is not a , the TM should not accept (that is, it should not halt, or it should halt in a non-final state).

We include five-tuples and to read the st symbol and put the TM in state .

We include five-tuples and to read the nd symbol and either move to state if this symbol is a , or to state if this symbol is a ( should be a final state).

We do not want to recognize strings with as their nd symbol, so should not be a final state (final states have no outgoing transitions). Thus, we include the five-tuple .

We do not want to recognize the empty string, respectively a string with one bit only. Thus, we include the five-tuples , respectively .

The TM is , where , the alphabet is , the initial state is , the final state is , and the transition function is defined by the seven five-tuples we described.

This TM will terminate in the final state if and only if the input bit string has at least two bits, and the nd bit of the input string is a .

If the bit string contains fewer than two bits, or if the nd bit is not a , the TM will terminate in the non-final state .

Final states are double-circled nodes (final states = states with no outgoing arrows).

TM computation on input string (accept, as nd bit is ) .

TM computation on input string (not accept)

TM computation on input string , and blank tape (not accept) .

Note: This TM is not minimal.

Example:

Construct a TM that recognizes the set .

We will use an auxiliary tape symbol as a marker.

We have , and .

We wish to recognize only a subset of strings in .

We will have one final state, .

The TM successively replaces a at the leftmost position of the string with an , and a at the rightmost position of the string with an , sweeping back and forth, terminating in a final state if and only if the string consists of a block of s followed by a block of the same number of s.

Although this is easy to describe and is easily carried out by a Turing Machine, the machine is somewhat complicated.

We use the marker to keep track of the leftmost and rightmost symbols we have already examined.

To consider a TM as computing number-theoretic functions (functions from the set of -tuples of natural numbers to the set of natural numbers), we need a way to represent tuples of natural numbers on tape.

We use unary representations, whereby the natural number is represented by a string of s.

For instance, is represented by the string , and is represented by the string .

To represent the -tuple ( we use a string of s, followed by an asterisk, followed by a string of s, followed by an asterisk, and so on, ending with a string of s.

For example, to represent the four-tuple we use the string .

Example: Construct a TM that adds two natural numbers.

We need a TM computing function .

The pair is represented by a string of s, followed by an asterisk, followed by a string of s.

The TM should take this as an input and produce as output a tape with s.

One way to do this is as follows (the alphabet is .

The TM first erases the leftmost of . If , then it erases the asterisk and it halts.

Otherwise, it reads the leftmost remaining in (and it deletes it, but remembers this by changing to state ), then traverses all remaining s in until it reaches the asterisk , which it replaces by the “remembered” . Then it halts, in final state .

The transition function is: .

A total function that can be computed by a total Turing machine is called computable, otherwise it is called uncomputable.

Uncomputable function example: the Busy Beaver function.

Let be the maximum number of s that a Turing machine with states and alphabet may print on a tape before halting, when started with a blank tape. The problem of determining for particular values of is known as the Busy Beaver Problem.

Currently it is known that and , but is not known for . It is known that and

Constructing TMs to compute relatively simple functions can be extremely tedious. For example, a TM for multiplying two non-negative integers, which is found in many books, has five-tuples, and states.

If it is challenging to construct TMs to compute even relatively simple functions, what hope do we have of building TMs for more complicated functions?

One way to simplify this problem is to use a multi-tape TM that uses more than one tape simultaneously, and to build up multi-tape TMs for the composition of functions.

It can be shown that TMs and multi-tape TMs have the same computational power, that is, for any multi-tape TM there is as one-tape TM that can compute the same thing.

Assuming that the Church-Turing thesis holds, “If there exists an algorithm that solves a problem, then there exists a TM that solves it.”

Logic17: Peano Arithmetic

We gave seen two rules of formal deduction concerning equality, , where is a relation, and are terms.

If , then , where results from by replacing some occurrences of by .

We can use these rules to prove the usual properties of equality.

  • (Reflexitivity of Equality)
  • (Symmetry of Equality)
  • (Transitivity of Equality)

Proof that

  1. [ not elsewhere]

Notation conventions:

We employ and interchangeably, usually using when citing a formal deduction rule/theorem involving equality, and using when equality occurs inside a formula.

Proof that

  1. , [ not elsewhere]
  2. , [ not elsewhere]

Proof that

  1. , [ not elsewhere]
  2. , [ not elsewhere]
  3. , [ not elsewhere]

First-order logic is often used to describe specialized domains, starting from a small number of relation and function symbols. In each case, we use some “domain axioms”, which are first-order logic formulas assumed to be true in that domain, and that specify properties of the relation and function symbols.

A set of domain axioms, together with a system of formal deduction, and all theorems that can be formally proved from the domain axioms, is called a theory. Examples:

  • Number theory
  • Set theory
  • Group theory
  • Graph theory

The set of domain axioms is a set of first-order logic formulas which we accept (assume to be always true in that domain/theory).

The set should be decidable: There should exist a terminating algorithm to decide if a given formula is a domain axiom.

The set should be consistent (with respect to for first-order logic).

The set should be syntactically complete, in the sense that for any formula describable in the language of the system, either or its negation, , should be provable from .

Note: The notion of syntactic completeness of a set of domain axioms (and its corresponding theory) is different from that of (semantic) completeness of a system of formal deduction (the latter means that implies ).

Oldest example of a “theory” - Euclidean Geometry.

Euclid’s Postulates (“Geometry Axioms”)

  1. A straight line may be drawn between any two points.
  2. Any straight line can be extended infinitely.
  3. A circle may be drawn with any given point as the centre, and any given radius.
  4. All right angles are equal.
  5. Parallel Postulate: For any given point not on a given line, there is exactly one line passing through the point, that is parallel to the given line.

There were many failed attempts over the centuries to prove that Parallel Postulate from the others.

Finally, it was proved that there exist interpretations in which all the other “geometry axioms” hold true, but the Parallel Postulate fails.

Thus, by the Soundness and Completeness Theorem, the Parallel Postulate is not provable from the other geometry axioms.

Note: In non-euclidean geometry the Parallel Postulate is replaced with other possibilities: no such line (spherical or elliptic geometry), infinitely many lines (hperbolic geometry), or no assumption (absolute geometry).

Another example is Number Theory.

Intended interpretation:

  • Domain: Natural numbers
  • Addition
  • Multiplication
  • Ordering via

Number Theory Axioms should be a small set of true statements (formulas) from which all theorems about natural numbers can be derived. We want induction.

Peano’s axioms are the basis for the version of number theory known as Peano Arithmetic (PA).

Non-logical symbols:

  • Individual (constant):
  • Functions: Successor , (addition), (multiplication)
  • Relation: Equality (this is already part of first-order logic)

Axioms defining the unary function successor, and the binary functions addition, and multiplication and axiom for induction.

Axioms defining the unary function successor, denoted by

PA1

PA2

We want the successor to give us

  • Numbers (which are )
  • (we will prove it later), etc.

Note: We often use to denote

Axioms defining the binary function addition, denoted by

PA3

PA4

Axioms defining the binary function multiplication, denoted by

PA5

PA6

Principle of Mathematical Induction

Let be a statement that depends on .

If

  1. (Base Case) is true and
  2. (Inductive Step) For all we have: ” is true implies that is true”

then is true for all .

Recall that ” is true” is called the “Inductive Hypothesis”)

Express the Principle of Mathematical Induction in first-order logic:

Let PA be the set PA1, PA2, PA3, PA4, PA5, PA6, PA7

In a Peano Arithmetic proof, the set PA is implicitly considered to be part of the set of premises of any theorem we wish to prove.

To account for this, we introduce the following;

Notation: Given a theory , with an associated set of axioms , we use to denote the fact that

In particular, for Peano Arithmetic, denotes

Proofs in Peano arithmetic.

Example 1: Prove that .

Solution: Formally, we want to prove that

Proof idea: Apply induction to .

Use PA7:

Proof structure:

  1. Prove , the Base Case.
  2. Prove , the Inductive Step
  3. Obtain from and , by
  4. Obtain , using and PA7, by

Informal Proof

Apply induction to

Base Case:

By PA1: , with proves the Base Case.

Inductive Step:

Assume (IH).

Prove

Prove the inductive step by contradiction.

Suppose .

By PA2: , with , we have . This contradicts the I.H

Formal proof of

Example 2: Prove that .

(A natural number is either zero, or it has a predecessor.)

Formally, we have to prove that

Take to be . We have to prove .

We will use induction on , as formalized by:

PA7:

(Base Case) We first need to prove the first operand of , that is, prove which is

(Inductive Step) For the second operand of , we will assume the Inductive Hypothesis holds: .

Under this assumption, we will have to prove holds:

Then we use to obtain , and use to generalize over , to conclude the proof of the Inductive Step.

Finally, we will use PA7 and to obtain .

To prove

Base Case: - the proof is easy, with and .

Inductive Step: Prove . Since is the disjunction , we seem to need proof by cases, . However, this is not needed. Note that is , which we can prove without using .

We will use ”, where is any term,” proved below:

  1. (Reflexitivity of )

We use this theorem under the same name, “Reflexitivity of “.

Proof of

Other theorems we can prove.

  • Commutativity of addition (requires double induction)
  • Associativity of addition
  • Commutativity of multiplication
  • All the things you expect

We can define new arithmetic relations be using logic formulas to describe their behaviour. For example, we can define:

  • to be true iff
  • to be true iff
  • to be true iff
  • to be true iff

We can use axioms of Peano Arithmetic to prove properties of relations.

Example 3: Prove that is transitive:

We do not need induction. We only need the properties of equality, and associativity of addition (in this example, we assume that we proved associativity of addition).

Proof idea (informal):

  • From and we want to prove
  • means , implying for some
  • means , implying for some .
  • Start with and , and use to substitute in , resulting in
  • Use associativity of addition to obtain
  • Introduce to obtain which means .

In this way we can obtain all the theorems we have ever seen in number theory, starting with just Peano axioms, and using the rules of formal deduction for first-order logic to deduce new theorems.

Theorem (Gödel's Incompleteness Theorem)

In any consistent formal theory with a decidable set of axioms, that is capable of expressing elementary arithmetic (e.g., Peano Arithmetic), there exists a statement/formula that can neither be proved nor disproved in the theory.

Gödel’s original proof constructs a particular statement indirectly stating ” is unprovable in ” ( is referred to as “the Gödel sentence” for the system ).

Gödel specifically cites the Liar Paradox, namely the sentence stating “This sentence is false”

A Gödel sentence for a theory makes an assertion similar to the Liar Paradox, but with “truth” replaced by “provability”.

The analysis of the provability of is a formalized version of the analysis of the truth of the Liar Paradox.

A CS proof of Gödel’s Incompleteness Theorem.

Proof (by contradiction): Assume that any statement can be formally proved or disproved in the theory . We will use this assumption to solve the Halting Problem.

Write a program (Turing Machine) that takes two inputs, a program and an input for the program , and:

1. Generates all strings , of all lengths (in increasing length-order), over the Latin alphabet and the set of math symbols.

  • Most of them will be nonsense, some will be English, some will be “Hamlet”, some will be proofs.

  • By definition, any proof is of finite length.

  • Among the strings , there will be attempted proofs that halts on , and attempted proofs that does not halt on .

2. For each string , the program checks whether is a correct formal proof of the statement ” halts on input ” (output “yes and stop), or a proof of its negation (output “no” and stop).

Since either the statement ” halts on input ” or its negation can be formally proved in , our program terminates and gives the correct yes/no answer.

This means we solved the Halting Problem, which is unsolvable.

Since we reached a contradiction, our assumption was incorrect, and there exist statements, expressible in , that can neither be proved or disproved from the axioms of .

The CS proof of Gödel’s Incompleteness Theorem requires the ability to express a program (Turing Machine) in the theory . Peano Arithmetic is such a theory.

The proof contains the consistency of as hidden assumption: If were inconsistent, the program could find a formal proof that halts on , even if did not halt on , and viceversa (since both proofs could exist). Thus, the program would not solve the Halting Problem since it could output an incorrect answer.

Theory domain axioms a system of formal deduction, all theorems thus provable from domain axioms.

Gödel’s Incompleteness Theorem establishes inherent limitations of all but the most trivial theories, i.e., inherent limitations of theories capable of doing at least basic arithmetic.

Gödel’s Incompleteness Theorem is important both in mathematical logic and in the philosophy of mathematics.

This result is widely - but not universally - interpreted as showing that Hilbert’s program to find a (decidable) syntactically complete and consistent set of axioms for all mathematics is impossible.

Gödel proved the Completeness Theorem for First-Order Logic in 1929.

Gödel published his Incompleteness Theorem (syntactic incompleteness of consistent theories with a decidable set of axioms, capable of expressing basic arithmetic) in .

Paris-Harrington Theorem is a theorem, expressible in Peano Arithmetic and not self-referring, that is unprovable in Peano Arithmetic (it can be proved in another system).

Another such theorem was found by Putnam and Kripke.

Does this contradict the “Completeness of “? (since if then by Completeness of FoL ?) NO.

  • Theorem does not say that (this would mean that all interpretations that make true, also make true).

  • What happens is that, while is true in the standard interpretation of arithmetic, (domain is is “zero”, etc.), there are “nonstandard interpretations” of natural numbers that satisfy the Peano axioms , but do not satisfy .

  • In other words, , because there exist two interpretations that make true, one (standard) making true, the other (nonstandard) making false.

  • Thus, Completeness of first-order logic () is not contradicted.

The book “Godel, Escher, Back: an Eternal Golden Braid” includes a complete and entertaining proof of Gödel’s Incompleteness Theorem.

Logic18: Program Verification

Question

Program correctness: does a program satisfy its specification-does it do what it is supposed to do?

Techniques for showing program correctness:

Inspection, code walk-throughs

Testing

  • Black-box testing: Tests designed independent of code

  • White-box testing: Tests designed based on code

Formal program verification

  • Formal verification is a formal proof system for proving programs correct.

  • The motivation being formal verification is similar to that of previous modules: A proof can provide confidence of correctness in a situation where exhaustive semantic checking is time-consuming or impossible.

Testing is analogous to checking that a propositional formula is a theorem by trying a few truth valuations, or to checking that a first-order formula is a theorem by constructing a few valuations.

Testing is not proof.

A proof calculus for program correctness was first proposed by Robert Floyd and Tony Hoare.

Formal program verification:

  • Formally state the specification of a problem (using the formalism of first-order logic), and

  • Prove that the program satisfies the specification for all inputs.

Question

Why formally specify and verify programs?

  • Reduce bugs

  • Safety-critical software or important components

  • Documentation

The steps of formal (program) verification:

  1. Convert the informal description of requirements for an application into an “equivalent” formula of some symbolic logic,

  2. Write a program which is meant to realize in some given programming environment, and

  3. Prove that the program satisfies the formula

We consider only Step 3 in this course and use a subset of C/C++ and Java, with their core features:

  • Integer and Boolean expressions

  • Assignment

  • Sequence

  • Conditionals

  • While-loops

A program specification is an informal or formal definition of what the program is expected to do.

Hoare Triples

Our assertions about programs will have the form

precondition

program or code

postcondition

The meaning of the triple :

If program is run starting in a state that satisfies the logic formula , then the resulting state after the execution of will satisfy the logic formula .

An assertion is called a Hoare triple.

Conditions and are written in the first-order logic of integers. Use relations functions, and other derivable from these.

Definition

A specification of a program is a Hoare triple with the program as the second component.

Example:

“If the input is a positive number, compute a number whose square is less than ” can be expressed as the Hoare triple .

Often we do not want to put any constraints on the initial state. In that case, the precondition can be set to true, which is a formula which is true in any state.

We want to develop a notion of program verification “formal proof” that will allow us to prove that a program satisfies the specification given by the precondition and the postcondition .

This kind of proof calculus is different from the (formal) proof calculus in first-order logic, since reasoning about Hoare triples has two additional features besides the logic formulas and :

  • Program instructions, and

  • A sense of time: Before execution, versus after execution

Definition

A Hoare triple is satisfied under partial correctness, denoted

if and only if for every state that satisfies condition , if the execution of the program starting from state terminates in state , then the state satisfies condition .

The program

while true {x = 0; }

satisfies all specifications under partial correctness.

It is an endless loop and never terminates, but partial correctness only says what must happen if the program terminates.

Definition

A Hoare triple is satisfied under total correctness, denoted

if and only if for every state that satisfies , execution of program starting from state terminates, and the resulting state satisfies .

Total Correctness = Partial Correctness + Termination

Example 1:

((x=1))
y=x;
((y=1))

This Hoare triple is satisfied under both partial and total correctness.

Example 2:

((x=1))
y=x;
((y=2))

This Hoare triple is satisfied under neither total nor partial correctness.

Example 3:

((x>=0))
y = 1;
z = 0;
while (z != x) {
    z = z + 1;
    y = y * z;
}
((y=x!))

This Hoare triple is satisfied under both partial and total correctness.

Partial correctness is a weak notion.

Example: Give a program that is satisfied under partial correctness for any pre- and postconditions.

Answer:

((P))
while (true) {
    x = 0;
}
((Q))

This program never terminates so partial correctness is vacuously satisfied.

Example: Give pre- and postconditions that are satisfied by any program under partial correctness.

Answer:

((true))
C
((true))

Suppose

  • never terminates satisfies the specification under partial correctness, but not under total correctness
  • sometimes terminates satisfies the specification under partial correctness, but not under total correctness
  • always terminates satisfies the specification under both partial and total correctness

Total correctness is our goal.

We usually prove partial correctness and termination separately.

  • For proving partial correctness, we will introduce sound inference rules.

  • For proving termination, we will use ad hoc reasoning, which suffices for our examples. (In general, program termination is undecidable)

There are different techniques for proving partial and total correctness.

We introduce a formal proof system for proving partial correctness.

Recall the definition of partial correctness: For every starting state that satisfies and for which terminates, the final state satisfies .

Question

How do we show this, if there are large or infinite number of possible states?

Answer: We define sound inference rules (like formal deduction rules)

A partial correctness proof will be an annotated program, with one or more conditions before and after each program statement.

Each program statement (instruction), together with the preceding and following condition, form a Hoare triple.

Each Hoare triple has a justification that explains its correctness.

Sometimes the pre- and postconditions require additional variables that do not appear in the program.

These are called logical variables (or auxiliary variables).

Inference rule for assignment

How to read program verification inference rules: “If the condition(s)/Hoare triples above the horizontal line are proved, then the Hoare triples above the horizontal line are proved, then the Hoare triple under the horizontal line holds.”

Intuition for the assignment rule: Normally, is a relation depending on the variable . If we denote this by writing , then the assignment rule informally means that the following statement holds, with no assumptions: ” will hold after assigning (the value of) to , if was true beforehand.”

We read the stroke "" as “in place of”. Thus, is read as ” with in place of ,” and it denotes the result of substituting in all occurrences of by . Here is a free variable.

Example:

Prove that the following Hoare triple is satisfied under partial correctness

((y+1 = 7))
x = y + 1
((x = y))

Solution:

The partial correctness is formally proved by one application of the (sound) assignment inference rule, with being "", and being "".

The assignment rule is applied backwards: The right way to understand it is to think about what we would have to prove about the initial state, in order to prove that holds in the resulting state.

Since will be in general depending on , whatever it says about must have been true for , since in the resulting state the value of is .

Thus, ” with in place of ” must be true of the initial state.

Example 1:

((y=2)) ((Q[E/x]))
x=y; x=E;
((x=2)) ((Q))

If we want to prove that after the assignment whereby takes value , then we must have proved before it.

Here is "", is , is "".

Example 2:

((0<2)) ((Q[E/x]))
x = 2; x = E;
((0 < x)) ((Q[E/x]))

If we want to prove that after the assignment whereby takes value , we must have proved before it.

Here is "", is , is "".

Implied Rule of “precondition strengthening”:

Implied Rule of “postcondition weakening”:

The implied rules allow us to import formal deduction proofs from first-order logic, , (enhanced with basic facts of arithmetic) into proofs in formal program verification.

Note that the first implied rule allows us the precondition to be strengthened (thus, we assume more than we need to), while the second implied rule allows the postcondition to be weakened (i.e., we conclude less than we are entitled to).

Example: Show that the program "" satisfies the specification under partial correctness.

((y=6))
((y+1=7)) implied
x = y + 1
((x=y)) assignment

Here the strengthened precondition is is , the precondition is , the program is , and the postcondition is .

Note that here we have .

Example: Show that the program "" satisfies the specification under partial correctness.

((y+1=7))
x=y+1
((x=7)) assignment
((x<= 7)) implied

Here the precondition is , the program is , the postcondition is , and the weakened postcondition is .

In this case, , but the converse does not hold.

Inference rule for instruction composition

In order to prove , whereby the program consists of a sequence (composition) of two instructions and , we need to:

  • Find a midcondition for which

  • We can prove , and

  • We can prove

Inference rules applied to a composition/sequence of instructions allows us to “string together” pre/postconditions and lines of code/

Each condition is the postcondition of the previous line of code and the precondition of the next line of code.

Interleave program statements with assertions ( conditions), each justified by an inference rule.

The composition rule is implicit.

Each assertion should hold whenever the program reaches that point in its execution.

Each assertion (condition) is justified by an inference rule.

If the implied reference rule is used, we also need to prove a (first-order logic) formal proof of the implication or . Usually, we do these proofs separately, after annotating the program.

Example 1: Show that the program "" satisfies the specification under partial correctness.

((y=5))
(y+1=6)) implied
x=y+1
((x=6)) assignment

The proof is constructed from the bottom upwards.

We start with and, using the assignment rule, we “push it upwards”, “through” the assignment that gives value .

This means substituting for all occurrences of , resulting in .

Now compare this with the given precondition .

The given precondition and the arithmetic fact that imply , so we have finished the proof.

Although constructed bottom-up, its justifications make sense when read top-down.

The second line is implied by the first line.

The fourth line followed from the second, by the intervening assignment which gives value .

Note that implied always refers to the immediately preceding line.

Programs with Conditional Statements:

if-then-else:

if-then (without else):

Annotated program template for if-then-else:

((P))
if ( B ) {
	((P ∧ B))
	C_1
	((Q))
} else {
	((P ∧ ¬B))
	C_2
	((Q))
}
((Q))

Example: Prove that the program below satisfies the specifications under partial correctness.

((true))
if (max < x) {
	max = x
}
((max >= x))

Let’s recall our proof method.

The three steps of a proof of partial correctness:

  1. First annotate the program using the appropriate inference rules.

  2. Then “back up” in the proof: Add an assertion/condition before each assignment statement, based on the assertion/condition following the assignment.

  3. Finally prove any “implieds”

Proofs here can use first-order logic, basic arithmetic, or any other appropriate reasoning.

((true))
if (max < x) {
	((true ∧ max < x))
	((x >= x)) Implied (a)
	max = x
	((max >= x))
}
((max >= x))

Implied (b)

The auxiliary “implied” proofs can be done using formal deduction in first-order logic (and assuming the necessary arithmetic properties). We will write them formally, or informally but clearly.

Proof of Implied (a):

Clearly, holds (basic arithmetic), and thus the required implication holds.

Proof of Implied (b): Show , which in this case is

”Partial while” (does not require termination)

(partial-while)

Intuitively: If the code C satisfies the tripe under partial correctness then, no matter how many times C is executed, if I was true initially and the while-statement terminates, then I will be true at the end.

Condition is called a loop invariant.

Annotations for partial-while:

((P))
((I)) Implied (a)
while (B) {
	((I ∧ B)) partial-while
	C
	((I))
}
((I ∧ ¬B)) partial-while
((Q)) Implied (b)

(a) Prove (precondition implies the loop invariant)

(b) Prove (exit condition implies postcondition)

We need to determine/find the loop invariant .

A loop invariant is an assertion (condition) that is true both before and after each execution of the body of a loop.

  • True before the while-loop begins

  • True after the while-loop ends

  • It expresses a relationship among the variables used within the body of the loop. Some of these variables will have their values changed within the loop.

  • An invariant may or may not be useful in proving termination.

((x >= 0))
y = 1
z = 0
while(z != x) {
	z = z + 1
	y = y * z
}
((y = x!))

From the trace of the loop and the postcondition, a candidate loop invariant is

((x>=0))
((1=0!)) Implied (a)
y=1
((y=0!))
z=0
((y=z!))
while (z != x) {
	(( (y=z!) ∧ ¬(z=x)) )) partial-while (( I ∧ B ))
	(( y(z+1) = (z + 1)! )) Implied (b)
	z = z+1
	((yz = z!))
	y = y * z
	((y = z!))
}
(( y = z! ∧ z = x )) partial-while (( I ∧ ¬B))
(( y = x! )) Implied (c)

Proof of implied (a): . By definition of factorial.

Proof of implied (c):

Proof of implied (b):

Total Correctness = Partial Correctness + Termination

Only while-loops can be responsible for non-termination in our programming language.

Proving termination: For each while-loop in the program: Identify an integer expression which is always non-negative and whose values decreases every time through the while-loop.

Total Correctness Problem: Is a given Hoare triple satisfied under total correctness?

Theorem

The Total Correctness Problem is undecidable.

Proof: Reduce the Blank-Tape Halting Problem to our problem:

  • Suppose we have a terminating algorithm to solve the Total Correctness Problem

  • We can use it to solve the Blank-Tape Halting Problem

  • Given program as input, construct a program that erases any input to , and then runs on the blank tape.

  • We can now use our algorithm to test if is totally correct.

  • Claim: The program halts on a blank take iff the Hoare triple is totally correct.

  • Contradiction, since the Blank-Tape Halting Problem is undecidable.

Question

Partial Correctness Problem: Is a given Hoare triple satisfied under partial correctness?

Theorem

The Partial Correctness Problem is undecidable.

Proof: Reduce the Blank-Tape Halting Problem to our problem.

  • Suppose we have a terminating algorithm to solve the Partial Correctness Problem. We can use it to solve the Blank-Tape Halting Problem for any program as follows.

  • Given program as input, make a new program by adding the new line "" to the end of (here is a new variable).

  • Claim: The program does not halt on a blank take iff the Hoare Triple is partially correct.

  • Contradiction, since the Blank-Tape Halting Problem is undecidable.