lessons from discrete mathematics -...

75
Lessons from Discrete Mathematics Kirsten Nelson Carleton University October 14, 2017 Contact: [email protected] Kirsten Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 1 / 63

Upload: phungdan

Post on 30-Mar-2018

216 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Lessons from Discrete Mathematics

Kirsten Nelson

Carleton University

October 14, 2017

Contact: [email protected] Nelson (Carleton University) Lessons from Discrete Mathematics October 14, 2017 1 / 63

Page 2: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

1 IntroductionBiographyDiscrete vs. Discreet, and vs. Continuous

2 Ramsey NumbersModeling and Graph TheoryIsomorphismFactorials and ‘choose’

3 Covering ArraysOrthogonal ArraysExample and ApplicationProgramming ToolsBacktracking AlgorithmData Structures

4 Kirkman’s Schoolgirl Problem

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

Page 3: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A Short Bio

Cool things I’ve been able to do:

Programmer

I Netron - small software company, mostly business applicationsI IBM - data mining software for WebSphere CommerceI Intelliware - small programming-for-hire company

Teacher

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

Math, Grades 7 to 12I Independent Learning Centre, Homework Help, TVO

Mathematician

I B. Math, C&O/PM from the University of WaterlooI MMT from Waterloo, 2016I M. Sc. in Discrete Mathematics from Carleton, 2018 (hopefully)I PhD???

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

Page 4: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A Short Bio

Cool things I’ve been able to do:

Programmer

I Netron - small software company, mostly business applicationsI IBM - data mining software for WebSphere CommerceI Intelliware - small programming-for-hire company

Teacher

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

Math, Grades 7 to 12I Independent Learning Centre, Homework Help, TVO

MathematicianI B. Math, C&O/PM from the University of Waterloo

I MMT from Waterloo, 2016I M. Sc. in Discrete Mathematics from Carleton, 2018 (hopefully)I PhD???

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

Page 5: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A Short Bio

Cool things I’ve been able to do:

Programmer

I Netron - small software company, mostly business applicationsI IBM - data mining software for WebSphere CommerceI Intelliware - small programming-for-hire company

Teacher

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

Math, Grades 7 to 12I Independent Learning Centre, Homework Help, TVO

MathematicianI B. Math, C&O/PM from the University of Waterloo

I MMT from Waterloo, 2016I M. Sc. in Discrete Mathematics from Carleton, 2018 (hopefully)I PhD???

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

Page 6: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A Short Bio

Cool things I’ve been able to do:

ProgrammerI Netron - small software company, mostly business applications

I IBM - data mining software for WebSphere CommerceI Intelliware - small programming-for-hire company

Teacher

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

Math, Grades 7 to 12I Independent Learning Centre, Homework Help, TVO

MathematicianI B. Math, C&O/PM from the University of Waterloo

I MMT from Waterloo, 2016I M. Sc. in Discrete Mathematics from Carleton, 2018 (hopefully)I PhD???

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

Page 7: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A Short Bio

Cool things I’ve been able to do:

ProgrammerI Netron - small software company, mostly business applicationsI IBM - data mining software for WebSphere Commerce

I Intelliware - small programming-for-hire company

Teacher

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

Math, Grades 7 to 12I Independent Learning Centre, Homework Help, TVO

MathematicianI B. Math, C&O/PM from the University of Waterloo

I MMT from Waterloo, 2016I M. Sc. in Discrete Mathematics from Carleton, 2018 (hopefully)I PhD???

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

Page 8: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A Short Bio

Cool things I’ve been able to do:

ProgrammerI Netron - small software company, mostly business applicationsI IBM - data mining software for WebSphere CommerceI Intelliware - small programming-for-hire company

Teacher

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

Math, Grades 7 to 12I Independent Learning Centre, Homework Help, TVO

MathematicianI B. Math, C&O/PM from the University of Waterloo

I MMT from Waterloo, 2016I M. Sc. in Discrete Mathematics from Carleton, 2018 (hopefully)I PhD???

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

Page 9: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A Short Bio

Cool things I’ve been able to do:

ProgrammerI Netron - small software company, mostly business applicationsI IBM - data mining software for WebSphere CommerceI Intelliware - small programming-for-hire company

Teacher

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

Math, Grades 7 to 12I Independent Learning Centre, Homework Help, TVO

MathematicianI B. Math, C&O/PM from the University of Waterloo

I MMT from Waterloo, 2016I M. Sc. in Discrete Mathematics from Carleton, 2018 (hopefully)I PhD???

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

Page 10: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A Short Bio

Cool things I’ve been able to do:

ProgrammerI Netron - small software company, mostly business applicationsI IBM - data mining software for WebSphere CommerceI Intelliware - small programming-for-hire company

