Lessons from Discrete Mathematics Kirsten Nelson Carleton - - PowerPoint PPT Presentation

lessons from discrete mathematics
SMART_READER_LITE
LIVE PREVIEW

Lessons from Discrete Mathematics Kirsten Nelson Carleton - - PowerPoint PPT Presentation

Lessons from Discrete Mathematics Kirsten Nelson Carleton University October 14, 2017 Contact: kirsten.nelson@carleton.ca Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 1 / 63 Introduction 1


slide-1
SLIDE 1

Lessons from Discrete Mathematics

Kirsten Nelson

Carleton University

October 14, 2017

Contact: kirsten.nelson@carleton.ca

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 1 / 63

slide-2
SLIDE 2

1

Introduction Biography Discrete vs. Discreet, and vs. Continuous

2

Ramsey Numbers Modeling and Graph Theory Isomorphism Factorials and ‘choose’

3

Covering Arrays Orthogonal Arrays Example and Application Programming Tools Backtracking Algorithm Data Structures

4

Kirkman’s Schoolgirl Problem

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 2 / 63

slide-3
SLIDE 3

A Short Bio

Cool things I’ve been able to do: Mathematician

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 3 / 63

slide-4
SLIDE 4

A Short Bio

Cool things I’ve been able to do: Mathematician

◮ B. Math, C&O/PM from the University of Waterloo Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 3 / 63

slide-5
SLIDE 5

A Short Bio

Cool things I’ve been able to do: Programmer Mathematician

◮ B. Math, C&O/PM from the University of Waterloo Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 3 / 63

slide-6
SLIDE 6

A Short Bio

Cool things I’ve been able to do: Programmer

◮ Netron - small software company, mostly business applications

Mathematician

◮ B. Math, C&O/PM from the University of Waterloo Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 3 / 63

slide-7
SLIDE 7

A Short Bio

Cool things I’ve been able to do: Programmer

◮ Netron - small software company, mostly business applications ◮ IBM - data mining software for WebSphere Commerce

Mathematician

◮ B. Math, C&O/PM from the University of Waterloo Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 3 / 63

slide-8
SLIDE 8

A Short Bio

Cool things I’ve been able to do: Programmer

◮ Netron - small software company, mostly business applications ◮ IBM - data mining software for WebSphere Commerce ◮ Intelliware - small programming-for-hire company

Mathematician

◮ B. Math, C&O/PM from the University of Waterloo Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 3 / 63

slide-9
SLIDE 9

A Short Bio

Cool things I’ve been able to do: Programmer

◮ Netron - small software company, mostly business applications ◮ IBM - data mining software for WebSphere Commerce ◮ Intelliware - small programming-for-hire company

Teacher Mathematician

◮ B. Math, C&O/PM from the University of Waterloo Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 3 / 63

slide-10
SLIDE 10

A Short Bio

Cool things I’ve been able to do: Programmer

◮ Netron - small software company, mostly business applications ◮ IBM - data mining software for WebSphere Commerce ◮ Intelliware - small programming-for-hire company

Teacher

◮ B. Ed. from York University

Mathematician

◮ B. Math, C&O/PM from the University of Waterloo Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 3 / 63

slide-11
SLIDE 11

A Short Bio

Cool things I’ve been able to do: Programmer

◮ Netron - small software company, mostly business applications ◮ IBM - data mining software for WebSphere Commerce ◮ Intelliware - small programming-for-hire company

Teacher

◮ B. Ed. from York University ◮ Bishop Strachan School and University of Toronto Schools - CS and

Math, Grades 7 to 12

Mathematician

◮ B. Math, C&O/PM from the University of Waterloo Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 3 / 63

slide-12
SLIDE 12

A Short Bio

Cool things I’ve been able to do: Programmer

◮ Netron - small software company, mostly business applications ◮ IBM - data mining software for WebSphere Commerce ◮ Intelliware - small programming-for-hire company

Teacher

◮ B. Ed. from York University ◮ Bishop Strachan School and University of Toronto Schools - CS and

Math, Grades 7 to 12

◮ Independent Learning Centre, Homework Help, TVO

Mathematician

◮ B. Math, C&O/PM from the University of Waterloo Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 3 / 63

slide-13
SLIDE 13

A Short Bio

Cool things I’ve been able to do: Programmer

◮ Netron - small software company, mostly business applications ◮ IBM - data mining software for WebSphere Commerce ◮ Intelliware - small programming-for-hire company

Teacher

◮ B. Ed. from York University ◮ Bishop Strachan School and University of Toronto Schools - CS and

Math, Grades 7 to 12

◮ Independent Learning Centre, Homework Help, TVO

Mathematician

◮ B. Math, C&O/PM from the University of Waterloo ◮ MMT from Waterloo, 2016 Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 3 / 63

slide-14
SLIDE 14

A Short Bio

Cool things I’ve been able to do: Programmer

◮ Netron - small software company, mostly business applications ◮ IBM - data mining software for WebSphere Commerce ◮ Intelliware - small programming-for-hire company

Teacher

◮ B. Ed. from York University ◮ Bishop Strachan School and University of Toronto Schools - CS and

Math, Grades 7 to 12

◮ Independent Learning Centre, Homework Help, TVO

Mathematician

◮ B. Math, C&O/PM from the University of Waterloo ◮ MMT from Waterloo, 2016 ◮ M. Sc. in Discrete Mathematics from Carleton, 2018 (hopefully) Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 3 / 63

slide-15
SLIDE 15

A Short Bio

Cool things I’ve been able to do: Programmer

◮ Netron - small software company, mostly business applications ◮ IBM - data mining software for WebSphere Commerce ◮ Intelliware - small programming-for-hire company

Teacher

◮ B. Ed. from York University ◮ Bishop Strachan School and University of Toronto Schools - CS and

Math, Grades 7 to 12

◮ Independent Learning Centre, Homework Help, TVO

Mathematician

◮ B. Math, C&O/PM from the University of Waterloo ◮ MMT from Waterloo, 2016 ◮ M. Sc. in Discrete Mathematics from Carleton, 2018 (hopefully) ◮ PhD??? Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 3 / 63

slide-16
SLIDE 16

diagram courtesy of Math by Tori, at kelsoemath.blogspot.ca Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 4 / 63

slide-17
SLIDE 17

Learning through Wikipedia?

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 5 / 63

slide-18
SLIDE 18

Maybe if I just click on all the links...

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 6 / 63

slide-19
SLIDE 19

A More Intuitive Description

In any group of six people, there are either three people that know each

  • ther, or three people that don’t know each other.

Knowing someone is symmetric; if Anthony know Betty, then Betty must know Anthony Obvious group-work opportunity “Why?” is the interesting question

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 7 / 63

slide-20
SLIDE 20

Modeling with Graphs

In the sense I’ll be talking about today, a graph is a series of points and lines. The points are formally known as vertices (singular vertex), and represent any discrete set of things. The lines are formally known as edges, and represent relationships between the things. Common examples include computer networks, with computers joined by cables; cities joined by roads; and airports joined by flights. In this case we’ll be representing the people by points and the relationships by lines. If two people know each other, we’ll join them with a line.

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 8 / 63

slide-21
SLIDE 21

Modeling the Problem

It’s pretty natural to draw six dots to represent the six people. We can start with no relationships, meaning that we have six people who don’t know each other. We then want to add lines to get down to two people who don’t know each other, without connecting a group of three people who do all know each other.

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 9 / 63

slide-22
SLIDE 22

“Without loss of generality...”

We love to throw around the term “without loss of generality”, often shorted to simply “w.l.o.g.”. In this case we use it to argue that we can choose A-B as our first

  • connection. You could choose any one of 15 lines to start with (why it’s

15 is an interesting thought exercise). No matter which line you pick, you can relabel the vertices so that A and B are the ends of the line. This is a natural way to introduce the notion of isomorphism. Whether two things are the same or not is a pretty tricky question, and it all depends on your definition. We like things to be cut and dried, so instead of saying things are the same, we say that they’re isomorphic under some operation. That makes it objective; if we agree on the

  • peration, we (usually) agree on whether two things are isomorphic.

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 10 / 63

