Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC 121: Models of Computation 2016 Winter Term 2

Similar presentations


Presentation on theme: "CPSC 121: Models of Computation 2016 Winter Term 2"— Presentation transcript:

1 CPSC 121: Models of Computation 2016 Winter Term 2
Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others 2009W1, wolf The “sword” is from a previous term where I started off with Jabberwocky. (It’s the vorpal blade and it goes “snickersnack” or “snick v snack”.) I used Jabberwocky to talk about the syntax/semantics distinction and about meaning derived from structure vs. derived from context/semantics. I don’t anymore… but I still like the sword  TODO: term-by-term update, term on slide                            This work is licensed under a Creative Commons Attribution 3.0 Unported License.

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. Explain what’s meant by pre-class LGs (THEY should achieve these BEFORE next class by reading, working problems, and getting help from bulletin board/course staff). Discuss point of learning goals.

3 Outline Introductions Introductions Exercise The CS121 Story
Course Administration Next Lecture Notes

4 Introductions Steven Wolfman <wolf@cs.ubc.ca>
ICICS 239; office hours TBA on the website I 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 the many other staff office hours (to be posted on the website soon!) Explain what “office hours” are. (Many students seem to be under the delusion that office hours are times when they can make an appointment to see the prof if there’s something REALLY important to discuss. Pah.) Spend a bit of time on this slide introducing yourself, including telling at least one personal thing about yourself (to set up for next two slides). TODO: term-by-term update, other instructor office hours??

5 Outline Introductions Introductions Exercise The CS121 Story
Course Administration Next Lecture Notes

6 More Introductions Introduce yourselves… how?
Ask students how they should introduce themselves. Try everyone at once (silly). Discuss scaling problems to large classes. Talk about techniques to make large classes more effective (including clickers, groupwork problems, and Just-in-Time Teaching?). Propose finding one new person and introducing yourselves to each other. Be sure to demonstrate with volunteer from the front (and do this again at each step). Then, propose finding two new people, and all three introduce yourselves to each other (pairwise). Finally, find three new people and all four introduce yourselves to each other (pairwise).

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

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

9 Concept Q: Intros for 4 How many introductions does a group of 4 people take? 3 4 6 12 None of these This is an EXCELLENT question to kick off a term of ambiguous, no-right-answer clicker questions with. There are good reasons to think that 4, 6, and 12 are all correct (3 is less convincing). Let them come up with these answers (i.e., no consensus). Then, have them convince their neighbours. Then, come back and re-click! 4: “Broadcast” model 6: “Handshake” model 12: “Hello” model (2*handshakes)

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

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

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

13 How Many Introductions?
For 2 people? For 3 people? For 4 people? For 5 people? For n people? Our examples. Should 0 and 1 be examples? Elicit a formula. Talk about use of mathematical techniques and notation to represent the problem and its solution and to prove the correctness of the solution. Elicit some proofs. Establish some confidence in the solution.

14 How Many Introductions?
For 100 people? For people? For people? It’s not a coincidence that all of these are in range for Java ints. is both “Jenny’s” number (from the Tommy Tutone song) and… wait for it… a prime! The other one is semi-arbitrary, picked to fit in 32 bits and to produce a negative result.

15 Program for Introductions
int introductions(int n) { return n * (n - 1); } (define (introductions n) (* n (- n 1))) (in Java) If you have time, these “do you believe it” questions can be clicker questions. Indeed, they can be ONE clicker question left with the chart open, with “mass” moving as you go from “yes” to “no”. (in Racket) Do you believe it? Talk about parallels to CPSC 111

16 Program for Introductions: Testing
Java version with 100: 9900 Do you believe it? Talk about parallels to CPSC 111

17 Program for Introductions: Testing
Java version with 100: 9900 Java version with : Some students may point out the problem right here, either on the basis of the number of digits in the answer (too few!) or (more often in my experience) on the basis of the final digit (9*8 mod 10 != 4). I suggest bulling on through since EVERYONE will get it on the next one. Do you believe it? Talk about parallels to CPSC 111

18 Program for Introductions: Testing
Java version with 100: 9900 Java version with : Java version with : Negative! Um.. Do you believe it? Does this fit with your “model” of computation? Talk about parallels to CPSC 111

19 Program for Introductions: Testing
Racket version with 100: 9900 Racket version with : Racket version with : Old text below. Used to harp on the idea of “belief” at this point. Mostly ditched that. There’s MANY levels of belief here: Belief that our proposed solution is correct Belief that our formal expression (Haskell or Java code) of the proposed solution reflects the solution’s intent Belief that the Java/Haskell compiler/interpreter correctly renders code in whatever low-level language it uses Belief in the chain of translations that take those low-level languages to machine language Belief that the computer faithfully executes the machine level code. This belief reflects belief in many different levels of abstraction, many different processes of translation and computation, and many different designers. Each of these levels requires formal techniques to model it so we can design and implement solutions at those levels, reason about the properties of those solutions, and determine their implications on higher and lower levels. Do you believe it? Will Racket always get the right answer?

20 Alternate Introductions 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. (if (= n 0) (+ (introductions (- n 1))) ; the smaller group (* 2 (- n 1))) ; the extra intros Talk about parallels to CPSC 111 Are both correct?

21 Outline Introductions Introductions Exercise The CS121 Story
Course Administration Next Lecture Notes

