Formula calculator
Encyclopedia
A formula calculator is a software calculator that can perform a calculation in two steps:

1. Enter the calculation by typing it in from the keyboard.

2. Press a single button or key to see the final result.

This is unlike button-operated calculators, such as the Windows calculator or the Mac OS X calculator, which require the user to perform one step for each operation, by pressing buttons to calculate all the intermediate values, before the final result is shown.

In this context, a formula is also known as an expression
Expression (programming)
An expression in a programming language is a combination of explicit values, constants, variables, operators, and functions that are interpreted according to the particular rules of precedence and of association for a particular programming language, which computes and then produces another value...

, and so formula calculators may be called expression calculators. Also in this context, calculation is known as evaluation, and so they may be called formula evaluators, rather than calculators.

How they work

Formulas as they are commonly written use infix notation
Infix notation
Infix notation is the common arithmetic and logical formula notation, in which operators are written infix-style between the operands they act on . It is not as simple to parse by computers as prefix notation or postfix notation Infix notation is the common arithmetic and logical formula notation,...

 for binary operators, such as addition, multiplication, division and subtraction. This notation also uses:
  • Parentheses to enclose parts of a formula that must be calculated first.

  • In the absence of parentheses, operator precedence, so that higher precedence operators, such as multiplication, must be applied before lower precedence operators, such as addition. For example, in 2 + 3*4, the multiplication, 3*4, is done first.

  • Among operators with the same precedence, associativity
    Associativity
    In mathematics, associativity is a property of some binary operations. It means that, within an expression containing two or more occurrences in a row of the same associative operator, the order in which the operations are performed does not matter as long as the sequence of the operands is not...

    , so that the left-most operator must be applied first. For example, in 2 - 3 + 4, the subtraction, 2 - 3, is done first.


Also, formulas may contain:
  • Non-commutative operators that must be applied to numbers in the correct order, such as subtraction and division.

  • The same symbol used for more than one purpose, such as - for negative numbers and subtraction.


Once a formula is entered, a formula calculator follows the above rules to produce the final result by automatically:
  • Analysing the formula and breaking it down into its constituent parts, such as operators, numbers and parentheses.

  • Finding both operands of each binary operator.

  • Working out the values of these operands.

  • Applying the operator to these values, in the correct order so as to allow for non-commutative operators.

  • Evaluating the parts of a formula in parentheses first.

  • Taking operator precedence and associativity into account.

  • Distinguishing between different uses of the same symbol.

Operators

Formulas printed in many text books use juxtaposition, underline and superscripts for multiplication, division and exponentiation respectively. Also, some operations, such as square root, are represented by special symbols that are not usually available on a computer keyboard. For example, see the formulas in Amortization calculator
Amortization calculator
An amortization calculator is used to determine the periodic payment amount due on a loan , based on the amortization process....

, Heron's formula and Law of cosines
Law of cosines
In trigonometry, the law of cosines relates the lengths of the sides of a plane triangle to the cosine of one of its angles. Using notation as in Fig...

.

Multiplication

In many software tools, including spreadsheets and programming languages, the asterisk, *, is used for multiplication. However, it is also possible to use juxtaposition. For example:

2cos(3)

means 2 multiplied by cos(3).

In calculators that don’t allow juxtaposition, the asterisk (and possibly x rather than, or as well as, the asterisk), is used, and the calculation should be entered as:

2*cos(3)

Also, a period is sometimes used for multiplication, as in:

2.cos(3)

Because the period is also used as the decimal point in numbers, so that the “2.” in the above would be interpreted as 2.0, the period is not used for multiplication in a formula calculator, and this calculation should be entered using a different symbol, as above.

Division

Printed formulas often use a horizontal line for division, but in a formula calculator that uses only keyboard symbols, division is entered using the forward slash, /. When there is a calculation above or below the line, this should be done first, and so it should be enclosed in parentheses when typed in. For example,

2 + 3
—————
4 - 5

should be entered as

(2 + 3)/(4 - 5)

Also, the symbol ÷ is often used for division, as in

2 ÷ 3

This symbol is not available on most computer keyboards, so this division operation is entered using the forward slash, as above.

Exponentiation

Exponentiation, or raising to a power, is often represented using a superscript. For example:

2.452

means 2.45 squared.

With the limitations of a computer keyboard, in some software packages, such as Microsoft Excel
Microsoft Excel
Microsoft Excel is a proprietary commercial spreadsheet application written and distributed by Microsoft for Microsoft Windows and Mac OS X. It features calculation, graphing tools, pivot tables, and a macro programming language called Visual Basic for Applications...

