Docsity

Brief History of Computers: From Pre-History to Modern PCs and Programming - Prof. John Pe, Study notes of Mathematics

Partial preview of the text

Download Brief History of Computers: From Pre-History to Modern PCs and Programming - Prof. John Pe and more Study notes Mathematics in PDF only on Docsity!

Notes for Mathematical Computing

John Perry

THE UNIVERSITY OF SOUTHERN MISSISSIPPI, DEPARTMENT OF MATHEMATICS, BOX

5045, HATTIESBURG, MS 39406

E-mail address: [email protected] URL: http://www.math.usm.edu/~perry/

CHAPTER 1

A short, informal history of computers

Who invented computers, and why? You can find computers everywhere today. Most consumer electronics today have at least a primitive computer in them. We usually say that people who work with computers are specialists in computer science or information technology. However, computer science is really a branch of mathematics! Computers were invented by mathematicians to help them do the mechanical routines of mathematics more easily, more quickly, and more reliably.

1.1. FROM PRE-HISTORY TO PRE-COMPUTERS

Today’s computers are the descendants of a very long line of devices invented for reliable computation—in other words, for doing a certain kind of applied mathematics. One of the earliest such devices is the abacus, which even today remains in active use throughout much of the world. Most of us will never learn to use an abacus, but those who are trained in it can do basic arithmetic at impressive speeds. The abacus was so important to commerce in medieval Europe that Europeans refused for hundreds of years to switch to the Hindu-Arabic numerals with which we are familiar,

0, 1, 2, 3, 4, 5, 6, 7, 8, 9

because they could not do arithmetic with these numerals on an abacus! It was for this reason that Leonardo of Pisa, better known as Fibonacci, wrote Liber Abaci (the Book of the Abacus). Not until then did Europeans felt comfortable with abandoning Roman numerals for Hindu-Arabic.^1 Scientists and engineers achieved a number of important advances in counting devices be- fore the 20th century. The Tabulating Machine Company became rich by marketing a newly- invented counting device to the U.S. Census Bureau; today we know this company as Interna- tional Business Machines, or IBM. Their most important invention of the time, the punch card, is now technologically obsolete. Most of these machines did not use electricity, but relied on:

  • steam power that turned extremely precise gears;
  • “punch cards” or a mechanical keyboard to receive information; and
  • a paper tape to display results of the computation.

Even today you can walk into stores whose cash registers rely on this mechanical architecture. Each of these machines was constructed with a particular purpose in mind. None of them approached the role of a general-purpose computer. The 19th-century mathematician Charles

(^1) Don’t write the medieval Europeans off as morons; they made a number of impressive advances in their day. Besides, we in the United States understande 25mph more than 40kph, which strikes us as unnatural. So we cling to the English system of measure of pounds, gallons, and feet, whereas virtually the entire world has moved to the decimal system, with grams, liters, and meters. Conversions are far easier in the metric system, and a failure to convert properly the systems can cost millions of dollars, if not more. Only a few years ago, a planetary probe crashed onto the Martian surface because part of it was designed in Britain, and someone forgot to convert from meters to feet.

4

1.2. PRE-MODERN COMPUTERS 5

Babbage tried to change this. He designed a computational device that could address more than one problem, called the Analytical Engine. If he could have built it, it would have worked brilliantly; its design was similar to the modern computer. Alas, the machine never saw the light of day. The technology of his time was not sufficient for his needs, and he couldn’t convince the British government to fund his research.

1.2. PRE-MODERN COMPUTERS

