Some administrative stuff Class mailing list: –send to with the command “subscribe”

Slides:



Advertisements
Similar presentations
Artificial Intelligence
Advertisements

Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Completeness and Expressiveness
Introduction to Proofs
Synthesis, Analysis, and Verification Lecture 04c Lectures: Viktor Kuncak VC Generation for Programs with Data Structures “Beyond Integers”
Semantics Static semantics Dynamic semantics attribute grammars
Primitive Recursive Functions (Chapter 3)
Situation Calculus for Action Descriptions We talked about STRIPS representations for actions. Another common representation is called the Situation Calculus.
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
Compiler Construction
Plan for today Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Chapter 14: Overloading and Templates
ITERATIVE CONSTRUCTS: DOLIST Dolist is an iterative construct (a loop statement) consisting of a variable declaration and a body The body states what happens.
1 Module 7 Halting Problem –Fundamental program behavior problem –A specific unsolvable problem –Diagonalization technique revisited Proof more complex.
Correctness. Until now We’ve seen how to define dataflow analyses How do we know our analyses are correct? We could reason about each individual analysis.
1 Lecture 7 Halting Problem –Fundamental program behavior problem –A specific unsolvable problem –Diagonalization technique revisited Proof more complex.
1 Lecture 7 Halting Problem –Fundamental program behavior problem –A specific unsolvable problem –Diagonalization technique revisited Proof more complex.
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
1 Lecture 7 Topics –Problems about program behavior At least problem input is a program/algorithm –Halting Problem Fundamental problem about program behavior.
Review: forward E { P } { P && E } TF { P && ! E } { P 1 } { P 2 } { P 1 || P 2 } x = E { P } { \exists … }
Some administrative stuff Classroom change: –from next Tuesday on, we’ll be in Warren 2209 Class mailing list:
28-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
Review: forward E { P } { P && E } TF { P && ! E } { P 1 } { P 2 } { P 1 || P 2 } x = E { P } { \exists … }
EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 6 Limitations of propositional logic Introduction to predicate logic Symbols, terms and formulae, Parse.
CS 106 Introduction to Computer Science I 10 / 15 / 2007 Instructor: Michael Eckmann.
1 Assignment 8. Implementing type integer Due on Tuesday, 4 December, by midnight (submitted electronically). Download class List and a skeleton of class.
Ofer Strichman, Technion Deciding Combined Theories.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
The ACL2 Proof Assistant Formal Methods Jeremy Johnson.
Introduction to Proofs
Reading and Writing Mathematical Proofs
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
MATH 224 – Discrete Mathematics
4.1 Instance Variables, Constructors, and Methods.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Slide 1 Propositional Definite Clause Logic: Syntax, Semantics and Bottom-up Proofs Jim Little UBC CS 322 – CSP October 20, 2014.
CS621: Artificial Intelligence Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 28– Interpretation; Herbrand Interpertation 30 th Sept, 2010.
1 Advanced Issues on Classes Part 3 Reference variables (Tapestry pp.581, Horton 176 – 178) Const-reference variables (Horton 176 – 178) object sharing:
Course Overview and Road Map Computability and Logic.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Recap form last time How to do for loops map, filter, reduce Next up: dictionaries.
Pointers: Basics. 2 What is a pointer? First of all, it is a variable, just like other variables you studied  So it has type, storage etc. Difference:
1 CS161 Introduction to Computer Science Topic #9.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
Copyright © Curt Hill Proofs An Introduction.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
Fall 2008Programming Development Techniques 1 Topic 17 Assignment, Local State, and the Environment Model of Evaluation Section 3.1 & 3.2.
Daniel Kroening and Ofer Strichman Decision Procedures An Algorithmic Point of View Deciding Combined Theories.
1 CSC103: Introduction to Computer and Programming Lecture No 16.
Struct s (7.4) Used as data aggregates for an entity can be different types of data e.g. for student id, name, GPA, address,... Similar to classes, but.
Extra Recitations Wednesday 19:40-22:30 FENS L055 (tomorrow!) Friday 13:40-16:30 FENS L063 Friday 17: :30 FENS L045 Friday 19:40-22:30 FENS G032.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Arrays and Loops. Learning Objectives By the end of this lecture, you should be able to: – Understand what a loop is – Appreciate the need for loops and.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
1 Recursion Recursive function: a function that calls itself (directly or indirectly). Recursion is often a good alternative to iteration (loops). Its.
Interface specifications At the core of each Larch interface language is a model of the state manipulated by the associated programming language. Each.
© 2004 Pearson Addison-Wesley. All rights reserved October 5, 2007 Arrays ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
Module 7 Halting Problem –Fundamental program behavior problem –A specific unsolvable problem –Diagonalization technique revisited Proof more complex 1.
User-Written Functions
Great Theoretical Ideas in Computer Science
Intro to PHP & Variables
Introduction to Functional Programming in Racket
Introduction to Functional Programming in Racket
Java Programming Language
This Lecture Substitution model
Presentation transcript:

