<<

1151 PROGRAMMABLE PROGRAMMING INSTRUCTIONS TABLE OF CONTENTS

INTRODUCTION. • . • . . • • . . . • . • . • . . • • . . • • . • • • . . . . . • . • . . . • 1

GENERAL.. • . . • . • • • • • • . . . • . • . . . • . • • • . . . • • • • • • • . . • • • • . • 1 Interchange Key . . • • • . • . • . • . . • • . • • • . . • • . . . • • • . . . • . . • • . 1 Learn Key . • • • . • . • • • . • • • . • . • . • . . • . . . . • . . . . . • . • . • . . • • 1 Auto Key . . • • • • • • • . . • • . . . • . • • • • • . . . • . • . . . • . • • . • . • . • . 2 Progr am Reset Key. . • . • • ...... • . . . • . . • • . • . • . • • • • • . • . • . 2 Looping. • . . . . . • • • • • . . • • . • . • . • ...... • • • . • . • • • • . • . . . • 3 Decimalization and Overcapacity. • . . • • • . . • • • . . . • . . . . . • • • . • • 4 Program Steps • • • • • ...... • . . . . • • • . • . • . . . . • • . • • • • . 4

BASIC PROGRM1MING. . . . . • • . • • • . • . • . . . • . . . . . • • • . • . • . • . • 5 Simple Programming. . • . . • . • . • . • • • • . . • • . . . . • . • . • • • . • . • . 5 Stack Constant • . • . • . • . . • • . • . . • . • ...... • . . • ...... • . . • . • 5 Payroll Application. • . • . . • . • . . . . • . . . . • . . . . . • . . • . . . . • . • . 6 Two Totals in the Stack • . • . • . • • • . . . • . • . • . . • . . • • • . • . . • • . • 7 Cost/Sell Quotations . • . . • • • • . • . • • • ...... • • • • • . . . • • • • . • 8

MULTIPLE AND ITERATIVE PROGRAMS. . . • . . . . • . . . . . • • • . • . . • 9 Looping at a Stop Command. • • . • . • • • • • • . . . . • . . . • • . . . . • . • • • 9 Invoicing. • . . . • . • . • • . . . . • . • . • . • . . • • . • . . . • . • • • • . . . • .. 11 Iterati ve Programs. . • • . . . • . • • . . • ...... • • . . • . . • • . . . • .• 12 Compound Interest. . . . . • • • . • . • • • . • . • . . . • . • • • . • . • . • . • . •. 13 Square Root. . . . . • • . • • • . • . . • • . • • . . . • • . • . . . • • . • . • • . . .. 14 Iterative Programs - General. . . . • . • • . • . . . • . • . • . • • • . . . • . •. 16

SPECIAL TECHNIQUES. . • • . . . • • . . . • . • • . . • . . • . . . • ...... •• 17 General. • . • • • . . • • . • • • . . . . . • . • . • . • . . • • • ...... • . . .. 17 Number Generation. . . . • • . . • . . • • . • • • • . • • • • • . . • • • . • • • . .. 17 Round-off in Division. • • ...... • • . . . • • • . • . • • • • . • • • . • . . .. 17 Comparison Tests. . . • . . . • . • . . . • • • • ...... • . . • ...... •. 18 Sequence Skipping. . . • . . • . • . . . • . • . . . • . . . • . • . • . • . • . • • • •• 19

Published by Friden Sales Promotion Department, Rochester, New York INTRODUCTION

Welcome to the world of "customized cal­ 1151 Operating Instructions, three applica­ culators·. The Friden* 1151 Programmable tion manuals are available: SP 9495, Statis­ Calculator can be customized to your indi­ tics, SP 9496, Finance, and SP 9497, Sci­ vidual calculating requirements. The 1151 ence and Engineering. These booklets des­ benefit that makes this possible is Program cribe solutions to many problems for which Learning. the 1151 is particularly suited. In this manual, 1151 Programming In­ 1\1 anual operation of the 1151 is covered structions, a working knowledge of the in detail in SP 9474, 1151 Operating In­ manual operation of the 1151 is assumed. structions. That manual also contains Let's start by discussing the 1151 keys that information about the Program Learning are particularly important to Program capabilities of the 1151. In addition to the Learning.

GENERAL THE INTERCHANGE KEY Divide Equals Interchange The INTEHC HANGE key interchanges the Duplicate contents of the bottom two registers in the To Memory stack. Some calculations require that the From Memory divisor in a division problem be calculated Print before the dividend. This often results in Stop the divisor being contained in R2 with the dividend in HI. The I:\TEHCHANGE key The manual functions, Clear, Clear Stack, allows us to eXChange the contents of Rl and Stack Read-Out cannot be programmed. and R2, thus placing the divisor in HI so that we may properly divide. Added benefits These commands are self-explanatory, ex­ of this powerful key are that a constant can cept, perhaps, for two: Print and Stop. You be retained in the stack, or that two totals must instruct the 1151 as to which answers can be carried in the stack. Examples are to be printed on the tape during auto­ given in this manual are Payroll and matic operation by de pre s sin g F LHST Cost/Sell Quotations. Nl\IBH/PHINT when they occur in HI. When programming an application, ask yourself at each step if you want the contents of Rl to THE LEAHN KEY print on the tape during automatic operation.

DepreSSion of the LEAH)\; key places the A Stop Command in a program sequence 1151 into a learning condition. Until the automatically stops automatic operation. It LEARN key is restored to its original is placed in a program whenever a manual pOSition by depressing the PHOGHAIII HE­ keyboard entry is made while the 1151 is SET key, the 1151 will learn in sequence learning an application. Stop Comm ands are the functions required to perform the de­ used for three reasons: sired calculation. 1. To allow for manual entries of variable The following commands are programmable: numbers into the program. Plus 2. To allow for manual calculations, the Minus answer, or answers, to which to be Times Equals used in the program.

