• Stars
    star
    278
  • Rank 148,454 (Top 3 %)
  • Language
    Julia
  • License
    Other
  • Created almost 12 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Calculus functions in Julia

Calculus.jl

Build Status Coverage Status Calculus Calculus

Introduction

The Calculus package provides tools for working with the basic calculus operations of differentiation and integration. You can use the Calculus package to produce approximate derivatives by several forms of finite differencing or to produce exact derivative using symbolic differentiation. You can also compute definite integrals by different numerical methods.

API

Most users will want to work with a limited set of basic functions:

  • derivative(): Use this for functions from R to R
  • second_derivative(): Use this for functions from R to R
  • Calculus.gradient(): Use this for functions from R^n to R
  • hessian(): Use this for functions from R^n to R
  • differentiate(): Use this to perform symbolic differentiation
  • simplify(): Use this to perform symbolic simplification
  • deparse(): Use this to get usual infix representation of expressions

Usage Examples

There are a few basic approaches to using the Calculus package:

  • Use finite-differencing to evaluate the derivative at a specific point
  • Use higher-order functions to create new functions that evaluate derivatives
  • Use symbolic differentiation to produce exact derivatives for simple functions

Direct Finite Differencing

using Calculus

# Compare with cos(0.0)
derivative(sin, 0.0)
# Compare with cos(1.0)
derivative(sin, 1.0)
# Compare with cos(pi)
derivative(sin, float(pi))

# Compare with [cos(0.0), -sin(0.0)]
Calculus.gradient(x -> sin(x[1]) + cos(x[2]), [0.0, 0.0])
# Compare with [cos(1.0), -sin(1.0)]
Calculus.gradient(x -> sin(x[1]) + cos(x[2]), [1.0, 1.0])
# Compare with [cos(pi), -sin(pi)]
Calculus.gradient(x -> sin(x[1]) + cos(x[2]), [float64(pi), float64(pi)])

# Compare with -sin(0.0)
second_derivative(sin, 0.0)
# Compare with -sin(1.0)
second_derivative(sin, 1.0)
# Compare with -sin(pi)
second_derivative(sin, float64(pi))

# Compare with [-sin(0.0) 0.0; 0.0 -cos(0.0)]
hessian(x -> sin(x[1]) + cos(x[2]), [0.0, 0.0])
# Compare with [-sin(1.0) 0.0; 0.0 -cos(1.0)]
hessian(x -> sin(x[1]) + cos(x[2]), [1.0, 1.0])
# Compare with [-sin(pi) 0.0; 0.0 -cos(pi)]
hessian(x -> sin(x[1]) + cos(x[2]), [float64(pi), float64(pi)])

Higher-Order Functions

using Calculus

g1 = derivative(sin)
g1(0.0)
g1(1.0)
g1(pi)

g2 = Calculus.gradient(x -> sin(x[1]) + cos(x[2]))
g2([0.0, 0.0])
g2([1.0, 1.0])
g2([pi, pi])

h1 = second_derivative(sin)
h1(0.0)
h1(1.0)
h1(pi)

h2 = hessian(x -> sin(x[1]) + cos(x[2]))
h2([0.0, 0.0])
h2([1.0, 1.0])
h2([pi, pi])

Symbolic Differentiation

using Calculus

differentiate("cos(x) + sin(x) + exp(-x) * cos(x)", :x)
differentiate("cos(x) + sin(y) + exp(-x) * cos(y)", [:x, :y])

Numerical Integration

The Calculus package no longer provides routines for univariate numerical integration. Use QuadGK.jl instead.

Credits

Calculus.jl is built on contributions from:

  • John Myles White
  • Tim Holy
  • Andreas Noack Jensen
  • Nathaniel Daw
  • Blake Johnson
  • Avik Sengupta
  • Miles Lubin

And draws inspiration and ideas from:

  • Mark Schmidt
  • Jonas Rauch

More Repositories

1

openlibm

High quality system independent, portable, open source libm implementation
C
512
star
2

Interpolations.jl

Fast, continuous interpolation of discrete datasets in Julia
Julia
475
star
3

MeasureTheory.jl

"Distributions" that might not add to one.
Julia
388
star
4

SpecialFunctions.jl

Special mathematical functions in Julia
Julia
317
star
5

Polynomials.jl

Polynomial manipulations in Julia
Julia
301
star
6

Roots.jl

Root finding functions for Julia
Julia
299
star
7

FFTW.jl

Julia bindings to the FFTW library for fast Fourier transforms
Julia
267
star
8

QuadGK.jl

adaptive 1d numerical Gauss–Kronrod integration in Julia
Julia
267
star
9

Combinatorics.jl

A combinatorics library for Julia
Julia
205
star
10

NFFT.jl

Julia implementation of the Non-equidistant Fast Fourier Transform (NFFT)
Julia
152
star
11

HCubature.jl

