34
five metaphors in computation

Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

  • View
    217

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

five

metaphors in computation

Page 2: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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?

Page 3: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

Computation

Computations have inputs and outputs Inputs are also known as arguments or parameters Outputs are also known as results or return values

input output

Page 4: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

Computation as call and response

Procedures are “called” with their inputs And “respond” with their return values

input output

Page 5: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

Computation as transformation

It’s often useful to think of the computation as transformingthe 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)

input output

Page 6: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

Page 7: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

Page 8: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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.362 + 1.642 ) = 2

.87

Page 9: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

n2

n2

+ √n length

start

end

line

Page 10: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

n2

n2

+ √n length

start

end

line

0

0

1

1

Page 11: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

n2

n2

+ √n length

start

end

line

0

0

1

1

1

1

Page 12: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

n2

n2

+ √n length

start

end

line

0

0

1

1

1

1

1

1

Page 13: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

n2

n2

+ √n length

start

end

line

0

0

1

1

1

1

1

1

2

Page 14: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

n2

n2

+ √n length

start

end

line

0

0

1

1

1

1

1

1

2 1.414

Page 15: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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 sound

Page 16: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

Page 17: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

− n2

− n2

+ √n length

start

end

line

Page 18: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

+ √n length

start

end

line

− n2=−2

Page 19: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

Program as pattern

Named patterns are called abstractions Procedural abstractions (procedures, subroutines) Data abstractions (types, classes)

x

y

x

y

−2

−2

+ √n length

start

end

line

− n2=−2

Page 20: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

+ √n length

start

end

line

− n2=−2

Page 21: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

Program as language

Programs aredescriptions 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

Page 22: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

Page 23: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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 bLanguage has hierarchical structure

Clauses inside sentences Phrases inside clauses Words inside phrases Syllables inside words

Page 24: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

Page 25: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

Page 26: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

Page 27: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

Page 28: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

Page 29: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

Page 30: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

Page 31: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

Page 32: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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

Page 33: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

Computation as substitution

Computation follows the program’s outline structure To compute the output

of a phrase First compute its

subphrases’ outputs

1.414

Page 34: Five metaphors in computation. Program as recipe A program is a description of a computation It’s like a recipe Tells out to make an output (food) From

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