*A Trademark of THE SINGER COMPANY 1 3. To separate a portion of a program Clear from the remainder of the program Clear Stack instructions. Stack Read-Out

The functions Clear and Clear Stack can be The first reason for using a Stop Command accomplished through special program­ is most important. What use would there ming. For example: be for programming if you could not use the learned program with a different set of variables? To Clear HI:

1. DUP The second reason for using a Stop Com­ 2. - (0 in RI) mand is important particularly when an application requires more than 30 program steps. Normally, the Stop Command would To Clear Stack: be the first step in the program so that the first part of the application could be done 1. DUP manually and the program entered to com­ 2. plete the problem. Though it takes a little 3. x= more programming finesse, we could design 4. x= (0 in RI, R2, R3, R4) our program so that we have a Stop Com­ mand somewhere in the middle of a sequence of instructions for such manual calculations. The function Stack Read-Out can be accom­ plished only by destroying the contents of 2 of the 5 registers in the calculator. The third function of a Stop Command points up the greatest advantage that the 1151 has over any other programmable THE AUTO KEY calculator to date: the capability of storing several programs at one time, to be used At any point where a manual entry must be indi vidually or in combination, at the option made in an established program, the num­ of the operator! An example of such a ber is indexed on the keyboard and entered program is SP 9541, Coefficient of Linear into the calculator by depressing the AUTa Correlation. Three programs in one are key. The 1151 will then continue with the used. The operator uses the first ana automatic program using the new number. second programs to obtain the sum of x, When the AUTO key is depressed, the num­ the sum of x2, and the xy values. Then the ber indexed on the keyboard is printed on operator uses only the first program to the tape and identified by the symbol "F". compute the sum of y and the sum of y2. Finally, the operator uses only the third THE PROGRAl\] RESET KEY program to calculate the square root of the value obtained by a manual calculation done Depression of the PROGRAM RESET key at the Stop Command between the second cycles the 1151 program memory back to and third programs! Let's face it. Multiple­ the first step in the calculating procedure. part programs can be very complicated to If the first step in the learned program was devise. But they do not have to be compli­ a manual keyboard entry (Stop Command), cated to use! the 1151 will stop, ready to accept a new manual entry. If the first step in the pro­ gram is not a manual entry, the 1151 will As stated on page 1, there are three man­ automatically carry out all the steps up to ual 1151 functions that cannot be program­ the first point where a manual entry is to med. be made and then stop.

2 LOOPING The third reason for a Stop Command brings up the topic of "manual looping". A manual A sequence of instructions learned by the loop may be accomplished at any Stop Com­ 1151 forms what may be referred to as a mand in a program by depressing the "loop". The diagram, below, illustrates PROGRAM RESET key. This will return, this: or "loop", the 1151 to the first step in the program sequence. The diagram below, illustrates this operation.

TO DUP MEMORY

PHiKT X= -'- = = + DUP

FHOM ~lE~10RY

+ X= DUP FHO~l ~lEMORY FHOM ~lnl0HY + ..,- = +

FRO~l ME110RY

Notice that in the hypothetical sequence shown, we have two Stop Commands. He­ member what was stated preViously about the uses for a Stop Command: This ability to perform a manual loop allows us to re-use, indefinitely, the first portion 1. To allow for manual calculations. of a program, avoiding the remaining in­ 2. To allow for manual entries. structions. The 1151 is the only desk-top 3. To separate a portion of a program programmable calculator that offers this from the remainder of the program. program flexibility.

3 DECIMALIZATION AND OVERCAPACITY PROGRAMMING STEPS

The position of the Answer Decimal is The 1151 will learn any sequence of up to immaterial when programming the 1151. 30 steps of programmable instructions. Each programmable command counts as one step. Remember that if while the 1151 If the operator is using a learned program is learning a sequence: and inadvertently has set the Answer Dec­ imal in the wrong position or incorrectly 1. A number is indexed and the FIRST enters a variable, it is possible that an NMBR/ PRINT key depressed, a Stop answer will exceed register capacity. If Command (1 step) is recorded. this happens, the automatic operation will 2. A number is indexed and a function stop, and the symbol "En will print on the key (X=, +, DUP, INTERCHANGE, tape. The 1151 is now at the instruction etc.) depressed, a Stop Command (1 in the program where overcapacity oc­ step) and the key function (1 step) are curred. recorded. The operator should depress PROGRAM Most common applications require less RESET to return to the first step in the than 30 program steps. Therefore, it is program, then check the decimal setting not normally necessary to count the num­ and the numbers entered for errors. ber of steps in a program.

4 BASIC PROGRAMMING

SIMPLE PROGRA;\IMING Index Touch

Let's start with a simple program. The 3 (A) AUTO problem is this: 4 (B) AUTO (Second value prints)

Formul-t. A2 + B2 = C The 1151 has accepted the new values for Data: .f..ll.. A and B, and printed the answer, C. The 1 2 machine has automatically reset to Step 1 3 4 in the program sequence and stopped, wait­ 5 6 ing for the next value of A:

