Advanced Formal Methods Lecture 5: Isabelle – Proofs and Rewriting Mads Dam KTH/CSC Course 2D1453, 2006-07 Some slides from Paulson.

Slides:



Advertisements
Similar presentations
Artificial Intelligence 8. The Resolution Method
Advertisements

Types and Programming Languages Lecture 13 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Type Inference David Walker COS 320. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
SLD-resolution Introduction Most general unifiers SLD-resolution
10 October 2006 Foundations of Logic and Constraint Programming 1 Unification ­An overview Need for Unification Ranked alfabeths and terms. Substitutions.
Computing Fundamentals 2 Introduction to CafeOBJ Lecturer: Patrick Browne Lecture Room: K408 Lab Room: A308 Based on work by: Nakamura Masaki, João Pascoal.
AR for Horn clause logic Introducing: Unification.
Standard Logical Equivalences
For Friday No reading Homework: –Chapter 9, exercise 4 (This is VERY short – do it while you’re running your tests) Make sure you keep variables and constants.
This Week Finish relational semantics Hoare logic Interlude on one-point rule Building formulas from programs.
F22H1 Logic and Proof Week 7 Clausal Form and Resolution.
Algebra Problems… Solutions Algebra Problems… Solutions © 2007 Herbert I. Gross Set 22 By Herbert I. Gross and Richard A. Medeiros next.
CPSC 121: Models of Computation
Advanced Formal Methods Lecture 6: Isabelle - HOL Mads Dam KTH/CSC Course 2D1453, Material from L. Paulson.
Advanced Formal Methods Lecture 2: Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from G. Klein, NICTA.
Introduction to Computability Theory
Proving Facts About Programs With a Proof Assistant John Wallerius An Example From: Isabelle/HOL, A Proof Assistant for Higher Order Logic, By T. Nipkow,
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Programming Language Semantics Denotational Semantics Chapter 5 Based on a lecture by Martin Abadi.
0 PROGRAMMING IN HASKELL Chapter 7 - Higher-Order Functions.
Inference and Resolution for Problem Solving
Advanced Formal Methods Lecture 7: Isabelle – Sets Mads Dam KTH/CSC Course 2D1453, Material from L. Paulson.
Restricted Satisfiability (SAT) Problem
Type Inference David Walker COS 441. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Type Inference David Walker CS 510, Fall Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs.
Type Inference II David Walker COS 441. Type Inference Goal: Given unannotated program, find its type or report it does not type check Overview: generate.
Programming Language Semantics Denotational Semantics Chapter 5 Part III Based on a lecture by Martin Abadi.
Introduction to Logic for Artificial Intelligence Lecture 2 Erik Sandewall 2010.
Chapter 3 Section 5 Copyright © 2011 Pearson Education, Inc.
Reading and Writing Mathematical Proofs
CAS- 734 (Presentation -1) By : Vasudha Kapil
Chapter 4.1 Solving Systems of Linear Equations in two variables.
CSE S. Tanimoto Horn Clauses and Unification 1 Horn Clauses and Unification Propositional Logic Clauses Resolution Predicate Logic Horn Clauses.
Lee CSCE 314 TAMU 1 CSCE 314 Programming Languages Haskell: Types and Classes Dr. Hyunyoung Lee.
Solving Equations. The equations are equivalent If they have the same solution(s)
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
CSE Winter 2008 Introduction to Program Verification January 31 proofs through simplification.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Extra slides for Chapter 3: Propositional Calculus & Normal Forms Based on Prof. Lila Kari’s slides For CS2209A, 2009 By Dr. Charles Ling;
Closure Properties Lemma: Let A 1 and A 2 be two CF languages, then the union A 1  A 2 is context free as well. Proof: Assume that the two grammars are.
CSE (c) S. Tanimoto, 2008 Predicate Calculus II 1 Predicate Calculus 2 Outline: Unification: definitions, algorithm Formal interpretations and satisfiability.
Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from.
Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Dublin City University.
Lecture Coursework 2 AGAIN. Rectangle Game Look at proof of matchsticks A rectangular board is divided into m columns by n rows. The area of the board.
1 Knowledge Based Systems (CM0377) Lecture 6 (last modified 20th February 2002)
Advanced Formal Methods Lecture 4: Isabelle – Types and Terms Mads Dam KTH/CSC Course 2D1453, Some material from Paulson.
0 PROGRAMMING IN HASKELL Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources) Odds and Ends,
1 Lecture 5 PVS commands. 2 Last week Logical formalisms, first-order logic (syntax, semantics). Introduction to PVS. Language of PVS. Proving sequents.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
1 Proving Properties of Recursive Functions and Data Structures CS 270 Math Foundations of CS Jeremy Johnson.
Introduction to Logic for Artificial Intelligence Lecture 2
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
Horn Clauses and Unification
Proving Properties of Recursive Functions and Data Structures
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
Prolog syntax + Unification
PROGRAMMING IN HASKELL
Horn Clauses and Unification
Simplification of Boolean Expressions
Horn Clauses and Unification
Types and Classes in Haskell
Horn Clauses and Unification
CSE 341 Section 2 Nick Mooney Spring 2017
CSE 3302 Programming Languages
Horn Clauses and Unification
PROGRAMMING IN HASKELL
Presentation transcript:

