Reasoning about programs. Chapter 9 of Thompson
|
|
- Solomon Ferguson
- 6 years ago
- Views:
Transcription
1 Reasoning about programs Chapter 9 of Thompson
2 Proof versus testing A proof will state some property of a program that holds for all inputs. Testing shows only that a property holds for a particular set of inputs. Property checking, such as with QuickCheck, improves coverage by randomly generating inputs, but is still not a proof. Proofs in functional programming rely on treating function definitions as logical terms, amenable to manipulation via the rules of logic.
3 Understanding definitions Consider: length [] = 0 -- (length.1) length (z:zs) = 1 + length zs -- (length.2)
4 Understanding definitions: by evaluation length [2,3,1] 1 + length [3,1] by (length.2) 1 + (1 + length [1]) by (length.2) 1 + (1 + (1 + length [])) by (length.2) 1 + (1 + (1 + 0)) by (length.1) 3
5 Understanding definitions: as descriptions (length.1) says what length [] is (length.1) says that whatever values of x and xs we choose, length (x:xs) will be equal to 1 + length xs The second case is a general property of length: how it behaves on all non-empty lists. These allow us to conclude that length [x] = 1 (length.3)... but how?
6 Understanding definitions: as descriptions length [x] = length (x:[]) by definition of [x] = 1 + length [] by (length.2) = by (length.1) = 1 We can read a definition as: 1. describing how to compute particular results, and 2. a general description of the behaviour of the function, allowing deductions to be made like (length.3) and others like length (xs ++ ys) = length xs + length ys
7 Proof as symbolic evaluation Instead of using a particular value as argument to length, like 2, we replace 2 with a symbolic variable x, but use the evaluation rules in the same way. Combining this symbolic evaluation with other proof techniques (like induction) allows many proofs for recursive functions.
8 Testing mysterymax :: Integer -> Integer -> Integer -> Integer mysterymax x y z x > y && x > z = x y > x && y > z = y otherwise = z prop_mystery :: Integer -> Integer -> Integer -> Bool prop_mystery x y z = mysterymax x y z == (x `max` y) `max` z
9 Proof by cases Consider: x > y && x > z y > x && y > z z > x && z > y For each of these cases, mysterymax is correct.
10 Proof by cases For all other cases at least two of the arguments are equal. If all three are equal: x == y && y == z then mysterymax is correct. Suppose: y == z && z > x then it is still correct. But, for: x == y && y > z theresult z is incorrect!
11 Proof by cases A form of symbolic testing case by case, for classes of inputs. However, in general, finding a proof of correctness is more difficult than this example. So, concrete testing is still a valuable exercise.
12 Definedness and termination Evaluation can have two outcomes: the evaluation can halt (terminate) with an answer the evaluation can go on forever (the value is undefined) Consider: fact :: Integer -> Integer fact n n==0 = 1 otherwise = n * fact (n-1)
13 Definedness and termination fact 2 terminates. fact (-2) is undefined: fact (-2) (-2) * fact (-3) (-2) * (-3) * fact (-4)...
14 Definedness and termination Proofs must confine themselves to cases for defined values where expected properties hold. 0 * e = 0, but only if e is defined 0 * e = undefined 0, if e is undefined Proofs usually hold only for all defined values. Undefined values are only of interest if the function in question does not give a defined value when it is expected to.
15 Finiteness Haskell evaluation is lazy, so arguments are evaluated only if their values are actually needed. Lazy evaluation allows definition and use of infinite lists, like [1,2,3,...] and partially defined lists. Our main attention will be to finite lists, which have a defined, finite length, and defined elements, e.g.: [] [1,2,3] [[4,5],[3,2,1],[]]
16 Assumptions in proofs Logical implication A B says that if A holds then B also holds (B follows from A) Proving an implication A B, we can assume A in proving B, and then simply need to prove A to guarantee our proof of B. A proof of A B is a process for turning a proof of A into a proof of B. In proof by induction, the induction step proves one property assuming another.
17 Free variables and quantifiers Equational reasoning implicitly quantifies over all possible values of free variables: square x = x * x says this holds for all (defined) values of the free variable x. More explicitly, we should actually write this with a logical quantifier: x (square x = x * x)
18 Induction Consider: sum :: [Integer] -> Integer sum [] = 0 -- (sum.1) sum (x:xs) = x + sum xs -- (sum.2) This gives a value outright at [], and defines the value of sum (x:xs) using the value sum xs
19 Principle of structural induction for lists In order to prove that a logical property P(xs) holds for all finite lists xs we have to do two things: Base case: Prove P([]) outright. Induction step: Prove P(x:xs) on the assumption that P(xs) holds. In other words P(xs) P(x:xs) has to be proved. The P(xs) is called the induction hypothesis since it is assumed in proving P(x:xs). This is just like primitive recursion: instead of building values of a function we build up parts of a proof. In both cases [] is a base case, and the general case goes from xs to (x:xs).
20 Justification of structural induction for lists Just as recursion is not circular, proof by induction builds a proof for all finite lists in stages. Given proofs of P([]) and P(xs) P(x:xs) for all x and xs suppose we want to show that P([1,2,3]): 1. P([]) holds; 2. P([]) P([3]) holds, since it is a case of P(xs) P(x:xs); 3. 1 & 2 give us that P([3]) holds; 4. P([3]) P([2,3]) holds, as for 2; 5. 3 & 4 give us that P([2,3]) holds; 6. P([2,3]) P([1,2,3]) holds, as for 2; 7. 5 & 6 give us that P([1,2,3]) holds. This works for all finite lists, so we have P(xs) for all finite lists.
21 Example: doubleall Consider: doubleall :: [Integer] -> [Integer] doubleall [] = [] -- (doubleall.1) doubleall (z:zs) = 2*z : doubleall zs -- (doubleall.2) Presumably: sum (doubleall xs) = 2 * sum xs -- (sum+dblall) [quickcheck property testing passes]
22 Example: doubleall Two induction goals: sum (doubleall []) = 2 * sum [] sum (doubleall (x:xs)) = 2 * sum (x:xs) using the induction hypothesis: sum (doubleall xs) = 2 * sum xs -- (base) -- (ind) -- (hyp)
23 Example: doubleall The base case: sum (doubleall []) = sum ([]) by (doubleall.1) = 0 by (sum.1) 2 * sum ([]) = 2 * 0 by (sum.1) = 0 by *
24 Example: doubleall The induction step: Now: sum (doubleall (x:xs)) = sum (2*x : doubleall xs) by (doubleall.2) = 2*x + sum (doubleall xs) by (sum.2) 2 * sum (x:xs) = 2 * (x + sum xs) by (sum.2) = 2*x + 2 * sum xs by distribution of * 2*x + sum (doubleall xs) = 2*x + 2 * sum xs by (hyp) QED
25 Finding induction proofs First step: define a QuickCheck property, and ensure it generates no counter examples. State the goal of the induction and the two sub-goals: (base) and (hyp) (ind) Change variable names as needs to avoid confusion (α-conversion) Use only definitions of functions involved and general rules of arithmetic to simplify sub-goals (for equations do LHS and RHS separately) For the induction step (ind) use (hyp) in its proof Label each step of the proof with its justification
Week 5 Tutorial Structural Induction
Department of Computer Science, Australian National University COMP2600 / COMP6260 Formal Methods in Software Engineering Semester 2, 2016 Week 5 Tutorial Structural Induction You should hand in attempts
More informationPROGRAMMING IN HASKELL. CS Chapter 6 - Recursive Functions
PROGRAMMING IN HASKELL CS-205 - Chapter 6 - Recursive Functions 0 Introduction As we have seen, many functions can naturally be defined in terms of other functions. factorial :: Int Int factorial n product
More informationIsabelle s meta-logic. p.1
Isabelle s meta-logic p.1 Basic constructs Implication = (==>) For separating premises and conclusion of theorems p.2 Basic constructs Implication = (==>) For separating premises and conclusion of theorems
More informationFUNCTIONAL PEARLS The countdown problem
To appear in the Journal of Functional Programming 1 FUNCTIONAL PEARLS The countdown problem GRAHAM HUTTON School of Computer Science and IT University of Nottingham, Nottingham, UK www.cs.nott.ac.uk/
More informationTheorem Proving Principles, Techniques, Applications Recursion
NICTA Advanced Course Theorem Proving Principles, Techniques, Applications Recursion 1 CONTENT Intro & motivation, getting started with Isabelle Foundations & Principles Lambda Calculus Higher Order Logic,
More informationIntroduction to the Lambda Calculus
Introduction to the Lambda Calculus Overview: What is Computability? Church s Thesis The Lambda Calculus Scope and lexical address The Church-Rosser Property Recursion References: Daniel P. Friedman et
More informationShell CSCE 314 TAMU. Functions continued
1 CSCE 314: Programming Languages Dr. Dylan Shell Functions continued 2 Outline Defining Functions List Comprehensions Recursion 3 A Function without Recursion Many functions can naturally be defined in
More informationFoundations of Computation
The Australian National University Semester 2, 2018 Research School of Computer Science Tutorial 5 Dirk Pattinson Foundations of Computation The tutorial contains a number of exercises designed for the
More informationIntroduction. chapter Functions
chapter 1 Introduction In this chapter we set the stage for the rest of the book. We start by reviewing the notion of a function, then introduce the concept of functional programming, summarise the main
More informationProgramming Languages 3. Definition and Proof by Induction
Programming Languages 3. Definition and Proof by Induction Shin-Cheng Mu Oct. 22, 2015 Total Functional Programming The next few lectures concerns inductive definitions and proofs of datatypes and programs.
More informationintroduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion
introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion Today s video will talk about an important concept in computer science which is
More information(a) Give inductive definitions of the relations M N and M N of single-step and many-step β-reduction between λ-terms M and N. (You may assume the
COMPUTER SCIENCE TRIPOS Part IB 205 Paper 6 4 (AMP) (a) Give inductive definitions of the relations M N and M N of single-step and many-step β-reduction between λ-terms M and N. (You may assume the definition
More informationFall 2018 Lecture N
15-150 Fall 2018 Lecture N Tuesday, 20 November I m too lazy to figure out the correct number Stephen Brookes midterm2 Mean: 79.5 Std Dev: 18.4 Median: 84 today or, we could procrastinate lazy functional
More informationVerifying Safety Property of Lustre Programs: Temporal Induction
22c181: Formal Methods in Software Engineering The University of Iowa Spring 2008 Verifying Safety Property of Lustre Programs: Temporal Induction Copyright 2008 Cesare Tinelli. These notes are copyrighted
More informationBasic Foundations of Isabelle/HOL
Basic Foundations of Isabelle/HOL Peter Wullinger May 16th 2007 1 / 29 1 Introduction into Isabelle s HOL Why Type Theory Basic Type Syntax 2 More HOL Typed λ Calculus HOL Rules 3 Example proof 2 / 29
More informationProgram Calculus Calculational Programming
Program Calculus Calculational Programming National Institute of Informatics June 21 / June 28 / July 5, 2010 Program Calculus Calculational Programming What we will learn? Discussing the mathematical
More information(a) (4 pts) Prove that if a and b are rational, then ab is rational. Since a and b are rational they can be written as the ratio of integers a 1
CS 70 Discrete Mathematics for CS Fall 2000 Wagner MT1 Sol Solutions to Midterm 1 1. (16 pts.) Theorems and proofs (a) (4 pts) Prove that if a and b are rational, then ab is rational. Since a and b are
More informationShell CSCE 314 TAMU. Higher Order Functions
1 CSCE 314: Programming Languages Dr. Dylan Shell Higher Order Functions 2 Higher-order Functions A function is called higher-order if it takes a function as an argument or returns a function as a result.
More informationSTABILITY AND PARADOX IN ALGORITHMIC LOGIC
STABILITY AND PARADOX IN ALGORITHMIC LOGIC WAYNE AITKEN, JEFFREY A. BARRETT Abstract. Algorithmic logic is the logic of basic statements concerning algorithms and the algorithmic rules of deduction between
More informationLecture 10 September 11, 2017
Programming in Haskell S P Suresh http://www.cmi.ac.in/~spsuresh Lecture 10 September 11, 2017 Combining elements sumlist :: [Int] -> Int sumlist [] = 0 sumlist (x:xs) = x + (sumlist xs) multlist :: [Int]
More informationTesting. Wouter Swierstra and Alejandro Serrano. Advanced functional programming - Lecture 2. [Faculty of Science Information and Computing Sciences]
Testing Advanced functional programming - Lecture 2 Wouter Swierstra and Alejandro Serrano 1 Program Correctness 2 Testing and correctness When is a program correct? 3 Testing and correctness When is a
More informationAbstract Interpretation Using Laziness: Proving Conway s Lost Cosmological Theorem
Abstract Interpretation Using Laziness: Proving Conway s Lost Cosmological Theorem Kevin Watkins CMU CSD POP Seminar December 8, 2006 In partial fulfillment of the speaking skills requirement ? 2111 1231
More informationProgramming Languages Third Edition
Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand
More informationThe List Datatype. CSc 372. Comparative Programming Languages. 6 : Haskell Lists. Department of Computer Science University of Arizona
The List Datatype CSc 372 Comparative Programming Languages 6 : Haskell Lists Department of Computer Science University of Arizona collberg@gmail.com All functional programming languages have the ConsList
More informationLecture 7: Primitive Recursion is Turing Computable. Michael Beeson
Lecture 7: Primitive Recursion is Turing Computable Michael Beeson Closure under composition Let f and g be Turing computable. Let h(x) = f(g(x)). Then h is Turing computable. Similarly if h(x) = f(g 1
More informationOverview. A Compact Introduction to Isabelle/HOL. Tobias Nipkow. System Architecture. Overview of Isabelle/HOL
Overview A Compact Introduction to Isabelle/HOL Tobias Nipkow TU München 1. Introduction 2. Datatypes 3. Logic 4. Sets p.1 p.2 System Architecture Overview of Isabelle/HOL ProofGeneral Isabelle/HOL Isabelle
More information1.3. Conditional expressions To express case distinctions like
Introduction Much of the theory developed in the underlying course Logic II can be implemented in a proof assistant. In the present setting this is interesting, since we can then machine extract from a
More informationLesson 20: Every Line is a Graph of a Linear Equation
Student Outcomes Students know that any non vertical line is the graph of a linear equation in the form of, where is a constant. Students write the equation that represents the graph of a line. Lesson
More informationCOMP4161: Advanced Topics in Software Verification. fun. Gerwin Klein, June Andronick, Ramana Kumar S2/2016. data61.csiro.au
COMP4161: Advanced Topics in Software Verification fun Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au Content Intro & motivation, getting started [1] Foundations & Principles Lambda
More informationIntroduction to Automata Theory. BİL405 - Automata Theory and Formal Languages 1
Introduction to Automata Theory BİL405 - Automata Theory and Formal Languages 1 Automata, Computability and Complexity Automata, Computability and Complexity are linked by the question: What are the fundamental
More informationCSE 20 DISCRETE MATH WINTER
CSE 20 DISCRETE MATH WINTER 2016 http://cseweb.ucsd.edu/classes/wi16/cse20-ab/ Today's learning goals Explain the steps in a proof by (strong) mathematical induction Use (strong) mathematical induction
More informationProgramming Languages Fall 2013
Programming Languages Fall 2013 Lecture 3: Induction Prof. Liang Huang huang@qc.cs.cuny.edu Recursive Data Types (trees) data Ast = ANum Integer APlus Ast Ast ATimes Ast Ast eval (ANum x) = x eval (ATimes
More informationRecursive Data and Recursive Functions
Structural Recursion and Induction Of all the material in this course, this lesson is probably the hardest for students to grasp at first, but it s also one of the most fundamental. Once you understand
More informationFunctional Programming. Overview. Topics. Definition n-th Fibonacci Number. Graph
Topics Functional Programming Christian Sternagel Harald Zankl Evgeny Zuenko Department of Computer Science University of Innsbruck WS 2017/2018 abstract data types, algebraic data types, binary search
More informationShell CSCE 314 TAMU. Haskell Functions
1 CSCE 314: Programming Languages Dr. Dylan Shell Haskell Functions 2 Outline Defining Functions List Comprehensions Recursion 3 Conditional Expressions As in most programming languages, functions can
More informationChapter 3. Set Theory. 3.1 What is a Set?
Chapter 3 Set Theory 3.1 What is a Set? A set is a well-defined collection of objects called elements or members of the set. Here, well-defined means accurately and unambiguously stated or described. Any
More informationELEMENTARY NUMBER THEORY AND METHODS OF PROOF
CHAPTER 4 ELEMENTARY NUMBER THEORY AND METHODS OF PROOF Copyright Cengage Learning. All rights reserved. SECTION 4.6 Indirect Argument: Contradiction and Contraposition Copyright Cengage Learning. All
More informationRecursion. Tjark Weber. Functional Programming 1. Based on notes by Sven-Olof Nyström. Tjark Weber (UU) Recursion 1 / 37
Tjark Weber Functional Programming 1 Based on notes by Sven-Olof Nyström Tjark Weber (UU) Recursion 1 / 37 Background FP I / Advanced FP FP I / Advanced FP This course (Functional Programming I) (5 hp,
More informationCSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Functions
1 CSCE 314: Programming Languages Dr. Flemming Andersen Haskell Functions 2 Outline Defining Functions List Comprehensions Recursion 3 Conditional Expressions As in most programming languages, functions
More informationBases of topologies. 1 Motivation
Bases of topologies 1 Motivation In the previous section we saw some examples of topologies. We described each of them by explicitly specifying all of the open sets in each one. This is not be a feasible
More informationType Processing by Constraint Reasoning
, Martin Sulzmann, Jeremy Wazny 8th November 2006 Chameleon Chameleon is Haskell-style language treats type problems using constraints gives expressive error messages has a programmable type system Developers:
More informationCSci 450: Org. of Programming Languages Overloading and Type Classes
CSci 450: Org. of Programming Languages Overloading and Type Classes H. Conrad Cunningham 27 October 2017 (after class) Contents 9 Overloading and Type Classes 1 9.1 Chapter Introduction.........................
More informationSide Effects (3A) Young Won Lim 1/13/18
Side Effects (3A) Copyright (c) 2016-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationInduction and Recursion. CMPS/MATH 2170: Discrete Mathematics
Induction and Recursion CMPS/MATH 2170: Discrete Mathematics Outline Mathematical induction (5.1) Sequences and Summations (2.4) Strong induction (5.2) Recursive definitions (5.3) Recurrence Relations
More informationDenotational semantics
1 Denotational semantics 2 What we're doing today We're looking at how to reason about the effect of a program by mapping it into mathematical objects Specifically, answering the question which function
More informationInduction and Semantics in Dafny
15-414 Lecture 11 1 Instructor: Matt Fredrikson Induction and Semantics in Dafny TA: Ryan Wagner Encoding the syntax of Imp Recall the abstract syntax of Imp: a AExp ::= n Z x Var a 1 + a 2 b BExp ::=
More informationCSCE 314 Programming Languages
CSCE 314 Programming Languages Haskell: Higher-order Functions Dr. Hyunyoung Lee 1 Higher-order Functions A function is called higher-order if it takes a function as an argument or returns a function as
More informationThis session. Recursion. Planning the development. Software development. COM1022 Functional Programming and Reasoning
This session Recursion COM1022 Functional Programming and Reasoning Dr. Hans Georg Schaathun and Prof. Steve Schneider University of Surrey After this session, you should understand the principle of recursion
More informationDiagonalization. The cardinality of a finite set is easy to grasp: {1,3,4} = 3. But what about infinite sets?
Diagonalization Cardinalities The cardinality of a finite set is easy to grasp: {1,3,4} = 3. But what about infinite sets? We say that a set S has at least as great cardinality as set T, written S T, if
More informationQuickCheck, SmallCheck & Reach: Automated Testing in Haskell. Tom Shackell
QuickCheck, SmallCheck & Reach: Automated Testing in Haskell By Tom Shackell A Brief Introduction to Haskell Haskell is a purely functional language. Based on the idea of evaluation of mathematical functions
More informationInduction for Data Types
Induction for Data Types COMP1600 / COMP6260 Dirk Pattinson Australian National University Semester 2, 2017 Catch Up / Drop in Lab When Fridays, 15.00-17.00 Where N335, CSIT Building (bldg 108) Until the
More informationLecture 19: Functions, Types and Data Structures in Haskell
The University of North Carolina at Chapel Hill Spring 2002 Lecture 19: Functions, Types and Data Structures in Haskell Feb 25 1 Functions Functions are the most important kind of value in functional programming
More informationLecture 5: Lazy Evaluation and Infinite Data Structures
Lecture 5: Lazy Evaluation and Infinite Data Structures Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense October 3, 2017 How does Haskell evaluate a
More informationCS103 Spring 2018 Mathematical Vocabulary
CS103 Spring 2018 Mathematical Vocabulary You keep using that word. I do not think it means what you think it means. - Inigo Montoya, from The Princess Bride Consider the humble while loop in most programming
More informationSoftware Properties as Axioms and Theorems
Applied Software Properties as Axioms and Theorems proofs by induction or How to Write Reliable Software and know it's reliable Applied 1 Example: Multiplexor Function Problem: Multiplex two sequences
More informationFall Recursion and induction. Stephen Brookes. Lecture 4
15-150 Fall 2018 Stephen Brookes Lecture 4 Recursion and induction Last time Specification format for a function F type assumption guarantee (REQUIRES) (ENSURES) For all (properly typed) x satisfying the
More information1. Chapter 1, # 1: Prove that for all sets A, B, C, the formula
Homework 1 MTH 4590 Spring 2018 1. Chapter 1, # 1: Prove that for all sets,, C, the formula ( C) = ( ) ( C) is true. Proof : It suffices to show that ( C) ( ) ( C) and ( ) ( C) ( C). ssume that x ( C),
More informationCS 44 Exam #2 February 14, 2001
CS 44 Exam #2 February 14, 2001 Name Time Started: Time Finished: Each question is equally weighted. You may omit two questions, but you must answer #8, and you can only omit one of #6 or #7. Circle the
More information1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall
CSE 20 https://goo.gl/forms/1o 1KOd17RMoURxjn2 DISCRETE MATH Fall 2017 http://cseweb.ucsd.edu/classes/fa17/cse20-ab/ Today's learning goals Explain the steps in a proof by mathematical and/or structural
More informationTo illustrate what is intended the following are three write ups by students. Diagonalization
General guidelines: You may work with other people, as long as you write up your solution in your own words and understand everything you turn in. Make sure to justify your answers they should be clear
More informationUNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING
UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING Monday 15 th December 2014 14:30 to 16:30 INSTRUCTIONS TO CANDIDATES 1.
More informationCS 3512, Spring Instructor: Doug Dunham. Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010
CS 3512, Spring 2011 Instructor: Doug Dunham Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010 Prerequisites: Calc I, CS2511 Rough course outline:
More informationSource-Based Trace Exploration Work in Progress
Source-Based Trace Exploration Work in Progress Olaf Chitil University of Kent, UK Abstract. Hat is a programmer s tool for generating a trace of a computation of a Haskell 98 program and viewing such
More informationIntroduction to Programming, Aug-Dec 2006
Introduction to Programming, Aug-Dec 2006 Lecture 3, Friday 11 Aug 2006 Lists... We can implicitly decompose a list into its head and tail by providing a pattern with two variables to denote the two components
More informationSolutions to In-Class Problems Week 4, Fri
Massachusetts Institute of Technology 6.042J/18.062J, Fall 02: Mathematics for Computer Science Professor Albert Meyer and Dr. Radhika Nagpal Solutions to In-Class Problems Week 4, Fri Definition: The
More informationLiquidate your assets
Liquidate your assets Reasoning about resource usage in Liquid Haskell MARTIN A.T. HANDLEY, University of Nottingham, UK NIKI VAZOU, IMDEA Software Institute, Spain GRAHAM HUTTON, University of Nottingham,
More informationCS 457/557: Functional Languages
CS 457/557: Functional Languages Lists and Algebraic Datatypes Mark P Jones Portland State University 1 Why Lists? Lists are a heavily used data structure in many functional programs Special syntax is
More information3.7 Denotational Semantics
3.7 Denotational Semantics Denotational semantics, also known as fixed-point semantics, associates to each programming language construct a well-defined and rigorously understood mathematical object. These
More informationCMSC 330: Organization of Programming Languages. Operational Semantics
CMSC 330: Organization of Programming Languages Operational Semantics Notes about Project 4, Parts 1 & 2 Still due today (7/2) Will not be graded until 7/11 (along with Part 3) You are strongly encouraged
More informationEnumerations and Turing Machines
Enumerations and Turing Machines Mridul Aanjaneya Stanford University August 07, 2012 Mridul Aanjaneya Automata Theory 1/ 35 Finite Sets Intuitively, a finite set is a set for which there is a particular
More informationChapter 1 Programming: A General Overview
Introduction Chapter 1 Programming: A General Overview This class is an introduction to the design, implementation, and analysis of algorithms. examples: sorting large amounts of data organizing information
More informationTuring Machines. A transducer is a finite state machine (FST) whose output is a string and not just accept or reject.
Turing Machines Transducers: A transducer is a finite state machine (FST) whose output is a string and not just accept or reject. Each transition of an FST is labeled with two symbols, one designating
More informationCombining Static and Dynamic Contract Checking for Curry
Michael Hanus (CAU Kiel) Combining Static and Dynamic Contract Checking for Curry LOPSTR 2017 1 Combining Static and Dynamic Contract Checking for Curry Michael Hanus University of Kiel Programming Languages
More informationThis assignment has four parts. You should write your solution to each part in a separate file:
Data Structures and Functional Programming Problem Set 1 CS 3110, Fall 013 Due at 11:59 PM, Thursday, September 5 Version: 3 Last Modified: Wednesday, August 8 This assignment has four parts. You should
More informationInformatics 1 Functional Programming Lecture 4. Lists and Recursion. Don Sannella University of Edinburgh
Informatics 1 Functional Programming Lecture 4 Lists and Recursion Don Sannella University of Edinburgh Part I Lists and Recursion Cons and append Cons takes an element and a list. Append takes two lists.
More informationHeron Quadrilaterals with Sides in Arithmetic or Geometric Progression
Heron Quadrilaterals with Sides in Arithmetic or Geometric Progression R.H.Buchholz & J.A.MacDougall Abstract We study triangles and cyclic quadrilaterals which have rational area and whose sides form
More informationCourse year Typeclasses and their instances
Course year 2016-2017 Typeclasses and their instances Doaitse Swierstra and Atze Dijkstra with extra s Utrecht University September 29, 2016 1. The basics 2 Overloading versus parametric polymorphism 1
More informationp x i 1 i n x, y, z = 2 x 3 y 5 z
3 Pairing and encoding functions Our aim in this part of the course is to show that register machines can compute everything that can be computed, and to show that there are things that can t be computed.
More informationHaske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell
Haskell An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dk The most popular purely functional, lazy programming language Functional programming language : a program
More informationRecursion. What is Recursion? Simple Example. Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem
Recursion Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem What is Recursion? A problem is decomposed into smaller sub-problems, one or more of which are simpler versions of
More informationTypes and Static Type Checking (Introducing Micro-Haskell)
Types and Static (Introducing Micro-Haskell) Informatics 2A: Lecture 13 Alex Simpson School of Informatics University of Edinburgh als@inf.ed.ac.uk 16 October, 2012 1 / 21 1 Types 2 3 4 2 / 21 Thus far
More informationAn introduction introduction to functional functional programming programming using usin Haskell
An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dkau Haskell The most popular p purely functional, lazy programming g language Functional programming language : a program
More informationTrees. Solution: type TreeF a t = BinF t a t LeafF 1 point for the right kind; 1 point per constructor.
Trees 1. Consider the following data type Tree and consider an example inhabitant tree: data Tree a = Bin (Tree a) a (Tree a) Leaf deriving Show tree :: Tree Int tree = Bin (Bin (Bin Leaf 1 Leaf ) 2 (Bin
More informationAnnouncements. CS243: Discrete Structures. Strong Induction and Recursively Defined Structures. Review. Example (review) Example (review), cont.
Announcements CS43: Discrete Structures Strong Induction and Recursively Defined Structures Işıl Dillig Homework 4 is due today Homework 5 is out today Covers induction (last lecture, this lecture, and
More informationThe Worker/Wrapper Transformation
The Worker/Wrapper Transformation Andy Gill 1 Graham Hutton 2 1 The University of Kansas 2 The University of Nottingham March 26th, 2009 Andy Gill, Graham Hutton The Worker/Wrapper Transformation March
More informationTypes and Static Type Checking (Introducing Micro-Haskell)
Types and Static (Introducing Micro-Haskell) Informatics 2A: Lecture 14 John Longley School of Informatics University of Edinburgh jrl@inf.ed.ac.uk 17 October 2017 1 / 21 1 Types 2 3 4 2 / 21 So far in
More informationLogic and Computation Lecture 20 CSU 290 Spring 2009 (Pucella) Thursday, Mar 12, 2009
Logic and Computation Lecture 20 CSU 290 Spring 2009 (Pucella) Thursday, Mar 12, 2009 Note that I change the name of the functions slightly in these notes from what I used in class, to be consistent with
More informationFunctional Programming with Isabelle/HOL
Functional Programming with Isabelle/HOL = Isabelle λ β HOL α Florian Haftmann Technische Universität München January 2009 Overview Viewing Isabelle/HOL as a functional programming language: 1. Isabelle/HOL
More informationUNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING
UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING Monday 15 th December 2014 09:30 to 11:30 INSTRUCTIONS TO CANDIDATES 1.
More informationMath 485, Graph Theory: Homework #3
Math 485, Graph Theory: Homework #3 Stephen G Simpson Due Monday, October 26, 2009 The assignment consists of Exercises 2129, 2135, 2137, 2218, 238, 2310, 2313, 2314, 2315 in the West textbook, plus the
More informationSemantics of programming languages
Semantics of programming languages Informatics 2A: Lecture 27 John Longley School of Informatics University of Edinburgh jrl@inf.ed.ac.uk 21 November, 2011 1 / 19 1 2 3 4 2 / 19 Semantics for programming
More informationHomework 1: Functional Programming, Haskell
Com S 541 Programming Languages 1 September 25, 2005 Homework 1: Functional Programming, Haskell Due: problems 1 and 3, Thursday, September 1, 2005; problems 4-9, Thursday, September 15, 2005; remaining
More information1 The language χ. Models of Computation
Bengt Nordström, 1 2017-10-13 Department of Computing Science, Chalmers and University of Göteborg, Göteborg, Sweden 1 The language χ The main purpose of the language χ is to illustrate some basic results
More informationIt is important that you show your work. There are 134 points available on this test.
Math 1165 Discrete Math Test April 4, 001 Your name It is important that you show your work There are 134 points available on this test 1 (10 points) Show how to tile the punctured chess boards below with
More informationCS 161 Computer Security
Wagner Spring 2014 CS 161 Computer Security 1/27 Reasoning About Code Often functions make certain assumptions about their arguments, and it is the caller s responsibility to make sure those assumptions
More informationStructural polymorphism in Generic Haskell
Structural polymorphism in Generic Haskell Andres Löh andres@cs.uu.nl 5 February 2005 Overview About Haskell Genericity and other types of polymorphism Examples of generic functions Generic Haskell Overview
More informationChapter 1 Programming: A General Overview
Chapter 1 Programming: A General Overview 2 Introduction This class is an introduction to the design, implementation, and analysis of algorithms. Examples: sorting large amounts of data organizing information
More informationHaskell Introduction Lists Other Structures Data Structures. Haskell Introduction. Mark Snyder
Outline 1 2 3 4 What is Haskell? Haskell is a functional programming language. Characteristics functional non-strict ( lazy ) pure (no side effects*) strongly statically typed available compiled and interpreted
More information6.001 Notes: Section 15.1
6.001 Notes: Section 15.1 Slide 15.1.1 Our goal over the next few lectures is to build an interpreter, which in a very basic sense is the ultimate in programming, since doing so will allow us to define
More information1 Introduction. 3 Syntax
CS 6110 S18 Lecture 19 Typed λ-calculus 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic semantics,
More information