Problem: For each of the 3 sets of values Index Touch for A & B, find the corresponding value of C. 5 (A) AUTO 6 (B) AUTO (Third C value prints) Index Touch Programming for such problems as this is LEARN obviously simple. We merely have to de­ 1 DUP press LEARN, calculate the problem once X = (just as you would manually, except that you 2 DUP must touch PRINT when an answer is in X= Rl), and depress PROGRAlIl RESET. For a + second set of values, merely enter each, PRINT (First C value prints) in the proper sequence, with the AUTO key. PROGRAlII RESET The answer - or answers - automatically print, and the 1151 automatically resets, We have now programmed the 1151 for this ready to accept another set of values. application. In this case (it is not always true, as you will see later on!) we were able STACK CONSTA"T to calculate our first answer while the 1151 was learning the formuLt. Let's look at the The easiest way to hold a constant number actual commands learned by the 1151: would be to place the constant in the Mem­ ory Register, recalling it for use. In some Step Command applications, however, it is not practical to use the Memory Register for a constant 1. Stop (for entry of A value) number. For such occasions, let's describe 2. Duplicate a simple calculation where one term is a 3. X = constant and we retain the constant in the 4. Stop (for entry of B value) stack. 5. Duplicate 6. X = Formula: A2 + B2 = C 7. + 8. Print (to print C value) Data: A 1 The 1151 is now at Step I, waiting for the 2 next A value. Let's get Our second answer: 3

5 Problem: With B2 = 4 a constant for the consider a payroll application. (Payroll three problems, find the values for C cor­ calculations may be programmed in many responding to the given values of A. ways, depending on the deSires and re­ quirements of the user. This is only one Index Touch of many possible solutions.)

4 (B2) Dt.:P Data: LEARl' 1 DUP Regular hours - 40 X = Overtime hours - 6 + Pay rate - $2.30/hr. PRINT (First C value prints) INTERCHANGE For this example, we assume that the over­ DUP (B2 = 4 is duplicated) time pay rate is 1.5 times the normal rate. PROGRAlI! RESET This is what our problem looks like: The 1151 is now at Step 1 (Stop Command) in the program, waiting for a new value of 40 x $2.30 = $ 92.00 A. The constant, B2 = 4, is in Rl and R2. 9 (6 x 1.5) x $2.30 = 20.70 The last two program steps automatically Total = $112.70 regenerate our constant. Why did we use the Il'TERCHANGE key to place the con­ We are looking for dollars and cents an­ stant number into Rl for duplication? swers, so we set the Answer Decimal on 2.

Manually, this could be done with the CLEAR Index Touch key, to clear the value of C in Rl, thus dropping the constant into R1. However, the 40 TO MEMORY CLEAR key is not a programmable function LEARN key! 2. 30 DUP DUP Let's calculate the second C value: FROM MEMORY X = Index Touch PRINT (Regular pay prints) I INTERCHANGE (Pay rate, 2.30, is 2 AUTO (Second C value prmts) now in R 1) 9 X = PRINT (Overtime pay prints) Our program sequence has duplicated the + constant and the 1151 is ready to accept PRINT (Total pay prints) the A value for the third calculation: INTERCHANGE (Pay rate, 2. 30,is now in R 1) Index I Touch PROGRAM RESET 3 AUTO (Third C value prints) Our application is now programmed; we are at Step 1 in the program, the Stop Now, let's look at a common application Command for entry of the pay rate for the where this ability to hold a constant in the next employee. stack is important. Let's take a close look at our program. First, we have a constant, 40 , which is kept PAYROLL APPLICATION in memory. Second, we are retainingacon­ stant in the stack using the INTERCHANGE To illustrate the use of the INTERCHANGE key. This second constant is the pay rate of key to keep a constant in the stack, let' s $2.30.

6

, There is a yery big difference between the Note that the stack constant is now 3.601 stack constant shown in the preceding sec­ If the next employee's pay rate is $3.60/hr. tion, and the stack constant in this applica­ we merely depress AUTO. If the next tion. The constants are retained in the same employee's rate is different, index the manner using the IKTERCHANGE and DUP rate, then touch ACTO. keys. The difference lies in the fact that in this payroll program, the operator has the option of using the constant (the pay rate) TWO TOTALS 11\ THE STACK or using a new pay rate. Quite frequently, we are faced with the prob­ Let's say that the next employee is to be lem of accumulating two (2) totals at the paid at the same pay rate. same time. Generally speaking, the easiest way to do this is to carry one total in the Data: stack, the other in memory. Often, however, Regular hours - 40 it is advantageous to be able to carry both Overtime hours - 10 totals in the stack, leaving the I\Iemory Pay rate - $2.30/hr. Register available for accumulation of an additional total, or perhaps using it to re­ We are at Step 1 in the program, the Stop tain a constant num ber. Command at which the pay rate is to be entered. However, our program has re­ Let's take a simple example of accumulat­ tained the pay rate of $2.30 as a constant, ing two totals in the stack: now in Rl: Data: x Though a Stop Command allows for a man­ x.. ual entry, an entry need not be made to 1 5 continue the program. If the AUTO key is 2 6 depressed with no entry being made, the 3 7 1151 accepts the contents of R1 as the 4 8 entry. and proceeds with the program. Totals 10 26

Let's solve the second problem. Problem: We are to add both columns si­ multaneously. Index Touch Index Touch AUTO (Regular pay prints) 15 (10 x 1.5) AUTO (Overtime, then total CLEAR STACK pay prints) LEARN Again, the pay rate of $2.30 has been re­ 1 (First x + tained and is in Rl, ready to be used again. value) INTERCHANGE Let' s say that our pay rate changes: 5 (First y + value) Data: INTERCHANGE PROGRAM RESET Regular hours - 40 Overtime hours - 4 Let's look at the program. Note that the Pay rate - $3.60/hr. last step places the number"I"(really, the subtotal to this point of the x values) into Index Touch Rl, and the number "5" (the subtotal to this point of the y values) in R2 . There are no 3.60 AUTO (Regular pay prints) Print Commands in the program because 6 AUTO (Overtime, than total pay we are not interested in seeing subtotals - prints) only the final totals.

