CPSC 121: Models of Computation 2018 Summer Term 1 Introduction - - PowerPoint PPT Presentation

cpsc 121 models of computation 2018 summer term 1
SMART_READER_LITE
LIVE PREVIEW

CPSC 121: Models of Computation 2018 Summer Term 1 Introduction - - PowerPoint PPT Presentation

CPSC 121: Models of Computation 2018 Summer Term 1 Introduction & Motivation Cinda Heeren, based on notes by Steve Wolfman, Patrice Belleville and others 1 This work is licensed under a Creative Commons Attribution 3.0 Unported License.


slide-1
SLIDE 1

CPSC 121: Models of Computation 2018 Summer Term 1

Introduction & Motivation Cinda Heeren, based on notes by Steve Wolfman, Patrice Belleville and

  • thers

1

This work is licensed under a Creative Commons Attribution 3.0 Unported License.

slide-2
SLIDE 2

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

slide-3
SLIDE 3

Outline

  • Introductions
  • Introductions Exercise
  • The CS121 Story
  • Course Administration
  • Demo
  • Next Lecture Notes

3

slide-4
SLIDE 4

Introductions

Cinda Heeren <cheeren@cs.ubc.ca> ICICS 233 – OH: Mon Wed 2:30-4p LOTS of TAs!

4

slide-5
SLIDE 5

Outline

  • Introductions
  • Introductions Exercise
  • The CS121 Story
  • Course Administration
  • Demo
  • Next Lecture Notes

5

slide-6
SLIDE 6

More Introductions

Introduce yourselves… how?

6

slide-7
SLIDE 7

Introduce Yourselves…

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. BUT, tell two truths and a lie!

7

slide-8
SLIDE 8

How Many Introductions?

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

8

slide-9
SLIDE 9

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

slide-10
SLIDE 10

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

slide-11
SLIDE 11

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 #2

11

slide-12
SLIDE 12

How Many Introductions?

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

12

slide-13
SLIDE 13

How Many Introductions?

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

13

Our examples. Should 0 and 1 be examples?

slide-14
SLIDE 14

How Many Introductions?

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

slide-15
SLIDE 15

Program for Introductions

int introductions(int n) { return _____________; } (define (introductions n) ____________ )

15

(in Java) (in Racket)

slide-16
SLIDE 16

Program for Intros: Testing

Java version with 100: 9900

Do you believe it?

16

slide-17
SLIDE 17

Program for Intros: Testing

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

Do you believe it?

17

slide-18
SLIDE 18

Program for Intros: 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

slide-19
SLIDE 19

Program for Intros: 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

slide-20
SLIDE 20

Alternate Intros Program

;; Model in math, translate to Racket. (define (introductions n) (* n (- n 1))) ;; Model as “I know what happens ;; a) in a group of 0 people, and ;; b) when someone new enters a group.” ;; Translate to Racket. (define (introductions n) (if (= n 0) _______ ____________________ ; soln on smaller instance ____________________); + the extra intros

20

Are both correct?

slide-21
SLIDE 21

Outline

  • Introductions
  • Introductions Exercise
  • The CS121 Story
  • Course Administration
  • Demo
  • Next Lecture Notes

21

slide-22
SLIDE 22

Questions that CPSC121 Answers…

How can we prove that our formula for the number of introductions is correct? What went wrong in our Java implementation but right in Racket? How does the computer (or DrRacket) decide if the characters of your program represent a name, a number,

  • r something else? How does it figure out if you have

mismatched " " or ( )? How do we model and reason about computational systems at various levels of abstraction?

22

slide-23
SLIDE 23

CPSC 121: The Big Stories

Theory How do we model computational systems (programs/computers) in

  • rder 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.

23

slide-24
SLIDE 24

Our Working Computer

24

The whole thing (mostly wires connecting boxes).

slide-25
SLIDE 25

Working Computer—zoomed in on one box

25

Just the “ALU” (Arithmetic/Logic Unit). You’ll see a pared-down version in lab in a couple of weeks.

slide-26
SLIDE 26

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

26

slide-27
SLIDE 27

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
  • ther CS experts on complex topics.
  • characterize algorithms (CS problem solutions),

such as proving their correctness or comparing their performance.

  • critically read proofs: justifying why each step is

correct and judging what the proof means.

27

slide-28
SLIDE 28

Outline

  • Introductions
  • Introductions Exercise
  • The CS121 Story
  • Course Administration
  • Demo
  • Next Lecture Notes

28

slide-29
SLIDE 29

Course Administration

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

Pre-class quizzes (10) HW (5) Labs (9) Tutorials (9) Clickers Exams (3)

29

slide-30
SLIDE 30

Announcements

Quiz 1: av on Canvas. Due 5/16, noon. HW1: av 5/17. Due 5/24, 11:59p. Labs and tutorials start tomorrow, 5/15. Join Piazza –

piazza.com/ubc.ca/summer2018/cpsc121

30

slide-31
SLIDE 31

Outline

  • Introductions
  • Introductions Exercise
  • The CS121 Story
  • Course Administration
  • Demo
  • Next Lecture Notes

31

slide-32
SLIDE 32

What Works is NOT Always Obvious

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

1. Assemble some items (numbers or words) together in a list 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:

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?

32

slide-33
SLIDE 33

What Doesn’t Work is Not Always Obvious

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)); } }

33

https://repl.it/@ckh205/cpsc121-intro

slide-34
SLIDE 34

What Doesn’t Work is Not Always Obvious

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)); } }

34

slide-35
SLIDE 35

Even Bigger Story: __________

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

  • r 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”.

35

slide-36
SLIDE 36

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.

36

slide-37
SLIDE 37

Next Class 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.

37

slide-38
SLIDE 38

Next Lecture Prerequisites

Read Epp Sections 1.1 and 1.4/2.1 and 2.4 Read propositional logic supplement:

http://www.ugrad.cs.ubc.ca/~cs121/current/handouts/prop-circuit-xlate.html

You should have completed the open-book, untimed (two-part!) quiz on Canvas that’s due by start of next class.

38

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