As with many technological advances, the “great leap forward” in computer science came from the military. During the second world war, the Americans and the British developed com- putational machines that served two important purposes:

  • breaking the “unbreakable” codes generated by Enigma, the German cryptographic ma- chine;
  • performing the phenomenal number of computations necessary to design the industrial- grade weaponry necessary for modern warfare. These machines succeeded quite well. They owed their designs in large part to mathematicians employed by the military: for example, Alan Turing in Great Britain, and John von Neumann in the United States. Turing went on to develop a number of important theoretical ideas in computer science, including the basic notions of which problems can be solved by computa- tion. Students of computer science study the theoretical Turing Machine and Turing’s theory of computation. It was in 1948 that the first “modern” computers appeared. By a modern computer, we mean one that a human can use to solve many problems without manually changing the physical arrangement of the machine. This is the origin of writing a program in “software”, instead of creating a new machine for each problem. As we stated above, pre-modern computational devices were designed to solve only one prob- lem. The first computers designed in Britain and the United States could solve more than one problem, but a squad of technicians had to go into the computer room—the computer occupied an entire room!—and rewire the computer. This time-consuming task could take days, and led to many errors, including the first computer “bug”, a moth that made its way into the electronics. The ENIAC computer was one such device used to perform calculations for artillery tables and the design of atomic weapons. John von Neumann, who was working on the latter, had the idea to design the computer so that the instructions on how to solve the problem were not part of the machine’s wiring, but part of the data. Such computers first appeared in 1948, with EDVAC. None of them used keyboards, mice, or disk drives, but punch cards and, later, magnetic tape. But the notion of software, that instruc- tions on solving a particular problem do not have to be part of the machine’s design, were first enfleshed in that year. From our point of view as programmers, this idea stands as the conception of the modern computer.

Exercises

1.1: Define the following terms: a computer bug, the Enigma device, a vacuum tube, a transis- tor. Note that a computer bug is not a moth stuck in a vacuum tube; that is merely the putative origin of the phrase. The terms vacuum tube and transistor are not defined in this text, so you’ll have to crack open a dictionary, or ask a computer engineer, or look at an encyclopedia. (Wikipedia would be okay for this.)

1.3. MODERN COMPUTERS AND COMPUTER LANGUAGES 7

allows the blind man to make decisions based on the value of information. (“Are my hands touching anything?”) An interesting question would be to determine the smallest number of commands you would need to direct a blind man across the room. This example might seem extreme. You may be thinking that the blind man must be a moron if he can’t know what to do if someone is standing in front of him! This is actually the point, which we codify as our Fundamental Principle of Computer Programming: Computers are morons. Actually, it isn’t even proper to speak of computers as morons, because they are only machines. They cannot “think,” and a moron is someone who can think, but doesn’t. Nevertheless, by way of analogy we will use this principle to justify its corollary: If a program doesn’t work, it is not the computer’s fault. If the computer isn’t doing what you want it to do, that’s because you aren’t telling it what you want it to do. The computer is a moron, and doesn’t know what you want it to do. The computer doesn’t even have sufficient brains to guess what you want it to do. Keep these two points in mind throughout the course. Sooner or later, you will hear Dr. Perry call the computer a moron, or blame the computer for the fact that something isn’t work- ing. When this happens, smile inwardly & keep quiet, content in the fact that you are wiser than your professor. When the author was a child thirty years ago, the most common word size for a home com- puter was 8 bits. The first personal computers, such as the Apple, the Apple II, the VIC-20, and the Commodore-64, were 8-bit computers. Eight-bit computers work “easily” with problems whose numbers range from 0 to 255 (2^8 − 1). Sixteen-bit computers work “easily” with problems whose numbers range from 0 to 65,535 (2^16 − 1). Four bit machines and 32-bit machines also existed, but they were far less common. Intel Corporation created the first transistor-based computer using a 4-bit processor dubbed the 4004. Four-bit processors can work easily with numbers from 0 to 15 (2^4 − 1), which means that you need some serious trickery to do serious work. By contrast, a 32-bit processor can address numbers from 0 to 4,294,967,295 (2^32 − 1). This is enormously useful, but even twenty years ago, that kind of technology was very expensive. Even 16-bit technology was expensive, so computers simulated 16 bit words by pumping two 8 bit words in a row through the wires. Radio Shack’s Color Computer was an example of this, and it cost more than $700 when it was released. This bit of engineering strategy worked just as well with the Macintosh and Amiga twenty years ago, whose word size was 32 bits even though they were only wired for 16. These machines cost more than $1,000 when they were released. Today, that amount of money will buy you a 64-bit computer that often works with 128-bit numbers... by pumping two 64-bit words in a row through the wires.