7 Let's enter our remaining x and y values: in the preceding section. Set the Answer Decimal on 2. Index Touch 2 (x) AUTO Index Touch 6 (y) AUTO 3 (x) AUTO CLEAH STACK 7 (y) AUTO LEARN 4 (x) AUTO 10 (Quantity) TO MEMORY 8 (y) AUTO 3.95 (Cost/Unit) FROM MEMORY X= As you can see, each x value is added to the PHINT (Cost. $39.50, Line x subtotal. The contents of RI and R2 are (1) prints) interchanged, placing the y subtotal in RI. + Then, the corresponding y value is entered INTERCHANGE and added to the y subtotal. Finally, the 4.85 (Price/Unit) FROM MEMORY contents of RI and R2 are interchanged X= again, placing the x subtotal in HI, the y PRINT (Sell, $48. 50. Line subtotal in R2. (1) prints) + After all x and y values have been entered, INTERCHANGE we need only touch the PRINT key. The PHOGRAM RESET resulting Stack Read- out shows the total of the x values (10) in RI and the total of the This application differs from the example y values (26) in R2. shown in the previous section. We are using the Memory Register to hold a con­ Now, let's take a look at a practical appli­ stant used in the two multiplications in the cation where this capability is put to use. program, and we are printing the products of these two multiplications. COST/SELL QUOTATIONS

In this application we are going to compute Let's enter the figures for Line 2 of our individual cost and sell, and the total cost quotation: and sell, figures for a quotation. -- Index Touch Data: Quantity Cost/Unit Price/Unit 12 AUTO 8.91 A UTO (Cost, $106.92, Line (2) prints) Line (1) 10 $3.95 $4.85 9.95 AUTO (Sell, $119.40. Line Line (2) 12 8.91 9.95 (2) prints) Line (3) 23 1.26 2.49 The 1151 has accumulated the cost and sell To find the cost and sell figures for each figures from Lines 1 and 2. Let's complete line we must make two calculations: the problem:

Cost = Quantity x Cost/Unit Index Touch Sell = Quantity x Price/Unit 23 AUTO The quantity for each line is a constant for 1.26 AUTO (Cost. $28.98. Line these two calculations. Therefore, we will (3) prints) use the "'I emory Hegister to hold it as a 2.49 A UTO (Sell, $57.27, Line constant. When each of our two answers (3) prints) occurs in HI we will cause it to print. PHINT (Stack Head-out: total cost. $175.40 in Additionally, we will sum the cost and sell Rl, and total sell, figures in the stack, by the method shown $225.17, in H2, print)

8 MULTIPLE AND ITERATIVE PROGRAMS

LOOPING AT A STOP COMMAND To find the first value of A, we would have to use the first program four (4) times - The 1151 has been designed so that two or for B=.2, C=.3, D=.4, and E=.5. We would then more separate programs in one may be use the second program once to produce learned and used separately or in com­ the value of A. How do we combine these bination. Let's look at a fairly simple prob­ two programs into one? lem where this capability can be used. Problem: A = (1/2) (B2 + C2 + D2 +E2)3 We have a constant, 2: let's put this in memory before we begin programming: BCD E Index Touch .2 .3 .4 .5 2 TO :\lEMORY .6 .7 .8 .9 LEARN o DUP 1.0 1.1 1.2 1.3 x = + There are two separate problems here: o DUP (1) Sum the squares of the corresponding DUP values of, B, C, D, and E. x = (2) Raise that answer to the third power x = and divide by the number 2. FnOl\1 l\IEMORY + = Let's see what the separate programs for PRINT these two problems would look like. PHOGRAM HESET Problem (1) Let's l ook at the commands that the 1151 Index Touch has learned:

CLEAR STACK Step Command LEARN B DUP 1. Stop x = 2. Duplicate + 3. x = PROGRAM HESET 4. + 5. Stop Problem (2) (Assume B2 + C2 + D2 + E2 6. Duplicate is in R1) 7. Duplicate 8. x = Index Touch 9. x = 10. From l\lemory 2 TO 1I1EMOHY 11. -:- = LEARN 12. Print DUP DUP There are two (2) Stop Commands in the x = program: Step 1, for entry of variable x = numbers, and Step 5, to separate the first FHOllI MEMORY and second portions of the program. As mentioned previously, at any Stop Com­ PIUNT mand, we may manually loop to the first PROGRAlIl RESET step in the program.

9 It was stated earlier that we cannot always The answer to the first problem has print­ calculate the anSwer to the first problem ed, and the 1151 is again at Step 1, waiting as the 1151 is learning the application. This for the next variable. The constant, 2, is is an example of such an application. still in memory, and the answer to the last problem is in H.1. The first step is to clear HI; otherwise its contents will be added into In general, usable answers are not generated the next calculation. Let's perform the sec­ while the 1151 is learning if one or more ond calculation. Stop Commands are used in a program for the purpose of manually looping. Index Touch

