Numeric and Mathematical Modules
********************************

The modules described in this chapter provide numeric and math-related
functions and data types. The "numbers" module defines an abstract
hierarchy of numeric types. The "math" and "cmath" modules contain
various mathematical functions for floating-point and complex numbers.
The "decimal" module supports exact representations of decimal
numbers, using arbitrary precision arithmetic.

The following modules are documented in this chapter:

* "numbers" --- Numeric abstract base classes

  * "Number"

  * The numeric tower

    * "Complex"

      * "real"

      * "imag"

      * "conjugate()"

    * "Real"

    * "Rational"

      * "numerator"

      * "denominator"

    * "Integral"

  * Notes for type implementers

    * Adding More Numeric ABCs

    * Implementing the arithmetic operations

* "math" --- Mathematical functions

  * Number-theoretic and representation functions

    * "ceil()"

    * "comb()"

    * "copysign()"

    * "fabs()"

    * "factorial()"

    * "floor()"

    * "fmod()"

    * "frexp()"

    * "fsum()"

    * "gcd()"

    * "isclose()"

    * "isfinite()"

    * "isinf()"

    * "isnan()"

    * "isqrt()"

    * "lcm()"

    * "ldexp()"

    * "modf()"

    * "nextafter()"

    * "perm()"

    * "prod()"

    * "remainder()"

    * "sumprod()"

    * "trunc()"

    * "ulp()"

  * Power and logarithmic functions

    * "cbrt()"

    * "exp()"

    * "exp2()"

    * "expm1()"

    * "log()"

    * "log1p()"

    * "log2()"

    * "log10()"

    * "pow()"

    * "sqrt()"

  * Trigonometric functions

    * "acos()"

    * "asin()"

    * "atan()"

    * "atan2()"

    * "cos()"

    * "dist()"

    * "hypot()"

    * "sin()"

    * "tan()"

  * Angular conversion

    * "degrees()"

    * "radians()"

  * Hyperbolic functions

    * "acosh()"

    * "asinh()"

    * "atanh()"

    * "cosh()"

    * "sinh()"

    * "tanh()"

  * Special functions

    * "erf()"

    * "erfc()"

    * "gamma()"

    * "lgamma()"

  * Constants

    * "pi"

    * "e"

    * "tau"

    * "inf"

    * "nan"

* "cmath" --- Mathematical functions for complex numbers

  * Conversions to and from polar coordinates

    * "phase()"

    * "polar()"

    * "rect()"

  * Power and logarithmic functions

    * "exp()"

    * "log()"

    * "log10()"

    * "sqrt()"

  * Trigonometric functions

    * "acos()"

    * "asin()"

    * "atan()"

    * "cos()"

    * "sin()"

    * "tan()"

  * Hyperbolic functions

    * "acosh()"

    * "asinh()"

    * "atanh()"

    * "cosh()"

    * "sinh()"

    * "tanh()"

  * Classification functions

    * "isfinite()"

    * "isinf()"

    * "isnan()"

    * "isclose()"

  * Constants

    * "pi"

    * "e"

    * "tau"

    * "inf"

    * "infj"

    * "nan"

    * "nanj"