pure-Julia multidimensional h-adaptive integration
Julia
151
star
12

DoubleFloats.jl

math with more good bits
Julia
130
star
13

Cubature.jl

One- and multi-dimensional adaptive integration routines for the Julia language
Julia
117
star
14

AbstractFFTs.jl

A Julia framework for implementing FFTs
Julia
116
star
15

GSL.jl

Julia interface to the GNU Scientific Library (GSL)
Julia
100
star
16

IntervalSets.jl

Interval Sets for Julia
Julia
93
star
17

Primes.jl

Prime numbers in Julia
Julia
87
star
18

FixedPointNumbers.jl

fixed point types for julia
Julia
80
star
19

Bessels.jl

Bessel functions for real arguments and orders
Julia
78
star
20

RandomMatrices.jl

Random matrices package for Julia
Julia
77
star
21

Sobol.jl

generation of Sobol low-discrepancy sequence (LDS) for the Julia language
Julia
74
star
22

IntelVectorMath.jl

Julia bindings for the Intel Vector Math Library
Julia
72
star
23

HypergeometricFunctions.jl

A Julia package for calculating hypergeometric functions
Julia
67
star
24

AccurateArithmetic.jl

Calculate with error-free, faithful, and compensated transforms and extended significands.
Julia
64
star
25

Richardson.jl

Richardson extrapolation in Julia
Julia
62
star
26

FastChebInterp.jl

fast multidimensional Chebyshev interpolation and regression in Julia
Julia
58
star
27

Decimals.jl

Pure Julia decimal arithmetic library.
Julia
57
star
28

DecFP.jl

Julia IEEE decimal floating-point via the Intel decimal-float library
Julia
55
star
29

Yeppp.jl

Yeppp! bindings
Julia
54
star
30

NaNMath.jl

Julia math built-ins which return NaN and accumulator functions which ignore NaN
Julia
53
star
31

BFloat16s.jl

Julia implementation for the BFloat16 number type
Julia
48
star
32

FastPow.jl

optimal addition-chain exponentiation for Julia
Julia
41
star
33

Tau.jl

A Julia module providing the definition of the circle constant Tau (2Ï€)
Julia
36
star
34

Quadmath.jl

Float128 and libquadmath for the Julia language
Julia
35
star
35

Hadamard.jl

Fast Walsh-Hadamard transforms for the Julia language
Julia
35
star
36

openspecfun

A collection of special mathematical functions
Fortran
33
star
37

FixedPointDecimals.jl

Julia fixed-point decimals built from integers
Julia
33
star
38

ChangePrecision.jl

macro to change the default floating-point precision in Julia code
Julia
33
star
39

InverseLaplace.jl

Inverse Laplace transform
Julia
30
star
40

InverseFunctions.jl

Interface for function inversion in Julia
Julia
29
star
41

MeasureBase.jl

Julia
26
star
42

DoubleDouble.jl

Extended precision arithmetic for Julia (deprecated)
Julia
26
star
43

Libm.jl

A pure Julia math library
Julia
24
star
44

TensorCore.jl

Lightweight package for sharing tensor-algebra definitions
Julia
23
star
45

LambertW.jl

Lambert W mathematical function
Julia
21
star
46

KahanSummation.jl

Sum and cumulative sum using the Kahan-Babuska-Neumaier algorithm
Julia
19
star
47

Float8s.jl

A number format that you can count with your fingers.
Julia
17
star
48

Infinities.jl

A Julia package for representing infinity in all its forms
Julia
17
star
49

Xsum.jl

exactly rounded double-precision summation for Julia
Julia
16
star
50

IrrationalConstants.jl

defines additional irrationals
Julia
16
star
51

FunctionAccuracyTests.jl

ULP testing for Floating Point special functions.
Julia
13
star
52

DensityInterface.jl

Interface for mathematical/statistical densities in Julia
Julia
12
star
53

ChangesOfVariables.jl

Interface for transformation functions in Julia
Julia
11
star
54

CheckedArithmetic.jl

Utilities for handling arithmetic overflow
Julia
10
star
55

RoundingIntegers.jl

Integer types that automatically round assigned values
Julia
10
star
56

IntegerMathUtils.jl

Julia
6
star
57

MittagLeffler.jl

Mittag-Leffler function
Julia
6
star
58

ILog2.jl

integer valued base 2 logarithm
Julia
5
star
59

FunctionZeros.jl

Zeros of Bessel J and Y functions
Julia
4
star
60

RealDot.jl

Compute `real(dot(x, y))` efficiently.
Julia
4
star
61

FFTWBuilder

binary builder for FFTW.jl package
Julia
2
star
62

OpenlibmBuilder

Julia
2
star
63

Roadmap.jl

1
star
64

OpenspecfunBuilder

Julia
1
star
65

DSFMTBuilder

Julia
1
star
66

MPFRBuilder

Julia
1
star
67

GMPBuilder

Julia
1
star