38
snick snack CPSC 121: Models of Computation 2011 Winter Term 1 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others 1

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

  • View
    219

  • Download
    4

Embed Size (px)

Citation preview

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

snick

snack

CPSC 121: Models of Computation2011 Winter Term 1

Introduction & Motivation

Steve Wolfman, based on notes by Patrice Belleville and others

1

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

Learning Goals: In-Class

By the end of the unit, you should be able to:– Give an example of how we can apply formal

reasoning and computers to a simple, real-world task.

– Give an example of how a computational solution to a simple task might go wrong.

– Describe the two “big stories” of CS121: reasoning about computation and building computers.

2

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

Outline

• Introductions

• Introductions Exercise

• The CS121 Story

• Course Administration

• Next Lecture Notes

3

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

Introductions

Steven Wolfman <[email protected]>

ICICS 239; office hours listed on the websiteI also 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.Additionally, you can use TA office hours.

4

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

Outline

• Introductions

• Introductions Exercise

• The CS121 Story

• Course Administration

• Next Lecture Notes

5

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

More Introductions

Introduce yourselves… how?

6

Page 7: Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 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.

7

Page 8: Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 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?

8

Page 9: Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 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.3

b.4

c.6

d.12

e.None of these

9

Page 10: Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 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.10

Page 11: Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 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. (Two people need two introductions to introduce themselves to each other.)

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

Hi, I’m Grace H.

Hi Grace, I’m Alan T.Intro #1

Intro #211

Page 12: Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 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?

12

Page 13: Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 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?

13

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

How Many Introductions?

For 100 people?

For 8675309 people?

For 1526097757 people?

14

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

Program for Introductions

int introductions(int n)

{

return n * (n - 1);

}

(define (introductions n)

(* n (- n 1)))

Do you believe it?15

(in Java)

(in Scheme/Racket)

Page 16: Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 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?16

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

Program for Introductions: Testing

Java version with 100: 9900

Java version with 8675309: 265642364

Do you believe it?17

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

Program for Introductions: Testing

Java version with 100: 9900

Java version with 8675309: 265642364

Java version with 1526097757: -645820308

Um.. Do you believe it?Does this fit with your “model” of computation?

18

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

Program for Introductions: Testing

Racket version with 100: 9900

Racket version with 8675309: 75260977570172

Racket version with 1526097757: 2328974362394333292

Do you believe it?Will Racket always get the right answer?

19

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

Outline

• Introductions

• Introductions Exercise

• The CS121 Story

• Course Administration

• Next Lecture Notes

20

Page 21: Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 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 and reason about computational systems at various levels of abstraction? (propositional and predicate logic, proof, sets, functions, DFAs, relations, ...)

21

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

CPSC 121: The Big Stories

Theory

How do we model computational systems (programs/computers) in order to design and analyze them?

Grand goal: Reason about what is and isn’t possible to compute.

Hardware

How do we build devices that can compute out of real materials (“sand and rocks and water”)?

Grand goal: break

down a full computer

into simple “gates”.

Bonus end goal: Develop tools to communicate computational ideas clearly and precisely. 22

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

Our Working Computer

23The whole thing (mostly wires connecting boxes).

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

Our Working Computer(zoomed in on one “box”)

24Just the “ALU” (arithmetic and logic unit). You’ll see a pared-down version in lab in a couple of weeks.

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

CPSC 121: The (By?)Products

Theory

Products:• Propositional logic• Predicate logic• Sets and functions• Proof techniques (especially

induction!)

• Finite Automata/Regular Expressions

• Universal machines• Uncomputability

Hardware

Products:• Gates• Combinational circuits• Binary data

representations• Sequential circuits• A full computer

25

Page 26: Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 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.

26

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

Outline

• Introductions

• Introductions Exercise

• The CS121 Story

• Course Administration

• Next Lecture Notes

27

Page 28: Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 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/

You are required to be familiar with the course website. Ignorance of information on the website may harm you.

28

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

Additional Administrative Notes

The first quiz is “any marks gives full marks”. So, if you get more than 0%, we’ll count it as 100%.

Labs, tutorials, and TA office hours in the Learning Centre all start NEXT week.

(My office hours start this week!)

29

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

Outline

• Introductions

• Introductions Exercise

• The CS121 Story

• Course Administration

• Next Lecture Notes

30

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

Learning Goals: In-Class

By the end of the unit, you should be able to:– Give an example of how we can apply formal

reasoning and computers to a simple, real-world task.

– Give an example of how a computational solution to a simple task might go wrong.

– Describe the two “big stories” of CS121: reasoning about computation and building computers.

31

Page 32: Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 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.

32

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

Next Lecture Prerequisites

Read Sections 1.1 and 1.4/2.1 and 2.4

You should have completed the open-book, untimed quiz on Vista that’s due by 9PM the day before class.

(You are responsible for ensuring that you have submitted the quiz by 9PM!)

33Readings: 3rd ed in black/4th ed in red

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

snick

snack

Some Things to Try...

(on your own if you have time, not required)

34

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

What Works is NOT Always Obvious

Let’s try out what we’ll call the “Radix” Algorithm. General form:

1. Put all items together in a list in order

2. Make an empty list for each possible value of each “digit” in the items (or letter in a word, etc.).

3. For each digit of the items in the main list, starting with the rightmost digit:

a) For each item in the main list, in order: Put it at the back of the list indicated by the current digit in that item

b) For each digit list, in order: Put the list at the back of the main list.

What does this do?How does it work?

35

Page 36: Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 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)); }}

36

Page 37: Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 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)); }}

37

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

Even Bigger Story:“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”.

38