# Arithmetic Expressions

Arithmetic expressions are a compact notation for combining arithmetic operations that go together. An arithmetic expression results in a numeric result.

The operations that can be combined are the binary arithmetic operations and unary arithmetic operations.

## Order of operations

1. `^`
2. unary `+` and `-`
3. `*`, `/`, `mod`
4. binary `+` and `-`

## Expression Evaluation Order

An expression is evaluated depth-first with the left branch chosen before the right.

All expressions are converted to a sequence of single operations before a computer can evaluate them.

### Equivalent Evaluations

Equivalent evaluations are evaluations that cause the same result within the maximum allowed loss of precision.

## Precision

Each operation in an expression can cause loss of precsision. The field of mathematics that contains the theory for this is the Calculus of Errors.

### Loss of precision

The loss of precision in an arithmetic expression is the precision lost when the expression is evaluated depth-first with the left branch chosen before the right. Each operation looses precision accoring to the Calculus of Erros.

## Basics of Calculus of Errors

Two values `A` and `B` have approximations `a` and `b` with errors `Δa` and `Δb`.

OperationAbsolute Error Bounds
`a + b``Δa + Δb`
`a - b``Δa + Δb`
`a * b``Δa*abs(b) + Δb*abs(a)`
`a / b``(Δa*abs(b) + Δb*abs(a))/b^2`
`a ^ b``Δa*abs(b*a^(n-1))`

Error bounds, both absolute and relative, for all arithmetic operations available in the Progsbase system are available in the literature of the Calculus of Errors.

For more information about error bounds, check out the literature of the calculus of erros.

## Examples of Expression evaluations

### Example 1

The T-Table of

`-x^2 + 3*x - 2`

is

ExpressionOperation
`-x^2 + 3*x - 2`
`-t1 + 3*x - 2``t1 = x ^ 2`
`t2 + 3*x - 2``t2 = -t1`
`t2 + t3 - 2``t3 = 3 * x`
`t4 - 2``t4 = t2 + t3`
`t5``t5 = t4 - 2`

### Example 2

The T-Table of

`(-x)^2`

is

ExpressionOperation
`(-x)^2`
`t1^2``t1 = -x`
`t2``t2 = t1 ^ 2`
###### Contact Information

We would be more than happy to help you. Our opening hours are 9–15 (CET).

📞 (+47) 93 68 22 77

Nils Bays vei 50, 0876 Oslo, Norway

Copyright © 2018-22 progsbase.com by Inductive AS.