CSE 3341.03 Winter 2008 Introduction to Program Verification February 5 calculating with simplify.

Slides:



Advertisements
Similar presentations
Semantics Static semantics Dynamic semantics attribute grammars
Advertisements

Introducing Formal Methods, Module 1, Version 1.1, Oct., Formal Specification and Analytical Verification L 5.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Chapter 2 Logic Circuits.
Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Inference and Reasoning. Basic Idea Given a set of statements, does a new statement logically follow from this. For example If an animal has wings and.
CSE Winter 2008 Introduction to Program Verification January 24 tautology checking, take 2.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
CS 355 – Programming Languages
CSE Winter 2008 Introduction to Program Verification symbolic execution continued.
PSUCS322 HM 1 Languages and Compiler Design II Formal Semantics Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything removed.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Dec Formal Semantics1 Programming Language Theory Formal Semantics Leif Grönqvist The national Graduate School of Language Technology (GSLT) MSI.
Chapter 2 A Simple Compiler
Describing Syntax and Semantics
Chapter 3 Planning Your Solution
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
The ACL2 Proof Assistant Formal Methods Jeremy Johnson.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Mathematical Modeling and Formal Specification Languages CIS 376 Bruce R. Maxim UM-Dearborn.
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
COP3530 Data Structures600 Stack Stack is one the most useful ADTs. Like list, it is a collection of data items. Supports “LIFO” (Last In First Out) discipline.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Computer Science Department Data Structure & Algorithms Lecture 8 Recursion.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
Chapter Twenty-ThreeModern Programming Languages1 Formal Semantics.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
CS 363 Comparative Programming Languages Semantics.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
Introduction to Data Structures and Algorithms CS 110: Data Structures and Algorithms First Semester,
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 3.
Chapter 3 Part II Describing Syntax and Semantics.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Semantics In Text: Chapter 3.
CSE Winter 2008 Introduction to Program Verification January 31 proofs through simplification.
June 11, 2002© Howard Huang1 Boolean algebra Last time we talked about Boolean functions, Boolean expressions, and truth tables. Today we’ll learn.
Extra slides for Chapter 3: Propositional Calculus & Normal Forms Based on Prof. Lila Kari’s slides For CS2209A, 2009 By Dr. Charles Ling;
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
CSE Winter 2008 Introduction to Program Verification January 15 tautology checking.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
CSCI1600: Embedded and Real Time Software Lecture 28: Verification I Steven Reiss, Fall 2015.
CSE Winter 2008 Introduction to Program Verification January 8 Boolean operators.
CSE Winter 2008 Introduction to Program Verification for-loops; review.
Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data LIFO (Last In First Out) structure.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
INTRODUCTION TO COMPUTER PROGRAMMING(IT-303) Basics.
COMP 412, FALL Type Systems C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
Stacks Access is allowed only at one point of the structure, normally termed the top of the stack access to the most recently added item only Operations.
Introduction to Optimization
Comprehensive Introduction to OOP with Java, C. Thomas Wu Stack ADT
Edited by Original material by Eric Grimson
tautology checking continued
Boolean algebra Last time we talked about Boolean functions, Boolean expressions, and truth tables. Today we’ll learn how to how use Boolean algebra to.
Dr. Clincy Professor of CS
Introduction to Optimization
Dr. Clincy Professor of CS
Dr. Clincy Professor of CS
Background In his classic 1972 paper on definitional interpreters, John Reynolds introduced two key techniques: Continuation-passing style - Makes.
Simplification of Boolean Expressions
Introduction to Optimization
Verifying a compiler for a simple language with exceptions (MPC 04).
This Lecture Substitution model
Algebraic Specification Software Specification Lecture 34
CSE Winter 2008 Introduction to Program Verification February 7
Presentation transcript:

CSE Winter 2008 Introduction to Program Verification February 5 calculating with simplify

review the simplify algorithm simplify(Expr) = Result if path_arg(Path, Expr) = Lhs, % (there is a path in Expr to the sub-expression LHS) and Lhs ->> Rhs, and Modified = change_path_arg(Path, Expr, Rhs), and Result = simplify(Modified) otherwise simplify(Expr) = Expr.

in English -- Result is the result of simplifying Expr if there is a path in Expr to a subterm Lhs, and there is a rule that Lhs ->> Rhs, and Modified is the term Expr with the Lhs subterm replaced by Rhs, otherwise Result is the input Expr simplify is an interpreter for "rewrite programs" (rules)

how do we enter rules? |: theory(file). looks for a file named file.simp |: theory('file.simp'). or |: assert(( rule )). adds the rule at the end of the current list of rules

