CS 4110 Programming Languages & Logics. Lecture 25 Records and Subtyping

Size: px
Start display at page:

Download "CS 4110 Programming Languages & Logics. Lecture 25 Records and Subtyping"

Transcription

1 CS 4110 Programming Languages & Logics Lecture 25 Records and Subtyping 31 October 2016

2 Announcements 2 Homework 6 returned: x = 34 of 37, σ = 3.8 Preliminary Exam II in class on Wednesday, November 16 New date! Please me as soon as you can if you have a conflict. Topics: λ-calculus through subtyping (today) Not cumulative (unlike the final) Practice problems available on CMS now

3 Records 3 We ve seen binary products (pairs), and they generalize to n-ary products (tuples). Records are a generalization of tuples where we mark each field with a label.

4 Records 3 We ve seen binary products (pairs), and they generalize to n-ary products (tuples). Records are a generalization of tuples where we mark each field with a label. Example: {foo = 32, bar = true} is a record value with an integer field foo and a boolean field bar.

5 Records 3 We ve seen binary products (pairs), and they generalize to n-ary products (tuples). Records are a generalization of tuples where we mark each field with a label. Example: {foo = 32, bar = true} is a record value with an integer field foo and a boolean field bar. Its type is: {foo:int, bar:bool}

6 Syntax 4 l L e ::= {l 1 = e 1,..., l n = e n } e.l v ::= {l 1 = v 1,..., l n = v n } τ ::= {l 1 :τ 1,..., l n :τ n }

7 Dynamic Semantics 5 E ::=... {l 1 = v 1,..., l i 1 = v i 1, l i = E, l i+1 = e i+1,..., l n = e n } E.l {l 1 = v 1,..., l n = v n }.l i v i

8 Static Semantics 6 i 1..n. Γ e i :τ i Γ {l 1 = e 1,..., l n = e n }:{l 1 :τ 1,..., l n :τ n } Γ e:{l 1 :τ 1,..., l n :τ n } Γ e.l i :τ i

9 Example 7 GETX λp:{x : int, y : int}. p.x

10 Example 7 GETX λp:{x : int, y : int}. p.x GETX {x = 4, y = 2}

11 Example 7 GETX λp:{x : int, y : int}. p.x GETX {x = 4, y = 2} GETX {x = 4, y = 2, z = 42}

12 Example 7 GETX λp:{x : int, y : int}. p.x GETX {x = 4, y = 2} GETX {x = 4, y = 2, z = 42} GETX {y = 2, x = 4}

13 Subtyping 8 Definition (Subtype) τ 1 is a subtype of τ 2, written τ 1 τ 2, if a program can use a value of type τ 1 whenever it would use a value of type τ 2. If τ 1 τ 2, we also say τ 2 is the supertype of τ 1.

14 Subtyping 8 Definition (Subtype) τ 1 is a subtype of τ 2, written τ 1 τ 2, if a program can use a value of type τ 1 whenever it would use a value of type τ 2. If τ 1 τ 2, we also say τ 2 is the supertype of τ 1. Γ e:τ τ τ Γ e:τ SUBSUMPTION This typing rule says that if e has type τ and τ is a subtype of τ, then e also has type τ.

15 Record Subtyping 9 We ll define a new subtyping relation that works together with the subsumption rule. τ 1 τ 2

16 Record Subtyping 10 This program isn t well-typed (yet): (λp:{x : int}. p.x) {x = 4, y = 2}

17 Record Subtyping 10 This program isn t well-typed (yet): (λp:{x : int}. p.x) {x = 4, y = 2} So let s add width subtyping: k 0 {l 1 :τ 1,..., l n+k :τ n+k } {l 1 :τ 1,..., l n :τ n }

18 Record Subtyping 11 This program also doesn t get stuck: (λp:{x : int, y : int}. p.x + p.y) {y = 37, x = 5}

19 Record Subtyping 11 This program also doesn t get stuck: (λp:{x : int, y : int}. p.x + p.y) {y = 37, x = 5} So we can make it well-typed by adding permutation subtyping: π is a permutation on 1..n {l 1 :τ 1,..., l n :τ n } {l π(1) :τ π(1),..., l π(n) :τ π(n) }

20 Record Subtyping 12 Does this program get stuck? Is it well-typed? (λp:{x : {y : int}}. p.x.y) {x = {y = 4, z = 2}}

21 Record Subtyping 12 Does this program get stuck? Is it well-typed? (λp:{x : {y : int}}. p.x.y) {x = {y = 4, z = 2}} Let s add depth subtyping: i 1..n. τ i τ i {l 1 :τ 1,..., l n :τ n } {l 1 :τ 1,..., l n :τ n }

22 Record Subtyping 13 Putting all three forms of record subtyping together: i 1..n. j 1..m. l i = l j τ j τ i {l 1 :τ 1,..., l m :τ m } {l 1 :τ 1,..., l n :τ n} S-RECORD