Some administrative stuff Class mailing list: –send to with the command “subscribe” in the Mini-project is up on the web page: –

Where we’re at Last time we explored the three standard logics, and compared them along three dimensions –expressiveness –automation –human-friendliness Today we’ll look in more detail at FOL –we will explore how to encode computations in FOL in an axiomatic way –we will use Simplify as the running theorem prover for today’s lecture

Encoding functions in FOL Suppose I have a pure function f. How can this function be encoded in FOL? For example: int f(int x) { return x + 1 } In Simplify syntax: (BG_PUSH (FORALL (x) (EQ (f x) (+ x 1))))

Another example Factorial function in C: In Simplify: int fact(int n) { if (n <= 0) return 1; else return n * fact(n-1); } (BG_PUSH (FORALL (n) (EQ (fact n) ???)))

Ideally, would like an IF stmt Factorial function in C: In Simplify: int fact(int n) { if (n <= 0) return 1; else return n * fact(n-1); } (BG_PUSH (FORALL (n) (EQ (fact n) (IF (<= n 0) 1 (* n (fact (- n 1)))))))

No built-in IF in Simplify Simplify has (IMPLIES P 1 P 2 ), which stands for P 1 ) P 2 However, it does not have the IF statement we want How do we encode factorial?

Solution 1: write your own IF Write your own IF function – is this even possible? IF is a function symbol, so it takes terms as arguments. This means that (IF (<= 0 1) A B ) is in fact mal-formed. Can get around this by thinking of predicates as being function symbols that return special terms or –Simplify does this in fact, but only for user defined predicates

Solution 1: write your own IF (BG_PUSH (FORALL (P A B) (IMPLIES (EQ P (EQ (IF P A B) A)))) (BG_PUSH (FORALL (P A B) (IMPLIES (NEQ P (EQ (IF P A B) B)))) (DEFPRED (leq a b) (<= a b)) (BG_PUSH (FORALL (n) (EQ (fact n) (IF (leq n 0) 1 (* n (fact (- n 1)))))))

Solution 1: write your own IF The IF function symbol makes it easy to write functions However, in Simplify it doesn’t work for primitive predicates –although there is not theoretical reason it shoudn’t Also, the extra indirection of using predicates like leq in the previous slide, instead of <=, can confuse Simplify

Solution 2: break the function cases Break the function into cases, and pull the case analysis to the top level (BG_PUSH (FORALL (n) (IMPLIES (<= n 0) (EQ (fact n) 1)))) (BG_PUSH (FORALL (n) (IMPLIES (NOT (<= n 0)) (EQ (fact n) (* n (fact (- n 1)))))))

Solution 2: break the function cases Break the function into cases, and pull the case analysis to the top level Let’s try it out in Simplify! (BG_PUSH (FORALL (n) (IMPLIES (<= n 0) (EQ (fact n) 1)))) (BG_PUSH (FORALL (n) (IMPLIES (NOT (<= n 0)) (EQ (fact n) (* n (fact (- n 1)))))))

Solution 2: break the function cases In general, the cases may overlap –Simple example: can add the following to the previous definition of factorial –A slightly more complicated example: (BG_PUSH (FORALL (a b) (IMPLIES (<= a b) (EQ (min a b) a)))) (BG_PUSH (FORALL (a b) (IMPLIES (>= a b) (EQ (min a b) b)))) (BG_PUSH (EQ (fact 0) 1))))

Overlapping: good or bad? Some functions may be easier to define if we allow overlap Some of the overlap provides redundancies that may actually help the theorem prover –The above axiom is completely redundant, since it doesn’t add anything to the definition of factorial –However, it may help the theorem prover (BG_PUSH (EQ (fact 0) 1))))

Overlapping: good or bad? What happens if the overlapping definitions don’t agree? For example: (BG_PUSH (FORALL (a b) (IMPLIES (<= a b) (EQ (f a b) (+ a b))))) (BG_PUSH (FORALL (a b) (IMPLIES (>= a b) (EQ (f a b) (* a b)))))

Overlapping: good or bad? What happens if the overlapping definitions don’t agree? For example: Can prove false! –which means can prove anything –let’s try it out (BG_PUSH (FORALL (a b) (IMPLIES (<= a b) (EQ (f a b) (+ a b))))) (BG_PUSH (FORALL (a b) (IMPLIES (>= a b) (EQ (f a b) (* a b)))))

Inconsistencies in axioms In Simplify, there are no safeguards against user-defined inconsistencies –What can we do about this? Other theorem provers, for example ACL2, have safeguards –In ACL2, functions are defined in LISP. Thus, there are no ill-defined functions, such as f in the previous slide –Theorems are proved about LISP code –The LISP code is therefore a model for the formulas you are proving

