Principles of programming languages 3: Answers for exercises Isao Sasano Department of Information Science and Engineering.

Slides:



Advertisements
Similar presentations
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Advertisements

Reasoning About Code; Hoare Logic, continued
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Limits and Continuity Definition Evaluation of Limits Continuity
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
Notes on Logic Continued
Axiomatic Semantics Dr. M Al-Mulhem ICS
Describing Syntax and Semantics
Determine whether each curve below is the graph of a function of x. Select all answers that are graphs of functions of x:
x + 5 = 20 x+5 20 (-5) x + 5 = 20 x 20 (-5) x + 5 = 20.
Slide Copyright © 2012 Pearson Education, Inc.
and Logarithmic Equations
Reading and Writing Mathematical Proofs
Principles of programming languages 2: Answers for exercises
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
Derivatives of Exponential Functions Lesson 4.4. An Interesting Function Consider the function y = a x Let a = 2 Graph the function and it's derivative.
Homework questions? 2-5: Implicit Differentiation ©2002 Roy L. Gover ( Objectives: Define implicit and explicit functions Learn.
Secret Signal … on your chest “1” if true “2” if false 2 3 = (2)(2)(2)
Principle of Programming Lanugages 2: Imperative languages Isao Sasano Department of Information Science and Engineering ( structured programming, control.
Piecewise Defined Functions Lesson 2.3. How to Write a Weird Function What if we had to write a single function to describe this graph … We must learn.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
Activity 2.1 Spending and Earning Money. In your groups read page 181 and complete questions 1, 2 and 3 Definition –A sum function is when you add two.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Logical Reasoning:Proof Prove the theorem using the basic axioms of algebra.
A DPLL example C1:(a  b) C2:(  a   b) C3:(a   c) C4:(c  d  e) C5:(d   e) C6:(  d   f) C7:(f  e) C8:(  f   e) false true a a a=false by.
Increasing and Decreasing Functions Lesson 5.1. The Ups and Downs Think of a function as a roller coaster going from left to right Uphill Slope > 0 Increasing.
Warm Up Week 6 1) State the postulate that shows the statement to be false: A line contains at least three points.
Principles of programming languages 6: Types Isao Sasano Department of Information Science and Engineering.
Boolean Algebra M. AL- Towaileb1. Boolean Functions In Boolean algebra we work with the set {0,1}, where: 0 ≡ F (False) & 1 ≡ T (True). The 3 Operations.
Ch 9: Quadratic Equations F) Graphing Quadratic Inequalities Objective: To graph quadratic inequalities.
Principles of programming languages 12: Logic programming Supplemental material Definition of prefix and suffix Isao Sasano Department of Information Science.
Principle of Programming Lanugages 3: Compilation of statements Statements in C Assertion Hoare logic Department of Information Science and Engineering.
Types and Programming Languages
Function Notation Assignment. 1.Given f(x) = 6x+2, what is f(3)? Write down the following problem and use your calculator in order to answer the question.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Thinking Mathematically Logic 3.4 Truth Tables for the Conditional and Biconditional.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
11.3 Solving Radical Equations Definitions & Rules Simplifying Radicals Practice Problems.
Warm-up #12 ab 1 3x  1814x  x > 32-5x < x  -3 7x > x < x  -24.
SECTION 5-1 The Derivative of the Natural Logarithm.
Limits and Continuity Definition Evaluation of Limits Continuity Limits Involving Infinity.
Principles of programming languages 12: Functional programming
Principle of Programming Lanugages 2: Imperative languages
Principles of programming languages 8: Types
Piecewise-Defined Functions
Rule Exercises Status of the Ball Definitions and Rule 15
Rule Exercises Status of the Ball Definitions and Rule 15
Formal Methods in Software Engineering 1
Factors, multiple, primes: Factors from prime factors
Computers & Programming Languages
Which of the following graphs is the graph of the derivative of the function {image} . 1. {applet}
Reasoning About Code; Hoare Logic
Entry Task Consider the function f(x):
Derivatives of Exponential Functions
Agenda Warm-up Lesson 2 hw corrections Lesson 3 hw questions? Lesson 4
Piecewise Defined Functions
Lesson Objective: I will be able to …
Trig Identities Lesson 3.1.
Axiomatic Verification I
Relational Operators.
Exponents and Order of Operations
Logarithms – Changing the Base
Program correctness Axiomatic semantics
Flowcharts Some Rules.
Straight line graphs: Horizontal and vertical lines
Factors, multiple, primes: Multiples
Straight line graphs: Horizontal and vertical lines
Standard form: In standard form?
Coordinates: Naming 2D coordinates – quadrant 1
Presentation transcript:

Principles of programming languages 3: Answers for exercises Isao Sasano Department of Information Science and Engineering

Exercise (1) Illustrate the control flow graph of the following program fragment in C. if (y==1 || y==2) if (x > 0) x = x - 1; (2) Illustrate the control flow graph of the following program fragment in C. while (x > 0) { if (x%2==0 || x%3==0) s = s + x; x = x – 1; }

(1) An answer Entry y==1 Exit F T x = x-1 y==2 T F x>0 T F

(2) An answer Entry x%2== 0 Exit F T s = s+x x%3==0 T F x>0 T F x=x-1

Exercises Derive (prove) the following Hoare triples. (1){ a = 0 } a := a + 2 { a = 2 } (2){ a = 3 } if a = 3 then a := a + 1 else a := a – 1 { a = 4 } (3){ a = 1 } while (a < 5) do a := a + 1 { a = 5 }

(1) An answer { a + 2 = 2 } a := a + 2 { a = 2 } (assign) (conseq) { a = 0 } a := a + 2 { a = 2 } a=0  a+2=2 We abbreviate (assignment axiom) as (assign) and (consequence rule) as (conseq).

(2) An answer (if) { a = 3 } if a = 3 then a := a + 1 else a := a – 1 { a = 4 } { a = 3  a = 3} a := a + 1 { a = 4 }{ a = 3   a = 3} a := a - 1 { a = 4 } See the next page. See the next next page. We abbreviate (conditional rule) as (if).

(2) Cont. (assignment) { a = 3  a = 3} a := a + 1 { a = 4 } (a = 3  a = 3)  a+1 = 4 {a+1 = 4} a := a + 1 {a = 4} a=4  a=4 (consequence)

(2) Cont. (assignment) (a = 3   a = 3)  a-1 = 4 {a-1=4} a := a - 1 {a=4} a=4  a=4 (consequence) { a = 3   a = 3} a := a - 1 { a = 4 } (Note) The logical expression (a = 3   a = 3)  a-1 = 4 is true because a = 3   a = 3 is false for the cases where a=true or a=false. By the definition of , the whole expression is true since the left side of  is false.

(3) An answer { a = 1 } while (a < 5) do a := a + 1 { a = 5 } a=1  a  5 {a  5} while (a<5) do a := a + 1 {a  5   a<5} (a  5   a<5)  a=5 (consequence) (while) {a  5  a<5} a := a + 1 {a  5} (a  5  a<5)  a+1  5 {a+1  5} a := a+1 {a  5} a  5  a  5 (consequence) (assignment)