Copyright: ® 1994 Stephen Kent Stephenson.
Citation: ® 1994 Stephen Kent Stephenson.


Contents

Copyright and Trademark Notices

Introduction

Getting Started

Using PenCalc 1.1 and KeyCalc 1.1

Technical Support

Distribution/Registration


Copyright and Trademark Notices

PenCalc 1.1 and KeyCalc 1.1 program, text, and help files are all:

Copyright © 1994 Stephen Kent Stephenson.
All Rights Reserved.

PenCalc, KeyCalc, and StuPENdous Software are trademarks of
Stephen Kent Stephenson.


Introduction

Overview & Features

Requirements & Limitations

How Do PenCalc 1.1 and KeyCalc 1.1 Work?


Overview & Features

PenCalc 1.1 is a pencentric software calculator. KeyCalc 1.1 is a mouse and keyboard oriented software calculator.  Both calculators share the same calculation engine and differ only in the ability to recognize pen input.  Either of them will replace all your handheld electronic calculators, freeing up valuable space in your briefcase (when used on a mobile computer) or on your desktop.

PenCalc 1.1 and KeyCalc 1.1 combine the functionality of all types of handheld electronic calculators; with functions and capabilities covering business, finance, science, mathematics, engineering, and computer programming.

PenCalc 1.1 and KeyCalc 1.1 are easy to use.  Instead of confusing multi-function keys, they use sequences of action words and numbers to perform calculations.  And you can save the sequences in standard text documents for audit and reuse.

PenCalc 1.1 and KeyCalc 1.1 are extensible.  You can define your own action words in terms of existing action words.  You can even define words that themselves are used to define other words.


Requirements & Limitations

PenCalc 1.1 requires Microsoft's Windows For Pen Computing and Windows 3.1.

KeyCalc 1.1 requires Microsoft's Windows 3.1  (It may be that KeyCalc 1.1 would run on previous versions of Windows, but this has not been tried/tested by the author).


How Does PenCalc/KeyCalc 1.1 Work?

To perform a calculation, you compose a Calculation String containing a sequence of Data items (Strings and Numbers) and action Words.

The Data items and Words must be separated from each other by one or more spaces.

The Calculation String is scanned from left to right.

When a Data item is encountered, it is put it on top of the Data Stack.

When a Word is encountered, its predefined actions are performed, which may use one or more of the Data items on the Data Stack.  The Word's definition indicates what the Word expects on the Data Stack and how the Word changes the Data Stack.

Some Words also require certain character sequences to occur after them in the Calculation String.

When the Calculation String is exhausted the Data Stack is examined.  If there is more than one item on the Data Stack, an Error message is displayed.  If there is only one Data item on the Data Stack, it is display in the Result Window.

As an example, consider the Calculation String:

3  7  -

First 3 is put on the Data Stack, then 7 is put on top of the 3 on the Data Stack, and finally the action definition for the Word  - is executed, which is (see Using PenCalc/KeyCalc 1.1 / Word Descriptions / Math / Algebraic / - ):

...  x  y  -

...  z

z  =  x  -  y

This action definition says to take the top two Data items (x and y, where y is the top of the Data Stack) off the Data Stack and to put their difference (z) on the Data Stack.  (The ellipses indicate that there could be more data below the x or z on the Data Stack.)

The result is that the 3 and 7 will be removed from the Data Stack and their difference,  3  -  7  =  - 4, put on the Data Stack (and displayed in the Results Window).

As another example, consider the Calculation String:

3  -7  10  -2  99  22  - +  +  *  /

Which is calculated by PenCalc/KeyCalc 1.1 as:

3 / ( -7 * ( 10 + ( -2 + ( 99 - 22 ) ) ) )

=  -0.0050420168067227

Note that the -7 is interpreted by PenCalc/KeyCalc 1.1 as a negative 7, not the Word  -  followed by the Number 7.  This is so because there is no space between the - and the 7.

Yet another example, consider the Calculation String:

3  -7  -  10  +  -2  +  99  *  22  /

Which is calculated by PenCalc/KeyCalc 1.1 as:

( ( ( ( 3 - ( -7 ) ) + 10 ) + ( -2 ) ) * 99 ) / 22

=  81

Many other examples are included in the Word Descriptions section and the user is encouraged to read them.

Those familiar with RPN calculators (like the ones from HP) will recognize the above examples as RPN expressions.


Getting Started

Installing PenCalc/KeyCalc 1.1

Registering Your Copy


Installing PenCalc/KeyCalc 1.1
Installing PenCalc 1.1 and/or KeyCalc 1.1

You received one of the following compressed files (*.ZIP) with the indicated contents:

Contents:	Support Files	PENCALC.EXE	PENCNTRL.VBX	VBRUN300.DLL	KEYCALC.EXE
*.ZIP file
SSPC11.ZIP	X	X
S2PC11.ZIP	X	X	X
S3PC11.ZIP	X	X	X	X
SSKC11.ZIP	X				X
S2KC11.ZIP	X			X	X
SSXC11.ZIP	X	X	X	X	X
Decompress the *.ZIP file using version 2.04G, or later, of PKUNZIP from PKWARE (available on most BBS systems) into its own directory.  Both PenCalc 1.1 and KeyCalc 1.1 need to have VBRUN300.DLL in the \WINDOWS directory.  PenCalc 1.1 also needs PENCNTRL.VBX in the \WINDOWS\SYSTEM directory.  These two files are from Microsoft Corporation's Visual Basic for Windows.  Be sure not to overwrite newer versions of these files that you may already have.

In the Windows Program Manager create a Program Group for PenCalc 1.1 and/or KeyCalc 1.1.  From the File Manager, drag the program (*.EXE) and help (*.HLP) files into the new Program Group.  Change the command line property of the program icon(s) to add " {all.wds} Load" at the end (without the quotes, but with the initial space).  This will automatically load all predefined Action Words, including the required System Words, into the calculator when you double tap/click the program icon.


Registering Your Copy

PenCalc 1.1 and KeyCalc 1.1 are distributed as Shareware.  They are NOT free.  You are permitted to use PenCalc 1.1 and KeyCalc 1.1 on a trial basis for up to 30 days.  If you wish to continue using PenCalc 1.1 and/or KeyCalc 1.1 beyond that period, you are required to Register and purchase right-to-use Licenses.  For details on Registering, see the Distribution / Registration section below.


Using PenCalc/KeyCalc 1.1

User Interface Windows

Data Formats

Word Descriptions


User Interface Windows

Numbers Window

Words Window

Calculation String Window

Results Window


Numbers
Numbers Window

The Numbers Window is at the bottom left of the PenCalc/KeyCalc 1.1 display.

It's primary purpose is to make it easier to enter numbers with the pen by restricting the character set allowed for input.  It automatically assumes you are entering a number, so O, o, and 0 become zero, and l and 1 become a one, for example.

It's secondary purpose is to provide a facility for negating complicated numbers that appear in the Results Window; e.g., base complement forms of negative hexadecimal numbers.  Simply drag and drop the Results Window contents into the Numbers Window.

If you enter a string of text that is not a valid number, the Number Window will show its contents in bold.

If the Number Window contains a valid number, a "+/-" push-button appears.  Pressing it changes the sign of the number in the window.

To delete the contents of the Number Window tap/click the X button in the Number Window.

To transfer the contents of the Number Window to the Calculation String Window tap/click the Add button in the Number Window.


Words
Words Window

The Words Window is in the lower right of the PenCalc/KeyCalc 1.1 display.

Tap/click on the window or the button at the right and a list of defined words will appear.

Select the one you want by tapping or clicking it, then tap/click the Add button in the Words Window.

See the Word Descriptions sections below for explanations of the PenCalc/KeyCalc 1.1 words.


Calculation String
Calculation String Window

The Calculation String Window is in the middle of the PenCalc/KeyCalc 1.1 display.

It's where you compose calculation strings you want PenCalc/KeyCalc 1.1 to perform, the results of which are then displayed in the Results Window.

The Calculation String Window allows multi-line definitions; where each line can have an active part followed by an optional comment that starts with a #.  See the System Words file for examples of using comments to show stack contents after each word is executed.  Following the format of the examples makes it a lot easier to compose correct Calculation Strings.

To perform the calculation either double tap/click in the Calculation String Window, or tap/click the = button.

If you are defining your own Words, the Debug menu (available only in registered copies of PenCalc/KeyCalc 1.1) has some useful features:  e.g., Tracing execution of your Words with optional single instruction stepping, and User and System Dictionary Dumps.  If you have activated stepping, a step button (+) appears at the top of the Calculation String window which you use to trigger each step.

The Calculation String window also has a delete contents button labeled X.


Results
Results Window

The Results Window is the top window, positioned just under the title line.

The right side of the Results Window is where the results of calculations appear.

Sometimes a result is so long that all of it can't be seen in the result window.  When that happens, simply drag and drop (press-hold-drag-release, or click-hold-drag-release) the result into the Calculation String window and use scrolling if necessary.

The left side of the Results Window contains the mode and mode modifier lists explained below.  The mode determines the format in which to display the result, without actually modifying the internally stored value as the word BaseN$ does.

Display Modes


Modes
Display Modes

FLT

SCI

ENG

FIX

BIN

OCT

DEC

HEX

ASC


FLT
FLT  Display Mode

FLT:	General Floating Point Format

Modifier:	None

Use for numeric results.

FLT will display the 15 most significant digits of the result, with the integral portion grouped by commas every 3 digits.

It will attempt to do so without a scaling factor (*10^scalingFactor) by "floating" the decimal to the proper position within the 15 digits.

It will even add leading zeros to the 15 digits and position the decimal to the left of them for numbers less than 1 and greater than or equal to 0.001.

If a scaling factor is necessary, FLT reverts to SCI.


SCI
SCI  Display Mode

SCI:	Scientific Format

Modifier:	None

Use for numeric results.

SCI displays one digit to the left of the decimal point and the other 14 to the right.

To accomplish this, it adds a scaling factor suffix (*10^scalingFactor) to the displayed result.


ENG
ENG  Display Mode

ENG:	Engineering Format

Modifier:	None

Use for numeric results.

ENG displays one to three digit to the left of the decimal point and the rest of the 15 to the right.

To accomplish this, it adds a scaling factor suffix (*10^scalingFactor) to the displayed result where the scaling factor is forced to an integral multiple of 3.


FIX
FIX  Display Mode

FIX:	Fixed Point Format

Modifier:	The number of digits to the right of the decimal point to display (0 to 17).

Use for numeric results.

If result is > 10 ^ 14, FIX reverts to FLT.

FIX adjusts the modifier, if necessary, to ensure that it will not display more than 15 significant digits.

Then it displays the (adjusted) modifier number of digits to the right of the decimal point.


BIN
BIN  Display Mode

BIN:	Binary Format

Modifier:	1 to show result in 2's complement form,
0 to show result in normal form.

Use for numeric results.

BIN shows the result as a binary (base 2) number, with zero scaling, and the digits grouped in fours on both sides of the decimal point (to the left with commas, to the right with apostrophes).


OCT
OCT  Display Mode

OCT:	Octal Format

Modifier:	1 to show result in 8's complement form,
0 to show result in normal form.

Use for numeric results.

OCT shows the result as an octal (base 8) number, with zero scaling, and the digits grouped in fours on both sides of the decimal point (to the left with commas, to the right with apostrophes).


DEC
DEC  Display Mode

DEC:	Decimal Format

Modifier:	1 to show result in 10's complement form,
0 to show result in normal form.

Use for numeric results.