slide-23
SLIDE 23

Back to the model

We connect A and B, then consider our next move. A little thought will show you that there are two unique choices next. We can either draw our new line so that it connects with the previous line, or so that it doesn’t. If we choose the first possible letters for each, we end up with B-C and C-D as our only possible next two moves.

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 11 / 63

slide-24
SLIDE 24

Continuing the Single Line

A little playing around shows there are four possible next steps in the first

  • ption above. You can consider it as three choices; either connect the line

into a triangle, connect a new person to the existing group, or choose a completely new line.

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 12 / 63

slide-25
SLIDE 25

Continuing the Double Lines

This time there are three options. You can choose an entirely new line, connect up the two previous lines, or connect to just one of the existing lines.

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 13 / 63

slide-26
SLIDE 26

Two Things to Notice

As soon as we create a triangle, we have three people who know each

  • ther. So we reject any graph that has a triangle, and focus on the other
  • ptions.

These two graphs are isomorphic under our operation, which is a relabeling

  • f the points. So although we can think of a tree to organize these steps

in, there will sometimes be more than one route to get to the “same” (isomorphic) diagram.

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 14 / 63

slide-27
SLIDE 27

Eliminating Cases

Knowing that we want to avoid triangles is helpful, because we can automatically reject any line that would create a triangle. In this case we could connect A-D, A-E, or B-E. How many people don’t know each other now?

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 15 / 63

slide-28
SLIDE 28

Eliminating Cases

Knowing that we want to avoid triangles is helpful, because we can automatically reject any line that would create a triangle. In this case we could connect A-D, A-E, or B-E. How many people don’t know each other now?

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 16 / 63

slide-29
SLIDE 29

Another Model

The way these are normally represented for computer science purposes are with a matrix. You can also call it an array or table if that makes more sense in your context. The most natural choice for this problem is an incidence matrix or table. We label the rows and columns with the people, and if they know each

  • ther, we put a 1 where their boxes cross. Otherwise we put a 0. Here’s

how we could represent the last diagram we were looking at. A B C D E F A 1 B 1 1 1 C 1 1 D 1 E 1 F

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 17 / 63

slide-30
SLIDE 30

A Useful Calculation

Definition

If n is an integer, we write the factorial of n as n! and define it to be n! = n × (n − 1) × (n − 2) . . . 3 × 2 × 1.

Definition

If n and m are integers, we write n choose m as n

m

  • and define it to be

n

m

  • =

n! m!(n−m)!.

If we want to choose six of the fifteen possible places to put a 1 in our matrix, we can calculate the number of ways to do that by 15

6

  • = 15!

6!9! = 1307674368000 261273600

= 5005

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 18 / 63

slide-31
SLIDE 31

“Be wise, and generalize”

  • Dr. Gary Mullen, of Penn State often quotes

his supervisor, 45 years ago, who gave him the mantra “be wise, and generalize”. How do we generalize our friends-and-strangers problem? We could say 5 friends and 6 strangers, or any pair of numbers we want. Let’s call them m and n, or as is traditional in this problem, red and blue. The problem then becomes, how many people do we need to invite to our party, to ensure that there aren’t either m friends or n strangers? The number for each pair is known as the Ramsey number for that pair. In this terminology, we’ve been talking about the fact that R(3, 3) = 6.

photo: http://science.psu.edu/alumni/recent-gift-announcements/faculty-gift-endows-math-professorship-1 Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 19 / 63

slide-32
SLIDE 32

Erd˝

  • s’s take on Ramsey numbers

Paul Erd˝

  • s reportedly had this to say about finding Ramsey numbers:

Suppose aliens invade the earth and threaten to obliterate it in a year’s time unless human beings can find the Ramsey number for red five and blue five. We could marshal the world’s best minds and fastest computers, and within a year we could probably calculate the value. If the aliens demanded the Ramsey number for red six and blue six, however, we would have no choice but to launch a preemptive attack.

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 20 / 63