playing with simplify indigo 301 % simplify Version 1.4.2SWI, January 6, 2007 |:x > 0 implies a+a=a*2. x>0 implies a+a=a*2 ->> 0<x implies a+a=a*2 Can we simplify further? try using a theory? trace ?

review: use simplify to do calculations on abstract datatypes - symbolically we represent everything by expressions (terms) — not objects example: calculate on stacks, using expressions to represent the stack objects evaluation of expressions is symbolic hence general: X-X ->> 0 means that X-X = 0 for all (symbolic) values of X.

conditional rules conditional rules evaluate relations and numerical expressions left ->> right :- condition applies if condition can be shown to simplify to true, X > Y ->> true :- X > Y. condition is true if X, Y are numbers and X is less than Y. conditional rules use a built-in evaluator, assigned, to evaluate functions in numerical expressions type information such as integer(X)can be used in a conditional rule.

conditional example |:assert((M*N ->> Product :- Product assigned M*N)). |: 2*3. 2*3 ->> 6 Check use of assigned in /cs/course/3341/arithmetic.simp.

developing rules to get a proof exercise 4.1 |:(a + b = b + a) implies a > false find a general rule to complete the proof. (replace arithmetic variables (lower-case) with pattern (upper- case) variables)

exercise 4.3, page 12. |: assert((0*X ->> 0)). |: x*y*0. x*y*0 ->> 0 |: x*0*y. x*y*0 ->> 0 reconstruct the rules which achieve the simplifications in Sec. 4.4

4.4 |:2*q+q*((a+8-a)-7) + q. 2*q+q* (8-7)+q 2*q+q*1+q 2*q+q+q 2*q+q*2 q*4 2*q+q* (a+8-a-7)+q ->> q*4

Ch. 5.1: abstract data types now have the tools for verifying some algebraic calculations given the right theory file, we can do symbolic calculation on abstract datatypes ADTs are characterized by interrelated equations "if it quacks like a duck..." Leibnitz law ?

start with stacks push makes a new stack out of a stack argument and a data item pop makes a new smaller stack from a stack argument top extracts a data item from a stack stacks are actually isomorphic to a simple kind of list (CONS X List) = add X to the front of List = push X on the stack List specific stacks (constants) represented by expressions using push example: push(z, push(b, nil)) push is the constructor for this datatype. treat these as functors of terms push(data, stack)

stack computers examples: HP calculators a stack computer will have stack operations or functions defined from push, pop, and top languages: Forth, Factor Java VM -- see exercise 5.3 examples on p. 49

verification scenario: evaluate an ADT expression context: ADT defined by axioms in the form of identities method: input ADT axioms and definitions to the simplify tool in the form of simplification rules; input an expression to be checked and see if it simplifies to the expected result. background: mathematical simplification rules. The correctness of the evaluation is relative to the assumed correctness of the simplification rules and the correctness of the ADT axioms and definitions.

stack calculations stack function definitions are equations, turn them into rewrite rules and use them to do symbolic calculation on stacks definitions of plus, times, etc. describe a stack-based arithmetic calculator

unspecified implementation Example: over(S) = push(top(pop(S)), S) What does over(S) do? does it really work by popping S, and pushing the top element of this new stack onto the original S? implementation is not specified (that's why the datatype is abstract)

what happens if we do an illegal operation? e. g. pop(pop(push(a, nil))) can we use simplify to detect illegal operations?

a very simple verification scenario prove (by symbolic calculation) that a certain sequence of operations on an abstract datatype computes a particular mathematical function. doubling example: |: theory('stack.simp'). |: plus(dup(push(a, nil))). plus(dup(push(a,nil))) ->> push(a+a,nil)

correctness relies on correctness? correctness of our verification scenario for expression evaluation rests on correctness of theory files doesn't this invalidate the whole idea of verification? No, theory (.simp) files are general should be highly re-usable theories become quickly "bug-free" much easier to check than code evolve through use to become more comprehensive

verifying a Java stack machine program what does [Ingram, 1997] refer to? what does the manual tell you about a bytecode? pop=87 Stack:..., VAL ->... pop2=88 Stack:..., VAL1, VAL2 ->... dup=89 Stack:..., V ->..., V, V what would a verification scenario for the JVM look like?

JVM scenario title: verify JVM bytecode sequence method: input bytecode definitions as rewrite rules, input bytecode sequence, perhaps as a list [..,..... ] and initial stack (as an expression) to simplify confirm the simplification yields desired result. background: stack axioms, stack operation definitions, and perhaps theorems; additional rewrite rules for processing a list (see Forth exercise)

queues a new ADT: queues Exercise (a) and (b)