DEC shows the result as a decimal (base 10) number, with zero scaling, and the digits grouped in threes on both sides of the decimal point (to the left with commas, to the right with apostrophes).

While the Display Modes FLT , SCI , ENG , and FIX also show the result as a decimal number, DEC can show the 10's complement form.  And it groups the digits to the right of the decimal point as well as those to the left.


HEX
HEX  Display Mode

HEX:	Hexadecimal Format

Modifier:	1 to show result in 16's complement form,
0 to show result in normal form.

Use for numeric results.

HEX shows the result as a hexadecimal (base 16) number, with zero scaling, and the digits grouped in fours on both sides of the decimal point (to the left with commas, to the right with apostrophes).


ASC
ASC  Display Mode

ASC:	ASCII Format

Modifier:	1 to enclose in braces,
0 to not.

Use for numeric or string results.

For a string, ASC just displays the string's characters.

For a number, ASC first converts it internally to a base 256 number in base complement form.  Then for each digit of that number, not including the sign digit, from high order to low, it displays the associated Visual Basic 3.0 glyph.

... 72,101,108,108,111,33*256^0 displayASC

... Hello

... 5465,7374*16^0

... Test

... <F,8081,8283*16^0

... Çü,_


Data Formats

 Numbers

 Strings


Numbers

Numbers entered by the user or generated by PenCalc/KeyCalc 1.1 are of the following formats:

	d,d	+d,d	-d,d
	.d'd	+.d'd	-.d'd
	d,d.d'd	+d,d.d'd	-d,d.d'd
	d,d.d'd*b^e	+d,d.d'd*b^e	-d,d.d'd*b^e
	d,d.d'd*b^+e	+d,d.d'd*b^+e	-d,d.d'd*b^+e
	d,d.d'd*b^-e	+d,d.d'd*b^-e	-d,d.d'd*b^-e
			<d,d.d'd*b^e
			<d,d.d'd*b^+e
			<d,d.d'd*b^-e
where:	d is one or more digits

+ and - are the usual sign characters

< is a negative sign character that also signifies that the number is in base complement form and that the first digit is infinitely duplicated to the left.

, and ' are grouping characters (which may be optional if the base has an encoding string -- see description for BaseN$ ).

b, in base 10, is the number's base

e, in base 10, is an exponent of b

* and ^ indicate that the digit value is to be scaled by multiplying by the base raised to the exponent power.


Strings

A string is text enclosed in braces; e.g.:  {Hello World} .

Actually, an opening brace starts the string and a closing brace and blank combination ends the string.  This allows opening and closing braces to occur as part of the string.


Word Descriptions

Beep

Business/Financial

Conversion

Curve fitting

Date/Time

DisplayXxx

List

Logic

Math

Programming

Stack

Statistical

String/Text


Beep

...  Beep

...

Generates an audible tone on the computer's speaker.


Business/Financial

Cash Flows, Constant Size

Cash Flows, Variable Size

Depreciation

Interest, APR vs. EFF

Percentage


Cash Flows, Constant Size

Fv

Future Value.

Nper

Number of periods.

Pv

Present Value.

Pmt

Payment per Period.

Pmti

Interest portion of a payment for a specific period.

Pmtp

Principal portion of a payment for a specific period.

PmtParts

Returns both the interest and principal portions of a payment for a specific period.

Rate


Fv

...  ( rate  nper  pmt  pv  begin ) Fv

...  fv

Gives the future value (fv) of an investment at a constant interest rate (rate) of a number (nper) of periodic constant payments (pmt) and present value (pv).  The payments can occur at the end of each period (begin = 0, the default) or the beginning (begin <> 0).

For pmt, pv, and fv, cash received is positive and cash paid out is negative.

rate and nper must refer to the same type of period.  If nper is months, then rate must be the monthly interest.

Your savings account currently has $1,000 in it earning 6% APR.  If you deposit an additional $100 at the beginning of every month, how much will you have at the end of the first year?

... ( 6 % 12 / 12 -100 -1,000 1 ) Fv

...  2,301.40183034094

You invest $10,000 at an annual interest rate of 10%, compounded quarterly.  What is the value of your investment after 5 years?

... ( 10 % 4 / 5 4 * 0 -10,000 ) Fv

...  16,386.164402904

Your company is depositing $5,000 quarterly in a fund paying 16% annually with quarterly compounding.  Calculate the value at the end of three years for an ordinary annuity and for an annuity due (begin = true).

... ( 16 % 4 / 3 4 * -5,000 ) Fv

... 75,129.0273209601

... ( 16 % 4 / 12 -5,000 0 true ) Fv

... 78,134.1884137985


Nper

...  ( rate  pmt  pv  fv  begin )  Nper

...  nper

Gives the number of periods (nper) necessary for an investment made at a constant interest rate (rate) with constant payments (pmt) and present (pv) and future (fv) values.  The payments can occur at the end of each period (begin = 0, the default) or the beginning (begin <> 0).

For pmt, pv, and fv, cash received is positive and cash paid out is negative.

rate and nper refer to the same type of period.  If rate is monthly interest, then nper is months.

If you invest $100 at the beginning of every month, with an additional initial investment of $1,000, in a plan that returns 12% APR, in how many months will your investment be worth $10,000?

... ( 12 % 12 / -100 -1,000 10,000 true ) Nper

... 59.6738656742946


Pv

...  ( rate  nper  pmt  fv  begin ) Pv

...  pv

Gives the present value (pv) of an investment at a constant interest rate (rate) of a number (nper) of periodic constant payments (pmt) and future value (fv).  The payments can occur at the end of each period (begin = 0, the default) or the beginning (begin <> 0).

For pmt, pv, and fv, cash received is positive and cash paid out is negative.

rate and nper must refer to the same type of period.  If nper is months, then rate must be the monthly interest.

For the past year, you have been depositing $100, at the beginning of every month, into your savings account; which has been earning 6% APR.  If your balance is now $2,301.40, how much did you have in the savings account at the beginning of the year?

... ( 6 % 12 / 12 -100 2,301.40  true ) Pv

... -999.998275992134

What must your initial investment be in a plan that pays an annual interest rate of 10%, compounded quarterly, if in 5 years you receive $16,386.16?

... ( 10 % 4 / 5 4 * 0 16,386.16 ) Pv

...  -9,999.99731303564


Pmt

...  ( rate  nper  pv  fv  begin  ) Pmt

...  pmt

Gives the constant periodic payment (pmt) required for an investment made at a constant interest rate for nper periods with present (pv) and future (fv) values.   The payments can occur at the end of each period (begin = 0, the default) or the beginning (begin <> 0).

For pmt, pv, and fv, cash received is positive and cash paid out is negative.

rate and nper must refer to the same type of period.  If nper is months, then rate must be the monthly interest.

What's your monthly payment on a 20 year mortgage of $300,000 at 15% APR?

... ( 15 % 12 / 20 12 * 300,000 ) Pmt

... -3,950.3687J4775991

What's your monthly payment on a car loan of $12,000 at 9% APR over 24 months?

... ( 9 % 12 / 24 12,000 ) Pmt

... -548.216907350077


Pmti

...  ( rate  per  nper  pv fv  begin  ) Pmti

...  pmti

Gives the interest portion (pmti) of the constant periodic payment required for a specified period (per) of an investment made at a constant interest rate for nper periods with present (pv) and/or  future (fv) values.   The payments can occur at the end of each period (begin = 0, the default) or the beginning (begin <> 0).

For pmt, pv, and fv, cash received is positive and cash paid out is negative.

per must be in the range 1 to nper.  rate and nper must refer to the same type of period.  If nper is months, then rate must be the monthly interest.

For a 20 year mortgage of $300,000 at 15% APR, what is the interest paid in the first month?

... (  15 % 12 / 1 20 12 * 300,000 ) Pmti

... -3,750.00000000001


Pmtp

...  ( rate  per  nper  pv  fv   begin  ) Pmtp

...  pmtp

Gives the principal portion (pmtp) of the constant periodic payment required for a specified period (per) of an investment made at a constant interest rate for nper periods with present (pv) and future (fv) values.   The payments can occur at the end of each period (begin = 0, the default) or the beginning (begin <> 0).

For pmt, pv, and fv, cash received is positive and cash paid out is negative.

per must be in the range 1 to nper.  rate and nper must refer to the same type of period.  If nper is months, then rate must be the monthly interest.

For a 20 year mortgage of $300,000 at 15% APR, what is the principal paid in the first month?

... ( 15 % 12 / 1 20 12 * 300,000 ) Pmtp

... -200.368747759902


PmtParts

...  ( rate  per  nper  pv  fv   begin  )  PmtParts

...  pmtp  pmti

Gives the principal portion ( pmtp ) and the interest portion ( pmti ) of the constant periodic payment required for a specified period (per) of an investment made at a constant interest rate for nper periods with present (pv) and future (fv) values.   The payments can occur at the end of each period (begin = 0, the default) or the beginning (begin <> 0).

For pmt, pv, and fv, cash received is positive and cash paid out is negative.

per must be in the range 1 to nper.  rate and nper must refer to the same type of period.  If nper is months, then rate must be the monthly interest.


Rate

...  ( nper  pmt  pv  fv   begin  guess  )  Rate

...  rate

Gives the constant interest rate of an investment that has a number (nper) of periodic constant payments (pmt) and present (pv) and future (fv) values.  The payments can occur at the end of each period (begin = 0, the default) or the beginning (begin <> 0).

For pmt, pv, and fv, cash received is positive and cash paid out is negative.

rate will refer to the same type of period as nper.  If nper is months, then rate will be the monthly interest.

Newton's iterative method is used to find the rate.  There may be more than one solution.  If convergence is not achieved within 50 iterations, an error is reported.

guess is an optional starting value for the iteration.  It defaults to 10%.  Try different values > 0 if convergence is not achieved.

Your company bought an office building for $750,000, received $100,000 annually in rents, and sold the building 6 years later for $1.5 million.  What was the rate of return on the office building investment?

... ( 6 100,000 -750,000 1,500,000 ) Rate

... 0.227346390097793 = 22.7%


Cash Flows, Variable Size

Irr

Internal rate of return.

Mirr

Modified internal rate of return.

Npv

Net present value.


Irr

...  (  ( v1 ... vn  )  guess  )  Irr

...  irr

The internal rate of return (irr) of a series of future cash flows ( v1 ... vn ) is the rate for which the net present value (npv) of those cash flows is zero.

The cash flows must include at least one positive and one negative value.

Cash received is positive and cash paid out is negative.

Newton's iterative method is used to find the irr.  There may be more than one solution.  If convergence is not achieved within 50 iterations, an error is reported.

guess is an optional starting value for the iteration.  It defaults to 10%.  Try different values > 0 if convergence is not achieved.

What interest rate must you get if you want to invest $8,000 and get back $12,000 per the following investment schedule:  -$5,000, $1,000, $1,500, $2,000, -$3,000, $2,500, and $5,000?

... ( ( -5,000 1,000 1,500 2,000 -3,000 2,500 5,000 ) ) Irr

... 0.150482578238737 = 15 %

Check your answer by calculating the net present value at that interest rate.  The npv should be zero (or practically so).

... ( ( -5,000 1,000 1,500 2,000 -3,000 2,500 5,000 ) 0.150482578238737 ) Npv

...  -1.73627778821128*10^-12 =  -0.000000000001736 = 0


Mirr

...  b_rate  i_rate  ( v1 ... vn )  Mirr

...  mirr

