Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pat Langley School of Computing and Informatics Arizona State University Tempe, Arizona USA Stored Programs for Routine Activities CPI 101: Meeting 7.

Similar presentations


Presentation on theme: "Pat Langley School of Computing and Informatics Arizona State University Tempe, Arizona USA Stored Programs for Routine Activities CPI 101: Meeting 7."— Presentation transcript:

1 Pat Langley School of Computing and Informatics Arizona State University Tempe, Arizona USA Stored Programs for Routine Activities CPI 101: Meeting 7

2 Routine Activities We spend much of our time engaging in various routine activities: We may value novelty, but familiar routines make our life much simpler than it would be without them. Morning activities like taking a shower and getting dressed Morning activities like taking a shower and getting dressed Getting to the university or work and returning home Getting to the university or work and returning home Organizing and holding a party for your friends Organizing and holding a party for your friends Driving or flying to visit your parents or siblings Driving or flying to visit your parents or siblings Having lunch or dinner at a restaurant or fast food outlet Having lunch or dinner at a restaurant or fast food outlet

3 Familiar Automated Routines We rely on devices for many of our routine activities, including: These devices store and interpret routines so we do not have to carry them out ourselves. Alarm clocks or cell phones to wake up in the morning Alarm clocks or cell phones to wake up in the morning Microwave ovens to cook or reheat our meals Microwave ovens to cook or reheat our meals Tivo boxes to record our favorite TV programs Tivo boxes to record our favorite TV programs Thermostats to control air conditioners and heaters Thermostats to control air conditioners and heaters Washers and dryers to clean and dry our clothes Washers and dryers to clean and dry our clothes iPods to play the songs or lectures we want to hear iPods to play the songs or lectures we want to hear

4 Stored Programs How do we or our devices know how to carry out routine activity? This notion of a stored program is one of the basic insights that underlies computing and informatics. All of the applications we will consider in the course reside on this important idea. This concept is also central to all computational theories of human thinking and intelligence. Basic claim: We can store the steps of a routine activity as data in memory in a way that a computer can interpret them. Basic claim: We can store the steps of a routine activity as data in memory in a way that a computer can interpret them.

5 Storing and Interpreting Programs We need two things to automate routine activity on a computer: These ideas apply not only to routine behavior on silicon devices, but also to our own everyday activities. Encoding and storing the program in memory: Encoding and storing the program in memory: Giving the program a name or index so we can access it. Giving the program a name or index so we can access it. Specifying the programs initial, intermediate, and final steps. Specifying the programs initial, intermediate, and final steps. Accessing and running the program on demand: Accessing and running the program on demand: Retrieving the program by its name or index. Retrieving the program by its name or index. Passing any arguments to the program. Passing any arguments to the program. Executing each of the programs steps in turn. Executing each of the programs steps in turn. Halting the program and returning any results. Halting the program and returning any results.

6 Obsession with Computer Programming Because so many computing applications rely on stored programs, traditional CS degrees begin with a course in programming. This has been an unfortunate historical development because: In this course, we will convey the central ideas without getting bogged down in the details. One need not be a skilled programmer to understand or use many computer applications. One need not be a skilled programmer to understand or use many computer applications. Most programming languages are low level and their syntax obscures the key ideas. Most programming languages are low level and their syntax obscures the key ideas. Religious disagreements have led to a plethora of alternative programming languages. Religious disagreements have led to a plethora of alternative programming languages. Many now believe that computer science equals programming. Many now believe that computer science equals programming.

7 Recipe for Jamaican Curry Chicken 1.Wash chicken with lemon and cut into bite-sized pieces. 2.Season with all dry ingredients. 3.Chop all herbs and add to chicken (use hands to rub in seasonings, and let sit in refrigerator for 1/2 hr.). 4.Place chicken, water, and oil in a pot, stir, cook on high until it comes to a boil, stir, lower heat until chicken is almost cooked. 5.Add potatoes and butter. 6.Cook until water is reduced and potatoes are tender. 7.Serve over steamed white rice. Ingredients: 1/2 chicken, 4 stems thyme, 1 onion, 5 tbsp. curry, 2 cloves garlic, 3 tbsp. seasoning, 3 tbsp. black pepper, 1 tbsp. chicken seasoning, 3 cubed potatoes,1 lemon,1 tbsp. vegetable oil, 2 tbsp. butter, 2 c. water, 1/2 Scotch bonnet pepper

8 Sequential Action in Stored Programs A stored program for carrying out some routine activity has: Interpreting a program involves executing accessing it, passing arguments, and executing these steps in the obvious order. These operations are analogous to following a recipe when one is cooking a meal, where orders can be very important. A name by which one can access the program. A name by which one can access the program. A set of inputs or arguments on which it operates. A set of inputs or arguments on which it operates. Initialization steps that get the program ready. Initialization steps that get the program ready. An ordered list of steps that must occur in sequence. An ordered list of steps that must occur in sequence. Halting steps that end the program and return results. Halting steps that end the program and return results.

9 History of Stored Programs The notion of stored programs has a diverse, extended history: Modern computer programming builds on these innovations. Joseph-Marie Jacquard (~1800) introduces punched cards to control a loom for weaving silk cloth. Joseph-Marie Jacquard (~1800) introduces punched cards to control a loom for weaving silk cloth. Herman Hollerith (~1890) uses punched cards for tabulating data from the US Census. Herman Hollerith (~1890) uses punched cards for tabulating data from the US Census. Alan Turing (1937) introduces the idea of a machine that can store and interpret a program as data. Alan Turing (1937) introduces the idea of a machine that can store and interpret a program as data. William Mauchly and J. P. Eckert (~1946) design the first stored-program digital computer. William Mauchly and J. P. Eckert (~1946) design the first stored-program digital computer. First commercial programmable computer (UNIVAC 1) goes on the market (1951). First commercial programmable computer (UNIVAC 1) goes on the market (1951).

