Constructors - Cont. must be distinguished by the number or type of their arguments.

Size: px
Start display at page:

Download "Constructors - Cont. must be distinguished by the number or type of their arguments."

Transcription

1 Constructors - Cont. 1 Constructors can be overloaded! must be distinguished by the number or type of their arguments. 2 When no constructor is defined, there is a default constructor with no arguments. You cannot use the default constructor once one has been defined in your program. (bad style!) 3 When declaring a type, it is also possible to define default values for each field: c l a s s P o i n t { double l a t i t u d e = ; double l o n g i t u d e = 0. 0 ; double a l t i t u d e = 0. 0 ; } J.Carette (McMaster) CS/SE 2S03 1 / 22

2 The Semantics of Records To cover records: we need to add a fifth argument to the functions Σ and Θ: the list of constructed types, each type being associated to an ordered pair composed: T (list of fields, list of constructors) J.Carette (McMaster) CS/SE 2S03 2 / 22

3 Define the Σ function for the four operations: type definition, cell allocation, accessing to a field, assigning to a field. Sharing 4.2 Sharing Sharing Suppose that x and y are two variables of type Point, associated with two references r1 and r2 in the environment. In addition, suppose that, in memory, r1 is associated with a reference r3, which itself is associated with a record {latitude = , longitude = 2.208, altitude = 156.0} and r2 with a reference r4, which itself is associated with the record {latitude = 90.0, longitude = 0.0, altitude = 0.0}. So, e = [x = r1, y = r2 ], m = [r1 = r3, r2 = r4, r3 = {latitude = , longitude = 2.208, altitude = 156.0}, r4 = {latitude = 90.0, longitude = 0.0, altitude = 0.0}]. In the first case (sharing), all changes of the cell associated with x automatically change the cell associated with y, and vice versa. 4.2 Sharing Sharing 67 x x x! x x! ! ! y ! y y! y y! ! ! ! x = y (Sharing!) y,lat = x.lat y.long = x.long y.alt = x.alt ! ! ! 0.0 In contrast, if the statements y.latitude = x.latitude; y.longitude = x.longitude; y.altitude = x.altitude; are executed, the resultant mem ! 0.0! =90.0 {latitude 0.0 = , longitude = ory state is [r1 = r3, r2 = r4, r3 90.0! 2.208, altitude = 156.0}, r4 = {latitude = , longitude = 2.208, altitude = 156.0}]. In contrast, if the statements y.latitude = x.latitude; y.longitude = x x! x.longitude; y.altitude = x.altitude; are executed, the resultant memory state is [r1 = r3, r2 = r4, r3 = {latitude = , longitude = 2.208, altitude = 156.0}, r4 = {latitude = , longitude = 2.208, altitude = 156.0}] ! ! 2.208! When the statement y = x; is executed, the value of x is computed, which is the reference r3 and we associate this value with the reference r2. The memory state becomes [r1 = r3, r2 = r3, r3 = {latitude = , longitude = 2.208, altitude = 156.0}, r4 = {latitude = 90.0, longitude = 0.0, altitude = 0.0}]. x y y! ! ! ! If you then assign to the field latitude of the record x: x.latitude = y 23.45; and then output the field latitude of y, you get in the first case, and in the second. We say, in the first case, that the variables x and y share the cell r3. All changes of the cell associated with x automatically change the cell associated with y, and vice versa. J.Carette (McMaster) CS/SE 2S / 22

4 Equality a = new P o i n t ( 1, 2, 3 ) ; b = new P o i n t ( 1, 2, 3 ) ; Two types of equality: Physical. Two records of the same type are physically equivalent (a==b) only when they are identical (share the same cell). Hence, a == b is false. Structural. Two records of the same type are structural equivalent when their field s value are equal. Hence, a and b are structural equivalent. J.Carette (McMaster) CS/SE 2S03 4 / 22

5 Wrapper Types (from Base type to Object type) A wrapper is a type of record with one lone field. c l a s s I n t e g e r { i n t c ; I n t e g e r ( i n t x ) { t h i s. c = x ; } } The Points (allows several variables to share a single value.): 1 Uniformity 2 Sharing J.Carette (McMaster) CS/SE 2S03 5 / 22

6 Wrapper Types - Cont. x! x y! y 5! 5 4! 4 Integer x = new Integer(4); int x = 4; Integer y = new Integer(x.c); int y = x; x.c = 5; x = 5; System.out.println(y.c); System.out.println(y); print 4 print 4 If we replace the second line with Integer y = x then it prints 5 x! 5! y! y J.Carette (McMaster) CS/SE 2S03 6 / 22

7 Wrapper Types - Cont. The following function swaps values of x and y. s t a t i c void swap ( I n t e g e r x, I n t e g e r y ) { i n t temp = x. c ; x. c = y. c ; y. c = temp ; } In java, it is not possible to do so with arguments of type int. The following functions do nothing on x and y. s t a t i c void swp ( i n t x, i n t y ) { i n t temp = x ; x = y ; y = temp ; } J.Carette (McMaster) CS/SE 2S03 7 / 22

8 Wrapper Types - Cont. When we call the function swap(a, b), we create the state: a! a bb! 44! 77! x! x y! and so swapping the contents of x and y will also swap those of a and b. sif a, b are constant (final), and x, y too, then: a a! x! x b! b y! y 44! 7! 7 and swap works too. J.Carette (McMaster) CS/SE 2S03 8 / 22

