FormulaCalc -- A Formula Calculator for the Palm OS
Version 1.1*

Description

Welcome Display
FormulaCalc is a calculator which accepts algebraic formulas and computes their values.
The formulas:

It can be used as a simple calculator, or one to compute complicated routines. We hope you find FormulaCalc useful.

About This Documentation

FormulaCalc is intuitive and easy to use. That seems to be contradicted by the size of this documentation. It's large because of the many features and functions. But once you become familiar with FormulaCalc we think you will agree that it is easy to use.
You really should read this entire document to fully understand FormulaCalc.

For a quick start read Installation and Quick Start.
Then after trying it out please return to this documentation to learn all of the features.

Documentation Sections:

Installation

This archive file includes:
frmclc11.prc
The executable file
MathLib.prc
The required mathematics library -- V1.1
FormulaCalc.html
This file
fcDisp1.gif fcDisp2.gif fcExample.gif fcMenu1.gif fcMenu2.gif fcPrefs.gif
Images for FormulaCalc.html

Use your Pilot installer to install frmclc11.prc. If you are upgrading FormulaCalc Version 1.0 (frmclc10.prc) you must first delete FormulaCalc V1.0 or risk requiring a Palm OS reset.
FormulaCalc requires MathLib.prc*. If you have MathLib.prc already installed (because some other application uses it) just install frmclc11.prc. Otherwise install both frmclc11.prc and MathLib.prc.

The included MathLib.prc is the latest version (V1.1 dated 4/14/1999). You may update with this one if you desire.

Quick Start

Welcome Display When you first use FormulaCalc you will be greeted with a display as shown on the right.
The display consists of 3 areas:

If you want to use FormulaCalc as a simple calculator:

First Routine Display

Your First Routine

This is an interactive trial so install FormulaCalc now, and launch it.
In the text which follows, characters which you enter are blue, output values are green, and register names are red.

For this first trial tap the diamond to the right side of the input area. This icon action is "highlight all text in the input store". Tap it again. That cut it to the clipboard, and accomplished our immediate goal of clearing the input area. Now with the pen and enter:   3*4-7/3   then press Compute.
The value 9.67 will appear in the output box. An "ordinary" calculator would have displayed 1.666... because it would use a left to right calculation rather than computing 3*4 then 7/3 and then subtracting as we understand algebraic formulas.

Now on the second input line enter: a=2; sr(a); a^2 then press Compute. The output box now displays 4 lines: 9.67 2.00 1.41 4.00
Press the Compute and Clear buttons several times to see what happens.

Next press the Reg button. You will see that the A register now has 2.00 and R has 4.00. That is because you stored 2 in A, and R is the result register which contains the last computed value 4.00.
Using the pen select register G, enter 20 and press Set Value. Now G contains 20. Press Done. On the third input line enter G to the end of your routine. Your routine should now read:

  1. 3*4-7/3
  2. a=2; sr(a); a^2
  3. g
Press Compute. You will see 20.00 added to your output lines, and if you check the resisters (Reg button) R will be 20.00 since it is now the last result.

You are now an expert! Example

To prove that see if you understand the example on the right.

Allowable Formula Objects

The allowable operators, functions and symbols are:
arithmetic: +   -   *   /   ^   %;
functions: sr()   sq()   ln()   log()   int()   pi
trig: sin()   cos()   tan()   asin()   acos()   atan()
assignment: =   +=   -=   *=   /=
decision: <   <=   = =   >=   >
grouping: (   )
control: ;   if(,,)   deg   rad   dd:   sr:
string: " "   [ ]
String function: st(string,string,exp) st(string,exp,exp) st(exp,string,exp) when a st(,,control) control evaluates 0 the result is stored but not printed. This holds all strings from being printed until a st(,,control) control evaluates to non-0 is excuted. Thus st("","",0) is a 'stop string display command'. Strings cannot be assigned to a letter. The definitions for these are given below, but it is now time for you to try FormulaCalc for yourself.
When you get puzzled or you want to save a routine for future use come back. It's all explained below.
This is the end of Quick Start.

Using FormulaCalc

Menu Actions

Commands

Commands Menu The first three commands refer to routines stored in a Memo Pad entry. Your routines are stored in the Memo Pad under the name "Formula Calculator". ( See Storing Routines.)

Edit

Edit Menus The actions of the Edit Menu work only with the Pen Store.

Info

Storing Routines

You can store as many routines as desired in the Memo Pad. (Memo Pad has a limit of 4000 characters, but that is enough for many routines.)

Create a Memo Pad entry entitled: Formula Calculator (the first line and column 1 of the entry -- be sure there are no leading spaces). It can be in an category. FormulaCalc will find it.

