Prime programs Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 8.3.3.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
Reductions Complexity ©D.Moshkovitz.
PZ03D Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03D - Program verification Programming Language Design.
Chapter 2: Understanding Structure
PZ08A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ08A - Prime programs Programming Language Design and.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
Section 2.3 Gauss-Jordan Method for General Systems of Equations
PZ12A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ12A - Guarded commands Programming Language Design.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
PZ07B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ07B - Basic statements Programming Language Design.
CS 454 Theory of Computation Sonoma State University, Fall 2011 Instructor: B. (Ravi) Ravikumar Office: 116 I Darwin Hall Original slides by Vahid and.
Axiomatic Semantics Dr. M Al-Mulhem ICS
PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03CX - Language semantics Programming Language Design.
Chapter 2 Section 2 Solving a System of Linear Equations II.
1 Regular Grammars Generate Regular Languages. 2 Theorem Regular grammars generate exactly the class of regular languages: If is a regular grammar then.
Chapter 8 . Sequence Control
October 8, 2009Theory of Computation Lecture 10: A Universal Program II 1 Pairing Functions and Gödel Numbers This way the equation  x, y  = z defines.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
PZ02B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02B - Regular grammars Programming Language Design.
CS 454 Theory of Computation Sonoma State University, Fall 2011 Instructor: B. (Ravi) Ravikumar Office: 116 I Darwin Hall Original slides by Vahid and.
Chapter 1 Program Design
6 6.3 © 2012 Pearson Education, Inc. Orthogonality and Least Squares ORTHOGONAL PROJECTIONS.
Unit Testing CS 414 – Software Engineering I Don Bagert Rose-Hulman Institute of Technology January 16, 2003.
8.2 Solving Systems of Linear Equations by Substitution.
1 1.1 © 2012 Pearson Education, Inc. Linear Equations in Linear Algebra SYSTEMS OF LINEAR EQUATIONS.
Linear Equations in Linear Algebra
Simple Program Design Third Edition A Step-by-Step Approach
CMPS 3223 Theory of Computation Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided.
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
PZ02B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02B - Regular grammars Programming Language Design.
Table of Contents Solving Linear Systems of Equations - Dependent Systems The goal in solving a linear system of equations is to find the values of the.
AN ORTHOGONAL PROJECTION
DISTRIBUTED SYSTEMS II A POLYNOMIAL LOCAL SOLUTION TO MUTUAL EXCLUSION Prof Philippas Tsigas Distributed Computing and Systems Research Group.
PZ07A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ07A - Expressions Programming Language Design and Implementation.
Semantics In Text: Chapter 3.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
Chapter 4 Section 2. Objectives 1 Copyright © 2012, 2008, 2004 Pearson Education, Inc. Solving Systems of Linear Equations by Substitution Solve linear.
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03CX - Language semantics Programming Language Design.
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
1 Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Solving Systems of Linear Equations by Substitution
Computability and Complexity
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
3.3 Applications of Maximum Flow and Minimum Cut
Complexity 6-1 The Class P Complexity Andrei Bulatov.
Alternating tree Automata and Parity games
Understanding the Three Basic Structures
PZ08A - Prime programs Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section PZ08A.
Semantics In Text: Chapter 3.
CS21 Decidability and Tractability
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Language semantics Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Reductions Complexity ©D.Moshkovitz.
Reductions Complexity ©D.Moshkovitz.
Prime programs Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Copyright © 2008 Pearson Education, Inc
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Prime programs Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Prime programs Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
PZ07B - Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
PZ02B - Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section PZ02B.
CH 4 - Language semantics
Presentation transcript:

Prime programs Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 8.3.3

Prime programs 2 Understanding control structures Earlier discussion on control structures seemed somewhat ad hoc. Is there a theory to describe control structures? Do we have the right control structures? Roy Maddux in 1975 developed the concept of a prime program as a mechanism for answering these questions.

Prime programs 3 Spaghetti code

Prime programs 4 Control structures represented as flowcharts

Prime programs 5

6 Theory of prime programs Consider 3 classes of flowchart nodes: Any flowchart is a graph of directed arcs and these 3 types of nodes:

Prime programs 7 Proper programs A proper program is a flowchart with:  1 entry arc  1 exit arc  There is a path from entry arc to any node to exit arc A prime program is a proper program which has no embedded proper subprogram of greater than 1 node. (i.e., cannot cut 2 arcs to extract a prime subprogram within it). A composite program is a proper program that is not prime.

Prime programs 8 Prime flowcharts

Prime programs 9 Prime decomposition Every proper program can be decomposed into a hierarchical set of prime subprograms. This decomposition is unique (except for special case of linear sequences of function nodes).

Prime programs 10 All prime programs can be enumerated All primes can be enumerated (next slide) Each implements a function. What is function for 2-node primes (c) and (d) and 4-node primes (l) through (q)? All primes with at least 1 function node are our usual control structures - except (k) - the do-while-do construct. More about this later.

Prime programs 11

Prime programs 12 Number of primes is infinite Construction to create primes with any number of nodes: Use of prime programs to define structured programming: Concept first used by Dijkstra in 1968 as gotoless programming. Called structured programming in early 1970s- Program only with if, while and sequence control structures.

Prime programs 13 Structured programming Issue in 1970s: Does this limit what programs can be written?  Resolved by Structure Theorem of Böhm-Jacobini. Here is a graph version of theorem originally developed by Harlan Mills:

Prime programs 14 Structure theorem Outline of proof: 1. Label each arc with 1 being the entry arc and 0 the exit arc. 2. Let I be a new variable not used in program. 3. For each node in program construct the following:

Prime programs 15 Structure theorem (continued) 4. Create the following new flowchart on right. If F is the original function, what is the new function?

Prime programs 16 Program verification - again For every flowchart, we can compute a function for each arc in its prime decomposition. f1: S1  S3; f2: S2  S4; f3: S5  Sf A program is then C(f1, f2, f3): S0  Sf Program verification is a formal method to define these functions: Axiomatic - Hoare, 1969 Weakest precondition - Dijkstra, 1972 Algebraic data types - Guttag, 1975 Functional correctness - Mills, 1975

Prime programs 17 Prime programs - Summary Structure theorem does not say: Given any “spaghetti program” convert it into a structured program. What it does say is that there is no loss of functionality in using only those control structures. It is still up to the programmer to choose the best algorithm to solve problem. Also, the prime decomposition shows that the primes up to 4 nodes are the useful programming language control structures, except for the do-while-do, which has been ignored by language designers.