David Evans http://www.cs.virginia.edu/evans Lecture 9: The Great Lambda Tree of Infinite Knowledge and Ultimate Power CS200: Computer Science University.

Slides:



Advertisements
Similar presentations
Cs1120 Fall 2009 David Evans Lecture 11: Generalizing List Procedures 1.
Advertisements

Class 21: Imperative Programming University of Virginia cs1120 David Evans.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 13: Of On and Off Grounds Sorting.
Cs1120 Fall 2009 David Evans Lecture 15: Running Practice.
Cs1120 Fall 2009 David Evans Lecture 16: Power Analysis.
David Evans CS200: Computer Science University of Virginia Computer Science Class 30: Models of Computation.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 18: The Story So Far.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 16: Quicker Sorting.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 31: Types of Types.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 14: Asymptotic Growth.
6.001 SICP SICP – October Introduction Trevor Darrell 32-D512 Office Hour: W web page:
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 11: 1% Pure Luck Make-up lab hours:
Cs1120 Fall 2009 David Evans Lecture 20: Programming with State.
Cs1120 Fall 2009 David Evans Lecture 19: Stateful Evaluation.
David Evans Class 12: Quickest Sorting CS150: Computer Science University of Virginia Computer Science Rose Bush by Jacintha.
CS 152: Programming Language Paradigms February 24 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
David Evans Class 13: Quicksort, Problems and Procedures CS150: Computer Science University of Virginia Computer Science.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 12: Decrypting Work Circle Fractal.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 11: CS Logo, by Lincoln Hamilton and.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 18: Think Globally, Mutate Locally.
Lecture 31: Laziness University of Virginia cs1120 Fall 2009 David Evans.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
David Evans CS200: Computer Science University of Virginia Computer Science Class 17: Mutation M. C. Escher, Day and Night.
David Evans Class 20: Quick Sorting CS200: Computer Science University of Virginia Computer Science Queen’s University,
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 10: Puzzling Pegboards.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 9: Strange Loops and Sinister Repeaters.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 12: QuickSorting Queen’s University,
David Evans CS200: Computer Science University of Virginia Computer Science Class 16: Mutation M. C. Escher, Day and Night.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 19: Environments.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 18: Mutation M. C. Escher, Day and.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 9: Of On and Off Grounds Sorting Coffee.
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.
Class 7: List Procedures David Evans cs1120 Fall 2009.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 14: P = NP?
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 4: Programming with Data.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 8: Cons car cdr sdr wdr.
Lecture 4: Metacircles Eval Apply David Evans
Lecture 17: Environments CS200: Computer Science
Lecture 4: Evaluation Rules Recursion CS200: Computer Science
Lecture 13: Quicksorting CS200: Computer Science
Class 30: Models of Computation CS200: Computer Science
PPL Lazy Lists.
Lecture 7: List Recursion CS200: Computer Science
Class 19: Think Globally, Mutate Locally CS150: Computer Science
Lecture 8: Recursion Practice CS200: Computer Science
Lecture 16: Quickest Sorting CS150: Computer Science
Lecture 6: Programming with Data CS150: Computer Science
Lecture 11: All Sorts CS200: Computer Science University of Virginia
Lecture 28: Types of Types
Lecture 13: Cost of Sorts CS150: Computer Science
Lecture #8 מבוא מורחב.
Lecture 22: P = NP? CS200: Computer Science University of Virginia
Lecture 10: Quicker Sorting CS150: Computer Science
Lecture 27: In Praise of Idleness CS200: Computer Science
Lecture 26: The Metacircular Evaluator Eval Apply
Lecture 9: The Great Lambda Tree of Knowledge and Power
Lecture #7 מבוא מורחב.
List and list operations (continue).
Class 31: Universal Turing Machines CS200: Computer Science
Lecture # , , , , מבוא מורחב.
Class 33: Learning to Count CS200: Computer Science
Cs1120 Fall 2009 David Evans Lecture 10: Fracturing Fractals cs1120 Fall 2009 David Evans
Lecture 3: Rules of Evaluation CS200: Computer Science
Lecture 15: Quicker Sorting CS150: Computer Science
Lecture 11: Sorting Grounds and Bubbles
Lecture 8: Recursing Lists CS150: Computer Science
Lecture 25: The Metacircular Evaluator Eval Apply
Presentation transcript:

David Evans http://www.cs.virginia.edu/evans Lecture 9: The Great Lambda Tree of Infinite Knowledge and Ultimate Power CS200: Computer Science University of Virginia Computer Science David Evans http://www.cs.virginia.edu/evans

