Previous page Next page Navigation bar

Calculator Programming Tutorial

Programming Building Blocks I


Logical Operations for the Calculator

Problem Statement

The problem statement presented to us is:

The Casio FX-7400G calculator does not support logical operations. Provide them.

We need to analyze the problem posed, determine all viable solutions, and provide the best one.

Problem Analysis

The first thing to do is to validate the problem. There are three questions that need to be answered: whether the FX-7400G calculator in fact fails to provide logical operations, whether logical operations would be useful to the FX-7400G, and whether logical operations can be feasibly provided to the FX-7400G.

A little research shows that the FX-7400G calculator indeed fails to provide the elementary logical operators Not, Or, and And.

Being professionals, we do not want to help our clients to harm themselves. We therefore want to consider, also, whether the stated actions we are to take would in fact solve a problem the client might have. Logical operations are generally used in conjunction with relational operations to provide complex range conditions. However, in order for logical operations to be of any use in such circumstances, the relational operations must generate values for their results.

For example, consider the situation where we want to conditionally execute a block of code upon the situation:

s less than or equal to t less than or equal to u

We can formulate this as:

(s less than or equal to t) and (t less than or equal to u)

We can evaluate this exactly as it is written, provided the less than or equal to operator returns a value that we can manipulate. The corresponding code sequence would be something like:

sless than or equal tot→A
tless than or equal tou→B
If C
Then ...

If, however, the less than or equal to operator does not return a value, but instead is valid only in a conditional context, then our code sequence would need to look something like:

If sless than or equal tot
Then 1→A
Else 0→A
If tless than or equal tou
Then 1→B
Else 0→B
If C≠0
Then ...

This latter code sequence is so cumbersome as to be almost useless; and should it be necessary, we would want to ask our client what need is to be met by the logical operations, and verify that the client’s idea of a solution is in fact appropriate.

Fortunately, a little experimentation shows that the FX-7400G relational operators generate values: in particular, they generate 0 when the condition is false, and 1 when the condition is true. So providing logical operations for the FX-7400G is likely a useful thing to do.

We have done two out of three steps of problem validation: we have shown the problem is real, and we have shown that solving the problem is useful. Now we need to determine whether we can solve the problem.

Now we brainstorm alternatives. We could wave money at Casio to produce a special version of the FX-7400G that has the desired logical operators. We could reverse engineer the CPU and ROMs inside the FX-7400G, and modify the logic of the calculator to provide the desired logical operators. We could not use the FX-7400G, but instead use the CFX-9850G calculator, which does provide the desired logical operators. We could write calculator subprograms to provide the desired logical operations. We could request more information on the actual problem to be solved, and produce a solution to that problem that does not depend upon the nonexistent logical operations.

Now we try to determine if the proposed solutions are feasible, and the best approach to take. Consider the first alternative: waving money at Casio. Even if Casio would be willing to produce a special version of the FX-7400G for us, it would want us to underwrite all product development costs, plus margin on top. This would doubtless run several million dollars — say 1.5 million dollars, for discussion. We would also need to pay for the calculators, say $20 each in quantity.

Reverse engineering the CPU and ROMs in side the FX-7400G is doubtless feasible. We can guess it, however, as somewhere over one engineer year — probably more like five engineer years, perhaps as many as ten. The fully loaded cost of an engineer for a year is about a quarter of a million dollars. This includes salary, benefits, office space, laboratory space, secretarial support, managerial support, and so forth. So the reverse engineering solution is likely 1.2 to 2.5 million dollars — say 2 million dollars, for discussion. We would also need to manufacture new ROMs, and install them into purchased FX-7400G calculators. In addition to $15 each in quantity for the calculators, there would be labor costs to open the calculator, replace the ROM, and close the calculator — with practice, say 5 minutes to do this, or about $1.70 per unit fully loaded cost. The replacement ROM itself would likely be about ten cents, so our total is $16.80 per unit.

Analyzing the alternative of using the CFX-9850G instead is simple. These calculators and likely be had for about $30 each in quantity, and this alternative has no engineering or other fixed costs.

Writing calculator subprograms to provide the desired logical operations would cost perhaps one engineer day, or about one thousand dollars at fully loaded cost, but could use standard FX-7400G calculators, at about $15 each in quantity.

Finally, solving the problem in a different way, that does not require logical operations, would probably require a great deal of engineering time — assuming the problem was correctly analyzed to begin with. We can suppose between one and six months would be required to reanalyze the problem — say about 63 thousand dollars, for discussion. However, we would still need calculators, at $15 each in quantity.

We can now consider the various alternatives, and discover the volumes at which each is most economical. We can summarize the fixed and per-unit costs in a table, as follows:


Fixed Cost

Per-Unit Cost

1: Wave money at Casio

$1.5 million


2: Reverse engineer

$2 million


3: Use CFX-9850G



4: Write program

$1 thousand


5: Reanalyze problem

$63 thousand


We can immediately discard some of these alternatives as “dominated” by other alternatives. This means the discarded alternative is uniformly more expensive than the other alternatives. Alternative 5, for example, is uniformly $62,000 more expensive than alternative 4, for all volumes, and so can be discarded. Alternatives 1 and 2 have both a higher per-unit cost and a higher fixed cost than alternative 4, and so can be discarded. The two remaining alternatives are:


Fixed Cost

Per-Unit Cost

3: Use CFX-9850G



4: Write program

$1 thousand


We can graph these two cost functions, and see which is more economical, as follows:

Graph of costs, showing intersection of costs around 65 units

Alternately, we can solve for the intersection point arithmetically:

C = $1000 + $15/unit k = $30/unit k, or
k = $1000/($15/unit) = 66.67 unit

where k is the number of units. So using the CFX-9850G instead of the FX-7400G is more economical for 1 through 66 units, and writing a program for the FX-7400G is more economical for 67 or more units.

We can now go back to the source of the assignment — for discussion, say our manager — and report two alternative solutions. The solutions are to use the CFX-9850G rather than the FX-7400G, which is most economical for volumes of 1 to 66 units, or produce a subprogram, which is most economical for volumes in excess of 66 units.

Our manager tells us more about the problem. Two thousand FX-7400G calculators have been purchased and will be distributed to the end users after the software has been downloaded into them, and are currently sitting in a back room accumulating carrying charges at $45 a day. The most economical solution is therefore to write a program to implement the logical operations, at a cost of $1,000, download it into the calculators (at 10 seconds per download, one day), and ship the calculators out.

It is a good thing we are in a programming tutorial.

[ Previous page | Top of page | Next page ]

Previous page Top of page Next page Navigation bar

Copyright © 2002 Brian Hetrick
Page last updated 27 January 2002.

Brian’s Casio Calculator Corner







Building Blocks I



Data Types




Control Flow I

Control Flow II


Basic I/O


A First Program



Logical Ops





Bitwise Ops





Data Structures I


Program Attributes

Building Blocks II

Algorithm Analysis


Data Structures II

Abstract Types


Problem Analysis

Reference Card



Site Information

Your Privacy

Site Map


Site Technical Data