29
snick snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Snick snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Embed Size (px)

DESCRIPTION

More Introductions Introduce yourselves… how?

Citation preview

Page 1: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

snick

snack

CPSC 121: Models of Computation2008/9 Winter Term 2

Introduction & Motivation

Steve Wolfman, based on notes by Patrice Belleville and others

Page 2: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Introductions

Steven Wolfman (call me Steve!)[email protected] 239; office hours (tentatively):Mon-Wed 11:30-12:30, Thu 2-4

but I have an open door policy:If my door is open, come in and talk!Also, I will usually be available after class.And, you can make appointments with me.

Page 3: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

More Introductions

Introduce yourselves… how?

Page 4: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Introduce Yourselves in Groups of 4-ish

FIND ~3 people around you, preferably people you’ve never met. Form a group.

Have everyone in the group introduce themselves to everyone else in the group. (Count the number of intros this takes.)

Tell everyone why you’re here, your favorite career that you’ll never have, and one unusual thing about you.

Page 5: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Problem: How Many Introductions?

Problem: How many introductions does it take for everyone in a group to meet everyone else in a group?

Page 6: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Concept Q: Intros for 4

How many introductions does a group of 4 people take?

a.3b.4c.6d.12e.None of these

Page 7: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Problem: How Many Introductions?

Problem: How many introductions does it take for everyone in a group to meet everyone else in a group?

To solve this problem, we need to model it more formally.

Page 8: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

How Many Introductions?

Model: One “introduction” is one person introducing themselves to another person. (So, two people need two introductions to introduce themselves to each other.)

A group has “introduced themselves” when every member of the group has introduced themselves to every other member of the group. (No self-introductions needed.)

Page 9: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

How Many Introductions?

Problem: How many introductions does it take for a group of n people to introduce themselves?

Page 10: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

How Many Introductions?

For 2 people?For 3 people?For 4 people?For 5 people?…For n people?

Page 11: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

How Many Introductions?

For 100 people?For 8675309 people?For 1526097757 people?

Page 12: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Program for Introductionsintroductions n = n * (n - 1)

(In a programming language called Haskell.)

int introductions(int n){ return n * (n - 1);}

(In the Java programming language.)

Do you believe it?

Page 13: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Program for Introductions: Testing

Java version with 100: 9900

Do you believe it?

Page 14: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Program for Introductions: Testing

Java version with 100: 9900Java version with 8675309: 265642364

Do you believe it?

Page 15: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Program for Introductions: Testing

Java version with 100: 9900Java version with 8675309: 265642364Java version with 1526097757: -645820308

Um.. Do you believe it?

Page 16: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Program for Introductions: Testing

Haskell version with 100: 9900Haskell version with 8675309: 75260977570172

Haskell version with 1526097757: 2328974362394333292

Do you believe it?

Page 17: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Questions that CPSC121 Answers

How can we prove that our formula for the number of introductions is correct? (induction)

What went wrong in our Java implementation? (number representation)

How do we model computational systems at various levels (from hardware to abstract intent) in ways that facilitate “clear thought”? (propositional and predicate logic, proof, sets, functions, DFAs, relations, ...)

Page 18: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

“Clear Thought”

Computer Science is the science of “clear thought”, but not like philosophy (or religion, or poetry, or...).

CS is the science of thoughts so clear in their expression and intent that we can realize them: execute them or test their truth in the world.

CPSC121 provides and applies the fundamentals you need to model the world with “clear thought”.

Page 19: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

What is CPSC 121 Good For?

With CPSC121’s help, you will be able to:• model important problems so that they are easier

to discuss, reason about, solve, and test.• learn new modeling formalisms more easily.• communicate clearly and unambiguously with

other CS experts on complex topics.• characterize algorithms (CS problem solutions),

such as proving their correctness or efficacy.• critically read proofs: justifying why each step is

correct and judging what the proof means.

Page 20: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

CPSC 121: Analysis & Proof

CPSC 121: Representation, Hardware, & Computation

