Technology moves fast! ⚡ Don't get left behind.🚶 Subscribe to our mailing list to keep up with latest and greatest in open source projects! 🏆


Subscribe to our mailing list

Calculus.jl

Calculus functions in Julia

Subscribe to updates I use Calculus.jl


Statistics on Calculus.jl

Number of watchers on Github 97
Number of open issues 23
Average time to close an issue 14 days
Main language Julia
Average time to merge a PR 3 days
Open pull requests 13+
Closed pull requests 8+
Last commit over 1 year ago
Repo Created over 6 years ago
Repo Last Updated over 1 year ago
Size 146 KB
Organization / Authorjohnmyleswhite
Contributors18
Page Updated
Do you use Calculus.jl? Leave a review!
View open issues (23)
View Calculus.jl activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating Calculus.jl for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Calculus.jl

Build Status 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 Rn to R
  • hessian(): Use this for functions from Rn 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])

Prime Notation

For scalar functions that map R to R, you can use the ' operator to calculate derivatives as well. This operator can be used abritratily many times, but you should keep in mind that the approximation degrades with each approximate derivative you calculate:

using Calculus

f(x) = sin(x)
f'(1.0) - cos(1.0)
f''(1.0) - (-sin(1.0))
f'''(1.0) - (-cos(1.0))

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
Calculus.jl open issues Ask a question     (View All Issues)
  • almost 3 years analytic Jacobian
  • about 3 years Calculus.hessian is not symmetric
  • over 3 years Using AbstractArray instead of Array in finite_difference_jacobian!() ?
  • over 3 years simplify give wrong result
  • over 3 years finite_difference routines temporarily mutate inputs
  • over 4 years replace methods
  • over 4 years Simplify(::Expr) failed
  • almost 6 years Disallow second_derivative and hessian functions to be called without g
  • almost 6 years Tests of differentiate() compares expressions too strictly
  • about 6 years Evaluate symbolic derivatives at specific points
Calculus.jl open pull requests (View All Pulls)
  • Change all Array and Vector to AbstractArray and AbstractVector
  • inline documentation for exported APIs
  • Fix simplify(:(a-0))
  • included complex step finite method for the gradient computation
  • updated defaults, require f' when calling f'', updated tests accordingly
  • code to treat differentiate as a first class higher order function
  • Combine terms in multiplication and addition
  • Add cancellation of common variables in 'simplify'
  • Updated differentiate.jl to be make finite differences based on a symbolic expression
  • Added differentiation rule for mod2pi
  • Pull request/149da947
  • fix deprecations and upgrade to 0.6
  • Add differentiation rule for √
Calculus.jl list of languages used
Other projects in Julia