Exercises

1.3: Define the following terms: software, binary numeral, bit, word size. 1.4: True or false? (a) Since computers understand only binary numerals, they can’t do mathematics the way humans do. (b) An 8-bit computer can only work with problems whose numbers are in the range 0,... , 2^8 − 1.

1.4. “LOW-LEVEL” PROGRAMMING LANGUAGES 8

(c) Computers are unlike humans in that each binary word represents one and only one idea. 1.5: Can the our Fundamental Principle of Computer Programming be applied in other contexts? For example, when Dr. Perry is trying to fix the stupid bathroom faucet that won’t stop leaking, and he calls it nasty names, is this an intelligent, rational course of action? What about when he finally gets it to stop leaking, and dances around while taunting it? Are these applications of the Fundamental Principle of Computer Program- ming?

1.4. “LOW-LEVEL” PROGRAMMING LANGUAGES

At the most basic level, a computer program on an 8-bit computer really looks something like this: 1 0 0 1 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1 0 0 0 1 1 1 1 1 1 1 0 0 This is an example of machine code. A significant number of simple electronic devices are com- puters that have been hand-programmed using machine code. Writing a program in machine code is considerably easier than rewiring the machine. How- ever, machine code is not especially easy to write, read, or modify. I defy anyone lacking both a manual and a substantially larger listing of memory to discern what is meant by the word

The next logical step is to represent each instruction by an English word, or an abbrevia- tion of several English words. Figure 1.1 shows an excerpt from a program written to compute the greatest common divisor of two integers. This assembly code has four visible groups. The rightmost column contains data which the computer needs to process. The column on its left contains instructions on how to process the data immediately on the right. Continuing left, we meet the labels; these organize instructions into groups, and reference different steps or tools for the problem-solving process. The leftmost column contains line numbers, which have no real meaning in the program, but are useful for humans to analyze and discuss the code. Assembly language, or assembly code, is thus a direct translation of machine code into human-readable codewords, or mnemonics. Its immediate goal is to render machine code into something readable by humans. It succeeds at that. For the larger aim of easily solving compli- cated mathematical problems, however, assembly code isn’t much help. We can identify three major defects. First, although you can guess from lines 7, 9, and 10 that the computer needs to divide, multiply, and subtract, it isn’t clear what numbers these are supposed to be done with. Besides, these instructions are the only ones whose meanings approach clarity to a layman! With some luck, you might guess that cmpwi has something to do with comparison, but what on earth are lwz, bne, and mr supposed to mean? Second, different computers often have different instruction sets. Since assembly code is merely a representation of the computer’s instruction set, the assembly code to solve a problem on one computer looks completely different on a different computer architecture. Ideally, the instructions to solve a problem ought to reflect the foundations of problem itself, and not the mechanical tool used to solve the problem.

1.5. “HIGH-LEVEL” PROGRAMMING LANGUAGES 10

Strictly speaking, the derivative can be found by working with

lim h→ 0

2 (x + h) sin

(x + h)^2 − 1

− 2 x sin

x^2 − 1

h

but this is needlessly time consuming. Instead, students of elementary calculus learn a battery of definitions, theorems, and (supposedly) logic to move directly to f ′^ (x) = 2 sin

x^2 − 1

  • 4 x^2 cos

x^2 − 1

without wasting time on the complex, mechanical algebra required to simplify the limit. A mathematician literate in calculus can explain that he obtained the derivative by applying:

  • the constant multiple rule;
  • the product rule;
  • the chain rule;
  • the rule for derivatives of polynomials; and
  • one of the rules for derivatives of trigonometric functions. It would likewise make sense to find ways to express our problems, and their solutions, in ab- stract terms that would allow us not to write the detailed, cryptic lists of instructions required by assembly code. This leads us to the necessity of expressive, “high-level” programming languages that incorporate more abstraction than the “low-level” machine and assembler codes.

