Arithmetic canon

From Fōrmulæ dictionary
Jump to: navigation, search

The Arithmetic canon is a set of rules to do symbolic arithmetic.

Canonic numbers

Number expressions are represented with the Math.Number Expression. They must have the following properties:

  • They represent only either positive real numbers or zero.
  • There are two types: Integer and decimal numbers. Integer numbers can represent only integer values, while decimal numbers can represent both integer and fractional values.

Canonic numeric expressions

A canonic numeric expression is either:

  • A canonic number, as it was previously defined.
  • A Math.Arithmetic.Negative expression, containing a canonic number as its unique child. It represents a negative number.
  • A Math.Arithmetic.Division expression, containing two Math.Number expressions representing integer numbers, as its children. Ir represents a rational number.
  • A Math.Arithmetic.Negative expression containing a rational number as defined in the previous line. It represents a negative rational number.

Canonic subtraction

There is no expression for subtraction. The operation that we represent as is a Math.Arithmetic.Addition that contains a Math.Arithmetic.Negative expression as addend, it is

However, there can be visualizations for the Math.Arithmetic.Addition that show suchh that expressions as subtraction, i.e. showing the expression

as

Canonic exact and approximated representations

There are numeric expressions that have the same value, for example (called exact) and (called decimal). However there are differences:

  • There are numbers that can be expressed in exact form but not in decimal second. For example the number (first form) cannot be represented in the second (decimal) form because it would require an infinite number of digits.
  • A decimal number with no exact representation can be approximated to an exact value, and this approximation can be improved using more significant digits. For the previous example, the number is an approximation and therefore there is an error, and is a better approximation —it has a smaller error—.
  • Performing operations with approximated decimal values usually makes the errors increase and propagate.
  • In counterpart, performing operations with exact representations produces always exact values, but the result tends to increase in number of expressions needed.

Examples

  • If we use the decimal number as an approximation for the exact value , and this result is multiplicated by 3, we will get instead of 1. In this case, the error has been propagated.
  • The constant can be calculated as a solution of the equation This exact representation is but cannot be represented with less operations.

Preferred exact representations

There are expressions in exact form that represent the same value, such as and . The expression with the less number of expressions used is preferred.

There are an infinite rational numbers that represent the same value, such as and . The preferred expression is the one that is in its lowest terms.

The exact representation is preferred over the decimal

An canonic exact representation is preferred over canonic decimal. This behavior is considered canonic.

Forcing approximated computation

However, there are situations where approximated representations are required. There are several ways to indicate this behavior:

Using a decimal number as operand

If the user creates a decimal number (even if it has no fractional part) as an operand of a certain operation, the operation will be performed approximately. The following rules apply:

  • The expected result is a mathematical calculation between the operand or several operands.
  • The result of the operation does not preserve any of the operands.
  • The nature of the operation is to generate a result that is always in exact form or always in approximated form.
  • The operation is related to explicit conversion between exact and approximated formats.

The following are examples:

Example Result Explanation
All the operators are in exact form, the result is in exact form
At least one operand is in approximated form, the result is in approximated form
The same No reduction is performed, the expression is already in an exact form
At least one operand is in approximated form, the result is in approximated form
The number of digits is defined by the precision
The expression was not in a preferred exact form
The intermediate result is exact but not in preferred form, while is
The same No reduction is performed, the expression is already in exact form and it is not expressible in less expressions
The number of digits is defined by the precision
The number of digits is defined by the precision

The following are examples where the rule does not apply:

Example Result Explanation
There are exact and decimal operators involved, but the operation preserve the nature of them
It is the operation to extract an element from a list
The same No reduction performed, there does not exist anything like a fractional index of a list
The extraction of an element from an index is not a mathematical operation, the required index is not exact but it makes sense to be considered as it would
The nature of the operation is to generate always an integer number.
The same No reduction performed, the conversion cannot be done.
The nature of the operation is to generate always an integer number.
The nature of the operation is to generate always an integer number.
The nature of the operation is to generate always a decimal number.
The nature of the operation is to generate always a rational or integer number.

Using the Math.Arithmetic.Numeric expression

The Math.Arithmetic.Numeric Expression has two purposes:

  1. To indicate the intention of perform calculations in decimal format, without the need of using decimal numbers
  2. To specify the number of significant digits used

The first form

Evaluates the given expression, using the predefined number of significant digits.

The second form

Evaluates the expression, using the given number of significant digits.

The following are examples:

Example Result Explanation
The result, if proceeded, will always be numeric.
The number only requires two significant digits to be represented.