23 Standard Subtyping Rules 14 We always make the subtyping relation both reflexive and transitive. τ τ S-REFL τ 1 τ 2 τ 2 τ 3 τ 1 τ 3 S-TRANS Think of every type describing a set of values. Then τ 1 τ 2 when τ 1 s values are a subset of τ 2 s.

24 Top Type 15 It s sometimes useful to define a maximal type with respect to subtyping: τ ::= τ S-TOP Everything is a subtype of, as in Java s Object or Go s interface{}.

25 Subtype All the Things! 16 We can also write subtyping rules for sums and products: τ 1 τ 1 τ 2 τ 2 τ 1 + τ 2 τ 1 + τ 2 S-SUM

26 Subtype All the Things! 16 We can also write subtyping rules for sums and products: τ 1 τ 1 τ 2 τ 2 τ 1 + τ 2 τ 1 + τ 2 S-SUM τ 1 τ 1 τ 2 τ 2 τ 1 τ 2 τ 1 τ 2 S-PRODUCT

27 Function Types 17 How should we decide whether one function type is a subtype of another???? τ 1 τ 2 τ 1 τ 2 S-FUNCTION

28 Desiderata 18 We d like to have: int {x:int, y:int} int {x:int}

29 Desiderata 18 We d like to have: int {x:int, y:int} int {x:int} And: {x:int} int {x:int, y:int} int

30 Desiderata We d like to have: And: In general, to prove: int {x:int, y:int} int {x:int} {x:int} int {x:int, y:int} int τ 1 τ 2 τ 1 τ 2 we ll require: Argument types are contravariant: τ 1 τ 1 Return types are covariant: τ 2 τ 2 18

31 Function Subtyping 19 Putting these two pieces together, we get the subtyping rule for function types: τ 1 τ 1 τ 2 τ 2 τ 1 τ 2 τ 1 τ 2 S-FUNCTION

32 Reference Subtyping 20 What should the relationship be between τ and τ in order to have τ ref τ ref?

33 Example 21 If r has type τ ref, then!r has type τ. Imagine we replace r with r, where r has a type τ ref that we ve somehow decided is a subtype of τ ref.

34 Example 21 If r has type τ ref, then!r has type τ. Imagine we replace r with r, where r has a type τ ref that we ve somehow decided is a subtype of τ ref. Then!r should still produce something can be treated as a τ. In other words, it should have a type that is a subtype of τ. So the referent type should be covariant: τ τ τ ref τ ref

35 Example 22 If v has type τ, then r := v should be legal. If we replace r with r, then it must still be legal to assign r := v. So!r would then produce a value of type τ.

36 Example 22 If v has type τ, then r := v should be legal. If we replace r with r, then it must still be legal to assign r := v. So!r would then produce a value of type τ. So the referent type should be contravariant! τ τ τ ref τ ref

37 Reference Subtyping 23 In fact, subtyping for reference types must be invariant: a reference type τ ref is a subtype of τ ref if and only if τ τ and τ τ. τ τ τ τ τ ref τ ref S-REF

38 Java Arrays 24 Tragically, Java s mutable arrays use covariant subtyping!

39 Java Arrays 24 Tragically, Java s mutable arrays use covariant subtyping! Suppose that Cow is a subtype of Animal. Code that only reads from arrays typechecks: Animal[ ] arr = new Cow[ ] { new Cow( Alfonso ) }; Animal a = arr[0];

40 Java Arrays 24 Tragically, Java s mutable arrays use covariant subtyping! Suppose that Cow is a subtype of Animal. Code that only reads from arrays typechecks: Animal[ ] arr = new Cow[ ] { new Cow( Alfonso ) }; Animal a = arr[0]; but writing to the array can get into trouble: arr[0] = new Animal( Brunhilda ); Specifically, this generates an ArrayStoreException.

Notes from Yesterday s Discussion. Big Picture. CIS 500 Software Foundations Fall November 1. Some lessons.

Notes from Yesterday s  Discussion. Big Picture. CIS 500 Software Foundations Fall November 1. Some lessons. CIS 500 Software Foundations Fall 2006 Notes from Yesterday s Email Discussion November 1 Some lessons This is generally a crunch-time in the semester Slow down a little and give people a chance to catch

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

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

Programming Languages and Types

Programming Languages and Types Programming Languages and Types Klaus Ostermann based on slides by Benjamin C. Pierce Subtyping Motivation With our usual typing rule for applications the term is not well typed. ` t 1 : T 11!T 12 ` t

More information

CSE 311 Lecture 28: Undecidability of the Halting Problem. Emina Torlak and Kevin Zatloukal

CSE 311 Lecture 28: Undecidability of the Halting Problem. Emina Torlak and Kevin Zatloukal CSE 311 Lecture 28: Undecidability of the Halting Problem Emina Torlak and Kevin Zatloukal 1 Topics Final exam Logistics, format, and topics. Countability and uncomputability A quick recap of Lecture 27.

More information

Today. Binary relations establish a relationship between elements of two sets

Today. Binary relations establish a relationship between elements of two sets Today Relations Binary relations and properties Relationship to functions n-ary relations Definitions Binary relations establish a relationship between elements of two sets Definition: Let A and B be two