* "decimal" --- Decimal fixed-point and floating-point arithmetic

  * Quick-start Tutorial

  * Decimal objects

    * "Decimal"

      * "adjusted()"

      * "as_integer_ratio()"

      * "as_tuple()"

      * "canonical()"

      * "compare()"

      * "compare_signal()"

      * "compare_total()"

      * "compare_total_mag()"

      * "conjugate()"

      * "copy_abs()"

      * "copy_negate()"

      * "copy_sign()"

      * "exp()"

      * "from_float()"

      * "fma()"

      * "is_canonical()"

      * "is_finite()"

      * "is_infinite()"

      * "is_nan()"

      * "is_normal()"

      * "is_qnan()"

      * "is_signed()"

      * "is_snan()"

      * "is_subnormal()"

      * "is_zero()"

      * "ln()"

      * "log10()"

      * "logb()"

      * "logical_and()"

      * "logical_invert()"

      * "logical_or()"

      * "logical_xor()"

      * "max()"

      * "max_mag()"

      * "min()"

      * "min_mag()"

      * "next_minus()"

      * "next_plus()"

      * "next_toward()"

      * "normalize()"

      * "number_class()"

      * "quantize()"

      * "radix()"

      * "remainder_near()"

      * "rotate()"

      * "same_quantum()"

      * "scaleb()"

      * "shift()"

      * "sqrt()"

      * "to_eng_string()"

      * "to_integral()"

      * "to_integral_exact()"

      * "to_integral_value()"

    * Logical operands

  * Context objects

    * "getcontext()"

    * "setcontext()"

    * "localcontext()"

    * "BasicContext"

    * "ExtendedContext"

    * "DefaultContext"

    * "Context"

      * "clear_flags()"

      * "clear_traps()"

      * "copy()"

      * "copy_decimal()"

      * "create_decimal()"

      * "create_decimal_from_float()"

      * "Etiny()"

      * "Etop()"

      * "abs()"

      * "add()"

      * "canonical()"

      * "compare()"

      * "compare_signal()"

      * "compare_total()"

      * "compare_total_mag()"

      * "copy_abs()"

      * "copy_negate()"

      * "copy_sign()"

      * "divide()"

      * "divide_int()"

      * "divmod()"

      * "exp()"

      * "fma()"

      * "is_canonical()"

      * "is_finite()"

      * "is_infinite()"

      * "is_nan()"

      * "is_normal()"

      * "is_qnan()"

      * "is_signed()"

      * "is_snan()"

      * "is_subnormal()"

      * "is_zero()"

      * "ln()"

      * "log10()"

      * "logb()"

      * "logical_and()"

      * "logical_invert()"

      * "logical_or()"

      * "logical_xor()"

      * "max()"

      * "max_mag()"

      * "min()"

      * "min_mag()"

      * "minus()"

      * "multiply()"

      * "next_minus()"

      * "next_plus()"

      * "next_toward()"

      * "normalize()"

      * "number_class()"

      * "plus()"

      * "power()"

      * "quantize()"

      * "radix()"

      * "remainder()"

      * "remainder_near()"

      * "rotate()"

      * "same_quantum()"

      * "scaleb()"

      * "shift()"

      * "sqrt()"

      * "subtract()"

      * "to_eng_string()"

      * "to_integral_exact()"

      * "to_sci_string()"

  * Constants

    * "MAX_PREC"

    * "MAX_EMAX"

    * "MIN_EMIN"

    * "MIN_ETINY"

    * "HAVE_THREADS"

    * "HAVE_CONTEXTVAR"

  * Rounding modes

    * "ROUND_CEILING"

    * "ROUND_DOWN"

    * "ROUND_FLOOR"

    * "ROUND_HALF_DOWN"

    * "ROUND_HALF_EVEN"

    * "ROUND_HALF_UP"

    * "ROUND_UP"

    * "ROUND_05UP"

  * Signals

    * "Clamped"

    * "DecimalException"

    * "DivisionByZero"

    * "Inexact"

    * "InvalidOperation"

    * "Overflow"

    * "Rounded"

    * "Subnormal"

    * "Underflow"

    * "FloatOperation"

  * Floating-Point Notes

    * Mitigating round-off error with increased precision

    * Special values

  * Working with threads

  * Recipes

  * Decimal FAQ

* "fractions" --- Rational numbers

  * "Fraction"

    * "numerator"

    * "denominator"

    * "as_integer_ratio()"

    * "is_integer()"

    * "from_float()"

    * "from_decimal()"

    * "limit_denominator()"

    * "__floor__()"

    * "__ceil__()"

    * "__round__()"

    * "__format__()"

* "random" --- Generate pseudo-random numbers

  * Bookkeeping functions

    * "seed()"

    * "getstate()"

    * "setstate()"

  * Functions for bytes

    * "randbytes()"

  * Functions for integers

    * "randrange()"

    * "randint()"

    * "getrandbits()"

  * Functions for sequences

    * "choice()"

    * "choices()"

    * "shuffle()"

    * "sample()"

  * Discrete distributions

    * "binomialvariate()"

  * Real-valued distributions

    * "random()"

    * "uniform()"

    * "triangular()"

    * "betavariate()"

    * "expovariate()"

    * "gammavariate()"

    * "gauss()"

    * "lognormvariate()"

    * "normalvariate()"

    * "vonmisesvariate()"

    * "paretovariate()"

    * "weibullvariate()"

  * Alternative Generator

    * "Random"

      * "seed()"

      * "getstate()"

      * "setstate()"

      * "random()"

      * "getrandbits()"

    * "SystemRandom"

  * Notes on Reproducibility

  * Examples

  * Recipes

* "statistics" --- Mathematical statistics functions

  * Averages and measures of central location

  * Measures of spread

  * Statistics for relations between two inputs

  * Function details

    * "mean()"

    * "fmean()"

    * "geometric_mean()"

    * "harmonic_mean()"

    * "median()"

    * "median_low()"

    * "median_high()"

    * "median_grouped()"

    * "mode()"

    * "multimode()"

    * "pstdev()"

    * "pvariance()"

    * "stdev()"

    * "variance()"

    * "quantiles()"

    * "covariance()"

    * "correlation()"

    * "linear_regression()"

  * Exceptions

    * "StatisticsError"

  * "NormalDist" objects

    * "NormalDist"

      * "mean"

      * "median"

      * "mode"

      * "stdev"

      * "variance"

      * "from_samples()"

      * "samples()"

      * "pdf()"

      * "cdf()"

      * "inv_cdf()"

      * "overlap()"

      * "quantiles()"

      * "zscore()"

  * Examples and Recipes

    * Classic probability problems

    * Monte Carlo inputs for simulations

    * Approximating binomial distributions

    * Naive bayesian classifier

    * Kernel density estimation
