| Line 1: |
Line 1: |
| | [[Image:Ada 1838.jpg|right|thumb|200px]] | | [[Image:Ada 1838.jpg|right|thumb|200px]] |
| − | '''Ada Lovelace''' is widely credited as "the first computer programmer"<ref>[http://www.cs.virginia.edu/~robins/Ada_and_the_First_Computer.pdf from Scientific American, May 1999]</ref>, though there are diverse opinions on this, since the computer had not yet been invented. The claim arises from the fact that she was first to publish a paper (in 1843) containing a mathematical algorithm ''encoded for the purpose of being executed by an automatically controlled digital computer''. That computer was the "analytical engine" designed by [[Charles Babbage]]. It was never built, because Babbage's design was way ahead of its time. The program calculated [[Bernoulli numbers]]. (Babbage undoubtedly also wrote some "code" as examples for the analytical engine, but it wasn't published, and it didn't perform a recognizable function.) | + | '''Ada Lovelace''' is widely credited as "the first computer programmer"<ref name="sciam">[http://www.cs.virginia.edu/~robins/Ada_and_the_First_Computer.pdf Scientific American, May 1999, pp76]</ref>, though there are diverse opinions on this, since the computer had not yet been invented. The claim arises from the fact that she was first to publish a paper (in 1843) containing a mathematical algorithm ''encoded for the purpose of being executed by an automatically controlled digital computer''. That computer was the "analytical engine" designed by [[Charles Babbage]]. It was never built, because Babbage's design was way ahead of its time. The program calculated [[Bernoulli numbers]]. (Babbage undoubtedly also wrote some "code" as examples for the analytical engine, but it wasn't published, and it didn't perform a recognizable function.) |
| | | | |
| | Ada had to write the algorithm on paper, rather than at a keypunch or computer terminal, of course. But she actually, to use modern terminology, "wrote code". Also, since the term "program" had not been coined, she described her algorithm as a "plan". In the 20th century, the program was carefully analyzed and simulated, and found to have a minor "bug". In 1983, a team of researchers at United States Department of Defense designed a computer language named '''Ada'''. It is not widely used. | | Ada had to write the algorithm on paper, rather than at a keypunch or computer terminal, of course. But she actually, to use modern terminology, "wrote code". Also, since the term "program" had not been coined, she described her algorithm as a "plan". In the 20th century, the program was carefully analyzed and simulated, and found to have a minor "bug". In 1983, a team of researchers at United States Department of Defense designed a computer language named '''Ada'''. It is not widely used. |
| Line 8: |
Line 8: |
| | | | |
| | ==What did Ada's Bernoulli program look like?== | | ==What did Ada's Bernoulli program look like?== |
| − | The program, and detailed technical commentary, appeared in a paper "Sketch of the Analytical Engine Invented by Charles Babbage" that Ada wrote in 1843. The program itself has been reproduced in the "sidebar" on page 79 of the referenced Scientific American article. First there is a list of the six input and output variables that are used: V1, V2, V3, V21, V22 and V23. And the temporary variables V4 through V13. In modern terminology in a strongly typed language such as C++, we would write something like: | + | The program, and detailed technical commentary, appeared in a paper "Sketch of the Analytical Engine Invented by Charles Babbage" that Ada wrote in 1843. The program itself has been reproduced in the "sidebar" on page 79<ref name="sciam"/>. |
| | + | First there is a list of the six input and output variables that are used: V1, V2, V3, V21, V22 and V23. And the temporary variables V4 through V13. In modern terminology in a strongly typed language such as C++, we would write something like: |
| | | | |
| | int V1, V2, V3; // inputs | | int V1, V2, V3; // inputs |
| Line 14: |
Line 15: |
| | int V4, V5, V6, V7, V8, V9, V10, V11, V12, V13; // temps | | int V4, V5, V6, V7, V8, V9, V10, V11, V12, V13; // temps |
| | | | |
| − | Then she lists the 23 instructions. Instruction 5, for example, appears to say (though it's hard to read):
| + | At the start of the program, she gives initialization of V1=1, V2=2, and V3=N. (Modern computers often have "immediate" instructions to handle constants without using up registers.) |
| | | | |
| − | V11 = V12 / V2; // V11 = (1/2) * (2N-1)/(2N+1)
| + | Then she lists the 23 instructions, giving their source and destination registers, opcodes, and commentary on the progress of the program. The first 5 intructions, for example, are: |
| | | | |
| − | (She used the old-fashioned divide sign "<math>\div</math>"; she didn't know any better. Neither the 026 keypunch nor the ASCII character set had been invented.) | + | V4=V5=V6 = V2 * V3; // Get 2N. The machine allowed multiple destination registers. |
| | + | V4 = V4 - V1; // Get 2N-1. |
| | + | V5 = V5 + V1; // Get 2N+1. |
| | + | V11 = V4 / V5; // Get (2N-1)/(2N+1). |
| | + | V11 = V12 / V2; // Get (1/2) * (2N-1)/(2N+1). |
| | + | |
| | + | (She used the old-fashioned multiply and divide signs "<math>\times</math>" and "<math>\div</math>"; she didn't know any better. Neither the 026 keypunch nor the ASCII character set had been invented.) |
| | | | |
| | She used two loops—see the other sidebar on page 78. V10 is the outer loop counter. The loop consists of instructions 13 to 23. It continues until V10 counts down to 1. | | She used two loops—see the other sidebar on page 78. V10 is the outer loop counter. The loop consists of instructions 13 to 23. It continues until V10 counts down to 1. |