9 Records in Caml 1 Record Type: t y p e p o i n t = { l a t i t u d e : double ; l o n g i t u d e : double ; a l t i t u d e : double ; } 2 Creating: l e t x = { l a t = ; l o n g i = 0. 0 ; a l t i t u d e = 0. 0 ; } or l e t y = r e f { l a t = ; l o n g i = 0. 0 ; a l t i t u d e = 0. 0 ; } 3 Accessing: x. l a t i t u d e (! y ). l a t i t u d e 4 Assigning: all fields are constant by default! t y p e i n t wrap = { mutable c : i n t } l e t x = { c = r e f 5} x. c < 4 J.Carette (McMaster) CS/SE 2S03 9 / 22

10 Records in C 1 Record Type: s t r u c t P o i n t { double l a t i t u d e ; double l o n g i t u d e ; double a l t i t u d e ; } ; 2 Creating: s t r u c t P o i n t x ; or s t r u c t P o i n t x = { 5. 0, 7. 0, } ; 3 Accessing: x. l a t i t u d e 4 Assigning: all fields are constant by default! x. l a t i t u d e = Call by copy! (the value of x is not a reference associated with a record in memory as it is in Java and Caml!) J.Carette (McMaster) CS/SE 2S03 10 / 22

11 Arrays Array Types: In Java, an array with elements of type T is of type T[ ]. int [ ] t; This adds t, a new reference r to the environment. The default value is null. In java, the box r can only contain null or another reference. Allocation of an Array: To allocate, you create a box large enough: new int [10]; This creates a new reference r pointing to an n-tuple (10-tuple in this case) of default values (0 in this case). The fields are numbered from 0 to n-1. i.e., int [ ] t = new int [10]; env: [t = r] mem: [r = r, r = [0,, 0]]: }{{} 10 J.Carette (McMaster) CS/SE 2S03 11 / 22

12 Arrays - Cont. Accessing: t[k] gives the k th field. Creation: i n t [ ] t1 ; t1 = new i n t [ ] { 1 0, 1 1, 1 2, 1 3, 1 4, 1 5, 1 6, 1 7 } ; i n t [ ] t2 = new i n t [ ] { 2 0, 2 1, 2 2, 2 3, 2 4, 2 5, 2 6, 2 7 } ; char [ ] ca = { J, a, v, a } ; t1[5] 15, t2[5] 25, ca[0] J Assigning: ca [ 0 ] = j ; (Arrays in C and Caml are essentially the same) J.Carette (McMaster) CS/SE 2S03 12 / 22

13 Arrays of Arrays (T [ ])[ ] is an array of arrays. i n t [ ] [ ] t = new i n t [ 2 0 ] [ 1 5 ] ; t[ i }{{} 0 19 ][ j ] }{{} 0 14 J.Carette (McMaster) CS/SE 2S03 13 / 22

14 Arrays of Objects P o i n t [ ] pa = new P o i n t [ 4 ] ; pa# x null# 0.0 null# 0.0 null# 0.0 Usual looping construct: f o r ( i n t i =0; i <pa. l e n g t h ; i ++) {... ( r e f e r to pa [ i ] ) } Better! f o r ( P o i n t p : pa ) {... ( r e f e r to p ) } J.Carette (McMaster) CS/SE 2S03 14 / 22

15 Dynamic Data Types - Recursive Records Example: c l a s s L i s t { i n t hd ; L i s t t l ; } Note: int List is only non-empty lists but List {empty list} (int List) Observe: List is a record and its value is a reference, a reference can be null. So, List {null} (int List) J.Carette (McMaster) CS/SE 2S03 15 / 22

16 Recursive Records - Example L i s t l ; l = new L i s t ( ) ; l. hd = 4 ; l. t l = new L i s t ( ) ; l. t l. hd = 5 ; l. t l. t l = n u l l ; J.Carette (McMaster) CS/SE 2S03 16 / 22

17 Recursive Records - Example - Cont. ll! l! l! 0! 0 44! (1)! (2)! (3)! l! 44! 0! 0 ll! (4)! 44! 05! (5)! J.Carette (McMaster) CS/SE 2S03 17 / 22

18 Recursive Records - Constructor L i s t ( f i n a l i n t x, f i n a l L i s t y ) { t h i s. hd = x ; t h i s. t l = y ; } L i s t l = new L i s t ( 4, new L i s t ( 5, n u l l ) ) ; J.Carette (McMaster) CS/SE 2S03 18 / 22

19 Recursive Definitions and Fixed Point Equations List {null} int List is not a definition but an equation to be solved! How? To construct a solution we proceed by successive approximations: Let i be the number step of approximation and L i the solution at the step i. L 0 = L 1 = {null} (int L 0 ) = {null} L 2 = {null} (int L 1 ) = {null} (int {null}) L 3 = {null} (int L 2 ) = {null} (int {null}) (int (int {null})). List := lim i L i J.Carette (McMaster) CS/SE 2S03 19 / 22

20 Infinite Values The type List contains values that cannot be constructed in a finite number of steps. For example: L i s t l = new L i s t ( ) ; l. hd = 4 ; l. t l = l ; Creates the following list: ll! 44! The following program terminates properly if you apply it to finite lists, but enters an infinite loop if you try to apply it to infinite lists. s t a t i c i n t sum ( f i n a l L i s t l ) { i f ( l == n u l l ) r e t u r n 0 ; r e t u r n l. hd + sum ( l. t l ) ; } J.Carette (McMaster) CS/SE 2S03 20 / 22

21 Type Algebra 0: empty 1: unit +: disjoint some : product X : variable, some types +: disjoint some µx.f (x): least-fixed point, solve x F (x) Bool := false true = A A A A.1 1.A A A + B B + A A.B B.A A.(B + C) A.B + A.C A + (B + C) (A + B) + C J.Carette (McMaster) CS/SE 2S03 21 / 22

22 Type Calculus δ x A δ x 1 = 0 δ x (A + B) = δ x A + δ x B δ x (A. B) = δ x A. δ x B δ x A = type of one context of A. δ x L = L. L. δ x ( 1 1 x ) = ( 1 1 x )2 Solve δ x Y (X ) = Y (X )? Y (X ) = Bag(X ) J.Carette (McMaster) CS/SE 2S03 22 / 22

Lists, Stacks, and Queues (plus Priority Queues)

Lists, Stacks, and Queues (plus Priority Queues) Lists, Stacks, and Queues (plus Priority Queues) The structures lists, stacks, and queues are composed of similar elements with different operations. Likewise, with mathematics: (Z, +, 0) vs. (Z,, 1) List

More information

ITI Introduction to Computing II

ITI Introduction to Computing II (with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 9, 2019 Please don t print these lecture notes unless you really need to!

More information

ITI Introduction to Computing II

ITI Introduction to Computing II (with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 11, 2015 Please don t print these lecture notes unless you really need to!

More information

Python. chrysn

Python. chrysn Python chrysn 2008-09-25 Introduction Structure, Language & Syntax Strengths & Weaknesses Introduction Structure, Language & Syntax Strengths & Weaknesses Python Python is an interpreted,

More information

Clojure Concurrency Constructs, Part Two. CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014

Clojure Concurrency Constructs, Part Two. CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014 Clojure Concurrency Constructs, Part Two CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014 1 Goals Cover the material presented in Chapter 4, of our concurrency textbook In particular,

More information

Programming Language Concepts, CS2104 Lecture 3

Programming Language Concepts, CS2104 Lecture 3 Programming Language Concepts, CS2104 Lecture 3 Statements, Kernel Language, Abstract Machine 31 Aug 2007 CS2104, Lecture 3 1 Reminder of last lecture Programming language definition: syntax, semantics

More information

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach EDA045F: Program Analysis LECTURE 10: TYPES 1 Christoph Reichenbach In the last lecture... Performance Counters Challenges in Dynamic Performance Analysis Taint Analysis Binary Instrumentation 2 / 44 Types

More information

More About Methods. Hsuan-Tien Lin. Deptartment of CSIE, NTU. OOP Class, March 8-9, 2010

More About Methods. Hsuan-Tien Lin. Deptartment of CSIE, NTU. OOP Class, March 8-9, 2010 More About Methods Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 8-9, 2010 H.-T. Lin (NTU CSIE) More About Methods OOP 03/08-09/2010 0 / 24 Methods: the Basic Method (1/2, Callee s View) 1 p

More information

Set Theory. CSE 215, Foundations of Computer Science Stony Brook University

Set Theory. CSE 215, Foundations of Computer Science Stony Brook University Set Theory CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook.edu/~cse215 Set theory Abstract set theory is one of the foundations of mathematical thought Most mathematical

More information

Functional Programming with F# Overview and Basic Concepts

Functional Programming with F# Overview and Basic Concepts Functional Programming with F# Overview and Basic Concepts Radu Nicolescu Department of Computer Science University of Auckland 27 Sep 2017 1 / 52 1 Background 2 Overview 3 Type System and Type Inference

More information

Any Wizard of Oz fans? Discrete Math Basics. Outline. Sets. Set Operations. Sets. Dorothy: How does one get to the Emerald City?

Any Wizard of Oz fans? Discrete Math Basics. Outline. Sets. Set Operations. Sets. Dorothy: How does one get to the Emerald City? Any Wizard of Oz fans? Discrete Math Basics Dorothy: How does one get to the Emerald City? Glynda: It is always best to start at the beginning Outline Sets Relations Proofs Sets A set is a collection of

More information

Basic Java OOP 10/12/2015. Department of Computer Science & Information Engineering. National Taiwan University

Basic Java OOP 10/12/2015. Department of Computer Science & Information Engineering. National Taiwan University Basic Java OOP 10/12/2015 Hsuan-Tien Lin ( 林軒田 ) htlin@csie.ntu.edu.tw Department of Computer Science & Information Engineering National Taiwan University ( 國立台灣大學資訊工程系 ) Hsuan-Tien Lin (NTU CSIE) Basic

More information

CHAPTER 6. Copyright Cengage Learning. All rights reserved.

CHAPTER 6. Copyright Cengage Learning. All rights reserved. CHAPTER 6 SET THEORY Copyright Cengage Learning. All rights reserved. SECTION 6.4 Boolean Algebras, Russell s Paradox, and the Halting Problem Copyright Cengage Learning. All rights reserved. Boolean Algebras,

More information

CITS2211 Discrete Structures (2017) Cardinality and Countability

CITS2211 Discrete Structures (2017) Cardinality and Countability CITS2211 Discrete Structures (2017) Cardinality and Countability Highlights What is cardinality? Is it the same as size? Types of cardinality and infinite sets Reading Sections 45 and 81 84 of Mathematics

More information

Introduction to Programming (Java) 3/12

Introduction to Programming (Java) 3/12 Introduction to Programming (Java) 3/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction

More information

Introduction to Python

Introduction to Python Introduction to Python Luis Pedro Coelho luis@luispedro.org @luispedrocoelho European Molecular Biology Laboratory Lisbon Machine Learning School 2015 Luis Pedro Coelho (@luispedrocoelho) Introduction

More information

Turing s thesis: (1930) Any computation carried out by mechanical means can be performed by a Turing Machine

Turing s thesis: (1930) Any computation carried out by mechanical means can be performed by a Turing Machine Turing s thesis: (1930) Any computation carried out by mechanical means can be performed by a Turing Machine There is no known model of computation more powerful than Turing Machines Definition of Algorithm:

More information

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

Introduction to Computing II (ITI 1121) FINAL EXAMINATION Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Identification

More information

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications NICTA Advanced Course Theorem Proving Principles, Techniques, Applications λ 1 CONTENT Intro & motivation, getting started with Isabelle Foundations & Principles Lambda Calculus Higher Order Logic, natural

More information

Big-O Notation and Complexity Analysis

Big-O Notation and Complexity Analysis Big-O Notation and Complexity Analysis Jonathan Backer backer@cs.ubc.ca Department of Computer Science University of British Columbia May 28, 2007 Problems Reading: CLRS: Growth of Functions 3 GT: Algorithm

More information

MiniMat: Matrix Language in OCaml LLVM

MiniMat: Matrix Language in OCaml LLVM Terence Lim - tl2735@columbia.edu August 17, 2016 Contents 1 Introduction 4 1.1 Goals........................................ 4 1.1.1 Flexible matrix notation......................... 4 1.1.2 Uncluttered................................

More information

Static Program Analysis

Static Program Analysis Static Program Analysis Xiangyu Zhang The slides are compiled from Alex Aiken s Michael D. Ernst s Sorin Lerner s A Scary Outline Type-based analysis Data-flow analysis Abstract interpretation Theorem

More information

Computer Science Introductory Course MSc - Introduction to Java

Computer Science Introductory Course MSc - Introduction to Java Computer Science Introductory Course MSc - Introduction to Java Lecture 1: Diving into java Pablo Oliveira ENST Outline 1 Introduction 2 Primitive types 3 Operators 4 5 Control Flow

More information

How many hours would you estimate that you spent on this assignment?

How many hours would you estimate that you spent on this assignment? The first page of your homework submission must be a cover sheet answering the following questions. Do not leave it until the last minute; it s fine to fill out the cover sheet before you have completely

More information

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal Präsenzstunden Today In the same room as in the first week Assignment 5 Felix Friedrich, Lars Widmer, Fabian Stutz TA lecture, Informatics II D-BAUG March 18, 2014 HIL E 15.2 15:00-18:00 Timon Gehr (arriving

More information

Discrete Mathematical Structures: Theory and Applications

Discrete Mathematical Structures: Theory and Applications Chapter 1: Foundations: Sets, Logic, and Algorithms Discrete Mathematical Structures: Theory and Applications Learning Objectives Learn about sets Explore various operations on sets Become familiar with

More information

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) October,

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever.   ETH Zürich (D-ITET) October, Automata & languages A primer on the Theory of Computation Laurent Vanbever www.vanbever.eu ETH Zürich (D-ITET) October, 19 2017 Part 5 out of 5 Last week was all about Context-Free Languages Context-Free

More information

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University COMP SCI / SFWR ENG 2S03 Department of Computing and Software McMaster University Week 10: November 7 - November 11 Outline 1 Resource 2 Introduction Nodes Illustration 3 Usage Accessing and Modifying

More information

CS156: The Calculus of Computation

CS156: The Calculus of Computation Page 1 of 61 CS156: The Calculus of Computation Zohar Manna Winter 2010 Chapter 5: Program Correctness: Mechanics Page 2 of 61 Program A: LinearSearch with function specification @pre 0 l u < a @post rv

More information

Binary Search Trees. Motivation

Binary Search Trees. Motivation Binary Search Trees Motivation Searching for a particular record in an unordered list takes O(n), too slow for large lists (databases) If the list is ordered, can use an array implementation and use binary

More information

CSE 505, Fall 2005, Midterm Examination 8 November Please do not turn the page until everyone is ready.

CSE 505, Fall 2005, Midterm Examination 8 November Please do not turn the page until everyone is ready. CSE 505, Fall 2005, Midterm Examination 8 November 2005 Please do not turn the page until everyone is ready. Rules: The exam is closed-book, closed-note, except for one side of one 8.5x11in piece of paper.

More information

COMP9020 Lecture 3 Session 2, 2014 Sets, Functions, and Sequences. Revision: 1.3

COMP9020 Lecture 3 Session 2, 2014 Sets, Functions, and Sequences. Revision: 1.3 1 COMP9020 Lecture 3 Session 2, 2014 Sets, Functions, and Sequences Revision: 1.3 2 Notation for Numbers Definition Integers Z = {... 2, 1, 0, 1, 2,...} Reals R. : R Z floor of x, the greatest integer

More information

Decision Problems with TM s. Lecture 31: Halting Problem. Universe of discourse. Semi-decidable. Look at following sets: CSCI 81 Spring, 2012

Decision Problems with TM s. Lecture 31: Halting Problem. Universe of discourse. Semi-decidable. Look at following sets: CSCI 81 Spring, 2012 Decision Problems with TM s Look at following sets: Lecture 31: Halting Problem CSCI 81 Spring, 2012 Kim Bruce A TM = { M,w M is a TM and w L(M)} H TM = { M,w M is a TM which halts on input w} TOTAL TM

More information

Physics 2B. Lecture 24B. Gauss 10 Deutsche Mark

Physics 2B. Lecture 24B. Gauss 10 Deutsche Mark Physics 2B Lecture 24B Gauss 10 Deutsche Mark Electric Flux Flux is the amount of something that flows through a given area. Electric flux, Φ E, measures the amount of electric field lines that passes

More information

Solutions. Problem 1: Suppose a polynomial in n of degree d has the form

Solutions. Problem 1: Suppose a polynomial in n of degree d has the form Assignment 1 1. Problem 3-1 on p. 57 2. Problem 3-2 on p. 58 3. Problem 4-5 on p. 86 4. Problem 6-1 on p. 142 5. Problem 7-4 on p. 162 6. Prove correctness (including halting) of SelectionSort (use loop

More information

1 Introduction. 2 Recap The Typed λ-calculus λ. 3 Simple Data Structures

1 Introduction. 2 Recap The Typed λ-calculus λ. 3 Simple Data Structures CS 6110 S18 Lecture 21 Products, Sums, and Other Datatypes 1 Introduction In this lecture, we add constructs to the typed λ-calculus that allow working with more complicated data structures, such as pairs,

More information

The Midterm Exam. Hsuan-Tien Lin. Department of CSIE, NTU. OOP Class, April 26-27, 2010

The Midterm Exam. Hsuan-Tien Lin. Department of CSIE, NTU. OOP Class, April 26-27, 2010 The Midterm Exam Hsuan-Tien Lin Department of CSIE, NTU OOP Class, April 26-27, 2010 H.-T. Lin (NTU CSIE) The Midterm Exam OOP 04/26-27/2010 0 / 20 Java Night Countdown I 1 (2%) What is the fully-qualified

More information

Mathematical Background

Mathematical Background Chapter 1 Mathematical Background When we analyze various algorithms in terms of the time and the space it takes them to run, we often need to work with math. That is why we ask you to take MA 2250 Math

More information

An analogy from Calculus: limits

An analogy from Calculus: limits COMP 250 Fall 2018 35 - big O Nov. 30, 2018 We have seen several algorithms in the course, and we have loosely characterized their runtimes in terms of the size n of the input. We say that the algorithm

More information

Functions If (x, y 1 ), (x, y 2 ) S, then y 1 = y 2

Functions If (x, y 1 ), (x, y 2 ) S, then y 1 = y 2 Functions 4-3-2008 Definition. A function f from a set X to a set Y is a subset S of the product X Y such that if (, y 1 ), (, y 2 ) S, then y 1 = y 2. Instead of writing (, y) S, you usually write f()

More information

Conservation of Information

Conservation of Information Conservation of Information Amr Sabry (in collaboration with Roshan P. James) School of Informatics and Computing Indiana University May 8, 2012 Amr Sabry (in collaboration with Roshan P. James) (IU SOIC)

More information

Introduction to functions

Introduction to functions Introduction to functions Comp Sci 1570 Introduction to C++ Outline 1 2 Functions A function is a reusable sequence of s designed to do a particular job. In C++, a function is a group of s that is given

More information

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers ALGEBRA CHRISTIAN REMLING 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers by Z = {..., 2, 1, 0, 1,...}. Given a, b Z, we write a b if b = ac for some

More information

Simply Typed Lambda Calculus

Simply Typed Lambda Calculus Simply Typed Lambda Calculus Language (ver1) Lambda calculus with boolean values t ::= x variable x : T.t abstraction tt application true false boolean values if ttt conditional expression Values v ::=

More information

DM507 - Algoritmer og Datastrukturer Project 1

DM507 - Algoritmer og Datastrukturer Project 1 DM507 - Algoritmer og Datastrukturer Project 1 Christian Skjøth Mat-Øk 280588 Morten Olsen Mat-Øk 090789 19. marts 2012 Task 1 - Double for-loop So, first we needed to create an instance of the class File

More information

CS 4110 Programming Languages & Logics. Lecture 16 Programming in the λ-calculus

CS 4110 Programming Languages & Logics. Lecture 16 Programming in the λ-calculus CS 4110 Programming Languages & Logics Lecture 16 Programming in the λ-calculus 30 September 2016 Review: Church Booleans 2 We can encode TRUE, FALSE, and IF, as: TRUE λx. λy. x FALSE λx. λy. y IF λb.

More information

BOOLEAN ALGEBRA INTRODUCTION SUBSETS

BOOLEAN ALGEBRA INTRODUCTION SUBSETS BOOLEAN ALGEBRA M. Ragheb 1/294/2018 INTRODUCTION Modern algebra is centered around the concept of an algebraic system: A, consisting of a set of elements: ai, i=1, 2,, which are combined by a set of operations

More information

6.001 Recitation 22: Streams

6.001 Recitation 22: Streams 6.001 Recitation 22: Streams RI: Gerald Dalley, dalleyg@mit.edu, 4 May 2007 http://people.csail.mit.edu/dalleyg/6.001/sp2007/ The three chief virtues of a programmer are: Laziness, Impatience and Hubris

More information

CSE 505, Fall 2009, Midterm Examination 5 November Please do not turn the page until everyone is ready.

CSE 505, Fall 2009, Midterm Examination 5 November Please do not turn the page until everyone is ready. CSE 505, Fall 2009, Midterm Examination 5 November 2009 Please do not turn the page until everyone is ready Rules: The exam is closed-book, closed-note, except for one side of one 85x11in piece of paper

More information

Modular Bisimulation Theory for Computations and Values

Modular Bisimulation Theory for Computations and Values Modular Bisimulation Theory for Computations and Values Swansea University, UK FoSSaCS, Rome March 2013 Part of the project: PLanCompS http://www.plancomps.org EPSRC-funded, 2011-2015 {Swansea, Royal Holloway,

More information

Blocking Synchronization: Streams Vijay Saraswat (Dec 10, 2012)

Blocking Synchronization: Streams Vijay Saraswat (Dec 10, 2012) 1 Streams Blocking Synchronization: Streams Vijay Saraswat (Dec 10, 2012) Streams provide a very simple abstraction for determinate parallel computation. The intuition for streams is already present in

More information

Reasoning About Imperative Programs. COS 441 Slides 10b

Reasoning About Imperative Programs. COS 441 Slides 10b Reasoning About Imperative Programs COS 441 Slides 10b Last time Hoare Logic: { P } C { Q } Agenda If P is true in the initial state s. And C in state s evaluates to s. Then Q must be true in s. Program

More information

7 RC Simulates RA. Lemma: For every RA expression E(A 1... A k ) there exists a DRC formula F with F V (F ) = {A 1,..., A k } and

7 RC Simulates RA. Lemma: For every RA expression E(A 1... A k ) there exists a DRC formula F with F V (F ) = {A 1,..., A k } and 7 RC Simulates RA. We now show that DRC (and hence TRC) is at least as expressive as RA. That is, given an RA expression E that mentions at most C, there is an equivalent DRC expression E that mentions

More information

Programming Languages Fall 2013

Programming Languages Fall 2013 Programming Languages Fall 2013 Lecture 11: Subtyping Prof Liang Huang huang@qccscunyedu Big Picture Part I: Fundamentals Functional Programming and Basic Haskell Proof by Induction and Structural Induction

More information

C++ For Science and Engineering Lecture 17

C++ For Science and Engineering Lecture 17 C++ For Science and Engineering Lecture 17 John Chrispell Tulane University Monday October 4, 2010 Functions and C-Style Strings Three methods for representing the C-style string: An array of char A quoted

More information

n CS 160 or CS122 n Sets and Functions n Propositions and Predicates n Inference Rules n Proof Techniques n Program Verification n CS 161

n CS 160 or CS122 n Sets and Functions n Propositions and Predicates n Inference Rules n Proof Techniques n Program Verification n CS 161 Discrete Math at CSU (Rosen book) Sets and Functions (Rosen, Sections 2.1,2.2, 2.3) TOPICS Discrete math Set Definition Set Operations Tuples 1 n CS 160 or CS122 n Sets and Functions n Propositions and

More information

CS 6110 Lecture 28 Subtype Polymorphism 3 April 2013 Lecturer: Andrew Myers

CS 6110 Lecture 28 Subtype Polymorphism 3 April 2013 Lecturer: Andrew Myers CS 6110 Lecture 28 Subtype Polymorphism 3 April 2013 Lecturer: Andrew Myers 1 Introduction In this lecture, we make an attempt to extend the typed λ-calculus for it to support more advanced data structures

More information

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Catie Baker Spring 2015

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Catie Baker Spring 2015 CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Catie Baker Spring 2015 Today Registration should be done. Homework 1 due 11:59pm next Wednesday, April 8 th. Review math

More information

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine) CS537 Theory of Computation Lecture : Computability Theory I (Turing Machine) Objectives Introduce the Turing Machine (TM) Proposed by Alan Turing in 936 finite-state control + infinitely long tape A stronger

More information

Fundamentals of Software Engineering

Fundamentals of Software Engineering Fundamentals of Software Engineering First-Order Logic Ina Schaefer Institute for Software Systems Engineering TU Braunschweig, Germany Slides by Wolfgang Ahrendt, Richard Bubel, Reiner Hähnle (Chalmers

More information

Automated Reasoning Lecture 5: First-Order Logic

Automated Reasoning Lecture 5: First-Order Logic Automated Reasoning Lecture 5: First-Order Logic Jacques Fleuriot jdf@inf.ac.uk Recap Over the last three lectures, we have looked at: Propositional logic, semantics and proof systems Doing propositional

More information

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine) CS537 Theory of Computation Lecture : Computability Theory I (Turing Machine) Objectives Introduce the Turing Machine (TM)? Proposed by Alan Turing in 936 finite-state control + infinitely long tape A

More information

Logic, Sets, and Proofs

Logic, Sets, and Proofs Logic, Sets, and Proofs David A. Cox and Catherine C. McGeoch Amherst College 1 Logic Logical Operators. A logical statement is a mathematical statement that can be assigned a value either true or false.

More information

CompA - Complex Analyzer

CompA - Complex Analyzer CompA - Complex Analyzer Xiping Liu(xl2639), Jianshuo Qiu(jq2253), Tianwu Wang(tw2576), Yingshuang Zheng(yz3083), Zhanpeng Su(zs2329) Septembee 25, 2017 1 Introduction The motivation for writing this language

More information

Extending the Lambda Calculus: An Eager Functional Language

Extending the Lambda Calculus: An Eager Functional Language Syntax of the basic constructs: Extending the Lambda Calculus: An Eager Functional Language canonical forms z cfm ::= intcfm boolcfm funcfm tuplecfm altcfm intcfm ::= 0 1-1... boolcfm ::= boolconst funcfm

More information

Relational Algebra and Calculus

Relational Algebra and Calculus Topics Relational Algebra and Calculus Linda Wu Formal query languages Preliminaries Relational algebra Relational calculus Expressive power of algebra and calculus (CMPT 354 2004-2) Chapter 4 CMPT 354

More information

Outline. 1 Introduction. 3 Quicksort. 4 Analysis. 5 References. Idea. 1 Choose an element x and reorder the array as follows:

Outline. 1 Introduction. 3 Quicksort. 4 Analysis. 5 References. Idea. 1 Choose an element x and reorder the array as follows: Outline Computer Science 331 Quicksort Mike Jacobson Department of Computer Science University of Calgary Lecture #28 1 Introduction 2 Randomized 3 Quicksort Deterministic Quicksort Randomized Quicksort

More information

Legendre s Equation. PHYS Southern Illinois University. October 13, 2016

Legendre s Equation. PHYS Southern Illinois University. October 13, 2016 PHYS 500 - Southern Illinois University October 13, 2016 PHYS 500 - Southern Illinois University Legendre s Equation October 13, 2016 1 / 10 The Laplacian in Spherical Coordinates The Laplacian is given

More information

Thomas Jefferson Invitational Open in Informatics

Thomas Jefferson Invitational Open in Informatics Thomas Jefferson Invitational Open in Informatics Sample Problems (With Solutions) Version 2.01.1 By programmers, For programmers Preface Preface Welcome to the TJ IOI Sample Problems document. Here, you

More information

Manual of Time Scales Toolbox for MATLAB

Manual of Time Scales Toolbox for MATLAB Manual of Time Scales Toolbox for MATLAB BAYLOR UNIVERSITY WACO, TX 76798 2005 Baylor University User s Manual: Time Scales Toolbox for MatLab Written By: Brian Ballard Bumni Otegbade This project funded

More information

Program verification. Hoare triples. Assertional semantics (cont) Example: Semantics of assignment. Assertional semantics of a program

Program verification. Hoare triples. Assertional semantics (cont) Example: Semantics of assignment. Assertional semantics of a program Program verification Assertional semantics of a program Meaning of a program: relation between its inputs and outputs; specified by input assertions (pre-conditions) and output assertions (post-conditions)

More information

Q = Set of states, IE661: Scheduling Theory (Fall 2003) Primer to Complexity Theory Satyaki Ghosh Dastidar

Q = Set of states, IE661: Scheduling Theory (Fall 2003) Primer to Complexity Theory Satyaki Ghosh Dastidar IE661: Scheduling Theory (Fall 2003) Primer to Complexity Theory Satyaki Ghosh Dastidar Turing Machine A Turing machine is an abstract representation of a computing device. It consists of a read/write

More information

Sets and Functions. (As we will see, in describing a set the order in which elements are listed is irrelevant).

Sets and Functions. (As we will see, in describing a set the order in which elements are listed is irrelevant). Sets and Functions 1. The language of sets Informally, a set is any collection of objects. The objects may be mathematical objects such as numbers, functions and even sets, or letters or symbols of any

More information

Fundamentals of Software Engineering

Fundamentals of Software Engineering Fundamentals of Software Engineering First-Order Logic Ina Schaefer Institute for Software Systems Engineering TU Braunschweig, Germany Slides by Wolfgang Ahrendt, Richard Bubel, Reiner Hähnle (Chalmers

More information

Internship report Testing judgements of type theory Chalmers Tekniska Högskola, Göteborg

Internship report Testing judgements of type theory Chalmers Tekniska Högskola, Göteborg Internship report Testing judgements of type theory Chalmers Tekniska Högskola, Göteborg Rodolphe Lepigre Université de Savoie, Chambéry rodolphe.lepigre@etu.univ-savoie.fr Under the supervision of Peter

More information

Software Engineering using Formal Methods

Software Engineering using Formal Methods Software Engineering using Formal Methods First-Order Logic Wolfgang Ahrendt 26th September 2013 SEFM: First-Order Logic 130926 1 / 53 Install the KeY-Tool... KeY used in Friday s exercise Requires: Java

More information

COMP6463: λ-calculus

COMP6463: λ-calculus COMP6463: λ-calculus 1. Basics Michael Norrish Michael.Norrish@nicta.com.au Canberra Research Lab., NICTA Semester 2, 2015 Outline Introduction Lambda Calculus Terms Alpha Equivalence Substitution Dynamics

More information

DARN: A Matrix Manipulation Language

DARN: A Matrix Manipulation Language DARN: A Matrix Manipulation Language Daisy Chaussee (dac2183) Anthony Kim (ak3703) Rafael Takasu (rgt2108) Ignacio (Nacho) Torras (it2216) December 20, 2016 1 Contents 1 Introduction to the Language 4

More information

Introduction to lambda calculus Part 6

Introduction to lambda calculus Part 6 Introduction to lambda calculus Part 6 Antti-Juhani Kaijanaho 2017-02-16 1 Untyped lambda calculus 2 Typed lambda calculi 2.1 Dynamically typed lambda calculus with integers 2.2 A model of Lisp 2.3 Simply

More information

Proving Programs Correct

Proving Programs Correct Proving Programs Correct Page 1 of 9 Proving Programs Correct How can we be sure that a piece of code does what we want it to do? One way is to try testing the code on a large group of data. Another is

More information

Recursion. Recursion. Steven Zeil. November 25, 2013

Recursion. Recursion. Steven Zeil. November 25, 2013 Steven Zeil November 25, 2013 Outline 1 2 Example: Compressing a Picture 3 Outline I 1 2 Example: Compressing a Picture 3 A function is recursive if it calls itself or calls some other function that eventually

More information

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata CISC 4090: Theory of Computation Chapter Regular Languages Xiaolan Zhang, adapted from slides by Prof. Werschulz Section.: Finite Automata Fordham University Department of Computer and Information Sciences

More information

Modern Functional Programming and Actors With Scala and Akka

Modern Functional Programming and Actors With Scala and Akka Modern Functional Programming and Actors With Scala and Akka Aaron Kosmatin Computer Science Department San Jose State University San Jose, CA 95192 707-508-9143 akosmatin@gmail.com Abstract For many years,

More information

CSCI 3110 Assignment 6 Solutions

CSCI 3110 Assignment 6 Solutions CSCI 3110 Assignment 6 Solutions December 5, 2012 2.4 (4 pts) Suppose you are choosing between the following three algorithms: 1. Algorithm A solves problems by dividing them into five subproblems of half

More information

CS415 Compilers Syntax Analysis Top-down Parsing

CS415 Compilers Syntax Analysis Top-down Parsing CS415 Compilers Syntax Analysis Top-down Parsing These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Announcements Midterm on Thursday, March 13

More information

CSE 311: Foundations of Computing. Lecture 26: Cardinality

CSE 311: Foundations of Computing. Lecture 26: Cardinality CSE 311: Foundations of Computing Lecture 26: Cardinality Cardinality and Computability Computers as we know them grew out of a desire to avoid bugs in mathematical reasoning A brief history of reasoning

More information

Universal Turing Machine. Lecture 20

Universal Turing Machine. Lecture 20 Universal Turing Machine Lecture 20 1 Turing Machine move the head left or right by one cell read write sequentially accessed infinite memory finite memory (state) next-action look-up table Variants don

More information

CSci 311, Models of Computation Chapter 9 Turing Machines

CSci 311, Models of Computation Chapter 9 Turing Machines CSci 311, Models of Computation Chapter 9 Turing Machines H. Conrad Cunningham 29 December 2015 Contents Introduction................................. 1 9.1 The Standard Turing Machine...................

More information

Solving Systems of Linear Equations Using Matrices

Solving Systems of Linear Equations Using Matrices Solving Systems of Linear Equations Using Matrices What is a Matrix? A matrix is a compact grid or array of numbers. It can be created from a system of equations and used to solve the system of equations.

More information

0.1 Non-enumerable Sets

0.1 Non-enumerable Sets 01 NON-ENUMERABLE SETS 1 01 Non-enumerable Sets Some sets, such as the set N of natural numbers, are infinite So far we ve seen examples of infinite sets which were all enumerable However, there are also

More information

CHAPTER 1. Preliminaries. 1 Set Theory

CHAPTER 1. Preliminaries. 1 Set Theory CHAPTER 1 Preliminaries 1 et Theory We assume that the reader is familiar with basic set theory. In this paragraph, we want to recall the relevant definitions and fix the notation. Our approach to set

More information

CS20a: Turing Machines (Oct 29, 2002)

CS20a: Turing Machines (Oct 29, 2002) CS20a: Turing Machines (Oct 29, 2002) So far: DFA = regular languages PDA = context-free languages Today: Computability 1 Church s thesis The computable functions are the same as the partial recursive

More information

ENS Lyon Camp. Day 5. Basic group. C October

ENS Lyon Camp. Day 5. Basic group. C October ENS Lyon Camp. Day 5. Basic group. C++. 30 October Contents 1 Input/Output 1 1.1 C-style.......................................... 1 1. C++-style........................................ Stack Overflow

More information

Mechanized Operational Semantics

Mechanized Operational Semantics Mechanized Operational Semantics J Strother Moore Department of Computer Sciences University of Texas at Austin Marktoberdorf Summer School 2008 (Lecture 5: Boyer-Moore Fast String Searching) 1 The Problem

More information

SFWR ENG/COMP SCI 2S03 Principles of Programming

SFWR ENG/COMP SCI 2S03 Principles of Programming (Slide 1 of 23) Dr. Ridha Khedri Department of Computing and Software, McMaster University Canada L8S 4L7, Hamilton, Ontario Acknowledgments: Material based on Java actually: A Comprehensive Primer in

More information

Introduction to Computing II (ITI1121) FINAL EXAMINATION

Introduction to Computing II (ITI1121) FINAL EXAMINATION Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Identification

More information

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 3

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 3 CS 70 Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 3 Modular Arithmetic In several settings, such as error-correcting codes and cryptography, we sometimes wish to work over a smaller

More information

INF 4140: Models of Concurrency Series 3

INF 4140: Models of Concurrency Series 3 Universitetet i Oslo Institutt for Informatikk PMA Olaf Owe, Martin Steffen, Toktam Ramezani INF 4140: Models of Concurrency Høst 2016 Series 3 14. 9. 2016 Topic: Semaphores (Exercises with hints for solution)

More information

Chapter 2 Sets, Relations and Functions

Chapter 2 Sets, Relations and Functions Chapter 2 Sets, Relations and Functions Key Topics Sets Set Operations Russell s Paradox Relations Composition of Relations Reflexive, Symmetric and Transitive Relations Functions Partial and Total Functions

More information

Comp 11 Lectures. Mike Shah. July 12, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 12, / 33

Comp 11 Lectures. Mike Shah. July 12, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 12, / 33 Comp 11 Lectures Mike Shah Tufts University July 12, 2017 Mike Shah (Tufts University) Comp 11 Lectures July 12, 2017 1 / 33 Please do not distribute or host these slides without prior permission. Mike

More information