slide-33
SLIDE 33

Warm-up: Orthogonal Arrays

Puzzle: Notice that when we read down the table, we have the pairs 00, 01, 10, and 11. Problem 1: Add another column so that when you look at the new pairs of columns that are created, you also get the same four pairs. Problem 2: How many columns can you add and keep the property? When you can’t add any more, what is stopping you? 1 1 1 1

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 21 / 63

slide-34
SLIDE 34

Warm-up: Orthogonal Arrays

As before, ‘why?’ is a more interesting question than the actual answer to the puzzle. Problem 1: Add another column so that when you look at the new pairs of columns that are created, you also get the same four pairs. Problem 2: How many columns can you add and keep the property? When you can’t add any more, what is stopping you? 1 1 1 1 1 1

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 22 / 63

slide-35
SLIDE 35

Formal definitions

Definition

An orthogonal array, denoted OAλ(st; k, s, t), is an st × k array on s symbols such that in every N × t subarray, each t-tuple of symbols occurs in exactly λ rows. t is the strength, k the number of factors, λ the index, and s the number of symbols.

Definition

A covering array, denoted CAλ(N; k, s, t), is an N × k array on s symbols such that in every N × t subarray, each t-tuple of symbols occurs in at least λ rows. t is the strength, k the number of factors, λ the index, and s the number of symbols.

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 23 / 63

slide-36
SLIDE 36

An example and application

An exhaustive testing of the factors shown below would be 24 = 16 tests, but by following this covering array, all pair-wise interactions can be tested in just 5 tests. Web Server Database JDBC Driver Directory Server Test 1 IBM HTTP DB2 IBM Tivoli Test 2 IBM HTTP Oracle Oracle MS Active Directory Test 3 Microsoft IIS DB2 Oracle MS Active Directory Test 4 Microsoft IIS Oracle IBM MS Active Directory Test 5 Microsoft IIS Oracle Oracle Tivoli

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 24 / 63

slide-37
SLIDE 37

A bigger example from industry

5 Operating Systems × 4 Application Servers × 8 Web Servers × 6 Databases × 3 JDBC drivers × 2 Network Servers × 9 Directory Servers × 9 Browsers = 466 560 test beds ≡ a massive headache

www.ibm.com/support/knowledgecenter Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 25 / 63

slide-38
SLIDE 38

Let’s Program!

Tools I use daily: Sage Math

◮ Browser front-end to a server back-end. ◮ Collaborative work with other researchers through the browser. ◮ Can access the back-end through my computer or iPad. ◮ Can play around directly in the iPad app. ◮ Python syntax with extra functionality for common high-level math

  • functions. (e.g. finite fields, can multiply polynomials)

◮ Vibrant open-source community with helpful experts on StackOverflow.

Python 3.5 with the Spyder IDE

◮ Has the numpy extension for matrices - which I rarely use. ◮ Has the itertools extension, which has combinatorics functions built in. ◮ Seems particularly well-suited to discrete math.

Excel (for analyzing results)

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 26 / 63

slide-39
SLIDE 39

The Basic Backtracking Algorithm

def search_object(temp_object, i): if i == final_size and object_props_met(temp_object): print(temp_object) else: for piece in generate_pieces(temp_object): new_object = temp_object[:] new_object.append(piece) if object_props_met(new_object): search_object(new_object, i+1) search_object([], 0)

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 27 / 63

slide-40
SLIDE 40

Deciding on a data structure

Transpose the array, so we are looking at pairs of rows instead of columns. 1 1 1 1 1 1 Turn it into a list of lists in Python. Now our ‘pieces’ are rows, and our final size is 3. [[0, 0, 1, 1], [0, 1, 0, 1], [1, 0, 0, 1]]

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 28 / 63

slide-41
SLIDE 41

The actual code