Data structures Our functions so far have only operated on integers Function symbols can be used to encode more complicated data structures –function symbols for constructors –function symbols for accessors (fields)

Example: pairs Suppose we want to encode pairs: We will have: –a function symbol “pair” to construct a pair –a function symbol “first” to extract the first element –a function symbol “second” to extract the second element Axioms: (BG_PUSH (FORALL (a b) (EQ (first (pair a b)) a))) (BG_PUSH (FORALL (a b) (EQ (second (pair a b)) b)))

Example: pairs Note that the above two axioms can be seen as definitions of “first” and “second” The following more explicit version of the axioms makes this clear: (BG_PUSH (FORALL (X a b) (IMPLIES (EQ X (pair a b)) (EQ (first X) a)) (BG_PUSH (FORALL (X a b) (IMPLIES (EQ X (pair a b)) (EQ (second X) b))

Example: pairs Do we need an axiom defining “pair”? (BG_PUSH (FORALL (a b...) (EQ (pair a b)...)))

Example: pairs Do we need an axiom defining “pair”? No, the “pair” constructor really only has meaning with respect to the “first” and “second” selectors So the two axioms for first and second completely specify the behavior of pairs (BG_PUSH (FORALL (a b...) (EQ (pair a b)...)))

A simple AST example Suppose we want to represent a calls in C –For now, let’s assume only one parameter –x = f(y) We’ll use the two constructors, Assgn and FunCall: –the term (Assgn LHS RHS) represents LHS = RHS –the term (FunCall f y) represents f(y) So the assignment would be: –(Assgn x (FunCall f y))

Some subtleties In (Assgn x (FunCall f y)), what are x,f, and y? Are they variables? Constants? –recall: a constant is a nullary function symbol If x, f, and y are variables, then they store the strings that represent the statements we are encoding –for example, if x = “result”, f = “fact” and y = “myvar”, then (Assgn x (FunCall f y)) represents the C statement result = fact(myvar) If x, f, and y are constants, then they actually are the strings in the statement –in this case, if we were to follow Simplify syntax, we should write then as (x), (f) and (y) Little difference between a constant and a global variable

A simple AST example Suppose now that we wanted to have function calls with 0 or more parameters –How would we do this?

A simple AST example Suppose now that we wanted to have function calls with 0 or more parameters –How would we do this? We need a data structure that can store many elements –could do this with a linked list –could also do it with an array Let’s do it with arrays, since Simplify has support for them

Maps in Simplify Simplify has built-in support for maps (arrays): –(select map idx) returns the value at index idx in map think: map[idx] –(store map idx value) returns the input map, but with idx updated to the given value think: map’ = copy map; map’[idx] = value; return map’ –(mapFill value) returns a map that has all indices set to value Simplify has background axioms defining these function symbols

Simplify axioms about maps (FORALL (map idx value) (EQ (select (store map idx value) idx) value)) (FORALL (idx1 idx2 map value) (IMPLIES (NEQ idx1 idx2) (EQ (select (store map idx1 value) idx2) (select map idx2)))) (FORALL (value idx) (EQ (select (mapFill value) idx) value)

Back to function calls in C The second parameter to FunCall is now a map, rather than a string –(FunCall f map) x := f(a,b) (Assgn x (FunCall f (store (store (mapFill uninit) 0 a) 1 b)))

Encoding predicates In the simple case: As before, we can split the definition over multiple possibly overlapping cases (DEFPRED (Pred A B C)) (BG_PUSH (FORALL (A B C) (IFF (Pred A B C) body)))

Special case When there is only one case, as in the previous slide, Simplify allows the body of the predicate to be given with the declaration: Logically equivalent, but… –the above declaration causes (Pred A B C) to immediately be rewritten to its body –whereas the declaration on the previous slide gets expanded using quantifier instantiation heuristics (DEFPRED (Pred A B C ) definition))

Typing

Incomplete functions or predicates Some functions may not be defined on all of their inputs. Such functions are said to be partial Easy to model in an axiomatic setting such as Simplify –incomplete axioms ) incomplete functions –for example, here is fact, only defined on naturals: (BG_PUSH (EQ (fact 0) 1)) (BG_PUSH (FORALL (n) (IMPLIES (> n 1) (EQ (fact n) (* n (fact (- n 1)))))))

Two examples of how theorem provers are used overview today, more details on Tuesday

ESC/Java: Key to making it work Give up on total correctness Require user annotations Give up on completeness (may report bugs that don’t exists) Give up on soundness (may miss some bugs it was supposed to find) Most of the unsoundness arises from loops

Rhodium: Key to making it work Use a domain specific language to restrict the programs you have to reason about Separate “profitability heuristics” from “correctness” Split the proof into two parts: –the first part is optimization independent, and is done by hand once and for all –the other part is optimization dependent, and this is what the theorem prover discharges