Ordered structures. Dr. C. Constantinides. Department of Computer Science and Software Engineering Concordia University Montreal, Canada

Similar documents
Functional programming with Common Lisp

2.1 Sets 2.2 Set Operations

Lecture 6,

9/19/12. Why Study Discrete Math? What is discrete? Sets (Rosen, Chapter 2) can be described by discrete math TOPICS

Sets MAT231. Fall Transition to Higher Mathematics. MAT231 (Transition to Higher Math) Sets Fall / 31

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Functions

PROGRAMMING IN HASKELL. Chapter 5 - List Comprehensions

Construction Techniques

Slides for Faculty Oxford University Press All rights reserved.

1.3 Functions and Equivalence Relations 1.4 Languages

CS314: FORMAL LANGUAGES AND AUTOMATA THEORY L. NADA ALZABEN. Lecture 1: Introduction

Chapter Seven: Regular Expressions

Alphabets, strings and formal. An introduction to information representation

Shell CSCE 314 TAMU. Haskell Functions

SML A F unctional Functional Language Language Lecture 19

This Lecture. We will first introduce some basic set theory before we do counting. Basic Definitions. Operations on Sets.

Shell CSCE 314 TAMU. Functions continued

2/18/14. Uses for Discrete Math in Computer Science. What is discrete? Why Study Discrete Math? Sets and Functions (Rosen, Sections 2.1,2.2, 2.

Dr. D.M. Akbar Hussain

Regular Languages and Regular Expressions

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

Theoretical Part. Chapter one:- - What are the Phases of compiler? Answer:

Formal Languages and Automata

a little more on macros sort of like functions, but..

Reasoning About Programs Panagiotis Manolios

PROGRAMMING IN HASKELL. CS Chapter 6 - Recursive Functions

Module 1 Topic C Lesson 14 Reflections

THE RELATIONAL DATA MODEL CHAPTER 3 (6/E) CHAPTER 5 (5/E)

CSE 444 Midterm Test

SC/MATH Boolean Formulae. Ref: G. Tourlakis, Mathematical Logic, John Wiley & Sons, York University

Specifying logic functions

Python I. Some material adapted from Upenn cmpe391 slides and other sources

OCaml. History, Variants. ML s holy trinity. Interacting with ML. Base type: Integers. Base type: Strings. *Notes from Sorin Lerner at UCSD*

OCaml. ML Flow. Complex types: Lists. Complex types: Lists. The PL for the discerning hacker. All elements must have same type.

Plan (next 4 weeks) 1. Fast forward. 2. Rewind. 3. Slow motion. Rapid introduction to what s in OCaml. Go over the pieces individually

Chapter Seven: Regular Expressions. Formal Language, chapter 7, slide 1

Discrete Mathematics

A Characterization of the Chomsky Hierarchy by String Turing Machines

The Relational Data Model. Functional Dependencies. Example. Functional Dependencies

Programming Languages

Relational Database: The Relational Data Model; Operations on Database Relations

Introduction to LISP. York University Department of Computer Science and Engineering. York University- CSE V.

Theory of Computations III. WMU CS-6800 Spring -2014

CHAPTER TWO LANGUAGES. Dr Zalmiyah Zakaria

Sets 1. The things in a set are called the elements of it. If x is an element of the set S, we say

News. Programming Languages. Complex types: Lists. Recap: ML s Holy Trinity. CSE 130: Spring 2012

Programming Languages

CS 320: Concepts of Programming Languages

Section 1.7 Sequences, Summations Cardinality of Infinite Sets

CSE 3302 Programming Languages Lecture 8: Functional Programming

LING/C SC/PSYC 438/538. Lecture 20 Sandiway Fong

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

SET DEFINITION 1 elements members

Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

A general introduction to Functional Programming using Haskell

Any questions. Say hello to OCaml. Say hello to OCaml. Why readability matters. History, Variants. Plan (next 4 weeks)

CMPSCI 250: Introduction to Computation. Lecture #7: Quantifiers and Languages 6 February 2012

Section 2.4 Sequences and Summations

Software Testing. 1. Testing is the process of demonstrating that errors are not present.

Compiler Design. 2. Regular Expressions & Finite State Automata (FSA) Kanat Bolazar January 21, 2010

A Theorem of Ramsey- Ramsey s Number

Lists. Michael P. Fourman. February 2, 2010

Closure Properties of CFLs; Introducing TMs. CS154 Chris Pollett Apr 9, 2007.

Properties of a Function s Graph

CMSC 330: Organization of Programming Languages. Functional Programming with Lists

Lisp. Versions of LISP

An introduction to Category Theory for Software Engineers*

Understanding Regular Expressions, Special Characters, and Patterns

Outline. CISC 1100/1400 Structures of Comp. Sci./Discrete Structures Chapter 1 Sets. Sets. Enumerating the elements of a set

Programming Languages

A Third Look At ML. Chapter Nine Modern Programming Languages, 2nd ed. 1

Lexical Analysis (ASU Ch 3, Fig 3.1)

Which of the following expressions has the type int list?

Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103. Chapter 2. Sets

λ-calculus Lecture 1 Venanzio Capretta MGS Nottingham

COP 3402 Systems Software Syntax Analysis (Parser)

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

The University of Nottingham

CMSC 330: Organization of Programming Languages. Architecture of Compilers, Interpreters

1.3. Conditional expressions To express case distinctions like

So what does studying PL buy me?

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

Regular Expressions. Steve Renals (based on original notes by Ewan Klein) ICL 12 October Outline Overview of REs REs in Python

Transformation a shifting or change in shape of a graph

Homework Questions 1 Gradient of a Line using y=mx+c

ACM-ICPC Indonesia National Contest Problem A. The Best Team. Time Limit: 2s

3 Lists. List Operations (I)

A set with only one member is called a SINGLETON. A set with no members is called the EMPTY SET or 2 N

An Approach to Geometry (stolen in part from Moise and Downs: Geometry)

A l Ain University Of Science and Technology

Architecture of Compilers, Interpreters. CMSC 330: Organization of Programming Languages. Front End Scanner and Parser. Implementing the Front End

Formal Languages and Compilers Lecture IV: Regular Languages and Finite. Finite Automata

Web Science & Technologies University of Koblenz Landau, Germany. Relational Data Model

System Functions and their Types in Shen

CSCC24 Functional Programming Scheme Part 2

The List Datatype. CSc 372. Comparative Programming Languages. 6 : Haskell Lists. Department of Computer Science University of Arizona

LECTURE 16. Functional Programming

Databases -Normalization I. (GF Royle, N Spadaccini ) Databases - Normalization I 1 / 24

Parsing Combinators: Introduction & Tutorial

CSC Discrete Math I, Spring Sets

Transcription:

Ordered structures Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada January 10, 2017 1/19

Introduction Ordered structures include tuples, lists and strings. 2/19

Tuples A tuple (also called sequence, or vector) is a structure which contains a collection of elements. Unlike sets and bags, the ordering of the elements matters in a tuple. Unlike a set, repetitions are allowed in a tuple. Note that since order is important and repetitions are allowed, (a,b,b,c) (c,a,b,b) (a,b,c) (c,a,b,b) The length of a tuple denotes the number of elements that it contains. A tuple of length n is called an n-tuple. A 2-tuple is often called an ordered pair and a 3-tuple is often called an ordered triple. 3/19

Cartesian product of sets For two sets A and B, an ordered pair is an object of the form (a,b) (alternative notations are < a,b > and a b) where a A and b B. The product (or Cartesian product) of two sets A and B is defined by A B = {(x,y) : x A,y B} which is the set of all ordered pairs in which the first element comes from A and the second element comes from B. 4/19

Lists A list is a finite ordered sequence of zero or more elements that can be repeated. We can only access two things in a list: the first element of the list (head) and the list made up of all except the head, called the tail of the list. The number of elements in a list is called the length of the list. For example, the list L = a,b,c,d has length 4, its head is a and its tail is b,c,d. 5/19

Lists /cont. We will use the notation head(l) and tail(l) to denote the head of L and the tail of L respectively. The empty list, denoted by does not have a head or tail. Note that a a a 6/19

Lists /cont. The elements of a list can be any kind of objects, including lists themselves in which case a list is said to be nested (as opposed to being flat). L head(l) tail(l) a, b a b a, b,c a b,c a a 7/19

Visualization of lists nil or a a nil a b nil a d nil e b c 8/19

Constructing lists We have three formal mechanisms to create a list which are summarized below: cons: It takes two arguments, an element and a list, and returns a new list whose head is the element and whose tail is the argument list. list: It creates a list comprised of its arguments. concat: It creates a list by concatenating existing lists. 9/19

Constructing lists with cons Function cons constructs a new list with an element and a list which are provided as arguments. For an element h and a list L, cons(h,l) denotes a list whose head is h and whose tail is L. Consider the following examples: cons(a, ) = a cons(a, b,c ) = a,b,c cons( a,b, c,d ) = a,b,c,d For any non-empty list L, the three operations are related: cons(head(l), tail(l)) = L 10/19

Constructing lists with cons /cont. We can use LISP as follows: (cons a ()) (A) > (cons a (cons b ())) (A B) > (cons a (cons (cons b (cons c ())) (cons d (cons e ())))) (A (B C) D E) 11/19

Constructing lists with list Function list takes any number of arguments and constructs a list comprised of these arguments. Function list has variable arity, i.e. it can take any number of arguments. For example: list(a, b,c,d) = a, b,c,d 12/19

Constructing lists with list /cont. Function concat constructs a new list by joining two or more sequences of elements end to end that are supplied as its arguments. Much like list, function concat has variable arity, i.e. it can take any number of arguments. There is a restriction on the types of its arguments: they must all be lists. For example: concat( a,b, c,d ) = a,b,c,d concat( a,b, c, d ) = a,b,c, d 13/19

Constructing lists with list /cont. We can use LISP as follows: > (list a) (A) > (list a b) (A B) > (list a (list a b) d e) (A (A B) D E) 14/19

Constructing lists with concat Much like list, function concat has variable arity, i.e. it can take any number of arguments. Note that there is a restriction on the types of its arguments: they must all be lists. Consider the following examples: concat( a,b, c,d ) = a,b,c,d concat( a,b, c, d ) = a,b,c, d 15/19

Constructing lists with concat In LISP, function append implements concat by joining two or more sequences of elements end to end that are supplied as its arguments. We can use LISP as follows: > (append (list a)) (A) > (append (list a) (list b)) (A B) > (append (list a) (list (list a b)) (list d) (list e)) (A (A B) D E) 16/19

Strings and languages A string is a finite sequence of zero or more elements. The elements are taken from a finite set called an alphabet. For example, if A = {a,b,c} then some strings over A are a,ba,aabb. A string with no elements is called the empty string, denoted by Λ. The number of elements in a string s is called the length of s denoted by s. For example, aabb = 4. 17/19

Strings and languages /cont. Concatenation is an operation to placing two strings s 1 and s 2 next to each other to form a new string. For example, concat(aa, bb) = aabb Given an alphabet A, a language is a set of strings over A. Any language over A is a subset of A, the set of all strings over A. 18/19

Summary Collection Order Repetitions allowed Set No No Bag No Yes Tuple Yes Yes List Yes Yes String Yes Yes 19/19