import itertools def search_CA(temp_array, i): if i == 3 and is_CA(temp_array): print(temp_array) else: for column in itertools.permutations([0, 0, 1, 1]): new_array = temp_array[:] new_array.append(column) if is_CA(new_array): search_CA(new_array, i+1) search_CA([], 0)

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 29 / 63

slide-42
SLIDE 42

Is it a CA?

We check the length of the array, since this subroutine needs to accept all partial solutions. Notice that the return of False takes place as soon as we find a failure, rather than waiting until the end. def is_CA(array): k = len(array) for t_set in itertools.combinations(range(k), 2): if not is_t_set_covered(array, t_set): return False return True

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 30 / 63

slide-43
SLIDE 43

What I actually write

import doctest # Top of program # ------------------------------------------------------ def is_CA(array): # ------------------------------------------------------ ’’’ >>> is_CA([[0,0,1,1],[0,1,0,1]]) True ’’’ k = len(array) for t_set in itertools.combinations(range(k), 2): if not is_t_set_covered(array, t_set): return False return True doctest.mod() # Just before the main body

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 31 / 63

slide-44
SLIDE 44

Is the t set covered?

We don’t actually need to care what the sets of symbols are - we just need to know if there are the right number. Using the built-in Python notion of a set automatically makes sure there are no duplicates in the set. def is_t_set_covered(array, t_set): row_set = set() for j in range(0, 3): row_set.add((array[t_set[0]][j], array[t_set[1]][j])) if len(row_set) == 3: return True else: return False

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 32 / 63

slide-45
SLIDE 45

First Set of Results, and Fixes

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 33 / 63

slide-46
SLIDE 46

Global variables - Counting results

def search_CA(temp_array, i): global number_found global branches if i == 3 and is_CA(temp_array): print(temp_array) number_found = number_found + 1 branches = branches + 1 else: branches = branches + 1 number_found = 0 branches = 0 search_CA([], 0) print(’number_found is: ’, number_found) print(’branches are: ’, branches)

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 34 / 63

slide-47
SLIDE 47

Pet Peeve

Problem: We are getting four times as many results as we should; the number found is 3072, with 3481 branches. Reason: itertools.combinations treats the two 0 symbols and two 1 symbols as distinct. Work-around: list(set(itertools.permutations([0, 0, 1, 1]))) Now we get 48 results, with 79 branches, which makes more sense.

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 35 / 63

slide-48
SLIDE 48

First round of isomorphism checking

The first tool to use is your eyes. Here are 16 of the 48 results. [(0, 1, 0, 1), (1, 1, 0, 0), (1, 0, 0, 1)] [(0, 1, 0, 1), (1, 1, 0, 0), (0, 1, 1, 0)] [(0, 1, 0, 1), (1, 0, 0, 1), (1, 1, 0, 0)] [(0, 1, 0, 1), (1, 0, 0, 1), (0, 0, 1, 1)] [(0, 1, 0, 1), (0, 1, 1, 0), (1, 1, 0, 0)] [(0, 1, 0, 1), (0, 1, 1, 0), (0, 0, 1, 1)] [(0, 1, 0, 1), (0, 0, 1, 1), (1, 0, 0, 1)] [(0, 1, 0, 1), (0, 0, 1, 1), (0, 1, 1, 0)] [(0, 0, 1, 1), (1, 0, 1, 0), (1, 0, 0, 1)] [(0, 0, 1, 1), (1, 0, 1, 0), (0, 1, 1, 0)] [(0, 0, 1, 1), (1, 0, 0, 1), (1, 0, 1, 0)] [(0, 0, 1, 1), (1, 0, 0, 1), (0, 1, 0, 1)] [(0, 0, 1, 1), (0, 1, 1, 0), (1, 0, 1, 0)] [(0, 0, 1, 1), (0, 1, 1, 0), (0, 1, 0, 1)] [(0, 0, 1, 1), (0, 1, 0, 1), (1, 0, 0, 1)] [(0, 0, 1, 1), (0, 1, 0, 1), (0, 1, 1, 0)]

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 36 / 63

