CS243, Logic and Computation Sets, functions, and languages

Similar documents
Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

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

9.5 Equivalence Relations

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

Computer Science and Mathematics. Part I: Fundamental Mathematical Concepts Winfried Kurth

Slides for Faculty Oxford University Press All rights reserved.

2.1 Sets 2.2 Set Operations

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

The Language of Sets and Functions

CHAPTER 8. Copyright Cengage Learning. All rights reserved.

Chapter 3. Set Theory. 3.1 What is a Set?

CSE 20 DISCRETE MATH. Fall

CSC Discrete Math I, Spring Sets

CSC 501 Semantics of Programming Languages

Logic and Discrete Mathematics. Section 2.5 Equivalence relations and partitions


Figure 1.1: This is an illustration of a generic set and its elements.

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

This book is licensed under a Creative Commons Attribution 3.0 License

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

Review of Sets. Review. Philippe B. Laval. Current Semester. Kennesaw State University. Philippe B. Laval (KSU) Sets Current Semester 1 / 16

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

CSE 20 DISCRETE MATH. Winter

Point-Set Topology 1. TOPOLOGICAL SPACES AND CONTINUOUS FUNCTIONS

THEORY OF COMPUTATION

Introduction to Sets and Logic (MATH 1190)

1.1 - Introduction to Sets

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

Sets and set operations

1 Introduction CHAPTER ONE: SETS

2. Sets. 2.1&2.2: Sets and Subsets. Combining Sets. c Dr Oksana Shatalov, Fall

Sets. Margaret M. Fleck. 15 September 2010

COMS 1003 Fall Introduction to Computer Programming in C. Bits, Boolean Logic & Discrete Math. September 13 th

Discrete Mathematics Lecture 4. Harper Langston New York University

MA651 Topology. Lecture 4. Topological spaces 2

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Discrete Mathematics

13 th Annual Johns Hopkins Math Tournament Saturday, February 18, 2012 Explorations Unlimited Round Automata Theory

RAQUEL s Relational Operators

LOGIC AND DISCRETE MATHEMATICS

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

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

MATH 22 MORE ABOUT FUNCTIONS. Lecture M: 10/14/2003. Form follows function. Louis Henri Sullivan

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08008 INFORMATICS 2A: PROCESSING FORMAL AND NATURAL LANGUAGES

CS100: DISCRETE STRUCTURES

Propositional Logic. Part I

This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS

Excerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.

Sets. Mukulika Ghosh. Fall Based on slides by Dr. Hyunyoung Lee

2.2 Syntax Definition

CHAPTER 3 FUZZY RELATION and COMPOSITION

Functions. How is this definition written in symbolic logic notation?

Today s Topics. What is a set?

SETS. Sets are of two sorts: finite infinite A system of sets is a set, whose elements are again sets.

r=1 The Binomial Theorem. 4 MA095/98G Revision

Programming Lecture 3

1. Relations 2. Equivalence relations 3. Modular arithmetics. ! Think of relations as directed graphs! xry means there in an edge x!

Chapter 3. Describing Syntax and Semantics

Sets. {1, 2, 3, Calvin}.

Notes on metric spaces and topology. Math 309: Topics in geometry. Dale Rolfsen. University of British Columbia

Formal languages and computation models

11 Sets II Operations

CS 341 Homework 1 Basic Techniques

A GRAPH FROM THE VIEWPOINT OF ALGEBRAIC TOPOLOGY

A.1 Numbers, Sets and Arithmetic

THREE LECTURES ON BASIC TOPOLOGY. 1. Basic notions.

Binary Relations McGraw-Hill Education

CSE 215: Foundations of Computer Science Recitation Exercises Set #9 Stony Brook University. Name: ID#: Section #: Score: / 4

13 th Annual Johns Hopkins Math Tournament Saturday, February 19, 2011 Automata Theory EUR solutions

Topic 1: What is HoTT and why?

Material from Recitation 1

CPSC 121 Some Sample Questions for the Final Exam Tuesday, April 15, 2014, 8:30AM

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

axiomatic semantics involving logical rules for deriving relations between preconditions and postconditions.

p x i 1 i n x, y, z = 2 x 3 y 5 z

14.1 Encoding for different models of computation

Topology and Topological Spaces

LECTURE NOTES ON SETS

10/11/2018. Partial Orderings. Partial Orderings. Partial Orderings. Partial Orderings. Partial Orderings. Partial Orderings

