+ All Categories
Home > Documents > Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Date post: 17-Jan-2016
Category:
Upload: corey-watts
View: 214 times
Download: 0 times
Share this document with a friend
39
Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?
Transcript
Page 1: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Computer Science 121

Scientific ComputingWinter 2014

Chapter 1: What is Computation?

Page 2: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.1 Computation as Transformation• A computation is a transformation from on or more

inputs to an output.– Input = time; Output = reactant (grams)

Page 3: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.1 Computation as Transformation•

Input = age (years); Output = recall (items)

Page 4: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.1 Computation as Transformation

Input = x; Output =√x

http://www.macalester.edu/~kaplan/scientificprogramming/figures.ppt

Page 5: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.1 Computation as Transformation

Input = financial info; Output = tax owed / refunded

http://www.macalester.edu/~kaplan/scientificprogramming/figures.ppt

Page 6: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.1 Computation as Transformation

Input = image file; Output = “This is the Mona Lisa!”

http://www.macalester.edu/~kaplan/scientificprogramming/figures.ppt

Page 7: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.1 Computation as Transformation

Input = .wav file; Output = “This is the vowel /i/”

Page 8: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.2 Computation as Reaction to Events

• Inputs often come from measurements • Measurements are typically performed using

transducers (convert input signal into numbers)

– microphone– speedometer– thermometer– seismograph– radar

• (What sort of data doesn't require transducers?)

Page 9: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.2 Computation as Reaction to Events

http://research.utk.edu/ora/explore/sundial.jpg

– Sundial (and compass): Analog transducers

Page 10: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.2 Computation as Reaction to Events

– Because measurements (signals) typically change over time, we get the concept of state : the set of values describing a system at a given time

– E.g.• Health: <blood pressure, temperature, heart rate>• Airplane: <heading, altitude, fuel>• Subatomic particle: <position, momentum>

– So...• A computation is a transition from an old state

to a new state.

Page 11: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.2 Computation as Reaction to Events

– A computation is a transition from an old state to a new state

– What does this mean?

– If we can build a computational model of how a

system changes state (reacts to events), we can make

predictions about how the system will behave

• Health: influence of drugs

• Airplane: response to turbulence

• Particle: Heisenberg's Uncertainty Principle (!!!)

Page 12: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.3 Algorithms

Muhammad ibn Mūsā al-Khwārizmī (c. 780 – 850)

Al-Kitāb al-mukhtaṣar fī hisāb al-jabr wa-l-muqābala

Page 13: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.3 Algorithms– “Don't Reinvent the Wheel” Principle: We should

build new computations out of ones that already exist

– Principle applies across the board in computer science:

• How computer runs programs:

Hardware

Operating System

Matlab Interpreter

Matlab Programs

Page 14: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.3 Algorithms

– Principle applies across the board

• How programs are written:

read_data.m save_data.m plot_data.m

my_program.m

Page 15: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.3 Algorithms

– Build new computations out of ones that already exist

– An algorithm is a set of directions for carrying out a

computation in terms of other, simpler computations.

– Difficulty in writing algorithms comes from

differences between the ways that people do things

and the way that computers do them

• People: Slow, parallel, good generalization

Page 16: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.3 Algorithms

– People: Slow, parallel, good generalization

“Cat!” “Cat!” “Cat!”

Page 17: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

1.3 Algorithms

– Computers: Fast, serial, poor generalization

6068 x 4859 29484412

Page 18: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms• Example: Compare two Arabic numerals (e.g., 23

and 97) to determine which is larger

– Count the digits in each numeral. If one has more digits than another, the one with more is the larger.

– Otherwise, compare the leftmost digits in the two numerals. If one digit is larger than the other, the numeral with the larger leftmost digit is the larger numeral.

– Otherwise, chop off the first numeral and go to step 2.

Q.: What haven't we considered?

Page 19: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Find smallest number in list

1. Assume smallest is first item in list.

2. If there are no more items in list, we're done. Report smallest number.

3. Otherwise, look at next item. If it's smaller than current assumed “smallest” value, make current answer equal to value of this item.

4. Go to step 2.

Page 20: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Find smallest

LIST: 5 2 9 1 3

Page 21: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Find smallest

LIST: 5 2 9 1 3

SMALLEST: 5

Page 22: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Find smallest

LIST: 5 2 9 1 3

SMALLEST: 2

Page 23: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Find smallest

LIST: 5 2 9 1 3

SMALLEST: 2

Page 24: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Find smallest

LIST: 5 2 9 1 3

SMALLEST: 1

Page 25: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Find smallest

LIST: 5 2 9 1 3

SMALLEST: 1

Page 26: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Find smallest

LIST: 5 2 9 1 3

SMALLEST: 1

Page 27: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Sort a list of numbers

1. Create a new, empty list

2. Find the smallest item in the old list.

3. Remove this item from the old list and add it to the beginning of the new list.

4. If the old list is empty, we're done. Output the new list.

5. Otherwise, go to step 2.

Page 28: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Sort a list of numbers

OLD: 5 2 9 1 3

NEW:

Page 29: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Sort a list of numbers

OLD: 5 2 9 1 3

NEW:

Page 30: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Sort a list of numbers

OLD: 5 2 9 3

NEW: 1

Page 31: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Sort a list of numbers

OLD: 5 2 9 3

NEW: 1

Page 32: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Sort a list of numbers

OLD: 5 9 3

NEW: 1 2

Page 33: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Sort a list of numbers

OLD: 5 9 3

NEW: 1 2

Page 34: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Sort a list of numbers

OLD: 5 9

NEW: 1 2 3

Page 35: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Sort a list of numbers

OLD: 5 9

NEW: 1 2 3

Page 36: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Sort a list of numbers

OLD: 9

NEW: 1 2 3 5

Page 37: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Sort a list of numbers

OLD: 9

NEW: 1 2 3 5

Page 38: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Expressing Algorithms

• Example: Sort a list of numbers

OLD:

NEW: 1 2 3 5 9

Page 39: Computer Science 121 Scientific Computing Winter 2014 Chapter 1: What is Computation?

Important Points• We re-used our smallest-number algorithm in our sorting

algorithm: instead of re-writing it, we referred to it!

• We needed a strange notion of “smallest” - smallest item in a one-item list is the item itself.

• Contrast this with ordinary language terminology

– No “smallest” (or largest) item in a one-item list.

– We (are supposed to) say “smaller” (not “smallest”) if there are only two items

– These sorts of differences contribute to our difficulty in learning to program.

– But as algorithms get more complicated, we will find it more difficult to use ordinary language (“the current smallest”) to express them – need variables


Recommended