slide-49
SLIDE 49

Non-isomorphic generation

search_CA([], 0) Becomes... search_CA([(0, 0, 1, 1)], 1) [(0, 0, 1, 1), (1, 0, 1, 0), (1, 0, 0, 1)] [(0, 0, 1, 1), (1, 0, 1, 0), (0, 1, 1, 0)] [(0, 0, 1, 1), (1, 0, 0, 1), (1, 0, 1, 0)] [(0, 0, 1, 1), (1, 0, 0, 1), (0, 1, 0, 1)] [(0, 0, 1, 1), (0, 1, 1, 0), (1, 0, 1, 0)] [(0, 0, 1, 1), (0, 1, 1, 0), (0, 1, 0, 1)] [(0, 0, 1, 1), (0, 1, 0, 1), (1, 0, 0, 1)] [(0, 0, 1, 1), (0, 1, 0, 1), (0, 1, 1, 0)] number_found is: 8 branches are: 13

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 37 / 63

slide-50
SLIDE 50

Non-isomorphic generation

if i == 3 and is_CA(temp_array): Becomes... if i == 3 and is_CA(temp_array): if temp_array[1] < temp_array[2]: With these results: [(0, 0, 1, 1), (1, 0, 0, 1), (1, 0, 1, 0)] [(0, 0, 1, 1), (0, 1, 1, 0), (1, 0, 1, 0)] [(0, 0, 1, 1), (0, 1, 0, 1), (1, 0, 0, 1)] [(0, 0, 1, 1), (0, 1, 0, 1), (0, 1, 1, 0)] number_found is: 4 branches are: 13

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 38 / 63

slide-51
SLIDE 51

Modification of Parameters

What if we want four rows instead of three? if i == 3 and is_CA(temp_array): Becomes... if i == 4 and is_CA(temp_array): With these results: number_found is: branches are: 13

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 39 / 63

slide-52
SLIDE 52

Modification of Parameters

What if we want five entries in each row, instead of four? column in list(set(itertools.permutations([0, 0, 1, 1]))): for j in range(0, 4): search_CA([(0, 0 1, 1)], 1) Becomes... column in list(set(itertools.permutations([0, 0, 0, 1, 1]))): for j in range(0, 5): search_CA([(0, 0, 0, 1, 1)], 1) With these results: number_found is: 9 branches are: 31

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 40 / 63

slide-53
SLIDE 53

Ease of Use

Reasons I love my job... no user testing! No error checking! But still... ease of use is still important, for efficiency’s sake. At this point I would make these modifications: if i == how_big and is_CA(temp_array): for column in list(set(itertools.permutations(base_row))): how_big = 8 base_row = (0, 0, 0, 1, 1, 1) search_CA([base_row], 1)

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 41 / 63

slide-54
SLIDE 54

Tracking Run Time

from time import time # top of program start_time = time() # before main body search_CA([base_row], 1) end_time = time() # after main body print(‘in: ’, end_time - start_time, ‘seconds.’)

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 42 / 63

slide-55
SLIDE 55

Running Time, and Combinatorial Explosion

Number Found and Running Time for numbers of entries and rows 4 entries 5 entries 6 entries 3 rows 4 in 0.0009s 18 in 0.0009s 288 in 0.017s 4 rows 0 in 0.001s 12 in 0.003s 4032 in 0.3s 5 rows n/a 0 in 0.004s 48384 in 4.7s 6 rows n/a 483840 in 63s 7 rows 3870720 in 746s

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 43 / 63

slide-56
SLIDE 56

Combinations to test

How many possible rows are there? [0, 0, 1, 1] choose 2 of 4 = 6 rows [0, 0, 0, 1, 1] choose 2 of 5 = 10 rows [0, 0, 0, 1, 1, 1] choose 3 of 6 = 20 rows [0, 0, 0, 0, 1, 1, 1] choose 3 of 7 = 35 rows [0, 0, 0, · · · ] 100

50

  • = 1 × 1029

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 44 / 63