22 Questions that CPSC121 Answers
How can we prove that our formula for the number of introductions is correct? (predicate logic proof for n*(n-1) version, induction for “recursive” version) What went wrong in our Java implementation but right in Racket? (number representation) How does the computer (or DrRacket) decide if the characters of your program represent a name, a number, or something else? How does it figure out if you have mismatched " " or ( )? (DFAs) How do we model and reason about computational systems at various levels of abstraction? (propositional and predicate logic, proof, sets, functions, DFAs, relations, ...) [2012S2] Stole the DFA question from Patrice from last term!

23 CPSC 121: The Big Stories Theory Hardware
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. 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”. These “big stories” slides will crop up over the term near the start of various lectures. They should really show up more often! Bonus end goal: Develop tools to communicate computational ideas clearly and precisely.

24 The whole thing (mostly wires connecting boxes).
Our Working Computer 2011W1: switched to Logisim. This is the version that needs two cycles to access memory, however. 2010W2: DONE: switch to the Logisim version?? 2009W1: As of now, they “meet” this computer in the second lab (which most will start in the very first week of labs, since we STRONGLY encourage moving on to lab 1 after finishing lab 0). I won’t go into detail about what this is except to say that it’s the top-level diagram of a computer that we can program in a (somewhat painful) assembly language. Each of the four major components pictured have MANY subparts. By the end of the term, students will be able to “trace execution of an instruction through our computer...down to individual wires and gates.” They certainly are NOT expected to do that at the start of the term, but it’s an exciting goal to have in mind! The whole thing (mostly wires connecting boxes).

25 Our Working Computer (zoomed in on one “box”)
Just the “ALU” (Arithmetic/Logic Unit). You’ll see a pared-down version in lab in a couple of weeks.

26 CPSC 121: The (By?)Products
Theory Hardware Products: Propositional logic Predicate logic Sets and functions Proof techniques (especially induction!) Finite Automata/Regular Expressions Universal machines Uncomputability Products: Gates Combinational circuits Binary data representations Sequential circuits A full computer

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 other 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. I loosely based these on the high-level course goals we established for CS121. I made changes to streamline, simplify, and in some cases generalize. I also dropped DFAs as a high-level goal, since they really fit nicely under the other goals.

28 Outline Introductions Introductions Exercise The CS121 Story
Course Administration Next Lecture Notes

29 Course Administration
Explore the CPSC 121 website: You are required to be familiar with the course website. Ignorance of information on the website may harm you. At minimum: read everything in the “course info” area, skimming the detailed learning goals. People (including Anthony) Pre-reqs (letters soon) Talk about parallels to CPSC 111 Discount Textbooks Magic Box teams HSH software; print coupons; copyright store Labs start next week in X251 NOTE: Perhaps there should be a deadline on this familiarization process? I’ve left off LOTS of administrivia comments in exchange for this note that they MUST read the website. I also hand out hardcopies of the syllabus (which is itself streamlined by referring to the website).

30 Additional Administrative Notes
We’ll double your mark on the first quiz to a max of 100%. (So, if you earn more than 50%, it will count as 100%.) BUT IT’S DUE BY NEXT CLASS! Labs, tutorials, and office hours all start next week!

31 Outline Introductions Introductions Exercise The CS121 Story
Course Administration Next Lecture Notes This was time for the CPSC 121 pre-test. With that 30 minute block, the whole lecture fit comfortably in one 80 minute TTh session.

32 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. Discuss point of learning goals.

33 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. Explain what’s meant by pre-class LGs (THEY should achieve these BEFORE next class by reading, working problems, and getting help from bulletin board/course staff). Discuss point of learning goals.

34 Next Lecture Prerequisites
Read Sections 1.1 and 1.4/2.1 and 2.4 Read propositional logic supplement: You should have completed the open-book, untimed (two-part!) quiz on Connect that’s due by 7PM the day before class. (You are responsible for ensuring that you have submitted the quiz by its deadline!) Explain what’s meant by prerequisites: our advice on how to get going on the preclass LGs + a quiz that assesses the preclass LGs AND also sets us up for the in-class LGs. PROBABLY want to announce that any mark above 0 on this first quiz will count as full credit. 2010W2: HAD: Solve problems like Exercise Set 1.1, #1-18 and Exercise Set 1.4, # Don’t want to update these for 4th ed, though  Readings: 3rd ed in black/4th ed in red

35 Other Critical Admin Notes
Join Piazza! Let’s write up the access code…

36 (on your own if you have time, not required)
Some Things to Try... (on your own if you have time, not required) Worth mentioning that these slides will OFTEN be in presentations and are just extra bits and pieces students might find interesting. (Generally: flotsam and jetsam from past edits.)

37 What Works is NOT Always Obvious
Let’s try out what we’ll call the “Radix” Algorithm. General form: Put all items together in a list in order Make an empty list for each possible value of each “digit” in the items (or letter in a word, etc.). For each digit of the items in the main list, starting with the rightmost digit: 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 For each digit list, in order: Put the list at the back of the main list. What does this do? How does it work?

38 What Doesn’t Work is Not 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( ); // 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)); } We used to cover this MUCH earlier in the course. Some students may have seen it in the “extra” slides. Fun little program. HAVE IT LOADED on your computer!

39 What Doesn’t Work is Not 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( ); // 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)); } Sum of s is NOT 1.0 with Java’s double-precision floats. Of course, the lower loop wraps around surprisingly quickly. Again, HAVE THIS ON YOUR COMPUTER. BUT, make sure they COMMIT to predictions (preferably with discussion) before you run it. See clicker Q on next slide.

40 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”.


Download ppt "CPSC 121: Models of Computation 2016 Winter Term 2"

Similar presentations


Ads by Google