2 Review of Set Theory

2. CONNECTIVITY Connectivity

Functions. Def. Let A and B be sets. A function f from A to B is an assignment of exactly one element of B to each element of A.

Figure 4.1: The evolution of a rooted tree.

ECS 20 Lecture 9 Fall Oct 2013 Phil Rogaway

CHAPTER 3 FUZZY RELATION and COMPOSITION

Technische Universität München Zentrum Mathematik

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.

Let A(x) be x is an element of A, and B(x) be x is an element of B.

Math 187 Sample Test II Questions

MATHEMATICS 191, FALL 2004 MATHEMATICAL PROBABILITY Outline #1 (Countability and Uncountability)

2.2 Set Operations. Introduction DEFINITION 1. EXAMPLE 1 The union of the sets {1, 3, 5} and {1, 2, 3} is the set {1, 2, 3, 5}; that is, EXAMPLE 2

MATH 139 W12 Review 1 Checklist 1. Exam Checklist. 1. Introduction to Predicates and Quantified Statements (chapters ).

Recursively Enumerable Languages, Turing Machines, and Decidability

2 Sets. 2.1 Notation. last edited January 26, 2016

Modular Arithmetic. Marizza Bailey. December 14, 2015

Cantor s Diagonal Argument for Different Levels of Infinity

SOFTWARE ENGINEERING DESIGN I

