Breaking News Costs • “Follow-up discussion on the CS education email and list has focused on the clothes, the accessories, Sneezewort and whether members of the list or their students might have stuffed the and ballot box electronically. (Might have happened!) Growth One person did ask a good question: he asked that anyone with young kids who like Barbie to report back on how they react to CpE Barbie. – Tom Horton #1 #2 One-Slide Summary Outline • The basic recursive computation of Fibonacci can • Sneezewort and Fibonacci take quite a while. There are faster ways . • Cost of computing Fibonacci • We can formally measure and evaluate the cost of • Cost of sorting a computer program. We abstract away details • Intro to Big-Oh Notation such as processor speed and instead measure how the solving time increases as the input increases . • g is in O(f) iff there exist positive constants c and n 0 such that g( n ) ≤ c f( n ) for all n ≥ n 0 . • If g is in O(f) we say that f is an upper bound for g. #3 #4 Sneezewort • Achillea ptarmica is real. • It is “moste efficacious in the inflaming of the braine, and [is] "V" shrubbery therefore much used in Confusing by Andrew Jesien, Becky Elstad and Befuddlement Draughts, where the wizard is desirous of producing hot-headedness and recklessness.” – Order of the Phoenix, p.18 After the Incident • Sneezewort's pattern of by Ben Morrison and Liz Peterson development displays the Robot Cav Man Fibonacci sequence. by Jamie Jeon & Walter Borges #5 #6
Sneezewort Growth Sneezewort Numbers 13 8? 5 3 2 1 1 First Time Unit Second Time Unit Offshoot pink by Jessica Geist, Ellen Clarke Could we model Sneezewort with PS3 code? #7 #8 Fibo Results Tracing Fibo > (fibo 2) > (require-library "trace.ss") 1 > (trace fibo) > (fibo 3) (fibo) 2 > (fibo 3) > (fibo 4) |(fibo 3) 3 | (fibo 2) > (fibo 10) | 1 55 | (fibo 1) > (fibo 60) | 1 Still working… |2 2 Purple Arrow At least we finished. by Rachel Lathbury and Andrea Yoon by Dmitriy Semenov and Sara Alspaugh See end of Class 5 lecture notes for information on “trace.ss”! #9 #10 > (fibo 5) A right-wing Christmas - awwwwww...... by Andrew Baker & Emily Lam |(fibo 5) Liberal Arts Trivia: History | (fibo 4) | |(fibo 3) | | (fibo 2) | | 1 • This 20 th -century American inventor is credited | | (fibo 1) with the phonograph, the carbon telephone | | 1 | |2 transmitter, the practical electric light, and | |(fibo 2) | |1 the phrase “Genius is one percent inspiration, To calculate (fibo 5) we calculated: | 3 (fibo 4) 1 time ninety-nine percent perspiration.” He fought | (fibo 3) (fibo 3) 2 times | |(fibo 2) against Nikola Tesla's alternating current in the (fibo 2) 3 times | |1 5 times total | |(fibo 1) (fibo 1) 2 times so-called War of the Currents. | |1 = 8 calls to fibo = (fibo 6) | 2 |5 How many calls to calculate (fibo 60)? 5 #11 #12
Liberal Arts Trivia: Film Studies Liberal Arts Trivia: Physics • In this Oscar-nominated 2006 film, David Bowie • Count Alessandro Antonio Anastasio Volta was is almost torched by Thomas Edison's goons but a 19 th -century Italian physicist. Volta studied invents a teleportation machine for Wolverine what we now call capacitance, developing so that he can defeat Batman in a magic trick separate means to study both electrical competition because he thinks Batman killed potential V and charge Q , and discovering that his wife. for a given object they are proportional. His experiments in “animal electricity”, in which two different metals were connected in series with frog's legs, eventually led to his most famous discovery. What was it? #13 #14 fast-fibo Fast-Fibo Results > (fast-fibo 10) 55 (define ( fast-fibo n) > (time (fast-fibo 61)) (define ( fib-helper a b left) cpu time: 0 real time: 0 gc time: 0 (if (<= left 0) 2504730781961 b (fib-helper b (+ a b) (- left 1)))) The original fibo would take at least 2.5 Trillion applications. A 2.5 GHz computer does 2.5 Billion simple operations per (fib-helper 1 1 (- n 2))) second, so 2.5 Trillion applications operations take ~1000 seconds. Each application of fibo involves hundreds of simple operations… #15 #16 ;;; The Earth's mass is 6.0 x 10^24 kg ;;; The Earth's mass is 6.0 x 10^24 kg > (define mass-of-earth (* 6 (expt 10 24))) > (define mass-of-earth (* 6 (expt 10 24))) ;;; A typical rabbit's mass is 2.5 kilograms ;;; A typical rabbit's mass is 2.5 kilograms > (define mass-of-rabbit 2.5) > (define mass-of-rabbit 2.5) > (/ (* mass-of-rabbit (fast-fibo 60)) mass-of-earth) > (/ (* mass-of-rabbit (fast-fibo 60)) mass-of-earth) 6.450036483e-013 6.450036483e-013 > (/ (* mass-of-rabbit (fast-fibo 120)) mass-of-earth) > (/ (* mass-of-rabbit (fast-fibo 120)) mass-of-earth) 2.2326496895795693 2.2326496895795693 According to Bonacci’s model, after less than 10 According to Bonacci’s model, after less than 10 years, rabbits would out-weigh the Earth! years, rabbits would out-weigh the Earth! Beware the Bunnies!! Beware the Sneezewort!! #17 #18
Evaluation Cost Actual running times vary according to: 80,000,000 – How fast a processor 70,000,000 you have 60,000,000 50,000,000 – How much memory 40,000,000 you have 30,000,000 – Where data is located 20,000,000 in memory 10,000,000 – How hot it is 0 1969 1972 1975 1978 1981 1984 1987 1990 1993 1996 1999 2002 2005 2008 – What else is running Moore’s “Law” – computing power doubles – etc... Broccoli Fallout by Paul DiOrio, Rachel Phillips every 18 months #19 #20 Measuring Cost Cost of Fibonacci Procedures (define ( fast-fibo n) (define ( fibo n) (define (fib-helper a b left) (if (or (= n 1) (= n 2)) • How does the cost scale (if (= left 0) 1 ;;; base case b (+ (fibo (- n 1)) with the size of the input ? (fibo (- n 2))))) (fib-helper b (+ a b) (- left 1)))) (fib-helper 1 1 (- n 2))) • If the input size increases by one, how much longer Input fibo fast-fibo will it take? m q mk • If the input size doubles , m +1 ( m +1) k how much longer will it m +2 at least q 2 ( m +2) k take? Untitled Nokomis McCaskill Chris Hooe #21 #22 Cost of Fibonacci Procedures The Golden Ratio (define ( fast-fibo n) (define ( fibo n) (define (fib-helper a b left) (if (or (= n 1) (= n 2)) (if (= left 0) 1 ;;; base case b (+ (fibo (- n 1)) (fibo (- n 2))))) (fib-helper b (+ a b) (- left 1)))) (fib-helper 1 1 (- n 2))) Input fibo fast-fibo m q mk m +1 q *Φ ( m +1) k Parthenon m +2 at least q 2 ( m +2) k Φ = (/ (+ 1 (sqrt 5)) 2) = “The Golden Ratio” ~ 1.618033988749895... ~ (/ (fast-fibo 61) (fast-fibo 60)) = 1.618033988749895 Nautilus Shell #23 #24
PS2 Question More Golden Ratios (define (find-best-hand hands) (car ( sort hands higher-hand?))) (define (find-best lst cf) (if (= 1 (length lst)) (car lst) (pick-better cf (car lst) (find-best (cdr lst) cf)))) (define (pick-better cf num1 num2) (if (cf num1 num2) num1 num2)) (define (find-best-hand hands) (find-best hands higher-hand?)) http://www.fenkefeng.org/essaysm18004.html Which is better and by how much? by Oleksiy Stakhov #25 #26 Simple Sorting Simple Sort • Can we use find-best to ;; cf = comparison function implement sort? (define ( sort lst cf) ;; simple sort – Yes! (if (null? lst) lst (let ((best (find-best lst cf))) • Use (find-best lst) to (cons find the best best • Remove it from the list (sort (delete lst best) cf))))) – Adding it to the answer ;; delete lst x = (filter ... (not (eq? x ... • Repeat until the list is crazy blue tree by Victor Malaret, Folami Williams empty #27 #28 Sorting Hands Sorting (define ( sort lst cf) (define ( sort lst cf) (if (null? lst) lst (if (null? lst) lst (let ((best (find-best lst cf))) (let ((best (find-best lst cf))) (cons best (sort (delete lst best) cf))))) (cons (define ( find-best lst cf) best (if (= 1 (length lst)) (car lst) (sort (delete lst best) cf))))) (pick-better cf (car lst) (find-best (cdr lst) cf)))) (define ( pick-better cf num1 num2) (if (cf num1 num2) num1 num2)) (define ( sort-hands lst) (sort lst higher-hand?)) How much work is sort? #29 #30
Recommend
More recommend