Exercises

1.6: Define the following terms: assembly language, mnemonic. 1.7: True or false? (a) Machine code is impossible to understand. (b) Assembly language succeeds at making machine code readable to humans. (c) Assembly language helps us solve mathematical problems using instructions that reflect the foundations of the problem itself. 1.8: Summarize the defects of assembly language from a perspective of solving mathematical problems, using your own words.

1.5. “HIGH-LEVEL” PROGRAMMING LANGUAGES

A “high-level” programming language is a pattern of words and symbols that

  • to a reasonable extent, resembles a list of commands in some human language, almost always English;^4 and
  • the computer translates from this human-like language into machine code so that it can understand what the author meant. These two, simple characteristics are what makes for a high-level language. Nearly every pro- grammer in the world programs exclusively in a high-level language. The first high-level language was released in 1957 by IBM. It was developed by a team led by the mathematician John Backus. Its purpose was to translate mathematical formulas into ma- chine code; hence its name, FORTRAN. Figure 1.2 shows an example of the 1977 revision of the language. A quick look shows that this code is far more understandable than the corresponding (^4) Those who invent the toys get to make the rules of the game! The vast majority of computer languages use English keywords. However, computer languages have been designed for other human languages. The author has seen programs written with languages whose instructions use French and Russian keywords.

1.5. “HIGH-LEVEL” PROGRAMMING LANGUAGES 11

FIGURE 1.2. FORTRAN code to compute the greatest common divisor of two integers [ 2 ]

  • euclid.f (FORTRAN 77)
  • Find greatest common divisor using the Euclidean algorithm PROGRAM EUCLID PRINT *, 'A?' READ *, NA IF (NA.LE.0) THEN PRINT *, 'A must be a positive integer.' STOP END IF PRINT *, 'B?' READ *, NB IF (NB.LE.0) THEN PRINT *, 'B must be a positive integer.' STOP END IF PRINT *, 'The GCD of', NA, ' and', NB, ' is', NGCD(NA, NB), '.' STOP END

FUNCTION NGCD(NA, NB)

IA = NA

IB = NB

1 IF (IB.NE.0) THEN

ITEMP = IA

IA = IB

IB = MOD(ITEMP, IB)

GOTO 1

END IF

NGCD = IA

RETURN

END

assembly code in Figure 1.1 on page 9. You can actually understand some of what is going on!^5

(^5) Really! The words are readable! Surely PRINT, READ, and IF make more sense that stw, lwz or bne.

1.5. “HIGH-LEVEL” PROGRAMMING LANGUAGES 13

  • Perl^9
  • Python
  • Ruby
  • Tcl/Tk
  • General-purpose compiled languages, usually derived from the language C
  • ADA (USDOD, not based on C)
  • C (AT&T Bell Labs)
  • C# (Microsoft)
  • C++ (Bell Labs)
  • Eiffel (ISE, not based on C)
  • Java (Sun)
  • Objective-C (Apple Macintosh)
  • Interpreted languages that are part of a software package adapted for a specific kind of problem
  • Numerical mathematics: MATLAB, Octave
  • Statistics: R, SAS
  • Symbolic computation and computer algebra: Maple, Mathematica, SAGE^10