Each routine starts with a # sign in column 1 followed by the name e.g. #Compound Interest.
A routine is of the form: formula followed by ; (and/or new line) followed by formula .....
The routine is terminated by one or more blank lines.
All space characters within a formula are ignored.

Following is an example memo with two routines:

    Formula Calculator
    #Compound Interest
    [Reg: I interest, P principle]
    [N years, M periods per year]
    dd:2
    (1+i/m)^(m*n)*p

    #Future Annuity
    dd:2; ((1+i/m)^(m*n)-1)/(i/m)*p

This starts with the required title: Formula Calculator (actually only "Formula" is needed).
The name of the routine is Compound Interest.
Next is a 2 line non-printing comment as a reminder of the register contents.
dd:2 tells FormulaCalc to show 2 decimal digits in the output.
The formula follows.

The second routine in the memo is Future Annunity.
As many routines as desired may be in the memo. Each must start with a #.

Operators and Functions

This explains each of the operators and function.
The operators:
arithmetic:
  +
addition -- e.g. 4 + 8     result: [12]
  -
negation -- e.g. -4 or subtraction e.g. 5 - 2.02     [2.98]
  *
multiplication -- e.g. 12 * 6     [72],     121 * -7     [-847]
  /
division -- e.g. 36 / 4.321     [8.3314]
  ^
x to power y -- e.g. 2 ^ 3     [8]
  %
remainder of x divided by y -- e.g. 30.25 % 5     [0.05],     30.25 % 1     [0.25] the fractional part
The functions:
arithmetic:
  sr()
square root -- e.g. sr(2)     [1.1414]
  sq()
square -- e.g. sq(2)     [4]
  ln()
natural logarithm -- e.g. ln(3)     [1.0986]
  log()
base 10 logarithm -- e.g. sr(1000)     [3]
  int()
integer part -- e.g. int(30.25)     [30]
  pi
constant pi -- e.g. pi * 2     [6.283185307]
trigonometric:
  sin()
sine -- e.g. sin(1)     [0.8415]
  cos()
cosine -- e.g. cos(1)     [0.5403]
  tan()
tangent -- e.g. tan(1)     [1.5574]
  asin()
arcsine -- e.g. asin(1)     [1.5708]
  acos()
arccosine -- e.g. acos(1)     [0.0000]
  atan()
arctangent -- e.g. atan(1.5574)     [1.0]
assignment:
  =
register store -- e.g. a = 2     [2] -- a cumulative example
  +=
add and store -- e.g. a += 13     [15]
  -=
subtract and store -- e.g. a -= 9     [6]
  *=
multiple and store -- e.g. a *= 3     [18]
  /=
divide and store -- e.g. a /= 3     [6]
decision -- used in if(,,):
  <
less than -- e.g. a < 10
  <=
less or equal -- e.g. a <= q
  ==
equal -- e.g. 20 == w
  >=
greater or equal -- e.g. t >= s
  >
greater than -- e.g. d / 3 > 10 * 7 + a
The miscellaneous statements:
control:
  if(,,)
select -- e.g.   a=18; if (a<10, a, a/3)     [6]     or a=9     [9]
  deg
set trig functions to degrees -- e.g. deg     [57.29577951]
  rad
set trig functions to radians -- e.g. rad     [0.017453292]
  dd:
set number decimal digits to (0-15) -- e.g. dd:4     [ ]
  se:
set exponent to display scientific notation (0-15) -- e.g. se:4     [ ]
  sr:
set show register assignments (y or n) -- e.g. sr:y     [ ]
comment:
  " "
printing comment -- e.g. "answer is:"     [answer is:]
  [ ]
non-printing comment -- e.g. [debug line]     [ ]

Operator Calculation Order

This section discusses the order in which operators are used for a calculation when not controlled by parenthesis.
The computation is done in a left to right order for the operators and functions of a given group as listed next listed next. This means that operators in a given group are computed in turn left to right and then the results of each group computation combined as specified by the order. Parenthesis modify the order forcing computation to be completed within the '( )' before combining with other values. See the example which follow the table.

Group computation order:
First: sr()   sq()   ln()   log()   int()   pi   sin()   cos()   tan()   asin()   acos()   atan()   if(,,)   deg   rad   <   <=   = =   >=   >
Second: *   /   ^   %;
Third: +   -
Last: =   +=   -=   *=   /=
Not Combined: dd:   sr:   " "   [ ]