More information

CIS 500 Software Foundations Fall October. Review. Administrivia. Subtyping

CIS 500 Software Foundations Fall October. Review. Administrivia. Subtyping CIS 500 Software Foundations Fall 2002 Administrivia Prof. Pierce out of town Nov. 5 14 No office hours Nov 5, 7, 12, or 14 Next Wednesday: guest lecturer (on Chapter 16) Following Monday: review session

More information

Reading 11 : Relations and Functions

Reading 11 : Relations and Functions CS/Math 240: Introduction to Discrete Mathematics Fall 2015 Reading 11 : Relations and Functions Instructor: Beck Hasti and Gautam Prakriya In reading 3, we described a correspondence between predicates

More information

Formal Reasoning CSE 331. Lecture 2 Formal Reasoning. Announcements. Formalization and Reasoning. Software Design and Implementation

Formal Reasoning CSE 331. Lecture 2 Formal Reasoning. Announcements. Formalization and Reasoning. Software Design and Implementation CSE 331 Software Design and Implementation Lecture 2 Formal Reasoning Announcements Homework 0 due Friday at 5 PM Heads up: no late days for this one! Homework 1 due Wednesday at 11 PM Using program logic

More information

Polymorphism, Subtyping, and Type Inference in MLsub

Polymorphism, Subtyping, and Type Inference in MLsub Polymorphism, Subtyping, and Type Inference in MLsub Stephen Dolan and Alan Mycroft November 8, 2016 Computer Laboratory University of Cambridge The select function select p v d = if (p v) then v else

More information

CSCI3390-Lecture 6: An Undecidable Problem

CSCI3390-Lecture 6: An Undecidable Problem CSCI3390-Lecture 6: An Undecidable Problem September 21, 2018 1 Summary The language L T M recognized by the universal Turing machine is not decidable. Thus there is no algorithm that determines, yes or

More information

6c Lecture 14: May 14, 2014

6c Lecture 14: May 14, 2014 6c Lecture 14: May 14, 2014 11 Compactness We begin with a consequence of the completeness theorem. Suppose T is a theory. Recall that T is satisfiable if there is a model M T of T. Recall that T is consistent

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

Equational Logic and Term Rewriting: Lecture I

Equational Logic and Term Rewriting: Lecture I Why so many logics? You all know classical propositional logic. Why would we want anything more? Equational Logic and Term Rewriting: Lecture I One reason is that we might want to change some basic logical

More information

Motivation. CS389L: Automated Logical Reasoning. Lecture 10: Overview of First-Order Theories. Signature and Axioms of First-Order Theory