The modified internal rate of return (mirr) of a series of future cash flows (v1 ... vn) is the effective Annual Percentage Rate (APR) when cash paid out is borrowed at b_rate, cash received is invested at i_rate, and there is a zero ending balance in the investment.

The cash flows must include at least one positive and one negative value.

Cash received is positive and cash paid out is negative.

Given the cash flows of -$5,000, $1,000, $1,500, $2,000, -$3,000, $2,500, and $5,000; where you will be borrowing the negative flows at 12% APR and investing the positive flows at 17% APR; what is your effective APR on the investment if, at the end, you have a zero balance?

... 0.12 0.17 ( -5,000 1,000 1,500 2,000, -3,000 2,500 5,000 ) Mirr

... 0.151866751908389 = 15.2%


Npv

...  ( ( v1 ... vn  )  rate  ) Npv

...  npv

Gives the net present value (npv) of a series of future cash flows ( v1 ... vn ) discounted at a constant interest rate.

It's assumed the cash flows occur at the end of equal time intervals.  You must add any cash flow occurring at the beginning of the first period.

Cash received is positive and cash paid out is negative.

If you make an $80,000 investment at an APR of 10%, and will be withdrawing $5,000, $15,000, $30,000, $40,000, and $50,000 at the end of each of the first 5 years, what is the net present value of your investment.

... ( ( 5,000 15,000 30,000 40,000 50,000 ) 10 % ) Npv  80,000 -

... 17,848.1971549385


Depreciation

Ddb

Declining balance (double, or other factor).

Sln

Straight line.

Syd

Sum of the year's digits.


Ddb

...  ( cost  salvage  life  period  factor  ) Ddb

...  z

Gives the depreciation (z) of an asset for the specified period using the double-declining (or specified factor) balance method.

All arguments should be positive numbers.

salvage value is ignored -- it is included only for consistency with other financial functions.

life and period must be in the same time units, e.g. years.

If factor is omitted it is assumed to be 2 (double-declining).

If you purchased a piece of equipment for $10,000 that has a useful life of 10 years and a salvage value of $500, what is the DDB depreciation during the 6th year?

...  ( 10,000 500 10 6 ) Ddb

...  655.36


Sln

...  ( cost  salvage  life  ) Sln

...  z

Gives the depreciation (z) of an asset for any period using the straight line method.

All arguments should be positive numbers.

If you purchased a piece of equipment for $10,000 that has a useful life of 10 years and a salvage value of $500, what is the SLN depreciation during the 6th year?

...  ( 10,000 500 10 ) Sln

...  950


Syd

...  ( cost  salvage  life  period  )  Syd

...  z

Gives the depreciation (z) of an asset for the specified period using the sum-of-the-year's-digits method.

All arguments should be positive numbers.

life and period must be in the same time units, e.g. years.

If you purchased a piece of equipment for $10,000 that has a useful life of 10 years and a salvage value of $500, what is the SYD depreciation during the 6th year?

...  ( 10,000 500 10 6 ) Syd

...  863.636363636364


Interest, APR vs EFF
Interest, APR vs. EFF

Annual vs. Effective explained

Apr

Annual Percentage Rate.

Eff

Effective percentage rate.


Annual vs Effective explained
Annual vs. Effective explained

The Annual Percentage Rate (apr) is the interest rate per compounding period multiplied by the number of compounding periods per year.

The annual effective rate (eff) is the compounded annual interest rate that you actually earn/pay over the year.

eff  =  100  *  ( interest amount paid over the year ) / ( principal at beginning of year )

eff  >  apr,  if  n >  1.

eff  =  apr,  if  n =  1.


Apr

...  eff  n  Apr

...  apr

An investment earns an eff of 18%.  If interest is compounded weekly, what is the apr?

...  18 % 52 Apr

...  0.165778131923149  =  16.6 %


Eff

...  apr  n  Eff

...  eff

What is the eff for a certificate of deposit that pays an apr of 15% compounded monthly?

...  15 % 12 Eff

...  0.160754517722998  =  16.1 %


Percentage

%

%+

%-

Delta%


%

...  x  %

...  z

... 15 %

... 0.15


%+

...  x  p  %+

...  z

Add a percentage ( p ) of x to x.

...  2,500  15  %+

...  2,875


%-

...  x  p  %-

...  z

Subtract a percentage ( p ) of x from x.

...  3,500 25 %-

...  2,625


Delta%

...  x  y  Delta%

...  z

Find percentage change from x to y.

If you made $80 last week and $100 this week, what is the percent increase?

...  80 100 Delta%

...  0.25

If a camera has been marked down from $400 to $300, what is the percent discount?

...  400 300 Delta%

...  -0.25


Conversion

To ASCII & Back

To base N number

To integer

To string & back

To string & back by format


To ASCII & Back

Ascii

Chr$


Ascii

...  str  Ascii

...  ascii

Converts the first character of a string to its  numeric ASCII value.

... {Alphabet} Ascii

... 65


Chr$

...  num  Chr$

...  char

Converts num to integer, then the low order byte to the corresponding ASCII string character.

... 65  Chr$

... {A}


To base N number

BaseN$

Encode


BaseN$

...  ( num  N  digitsInGroup  complement ) BaseN$

...  strNum

Converts a number (num) to a base N ( N > 1 ) string representation (strNum).

The result string is formatted as:

for num > 0:	dd,ddd,ddd.ddd'ddd'dd*N^0;

for num < 0:	-dd,ddd,ddd.ddd'ddd'dd*N^0;

or (complement <> 0)

<sdd,ddd,ddd.ddd'ddd'dd*N^

The number of digits offset by the grouping characters (commas and apostrophes) is digitsInGroup (working away from the decimal point).  If digitsInGroup < 2 then there will be no grouping done.

The above not withstanding, if there is no encoding string defined for base N (see Encode), then each digit is represented by a base 10 integer offset by the grouping characters.

In base complement form, the negative sign character (<) implies the infinite extension of the sign digit (only one of which is shown).

... ( 100 16 ) BaseN$

... {64*16^0}

... ( -2 16 2 1 ) BaseN$

... {<FE*16^0}

... ( 25 8 ) BaseN$

... {31*8^0}

... ( 36 1.5 * 36 ) BaseN$

... {1I*36^0}

... ( -1024.015625 64 ) BaseN$

... {-16,0.1*64^0}

... ( -16,0.1*64^0 2 4 true ) BaseN$