TeacherI B. Ed. from York University

I Bishop Strachan School and University of Toronto Schools - CS andMath, Grades 7 to 12

I Independent Learning Centre, Homework Help, TVO

MathematicianI B. Math, C&O/PM from the University of Waterloo

I MMT from Waterloo, 2016I M. Sc. in Discrete Mathematics from Carleton, 2018 (hopefully)I PhD???

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

Page 11: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A Short Bio

Cool things I’ve been able to do:

ProgrammerI Netron - small software company, mostly business applicationsI IBM - data mining software for WebSphere CommerceI Intelliware - small programming-for-hire company

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

Math, Grades 7 to 12

I Independent Learning Centre, Homework Help, TVO

MathematicianI B. Math, C&O/PM from the University of Waterloo

I MMT from Waterloo, 2016I M. Sc. in Discrete Mathematics from Carleton, 2018 (hopefully)I PhD???

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

Page 12: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A Short Bio

Cool things I’ve been able to do:

ProgrammerI Netron - small software company, mostly business applicationsI IBM - data mining software for WebSphere CommerceI Intelliware - small programming-for-hire company

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

Math, Grades 7 to 12I Independent Learning Centre, Homework Help, TVO

MathematicianI B. Math, C&O/PM from the University of Waterloo

I MMT from Waterloo, 2016I M. Sc. in Discrete Mathematics from Carleton, 2018 (hopefully)I PhD???

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

Page 13: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A Short Bio

Cool things I’ve been able to do:

ProgrammerI Netron - small software company, mostly business applicationsI IBM - data mining software for WebSphere CommerceI Intelliware - small programming-for-hire company

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

Math, Grades 7 to 12I Independent Learning Centre, Homework Help, TVO

MathematicianI B. Math, C&O/PM from the University of WaterlooI MMT from Waterloo, 2016

I M. Sc. in Discrete Mathematics from Carleton, 2018 (hopefully)I PhD???

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

Page 14: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A Short Bio

Cool things I’ve been able to do:

ProgrammerI Netron - small software company, mostly business applicationsI IBM - data mining software for WebSphere CommerceI Intelliware - small programming-for-hire company

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

Math, Grades 7 to 12I Independent Learning Centre, Homework Help, TVO

MathematicianI B. Math, C&O/PM from the University of WaterlooI MMT from Waterloo, 2016I M. Sc. in Discrete Mathematics from Carleton, 2018 (hopefully)

I PhD???

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

Page 15: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A Short Bio

Cool things I’ve been able to do:

ProgrammerI Netron - small software company, mostly business applicationsI IBM - data mining software for WebSphere CommerceI Intelliware - small programming-for-hire company

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

Math, Grades 7 to 12I Independent Learning Centre, Homework Help, TVO

MathematicianI B. Math, C&O/PM from the University of WaterlooI MMT from Waterloo, 2016I M. Sc. in Discrete Mathematics from Carleton, 2018 (hopefully)I PhD???

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

Page 16: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

diagram courtesy of Math by Tori, at kelsoemath.blogspot.ca

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

Page 17: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Learning through Wikipedia?

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

Page 18: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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

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

Page 19: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A More Intuitive Description

In any group of six people, there are either three people that know eachother, or three people that don’t know each other.

Knowing someone is symmetric; if Anthony know Betty, then Bettymust know Anthony

Obvious group-work opportunity

“Why?” is the interesting question

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

Page 20: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Modeling with Graphs

In the sense I’ll be talking about today, a graph is a series of points andlines.

The points are formally known as vertices (singular vertex), andrepresent any discrete set of things.

The lines are formally known as edges, and represent relationshipsbetween the things.

Common examples include computer networks, with computers joinedby cables; cities joined by roads; and airports joined by flights.

In this case we’ll be representing the people by points and therelationships by lines. If two people know each other, we’ll join themwith a line.

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

Page 21: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Modeling the Problem

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

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

Page 22: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

“Without loss of generality...”

We love to throw around the term “without loss of generality”, oftenshorted to simply “w.l.o.g.”.In this case we use it to argue that we can choose A-B as our firstconnection. You could choose any one of 15 lines to start with (why it’s15 is an interesting thought exercise). No matter which line you pick, youcan relabel the vertices so that A and B are the ends of the line. This is anatural way to introduce the notion of isomorphism.Whether two things are the same or not is a pretty tricky question, and itall depends on your definition. We like things to be cut and dried, soinstead of saying things are the same, we say that they’re isomorphicunder some operation. That makes it objective; if we agree on theoperation, we (usually) agree on whether two things are isomorphic.

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

Page 23: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Back to the modelWe connect A and B, then consider our next move.