Motivation. CS389L: Automated Logical Reasoning. Lecture 10: Overview of First-Order Theories. Signature and Axioms of First-Order Theory Motivation CS389L: Automated Logical Reasoning Lecture 10: Overview of First-Order Theories Işıl Dillig Last few lectures: Full first-order logic In FOL, functions/predicates are uninterpreted (i.e., structure

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

Essential facts about NP-completeness:

Essential facts about NP-completeness: CMPSCI611: NP Completeness Lecture 17 Essential facts about NP-completeness: Any NP-complete problem can be solved by a simple, but exponentially slow algorithm. We don t have polynomial-time solutions

More information

Proof by contrapositive, contradiction

Proof by contrapositive, contradiction Proof by contrapositive, contradiction Margaret M. Fleck 9 September 2009 This lecture covers proof by contradiction and proof by contrapositive (section 1.6 of Rosen). 1 Announcements The first quiz will

More information

KB Agents and Propositional Logic

KB Agents and Propositional Logic Plan Knowledge-Based Agents Logics Propositional Logic KB Agents and Propositional Logic Announcements Assignment2 mailed out last week. Questions? Knowledge-Based Agents So far, what we ve done is look

More information

One-to-one functions and onto functions

One-to-one functions and onto functions MA 3362 Lecture 7 - One-to-one and Onto Wednesday, October 22, 2008. Objectives: Formalize definitions of one-to-one and onto One-to-one functions and onto functions At the level of set theory, there are

More information

Math 31 Lesson Plan. Day 16: Review; Start Section 8. Elizabeth Gillaspy. October 18, Supplies needed: homework. Colored chalk. Quizzes!

Math 31 Lesson Plan. Day 16: Review; Start Section 8. Elizabeth Gillaspy. October 18, Supplies needed: homework. Colored chalk. Quizzes! Math 31 Lesson Plan Day 16: Review; Start Section 8 Elizabeth Gillaspy October 18, 2011 Supplies needed: homework Colored chalk Quizzes! Goals for students: Students will: improve their understanding of

More information

CS173 Lecture B, November 3, 2015

CS173 Lecture B, November 3, 2015 CS173 Lecture B, November 3, 2015 Tandy Warnow November 3, 2015 CS 173, Lecture B November 3, 2015 Tandy Warnow Announcements Examlet 7 is a take-home exam, and is due November 10, 11:05 AM, in class.

More information

CSE505, Fall 2012, Final Examination December 10, 2012

CSE505, Fall 2012, Final Examination December 10, 2012 CSE505, Fall 2012, Final Examination December 10, 2012 Rules: The exam is closed-book, closed-notes, except for one side of one 8.5x11in piece of paper. Please stop promptly at 12:20. You can rip apart

More information

Math 300: Final Exam Practice Solutions

Math 300: Final Exam Practice Solutions Math 300: Final Exam Practice Solutions 1 Let A be the set of all real numbers which are zeros of polynomials with integer coefficients: A := {α R there exists p(x) = a n x n + + a 1 x + a 0 with all a

More information

Context-free grammars and languages

Context-free grammars and languages Context-free grammars and languages The next class of languages we will study in the course is the class of context-free languages. They are defined by the notion of a context-free grammar, or a CFG for

More information

CMPSCI 250: Introduction to Computation. Lecture #29: Proving Regular Language Identities David Mix Barrington 6 April 2012

CMPSCI 250: Introduction to Computation. Lecture #29: Proving Regular Language Identities David Mix Barrington 6 April 2012 CMPSCI 250: Introduction to Computation Lecture #29: Proving Regular Language Identities David Mix Barrington 6 April 2012 Proving Regular Language Identities Regular Language Identities The Semiring Axioms

More information

Turing Machines Part Three

Turing Machines Part Three Turing Machines Part Three What problems can we solve with a computer? What kind of computer? Very Important Terminology Let M be a Turing machine. M accepts a string w if it enters an accept state when

More information

MA 1125 Lecture 15 - The Standard Normal Distribution. Friday, October 6, Objectives: Introduce the standard normal distribution and table.

MA 1125 Lecture 15 - The Standard Normal Distribution. Friday, October 6, Objectives: Introduce the standard normal distribution and table. MA 1125 Lecture 15 - The Standard Normal Distribution Friday, October 6, 2017. Objectives: Introduce the standard normal distribution and table. 1. The Standard Normal Distribution We ve been looking at

More information

Quadratic equations: complex solutions

Quadratic equations: complex solutions October 28 (H), November 1 (A), 2016 Complex number system page 1 Quadratic equations: complex solutions An issue that can arise when solving a quadratic equation by the Quadratic Formula is the need to

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

Reasoning Under Uncertainty: Introduction to Probability

Reasoning Under Uncertainty: Introduction to Probability Reasoning Under Uncertainty: Introduction to Probability CPSC 322 Lecture 23 March 12, 2007 Textbook 9 Reasoning Under Uncertainty: Introduction to Probability CPSC 322 Lecture 23, Slide 1 Lecture Overview

More information

Preparing for the CS 173 (A) Fall 2018 Midterm 1

Preparing for the CS 173 (A) Fall 2018 Midterm 1 Preparing for the CS 173 (A) Fall 2018 Midterm 1 1 Basic information Midterm 1 is scheduled from 7:15-8:30 PM. We recommend you arrive early so that you can start exactly at 7:15. Exams will be collected

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

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products Chapter 3 Cartesian Products and Relations The material in this chapter is the first real encounter with abstraction. Relations are very general thing they are a special type of subset. After introducing

More information

More on infinite series Antiderivatives and area

More on infinite series Antiderivatives and area More on infinite series Antiderivatives and area September 28, 2017 The eighth breakfast was on Monday: There are still slots available for the October 4 breakfast (Wednesday, 8AM), and there s a pop-in

More information

First Order Logic: Syntax and Semantics

First Order Logic: Syntax and Semantics CS1081 First Order Logic: Syntax and Semantics COMP30412 Sean Bechhofer sean.bechhofer@manchester.ac.uk Problems Propositional logic isn t very expressive As an example, consider p = Scotland won on Saturday

More information

Discrete Mathematics Fall 2018 Midterm Exam Prof. Callahan. Section: NetID: Multiple Choice Question (30 questions in total, 4 points each)

Discrete Mathematics Fall 2018 Midterm Exam Prof. Callahan. Section: NetID: Multiple Choice Question (30 questions in total, 4 points each) Discrete Mathematics Fall 2018 Midterm Exam Prof. Callahan Section: NetID: Name: Multiple Choice Question (30 questions in total, 4 points each) 1 Consider the following propositions: f: The student got

More information

Automated Program Verification and Testing 15414/15614 Fall 2016 Lecture 7: Procedures for First-Order Theories, Part 1

Automated Program Verification and Testing 15414/15614 Fall 2016 Lecture 7: Procedures for First-Order Theories, Part 1 Automated Program Verification and Testing 15414/15614 Fall 2016 Lecture 7: Procedures for First-Order Theories, Part 1 Matt Fredrikson mfredrik@cs.cmu.edu October 17, 2016 Matt Fredrikson Theory Procedures

More information

Lecture 27: Theory of Computation. Marvin Zhang 08/08/2016

Lecture 27: Theory of Computation. Marvin Zhang 08/08/2016 Lecture 27: Theory of Computation Marvin Zhang 08/08/2016 Announcements Roadmap Introduction Functions Data Mutability Objects This week (Applications), the goals are: To go beyond CS 61A and see examples

More information

Object Oriented Software Design (NTU, Class Even, Spring 2009) Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20

Object Oriented Software Design (NTU, Class Even, Spring 2009) Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20 Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20 This is a closed-book exam. Any form of cheating or lying will not be tolerated. Students can get zero scores and/or fail the class and/or

More information

Boolean circuits. Lecture Definitions

Boolean circuits. Lecture Definitions Lecture 20 Boolean circuits In this lecture we will discuss the Boolean circuit model of computation and its connection to the Turing machine model. Although the Boolean circuit model is fundamentally

More information

Lecture 6: Finite Fields

Lecture 6: Finite Fields CCS Discrete Math I Professor: Padraic Bartlett Lecture 6: Finite Fields Week 6 UCSB 2014 It ain t what they call you, it s what you answer to. W. C. Fields 1 Fields In the next two weeks, we re going

More information

CS1800: Strong Induction. Professor Kevin Gold

CS1800: Strong Induction. Professor Kevin Gold CS1800: Strong Induction Professor Kevin Gold Mini-Primer/Refresher on Unrelated Topic: Limits This is meant to be a problem about reasoning about quantifiers, with a little practice of other skills, too

More information

Propositional and Predicate Logic

Propositional and Predicate Logic Propositional and Predicate Logic CS 536-05: Science of Programming This is for Section 5 Only: See Prof. Ren for Sections 1 4 A. Why Reviewing/overviewing logic is necessary because we ll be using it

More information

Generating Function Notes , Fall 2005, Prof. Peter Shor

Generating Function Notes , Fall 2005, Prof. Peter Shor Counting Change Generating Function Notes 80, Fall 00, Prof Peter Shor In this lecture, I m going to talk about generating functions We ve already seen an example of generating functions Recall when we

More information

Element x is R-minimal in X if y X. R(y, x).

Element x is R-minimal in X if y X. R(y, x). CMSC 22100/32100: Programming Languages Final Exam M. Blume December 11, 2008 1. (Well-founded sets and induction principles) (a) State the mathematical induction principle and justify it informally. 1

More information

NP-Completeness Part II

NP-Completeness Part II NP-Completeness Part II Please evaluate this course on Axess. Your comments really do make a difference. Announcements Problem Set 8 due tomorrow at 12:50PM sharp with one late day. Problem Set 9 out,

More information

Math 31 Lesson Plan. Day 2: Sets; Binary Operations. Elizabeth Gillaspy. September 23, 2011

Math 31 Lesson Plan. Day 2: Sets; Binary Operations. Elizabeth Gillaspy. September 23, 2011 Math 31 Lesson Plan Day 2: Sets; Binary Operations Elizabeth Gillaspy September 23, 2011 Supplies needed: 30 worksheets. Scratch paper? Sign in sheet Goals for myself: Tell them what you re going to tell

More information

CS154, Lecture 15: Cook-Levin Theorem SAT, 3SAT

CS154, Lecture 15: Cook-Levin Theorem SAT, 3SAT CS154, Lecture 15: Cook-Levin Theorem SAT, 3SAT Definition: A language B is NP-complete if: 1. B NP 2. Every A in NP is poly-time reducible to B That is, A P B When this is true, we say B is NP-hard On

More information

Lecture Notes on Programs with Arrays

Lecture Notes on Programs with Arrays 15-414: Bug Catching: Automated Program Verification Lecture Notes on Programs with Arrays Matt Fredrikson Ruben Martins Carnegie Mellon University Lecture 6 1 Introduction The previous lecture focused

More information

Informatics 1 - Computation & Logic: Tutorial 3

Informatics 1 - Computation & Logic: Tutorial 3 Informatics 1 - Computation & Logic: Tutorial 3 Counting Week 5: 16-20 October 2016 Please attempt the entire worksheet in advance of the tutorial, and bring all work with you. Tutorials cannot function

More information

Propositional and Predicate Logic

Propositional and Predicate Logic 8/24: pp. 2, 3, 5, solved Propositional and Predicate Logic CS 536: Science of Programming, Spring 2018 A. Why Reviewing/overviewing logic is necessary because we ll be using it in the course. We ll be

More information

6.825 Techniques in Artificial Intelligence. Logic Miscellanea. Completeness and Incompleteness Equality Paramodulation

6.825 Techniques in Artificial Intelligence. Logic Miscellanea. Completeness and Incompleteness Equality Paramodulation 6.825 Techniques in Artificial Intelligence Logic Miscellanea Completeness and Incompleteness Equality Paramodulation Lecture 9 1 Logic is a huge subject. It includes esoteric mathematical and philosophical

More information

HW8. Due: November 1, 2018

HW8. Due: November 1, 2018 CSCI 1010 Theory of Computation HW8 Due: November 1, 2018 Attach a fully filled-in cover sheet to the front of your printed homework Your name should not appear anywhere; the cover sheet and each individual

More information

Symbolic Logic Outline

Symbolic Logic Outline Symbolic Logic Outline 1. Symbolic Logic Outline 2. What is Logic? 3. How Do We Use Logic? 4. Logical Inferences #1 5. Logical Inferences #2 6. Symbolic Logic #1 7. Symbolic Logic #2 8. What If a Premise

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

Announcements. CS243: Discrete Structures. Propositional Logic II. Review. Operator Precedence. Operator Precedence, cont. Operator Precedence Example

Announcements. CS243: Discrete Structures. Propositional Logic II. Review. Operator Precedence. Operator Precedence, cont. Operator Precedence Example Announcements CS243: Discrete Structures Propositional Logic II Işıl Dillig First homework assignment out today! Due in one week, i.e., before lecture next Tuesday 09/11 Weilin s Tuesday office hours are

More information

Natural Logic Welcome to the Course!

Natural Logic Welcome to the Course! 1/31 Natural Logic Welcome to the Course! Larry Moss Indiana University Nordic Logic School August 7-11, 2017 2/31 This course presents logical systems tuned to natural language The raison d être of logic

More information

CSE 311: Foundations of Computing I. Lecture 1: Propositional Logic

CSE 311: Foundations of Computing I. Lecture 1: Propositional Logic CSE 311: Foundations of Computing I Lecture 1: Propositional Logic About CSE 311 Some Perspective Computer Science and Engineering Programming CSE 14x Theory Hardware CSE 311 About the Course We will study

More information

Lecture 23 : Nondeterministic Finite Automata DRAFT Connection between Regular Expressions and Finite Automata

Lecture 23 : Nondeterministic Finite Automata DRAFT Connection between Regular Expressions and Finite Automata CS/Math 24: Introduction to Discrete Mathematics 4/2/2 Lecture 23 : Nondeterministic Finite Automata Instructor: Dieter van Melkebeek Scribe: Dalibor Zelený DRAFT Last time we designed finite state automata

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Kevin Zatloukal Summer 2017 Lecture 2 Reasoning About Code With Logic (Based on slides by Mike Ernst, Dan Grossman, David Notkin, Hal Perkins, Zach Tatlock) Recall

More information

CS156: The Calculus of Computation

CS156: The Calculus of Computation Page 1 of 31 CS156: The Calculus of Computation Zohar Manna Winter 2010 Chapter 3: First-Order Theories Page 2 of 31 First-Order Theories I First-order theory T consists of Signature Σ T - set of constant,

More information

6.045: Automata, Computability, and Complexity (GITCS) Class 17 Nancy Lynch

6.045: Automata, Computability, and Complexity (GITCS) Class 17 Nancy Lynch 6.045: Automata, Computability, and Complexity (GITCS) Class 17 Nancy Lynch Today Probabilistic Turing Machines and Probabilistic Time Complexity Classes Now add a new capability to standard TMs: random

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

MATH 341, Section 001 FALL 2014 Introduction to the Language and Practice of Mathematics

MATH 341, Section 001 FALL 2014 Introduction to the Language and Practice of Mathematics MATH 341, Section 001 FALL 2014 Introduction to the Language and Practice of Mathematics Class Meetings: MW 9:30-10:45 am in EMS E424A, September 3 to December 10 [Thanksgiving break November 26 30; final

More information

09 Modal Logic II. CS 3234: Logic and Formal Systems. October 14, Martin Henz and Aquinas Hobor

09 Modal Logic II. CS 3234: Logic and Formal Systems. October 14, Martin Henz and Aquinas Hobor Martin Henz and Aquinas Hobor October 14, 2010 Generated on Thursday 14 th October, 2010, 11:40 1 Review of Modal Logic 2 3 4 Motivation Syntax and Semantics Valid Formulas wrt Modalities Correspondence

More information

Finite State Machines CS 64: Computer Organization and Design Logic Lecture #15 Fall 2018

Finite State Machines CS 64: Computer Organization and Design Logic Lecture #15 Fall 2018 Finite State Machines CS 64: Computer Organization and Design Logic Lecture #15 Fall 2018 Ziad Matni, Ph.D. Dept. of Computer Science, UCSB Administrative The Last 2 Weeks of CS 64: Date L # Topic Lab

More information

Syllogistic Logic and its Extensions

Syllogistic Logic and its Extensions 1/31 Syllogistic Logic and its Extensions Larry Moss, Indiana University NASSLLI 2014 2/31 Logic and Language: Traditional Syllogisms All men are mortal. Socrates is a man. Socrates is mortal. Some men

More information

INDUCTIVE DEFINITION

INDUCTIVE DEFINITION 1 INDUCTIVE DEFINITION OUTLINE Judgements Inference Rules Inductive Definition Derivation Rule Induction 2 META-VARIABLES A symbol in a meta-language that is used to describe some element in an object

More information

n Empty Set:, or { }, subset of all sets n Cardinality: V = {a, e, i, o, u}, so V = 5 n Subset: A B, all elements in A are in B

n Empty Set:, or { }, subset of all sets n Cardinality: V = {a, e, i, o, u}, so V = 5 n Subset: A B, all elements in A are in B Discrete Math Review Discrete Math Review (Rosen, Chapter 1.1 1.7, 5.5) TOPICS Sets and Functions Propositional and Predicate Logic Logical Operators and Truth Tables Logical Equivalences and Inference

More information

Predicate Logic: Sematics Part 1

Predicate Logic: Sematics Part 1 Predicate Logic: Sematics Part 1 CS402, Spring 2018 Shin Yoo Predicate Calculus Propositional logic is also called sentential logic, i.e. a logical system that deals with whole sentences connected with

More information

Approximating MAX-E3LIN is NP-Hard

Approximating MAX-E3LIN is NP-Hard Approximating MAX-E3LIN is NP-Hard Evan Chen May 4, 2016 This lecture focuses on the MAX-E3LIN problem. We prove that approximating it is NP-hard by a reduction from LABEL-COVER. 1 Introducing MAX-E3LIN

More information

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska LECTURE 3 CHAPTER 1 SETS, RELATIONS, and LANGUAGES 6. Closures and Algorithms 7. Alphabets and Languages 8. Finite Representation

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms Spring 2017-2018 Outline Announcements 1 Announcements 2 3 Recap Mergesort Of Note Labs start in Week02 in CS305b Do you have linux account? Lab times: Fri. 15.00, 16.00

More information

Nondeterministic finite automata

Nondeterministic finite automata Lecture 3 Nondeterministic finite automata This lecture is focused on the nondeterministic finite automata (NFA) model and its relationship to the DFA model. Nondeterminism is an important concept in the

More information

Languages, regular languages, finite automata

Languages, regular languages, finite automata Notes on Computer Theory Last updated: January, 2018 Languages, regular languages, finite automata Content largely taken from Richards [1] and Sipser [2] 1 Languages An alphabet is a finite set of characters,

More information

Lecture 4.3: Closures and Equivalence Relations

Lecture 4.3: Closures and Equivalence Relations Lecture 4.3: Closures and CS 250, Discrete Structures, Fall 2015 Nitesh Saxena Adopted from previous lectures by Cinda Heeren Course Admin Mid-Term 2 Exam Solution will be posted soon Should have the results

More information

Truth-Functional Logic

Truth-Functional Logic Truth-Functional Logic Syntax Every atomic sentence (A, B, C, ) is a sentence and are sentences With ϕ a sentence, the negation ϕ is a sentence With ϕ and ψ sentences, the conjunction ϕ ψ is a sentence

More information

Introduction to the Theory of Computing

Introduction to the Theory of Computing Introduction to the Theory of Computing Lecture notes for CS 360 John Watrous School of Computer Science and Institute for Quantum Computing University of Waterloo June 27, 2017 This work is licensed under

More information

Lecture 4. Algebra. Section 1:. Signature, algebra in a signature. Isomorphisms, homomorphisms, congruences and quotient algebras.

Lecture 4. Algebra. Section 1:. Signature, algebra in a signature. Isomorphisms, homomorphisms, congruences and quotient algebras. V. Borschev and B. Partee, September 18, 2001 p. 1 Lecture 4. Algebra. Section 1:. Signature, algebra in a signature. Isomorphisms, homomorphisms, congruences and quotient algebras. CONTENTS 0. Why algebra?...1

More information

Induction on Failing Derivations

Induction on Failing Derivations Induction on Failing Derivations Technical Report PL-Sep13 September 2013, with addenda from Spring 2016 ay Ligatti Department of Computer Science and Engineering University of South Florida Abstract A

More information

1 Reals are Uncountable

1 Reals are Uncountable CS 30: Discrete Math in CS (Winter 2019): Lecture 6 Date: 11th January, 2019 (Friday) Topic: Uncountability and Undecidability Disclaimer: These notes have not gone through scrutiny and in all probability

More information

Problem One: Order Relations i. What three properties does a binary relation have to have to be a partial order?

Problem One: Order Relations i. What three properties does a binary relation have to have to be a partial order? CS103 Handout 16 Fall 2011 November 4, 2011 Extra Practice Problems Many of you have expressed interest in additional practice problems to review the material from the first four weeks of CS103. This handout

More information

University of Aberdeen, Computing Science CS2013 Predicate Logic 4 Kees van Deemter

University of Aberdeen, Computing Science CS2013 Predicate Logic 4 Kees van Deemter University of Aberdeen, Computing Science CS2013 Predicate Logic 4 Kees van Deemter 01/11/16 Kees van Deemter 1 First-Order Predicate Logic (FOPL) Lecture 4 Making numerical statements: >0, 1,>2,1,2

More information

Lecture 4: Proposition, Connectives and Truth Tables

Lecture 4: Proposition, Connectives and Truth Tables Discrete Mathematics (II) Spring 2017 Lecture 4: Proposition, Connectives and Truth Tables Lecturer: Yi Li 1 Overview In last lecture, we give a brief introduction to mathematical logic and then redefine

More information

Singular perturbation theory

Singular perturbation theory Singular perturbation theory Marc R Roussel October 19, 2005 1 Introduction When we apply the steady-state approximation (SSA) in chemical kinetics, we typically argue that some of the intermediates are

More information

CS 188: Artificial Intelligence Spring Today

CS 188: Artificial Intelligence Spring Today CS 188: Artificial Intelligence Spring 2006 Lecture 9: Naïve Bayes 2/14/2006 Dan Klein UC Berkeley Many slides from either Stuart Russell or Andrew Moore Bayes rule Today Expectations and utilities Naïve

More information

INTRODUCTION TO LOGIC 1 Sets, Relations, and Arguments. Why logic? Arguments

INTRODUCTION TO LOGIC 1 Sets, Relations, and Arguments. Why logic? Arguments The Logic Manual INTRODUCTION TO LOGIC 1 Sets, Relations, and Arguments Volker Halbach Pure logic is the ruin of the spirit. Antoine de Saint-Exupéry The Logic Manual web page for the book: http://logicmanual.philosophy.ox.ac.uk/

More information

A Subtyping for Extensible, Incomplete Objects

A Subtyping for Extensible, Incomplete Objects Fundamenta Informaticae XX (1999) 1 39 1 IOS Press A Subtyping for Extensible, Incomplete Objects To Helena Rasiowa: in memoriam Viviana Bono Dipartimento di Informatica Università di Torino C.so Svizzera

More information

Linear Classification: Linear Programming

Linear Classification: Linear Programming Linear Classification: Linear Programming Yufei Tao Department of Computer Science and Engineering Chinese University of Hong Kong 1 / 21 Y Tao Linear Classification: Linear Programming Recall the definition

More information

Announcements. CS311H: Discrete Mathematics. Propositional Logic II. Inverse of an Implication. Converse of a Implication

Announcements. CS311H: Discrete Mathematics. Propositional Logic II. Inverse of an Implication. Converse of a Implication Announcements CS311H: Discrete Mathematics Propositional Logic II Instructor: Işıl Dillig First homework assignment out today! Due in one week, i.e., before lecture next Wed 09/13 Remember: Due before

More information

CS 4700: Foundations of Artificial Intelligence Homework 2 Solutions. Graph. You can get to the same single state through multiple paths.

CS 4700: Foundations of Artificial Intelligence Homework 2 Solutions. Graph. You can get to the same single state through multiple paths. CS 4700: Foundations of Artificial Intelligence Homework Solutions 1. (30 points) Imagine you have a state space where a state is represented by a tuple of three positive integers (i,j,k), and you have

More information

Final Exam (100 points)

Final Exam (100 points) Final Exam (100 points) Honor Code: Each question is worth 10 points. There is one bonus question worth 5 points. In contrast to the homework assignments, you may not collaborate on this final exam. You

More information

Loop Convergence. CS 536: Science of Programming, Fall 2018

Loop Convergence. CS 536: Science of Programming, Fall 2018 Solved Loop Convergence CS 536: Science of Programming, Fall 2018 A. Why Diverging programs aren t useful, so it s useful to know how to show that loops terminate. B. Objectives At the end of this lecture

More information

Mathematical Preliminaries. Sipser pages 1-28

Mathematical Preliminaries. Sipser pages 1-28 Mathematical Preliminaries Sipser pages 1-28 Mathematical Preliminaries This course is about the fundamental capabilities and limitations of computers. It has 3 parts 1. Automata Models of computation

More information

Limitations of OCAML records

Limitations of OCAML records Limitations of OCAML records The record types must be declared before they are used; a label e can belong to only one record type (otherwise fun x x.e) would have several incompatible types; we cannot

More information

Relations. Binary Relation. Let A and B be sets. A (binary) relation from A to B is a subset of A B. Notation. Let R A B be a relation from A to B.

Relations. Binary Relation. Let A and B be sets. A (binary) relation from A to B is a subset of A B. Notation. Let R A B be a relation from A to B. Relations Binary Relation Let A and B be sets. A (binary) relation from A to B is a subset of A B. Notation Let R A B be a relation from A to B. If (a, b) R, we write a R b. 1 Binary Relation Example:

More information

CS1021. Why logic? Logic about inference or argument. Start from assumptions or axioms. Make deductions according to rules of reasoning.

CS1021. Why logic? Logic about inference or argument. Start from assumptions or axioms. Make deductions according to rules of reasoning. 3: Logic Why logic? Logic about inference or argument Start from assumptions or axioms Make deductions according to rules of reasoning Logic 3-1 Why logic? (continued) If I don t buy a lottery ticket on

More information

Adam Blank Spring 2017 CSE 311. Foundations of Computing I

Adam Blank Spring 2017 CSE 311. Foundations of Computing I Adam Blank Spring 2017 CSE 311 Foundations of Computing I Pre-Lecture Problem Suppose that p, and p (q r) are true. Is q true? Can you prove it with equivalences? CSE 311: Foundations of Computing Lecture

More information

MAGIC Set theory. lecture 2

MAGIC Set theory. lecture 2 MAGIC Set theory lecture 2 David Asperó University of East Anglia 22 October 2014 Recall from last time: Syntactical vs. semantical logical consequence Given a set T of formulas and a formula ', we write

More information