Programming with Lists PS3 Menu Programming with Lists PS3 5 February 2003 CS 200 Spring 2003

Review A list is either: a pair where the second part is a list or null (note: book uses nil) Pair primitives: (cons a b) Construct a pair <a, b> (car pair) First part of a pair (cdr pair) Second part of a pair 5 February 2003 CS 200 Spring 2003

Sum 5 February 2003 CS 200 Spring 2003

Gauss Sum (gauss-sum n) = 1 + 2 + … + n (define (gauss-sum n) (if (= n 0) (+ n (gauss-sum (- n 1))))) 5 February 2003 CS 200 Spring 2003

Simpler Gauss Sum? > (intsto 5) (1 2 3 4 5) > (intsto 1) (1) (define (insertl lst f stopval) (if (null? lst) stopval (f (car lst) (insertl (cdr lst) f stopval)))) > (intsto 5) (1 2 3 4 5) > (intsto 1) (1) Same as previous lecture. (define (gauss-sum n) (insertl (intsto n) + 0)) > (gauss-sum 10) 55 (insertl (list 1 2 3 … n) + 0)  (+ 1 (+ 2 (+ 3 (+ … (+ n 0))))) 5 February 2003 CS 200 Spring 2003

Reverse intsto (define (intsfrom n) (if (= n 0) null ;;; Evaluates to the list (n n-1 … 3 2 1) ;;; if n >= 1, null if n = 0. > (intsfrom 10) (10 9 8 7 6 5 4 3 2 1) (define (intsfrom n) (if (= n 0) null (cons n (intsfrom (- n 1))))) 5 February 2003 CS 200 Spring 2003

Intsto? (define (intsto n) (if (= n 0) null (list (intsto (- n 1)) n))) > (intsto 5) (((((() 1) 2) 3) 4) 5) 5 February 2003 CS 200 Spring 2003

append > (append (list 3) (list 4)) (3 4) > (append (list 3) null) (3) > (append null (list 3)) > (append (list 1 2 3) (list 4 5 6)) (1 2 3 4 5 6) Checkup: Try and define append yourself. 5 February 2003 CS 200 Spring 2003

Intsto (define (intsto n) (if (= n 0) null (append (intsto (- n 1)) (list n)))) > (intsto 5) (1 2 3 4 5) 5 February 2003 CS 200 Spring 2003

Using Intsto (define (gauss-sum n) (insertl (intsto n) + 0)) (define (factorial n) (insertl (intsto n) * 1)) 5 February 2003 CS 200 Spring 2003

map (map f lst) Evaluates to the list of values produced by applying f to each element of lst. 5 February 2003 CS 200 Spring 2003

map (define (map f lst) (if (null? lst) null (cons (f (car lst)) (map f (cdr lst)))) 5 February 2003 CS 200 Spring 2003

map (define (map f lst) (insertl lst (lambda (a b) (cons (f a) b)) null)) 5 February 2003 CS 200 Spring 2003

map examples > (map (lambda (x) x) (intsto 5)) (1 2 3 4 5) > (map (lambda (x) (* x x)) (intsto 5)) (1 4 9 16 25) > (map (lambda (row) (display-one-row output-file row tile-width tile-height)) tiles) Displays a photomosaic! 5 February 2003 CS 200 Spring 2003

PS3: Lindenmayer System Fractals 5 February 2003 CS 200 Spring 2003

L-Systems CommandSequence ::= ( CommandList ) CommandList ::= Command CommandList CommandList ::= Command ::= F Command ::= RAngle Command ::= OCommandSequence 5 February 2003 CS 200 Spring 2003

L-System Rewriting Start: (F) Rewrite Rule: CommandSequence ::= ( CommandList ) CommandList ::= Command CommandList CommandList ::= Command ::= F Command ::= RAngle Command ::= OCommandSequence L-System Rewriting Start: (F) Rewrite Rule: F  (F O(R30 F) F O(R-60 F) F) Work like BNF replacement rules, except replace all instances at once! Why is this a better model for biological systems? 5 February 2003 CS 200 Spring 2003

Level 1 Level 0 (F) Start: (F) (F O(R30 F) F O(R-60 F) F)

Level 2 Level 3 5 February 2003 CS 200 Spring 2003

The Great Lambda Tree of Ultimate Knowledge and Infinite Power 5 February 2003 CS 200 Spring 2003

Charge PS3 Due Next Week Weds Make some interesting fractals Once you have it working, its easy to produce lots of interesting pictures Make a better course logo Don’t leave until you get PS2 and I know your name or take your picture! 5 February 2003 CS 200 Spring 2003