Example:

          a = 10; deg                                          Left to right
          b = 2 * 3 + 5 * sin(a + 30) ^ 2 - 9 * (5 + 7)
              |   |   |     |  \   /    |    |    \  /
              |   |   |     |   40     /     |     12          Compute inside ()'s 1st
              |   |   |      \  /     /      |      |
              |   |   |      0.64    /       |      |          Then things in First
               \ /     \      /     /         \    /
                6        3.21      /            108            Then Second (leftmost)
                 \        \       /             /
                  \         10.33              /               And Second Again
                   \        /                 /
                     16.33                   /                 Then Third (leftmost)
                          \                 /
                                 -91.67                        And Third Again
          Finally the assignment

Examples

This section explains three examples in detail. The Julian Calendar is quite complicated but it is a good example of register storage, the if(,,) statement and number encoding.

Example 1:
This example shows the use of arithmetic assignments to registers, and iteration.

    #Powers of 2
    sr:y
    u += 1; v *= 2
This routine sets the output display to show register assignments. Then 1 is added to the current value of u and re-stored in u, and the current value of v is multiplied by 2 and re-stored in v.
Assume the initial value of the register u is 0, and v is 1.
Pressing Compute produces output of: 1   2 because 1 was added to u and v was multiplied by 2.
Pressing Compute again produces: 2   4 and again 3   8 etc.
Powers of 2 -- 1 raised to 2 is 2, 2 raised to 2 is 4, 3 raised to 2 is 8, etc.

Example 2:

This example shows the use of the int() function (i.e. whole number extraction).
Julian Date was defined by astronomers to have a uniform date code independent of the calendar. It makes taking the difference between 2 dates easy. (See note below.)

    #Julian Date
    sr:n; dd:2; se:10
    i=int(z/100); i=2-i+int(i/4)
    int(365.25*z)+int(30.6001*(x+1))+y+1720994.5+i
Assume that register x (month) is 10, y (day) is 15, z (year) is 1999 (October 15, 1999).
This routine sets the output display to not show register assignments, and to display 2 decimal digits. It then divides the year by 100, and fills the whole number part into register i. i is then further manipulated for leap years. The result is the integer part of a year and a month calculation, all added to the day, a constant and i.
The result displayed is: 2451466.50
It would be a good exercise to see the results of all computations by turning on the display of registers. You do this by accessing menu/show....
The output is then: 19   -17   2451466.50

Note: A Julian Date is defined to start at noon and show the fraction of a day. So to be accurate the day in y should be a day and a fraction. If y was 15.5 then noon on October 15, 1999 is the start of Julian Day 2451467.00
This routine is only accurate for the Gregorian calendar. A modification of this routine must be made for dates before October 15, 1582.

Example 3:

This example is really too complicated but it shows the use of the if(,,) function, and it shows how to encode 3 numbers into 1. It produces the calendar date for an Julian date, and show the fraction of a day to two decimal places.

    #Julian Calendar					Program Comments
    dd:6; se:10; sr:n					2 decimal digits, no scientific notation, no register values
    i=int((z+1-1867216.25)/36524.25);			number of centuries
    i=z+1+i-int(i/4);i=i+1524;				leap days
    j=int((i-122.1)/365.25)				a year value
    m=int(365.25*j); k=int((i-m)/30.6001)
    i=i-m-int(30.60001*k)				day of the month
    m=if(k<13.5,k-1,k-13);				month number
    if(m>2.5,j-4716,j-4715)+(m+i/100)/100		answer dependent on month value
The last line computes the year depending on the month. If the month is greater than February then the year is j-4716 otherwise it is j-4715. Add to the year a fraction of the combined month, day and fraction of a day. The form mmdddd. So the answer is yyyy.mmdddd (where dddd means: day dd -- implied decimal point -- decimal part of the day dd). In general, this scheme is a good way to display 3 different numbers as one number.
To see the result put 2451467.00 in register z. Pressing Compute produces: 1999.101500. That is, noon on October 15, 1999.

Contact Info

FormulaCalc was created by David W. Bray, Potsdam, NY;
Copyright © 1999-2004 David W. Bray, All Rights Reserved.

The Bray Palm OS Page can be found at: http://davidbray.org/palm/

Registering

FormulaCalc is freeware no registration is required. We hope you enjoy using it.

This archive may be freely redistributed, provided it is made available only in its complete, unmodified form with no additional files and for noncommercial purposes only. Any other use must have prior written authorization from David W. Bray.

Unauthorized commercial use includes, but is not limited to:

Disclaimer

This program is provided without warranty and the user accepts full responsibility for any damages, consequential or otherwise, resulting from its use.

Foot Notes

*Program Changes in Version 1.1

FormulaCalc Version 1.1 differs from Version 1.0 in:

*MathLib

Many thanks to Rick Huebner, the author of MathLib, for his excellent routines and making them freely available.