Arithmetic package for the Fōrmulæ programming language.
Fōrmulæ is also a software framework for visualization, edition and manipulation of complex expressions, from many fields. The code for an specific field —i.e. arithmetics— is encapsulated in a single unit called a Fōrmulæ package.
This repository contains the source code for the arithmetic package. It is intended to the computation of many arithmetical and mathematical operations.
The GitHub organization formulae-org encompasses the source code for the rest of packages, as well as the web application.
Take a look at this tutorial to know the capabilities of the Fōrmulæ arithmetic package.
- Types of numbers
- Integer numbers of arbitrary size
- Decimal numbers, of arbitrary precision
- Rational numbers, of arbitrary size for numerator / denominator
- Precision management
- Based on significant digits
- It can be set globally or by specific operation
-
Rounding
- Rounding operation
- Rounding to precision. This mode is used by most operations
- Rounding modes. They can be set globally or by specific operation
- Direct, away from zero
- Direct, towards zero
- Direct, towards infinity
- Direct, towards minus infinity
- To nearest, half away from zero
- To nearest, half towards zero
- To nearest, half towards infinity
- To nearest, half towards minus infinity
- To nearest, half to even
- Rounding operation
- "Numeric" operation, forces the operation to be performed with decimal arithmetic. Precision can be specified
- Basic arithmetic operations: addition, multiplication, division and exponentiation
- Integer, decimal and rational numbers, even mixing them
- With any precision and rounding mode
- Division is visualized as fraction
$\frac{a}{b}$ - Exponentiation is visualized as
$a^b$
- Comparison between integer, decimal and rational numbers, even mixing them
-
Relational operators
$a = b$ ,$a \ne b$ ,$a > b$ ,$a < b$ ,$a \leq b$ ,$a \geq b$ - Three-way comparison operator
-
Relational operators
- Rationalization of decimal values. Rationalization specifying number of repeating digits
-
Absolute value, visualized as
$|a|$ - Sign function
-
Square root, visualized as
$\sqrt a$ -
Factorial, visualized as
$n!$ - Rounding decimal and rational numbers to integers
- Truncation
- Floor, visualized as
$\lfloor x \rfloor$ - Ceiling, visualized as
$\lceil x \rceil$ - Any other rounding mode
- Rounding decimal and rational numbers to decimal with decimal places
- Rounding decimal and rational numbers to multiple values
- Separation of integer and decimal parts, retrieving the number of decimal places
- List of digits of a integer positive number
- In base 10 by default, but any integer positive number can be specified as the base
- A size (of list) can be specified. For numbers with less digits, zero values are padded
-
Pseudorandom number generation with uniform distribution
- In the real interval
$[ 0, 1 \rangle$ - In a range of integer values
- In the real interval
- Testing operation
- Expression being a real number (integer or decimal)
- Expression being a rational number
- Expression being numeric (a integer, decimal or rational number)
- Expression beig an integer number (an integer, or decimal number with no fractional part)
- Expression being an integer number
- Expression being a decimal number
- Expression beign a positive number, either integer, decimal or rational
- Expression beign a negative number, either integer, decimal or rational
- Expression being a zero number, either integer or decimal
- Expression being an even number (either integer or decimal with no fractional part)
- Expression being an odd number (either integer or decimal with no fractional part)
- Whether an integer number divides other, visualization as
$a \mid b$ - Whether an integer number does not divide other, visualization as
$a \nmid b$
- Conversion from/to other data types
- From string to integer or decimal values, in decimal or bases between 2 and 36
- From integer or decimal number to a string representation
- Div, Mod and DivMod operations
- Between integer, decimal and rational number, even mixing them
- Using any precision
- Using any of the 9 roundig modes, or the euclidean division mode
- Related to number theory
- Primality test of a positive integer number
- List of prime factors of a integer number
- Greatest common divisor of a list of integer numbers
- Least common multiple of a list of integer numbers
- Modular exponentiation
- Modular multiplicative inverse
- Piecewise-defined functions
-
Summation of a sequence of a finite number of terms, visually using the Capital-sigma notation
$\sum$ -
Product of a sequence of a finite number of terms, visually using the Capital-pi notation
$\prod$ - Numerical calculation of the following transcendental functions, for a decimal number, with any precision and rounding mode
- Numerical calculation of the following trigonometric functions, for a decimal number, with any precision and rounding mode
- Sine, cosine, tangent, cotangent, secant, cosecant
- Arc sine, arc cosine, arc tangent, arc cotangent, arc secant, arc cosecant
- 2-argument arctangent (atan2)
- Numerical calculation of the following hyperbolic functions, for a decimal number, with any precision and rounding mode
- Sine, cosine, tangent, cotangent, secant, cosecant
- Arc sine, arc cosine, arc tangent, arc cotangent, arc secant, arc cosecant
- Symbolic representation of π and e constants. Numeric conversion with any precision and roundig mode.