A little thought will show you that there are two unique choices next. Wecan either draw our new line so that it connects with the previous line, orso that it doesn’t. If we choose the first possible letters for each, we endup 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

Page 24: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Continuing the Single Line

A little playing around shows there are four possible next steps in the firstoption above. You can consider it as three choices; either connect the lineinto a triangle, connect a new person to the existing group, or choose acompletely new line.

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

Page 25: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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 existinglines.

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

Page 26: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Two Things to Notice

As soon as we create a triangle, we have three people who know eachother. So we reject any graph that has a triangle, and focus on the otheroptions.

These two graphs are isomorphic under our operation, which is a relabelingof the points. So although we can think of a tree to organize these stepsin, 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

Page 27: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Eliminating CasesKnowing that we want to avoid triangles is helpful, because we canautomatically 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’tknow each other now?

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

Page 28: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Eliminating CasesKnowing that we want to avoid triangles is helpful, because we canautomatically 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’tknow each other now?

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

Page 29: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Another Model

The way these are normally represented for computer science purposes arewith a matrix. You can also call it an array or table if that makes moresense 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 eachother, we put a 1 where their boxes cross. Otherwise we put a 0. Here’show we could represent the last diagram we were looking at.

A B C D E F

A 0 1 0 0 0 0

B 1 0 1 0 1 0

C 0 1 0 1 0 0

D 0 0 1 0 0 0

E 0 1 0 0 0 0

F 0 0 0 0 0 0

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

Page 30: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A Useful Calculation

Definition

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

Definition

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

)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 ourmatrix, we can calculate the number of ways to do that by(156

)= 15!

6!9! = 1307674368000261273600 = 5005

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

Page 31: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

“Be wise, and generalize”

Dr. Gary Mullen, of Penn State often quoteshis supervisor, 45 years ago, who gave himthe mantra “be wise, and generalize”. Howdo we generalize our friends-and-strangersproblem? We could say 5 friends and 6strangers, or any pair of numbers we want.Let’s call them m and n, or as is traditionalin this problem, red and blue.

The problem then becomes, how many people do we need to invite to ourparty, to ensure that there aren’t either m friends or n strangers? Thenumber for each pair is known as the Ramsey number for that pair. In thisterminology, 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

Page 32: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Erdos’s take on Ramsey numbers

Paul Erdos reportedly had this to say about finding Ramsey numbers:

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

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

Page 33: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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 ofcolumns that are created, you also get the same four pairs.

Problem 2: How many columns can you add and keep the property? Whenyou can’t add any more, what is stopping you?

0 0

0 1

1 0

1 1

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

Page 34: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Warm-up: Orthogonal Arrays

As before, ‘why?’ is a more interesting question than the actual answer tothe puzzle.

Problem 1: Add another column so that when you look at the new pairs ofcolumns that are created, you also get the same four pairs.

Problem 2: How many columns can you add and keep the property? Whenyou can’t add any more, what is stopping you?

0 0 1

0 1 0

1 0 0

1 1 1

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

Page 35: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Formal definitions

Definition

An orthogonal array, denoted OAλ(st ; k , s, t), is an st × k array on ssymbols such that in every N × t subarray, each t-tuple of symbols occursin 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 symbolssuch that in every N × t subarray, each t-tuple of symbols occurs in atleast λ rows. t is the strength, k the number of factors, λ the index, and sthe number of symbols.

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

Page 36: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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 testedin just 5 tests.

Web Server Database JDBC Driver Directory Server

Test 1 IBM HTTP DB2 IBM TivoliTest 2 IBM HTTP Oracle Oracle MS Active DirectoryTest 3 Microsoft IIS DB2 Oracle MS Active DirectoryTest 4 Microsoft IIS Oracle IBM MS Active DirectoryTest 5 Microsoft IIS Oracle Oracle Tivoli

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

Page 37: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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

Page 38: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Let’s Program!

Tools I use daily:

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

functions. (e.g. finite fields, can multiply polynomials)I Vibrant open-source community with helpful experts on StackOverflow.

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

Excel (for analyzing results)

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

Page 39: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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

Page 40: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Deciding on a data structure

Transpose the array, so we are looking at pairs of rows instead of columns.

0 0 1 1

0 1 0 1

1 0 0 1

Turn it into a list of lists in Python. Now our ‘pieces’ are rows, and ourfinal 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

Page 41: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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

Page 42: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Is it a CA?

We check the length of the array, since this subroutine needs toaccept all partial solutions.

Notice that the return of False takes place as soon as we find afailure, 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

Page 43: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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

Page 44: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Is the t set covered?

We don’t actually need to care what the sets of symbols are - we justneed to know if there are the right number.

Using the built-in Python notion of a set automatically makes surethere 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

