cse 3341.03 winter 2008 introduction to program verification january 15 tautology checking

22
CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

Upload: scott-shelton

Post on 18-Jan-2016

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

CSE 3341.03 Winter 2008Introduction to Program Verification

January 15

tautology checking

Page 2: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

recap

Boole is important because he showed how logic could be implemented in arithmetic (a calculus)

Page 3: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

examples:

arithmetic analogue to or?true <--> 1, false <--> 0

a and b <--> a * b

a or b <--> a + b - ?

not?

Page 4: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

computing reverses the logic-arithmetic relation

arithmetic is implemented by (digital) logic

Page 5: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

from the truth-table for implies

memorize:(P implies Q) iff (not P or Q)

• easy to check using tautology

logic operators are not intrinsically primitiveredefinable using other operators

Page 6: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

classifying propositions

propositions as functions divide into 3 obvious categories:constant false = contradiction

constant true = tautology

not constant = contingent

what’s the opposite of a contradiction?not always false = can be true = satisfiable

Page 7: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

another way to do it

the text (p. 13) uses different and more complicated expressions to define contradiction, contingent, satisfiable: what the point of this approach? we can use a tautology checker to test for all

the cases• examples:

• test for contradiction?• test for satisfiable?

Page 8: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

chapter 2 - tautology checking

tautology is our first tool for computational logic to be replaced with a better but more

complicated one we get started with a very simple one

note: the tools we will be using are in /cs/fac/binmake this part of your PATH variable.

Page 9: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

inputs tautology executes an input loop, either on sysin or a

data file.

each input must end in a period. Nothing happens until you enter the period (and carriage return)

the program is a compiled version of a SWI Prolog source file, executed by the SWI Prolog interpreter (virtual machine -- like Java)

runtime error almost always an error in the input note on using tautology: if you use terminal input to the tautology

program, how do you exit?

Page 10: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

input to be checked input a propositional function as a Boolean expression:

• false and true count as functions (with no arguments)

• use English operators

• function arguments are expressions or upper-case variables

• tautology echoes the input (replacing variable names with internal names)

• variables are renamed into a standard form $VAR(n), . .

Page 11: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

tautology's output

tautology reports whether the input is “valid” (i. e. a tautology) or “not valid”

if not valid, a valuation is printed that falsifies the input.

example output, pp. 14-15

Page 12: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

method of truth tables

how does this work? evaluation of truth-values is given by a set of rules that

define the meaning of each operation: example: X and Y = true if X =true and Y = true.

what if we find a certain combination of variable values make the expression false? we can quit evaluating

so tautology searches for falsifying values

Page 13: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

invalid inputs

how are invalid inputs detected?an assignment of truth-values to variables is

found which makes the input false. how is a counter-example constructed?

output the input with the variables in the input replaced by the falsifying truth-values

Page 14: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

under the hoodfalse('false').

false(not 'true').

false(P iff Q) :- false((P implies Q) and (Q implies P)).

false(P implies Q) :- false(not P or Q).

false(P or Q) :- false(P), false(Q).

false(P xor Q) :- false(not(P iff Q)).

false(P and Q) :- false(P) ; false(Q).

false(not not P) :- false(P).

false(not(P iff Q)) :- false( not(P implies Q)

or not(Q implies P)).

false(not(P implies Q)) :- false(not( not P or Q)).

false(not(P or Q)) :- false(not P and not Q).

false(not(P xor Q)):- false(P iff Q).

false(not(P and Q)) :- false(not P or not Q).

Page 15: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

why look for a proof of a false case rather than a proof of a true case?

what tells us that we don’t need any more rules?

• hint: have we covered all cases? (of what?)

Page 16: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

rule-based programming

tautology is example of data-driven rule-based programming

very important programming paradigm, first developed in AI;

data is matched to a sequence of patterns;

first pattern to match triggers a rule which computes a partial result;

repeat search for matching rule until no rule matches

Page 17: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

checking tautology how can we check if a rule like

• P or Q is false if P is false and Q is false

is correct logic? try: translate into tautology's input format

• not P and not Q implies not (P or Q)• and input to tautology

could we verify the tautology rules this way?

Page 18: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

exercises

exercise 2.2 Sec. 2.3: examples of translating various

notations into the tautology input format

Page 19: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

by hand vs. by machine?

why prove manually, what we can compute? logic professor’s argument: doing proofs in

propositional logic helps understanding proofs in math.

problem: not really true historically logic provides only a very sparse framework

on which to hang mathematical concepts(we'll see how to add the missing ingredient in Ch. 5)

Page 20: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

is there a fundamental difference between automating logic and automating arithmetic?

"AGPEPMPC

Applicative Goedelian Peano-Extended Principia

Mathematica Proof Checker

Grant Olney Passmore

October 15, 2004" "The Theorema project aims at extending current computer algebra systems

by facilities for supporting mathematical proving. The present Theorema software system is implemented in Mathematica . The system consists of a general higher-order predicate logic prover and a collection of special provers that call each other depending on the particular proof situations."

Page 21: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

Exercise 2.11

Let A -> B represent “If the car has gas, then I can go to the store.”;

B ^ C -> D represents “If I can go to the store and I have money, then I can buy food.”;

(D ^ (E v F)) -> G represents “If I have food and either the sun is shining or I have an umbrella, then today I can go on a picnic.”

If the above formulae are true, and the car has gas, and I have money and an umbrella, can I go on a picnic?

Show how to use tautology to answer the question.

Page 22: CSE 3341.03 Winter 2008 Introduction to Program Verification January 15 tautology checking

general vs specific

"If the above formulae are true, and the car has gas, and I have money and an umbrella, can I go on a picnic?"

Notice how the propositions can be divided into

general background statements and facts about a

specific situation, which generate an implication.

Apply this idea to Exercise 2.12