... {<1011,1111,1111.1111'11*2^0}


Encode

...  {encoding} Encode

...

Sets the encoding string for base = Len(encoding) to encoding.  The encoding string is used by BaseN$ and the Results Window.

A default encoding string is used for bases from 2 to 36 if the user has not specified one.  It is:

{0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ} base Left$

Set the binary encoding to F for 0 and T for 1.  Show a number with that encoding.  Then change the encoding back to 0 and 1 and show the same number.

... {FT} Encode

...

... ( 9.1875  2 ) BaseN$

... {TFFT.FFTT*2^0}

... {01} Encode

...

... ( 9.1875  2 ) BaseN$

... {1001.0011*2^0}


To integer

Fix

Int

Floor

Ceil


Fix

...  x  Fix

...  n

Gives the closest integer (n) to the number (x) that lies between the number and zero; i.e., truncates the fractional part.

... 8.9  Fix

... 8

... -8.9  Fix

... -8


Int

...  x  Int

...  n

Returns the closest integer (n) to the number (x) that is smaller than the number.

... 8.9  Int

... 8

... -8.9  Int

... -9


Floor

...  x  Floor

...  z

z  =  largest integer  <=  x.  (Floor is an alias for Int.)

... 8.9  Floor

... 8

... -8.9  Floor

... -9


Ceil

...  x  Ceil

...  z

z  =  smallest integer  >=  x.

... 8.9  Ceil

... 9

... -8.9  Ceil

... -8


To string & back

Str$

Val


Str$

...  x  Str$

...  str

Converts a number (x) to a string (str).

Positive numbers have a leading space; negative numbers have a negative sign.

... 9  Str$

... { 9}

... -9  Str$

... {-9}

... {Button Number}  3  Str$  +

... {Button Number 3}


Val

...  str  Val

...  z

Converts a string (str) to a number (z).

Val strips spaces, but any other non-numeric (base 10) character other than a decimal point will cause Val to truncate the string at that character.

... {923}  Val

... 923

... {123.456} {   7} + Val 1 +

... 124.4567


To string & back by format

Format$

Parse


Format$

...  (  x  {format}  )  Format$

...  str

Converts a number (x) to a string (str) following a specified format.

If {format} is omitted, Format$ simply converts the number to a string.  (See formatting characters below.)

... ( 2.715 {$0.00} )  Format$

... {$2.72}

... ( {4/15/1985}  dateValue  {mmmm d, yyy} )  Format$

... {April 15, 1985}

Numeric format characters:

None	Format$ is same as Str$, but without leading space.

0	Digit.  Use 0 instead of space.  Infinite automatic extension to left of decimal point.  Rounding at last specified digit to right of decimal point.

#	Same as 0, but suppress leading and trailing zeroes, without using blanks.

.	Decimal place holder, per Intl. Control Panel Number Format.

,	Thousands separator, per Intl. Control Panel Number Format.  Also scales by 1000 if in string of commas at end of format or just before decimal.

%	Number is multiplied by 100 and displayed with a %.

E- E+ e- e+	Scientific format.  Place an E or e at specified point.  Use + to force a + sign to show, or a - to show only - signs.

- + $ ( ) space	Display the literal character.

\	Display next character as a literal.

"xyz"	Display xyz as a literal string.

Number format strings can contain up to 3 sections (if none are predefined formats) separated by semicolons.

	Sections used	Result
	One	Applies to all values.
	Two	Values >= 0 : Values < 0.
	Three	Values > 0 : Values < 0 : 0.
Predefined Number Formats (use as "name"):

General Number	#.#...#
Currency	#,##0.00 : (#,##0.00)
Fixed	0.00
Standard	#,###.00
Percent	#.00%
Scientific	0.#...#E-###
Yes/No	"Yes" : "Yes" : "No"
True/False	"True" : "True" : "False"
On/Off	"On" : "On" : "Off"
Date/Time format characters:

:	Time separator, per Intl. Control Panel Time Format.

/	Date separator, per Intl. Control Panel Date Format.

c	Combination of ddddd and ttttt

d	Day of month, 1-31.

dd	Day of month, 01-31.

ddd	Day of week, 3 letters.

dddd	Day of week, spelled out.

ddddd	Date per Intl. Control Panel Short Date

dddddd	Date per Intl. Control Panel Long Date

w	Weekday, 1-7 = Sun - Sat.

ww	Week of year, 1-53.

m	Month of year, 1-12; or

Minute, 0-59, if after h or hh.

mm	Month of year, 01-12: or

Minute, 00-59, if after h or hh.

mmm	Month, Jan-Dec.

mmmm	Month, January-December.

q	Quarter of year, 1-4.

y	Day of year, 1-366.

yy	Year, 00-99.

yyyy	Year, 100-9999.

h	Hour, 0-23.

hh	Hour, 00-23.

n	Minutes, 0-59.

nn	Minutes, 00-59.

s	Seconds, 0-59.

ss	Seconds, 00-59.

ttttt	Time per Intl. Control Panel Time Format.

AM/PM	12 hour clock with AM or PM.

am/pm	12 hour clock with am or pm.

A/P	12 hour clock with A or P.

a/p	12 hour clock with a or p.

AMPM	12 hour clock with s1159 or s2359 string from WIN.INI file.

Predefined Date/Time Formats (use as "name"):

General Date	3/16/94  05:26 AM

Long Date	Intl. Control Panel Long Date

Short Date	Intl. Control Panel Short Date

Medium Date	Same as Short Date, except 3 letter Month

Long Time	Intl. Control Panel Long Time

Short Time	h:m

Medium Time	h:m AM/PM

String format characters:

Fill place holders from left to right (default is right to left).

@	Character or space place holder.

&	Character or nothing place holder.

<	Force lowercase.

>	Force uppercase.

String format strings can contain up to 2 sections (if none are predefined formats) separated by semicolons.

	Sections used	Result
	One	Applies to all strings.
	Two	Strings <> "" : Strings = "".


Parse

...  (  str  {format}  )  Parse

...  z

Converts a string (str) to a number (z) following a specified format.  (See Format$ for formatting characters.)

Note:  Parse was available in the PenPoint version of PenCalc, but is not (yet) available in the Windows version.  Do you see a need for it?

... ( {$1,000} {$,###} )  Parse

... 1,000

... ( {zero} {#;(#);zero} )  Parse

... 0

... ( {(12.7)} {0;(0);zero} )  Parse

... -12.7


Curve fitting

Straight line

Exponential curve

Logarithmic curve


Straight line

FitToLine

TrendLine


FitToLine

...  (   ( known_y's )   ( known_x's )   )  FitToLine

...  (  m  b  )

Fits the known data points to a straight line,  y = m * x + b, using the method of least squares.  Returns the slope (m) and y intercept (b) of that straight line.

If omitted, known_x's are set to  (  1  2  3  ...  ).

Find the slope and y intercept of the straight line that best fits your first 6 months of sales for this year.

... ( ( 3,100 4,500 4,400 5,400 7,500 8,100 ) ) FitToLine

... ( 1,000 2,000 )


TrendLine

...  (   ( known_y's )  ( known_x's )   ( new_x's )   )  TrendLine

...  (  y1  ...  yn  )

Fits the known data points to a straight line, y = m * x + b, using the method of least squares (by calling FitToLine).  Returns a list of y values on that line that correspond to the new_x's, or to the known_x's if the new_x's are omitted.

If omitted, known_x's are set to  (  1  2  3  ...  ).

Find the linear trend of your first 6 months of sales for this year.

... ( ( 3,100 4,500 4,400 5,400 7,500 8,100 ) ) TrendLine

... ( 3,000 4,000 5,000 6,000 7,000 8,000 )

Forecast your sales for the next 3 months.

... ( ( 3,100 4,500 4,400 5,400 7,500 8,100 ) ( 1 2 3 4 5 6 ) ( 7 8 9 ) ) TrendLine

... ( 9,000 10,000 11,000 )


Exponential curve

FitToExp

TrendExp


FitToExp

...  (   ( known_y's )  ( known_x's )   )  FitToExp

...  (  m  b  )

Fits the known data points to an exponential curve, y = b * m ^ x, using the method of least squares.  Returns the parameters  m  and  b.

If omitted, known_x's are set to  (  1  2  3  ...  ).

FitToExp uses FitToLine by converting the exponential curve to a straight line using logarithms.

Find the parameters of the exponential curve that best fits your first 6 months of sales for this year.

... ( ( 3,100 4,500 4,400 5,400 7,500 8,100 ) ) FitToExp

... ( 1.20544063515087 2,712.17323163296 )


TrendExp

...  (   ( known_y's )  ( known_x's )   ( new_x's )   )  TrendExp

...  (  y1  ...  yn  )

Fits the known data points to an exponential curve, y = b * m  ^ x, using the method of least squares (by calling FitToExp).  Returns a list of y values on that curve that correspond to the new_x's, or to the known_x's if the new_x's are omitted.

If omitted, known_x's are set to  (  1  2  3  ...  ).

Find the exponential trend for your first 6 months of sales for this year.

...  ( ( 3,100 4,500 4,400 5,400 7,500 8,100 ) ) TrendExp

...  ( 3,269.36382297882   3,941.02400331085   4,750.67047769584   5,726.65123802614   6,903.13810565373   8,321.32318261338 )

Forecast your sales for the next 3 months.

... ( ( 3,100 4,500 4,400 5,400 7,500 8,100 ) ( 1 2 3 4 5 6 ) ( 7 8 9 ) ) TrendExp

... ( 10,030.8611025451   12,091.6075785621   14,575.7151194969 )


Logarithmic curve

FitToLn

TrendLn


FitToLn

...  (   ( known_y's )  ( known_x's )   )  FitToLn

...  (  m  b  )

Fits the known data points to a logarithmic curve, y = m * ln (x) + b, using the method of least squares.  Returns the parameters  m  and  b.

If omitted, known_x's are set to  (  1  2  3  ...  ).

FitToLn uses FitToLine by first converting known_x's to ln ( known_x's ).


TrendLn

...  (   ( known_y's )  ( known_x's )   ( new_x's )   )  TrendLn

...  (  y1  ...  yn  )

Fits the known data points to a logarithmic curve, y = m * ln (x) + b, using the method of least squares (by calling FitToLn).  Returns a list of y values on that curve that correspond to the new_x's, or to the known_x's if the new_x's are omitted.

If omitted, known_x's are set to  (  1  2  3  ...  ).


Date/Time

Date/Time Serial Numbers

Date/Time To String

To Date/Time

Date/Time To Unit Number


Date/Time Serial Numbers

Dates are represented within a date/time serial number as the number of days since December 30, 1899.

Times are  represented within a date/time serial number as a fraction of one day (e.g., 12:00 noon = 12:00 pm = 0.5, 6:00 am = 0.25, and 6:00 pm = 0.75).

Date/time serial  numbers are held and manipulated internally as double precision floating point numbers, but are limited to the range January 1, 100 through December 31, 9999 and 0:00:00 to 23:59:59.


Date/Time To String

Date$

Time$


Date$

...  x  Date$

...  str

Converts date/time serial number (x) to a string (str) formatted as M/D/YY.

... Now Dup Date$ {, } -3 Rotate Time$ + +

... {4/7/94, 11:17 AM}


Time$

...  x  Time$

...  str

Converts date/time serial number (x) to a string (str) formatted as HH:MM AM/PM.

... Now Dup Date$ {, } -3 Rotate Time$ + +

... {4/7/94, 11:20 AM}


To Date/Time

Date/Time From Numbers

Date/Time From Strings

Now


Date/Time From Numbers

DateSerial

TimeSerial


DateSerial

...  year  month  day  DateSerial

...  z

Converts year, month, and day numbers into a date/time serial number (z).

... 1992 8 7 DateSerial

... 33,823

... 33,823 Date$

... {8/7/92}


TimeSerial

...  hour  minute  second  TimeSerial

...  z

Converts hour, minute, and second numbers into a date/time serial number (z).

... 0 0 50 TimeSerial

... 5.78703703703704*10^-4

... 5.78703703703704*10^-4  Second

... 50.

... 6 0 0 TimeSerial

... 0.25

... 12 0 0 TimeSerial

... 0.5


Date/Time From Strings

DateValue

TimeValue


DateValue

...  str  DateValue

...  z

Converts a valid date/time string (str) to a date serial number (z).  If the year is omitted, the computer's system date year is used.

... {1/1/91} DateValue

... 33,239

... ( {4/15/1985}  DateValue  {mmmm d, yyyy} )  Format$

... {April 15, 1985}

... {August, 30}  DateValue  Date$

... {8/30/94}

... {} DateValue

... Illegal function call

... Now

... 34,431.4822106482


TimeValue

...  str  TimeValue

...  z

Converts a valid date/time string (str) to a time serial number (z).

... {2:24 AM} TimeValue

... 0.1

... {0:0:50} TimeValue

... 5.78703703703704*10^-4

... 5.78703703703704*10^-4 Second

... 50.

... ( {0:0:50}  TimeValue  {h:n:s} )  Format$

... {0:0:50}

... {6:0}  TimeValue

... 0.25

... {12:0}  TimeValue

... 0.5


Now

...  Now

...  z

Gives the date/time serial number for the current system date and time.

... Now  Dup  Date$  {, }  -3  Rotate  Time$  +  +

... {4/7/94, 11:41 AM}


Date/Time To Unit Number

Date To Unit Number

Time To Unit Number


Date To Unit Number

Day

Month

Weekday

Year


Day

...  x  Day

...  day

Gives day of month (1 to 31) of the date/time serial number x.

... 1992  5  27  DateSerial  Day

... 27.

... {1/1/91}  DateValue  Day

... 1.


Month

...  x  Month

...  month

Gives month of year (1 to 12 ) of the date/time serial number x.

... 1992  5  27  DateSerial  Month

... 5.

... {1/1/91}  DateValue  Month

... 1.


Weekday

...  x  Weekday

...  weekday

Gives day of week (1 to 7, where 1  =  Sunday) of the date/time serial number x.

... {Nov 24, 1993}  DateValue  Weekday

... 4.


Year

...  x  Year

...  year

Gives year of the date/time serial number x.

...  Now  Year

... 1,994


Time To Unit Number

Hour

Minute

Second


Hour

...  x  Hour

...  hour

Gives the hour (0 to 23) of the specified date/time serial number x.

... {9 AM}  TimeValue  Hour

... 9.

... {4 pm}  TimeValue  Hour

... 16.


Minute

...  x  Minute

...  minute

Gives the minute (0 to 59) of the date/time serial number x.

... {3:17 PM}  TimeValue  Minute

... 17.


Second

...  x  Second

...  second

Gives the second (0 to 59) of the date/time serial number x.

... 0  0  50  TimeSerial  Second

... 50.


DisplayXxx

...  DisplayXxx

...

Set Result Window display mode to Xxx; where Xxx is one of the following:

Sci, Eng, Fix, Bin, Oct, Dec, Hex, Asc .


List

Parentheses

Define a list.

+ (With Lists)

Concatenate two lists.

Get

Copy an element of a list to the top of the stack.

Put

Put a value on the stack into a list, overwriting the element already there.

Split

Split a list into two lists.

UnGroup

Take all elements out of a list and place them on the stack.


Parentheses

...  (  )

...

Begin a list with  (  and end it with  ) , being sure to have at least one space on each side of both (since both are legitimate PenCalc words and need to be delimited by spaces).

... ( 55  54  51  55  53  53  54  52 )  Num  Swap  Drop

... 8.


+ (With Lists)

... (  x1  ...  xm  )   (  y1  ...  yn  )  +

... (  x1  ...  xm   y1  ...  yn  )

Concatenates two lists.

... ( 55  54  51 ) ( 55  53  53  54  52 ) +

... ( 55  54  51  55  53  53  54  52 )


Get

... ( x1 ... xn )   i  Get

... ( x1 ... xn )  xi

Get an item from a list.

... ( 55 54 51 55 53 53 54 52 )  8  Get  Swap  Drop

... 52.


Put

... ( x1 ... xn )   i  y  Put

... ( x1 ... xi-1  y   xi+1 ... xn )

Put an item into a list.

... ( 55  54  51  55  53  53  54  52 )  5  50  Put

... ( 55  54  51  55  50  53  54  52 )


Split

... (  x1  ...  xn  )  i  Split

... (  x1  ...  xi-1  )   (  xi  ...  xn  )

Split a list into two lists.

... ( 55 54 51 55 53 53 54 52 ) 4  Split  Memory  Store

... ( 55 54 51 )

...  Memory  Recall

... ( 55 53 53 54 52 )


UnGroup

... (  x1  ...  xn  )  UnGroup

... x1  ...  xn

Take all items out of a list and put them on the Data Stack individually.

... (  ( 55 54 51 55 53 53 54 52 )  UnGroup )

... ( 55 54 51 55 53 53 54 52 )


Logic

Bitwise Logical Operators

Relational Operators


Bitwise Logical Operators

And

Eqv

False

Imp

Not

Or

True

Xor


And

...  x  y  And

... z

Bitwise logical And.

Each bit in result z is 1 if the corresponding bits in both x and y are 1, otherwise it is 0.

... 1 2  And

... 0

... 1 3  And

... 1


Eqv

...  x  y  Eqv

... z

Bitwise logical equivalence.

Each bit in result z is 1 if the corresponding bits in both x and y are the same, otherwise it is 0.

... 1 2  Eqv

... -4

... 1 3  Eqv

... -3


False

...  False

... 0


Imp

...  x  y  Imp

... z

Bitwise logical implication.

Each bit in result z is 1 if the corresponding bit in x is 0 or the corresponding bit in y is 1, otherwise it is 0.

... 1 2  Imp

... -2

... 1 3  Imp

... -1


Not

...  x  Not

...  z

Bitwise negation (reverses bits).

Each bit in result z is 1 if the corresponding bit in x is 0, otherwise it is 0.

... 1  Not

... -2

... 2  Not

... -3


Or

...  x  y  Or

...  z

Bitwise logical inclusive Or.

Each bit in result z is 1 if one of the corresponding bits in x or y is 1, otherwise it is 0.

... 1 2  Or

... 3

... 1 3  Or

... 3


True

...  True

... -1

Every bit in -1 is a 1 (because negatives are held in 2's complement form).

Thus, True works as expected with the other bitwise logical operations.


Xor

...  x  y  Xor

...  z

Bitwise logical exclusive or.

Each bit in result z is 1 if the corresponding bits in x and y are different, otherwise it is 0.

... 1 2  Xor

... 3

... 1 3  Xor

... 2


Relational Operators

=

>

<

<>

<=

>=

0=

0<

0>


=

... x   y   =

... b

Equal to.

If  x  =  y  then  b  =  True, else  b  =  False.

... 1 2  =

... 0

... 1  1  =

... -1


>

... x   y   >

... b

Greater than.

If  x  >  y  then  b  =  True, else  b  =  False.

... 1  2  >

... 0

... 1 1 >

... 0

... 1 0  >

... -1


<

... x   y   <

... b

Less than.

If  x  <  y  then  b  =  True, else  b  =  False.

... 1 2  <

... -1

... 1 1  <

... 0

... 1 0  <

... 0


<>

... x   y   <>

... b

Not equal to.

If  x  <>  y  then  b  =  True, else  b  =  False.

... 1 2  <>

... -1

... 1 1  <>

... 0

... 1 0  <>

... -1


<=

... x   y   <=

... b

Less than or equal to.

If  x  <=  y  then  b  =  True, else  b  =  False.

... 1 2  <=

... -1

... 1 1  <=

... -1

... 1 0  <=

... 0


>=

... x   y   >=

... b

Greater than or equal to.

If  x  >=  y  then  b  =  True, else  b  =  False.

... 1 2  >=

... 0

... 1 1  >=

... -1

... 1 0  >=

... -1


0=

... x  0=

... b

b = ( x  =  0 )


0<

... x  0<

... b

b = ( x  <  0 )


0>

... x  0>

... b

b = ( x  >  0 )


Math

Algebraic

Exponential & Logarithmic

Hyperbolic

Polar Coordinates

Random Numbers

Trigonometric


Algebraic

+

-

*

!

/

\

*/

1+

1-

2+

2-

2*

2/

100*

100/

Abs

Mod

ModK

Neg

Product

Round

Sign

Sqrt


+ (Addition)
+

...  x  y  +

...  z

z  =  x  +  y

...  3  2  +

... 5


-

...  x  y  -

...  z

z  =  x  -  y

...  3  2 -

... 1


* (Multiplication)
*

...  x  y  *

...  z

z  =  x  *  y

...  3  2  *

... 6


! (Factorial)
!

...  n  !

...  m

m  =  n  ! ,  factorial.  I.e., m = [ n  *  (n - 1) * (n - 2 ) * ... * 1 ], where m and n are integers.

...  4  !

... 24


/

...  x  y  /

...  z

z  =  x  /  y

Converts operands to floating point, returns floating point result.

...  3  2  /

... 1.5


\

...  x  y  \

...  z

z  =  x  \  y,  integer division.

Rounds operands to integers, divides, then truncates the result.

...  3.21  2.6  \

... 1


*/

...  a  b  c  */

...  d

d  =  a  *  b  /  c

...  12  2  4  */

...  6


1+

...  x  1+

...  z

z  =  x  +  1


1-

...  x  1-

...  z

z  =  x  -  1


2+

...  x  2+

...  z

z  =  x  +  2


2-

...  x  2-

...  z

z  =  x  -  2


2*

...  x  2*

...  z

z  =  x  *  2


2/

...  x  2/

...  z

z  =  x  /  2


100*

...  x  100*

...  z

z  =  x  *  100


100/

...  x  100/

...  z

z  =  x  /  100


Abs

...  x  Abs

...  z

z = absolute value of x.

... 274  Abs

... 274

... -274  Abs

... 274


Mod

...  x  y  Mod

...  z

z  =  x  mod  y.

This is a direct call to the Visual Basic mod function.  Its results  differ substantially from the definition of the modulo function given by Knuth, "Fundamental Algorithms", 1969, pg. 38, and implemented by PenCalc/KeyCalc 1.1 as ModK.

x	x  3  Mod	x  3  ModK	x  -3  Mod	x  -3  ModK
3	0	0	0	0
2	2	2	2	-1
1.5	2	1.5	2	-1.5
1	1	1	1	-2
0	0	0	0	0
-1	-1	2	-1	-1
-1.5	-2	1.5	-2	-1.5
-2	-2	1	-2	-2
-3	0	0	0	0
x	x  1  Mod	x  1  ModK	x  -1  Mod	x  -1  ModK
1.5	0	0.5	0	-0.5
-1.5	0	0.5	0	-0.5
x	x  0  Mod	x  0  ModK
1.5	Error	1.5
	DivBy0


ModK

...  x  y  ModK

...  z

z  =  x  -  y  *  Floor (  x  /  y  ),  y  <>  0;
z  =  x,  y  =  0.

This is the definition of the modulo function given by Knuth, "Fundamental Algorithms", 1969, pg. 38.  Its results  differ from the Visual Basic Mod function (see table in Mod definition section).


Neg

...  x  Neg

...  -x

Algebraic negation.


Product

...  (  x1  ...  xn  )  Product

...  (  x1  ...  xn  )  z

z  =  x1  *  x2  *  ...  *  xn

... ( 5  15  30 )  Product  Swap  Drop

... 2,250

... ( 5  15  30  2 )  Product  Swap  Drop

... 4,500


Round

...  x  decimal_digit  Round

...  z

Gives z  =  x  rounded at the decimal_digit position to the right of the decimal point if  decimal_digit  >  0, or at the  -decimal_digit  position to the left of the decimal point if  decimal_digit  < 0

... 2.15  1  Round

... 2.2

... 2.149  1  Round

... 2.1

... -1.475  2  Round

... -1.48

... 891  -2  Round

... 900


Sign

...  x  Sign

...  z

x	z
>0	+1
=0	0
<0	-1
...  -5  Sign

...  -1

...  5  Sign

...  1

...  0  Sign

...  0


Sqrt

...  x  Sqrt

...  z

z  =  square root of x,  x  >  0.

... 16  Sqrt

... 4

... -16  Sqrt

... Error

... -16  Abs  Sqrt

... 4


Exponential & Logarithmic

^

Exponentiate.

e

Base of the natural logarithms.

Exp

Exponential of e.

Ln

Natural logarithm.

Log

Logarithm to any base.


^

...  x  y  ^

...  z

z  =  x  ^  y,  exponentiation.

...  3  2  ^

... 9


e

...  e

...  2.71828182845905

The base of the natural logarithms.


Exp

...  x  Exp

...  z

z  =  e  ^  x

... 1  Exp

... 2.71828182845905


Ln

...  x  Ln

...  z

z  =  ln  x, the natural logarithm of  x,  x > 0 .

... 2.71828182845905  Ln

... 1


Log

...  (  number   base   )  Log

...  z

Gives the logarithm of number to the base base, number > 0,  base > 1.

z  =  ( ln  number  )  /  (  ln  base  )

If base is not specified it is assumed to be 10.

... ( 10 )  Log

... 1

... ( 8 2 )  Log

... 3


Hyperbolic

Sinh

Cosh

Tanh

Asinh

Acosh

Atanh


Sinh

...  x  Sinh

...  z

z  = sinh  x.  The hyperbolic sine.

... 1.5  Cosh  1.5  Sinh  -

... 0.22313016014843


Cosh

...  x  Cosh

...  z

z  = cosh x.  The hyperbolic cosine.

... 1.5  Cosh  1.5  Sinh  -

... 0.22313016014843


Tanh

...  x  Tanh

...  z

z  = tanh  x.  The hyperbolic tangent.

... 2.5  Tanh

... 0.98661429815143


Asinh

...  x  Asinh

...  z

z  =  arc sinh  x.  The inverse of the hyperbolic sine.

... 30  Asinh

... 4.09462222433053


Acosh

...  x  Acosh

...  z

z  =  arc cosh  x,  x > 1.  The inverse of the hyperbolic cosine.

... 30  Acosh

... 4.09406666863209


Atanh

...  x  Atanh

...  z

z  =  arc tanh  x,  x  <  1.  The inverse of the hyperbolic tangent.

... 0.88  Atanh  4  /

... 0.343941914130244


Polar Coordinates

Ra2x

Ra2y

Xy2a

Xy2r


Ra2x

...  r  a  Ra2x

...  x

Calculates the  x  value of the rectangular coordinates of the point whose polar coordinates are  ( r, a ).

... 2  60 °  Ra2x

... 1


Ra2y

...  r  a  Ra2y

...  y

Calculates the  y  value of the rectangular coordinates of the point whose polar coordinates are  (r,a).

... 2 60 °  Ra2y

... 1.73205080756888

... 3  Sqrt

... 1.73205080756888


Xy2a

...  x  y  Xy2a

...  a

Calculates the polar coordinate angle (a), in radians, from the rectangular coordinates  (x,y)  of a point.

... 1  3  Sqrt  Xy2a  Deg

... 60


Xy2r

...  x  y  Xy2r

...  r

Calculates the polar length coordinate (r), from the rectangular coordinates  (x,y)  of a point.

... 1  3  Sqrt  Xy2r

... 2


Random Numbers

Seed

Rand


Seed

...  (  x  )  Seed

...

Seeds random number generator with  x.  If  x  is omitted, the number of seconds since 12:00 am is used.

Without  Seed, Rand  returns the same random numbers every time you run PenCalc.


Rand

... ( x )  Rand

...  z

z  =  a pseudo random number in the range  [0, 1).  Note that 1 is not in the range but 0 is.

z  is determined based on the value of  x  as follows:

x	z

Omitted	The next pseudo random number in the sequence.

>0	The next pseudo random number in the sequence.

=0	The pseudo random number returned by the last call to Rand.

<0	The same pseudo random number every time, as determined by x.


Trigonometric

pi

Deg

Rad

°

°'

°"

Sin

Cos

Tan

Asin

Acos

Atan


pi

...  pi

...  3.14159265358979

For all circles, pi  =  circumference / diameter.


Deg

...  x  Deg

...  z

Convert angular radians (x) to degrees (z).

...  pi  Deg

... 180.


Rad

...  x  Rad

...  z

Converts angular degrees ( x ) to radians ( z ).

...  180  Rad

...  3.14159265358979	=  pi


°

...  x  °

...  z

Convert angular degrees (x) to radians (z).

This does the same thing as Rad, but it is a useful notation.

... 180  °

... 3.14159265358979

...  30  °  Sin

... 0.5


°'

...  x  °'

...  z

Convert angular minutes (x) to radians (z).

... 63  °  52  °'  41  °"  +  +  Cos

... 0.440283084663162


°"

...  x  °"

...  z

Convert angular seconds (x) to radians (z).

... 63  °  52  °'  41  °"  +  +  Cos

... 0.440283084663162


Sin

...  x  Sin

...  z

z  =  sine  x,  x in radians.

... pi  6  /  Sin

... 0.5

... 60 °  Sin

... 0.866025403784439

... 3  Sqrt  2  /

... 0.866025403784439


Cos

...  x  Cos

...  z

z  =  cosine x,  x in radians.

... 63  °  52  °'  41  °"  +  +  Cos

... 0.440283084663162

... 60 °  Cos

... 0.5


Tan

...  x  Tan

...  z

z  =  tangent  x,  x in radians.

... 45 °  Tan

... 1

...  pi  Neg  2  /  Tan

...  -1.63245522776191*10^16	= -infinity

...  pi  2  /  Tan

...  1.63245522776191*10^16	= +infinity


Asin

...  x  Asin

...  z

z  =  arc sine x,  in radians, in range -pi/2 to pi/2.

... -0.5  Asin

... -0.523598775598299

... -0.5  Asin  Deg

... -30


Acos

...  x  Acos

...  z

z  =  arc cosine  x,  in radians, in range 0 to pi.

... -0.5  Acos

... 2.0943951023932

... -0.5  Acos  Deg

... 120


Atan

...  x  Atan

...  z

z  =  arc tangent  x,  in radians from  -pi/2  to  pi/2.

... 1  Atan

... 0.785398163397448

... 1  Atan  Deg

... 45

... -1.63245522776191*10^16  Atan  Deg

...  -90

... 1.63245522776191*10^16  Atan  Deg

... 90


Programming

Constants & Variables

Compiling

Execution

If, Else, Then

Input Stream & Dictionary

Iteration

Termination


Constants & Variables

Constant

Variable

Recall

Store

+Store

Predefined Constants & Variables


Constant

...  x  Constant  yyy

...

Defines a word named yyy with value x.  Subsequent references to yyy copies the value x onto the stack.  Note that x can be a list.

... 5  Constant  five

...

... five

... 5


Variable

... Variable  yyy

...

Defines a word named yyy which, when referenced, places its own address on the stack.  Thus values can be Stored and Recalled using Variables.

... Variable  temp

...

... 5  temp  Store

...

... temp  Recall

... 5

Note:  Memory is a predefined Variable.


Recall

... variable  Recall

... value

Copies variable's value onto top of Data Stack.

... ( 55 54 51 55 53 53 54 52 )  Memory  Store

...

... Memory Recall

... ( 55 54 51 55 53 53 54 52 )


Store

... x  variable  Store

...

Store  x  as  value  of  variable, overwriting previous value.

... ( 55 54 51 55 53 53 54 52 )  Memory  Store

...

... Memory Recall

... ( 55 54 51 55 53 53 54 52 )


+Store

... x  variable  +Store

...

If y is the value of variable, then x + y is Stored as the new value of variable.

... ( 55 54 51 55 )  Memory  Store

...

... ( 53 53 54 52 )  Memory  +Store

...

... Memory Recall

... ( 55 54 51 55 53 53 54 52 )

... {PenC}  Memory  Store

...

... {alc 1.0}  Memory  +Store

...

... Memory Recall

... {PenCalc/KeyCalc 1.1}

... 1  Memory  Store

...

... 2  Memory  +Store

...

... Memory Recall

... 3


Predefined Constants & Variables

The following definitions are in the System Words file:

	Value	Defining Word	Word
	0	Constant	0
	1	Constant	1
	-1	Constant	-1
	2	Constant	2
	-2	Constant	-2
	3	Constant	3
	-3	Constant	-3
	10	Constant	10
	100	Constant	100
	0	Constant	False
	-1	Constant	True
		Variable	Memory


Compiling

[    and    ]

Switch between Compiling and Calculator modes.

Choice

Add a word to Words Window choice list.

Colon Compiler

Create a new word.

,  (Comma)

Add/compile a stack data item to the word Dictionary.

Compile

[Compile]

Create

Create a word head in the Dictionary

Does>

Define the runtime behavior for a Defining Word's children.

Immediate

Flag a word to be executed inside a Colon Definition.

Literal

Compile a stack data item as a literal.


[    and    ]

[  leaves compile mode,
]  enters compile mode.

Inside a Colon Definition, anything placed inside brackets is executed Immediately -- it is not compiled.

... : Say-Hello  { Hello } ;

... : Greet [ Say-Hello ]  { I Speak FORTH. }  ;

... { Hello }

... Greet

... { I Speak FORTH. }

Note that in the above example Say-Hello is not an Immediate word.


Choice

Choice sets a flag in the last word in the Dictionary so that PenCalc will enter the word's name in the Words Window choice list.

... Variable Memory Choice


Colon Compiler

... :  xxx  yyy  ;

...

A new word named xxx is defined with action yyy.


,

... x  ,

...

,  compiles x into the Dictionary (at the end).

,  is the most basic compiling word.


Compile

Compile retrieves the contents of the next Dictionary address in the currently executing word and compiles it into the Dictionary (at the end). Compile then causes execution to skip the address it referenced.

... : Do Compile 2>R  Here ; Immediate Choice


[Compile]

If the next atom in the Input Stream is not a defined word when [Compile] is executed, Abort is executed.

[Compile] is an Immediate word that compiles the address of the next word in the Input Stream into the Dictionary (at the end) regardless of whether that word is Immediate or not.

Indeed, the intent of [Compile] is to be able to compile Immediate words that are inside Colon Definitions without having them execute.

... : Loop 1 [Compile] Literal [Compile] +Loop ; Immediate Choice


Create

... Create  name

...

Creates the Head of a new Dictionary entry, assigning the next atom from the Input Stream as its name.  When executed, name puts its pfa on the Data Stack.

Just after Create is executed, the next location for compilation in the Dictionary is the pfa of name.  If data is then added to the Dictionary (with comma (,), for instance) the address for that data can be obtained by executing name.

For example, here's the definition of Variable and Memory:

... : Variable Create 0 , ; Choice

... Variable Memory Choice

When executed, Variable creates a Dictionary entry for Memory and then stores a null data pointer in the location pointed to by Memory's pfa.  (Memory is a child of Variable.)  Then if Recall is executed you get:

... Memory  Recall

... 0

The usual usage of Create is inside the Colon Definition of a Defining Word, such as Variable or Constant.  See Does> for how to define the run-time behavior of the Defining Word's children.


Does>

Does> is used with Create inside the Colon Definition for a Defining Word, such as Constant.

Does> defines the run-time behavior of the Defining Word's children.   At run-time of a child, Does> leaves the pfa of the child on the Data Stack.

... : Constant  Create  ,  Does>  Recall  ;  Choice

... 76 Constant Trombones

... Trombones

... 76


Immediate

Immediate sets a flag in the last word in the Dictionary so that the Colon Compiler will execute the word rather than compiling its address.

Immediate itself is an Immediate word.

... : Say-Hello { Hello } ; Immediate

...

... Say-Hello

... { Hello }

... : Greet  Say-Hello { I Speak FORTH. } ;

... { Hello }

... Greet

... { I Speak FORTH. }


Literal

... x  Literal

...

Literal compiles x (on top of the Data Stack) into the Dictionary as a literal.

The following two definitions result in identical Dictionary entries:

... : 4+  4  +  ;

... 4  : 4+  Literal  +  ;


Execution

Execute

Vectored Execution


Execute

... adr  Execute

...

Executes the word whose pfa is adr.

... : Greet  {Hello, I speak FORTH} ;

...

... Greet

... {Hello, I speak FORTH}

... '  Greet  Execute

... {Hello, I speak FORTH}


Vectored Execution

Instead of Executing a word directly, as in

... '  Greet  Execute

... {Hello, I speak FORTH}

you can Execute it indirectly by using a variable to hold its address, then Executing the value of the variable:

... Variable  Pointer

...

... '  Greet  Pointer  Store

...

... Pointer  Recall  Execute

... {Hello, I speak FORTH}

The advantage is that you can change the pointer later, so that a single word (the pointer variable) can be made to perform different things at different times.


If, Else, Then

... :  aaa  b  If  xxx  Else  yyy  Then  zzz  ;

...

If-Else-Then phrases are only valid inside Colon Definitions (b, however, could be on the stack outside of the Colon Definition).  The Else  yyy phrase and zzz are optional.  xxx, yyy, and zzz can all be any valid sequence of valid words; in particular, they can all contain If-Else-Then phrases.

When aaa is executed, If  b <> 0  xxx is executed, Else  yyy is executed.  Then  zzz is executed.


Input Stream & Dictionary

[']

Empty

Find

Forget

Here

LastSystemWord

Load

Number

'  (Tick)

Word


[']

['] (Bracket-Tick-Bracket) is an Immediate word usually used inside Colon Definitions.

['] gets the next word from the Input Stream, finds its pfa in the Dictionary, and compiles the pfa into the Dictionary as a Literal.

For example:

... : Hello {Hello} ;

... : Goodbye {Good-bye} ;

... Variable 'Aloha

... : Aloha 'Aloha Recall Execute ;

... : Coming ['] Hello 'Aloha Store ;

... : Going ['] Goodbye 'Aloha Store ;

... Coming  Aloha

... {Hello}

... Going  Aloha

... {Good-bye}

Compare to the following example that uses ' (which is not an Immediate word):

... : Say  '  'Aloha  Store ;

... Say  Hello

... Aloha

... {Hello}

... Say  Goodbye

... Aloha

... {Good-bye}


Empty

... Empty

...

Scans the Dictionary starting with the last word defined and proceeding toward the first word defined.  If a scanned word is not LastSystemWord delete it and scan next word.  If a scanned word is LastSystemWord exit Forget without deleting LastSystemWord.


Find

... Find  xxx

... adr TRUE 	xxx found in Dictionary

or

... Find  xxx

... {xxx} FALSE 	xxx NOT found in Dictionary


Forget

... Forget  xxx

...

Scans the Dictionary starting with the last word defined and proceeding toward the first word defined.  If a scanned word is not xxx or LastSystemWord delete it and scan next word.  If a scanned word is xxx delete it and exit Forget.  If a scanned word is LastSystemWord exit Forget without deleting LastSystemWord.

Note:  You can tag the Dictionary to allow partial deletions by defining null definitions (e.g., ... : xxx ; ) before defining the words you later want to delete, and then Forgetting your null definition (e.g., ... Forget  xxx).


Here

... Here

... adr

Here returns the address of the next compiling location in the Dictionary.


LastSystemWord

A null word defined at the end of the System Words file to mark the end of System Word definitions in the Dictionary.  Used by Forget and Empty.


Load

... {file}  Load

...

The Input Stream for a calculation consists initially of the Calculation String in the Calculation Window.  Load logically inserts the contents of file into the Input Stream, replacing "{file}  Load".  file must a valid path and file name.  Note that Loaded files may contain Loads.


Number

... {str}  Number

... num

or

... {{str}}  Number

... {str}

Number is used by the PenCalc Interpreter to convert Input Stream atoms into numbers or strings after Execute has told the Interpreter that the atom is not a defined word in the Dictionary.

If Number can't convert the atom into a valid number or string, it returns the error "Not a number."

It's not obvious how Number would be useful to PenCalc users, but here it is.


'
'  (Tick)

Gets the next word from the Input Stream, finds its pfa in the Dictionary, and puts the pfa on the Data Stack.

... '  xxx

... pfa  	xxx found in Dictionary

or

... '  xxx

... {xxx ?}	xxx NOT found in Dictionary

If xxx is not found, '  not only sets the Data Stack to {xxx ?} but also Quits.

... : Greet  {Hello, I speak FORTH} ;

...

... Greet

... {Hello, I speak FORTH}

... '  Greet

... _da:848f

To find out if a word is defined in the Dictionary use ' to find its address.  If the word is not in the Dictionary ' will return its name with a question mark rather than its address.

... '  XX

... {XX ?}


Word

... Word  atom1  atom2  ...

... {atom1}

Word gets the next atom from the Input Stream and puts it on the Data Stack.

If the Input Stream is exhausted Word displays an error dialog and Quits.


Iteration

Do, +Loop, Loop, Leave

Begin, Until


Do, +Loop, Loop, Leave

... : aaa  limit index Do  xxx  n  +Loop  yyy ;

...

or

... : aaa  limit index Do  xxx  Loop  yyy;

...

Do-Loop and Do-+Loop phrases are only valid inside Colon Definitions.

Do puts the limit and index on the Return Stack and then continues execution with xxx.

+Loop increments index by n and then either:  a) reroutes execution back to the beginning of xxx; or b) removes limit and index from the Return Stack and continues execution with yyy (which can be null).  Case a) occurs when n >= 0 and index < limit, or when n < 0 and index >= limit.  Otherwise case b) occurs.  Note that xxx must reestablish n on the Data Stack on each iteration, since it is consumed by +Loop.  Never allow n to be zero as an infinite loop will occur and lock up your computer.

Loop is the same as +Loop except that n is internally set to 1 on each iteration.

Leave can be used in xxx to force termination of the loop on the next occurrence of Loop or +Loop.


Begin, Until

... :  aaa  Begin  xxx  b  Until  yyy  ;

...

Begin-Until phrases are only valid inside Colon Definitions.

Begin marks the beginning of the loop.

Until reroutes execution back to the beginning of xxx if b <> 0, otherwise execution continues with yyy (which can be null).  xxx must reestablish b on the Data Stack on each iteration since Until consumes it.


Termination

Exit

Quit

Abort


Exit

...  Exit

...

Terminate execution of present word and return flow of execution to calling word.  (Pops the Return Stack.)


Quit

...  Quit

...

Clears both stacks and ceases all execution.


Abort

... x  Abort

x

Same as Quit, except the top item on the stack before Aborting (x) becomes the only item on the stack afterwards.  Thus x will be displayed in the Result Window (usually x would be an error message string).


Stack

Data Stack

Return Stack


Data Stack

Drop

2Drop

Dup

?Dup

2Dup

Over

Rotate

Rot

Swap


Drop

... x  Drop

...

Delete item on top of stack.


2Drop

... : 2Drop Drop Drop ; Choice


Dup

... x  Dup

... x  x

Duplicates item on top of stack.


?Dup

... x  ?Dup

... x  x

or

... 0  ?Dup

... 0

Duplicates the top item on the stack only if it is not 0.


2Dup

... : 2Dup Over Over ; Choice


Over

... x  y  Over

... x  y  x

Puts a copy of second item onto stack.


Rotate

... xn  xn-1  ...  x2  x1  n  Rotate

... x1  xn  xn-1  ...  x2 	for  n > 0

or

... xn-1  ...  x2  x1  xn 	for  n < 0

Rotate  n  Data Stack items:  toward top of Data Stack for n > 0, toward bottom of Data Stack for n < 0.

300 cc is added to a solution of 500 cc.  What is the percent of the new volume to the initial one?

... 500  Dup  300  +  2  Rotate  /  100  *

... 160.


Rot

... x  y  z  Rot

... y  z  x

Rotates the third stack item to the top of the stack.


Swap

... x  y  Swap

... y  x

Swaps the top two stack items.

300 cc is added to a solution of 500 cc.  What is the percent of the new volume to the initial one?

... 500  Dup  300  + Swap  /  100  *

... 160.


Return Stack

The Return Stack is used by PenCalc to remember where it is in the various words that have called each other.  Using it for temporary storage is possible within a Colon Definition; but be sure to remove anything you added before you reach the semicolon.

>R

R>

I

I'

J

2>R


>R

... x  >R

...

>R (To R) takes x off Data Stack and puts it on Return Stack.


R>

... R>

... x

R> (R from) takes x off Return Stack and puts it on Data Stack.


I

... I

... x

I makes a copy of the top item on the Return Stack and puts it on the Data Stack.


I'

... I'

... x

I' (I prime) makes a copy of the second item on the Return Stack and puts it on the Data Stack.


J

... J

... x

J makes a copy of the third item on the Return Stack and puts it on the Data Stack.


2>R

2>R moves the top two items on the Data Stack to the Return Stack.

... : Do Compile 2>R  Here ; Immediate Choice


Statistical

Average

Average of a list of values.

GeoMean

Geometric mean of a list of values.

Max

Maximum of a list of values.

Min

Minimum of a list of values.

Num

Number of elements in a list of values.

StdDev

Standard deviation of a sample of a population.

StdDevP

Standard deviation of a population.

Sum

Sum of a list of values.

SumSqrs

Sum of the squares of a list of values.

Var

Variance of a sample of a population.

VarP

Variance of a population.


Average

...  (  x1  ...  xn  )  Average

...  (  x1  ...  xn  )  z

z =  Sum( xi )  /  n.

... ( 55  54  51  55  53  53  54  52 )  Average  Swap  Drop

... 53.375


GeoMean

...  (  x1  ...  xn  )  GeoMean

...  (  x1  ...  xn  )  z

z =  the geometric mean of the  x  values.

The geometric mean is the n-th root of the product of the n values.  The values should all be positive ( but it is possible to get an (erroneous and negative) answer when the product is negative if also n is odd).

... ( 55  54  51  55  53  54  200 )  GeoMean  Swap  Drop

... 64.7438349128531

... ( 55  54  51  55  53  54  200 )  Average  Swap  Drop

... 74.5714285714286

To gain insight into what the geometric mean is, consider the case where n = 2.  Multiplying the two values gives us the area of a rectangle with sides equal in length to the two values.  Taking the square root of the area gives the length of the sides of a square having the same area as the original rectangle.  Extrapolating to n > 2, the geometric mean is the length of the side of the n-dimensional square whose "area" is equal to the "area" of the n-dimensional rectangle represented by the x values.

So, in some sense, the geometric mean is more representative of the data than the arithmetic mean (average) when you have a few values much larger than the rest.

For example, the geometric mean is used to "average" the results of many performance tests on a computer into one "representative" number for that computer.  In this case, the geometric mean tends to reduce the impact of one measurement that is very high (which may be due to the fact that the computer was built to do that particular task extremely well -- at the expense of other tasks; e.g., floating point calculations), and results in a more balanced representative performance number for that computer.


Max

...  (  x1  ...  xn  )  Max

...  (  x1  ...  xn  )  z

z =  maximum  xi  value.

... ( 55 54 51 55 53 53 54 52 )  Max  Swap  Drop

... 55


Min

...  (  x1  ...  xn  )  Min

...  (  x1  ...  xn  )  z

z =  minimum  xi  value.

... ( 55 54 51 55 53 53 54 52 )  Min  Swap  Drop

... 51


Num

... ( x1 ... xn )   Num

... ( x1 ... xn )   n

n = number of items in the xi list.

... ( 55  54 51 55 53 53 54 52 )  Num  Swap  Drop

... 8


StdDev

...  (  x1  ...  xn  )  StdDev

...  (  x1  ...  xn  )  z

Gives the estimated standard deviation (z) of a population based on a sample ( x1 ... xn ) of the population.

... ( 55 54 51 55 53 53 54 52 )  StdDev  Swap  Drop

... 1.40788595317336


StdDevP

...  (  x1  ...  xn  )  StdDevP

...  (  x1  ...  xn  )  stddevp

Gives the standard deviation (z) of a population based on the entire population ( x1 ... xn ).

... ( 55 54 51 55 53 53 54 52 )  StdDevP  Swap  Drop

... 1.31695671910659

Note the following equivalent, but inefficient, method:

... ( 55 54 51 55 53 53 54 52 ( 55 54 51 55 53 53 54 52 )  Average  Swap  Drop )  StdDev  Swap  Drop

... 1.31695671910659


Sum

...  (  x1  ...  xn  )  Sum

...  (  x1  ...  xn  )  z

z =  sum of all the  xi  values.

... ( 55 54 51 55 53 53 54 52 )  Sum  Swap  Drop

... 427


SumSqrs

...  (  x1  ...  xn  )  SumSqrs

...  (  x1  ...  xn  )  z

z =  sum of all the xi ^ 2  values.

... ( 55 54 51 55 53 53 54 52 )  SumSqrs  Swap  Drop

... 22,805


Var

...  (  x1  ...  xn  )  Var

...  (  x1  ...  xn  )  z

Gives the estimated variance (z) of a population based on a sample (xi) of the population.

... ( 10 7 9 27 2 )  Var  Swap  Drop

... 89.5


VarP

...  (  x1  ...  xn  )  VarP

...  (  x1  ...  xn  )  z

Gives the variance (z) of a population based on the entire population (xi).

... ( 10 7 9 27 2 )  VarP  Swap  Drop

... 71.6

Note the following equivalent, but inefficient, method:

... ( 10 7 9 27 2 ( 10 7 9 27 2 )  Average  Swap  Drop )  Var  Swap  Drop

... 71.6


String/Text

+ (With Strings)

Concatenate two strings.

Instr

Find position of one string in another.

Lcase$

Force string to lower case.

Left$

Extract characters from left side of a string.

Len

Find length of a string.

Ljust$

Left justify non-blank characters in a string.

Ltrim$

Trim (discard) blank characters on the left side of a string.

Mid$

Get/set a substring within a string.

Right$

Extract characters from right side of a string.

Rjust$

Right justify non-blank characters in a string.

Rtrim$

Trim (discard) blank characters on the right side of a string.

Space$

Create a string made up of a sequence of spaces.

String$

Create a string made up of a sequence of the same character.

Trim$

Trim (discard) blank characters on the left and right side of a string.

Ucase$

Force string to upper case.


+  (With Strings)

...  {str1}  {str2}  +

... {str1str2}

Concatenates two strings.


Instr

...  (  string  pattern  start   )  Instr

...  i

i  =  position in string of the first occurrence of pattern beginning at position start.  If start is omitted, the search begins at position 1.

i  =  0  if pattern not found.

... ( {Average VanGun} {A} )  Instr

... 1

... ( {Average VanGun} {a} ) Instr

... 5

... ( {Average VanGun} {a} 6 ) Instr

... 10


Lcase$

...  STR  Lcase$

...  str

Converts a string's letters to lower case.

... {E.E.Cummings}  Lcase$

... {e.e.cummings}


Left$

...  str  n  Left$

...  z

Returns  n  characters from the left of  str.

... {Paul Irving}  4  Left$

... {Paul}


Len

...  str  Len

...  z

Returns the byte length of  str.

... {E.E.Cummings}  Len  Swap Drop

... 12


Ljust$

...  str  Ljust$

...  z

Left justifies text in a string without changing the length of the string.

... {         Left}  Ljust$

... {Left         }


Ltrim$

...  str  Ltrim$

...  z

Removes leading spaces and tabs from a string.

... {       XYZ       }  Ltrim$

... {XYZ       }


Mid$

... (  string  start  length  replacement_string  )  Mid$

... str

If replacement_string omitted:

str  is set to that portion of string beginning with character number start and length characters long.  If length is omitted, str extends from start to the end of string.

If replacement_string not omitted:

str  is set to string with that portion beginning with character number start, and length characters long, replaced with replacement_string.  If length is greater than the number of characters in replacement_string, it is reset to Len ( replacement_string ).  str  will always have the same number of characters as string.

... ( {Hello World} 1 5 )  Mid$

... {Hello}

... ( {Hello World} 12 5 )  Mid$

... {}

... ( {abcde} 1 1 {*} )  Mid$

... {*bcde}

... ( {abcde} 3 2 {*} )  Mid$

... {ab*de}

... ( {abcde} 3 2 {**} )  Mid$

... {ab**e}

... ( {abcde} 3 2 {***} )  Mid$

... {ab**e}

... ( {any text} 1 {any text} Len Swap Drop {} )  Mid$

... {any text}


Right$

...  str  n  Right$

...  z

Returns  n  characters from the right of str.

... {Paul Irving}  6  Right$

... {Irving}


Rjust$

...  str  Rjust$

...  z

Right justifies text in a string without changing the length of the string.

... {Right         }  Rjust$

... {         Right}


Rtrim$

...  str  Rtrim$

...  z

Removes trailing spaces and tabs from a string.

... {       XYZ       }  Rtrim$

... {       XYZ}


Space$

...  n  Space$

...  z

Gives a string of n spaces.

... 1  Space$

... { }


String$

...  n  char  String$

...  z

Gives a string made up of  n  char  characters.

... 10 {!}  String$

... {!!!!!!!!!!}


Trim$

...  str  Trim$

...  z

Removes leading and trailing spaces and tabs from a string.

... {       XYZ       }  Trim$

... {XYZ}


Ucase$

...  str  Ucase$

...  STR

Converts a string's letters to upper case.

... {Shout!}  Ucase$

... {SHOUT!}


Technical Support

Contact Information

Future Enhancements

Known Bugs

Release Notes


Contact Information

Please send questions, problem reports, suggestions for improvements, general comments, and all other correspondence about PenCalc/KeyCalc 1.1 to:

StuPENdous Software

P.O. Box 1582

Westford, MA  01886-4996

U.S.A.

Or on CompuServe, in PenForum ONLY please, to:  70372,2676

Or call us at:  (508) 692-4878

We'd like to hear from you!


Future Enhancements

The following are possible future enhancements to PenCalc/KeyCalc 1.1.  Let us know what you think.  Is this a good list to work on?  Is the priority right?  What other features are desirable?

a.	Graphic presentation of data  --  like graphical handheld calculators.

b.	Matrix algebra.

c.	DDE implementation -- so other programs could access PenCalc programmatically.

e.	Convert calculation engine to DLL using C (now in Visual Basic) to enhance speed.  But this would reduce ability to quickly add new features.

f.	Change List and String words to consume their stack data.  Currently they don't because I thought the list or string could be used by subsequent operations, thereby increasing efficiency.  But I have noticed that I have to use a lot of Swap Drop sequences in the examples.

g.	Add context sensitivity to Help.

h.	Add browsing to Help.

I.	Add simple file I/O.


Known Bugs

a.	The results of the Mod function differ substantially from the results of the ModK function;  where the ModK function is a direct implementation of an algorithm from a reputable mathematical text, and the Mod function is a direct call to the Visual Basic Mod function.


Release Notes

Version 1.1:  April 26, 1994

1.	Added Edit menu with Undo, Cut, Copy, Paste, and Delete functions.

2.	Made Mode and Modifier menus visible on Menu Bar to facilitate keyboard selections.

3.	First release of KeyCalc (as version 1.1 -- to keep versions of both products the same).

Initial Release:  Version 1.0, PenCalc only:  April 18, 1994.


Distribution/Registration

What is Shareware?

Warranty Disclaimer

Distribution

Registration


What is Shareware?

Shareware distribution gives users a chance to try software before buying it. If you try a Shareware program and continue using it, you are expected to register.  Individual programs differ on details -- some request registration while others require it, some specify a maximum trial period.  With registration, you get anything from the simple right to continue using the software to an updated program with printed manual.

Copyright laws and International Treaties apply to both Shareware and commercial software, and the copyright holder retains all rights, with a few specific exceptions as stated below.  Shareware authors are accomplished programmers, just like commercial authors, and the programs are of comparable quality.  (In both cases, there are good programs and bad ones!)  The main difference is in the method of distribution.  With Shareware distribution the author specifically grants the right to copy and distribute the software, either to all and sundry or to a specific group.  For example, some authors require written permission before a commercial disk vendor may copy their Shareware.

Shareware is a distribution method, not a type of software.  You should find software that suits your needs and pocketbook, whether it's commercial or Shareware.  The Shareware system makes fitting your needs easier, because you can try before you buy.  And because the overhead is low, prices are low also.  Shareware has the ultimate money-back guarantee -- if you don't use the product, you don't pay for it.


Warranty Disclaimer

PenCalc 1.1 AND KeyCalc 1.1 ARE SUPPLIED AS IS.  Stephen Kent Stephenson AND StuPENdous Software HEREBY DISCLAIM ALL WARRANTIES RELATING TO THIS SOFTWARE, WHETHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Stephen Kent Stephenson AND StuPENdous Software WILL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, INDIRECT OR SIMILAR DAMAGES DUE TO LOSS OF DATA OR ANY OTHER REASON, EVEN IF Stephen Kent Stephenson AND/OR StuPENdous Software AND/OR AN AGENT OF EITHER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.  IN NO EVENT SHALL LIABILITY FOR ANY DAMAGES EVER EXCEED THE PRICE PAID FOR THE LICENSE TO USE PenCalc 1.1 AND/OR KeyCalc 1.1, REGARDLESS OF THE FORM OF THE CLAIM.  THE USER OF PenCalc 1.1 AND/OR KeyCalc 1.1 BEARS ALL RISK AS TO THE QUALITY AND PERFORMANCE OF PenCalc 1.1 AND/OR KeyCalc 1.1.


Distribution

Personal Distribution Of PenCalc/KeyCalc 1.1

Commercial Distribution Of PenCalc/KeyCalc 1.1


Personal Distribution Of PenCalc/KeyCalc 1.1

PenCalc 1.1 and KeyCalc 1.1 are Shareware programs that are provided to the user for a 30 day evaluation at no charge.  You are encouraged to copy and distribute PenCalc 1.1 and KeyCalc 1.1 for non-commercial use with the following restrictions:

a.	You may copy and distribute the entire, original, unmodified, distribution files of PenCalc 1.1 and/or KeyCalc 1.1 (see *.ZIP files in Installation section above).  You may NOT distribute individual files.  This ensures that users receive a complete package with all documentation.

b.	You may NOT charge any fee for the use, copying, or distribution of PenCalc 1.1 and/or KeyCalc 1.1.


Commercial Distribution Of PenCalc/KeyCalc 1.1

The Personal Distribution terms apply equally to Commercial Distribution, except:

1.	Clubs, user groups, and ASP approved Shareware distributors may charge a nominal fee (not to exceed USA$10) for expenses of distributing PenCalc/KeyCalc 1.1, as long as they make it clear to the user that he or she has paid for distribution, NOT for registration of PenCalc/KeyCalc 1.1, and that he or she still has an obligation to register and purchase a right-to-use License for PenCalc/KeyCalc 1.1 if he or she continues to use PenCalc/KeyCalc 1.1 past the 30 day evaluation period.  Normal connect time charges of BBSs are not considered distribution charges.

2.	All other organizations must obtain written permission to distribute copies of PenCalc/KeyCalc 1.1 if any fee is to be charged for the use, copying, or distribution of the product.

3.	All organizations must notify StuPENdous Software that they are distributing PenCalc and/or KeyCalc 1.1 by letter or electronic mail.


Registration

If you continue to use PenCalc/KeyCalc 1.1 after the initial 30 day evaluation period, you must Register and purchase one or more right-to-use Licenses.

License to use PenCalc/KeyCalc 1.1

Registration Form


License to use PenCalc/KeyCalc 1.1

Each License purchased gives you the right to use one copy of PenCalc 1.1 and KeyCalc 1.1 on a single computer.  PenCalc 1.1 and/or KeyCalc 1.1 are being "used" on a computer when one or both of them are loaded into temporary memory (i.e., RAM) or installed into permanent memory (e.g., ROM, PROM, hard disk, attached floppy disk, PCMCIA card, etc.) of that computer.

Licenses are available for purchase individually or in various quantity lots at discounted prices (they're cheaper by the dozen).  To purchase Licenses to use PenCalc/KeyCalc 1.1, print, complete, and mail the Registration Form included at the end of this section, along with your payment.

When you Register you will receive a registration code.  Once the registration code has been entered into PenCalc/KeyCalc 1.1, the title line will no longer display "Unregistered Copy" or "Illegal Copy", and your name and address will appear in the About PenCalc/KeyCalc 1.1 dialog as the Registered User.  The Debug Menu will also appear, giving you some tools for debugging programs you write.  And the About dialogs will no longer be displayed on startup.

Registered Users will receive notices of new version releases with special update pricing.


Registration Form
PenCalc/KeyCalc 1.1 Registration Form

To Register your copy (or copies) of PenCalc/KeyCalc 1.1, print, complete, and mail this form with payment for the right-to-use License(s) to the address given below.  You will receive, by mail, a registration code which may be entered into PenCalc/KeyCalc 1.1 to enhance their features.

Name, Title, Company, Division, Mail Stop, Mail Address, Country, Phone, Email Address:

________________________________________________________________________________

________________________________________________________________________________

________________________________________________________________________________

________________________________________________________________________________

________________________________________________________________________________

Description	Price    (USA$)	Quantity	Total
PenCalc/KeyCalc 1.1 shareware distribution disk; right-to-use License NOT included (order below); disk available in U.S.A. only.	9.95
MA orders add 5% sales tax on disk total (tangible goods):
One (1) PenCalc/KeyCalc 1.1 right-to-use License	49.95
One dozen (12) PenCalc/KeyCalc 1.1 right-to-use Licenses	479.52
One gross (144) PenCalc/KeyCalc 1.1 right-to-use Licenses	4,603.39
Shipping and Handling:			9.95
Total Due:
Make payment by check or money order drawn on a U.S.A. bank in U.S.A. dollars made payable to the order of StuPENdous Software.

Mail To:	StuPENdous Software

P.O. Box 1582

Westford, MA  01886-4996

U.S.A.

Thank you for supporting Shareware.


RPN - Reverse Polish Notation


pfa - parameter field address

The dictionary address of the word's first parameter  (data) field.  The pfa points to the first dictionary address after the  word's head.


ASP - Association of Shareware Professionals, 545 Grover Rd., Muskegon, MI 49442-9427, USA.


BBS - Bulletin Board System (electronic).