In the last line, the reader will notice Maple and SAGE. This course focuses on these two pack- ages. The reason behind this is that in this course we want to see how computer programming will help us solve general problems in mathematics. The design of a programming language in a computer algebra system like Maple or SAGE allows the user to express mathematical relationships with relative ease and to simplify these relationships. This has made it very popular for use in educational and research institutions. Although the use of Maple continues to grow in education, industry, and science, very few programmers will ever need or use Maple. Because of this, we will try to address our problems, and their solutions, as generally as possible, using an vague language called pseudocode as well as programing listings. We show Maple’s solution to these two problems in Figure 1.3, and show the pseudocode in Figure 1.4. Compare the two with the assembly code given in Figure 1.1 on page 9 and the FORTRAN 77 code given in Figure 1.2 on page 11. I am sure that the reader will agree that Maple is more readable than they, while the pseudocode is most readable of all. You may have noticed that the Maple code uses the characters <> where the pseudocode uses 6 =. After more than 50 years of computer programming, keyboards continue to lack many of the keys necessary for basic mathematical expression. You will not find the symbols ≤ and 6 = on the keyboard. Programming languages have developed different ways to overcome this difficulty. Most of them, including Maple, use the “double pair” < = to represent ≤, but in Figure 1. we see that FORTRAN prefers instead the sequence of characters .LE. Figure 1.5 shows how different computer languages represent 6 =.

Exercises

(^9) Perl is a little like APL: expressive and abstract, but difficult to read. Tcl/Tk programmers refer to Perl as the

first “write once, read never” language. You probably have to be a computer scientist to have a hope of getting this joke, and you probably have to have programmed in Perl to find it funny. (^10) Properly speaking, SAGE does not have its own language, but uses Python (a well-known and well-regarded

scripting language) to tie together several different computer algebra packages, including (but not limited to) GAP, Linbox, Maxima, NTL, Pari, and Singular.

1.5. “HIGH-LEVEL” PROGRAMMING LANGUAGES 14

FIGURE 1.3. Maple program to compute the gcd of two integers.

Euclidean_Gcd:=proc(a,b)

find the greatest common divisor using the Euclidean algorithm

local ia, ib, itemp: if a<=0 or b<=0 then error("Inputs must be positive!"): end if: ia := a: ib := b: while ib<>0 do itemp := ia: ia := ib: ib := itemp mod ia: end do: return ia;

end:

FIGURE 1.4. pseudocode to compute the gcd of two integers

algorithm Euclidean_Gcd

inputs a, b ∈ Z +

outputs gcd (a, b )

if b ≤ 0

error: b must be a positive integer

if a ≤ 0

error: a must be a positive integer

while b 6 = 0

ol d _a := a a := b b := ol d _a mod a

return a

FIGURE 1.5. Common solutions in computer languages for representing the mathematical expression a 6 = b. FORTRAN A.NE.B C, C++, C#, Java, Python a != b Pascal, Maple a <> b Modula, Oberon a # b Ada, Eiffel a /= b

CHAPTER 2

Elementary concepts: algorithms and pseudocode

In this chapter, we will start looking at elementary concepts of programming, using both pseudocode and Maple. Before we look at them, however, we first have to discuss the notion of an algorithm.

2.1. ALGORITHMS

Computational mathematics focuses on the design and analysis of ways to solve mathematical problems. The end result usually takes the form of a list of instructions. For example, suppose that I want a program that will find all real-valued solutions to a uni- variate linear equation mx + b = 0 for x, when m and b are known real numbers. Such a program would be useful anywhere univariate linear equations would be useful, and univariate linear equations are extremely common. In order to solve the equation, the computer must consider the following: (1) Is m = 0? If so, then the set of solutions is R when b = 0, and ; when b 6 = 0. (2) Otherwise, m 6 = 0. Then the set of solutions has one element, −b /m. We make the following observations about our list. First, there are well-defined inputs, or known values. In this problem, the inputs are m and b. We sometimes call inputs parameters or arguments. Second, there is a well-defined output, or unknown and desired value. In our case, that value is a real number x that satisfies the equation mx + b = 0. Third, there is a list of instructions that will finish in a finite amount time. This aspect of finiteness is essential to computation; we are not interested in computations that will never finish. In fact, we are not even interested in computations that will take a very long time, but that is another issue. These three considerations lead to the definition of an algorithm. An algorithm consists of well-defined inputs, a well-defined output, and a list of instructions that produces the desired output in a finite amount of time. Thus, computational mathematics consists in the design and analysis of algorithms.