10 Some Stored Programs Cookbook Hollerith punched card Jacquard punched card

11 Another Stored Program To find Blackbeard the Pirates hidden treasure: This program requires one to count the number of steps taken, resetting the counter twice in the process. 1.Go to the dead tree in the center of the island. 2.Turn north and walk 200 paces. 3.Turn east and walk 100 paces. 4.Turn north and walk 50 paces. 5.Dig five feet down to the treasure.

12 Using Variables in Stored Programs A stored program may need to keep track of things that change during its operation using one or more variables, which: The use of variables adds considerably to the flexibility and power of stored programs. Are place holders that store some form of information. Are place holders that store some form of information. Take some initial value at the programs outset. Take some initial value at the programs outset. Can change repeatedly during the programs execution. Can change repeatedly during the programs execution. May be returned by the program when it halts. May be returned by the program when it halts.

13 Hierarchical Nature of Routine Activities Many everyday activities have an obvious hierarchical structure: We could get even more detailed, but this should be enough to convince everyone that we organize activities hierarchically. Morning activity: get up, take a shower, clean teeth, get dressed Morning activity: get up, take a shower, clean teeth, get dressed Take a shower: turn on water, shampoo hair, wash body, dry off Take a shower: turn on water, shampoo hair, wash body, dry off Clean teeth: floss teeth, brush teeth, use mouth wash Clean teeth: floss teeth, brush teeth, use mouth wash Brush teeth: put paste on brush, clean inner, clean outer, rinse Brush teeth: put paste on brush, clean inner, clean outer, rinse Put paste on brush: get brush, get paste, open paste, squeeze tube Put paste on brush: get brush, get paste, open paste, squeeze tube

14 Subroutines in Stored Programs We can produce hierarchical behavior in stored programs by: This simplifies greatly construction and debugging of computer programs because it makes them more modular and reusable. Nearly all nontrivial programs have this hierarchical character. Replacing some steps with calls to other programs Replacing some steps with calls to other programs Invoking these programs when reaching their steps Invoking these programs when reaching their steps Passing variables as arguments to subroutines when called Passing variables as arguments to subroutines when called Returning results from subroutines when they are complete Returning results from subroutines when they are complete

15 More on Jamaican Curry Chicken 1.Wash chicken with lemon and cut into bite-sized pieces. 2.Season with all dry ingredients. 3.Chop all herbs and add to chicken (use hands to rub in seasonings, and let sit in refrigerator for 1/2 hr.). 4.Place chicken, water, and oil in a pot, stir, cook on high until it comes to a boil, stir, lower heat until chicken is almost cooked. 5.Add potatoes and butter. 6.Cook until water is reduced and potatoes are tender. 7.Serve over steamed white rice. Note that our recipe incorporates some conditional statements: These tests are essential to produce an edible dish that is neither undercooked or overcooked.

16 Conditionals in Stored Programs We can produce conditional behavior in stored programs by: Such constructs simplify the construction of computer programs because it makes them more flexible and adaptive. Nearly all nontrivial stored programs have this conditional flavor. Stating that an activity should continue until a test is met. Stating that an activity should continue until a test is met. Stating that an activity should continue while a test is met. Stating that an activity should continue while a test is met. Indicating that a step should happen only if a condition is met. Indicating that a step should happen only if a condition is met.

17 Iteration in Stored Programs Conditionals often occur within iterative/looping constructs that: Iterative statements simplify the specification of stored programs because it handles repetitive behavior. Nearly all nontrivial computer programs incorporate either iteration or recursion. Initialize the values of variables, including counters. Initialize the values of variables, including counters. State one or more steps that should occur on each loop State one or more steps that should occur on each loop Including incrementing/decrementing of any counters Including incrementing/decrementing of any counters Indicate the conditions for halting the iteration. Indicate the conditions for halting the iteration.

18 Dicing an Onion Recursively To dice a piece of onion O: Recursion combines subroutines with conditional statements to support very elegant stored programs. 1.If the onion piece O is wider than 1 cm, 2.Then cut O into two pieces called P and Q. 3.Dice the piece of onion P. 4.Dice the piece of onion Q.

19 Modern Stored Programs Todays computer programs incorporate a variety of features: These are written in many different programming languages and range from a few lines of code to millions. What they hold in common is the idea that one can store programs as data and interpret them to produce behavior. Sequences of steps that should be executed Sequences of steps that should be executed Variables that store changing values Variables that store changing values Hierarchical calls to many levels of subroutines Hierarchical calls to many levels of subroutines Tests that place conditions on some activities Tests that place conditions on some activities Iteration or recursion to handle repetitive activities Iteration or recursion to handle repetitive activities

20 Summary Underlies all of modern computing and informatics Underlies all of modern computing and informatics But has a long history that goes back to at least 1800 But has a long history that goes back to at least 1800 Lets us automate complex but routine activities on computers Lets us automate complex but routine activities on computers But also accounts for routine human behavior But also accounts for routine human behavior Can be implemented with standard programming languages Can be implemented with standard programming languages But one need not master them to appreciate the key ideas But one need not master them to appreciate the key ideas The notion of a stored program is a powerful innovation that: We increasingly rely on programs stored in electronic devices, but we have always used them to carry out routine tasks.


Download ppt "Pat Langley School of Computing and Informatics Arizona State University Tempe, Arizona USA Stored Programs for Routine Activities CPI 101: Meeting 7."

Similar presentations


Ads by Google