CPSC 211: Software Design

CPSC 211: Data Structures

Where Does CPSC 121 Sit?

CPSC 111: Programming

Caveat #1: It couldn’t possibly be because we teach 121 that its box is biggest.Caveat #2: There’s a LOT more to learn on both sides after 121.

Page 21: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

What “Models of Computation” Will We Work With?

• Propositional logic, as model for the combinational circuitry at the heart of computers

• Predicate logic (and later enhanced by sets, functions, and relations), as modeling language for computational problems

• Deterministic Finite Automata and regular expressions as applications of all previous concepts and a crude but (in a sense) complete model of computation as a whole

• Circuit diagrams using both combinational and sequential circuits to model the operation of a complete computer

Page 22: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Course Administration

Explore the CPSC 121 website:http://www.ugrad.cs.ubc.ca/~cs121/

Page 23: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Next Lecture Learning Goals: Pre-Class

By the start of class, you should be able to:– Translate back and forth between simple

natural language statements and propositional logic.

– Evaluate the truth of propositional logic statements using truth tables.

– Translate back and forth between propositional logic statements and circuits that assess the truth of those statements.

Page 24: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Next Lecture Prerequisites

Read Sections 1.1 and 1.4Solve problems like Exercise Set 1.1, #1-18

and Exercise Set 1.4, #1-17.You should have completed the open-book,

untimed* quiz on WebCT that’s due by 9PM the day before class.

* For logistical reasons, we set a 2 hour time limit, but you may submit as often as you like.

Let us know if we need to make the limit longer.

Page 25: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

Additional Administrative NotesThe first quiz is “any marks gives full marks”.

So, if you get more than 0%, we’ll count it as 100%.

We may have to move the time of the midterm exam, since it conflicts with CPSC 211.

Labs, tutorials, and the Demco Learning Centre all start NEXT week (Jan 12).

TA assignments will be posted by end of day Tuesday (but may change through ~week 2).

Can I skip the last half hour of today’s office hours (to take care of Naomi)?

Page 26: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

snick

snack

Some Things to Try...

(on your own or if we have time)

Page 27: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

What Works is NOT Always Obvious

Let’s sort cards with the Quicksort “Algorithm” :1. If there are no cards in a deck, it’s sorted.2. Otherwise, pick a card at random.

a. Divide the other cards into a deck of cards less than or equal to that card and a deck of cards greater than it.

b. Give the “less” deck to a helper and have them Quicksort it.c. Give the “greater” deck to a helper and have them Quicksort it.d. Put the Quicksorted “less” deck on top of the picked card on

top of the Quicksorted “greater” deck. How can that work?It relies on itself to get its work done!

TRY it with a deck of cards.To compare cards, first: A < 2–10 < J < Q < K

If they’re equal so far: Clubs < Diamonds < Hearts < Spades

Page 28: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

What Doesn’t Work isNOT Always Obvious (1 of 2)

Class Main { public static void main(String[] args) { // Let's add up 4 quarters. System.out.println("4 quarters gives us:"); System.out.println(0.25 + 0.25 + 0.25 + 0.25);

// Let's do something a hundred times. int i = 100; do { // Make i one smaller. i--; } while (i > 0);

System.out.println("Done!"); System.out.println("i ended up with the value: " + i); System.out.println("It went down by: " + (100 - i)); }}

Predict and then TRY: What does this print?(If you’re just taking 111, give it a week and then try.)

Page 29: Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others

What Doesn’t Work isNOT Always Obvious (2 of 2)

Class Main { public static void main(String[] args) { // Let's add up 10 dimes. System.out.println("10 dimes gives us:"); System.out.println(0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1); // Let's try do something a hundred times.. // but accidentally go forever int i = 100; do { // Make i one LARGER. Oops! i++; } while (i > 0);

System.out.println("Done!"); System.out.println("i ended up with the value: " + i); System.out.println("It went down by: " + (100 - i)); }}

Predict and then TRY: What does this print?