Formula calculator

This is an old revision of this page, as edited by 180.192.20.190 (talk) at 11:03, 10 March 2011 (Square roots). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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. [1][2][3][4][5][6]

This is unlike button-operated calculators, such as the Windows calculator or the Mac os 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.[7][8][9]

In this context, a formula is also known as an expression,[10] and so formula calculators may be called expression calculators.[11] Also in this context, calculation is known as evaluation,[12] and so they may be called formula evaluators, rather than calculators.[13]

How they work

Formulas as they are commonly written use infix 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, 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.

How to enter formulas

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, Heron's formula and Law of cosines.

Multiplication

In many software tools, including spreadsheets and programming languages, the asterisk, *, is used for multiplication.[14] However, it is also possible to use juxtaposition.[15] 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, this is entered using the caret, ^:

       2.45^2

but two asterisks are also used:[14]

       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:[14]

      2**(1/2)

The parentheses specify that the division should be done first. 2 + 3

      —————
      4 - 5
 2 + 3
      —————
      4 - 5
 2 + 3
      —————
      4 - 5

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.[3][4][6]

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

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

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, because the user must provide details of how the calculation has to be performed.[16]

On the other hand, formula calculators are more declarative 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,[16][17] and so there has been a long-term trend from imperative to declarative methods.[18][19] Formula calculators are part of this trend.

Many software tools for the general user, such as spreadsheets, are declarative.[20] 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.[21]

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

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

See also

References

  1. ^ SpeedCrunch [home page on the Internet]; 2010. Available from: http://speedcrunch.org (freeware)
  2. ^ MagicPlot Calculator [home page on the Internet]; 2010. Available from: http://magicplot.com/calc (freeware)
  3. ^ a b Command Line Calculator [home page on the Internet]; 2010. Available from: http://www.kotiposti.net/jjhalme/clcmain.htm (freeware)
  4. ^ a b Formula Calculator Pty Ltd [home page on the Internet]; 2009. Available from: http://www.FormulaCalculator.com
  5. ^ a b Moisey Oysgelt [JavaScript Formula Calculator page on the Internet]; 2000. Available from: http://www.alemoi.com/math
  6. ^ a b Haxial Software Pty Ltd [calculator products page on the Internet]; 2001. Available from: http://www.haxial.com/products/calculator
  7. ^ Microsoft’s Windows Operating System Calculator Accessory; 2001. Available on a Windows PC at: Start/All Programs/Accessories/Calculator
  8. ^ MotionNET [calculator product page on the Internet]; 2006. Available from: http://www.motionnet.com/calculator
  9. ^ Flow Simulation Ltd [Virtual Calc98 page on the Internet]; 2008. Available from: http://www.calculator.org/jcalc98.html
  10. ^ Reference 3, paragraphs 1 and 2 use formula and expression interchangeably
  11. ^ Hot-Shareware.com [1st-Calculator page on the Internet]; 2009. Available from: http://www.hot-shareware.com/home-education/1st-calculator
  12. ^ Reference 3, paragraph 1
  13. ^ The Code Project [Dynamic Formula Calculator/Evaluator in VB.NET page on the Internet]; 2009. Available from: http://www.codeproject.com/KB/vb/Dynamic_Formula_Evaluator.aspx
  14. ^ a b c d The Python Programming Language. Available from http://www.python.org
  15. ^ See the discussion at http://www.autohotkey.com/forum/topic15055.ht
  16. ^ a b Harold Thimbleby. A new calculator and why it is necessary, Computing Science, Middlesex University, London, UK, September 1998. Available from: http://www.uclic.ucl.ac.uk/harold/srf/allcalcs.pdf
  17. ^ Roy E. Furman. Declarative Programming - Strategies for Solving Software Problems, http://www.articlesalley.com, July 2006. Available from: http://www.articlesalley.com/article.detail.php/7013/178/Education/Internet/36/Declarative_Programming_-_Strategies_for_Solving_Software_Problems
  18. ^ David A. Watt. Programming language concepts and paradigms, Prentice Hall, 1990 (citation 13 at http://citeseer.ist.psu.edu/context/14802/0)
  19. ^ Tatsuru Matsushita. Expressive Power of Declarative Programming Languages, PhD thesis, Department of Computer Science, University of York, October 1998 (citation 13 at http://citeseer.ist.psu.edu/context/14802/0)
  20. ^ Reference 15, paragraph 6
  21. ^ Reference 1, Buttons and The Works calculators. Available from: http://www.FC-Scientific.com and http://www.FC-Max.net
  22. ^ Gold-Software Development [LeoCalculator page on the Internet]; 2006. Available from: http://www.batchconverter.com/LeoCalculator-download-24300.shtml
  23. ^ FarsightSoft Inc [Farsight Calculator page on the Internet]; 2008. Available from: http://www.farsightsoft.com/farsightcalculator.html