, this is entered using the caret, ^:

2.45^2

but two asterisks are also used:

2.45**2

Exponentiation and functions

When using functions, the superscript is sometimes placed immediately after the function name. For example, it is common to write the trigonometric version of Pythagoras’ Theorem (List of trigonometric identities) as:

sin2(x) + cos2(x) = 1

In this identity,

sin2(x)

means the square of sin(x), and is the same as:

sin(x)2

So, for x = 3.25, it could be entered into a formula calculator that uses the caret for exponentiation as:

sin(3.25)^2

Square roots

Square roots are often specified using the √ symbol, but with the limitations of a keyboard this is can be entered by using exponentiation. For example, the square root of 2:

√2

could be entered as:

2^(1/2)

but two asterisks are also used:

2**(1/2)

The parentheses specify that the division should be done first.

Other roots

All roots can be specified in this way. For example, the cube root of 2 can be entered as:

2^(1/3)

Heron’s formula example

An example that illustrates these features is Heron’s formula.

One version of the formula, for a triangle with sides of length a, b and c, is equivalent to, using symbols that are available on a keyboard:

1/2*(a^2*c^2 - (a^2 + c^2 - b^2)/2)^0.5

For a = 2.5, b = 3.6 and c = 1.9, it could be entered into a formula calculator as:

1/2*(2.5^2*1.9^2 - (2.5^2 + 1.9^2 - 3.6^2)/2)^0.5

Types of calculator

The formula calculator concept can be applied to all types of calculator, including arithmetic, scientific, statistics, financial and conversion calculators.

The calculation can be typed or pasted into an edit box of:

• A software package that runs on a computer, for example as a dialog box.

• An on-line formula calculator hosted on a web site.

It can also be entered on the command line of a programming language.

Related software packages

Although they are not calculators in themselves, because they have a much broader feature set, many software tools have a formula-calculation capability, in that a formula can be typed in and evaluated. These include:

• Spreadsheets, where a formula can be entered to calculate a cell’s content.

• Databases, where a formula can be used to define the value of a calculated field in a record.

Declarative and imperative tools

Button-operated calculators are imperative
Imperative
Imperative can mean:*Imperative mood, a grammatical mood expressing commands, direct requests, and prohibitions * A morphological item expressing commands, direct requests, and prohibitions...

, because the user must provide details of how the calculation has to be performed.

On the other hand, formula calculators are more declarative
Declarative
Declarative may refer to:* Declarative learning, acquiring information that one can speak about* Declarative memory, one of two types of long term human memory* Declarative programming, a computer programming programming paradigm...

 because the typed-in formula specifies what to do, and the user does not have to provide any details of the step-by-step order in which the calculation has to be performed.

Declarative solutions are easier to understand than imperative solutions, and so there has been a long-term trend from imperative to declarative methods. Formula calculators are part of this trend.

Many software tools for the general user, such as spreadsheets, are declarative. Formula calculators are examples of such tools.

Hybrid calculators

There are hybrid calculators that combine typed-in formula and button-operated calculation. For example:

• Calculations can be entered entirely from the keyboard, or operations can be applied to typed-in numbers or formulas using buttons, in the same calculator.

• Formulas can be constructed using buttons, rather than being entered from the keyboard.

• Formula copies of button-operated calculations can be created, saved and re-loaded for application to different numbers.

See also

  • Software calculator
  • Comparison of software calculators
    Comparison of software calculators
    This is a list of notable software calculators.-Immediate execution calculators :-Expression or formula calculators:-See also:* Software calculator* Calculator input methods* Formula calculator* Calculator* Graphing calculator...

  • Calculator
    Calculator
    An electronic calculator is a small, portable, usually inexpensive electronic device used to perform the basic operations of arithmetic. Modern calculators are more portable than most computers, though most PDAs are comparable in size to handheld calculators.The first solid-state electronic...

  • Calculator input methods
    Calculator input methods
    There are various ways in which a calculator might interpret key strokes.One can categorize calculators into two main types: 1) single-step or immediate execution calculators and 2) expression or formula calculators....

  • Programmable calculator
    Programmable calculator
    Programmable calculators are calculators that can automatically carry out a sequence of operations under control of a stored program, much like a computer. The first programmable calculators such as the IBM CPC used punched cards or other media for program storage...

  • Scientific calculator
    Scientific calculator
    A scientific calculator is a type of electronic calculator, usually but not always handheld, designed to calculate problems in science, engineering, and mathematics...

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK