Download presentation
Presentation is loading. Please wait.
1
five metaphors in computation
2
Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From inputs (ingredients) Through a series of operations (Some of which may be other recipes) Okay, so what are computations like?
3
Computation Computations have inputs and outputs Inputs are also known as arguments or parameters Outputs are also known as results or return values inputoutput
4
Computation as call and response Procedures are “called” with their inputs And “respond” with their return values inputoutput
5
Computation as transformation It’s often useful to think of the computation as transforming the input into the output Photoshop turns images into brighter/darker/funkier images WinAmp turns the CD representation of sound (sound amplitudes) into the MP3 representation of sound (sound spectra) inputoutput
6
Computation as transformation Many computations are cascaded transforms Netscape turns A mouse click into A link to follow, into An HTML file, into Colors for the pixels on the screen
7
The Pythagorean Theorem Pythagoras proved The square of the long side of a right triangle Has the same area as the squares of the two other sides together Proof was through geometric construction Let you “see” the proof But the arguments behind it were justified by the axioms of geometry Important in analytic geometry and therefore, in computer graphics
8
Analytic geometry Descartes introduced the method of co-ordinates to specify points Merged geometry with arithmetic Described space (geometry) Using numbers (arithmetic) Allowed theorems from each to be used for the other (6.27, 4.66) (8.63, 3.02) 4.66-3.02 = 1.64 8.63-6.27 = 2.36 √(2.36 2 + 1.64 2 ) = 2.87
9
Computation as flow Computations can have multiple inputs The patterns they form are more complicated than simple chains But they’re still networks of data flow x y x y − − n2n2 n2n2 +√n length start end line
10
Computation as flow Computations can have multiple inputs The patterns they form are more complicated than simple chains But they’re still networks of data flow x y x y − − n2n2 n2n2 +√n length start end line 0 0 1 1
11
Computation as flow Computations can have multiple inputs The patterns they form are more complicated than simple chains But they’re still networks of data flow x y x y − − n2n2 n2n2 +√n length start end line 0 0 1 1 1 1
12
Computation as flow Computations can have multiple inputs The patterns they form are more complicated than simple chains But they’re still networks of data flow x y x y − − n2n2 n2n2 +√n length start end line 0 0 1 1 1 1 1 1
13
Computation as flow Computations can have multiple inputs The patterns they form are more complicated than simple chains But they’re still networks of data flow x y x y − − n2n2 n2n2 +√n length start end line 0 0 1 1 1 1 1 1 2
14
Computation as flow Computations can have multiple inputs The patterns they form are more complicated than simple chains But they’re still networks of data flow x y x y − − n2n2 n2n2 +√n length start end line 0 0 1 1 1 1 1 1 2 1.414
15
Computation as flow Connection patterns can be tricky One output can feed many inputs A computation’s output can be one of its own inputs + delay sound
16
Computation as sequence Ultimately, computations are performed as a series of steps Programs implicitly define the sequence of steps But we avoid specifying the sequence directly Because it looses much of the structure of the problem Get the line’s start point Get its x coordinate Get the line’s end point Get its x coordinate Find the − 2 of the coordinates Get the line’s start point Get its y coordinate Get the line’s end point Get its y coordinate Find the − 2 of the coordinates Sum the two squared differences Take the square root
17
Program as pattern Programs are descriptions of computations Computations exhibit recurring patterns Repeated operations in a specific computation Common patterns across computations x y x y −n2n2 −n2n2 +√n length start end line
18
Program as pattern Much of programming is identifying patterns Programming languages are designed to let you Name important patterns “Ask for” patterns by name x y x y −2−2 −2−2 +√n length start end line −n2n2 = −2−2
19
Program as pattern Named patterns are called abstractions Procedural abstractions (procedures, subroutines) Data abstractions (types, classes) x y x y −2−2 −2−2 +√n length start end line −n2n2 = −2−2
20
Program as pattern Abstractions can be referred to by name Procedures are called (“invoked”, “applied”) to yield an output Data types are instantiated to yield a data object Effect is to make a new copy of the pattern x y x y −2−2 −2−2 +√n length start end line −n2n2 = −2−2
21
Program as language Programs are descriptions of computations Programs are recipes Descriptions take many forms Diagrams Equations Numerical codes But language is the most common form of program To find the length of a line Sum the − 2 of the x- and y- coordinates of the start and end of the line and take the square root To find the − 2 of a and b Square a minus b
22
Program as language Why language? Not the simplest medium for description Or the most efficient But Very good at expressing abstractions Very good at naming Arguably most versatile To find the length of a line Sum the − 2 of the x- and y- coordinates of the start and end of the line and take the square root To find the − 2 of a and b Square a minus b
23
Program as grammar To find the length of a line Sum the − 2 of the x- and y- coordinates of the start and end of the line and take the square root To find the − 2 of a and b Square a minus b To find the length of a line Sum: The − 2 of The x- and y- coords of the start and end of the line And take the square root To find the − 2 of a and b Square: a minus b Language has hierarchical structure Clauses inside sentences Phrases inside clauses Words inside phrases Syllables inside words
24
Program as hybrid medium Reading complicated sentences is hard Phrases inside phrases inside phrases Easy to get lost So programs are traditionally indented like an outline Makes the structure visual Lets you start reading in the middle Programs are visual after all To find the length of a line Sum: The − 2 of The x- and y- coords of the start and end of the line And take the square root To find the − 2 of a and b Square: a minus b
25
Computation as substitution Computation follows the program’s outline structure To compute the output of a phrase First compute its subphrases’ outputs To find the length of a line Sum: The − 2 of The x- and y- coords of the start and end of the line And take the square root
26
Computation as substitution Computation follows the program’s outline structure To compute the output of a phrase First compute its subphrases’ outputs To find the length of a line Sum: The − 2 of The x- and y- coords of the start and end of (0,0) to (1,1) And take the square root
27
Computation as substitution Computation follows the program’s outline structure To compute the output of a phrase First compute its subphrases’ outputs To find the length of a line Sum: The − 2 of The x- and y- coords of Start: (0,0) End: (1,1) And take the square root
28
Computation as substitution Computation follows the program’s outline structure To compute the output of a phrase First compute its subphrases’ outputs To find the length of a line Sum: The − 2 of X coords: 0 and 1 Y coords: 0 and 1 And take the square root
29
Computation as substitution Computation follows the program’s outline structure To compute the output of a phrase First compute its subphrases’ outputs To find the length of a line Sum: The square of The difference of X coords: 0 and 1 Y coords: 0 and 1 And take the square root
30
Computation as substitution Computation follows the program’s outline structure To compute the output of a phrase First compute its subphrases’ outputs To find the length of a line Sum: The square of 1 and 1 And take the square root
31
Computation as substitution Computation follows the program’s outline structure To compute the output of a phrase First compute its subphrases’ outputs To find the length of a line Sum: 1 and 1 And take the square root
32
Computation as substitution Computation follows the program’s outline structure To compute the output of a phrase First compute its subphrases’ outputs To find the length of a line 2 And take the square root
33
Computation as substitution Computation follows the program’s outline structure To compute the output of a phrase First compute its subphrases’ outputs 1.414
34
Computation as substitution Connection patterns can be tricky One output can feed many inputs A computation’s output can be one of its own inputs done? reduce expression value (object) no yes
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.