(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

Mathematically Rigorous Software Design Review of mathematical prerequisites

15 212: Principles of Programming. Some Notes on Grammars and Parsing

Transcription:

CS243, Prof. Alvarez 1 NAIVE SET THEORY Prof. Sergio A. Alvarez http://www.cs.bc.edu/ alvarez/ Maloney Hall, room 569 alvarez@cs.bc.edu Computer Science Department voice: (617) 552-4333 Boston College fax: (617) 552-6790 Chestnut Hill, MA 02467 USA CS243, Logic and Computation Sets, functions, and languages These notes introduce standard set-theoretic concepts and notation that will be used throughout the course. 1 Naive set theory 1.1 Sets. Specification by extension A set is a collection of objects, such as the values of a particular array or the names of the seven days of the week. The objects in a set are called its elements. A set contains only one instance of each element. One way of specifying a set is by extension, that is, by an enumeration of its elements. It is customary to write curly braces around the list of elements: {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} {1, 0.5, 17.2, 6} Membership of an element x in a set S is denoted x S. For example, Wednesday W, where W denotes the set of the names of the days of the week. The number of the elements in a set S is denoted S. For example, W = 7. A set A is called a subset of a set B if every element of A is also an element of B; this is denoted A B or A B (even if A = B). 1.2 Equality of sets. Empty set Two sets A and B are equal if, and only if, they have the same elements, that is, if A is a subset of B and B is a subset of A. Although relative order among the elements is suggested by comma-separated list notation like that above, sets are unordered. The set of the names of the seven days of the week could be writen equivalently as follows: W = {Sunday, Wednesday, Monday, Thursday, Tuesday, Saturday, Friday} On the other hand, the two sets below are not the same: A = {1, 2, 3} B = {{1}, {2, 3}} That s because these two sets do not have the same elements. In fact, these two sets don t even have the same number of elements: A has the three elements 1, 2, 3, while B has the

1.3 Well-foundedness. Paradoxes 1 NAIVE SET THEORY two elements {1} and {2, 3} (each of which is a set in its own right). The special symbol is reserved for the empty set the set that has no elements. I say the empty set because there certainly can t be two: if there were, we should be able to find an element of one of the two that is not an element of the other! 1.3 Well-foundedness. Paradoxes Sets can have other sets as their elements, as we saw above. However, we will usually restrict ourselves to finite nesting depths. 1 Interesting things can happen otherwise. For example, one can consider the following set, R: R = {x x is not an element of x} The following question naturally arises here: Is R an element of itself? This rapidly leads to trouble. If R were an element of itself, that would mean that R should satisfy the condition for membership in R, namely not being an element of itself (contradiction). Likewise, if R were not an element of itself, then it would satisfy the condition for membership in R! Thus, beasts like R cannot exist in the standard sense. This example is known as Russell s paradox. 1.4 Specification of sets by intension It is possible to specify sets by intension, that is, by giving the required properties of their elements. We have already done this informally, as when describing a set as consisting of the names of the seven days of the week. Another example is the set of integers between 1 and 10, inclusive. Symbolic notation is useful in providing an intensional specification, as in this example: S = {x Z 1 x 10}, where Z is the standard name of the set of integers (from the German zahlen). Specification by intension is essentially what is used in Python list comprehension syntax: >>> L = set([x**2 for x in range(10)]) >>> L set([0, 1, 4, 81, 64, 9, 16, 49, 25, 36]) Specification by intension is particularly convenient when dealing with large sets, or in cases in which the extension of the set is incompletely understood: A = {(x, y) R 2 y = x 3 } B = {x R cos(x) = x} 1 An exception will occur in the definition of ordinal numbers.

1.5 Operations with sets 1 NAIVE SET THEORY 1.5 Operations with sets 1.5.1 Boolean set operations Suppose that A and B are sets. New sets can be defined in terms of A and B as follows: ˆ The complement of A, denoted A or A or Ā, is the set of all objects that are not elements of A. Some universe set U of all possible objects is usually assumed, and the complement of A then consists of all elements of U that do not belong to A. Notice that the complement of the complement of A is just A. ˆ The union of A and B is the set A B of all objects that belong to at least one of the sets A and B. ˆ The intersection of A and B is the set A B of all objects that belong to both of the sets A and B. Associativity. Commutativity. Union and intersection are both associative and commutative. That is, for any sets A, B, C, the following equalities hold: A (B C) = (A B) C A B = B A A (B C) = (A B) C A B = B A This means that order doesn t matter in applying union or intersection operations (as long as you stick to all unions or all intersections). In particular, the union or intersection of any number of sets are well-defined and there is a simplified notation for them: n A i is the set of all objects that belong to at least one of the sets A i, for i = 1 n i=1 n A i is the set of all objects that belong to all of the sets A i, for i = 1 n i=1 The union or intersection of an infinite number of sets can also be defined. We ll normally stick to the case in which there is one operand per natural number (positive integer): A i is the set of all objects that belong to at least one of the sets A i, i = 1, 2, 3, i=1 A i is the set of all objects that belong to all of the sets A i, i = 1, 2, 3, i=1

1.5 Operations with sets 1 NAIVE SET THEORY Mutual distributivity of interesection and union. Theorem 1.1. If A, B, and C are sets, then A (B C) = (A B) (A C) A (B C) = (A B) (A C) Proof. We will establish the equality of the two sets in the first part of Eq. 1. To do so, let L denote the set on the left-hand side, and R the set on the right-hand side. We will show that L R and that R L. This will prove that L and R have the same extension (contain the same elements), which is what is needed. ˆ First show that L R. Take any element x of L. We must show that x must also be an element of R. Since x is in L, we know that x must belong to A and to either B or C (by definition of intersection and union, respectively). If x belongs to B, then, since x also belongs to A, we see that x belongs to A B. If on the other hand, x belongs to C, then x belongs to A C (since x belongs to A in any case). This shows that x belongs to the union that defines R. ˆ Now show that R L. Take any element x of R, and show that x must also belong to L. Examining the union that defines R, we see that x either belongs to both A and B, or else to both A and C. Since B and C are both subsets of B C, we see that x will therefore belong to A (B C) in either case. This shows that x belongs to L, and completes the proof that intersection distributes over union (top part of Eq. 1). Boolean duality identities (DeMorgan s laws). Any given object x will simultaneously be in both A and B precisely when x fails to be in either A or B. Hence, A B = (A B) Since the complement of the complement of a set is the original set, substituting A for A and B for B in the preceding equation and then taking the complement on each side yields the following additional identity: (A B) = A B 1.5.2 Ordered tuples. Cartesian product of sets Sets are unordered, but it is convenient to have a notation for lists in which relative order matters. Custom dictates that round parentheses be used for this, as in: (3, 9, 2) Thus, 3 is the first element of this tuple, 9 is the second, and 2 is the third. The length of a tuple is the number of its elements. The above tuple has length 3. We will see later that ordered tuples can be represented using sets in a special way. Python lists are very close conceptually to tuples as we describe them here. Python tuples are close, but the immutability of Python tuples is a property that is extraneous to the mathematical notion of tuple in the present sense. (1)

2 OTHER OBJECTS BUILT FROM SETS: RELATIONS, FUNCTIONS Cartesian product. We can put the notion of tuple to use right away. Suppose that S 1, S k are sets. The Cartesian product (also called direct product) of these sets is the set that has as its elements all ordered tuples (x 1, x k ), where each x i is an element of the corresponding set S i. For example, the Cartesian product of the two sets {A, B, C} and {1, 2, 3, 4} is the set {(A, 1), (A, 2), (A, 3), (A, 4), (B, 1), (B, 2), (B, 3), (B, 4), (C, 1), (C, 2), (C, 3), (C, 4)}. This product is denoted S 1 S k. 2 Other objects built from sets: relations, functions 2.1 Ordered tuples. Although an ordered tuple such as (3, 9, 2) is not the same as as the set of its elements {3, 9, 2}, tuples can be constructed from ordinary unordered sets: one simply uses nesting to represent order, so that the i-the element of the tuple is located at nesting depth i. For example, the above tuple can be represented by the following set: 2.2 Relations {3, {9, {2}}} Modeling relationships among objects is very useful. For example, words can be related by syntax or semantic content, and can be related by common interests or other social connections. Relationships like these can be represented through constructs based on sets. 2.2.1 Binary relations. Domain and codomain. A binary relation describes a relationships between pairs of objects. For example, 3 < 5 is an instance of the binary relation less than, and CS243 : computer science is an instance of the binary relation course : department. A binary relationship that models friendship could have an instance such as John is friends with Mary. The domain of a relation is the set of objects on which the relation can be applied (tested). The friendship relation would have a set of people as its domain, for example (or a set of user accounts). In the case of the course : department relation, the term domain would be reserved for the set of course numbers (as these are listed first), and the set of department names would be called the codomain. Sometimes the terms domain and codomain are used generally to refer to all objects to which a relationship could be applied, that is, tested. For example, one might consider the domain of the < relation to be the set of real numbers, even if only the numbers 1, 2, 3, 4, 5, 6 are being considered at that moment. Set representation of binary relations. Relational notation. A binary relation can be represented as a set, the elements of which are either unordered pairs or ordered pairs. For example, the course : department relation would be represented by the set of ordered pairs (c, d), where c is a course number and d is the name of the department that teaches

2.2 Relations 2 OTHER OBJECTS BUILT FROM SETS: RELATIONS, FUNCTIONS course c. The less than relation would be represented by the set of all ordered pairs (x, y), where x < y. The friendship relation would be represented by a set of unordered pairs, assuming that it is being thought of as symmetric. Given this representation, it is natural to use the notation (x, y) R to state that x and y are related by relation R. The existence of relationship R between objects x and y is also denoted by R(x, y) (prefix notation) or xry (infix notation). Examples include Fr(John, Mary) and John Fr Mary. We had already used the standard infix notation for the < relation. The postfix notation xyr is sometimes used, but is uncommon. Properties of (some) binary relations. same domain and codomain. Suppose that R is a binary relation with the ˆ R is symmetric if, and only if, xry yrx for all objects x, y Notice that the friendship relationship can plausibly be thought of as being symmetric (thus, one would also expect that Mary is friends with John would be valid in the above context). On the other hand, the less than relation is clearly not symmetric, as the statement x < y precludes the statement y < x in the usual interpretation. ˆ R is reflexive if and only if, xrx for all objects x The friendship relation is reflexive, assuming that there are no self-haters. The less than relation is not reflexive. Proximity is typically a reflexive notion: if object x is close to object y, then object y is close to object x. However, one-way roads could change that assessment. ˆ R is transitive if and only if xry and yrz xrz for all objects x, y, z Less than is a transitive relation, but friendship is not. Equivalence relations. A binary relation that is reflexive, symmetric, and transitive is called an equivalence relation. Equivalence describes a de facto equality in a specific context: two objects that are equivalent are equal for the intended purposes. What purposes are intended, and if a given equivalence relation captures the necessary features, are important modeling issues that must be addressed in each case, but they fall outside the definition of the general notion of equivalence relation. As an example, define a binary relation SS on a domain consisting of finite sets as follows. A SS B A and B have the same number of elements

2.3 Functions 2 OTHER OBJECTS BUILT FROM SETS: RELATIONS, FUNCTIONS 5 4 1 2 3 Figure 1: An undirected graph. 6 We see that this relation SS (for same size ) is an equivalence relation: every set obviously has the same number of elements as itself, having the same number of elements is a symmetric property (if A has the same number of elements as B, then of course B has the same number as A), and, likewise, equality of size is clearly transitive (if A and B have the same size and B and C have the same size, then A and C have the same size). Two sets that have the same size (same number of elements) are not necessarily equal (have the same specific elements), but they are equal enough if the specific labels of the elements are irrelevant in a certain context. For example, one could be interested in measuring traffic or sales in two situations, and the specific details of the individual transactions may not be an immediate concern. Graphs. Graphs are graphical structures that represent binary relations. An undirected graph represents a symmetric binary relation as a collection of points called vertices, one for each element of the domain, with lines called arcs that connect pairs of vertices that are elements of the binary relation. An example appears in Fig. 1. Graphs allow the application of geometric or topological notions such as path, cycle, and connectedness to binary relations. For example, the graph in Fig. 1 is connected because it includes a path between every pair of vertices, and it has three cycles, namely the closed paths 1, 2, 5, 1, and 2, 3, 4, 5, 2, and 1, 2, 3, 4, 5, 1. Connected graphs without cycles, called trees, occur frequently and have important uses. 2.3 Functions Functions are the familiar processing boxes that, given an input object x, produce an output object f(x) that is determined by x. Functions can be thought of as special binary relations: ˆ A function f : X Y is a subset of the Cartesian product X Y such that, for each x X, there is a unique y Y such that (x, y) f. This unique value y is denoted f(x). The geometric-sounding term mapping and the term transformation

2.3 Functions 2 OTHER OBJECTS BUILT FROM SETS: RELATIONS, FUNCTIONS are sometimes used synonymously with function. The anonymous function notation x f(x) is also common. 2.3.1 Properties of (some) functions Suppose that f : X Y is a function. ˆ f is injective (also called one-to-one) if, and only if, f(x 1 ) = f(x 2 ) x 1 = x 2 for all objects x 1, x 2 in X Examples of injective functions include the function with the BC community as its domain that attaches an Eagle ID number to each person, and the function x x 3 on the real line. An example of a non-injective function is the function that associates to each person their home address. ˆ f is surjective (also called onto) if, and only if, y Y there is some x X such that f(x) = y This notion is relative to the codomain, of course. A function that is onto for a given codomain will not be onto if the codomain is redefined to be a larger set. Examples of surjective functions include the function that attaches an Eagle ID number to a member of the BC community, and the modulo 3 remainder function mod 3 : N {0, 1, 2} on the set of non-negative integers. ˆ f is bijective (or a bijection) if, and only if, f is both injective and surjective. Examples of bijections include the function x mod 3 (2 x) on the set {0, 1, 2}, and the function x x 3 on the set of real numbers. The existence of any bijection from X to Y implies that X and Y have the same number of elements. Since sets provide no structure other than membership, having the same number of elements is structurally indistinguishable from set equality, except for the names of the elements. For this reason, a bijection is sometimes called an isomorphism of sets. Example: near-associativity of the Cartesian product. Consider building the Cartesian product A B C in two stages, as follows: first, construct the Cartesian product A B, and then take the Cartesian product of the result with the remaining set, C, thereby obtaining (A B) C. The question is: does this two-stage procedure really produce the standard Cartesian product? Let s take a closer look at the result in each case: ˆ A B C was defined as consisting of all ordered tuples (a, b, c), where a A, b B, c C. ˆ (A B) C consists of all ordered pairs (d, c), where d A B, c C. Since the elements of A B are, in turn, ordered pairs of the form (a, b), where a A, b B, this means that (A B) C consists of all tuples ((a, b), c), where a A, b B, c C.

3 FORMAL LANGUAGES By the above, the two results are technically not the same. The first consists of ordered triples, while the second consists of ordered pairs in which the first component happens to be an ordered pair as well. However, the difference between (a, b, c) and ((a, b), c) for the same three objects a, b, c seems superficial. If we simply define the obvious function f : (A B) C A B C as follows: f ((a, b), c) = (a, b, c), then we will obtain a bijection between the two sets (check that this is true). Perhaps (A B) C and A B C are not equal, but we have shown them to be equivalent in a fundamental sense, by way of the above particularly natural bijection. 3 Formal languages Languages are used for human communication, as well as in the specification of computational procedures and systems. We will describe languages formally, in terms of sets. 3.1 Basic terminology: alphabet, string, Kleene closure, language. A fundamental object in any language is a string, which is just an ordered tuple of symbols taken from some alphabet. English words like terminology are strings over a well-known 26-letter alphabet. More generally, suppose that S denotes the alphabet to be used. The strings of length k over S are the elements of the Cartesian product S k. The length of a string can be any non-negative integer. We allow 0 as the length of the empty string, often known by the name ɛ. We will not consider strings of infinite length in most cases. Therefore, our default set of strings over an alphabet S will be the following union over all non-negative lengths: S = S k k=0 This set of all strings is called the Kleene closure of S. A language over an alphabet S is just a subset of S, that is, a language over S is some set of strings over S. 3.2 Syntax and semantics Syntax is taken to be synonymous with grammar, that is, the specification of the allowable forms of strings in a given language. For example, the syntax of Python allows the following string: >>> for i in range(1,10): but not the following string: >>> for each i between 1 and 10:

3.2 Syntax and semantics 3 FORMAL LANGUAGES Syntax is often described in terms of rules. An example of a formal syntactical specification appears below. Semantics refers to the meaning associated with strings. For example, in Python, the syntactically correct string in the first example above should set up an iteration over the values 0, 9 for i. 3.2.1 Example: a context-free grammar A grammar that models the syntax of a certain type of sentence can be described as a start symbol, S, together with a set of production rules or rewriting rules that allow successive transformation of the start symbol into more detailed forms, ending in a string of actual words. The grammar rules appear below. In each case, vertical lines or dashes are used on the right-hand side to indicate several available alternatives. S SNP SV P P NP P V P SNP SA ADJ SNP SA SNP P P SA SN P NP P A ADJ P NP P A P NP P P P A P N SA the a this that P A the these those SN boat boy girl car cat dog train plane poem scientist water sky P N SNs SV P SV ADV P P SV ADV SV SV is goes flies hits runs kisses imagines breaks enjoys P V P P V ADV P P P V P P P V P V are go fly hit run kiss imagine break enjoy P P P SNP P P NP P to at on near by below above before after ADV merrily greedily quickly clumsily ADJ bright green red yellow blue large small rough fragrant soft In order for a sentence (string) to be generated by a grammar, it is necessary that there be a derivation of that string in the grammar, meaning a sequence of strings of which the first string is the start symbol S, the last string is the target string (sentence), and each string in the sequence can be obtained from the one immediately preceding it by applying one of the transformation rules of the grammar to one of the variables in the predecessor string. Below are some examples of sentences generated by the above grammar. the bright blue dog runs merrily by the water those boys are on the plane a fragrant poem imagines in the sky that car kisses the soft boat Consider the second of those sentences: those boys are on the plane. This is generated

4 EXERCISES by the above grammar via the following derivation: S P NP P V P P A P N P V P those P NP P V P those P N P V P those SNs P V P those boys P V P those boys P V P P those boys are P P those boys are P SNP those boys are on SNP those boys are on SA SN those boys are on the SN those boys are on the plane We will encounter context-free grammars again later in the course. For now, we note that a context-free grammar can be defined formally in terms of sets and functions: Definition 3.1. A context-free grammar is a tuple (V, T, R, S) consisting of a set V of variables (like ADJ and P N P above), a set T of terminal symbols (such as the, boat, merrily), a set R of rewriting rules (e.g., SNP SA ADJ SNP ), and a selected variable S called the start symbol. Each rule in R is of the form V w, where w is a string of variables and / or terminals; equivalently, R V (V T ). 4 Exercises 1. In Python, what is the size (length) of set(l), where L is the list [x%5 for x in range(100)]? How does the answer differ from the length of L? Explain the difference. 2. Show in detail that the set of integers that are divisible (with zero remainder) by both 2 and by 3 is equal to the set {6n n is an integer}. 3. Are (A B) C and A (B C) the same set? Describe the relationship between the two precisely. Explain in detail. 4. Show that the bottom part of Eq. 1 follows from the top part by DeMorgan s laws. 5. A binary relation R is called antireflexive if xry implies that it is not the case that yrx. Give examples of a reflexive relation that is not antireflexive, an antireflexive relation that is not reflexive, and a binary relation that is neither reflexive nor antireflexive.

4 EXERCISES 6. Suppose that a function f : R R is a symmetric binary relation, where R is the set of real numbers. Give a precise expression for f(x) in terms of x. Explain.