Exercises

2.1: Define the following terms: algorithm, input, output. 2.2: True or false? (a) Some algorithms are not useful because there is no guarantee that they will finish. (b) Some algorithms are not useful because although there is a guarantee that they will finish, it will take more time to finish than we have to wait. 2.3: Try to follow the list of instructions for solving a linear equation to solve the following equations:

  • 2 x + 4 = 0 16

2.2. PSEUDOCODE 17

  • 0 x + 4 = 0
  • 0 x + 0 = 0 Is the final result correct each time? 2.4: Rewrite the list of instructions for solving a linear equation so that it outputs all integer solutions of mx + b = 0, where m and b are also integers. Recall that the integers consist of the set Z = {... , −3, −2, −1, 0, 1, 2, 3,.. .}. (No fractions allowed!) 2.5: Write a list of instructions that uses the greatest common divisor of two integers to find the least common multiple. You do not have to explain how to find the greatest common divisor of two integers, but you should refer to the pseudocode given previously in the text. Big Honking Hint: Use the fact that ab = gcd (^) (a, b (^) ) lcm (^) (a, b (^) ). 2.6: Write a list of instructions that finds the sum of two fractions. You do not have to explain how to find the least common multiple of two integers, but you should refer to where you described how to find it.

2.2. PSEUDOCODE

We referred earlier to pseudocode as a vague^1 language used to describe the steps to solving a problem. Pseudocode is enormously useful for programmers, because you can use pseudocode to sit down with pencil and paper and sketch a solution to the problem in a manner that is both natural and independent of the choice of computer language. Once we have described an algorithm in pseudocode, it is relatively easy to implement it in many different computer languages.^2 Pseu- docode is really the hardest part of computer programming, and this brings us to the Second Principle of Computer Programming: Describe your program in pseudocode before sitting down at the computer. There is no set convention for pseudocode. One author’s pseudocode almost always differs from another’s. There are, however, certain conventions to follow, and we will respect them in this book. The first set of standards is shown in Figure 2.1. You should check the pseudocode of Figure 1.4 on page 14, to see how it compares to the standards given here. The conventions refer to keywords; what are those? Keywords are a set of common com- mands that either highlight important data or direct the flow of the program. A preliminary list of keywords is given in Figure 2.2. As we proceed through the text, we will add a few more keywords to our pseudocode, but not many. You have already met some of these keywords; we describe the rest briefly. return indicates that the algorithm has finished successfully. If one or more variable names follow it, these are the data promised by the outputs keyword.

(^1) Calling pseudocode “vague” can given the wrong impression. Good pseudocode is actually not vague at all, but makes the method of finding a solution crystal clear. When we use the term here, we mean that pseudocode often describes a step in general or natural language that, in a fully realized computer program, requires a great deal more detail. (^2) This assumes that the pseudocode is actually correct. I recently implemented the pseudocode for a famous algorithm in two different languages: Maple and Eiffel. I had two different versions of the pseudocode, and a copy of the source code for a third language called MAGMA. In spite of this, the process took me about two weeks working every day, because both copies of the pseudocode had errors, and I am not accustomed to reading MAGMA source code.

2.2. PSEUDOCODE 19

FIGURE 2.3. Pseudocode to solve mx + b = 0 algorithm Solve_Linear_Over_Reals inputs m, b ∈ R outputs x ∈ R such that mx + b = 0 if m = 0 if b = 0 return R —At this point, m = 0 and b 6 = 0. return ; —At this point, m 6 = 0, so there is one unique solution. return −b /m

FIGURE 2.4. Syntax of the while keyword in some computer languages Pseudocode while condition instructions Maple while condition do instructions end do Python while condition instructions C-like while(condition) do { instructions } Pascal WHILE condition BEGIN instructions END Eiffel from until opposite of condition loop instructions end