Page 45: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

First Set of Results, and Fixes

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

Page 46: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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

Page 47: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Pet Peeve

Problem: We are getting four times as many results as we should; thenumber found is 3072, with 3481 branches.

Reason: itertools.combinations treats the two 0 symbols and two 1symbols 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

Page 48: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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

Page 49: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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

Page 50: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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

Page 51: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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: 0

branches are: 13

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

Page 52: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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

Page 53: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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 pointI 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

Page 54: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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

Page 55: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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.017s4 rows 0 in 0.001s 12 in 0.003s 4032 in 0.3s5 rows n/a 0 in 0.004s 48384 in 4.7s6 rows n/a 483840 in 63s7 rows 3870720 in 746s

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

Page 56: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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, · · · ](10050

)= 1 × 1029

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

Page 57: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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:0 0 1 11 0 0 11 0 1 0

0 0 1 10 1 0 11 0 0 1

0 0 1 10 1 0 10 1 1 0

‘The simplest thing that could possibly work’?

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

Page 58: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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

Page 59: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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.006s4 rows 0 in 0.0s 12 in 0.003s 504 in 0.05s5 rows n/a 0 in 0.004s 3024 in 0.37s6 rows n/a 15120 in 3.1s7 rows 60480 in 16s8 rows 181440 in 64s

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

Page 60: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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(92

)= 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

Page 61: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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

Page 62: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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.069s4 rows 0 in 0.0s 12 in 0.005s 504 in 0.02s 16152 in 1.27s5 rows n/a 0 in 0.004s 3024 in 0.23s 280944 in 20.4s6 rows n/a 15120 in 1.44s 3932640 in 367s7 rows 60480 in 7s 43323120 in 5127s8 rows 181440 in 25s9 rows 362880 in 76s

10 rows 362880 in 159s11 rows 0 in 212s

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

Page 63: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Enumeration vs. Existence

There are two fundamental problems in discrete mathematics, whenconsidering 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 ofComputer Science at the Universityof Ottawa. The previous exampleswere all inspired by her graduatecourse, “Applications ofCombinatorial Designs in ComputerScience”.

photo: http://www.site.uottawa.ca/~lucia/

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

Page 64: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Enumeration vs. Existence Timing Comparison

It seems clear that finding one example will be far quicker than finding allof them.Let’s take the covering array with 6 entries as an example.

enumerate existence

3 rows 72 in 0.002s 1 in 0.0s4 rows 504 in 0.02s 1 in 0.002s5 rows 3024 in 0.23s 1 in 0.000999s6 rows 15120 in 1.44s 1 in 0.0s7 rows 60480 in 7s 1 in 0.003s8 rows 181440 in 25s 1 in 0.001s9 rows 362880 in 76s 1 in 0.002s

10 rows 362880 in 159s 1 in 0.003s11 rows 0 in 212s 0 in 199s

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

Page 65: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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 and1s, then, we’re going to add 2s to the mix as well.Fortunately, we designed our program well, and only two changes need tobe 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

Page 66: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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 1414s4 rows 0.178s 1.335s 13.69s 157s 1966s5 rows (35s) (25745s) 21.32s 221s 2556s6 rows DNE 364s7 rows 2520s8 rows DNE9 rows

10 rows11 rows

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

Page 67: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A little light math

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

9 entries(93

)×(63

)= 1680 7937523004320

10 entries(104

(63

)= 4200 310725266014800

11 entries(114

)×(74

)= 11550 17786983680358200

12 entries(124

)×(84

)= 34650 1441244791295140000

13 entries(135

)×(84

)= 90090 65868446876657000000

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

Page 68: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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 problemssooner rather than later. The solution is a Python generator, whichgenerates 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

Page 69: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Ongoing Research

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

Page 70: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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

Page 71: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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

Page 72: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

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 eachgroup.

Less clear: What about the pairs? 15 choose 2 is 105. Each group ofthree accounts for three pairs, and there are five groups, so each dayaccounts for 15 pairs. 105/15= 7, so in 7 days we should see all thepairs.

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

Page 73: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

A smaller version

Arrange seven students in presentation groups of three, so that each pairof students occurs exactly once.

Andy, Bobby, Charlie Andy, Don, Edie Andy, Frank, GaryBobby, Don, Frank Bobby, Edie, Gary Charlie, Don, GaryCharlie, Edie, Frank

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

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

Page 74: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Kirkman’s Schoolgirl Problem: Solution

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

Page 75: Lessons from Discrete Mathematics - CEMCcemc.uwaterloo.ca/events/flomas-presentation/KirstenNelson.pdf · I IBM - data mining software for WebSphere Commerce I Intelliware ... Kirsten

Thank You! Remember... [email protected]

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