Advanced Formal Methods Lecture 5: Isabelle – Proofs and Rewriting Mads Dam KTH/CSC Course 2D1453, Some slides from Paulson

Isabelle’s Metalogic Basic constructs: t = s Equations on terms A 1 ) A 2 Implication Example: x = y ) append x xs = append y xs If A 1 is valid then so is A 2 Æx. A Universal quantification A[t/x] is valid for all t (of appropriate type) These are meta-connectives, not object-logic connectives

Isabelle Proof Goals Proof goals, or judgments: The basic shape of proof goal handled by Isabelle Local proof state, subgoal General shape: Æx 1,...,x m. « A 1 ;... ; A n ¬ ) A x 1,...,x m : Local variables A 1,...,A n : Local assumptions A: local proof goal Meaning: For all terms t 1,...,t m, if all A i [t 1 /x 1,...,t m /x m ] are provable then so is A[t 1 /x 1,...,t m /x m ]

Global Proof State An Isabelle proof state consists of number of unproven judgments 1. Æx 1,1,...,x m,1. « A 1,1 ;... ; A n,1 ¬ ) A k. Æx 1,k,...,x m,k. « A 1,k ;... ; A n,k ¬ ) A k If k = 0 proof is complete Judgment #1 is the one currently being worked on Commands to list subgoals, toggle between subgoals, to apply rules to numbered subgoals, etc.

Goal-Driven Proof - Intuition Proof goal: *Æx 1,...,x m. « A 1 ;... ; A n ¬ ) A Find some ”given fact” B, under assumptions B 1,...,B k such that A ”is” B Replace subgoal * by subgoals Æx 1,...,x m. « A 1 ;... ; A n ¬ ) B_1... Æx 1,...,x m. « A 1 ;... ; A n ¬ ) B_k But, ”is” is really ”is an instance of” so story must be refined

Unification Substitution: Mapping  from variables to terms [t/x]: Substitution mapping x to t, otherwise the identity t  : Capture-avoiding substitution  applied to t Unification: Try to make terms t and s equal Unifier: Substitution  on terms s, t such that s  = t  Unification problem: Given t, s, is there a unifier on s, t

Higher-Order Unification In Isabelle: Terms are terms in Isabelle = extended ! Terms Equality on terms are modulo , ,  Variables to be unified are schematic Schematic variables can have function type (= higher order) Examples: ?X Æ ?Y =  x Æ x under [x/?X,x/?Y] ?P x =  x Æ x under [ x.x Æ x/?P] P (?f x) =  ?Y x under [ x.x/?f,P/Y]

