On this page:
Math Library
6.11

Math Library

Neil Toronto <ntoronto@racket-lang.org>


Jens Axel Søgaard <jensaxel@soegaard.net>

 (require math) package: math-lib

The math library provides functions and data structures useful for working with numbers and collections of numbers. These include

With this library, we hope to support a wide variety of applied mathematics in Racket, including simulation, statistical inference, signal processing, and combinatorics. If you find it lacking for your variety of mathematics, please

This is a Typed Racket library. It is most efficient to use it in Typed Racket, so that contracts are checked statically. However, almost all of it can be used in untyped Racket. Exceptions and performance warnings are in bold text.

    1 Constants and Elementary Functions

      1.1 Constants

      1.2 Functions

      1.3 Random Number Generation

      1.4 Measuring Error

    2 Flonums

      2.1 Additional Flonum Functions

      2.2 Log-Space Arithmetic

      2.3 Debugging Flonum Functions

        2.3.1 Measuring Floating-Point Error

        2.3.2 Flonum Constants

        2.3.3 Low-Level Flonum Operations

      2.4 Double-Double Operations

        2.4.1 Debugging Double-Double Functions

        2.4.2 Low-Level Double-Double Operations

      2.5 Additional Flonum Vector Functions

    3 Special Functions

      3.1 Real Functions

      3.2 Flonum Functions

    4 Number Theory

      4.1 Congruences and Modular Arithmetic

        4.1.1 Parameterized Modular Arithmetic

      4.2 Primes

      4.3 Roots

      4.4 Powers

      4.5 Multiplicative and Arithmetic Functions

      4.6 Number Sequences

      4.7 Combinatorics

      4.8 Special Numbers

        4.8.1 Polygonal Numbers

      4.9 Fractions

      4.10 The Quadratic Equation

      4.11 The group Zn and Primitive Roots

    5 Arbitrary-Precision Floating-Point Numbers (Bigfloats)

      5.1 Quick Start

      5.2 Fictionally Asked Questions

      5.3 Type and Constructors

      5.4 Accessors and Conversion Functions

      5.5 Parameters

      5.6 Constants

      5.7 Predicates

      5.8 Rounding

      5.9 Mathematical Operations

      5.10 Low-level Functions

    6 Arrays

      6.1 Quick Start

      6.2 Definitions

      6.3 Broadcasting

        6.3.1 Broadcasting Rules

        6.3.2 Broadcasting Control

      6.4 Slicing

        6.4.1 (Sequenceof Integer): pick rows

        6.4.2 Slice: pick rows in a length-aware way

        6.4.3 Slice-Dots: preserve remaining axes

        6.4.4 Integer: remove an axis

        6.4.5 Slice-New-Axis: add an axis

      6.5 Nonstrict Arrays

        6.5.1 Caching Nonstrict Elements

        6.5.2 Performance Considerations

      6.6 Types, Predicates and Accessors

      6.7 Construction

      6.8 Conversion

        6.8.1 Printing

      6.9 Comprehensions and Sequences

      6.10 Pointwise Operations

        6.10.1 Broadcasting

      6.11 Indexing and Slicing

      6.12 Transformations

      6.13 Folds, Reductions and Expansions

        6.13.1 Axis Folds

        6.13.2 Whole-Array Folds

        6.13.3 General Reductions and Expansions

      6.14 Other Array Operations

        6.14.1 Fast Fourier Transform

      6.15 Subtypes

        6.15.1 Flonum Arrays

        6.15.2 Float-Complex Arrays

      6.16 Strictness

    7 Matrices and Linear Algebra

      7.1 Introduction

        7.1.1 Function Types

        7.1.2 Failure Arguments

        7.1.3 Broadcasting

        7.1.4 Strictness

      7.2 Types, Predicates and Accessors

      7.3 Construction

      7.4 Conversion

      7.5 Entrywise Operations and Arithmetic

      7.6 Polymorphic Operations

      7.7 Basic Operations

      7.8 Inner Product Space Operations

      7.9 Solving Systems of Equations

      7.10 Row-Based Algorithms

      7.11 Orthogonal Algorithms

      7.12 Operator Norms and Comparing Matrices

    8 Statistics Functions

      8.1 Expected Values

      8.2 Running Expected Values

      8.3 Correlation

      8.4 Counting and Binning

      8.5 Order Statistics

      8.6 Simulations

    9 Probability Distributions

      9.1 Distribution Objects

      9.2 Distribution Types and Operations

      9.3 Finite Distribution Families

        9.3.1 Unordered Discrete Distributions

      9.4 Integer Distribution Families

        9.4.1 Bernoulli Distributions

        9.4.2 Binomial Distributions

        9.4.3 Geometric Distributions

        9.4.4 Poisson Distributions

      9.5 Real Distribution Families

        9.5.1 Beta Distributions

        9.5.2 Cauchy Distributions

        9.5.3 Delta Distributions

        9.5.4 Exponential Distributions

        9.5.5 Gamma Distributions

        9.5.6 Logistic Distributions

        9.5.7 Normal Distributions

        9.5.8 Triangular Distributions

        9.5.9 Truncated Distributions

        9.5.10 Uniform Distributions

      9.6 Low-Level Distribution Functions

        9.6.1 Integer Distribution Functions

        9.6.2 Real Distribution Functions

    10 Stuff That Doesn’t Belong Anywhere Else

      10.1 Parallelization

      10.2 Discrete Fourier Transform Conventions

      10.3 Floating-Point Compliance Testing