slide-57
SLIDE 57

Improvements

Compare these three: [(0, 0, 1, 1), (1, 0, 0, 1), (1, 0, 1, 0)] [(0, 0, 1, 1), (0, 1, 0, 1), (1, 0, 0, 1)] [(0, 0, 1, 1), (0, 1, 0, 1), (0, 1, 1, 0)] Perhaps easier in matrix form: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ‘The simplest thing that could possibly work’?

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 45 / 63

slide-58
SLIDE 58

Improvement 1

We add a simple test: for column in list(set(itertools.permutations(base_row))): if column[0] == 0: new_array = temp_array[:] new_array.append(column) if is_CA(new_array): search_CA(new_array, i+1)

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 46 / 63

slide-59
SLIDE 59

Running Time (Improvement 1)

Number Found and Running Time for numbers of entries and rows 4 entries 5 entries 6 entries 3 rows 2 in 0.0s 18 in 0.0009s 72 in 0.006s 4 rows 0 in 0.0s 12 in 0.003s 504 in 0.05s 5 rows n/a 0 in 0.004s 3024 in 0.37s 6 rows n/a 15120 in 3.1s 7 rows 60480 in 16s 8 rows 181440 in 64s

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 47 / 63

slide-60
SLIDE 60

Improvement 2

Examine this code: def is_CA(array): k = len(array) for t_set in itertools.combinations(range(k), 2): if not is_t_set_covered(array, t_set): return False return True When we get to 9 rows, we are doing 9

2

  • = 36 tests, when we only need

to do 8 (the new row compared to all the previous rows).

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 48 / 63

slide-61
SLIDE 61

Improvement 2 - New Code

Examine this code: def is_CA(array): k = len(array) # for t_set in itertools.combinations(range(k), 2): # if not is_t_set_covered(array, t_set): for existing_row in range(0, k-1): if not is_t_set_covered(array, [existing_row, k-1]): return False return True

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 49 / 63

slide-62
SLIDE 62

Running Time (Improvement 2)

Number Found and Running Time for numbers of entries and rows 4 entries 5 entries 6 entries 7 entries 3 rows 2 in 0.0s 18 in 0.0009s 72 in 0.002s 762 in 0.069s 4 rows 0 in 0.0s 12 in 0.005s 504 in 0.02s 16152 in 1.27s 5 rows n/a 0 in 0.004s 3024 in 0.23s 280944 in 20.4s 6 rows n/a 15120 in 1.44s 3932640 in 367s 7 rows 60480 in 7s 43323120 in 5127s 8 rows 181440 in 25s 9 rows 362880 in 76s 10 rows 362880 in 159s 11 rows 0 in 212s

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 50 / 63

slide-63
SLIDE 63

Enumeration vs. Existence

There are two fundamental problems in discrete mathematics, when considering these combinatorial objects. Existence: either find an example, or prove none exists. Enumeration: how many unique objects exist, given an isomorphism?

  • Dr. Lucia Moura is a professor of

Computer Science at the University

  • f Ottawa. The previous examples

were all inspired by her graduate course, “Applications of Combinatorial Designs in Computer Science”.

photo: http://www.site.uottawa.ca/~lucia/ Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 51 / 63

slide-64
SLIDE 64

Enumeration vs. Existence Timing Comparison

It seems clear that finding one example will be far quicker than finding all

  • f them.

Let’s take the covering array with 6 entries as an example. enumerate existence 3 rows 72 in 0.002s 1 in 0.0s 4 rows 504 in 0.02s 1 in 0.002s 5 rows 3024 in 0.23s 1 in 0.000999s 6 rows 15120 in 1.44s 1 in 0.0s 7 rows 60480 in 7s 1 in 0.003s 8 rows 181440 in 25s 1 in 0.001s 9 rows 362880 in 76s 1 in 0.002s 10 rows 362880 in 159s 1 in 0.003s 11 rows 0 in 212s 0 in 199s

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 52 / 63

slide-65
SLIDE 65

Moar Symbols!!!

