# Numerical integration

## Integrate

Perform a numerical integration of a function for a specified variable on a
numerical interval. For example `2 3 'X*(X-3)' 'X' Integrate` returns `-7/6`.

The function takes four arguments:

* The lower bound of the integration range
* The higher bound of the integration range
* The program or expression to evaluate
* The integration variable

### IntegrationImprecision

This setting defines the relative imprecision for the result with respect to the
[Precision](#precision) setting. The default value is `6`, which means that at
the default precision of `24` digits, `Integrate` will try to compute to an
accuracy of 18 digits.

This setting only applies if the result is smaller than the display
settings. Like HP calculators, the display settings limits the precision
requested from the integration algorithm. For example, if the display is set to
`3 FIX`, then only 3 digits of precision are considered necessary in the result.

### IntegrationIterations

This setting limits the number of iterations for the integration algorithm. Each
iteration requires the evaluation of twice as many samples of the function to
integrate as the previous one, so the maximum number of samples taken is in the
order of `2^IntegrationIterations`.


# Continued fractions

## DFC

Decompose a real number into its continued fraction coefficients (Décomposition
en Fraction Continue).

`X` ▶ `{ a0 a1 a2 … }`

Returns a list of integers such that *X* ≈ a₀ + 1/(a₁ + 1/(a₂ + …)). For
integers the result is a single-element list. For rationals the expansion is
exact and finite. For decimals and irrationals (π, *e*, √2, etc.), the expansion
stops when the next convergent would exceed the precision of the input.

Examples: `22/7 DFC` → `{ 3 7 }`, `2 √ DFC` → `{ 1 2 2 2 … }`.

The inverse `DFC2F` reconstructs the value from the coefficient list.

## DFC2F

Reconstruct a real number from its continued fraction coefficient list.

`{ a0 a1 … an }` ▶ `a0 + 1/(a1 + 1/(… + 1/an))`

Evaluates the list right-to-left to produce a rational or decimal result.
`DFC2F(DFC(x))` gives an exact round-trip for integers and fractions, and an
approximate round-trip for irrationals within the current precision.

Example: `{ 3 7 } DFC2F` → `22/7`.


# Numerical conversions

## →Num

Convert fractions and symbolic constants to decimal form.
For example, `1/4 →Num` results in `0.25`.

## →Q

Convert decimal values to fractions. For example `1.25 →Frac` gives `5/4`.
The precision of the conversion in digits is defined by
[→FracDigits](#ToFractionDigits), and the maximum number of iterations for the
conversion is defined by [→FracDigits](#ToFractionIterations)

## →Qπ

Convert decimal values to a rational form, or a rational form with π, square
roots, natural logs, or the Euler constant *e* factored out, whichever yields
the smaller denominator.

The rational result is a "best guess", since there might be more than one
rational expression consistent with the argument. `→Qπ` finds a quotient of
integers that agrees with the argument to the number of decimal places specified
by the display format mode.

For example, `3.14159265359 →Qπ` gives `π`, `1.4142135624 →Qπ` gives `√2`,
and `0.346573590280 →Qπ` gives `ln 2/2`.

For a complex argument, the real or imaginary part (or both) can have a constant
factor.

The [→QπMaxPrime](#→qπmaxprime) setting (default 100, max 10000)
limits which primes are tried when factoring squares for √*n* detection. Lower
values speed up conversion on resource-constrained hardware.

The algorithm attempts: π; any √*n* (by squaring and factoring); ln 2, ln 3,
ln 5, ln 7, ln 10; *e*; *e*^(p/q); and combined factors π·√2, π·√3.

## →Integer

Convert decimal values to integers. For example `1. →Integer` gives `1`.
This command intentionally fails with `Bad argument value` if the input contains
a non-zero fractional part.