We can use these to write pseudocode for the list of instructions given in Section 2.1 on page 16. Compare the list with the pseudocode in Figure 2.3. Once you have the pseudocode for a program, you can write a program for it. This step is much easier than writing pseudocode; however, there are still pitfalls to beware. If you have ever translated from a foreign language into English, or vice-versa, then you know that translation is not merely a matter of rewriting words. Groups of words often have meanings in English that they do not have in other languages. For example, the Italian phrase, Dallo un’ occhiata ogni tanto means to Keep an occasional eye on him. However, the actual words translate as Give him a look each much, which makes no sense at all in English! We distinguish this difference using the terms syntax and semantics. Syntax refers to the arrangement of words. The actual meaning of this arrangement constitutes the semantics of a language. Computer languages are not much different. There are, of course, slight variations in syntax, and Figure 2.4 illustrates one such example. Notice that Python comes closest to the pseudocode, requiring new lines and indentation. The other languages allow one to write everything on one line, and use keywords to indicate where each group of instructions begins and ends. Actually, C-like languages use braces, but they are equivalent to keywords. Likewise, each language has its own semantics, and in addition offers certain built-in features that make certain kinds of programming easier. A good example would be sets. Maple, for example, allows one to work with sets, which are important for solving mathematical problems. Pascal offers sets, but they are not as well-developed as Maple’s. None of the other languages offers sets directly. If you want to model a union of two sets, the pseudocode looks like a ∪ b

2.3. OUR FIRST MAPLE PROGRAMS 20

and the Pascal looks like a + b , while using sets in each of the other languages requires the mathematician either to find a library of programs that organize sets. If no such library exists, she must write one herself, and this is not easy. In C, for example, one would have to make extensive use of pointers. Certain C-like languages, as well as Python and Eiffel, provide a standard data structure called a linked list that help one implement a set. However, each language has its own syntax and semantics for linked lists, making the programmer’s job difficult.

Exercises

2.7: Write pseudocode to solve the linear equation mx + b = 0 over the integers, where m, b ∈ Z. (See Exercise 2.4 on page 17.) 2.8: Write pseudocode to find the least common multiple of two integers using the greatest common divisor. (See Exercise 2.5 on page 17.) You do not have to explain how to find the greatest common divisor, but you should reference the pseudocode given on page 14. Since the name of the algorithm was Euclidean_Gcd, you do this by writing Euclidean_Gcd(a, b ). 2.9: Write pseudocode to add two fractions. (See Exercise 2.6 on page 17.) You do not have to explain how to find the least common multiple of two integers, but you should reference the pseudocode. 2.10: Write pseudocode to compute the derivative of a monomial xn^. Be careful about the case n = 0; it requires a special case. Hint: One of the keywords described is very useful for considering different cases; which one?2.

2.3. OUR FIRST MAPLE PROGRAMS

We turn our attention to the practical task of writing Maple programs from pseudocode. Figure 2.5 diagrams how to translate each keyword of Figure 2.2 into Maple. We will use this to implement our algorithm of solve a linear equation over the reals. The implementation appears in Figure 2.6. Notice that every Maple instruction ends with a colon! Comments do not have to end with a colon, and although if/then commands end with a colon, it appears after an end if. The while/do command is similar; its colon appears after an end do. Sometimes, the programmer has to be creative, and we can see this in the third line of Figure 2.6. Despite being a computer algebra package, Maple has no built-in way to represent the set of real numbers! Our algorithm, therefore, must make a choice of how to represent it. We have made the awful choice of using {−∞... ∞}. Awful though it may be, it reflects an important strategy of applying creativity to express ideas. Many ideas can be described in different ways, so different programmers may have different solutions. Some solutions have advantages over others; other solutions make tradeoffs. There is not always one right answer; the right answer is the one that takes the inputs and produces the desired output in a finite number of steps. If you want to test the program written above, you have two options. One is to type it into Maple’s worksheet mode as shown in class, then call it using different inputs:

  • Solve_Linear_Over_Reals(3,5);
  • Solve_Linear_Over_Reals(0,5);
  • Solve_Linear_Over_Reals(0,0);