To actually go off the beaten path, we need to make one last adjustment. That’s to bump up the number of symbols from 2 to 3. Instead of 0s and 1s, then, we’re going to add 2s to the mix as well. Fortunately, we designed our program well, and only two changes need to be made. if len(row_set) == 9: base_row = (0, 0, 0, 1, 1, 1, 2, 2, 2)

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 53 / 63

slide-66
SLIDE 66

Results for v=3

The table shows existence results only (no enumeration). 9 entries 10 entries 11 entries 12 entries 13 entries 3 rows 0.124s 0.95s 8.7595s 102s 1414s 4 rows 0.178s 1.335s 13.69s 157s 1966s 5 rows (35s) (25745s) 21.32s 221s 2556s 6 rows DNE 364s 7 rows 2520s 8 rows DNE 9 rows 10 rows 11 rows

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 54 / 63

slide-67
SLIDE 67

A little light math

Can we do a little math to show why this grows the way it does? Possible rows for numbers of entries, and then that number choose 4: 9 entries 9

3

  • ×

6

3

  • = 1680

7937523004320 10 entries 10

4

  • ×

6

3

  • = 4200

310725266014800 11 entries 11

4

  • ×

7

4

  • = 11550

17786983680358200 12 entries 12

4

  • ×

8

4

  • = 34650

1441244791295140000 13 entries 13

5

  • ×

8

4

  • = 90090

65868446876657000000

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 55 / 63

slide-68
SLIDE 68

Python Generators

Remember this little gem? for column in list(set(itertools.permutations(base_row))): This builds the whole list in memory, which is going to cause us problems sooner rather than later. The solution is a Python generator, which generates elements individually as needed, rather than in one list. 2 def firstn(n): 3 num, nums = 0, [] 4 while num < n: 5 nums.append(num) 6 num += 1 7 return nums 2 def firstn(n): 3 num = 0 4 while num < n: 5 yield num 6 num += 1

From: https://wiki.python.org/moin/Generators Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 56 / 63

slide-69
SLIDE 69

Ongoing Research

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 57 / 63

slide-70
SLIDE 70

One Last Programming Note

import winsound Freq = 2500 # Set Frequency To 2500 Hertz Dur = 1000 # Set Duration To 1000 ms == 1 second winsound.Beep(Freq,Dur)

From: https://stackoverflow.com/questions/6537481/python-making-a-beep-noise Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 58 / 63

slide-71
SLIDE 71

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 59 / 63

slide-72
SLIDE 72

Kirkman’s Schoolgirl Problem

Anna, Bertha, Clara; Dora, Ethel, Florence; Gertrude, Hattie, Ida; Jennie, Lillie, Minnie; Nellie, Olive, Pearl What are our constraints? Clear: the number of girls needs to be divisible by the number in each group. Less clear: What about the pairs? 15 choose 2 is 105. Each group of three accounts for three pairs, and there are five groups, so each day accounts for 15 pairs. 105/15= 7, so in 7 days we should see all the pairs.

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 60 / 63

slide-73
SLIDE 73

A smaller version

Arrange seven students in presentation groups of three, so that each pair

  • f students occurs exactly once.

Andy, Bobby, Charlie Andy, Don, Edie Andy, Frank, Gary Bobby, Don, Frank Bobby, Edie, Gary Charlie, Don, Gary Charlie, Edie, Frank We don’t have the nice property that all seven students can be assigned to a group at once, but over the course of seven classes/weeks/months, every student works with every other student exactly once. This is called a Steiner Triple System, after the second person to find a solution to Kirkman’s query. The “triple” part of the name comes from the fact that we always combine the items into groups of three. The example above is an STS(7). If we generalize the group size and the number of times a pair should appear, we get a Balanced Incomplete Block Design, or BIBD.

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 61 / 63

slide-74
SLIDE 74

Kirkman’s Schoolgirl Problem: Solution

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 62 / 63

slide-75
SLIDE 75

Thank You! Remember... kirsten.nelson@carleton.ca

Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 63 / 63