Therefore, it is immaterial what numbers CLEAR are used to create Stop Commands. We .6 ACTO have chosen to use the number zero (0) PHOGHA:lJ RESET in this case. . ( AUTO PHOGHA;\l RESET The 1151 is now at Step 1 of the program .8 AUTO waiting for the first variable. Set the An­ PHOGRAi\1 HESET swer Decimal on 2. .9 AUTO AUTO (R 1 at Step 5, then, Index second A value, 6.08350, ITouch print. ) .2(B) AUTO And for the third set of values: The 1151 is now at Step 5 of the program. There are three more variables to pro­ cess (C=.3, D=.4, and E=. 5) using the first Index Touch portion of the program. Manual looping makes it possible: CLEAR 1.0 AUTO Index Touch PHOGRA:\! RESET 1.1 AUTO PflOGRAi\! RESET (Manual PROGHAM RESET loop) 1.2 AUTO .3 AUTO PROGRAM RESET PROGRA:\I RESET 1.3 AUTO AUTO AUTO (R 1 at Step 5, then, PROGRMI RESET third A value, 76.13665, .5 AUTO print. )

We are again at Step 5, and we have pro­ cessed the four variables for the first value We have only used four variables (B, C, D, of A. We are now ready to use the second and E) in the first portion of the program. portion of the program: all that is required Obviously, we are not limited to that num­ is to depress the AUTO key: ber: any number of variables may be pro­ cessed, providing register capacity is not Index Touch exceeded.

A UTO (Contents of Rl at Step 5, then, first Let's take a look at a very practical ex­ A value, .07873, ample of manual looping, an invoicing print. ) application.

10 INVOICING Index Touch

The common involClng problem is a good PRINT illustration of manual looping to re-use a portion of program several times before PRINT using the remainder of the program. DUP o x ; Normally, an invoice is made up of a vary­ PRINT ing number of line extensions, discounts and + taxes. The program fo r the problem must PRINT allow for any number of extensions. What PROGRAM RESET answers should print depends on the needs of the user. If invoices are being checked, Let's look at the actual commands learned: perhaps only the net amount should print. In this example we are assuming that invoices Stop Command are being pre par e d. Therefore, we will cause the following answers to print: 1. Stop (Quantity) 2. Stop (Price) 1. Each extension 3. x ; 2. Invoice gross 4. Print (Extension prints) 3. Amount of discount 5. + 4. Subtotal after discount 6. Stop (To separate portions 5. Amount of tax of program) 6. Invoice net 7. Duplicate 8. Stop (Discount %) Problem: 9. x ; 10. Print (Discount prints) Quantity Price 11. 12. Print (Subtotal prints) 10 $1.25 ; $12.50 13. Duplicate 13 . 98 ; 12.74 14. Stop (Tax %) 26 2.46; 63.96 15. x ; Gross ; 89.20 16. Print (Tax prints) 7% Discount; 6.24 17. + Subtotal; 82.96 18. Print (Net prints) 3% Tax ; 2.49 Net; $85.45 Look carefully at these program steps. Will this program automatically print all the answers that we require of it? There We need dollars and cents answers with is no Print Command for the invoice gross - automatic round off, so the Answer Dec­ do we need a command for this? imal is placed on 2. When we have completed the last extenSion, Here's the program: the 1151 will be at Step 6 (Stop Command) of the program. At this point we want the Index Touch invoice gross to print, and we want to con­ tinue with the program. The invoice total LEARN is in Rl. IT we depress AUTO to continue 0 FIRST NUl\lBEH the program, the contents of R1 will auto­ 0 x; matically print. Having a separate com­ PRINT mand to print the invoice gross is there­ + fore not required. 0 DUP 0 x ; The 1151 is now at Step 1 in the program.

11 Let's clear the stack before we proceed - Problem: anything in R1 will be added to the first extension. Quantity Price

Index Touch 12 @ $11.12 less 10% = $120.12 8 @ 5.03 = 40.24 CLEAR STACK Gross = 160.36 10 AUTO 8% Discount = 12.83 1.25 AUTO (Extension, $12.50 Subtotal = 147.53 prints) 5% Tax = 7.38 PROGRAM RESET (Man­ Subtotal = 154.91 ual loop) Freight = 25.05 13 AUTO Credits = 10.95 .98 AUTO (Extension, $12.74, Net = $169.01 prints) PROGRMl RESET 26 AUTO Index Touch 2.46 AUTO (Extension, $63.96, prints) CLEAR STACK AUTO (Gross, $89.24, 12 AUTO prints) 11.12 DUP .07 A UTO (Discount amount, .1 x = $6.24, then subtotal, $82.96 - (Discounted price in H1) print) AUTO (Extension, $120.12, .03 AUTO (Tax amount, $2.49, prints) then, net, $85.45, print) PROGHAl\l HESET 8 AUTO The 1151 is at Step 1 in the program, ready 5.03 AUTO (Extension, $40.24, for the next invoice. Let's explore some prints) options available to us. AUTO (Gross prints) .08 AUTO (DiScount amount, It's obvious that our program will handle $12.83, then, subtotal, any number of line extensions. What if the $147.53, print) next invoice involved no discount off the .05 AUTO (Tax, $7.38, then, gross and no taxes? The answer is simple: subtotal, $154.91 print) when you come to the Stop Command for 25.05 + entry of either of these values, enter a 10.95 P R I N T (Net, $169.01, zero! prints)

But what if there is, for example, a line discount, freight charges and credits? If After the 1151 printed the subtotal after these items were standard, we would prob­ tax, it reset to Step 1 in the program. ably write a different program. Let's con­ Since this is a Stop Command and the sub­ sider that they are the exception to the rule, total was in R1, all we had to do was man­ and see how they can be handled by the ually add in the freight charge, subtract the present program. credi ts, and touc h PRINT to obtain the in­ voice net. The 1151 is now ready for the next invoice! Remember that whenever the 1151 is at a Stop Command, we may perform manual ITERATIVE PROGRAMS calculations, then, continue with the pro­ gram. This is exactly what we can do to Essentially, an iterative program is one handle the line discount, freight and credits. which must be repeated several times to

12 produce the answer or answers to one lndex Touch problem. Up to this point we have consid­ ered repetitive problems. The calculating FROl\! MEMORY steps were identical but the starting data x = (P) (1 +t)3 (variables) changed from one problem to the next. In this section, we will consider FROM MEMOHY repetitive use of a program sequence where x = (P) (1 +~4 each pass through the sequence generates the variables for the next pass. P RI N T (S, $1,050.94, prints) Let's take a simple example. PROGRAM RESET

COMPOUND INTEREST We have only indicated, above, that one answer printed - $1,050.94. However, when To find the value at the end of one year of PHOGRAM RESET was depressed, another the principal (P) compound quarterly at an number, $1,104.48, was calculated and annual interest rate (i) we would use the printed ..What is it? following formula: Notice: There are no Stop Commands in the S=P(1+,t)4 program. In the first chapter we stated that when the first step in the program is The interest rate is constant, therefore, so not a Stop Command for a manual entry, is the value: upon depression of the PROGRAM RESET key, the 1151 will proceed to the first Stop (1 +~) Command.

Let's assume: When no manual entries are made while the 1151 is learning a calculation, the 1151 P = $1,000 will automatically place a Stop Command i = 5% per annum, compounded quar­ after the last step in the program. This terly automatic Stop Command does not count or S = (1,000) (1 .!?f)4 toward the total of 30 steps ofprogramming Here is what the program looks like to instruction. solve for the compounded value (S) of $1,000 at the end of one year. Move the This means that when we depressed PRO­ Answer Decimal to 5. GHAl\1 RESET an automatic Stop Command was inserted as the last step in the pro­ Index Touch gram. The 1151 cycled to Step 1 in the program: since this is not a Stop Command, .05 FIRST NUl\IBEl~ it proceeded through the sequence to the 4 = automatic Stop Command. 1 + (1 +;p U we were to use this program to calculate TO l\IE~IOHY the compounded value at the end of one 1000 FIRST :\Ul\IBER year of some other principal at the same LEAH:-;- interest rate, we could place the principal FRO:'>I l\IE;\lOHY in HI and depress PHOGHAi\1 RESET. This x = (P) (1 +il in fact, is what occurred. A new principal, $1,050.94, was in IU; when PHOGHAl\1 FHD;\! MEl\lOHY HESET was depressed, the 1151 accepted x = (P) (1 +t)2 the new principal, then, calculated and

13 printed the compounded value, $1,104.48, Index Touch for the second year! .08 FIHST NUMBEH The principal (P) for each successive year 4 += is a variable generated by the program. 1 + The starting prinCipal for the third year TO :\lE1\10RY is in R1. If we depress PHOGHAM RESET, 2500 FIRST NUMBEH the 1151 will use this value to calculate PROGRAM HESET (De- and print the compounded value at the end press and hold down) of the third year. As long as the PROGRA:o.] RESET key is You could proceed likewise for the fourth, depressed, the 1151 will repeatedly cycle fifth, years, etc. The process can be speed­ through the program sequence, printing ed up, however. the ending balance for each succeeding year: If no manual entries are made while the Ending Balance 1151 is learning, and the PROGRAM RE­ Year SET key is held down, the 1151 will con­ 1 $2,706.08 tinuously cycle through the program se­ 2 2,929.14 quence until the PROGRAM RESET key 3 3,170.60 is released. 4 3,431. 96 5 3,714.86

Let's see how this process applies for this Let's look at another common iterative application. The compounded value after program. two years of the starting principal, $1,000, has printed. Depress and hold down the SQUARE HOOT PROGRAM RESET key. The values for each succeeding year will be automatically cal­ The simplest programmed method for find­ culated and printed: ing the square root of a number is known as Newton's Method of Approximations:

Year Ending Balance

3 $1,160.75 4 1,219.88 The symbol "=:<" is read, "is approximately 5 1,282.03 equal to."

The number we are taking the square root Since there are no Stop Commands in the of is "N": "a" is an approximation for the program, it may not be obvious how it is square root. When the values for "N" and used to determine compounded values for a "a" are substituted into the formula, we second problem. Actually, it is quite simple: obtain a new, more accurate approximation. using the new principal and interest rate, Inserting the new approximation into the perform the manual calculations preceding formula, we obtain a still more accurate depression of the LEAHN key. Then, depress approximation for the square root of "N". and hold down the PROGRAi\! RESET key. There are two constants in the formula: "N" and 2. The value of "a" is a variable Let's say that: generated by the formula.

P = $2,500 Before we write the program for square i = 8% per annum, compounded quarterly root, let's touch briefly on a topic covered

14 later in more detail - number generation. lr.dex Touch

Here is an equation that always has the same FROM MEMORY ] answer: DUP

x + x 2x -- = - =2 [ ~~Ol\1 l\1El\10RY x x

Regardless what value we assign "x" the PRINT (Second approxima­ answer is always the number 2. Of what tion, 12.45833, prints) importance is this? What if we have the PROGRAM RESET (Third need for a constant, 2, in a program, but, approximation, 12.44990, because of the nature of the problem, prints) have no way to carry that constant in the machine. We can very often solve that Our program automatically retains 155 (N) problem by using the above equation. Let's as a constant. The constant number 2 is show that it does work using an arbitrary generated by the bracketed steps. Each value for x: new approximation calculated becomes the new variable, "a", for the next pass through lndex Touch the program. The last approximation cal­ culated is in Rl. Depress and hold down 37 (x) TO l\1E:\10RY PHOGRAM RESET: FROM l\lEMOHY DUP Fourth Approximation = 12.44989 + (x + x) Fifth Approximation = 12.44989 FRO)'1 l\1EMORY ;..::;: The fourth and fifth approximations are identical. When this occurs, we have the The answer that printed was 2. Now let's answer. Regardless of the initial approx­ use this ability to generate the number imation we choose, the anSwers obtained 2 in the program for square root. The through the program will eventually repeat program is similar to the one for com­ to give us the square root. Let' s see what pound interest in that we will make no happens when a bad approximation is used. manual entries while the 1151 is learning the calculation. Problem :

Problem: "'99.65 = 9.98248

vT55 = 12.44989 Just as in the compound interest program, for a new calculation, we must perform the Set the Answer Decimal on 5. manual calculations preceding depression of the LEAHN key. This means we must place 99.65 in R2 and our first approx­ lndex Touch imation in Rl.

155(N) FIRST KUlIlBER We will use an approximation just about as 12(a) FlHST ~UMBER bad as possible. Let' s use the number LEAHN itself, as its own approximation. TO MEMORY DUP lndex Touch FROM MEMORY += 99.65 DUP FHOlll ~IEl\IORY PHOGHAlI1 RESET (De­ + press and hold down)

15 Approximations The same basic principles as discussed in #2 - 50.32500 the preceding section apply to these pro­ #3 - 26.15256 grams. In each case, there is at least one '14 - 14.98144 variable generated by the program which is #5 - 10.81650 used for the next pass through the program #6 - 10.01463 sequence. Some of these programs (Sine, #7 - 9.98253 Cosine, etc.) do, however, have stop com­ #8 - 9.98248 mands for manual entries. Thesestopcom­ '19 - 9.98248 mands are required due to the complex nature of the problems. It took longer for the answer to repeat, but the end result is the same regardless of There is one, very critical, point regarding what is chosen as the first approximation. iterative programs that we have not touched upon: ITERATIVE PROGRAMS - GENERAL

Here are some more examples of iterative In any iterative program, the register lo­ calculations: cations of the constants and variables at the first and last steps in the program MUST SP 9496 - F INANCE BE IDENTICAL. Page 5 - Amortization Schedule Look closely at the programs for compound SP 9497 - AND ENGINEERING interest and square root. The above state­ ment is true for these two programs, is it P . 4 - Cube Root not? P. 5 - Sine of x P. 6 - Cosine of x The reason for this should be obvious. If P. 7 - Hyperbolic Sine of x the constants and variables for an applica­ P. 8 - Hyperbolic Cosine of x tion are not in the correct register. they P. 9 - Exponential x will not be operated on properly by the P. 10 - Natural Logaritluns programmed instructions. The result would P. 12 - Quadratic Equation be incorrect answers. The effect is the same P. 15 - Conversion of Decimals to as what would occur in an invoicing appli­ Common Fractions cation if the percent discount were entered P. 19 - Analysis of a Free Falling Body at the Stop Command for the price!

16 SPECIAL TECHNIQUES

GENERAL one in memory, the other generated by the program using the memory constant. Our There are many special techniques that can answers are to be printed at two decimal be used to advantage when writingprograms places, but the constant in the memory has for the 1151. We will not attempt to discuss five decimal places. all of them here. The ones shown can often be incorporated into standard programs to Let's wr i te the sequence to develop the num­ make them more efficient, or simply to ber 7; set the Answer Decimal on 5. tailor them to the specific needs of the user. Index Touch NUMBER GENERATIO:-1 2.13741(x) TO MEMORY We have already shown one example of num­ LEARN ber generation: the generation of the con­ FRO:\l MEMORY stant, 2, for our square r oot program. The DUP same principle can be used to develop any + (2)(x) whole number, within, of course, the pro­ DUP gram step capacity of the calculator: DUP + (4)(x) + (6) (x) -nx ;n X FROM MEMORY + (7)(x) Where "n" is the whole number to be gen­ FROM JIlEMORY erated, and "x· is any arbitrary number. + = PRINT (7 prints) Let's restate the above formula: PROGRAM RESET

This sequence takes any number that hap­ To develop any whole number, n, a constant pens to be in memory and develops the num­ for each pass through a program, add an ber 7! To use this sequence in the program arbitrary number. x, to itself n-times: for an application, you would simply insert then, divide the answer, (n) (x), by x. this list of instructions immediately pre­ ceding the point in the program where the number 7 is to be used. (You don' t need the There may be several ways to accomplish command PRINT, of course!) Isn't this ex­ this, depending on the number to be gener­ actly what we did in the case of the program ated, and the application in which it is used. for square root? Generally, it is best when x is in memory and, thus, may be recalled appropriately to ROUND-OFF IN DIVISION satisfy the formula. There is only one re­ quirement for x: Round-off is automatic on the 1151 at any decimal setting (0-9) in addition, subtrac­ The number of decimal places in x should tion, and multiplication. Round -off in divi­ sion can be provided by programming. The never exceed the Answer Decimal setting. method shown here requires the use of the constant .1. The steps involved are identical, This could occur, for instance, if our prob­ and the constant the same regardless of the lem requires the use of two (2) constants, Answer Decimal setting.

17 Let's .say that we have the problems: Our answer is to be rounded-off at three decimal places: move the Answer Decimal 149 -7 12 = to 3. 13.76 -;- 1. 2 = 1.27 -;- .08 = Index Touch Our answers must be rounded-off at two (2) .1 TO MEMORY decimal places. Set the Answer Decimal LEARN on 2. 1 DUP x Index Touch = + 1 FROM MElI10RY .1 TO :\IElI10RY (lI1emory 7= constant) 1 -;-:; LEARN FHO:'.I lI1El\IOHY 149 FROll1 l\lEl\IOHY x += = PHlNT 12 PHOGHAM RESET FROll1 l\IElI10HY x = As you can see, the sequence within the PRINT brackets is the program for division round­ PHOGRA:\1 HESET off. Let's calculate the answer to the prob­ Division of the dividend, 149, by.1 moves the lem. decimal place one position to the right so that when we divide by the divisor, 12, we Index Touch obtain an extra significant digit (124.1~). The answer obtained at this point is identi­ CLEAH STACK cal to the answer we would obtain if we 2 AUTO divide 149 by 12 at decimal position 3, ex­ PROGRAM HESET cept that the decimal point is one position 3 AUTO off. PHOGHAl\1 HESET 4 AUTO To restore the decimal to its correct posi­ PHOGHAl\1 HESET tion, we then multiply 124.16 by .1. But we 5 AUTO not only shift the decimal by this multiplica­ A UTO (Dividend, 54. ODD, tion - we also get a rounded -off answer. prints) 36.536 AUTO (1.478 prints) Let's complete the application: The quotient, 1.478 is rounded-off at 3 dec­ Index Touch imal places as desired. And remember, once programmed, with .1 in memory, we can 13.76 AUTO obtain rounded-off answers in division at any 1.2 AUTO (11.47 prints) decimal setting. If the next problem requires 1.27 AUTO a five (5) decimal place rounded-off answer, .08 AUTO (15.88 prints) simply move the Answer Decimal to 5 and proceed! Let's insert this sequence of instructions into an application: COMPAHISON TESTS Problem: In iterative programs, such as square root, 22 + 32 + 42 + 52 cube root, etc., each pass through the pro­ 36.536 = 1.480 gram produces an answer more accurate

18 than that obtained by the previous pass. When Index I Touch the last two answers are identical, we know that we have calculated the most accurate PRINT (13.52774 prints) answer. This procedure requires that the operator compare the last two answers. Why With this comparison technique, the opera­ not make the 1151 do this automatically! tor does not have to compare the last two answers - the 1151 does that! All the Look back at the program for square r oot. operator has to do is the tape until a The last step is PRINT. At this point, N is in zero difference prints, then touch the PRINT R2, the latest approximation is in Rl, and the key to print the final answer. previous approximation is in memory. Let's rewrite the program so that we subtract these two approximations, and print the dif­ SEQUENCE SKIPPING ference. When the difference is zero, (0), we know that the last two approximations are identical. ~Iove the Answer Decimal to 5. Applications arise that require a multi - part program which allows the operator the Problem: option of using or not using selected por­ tions of a program. Up to this time, we have Vf83 = 13.52774 only considered the more frequent case where the operator repeatedly uses the first Index Touch portion of a program, bypassing the remain­ ing steps. What if the application requires 183 FIRST NUMBER that the operator repeatedly use the first 14 FIRST NUMBER portion, then repeatedly use a following LEARN portion? TO III EMORY Here is an example of such a problem: DUP FROM MEMORY -. = Problem: FROM MEMORY + 22 + 32 + 42 = 5.38516 FROM MEMORY v' DUP + Two problems are expressed here: FROIl! MEMORY += -7= (1) Calculate the sum of the squares of DUP 2, 3, 4. FROM MEMORY (2) Calculate the square root of the (PRINT (-.46429 prints) answer. TO MEMORY PROGRAM RESET (De­ press and hold down) Both of these problems require repeated use of their respective programs. We must be Second comparison: - .00796 able to use the first portion (by manual Third comparison: - .00001 looping) until we have accumulated the Fourth comparison: .00000 squares of 2, 3 and 4. We must then be able to enter an approximation for the square The difference between the last two approx­ root of this value, enter, then repeatedly imations is zero, (0). Therefore we have use the second portion of the program until the answer: it is in Rl. we obtain the square root.

19 Here is the program: Let's perform these steps:

Index Touch Index Touch

LEARN CLEAR STACK 1 DUP 2 AUTO x ; PROGRAM RESET + 3 AUTO 1 DUP PROGRAM RESET FROM I\lEMORY 4 AUTO += PRINT (29 prints) FROM I\lEMORY + FROI\l MEMOHY Our approximation for the square root of DUP 29 is 5. + FROM MEMORY Index Touch += PRINT 5 TO MEMORY TO MEMORY AUTO (Contents of Rl, 29, PROGRAM RESET then second approxima­ tion, 5.4, print)

The first portion of the program is self­ expanatory: each number to be squared is We have calculated the second approxima­ entered - we manually loop for the next tion. The radicand, 29, is in Rl, 5.4 is in number. memory. We are at Step 1 in the program. How can we skip the first portion of the program and use the second to give uS the next approximation for the square root? The second portion is a slightly modified program for square root. The second Stop Command has three functions: Index Touch

1) Separate the fir st and second portions o AUTO of the program.

2) After all values are processed by the The 1151 has squared 0 (which is, of course, first portion, allow us to print the 0, again!) and added this to 29. We still answer. have 29 in HI and 5.4 in memory. This is exactly where these two values should be 3) Allow us to place the first approxi­ located at the first step in our square root mation for the square root in memory. program. All we need do is:

At the second Stop Command, we will touch Index Touch PRINT: the radicand in the formula will print. We will then place the first approx­ AUTO (29, then, third ap­ imation in memory and depress A UTO to proximation, 5.38518, enter the second portion of the program. prints)

20 We must re-use the square root portion of The approximations for the square root the program until the approximations re­ have repeated - we have our answer! peat. The procedure to skip a set of instructions Index Touch is different for each application. As you can see, the instructions must be carefully o AUTO planned. The numbers to be operated on by A UTa (29, then, fourth a portion of the program must be in the approximation, 5.38516, proper register locations at the first step of prints) that portion. o AUTO A UTa (29, then, fifth ap­ Sequence skipping is not always possible. proximation, 5.38516 When it is, it allows us to get the most out prints) of the 30 step 1151 program capacityl

21 SINGER FRIDEN DIVISION

SP- 9598 Printed in U.S.A.