First Order Unification Decidable Most general unifiers (mgu’s) exist:  is mgu for t and s if  unifies t and s Whenever  ’ unifies t and s then t , t  ’, and s , s  ’ are both unifiable Exercise 1: Show that [h(?Y)/?X,g(h(?Y))/?Z] is mgu for f(?X,g(?X)) and f(h(?Y),?Z). Applications in e.g. logic programming

Higher Order Unification HO unification modulo ,  is semi-decidable HO unification modulo , ,  is undecidable Higher order pattern: Term t in  normal form (value in slides for lecture 3) Schematic variables only in head position ?f t 1... t n Each t i  -convertible to n distinct bound variables Unification on HO patterns is decidable

Exercises Exercise 2: Determine whether each pair of terms is unifiable or not. If it is, exhibit a unifier. If it is not, show why. 1.f(x 1, ?x 2, ?x 2 ) and f(?y 1, ?y 2, k) 2.f(x 1, ?x 2, ?x 2 ) and f(y 1, g ?x 2, k) 3.f (?p x y (h z)) and ?q (g(x,y),h(?r)) 4.?p (g x 1 ) (h x 2 ) and ?q (g y 2 ) (h y 1 ) 5.?p (g ?q, h z) and f(h ?r, h ?r)

Term Rewriting Use equations t = s as rewrite rules from left to right Example: Use equations: n = n 2.(suc m) + n = suc(m + n) 3.(suc m · suc n) = (m · n) 4.(0 · m) = true Then: 0 + suc 0 · (suc 0) + x (by (1)) =suc 0 · (suc 0) + x (by (2)) = suc 0 · suc (0 + x) (by (3)) =0 · 0 + x (by (4)) = true

More Formally Rewrite rule l = r is applicable to term t[s/x] if: There is a substitution  such that l  =  s  unifies l and s Result of rewrite is t[s  /x] Note: t[s/x] = t[s  /x] Example: Equation: 0 + n = n Term: a + (0 + (b + c)) Substitution: [b+c/n] Result: a + (b + c)

Conditional Rewriting Assume conditional rewrite rule RId: A 1 )... ) A n ) l = r Rule RId is applicable to term t[s/x] if: There is a substitution  such that l  =  s  unifies l and s A 1 ,..., A n  are provable Again result of rewrite is t[s  /x]

Basic Simplification Goal: « A 1 ;... ; A m ¬ ) B Apply(simp add: eq 1,..., eq n ) Simplify B using Lemmas with attribute simp Rules from primrec and datatype declarations Additional lemmas eq 1,...,eq n Assumptions A 1,..., A m Variation: (simp... del:...) removes lemmas from simplification set add, del are optional

Termination Isabelle uses simp-rules (almost) blindly from left to right Termination is the big issue Example: f(x) = g(x), g(x) = f(x) Rewrite rule « A 1 ;... ; A n ¬ ) l = r suitable for inclusion in simplification set only if rewrite from l to r reduces overall complexity of the global proof state So: l must be ”bigger” than r and each A i n < m = true ) (n < suc m) = true (may be good) (suc n < m) = true ) n < m = true (not good)

Case Splitting P(if A then s else t) = (A ! P(s)) Æ (:A ! P(t)) Included in simp by default P(case t of 0 ) s 1 | Suc n ) s 2 ) = (t = 0 ! P(s 1 )) Æ (8 n. t = Suc n ! P(s 2 )) Not included – use (simp split: nat.split) Similar for other datatypes T: T.split

Ordered Rewriting Problem: ?x + ?y = ?y + ?x does not terminate Isabelle: Use permutative rewrite rules only when term becomes lexicographically smaller Example: ?b + ?a à ?a + ?b but not ?a + ?b à ?b + ?a For types nat, int, etc. Lemmas add ac sort any sum Lemmas times ac sort any product Example: (simp add:add ac) yields (b + c) + a à a + (b + c)

Preprocessing Simplification rules are preprocessed recursively: : A  A = False A ! B  A ) B A Æ B ) A, B 8 x. A(x)  A(?x) A  A = True Example: (p ! q Æ : r) Æ s  p = True ) q = True, p = True ) r = False, s = True