GithubHelp home page GithubHelp logo

jakeconnor / dualnumbers.jl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from juliadiff/dualnumbers.jl

0.0 1.0 0.0 185 KB

Julia package for representing dual numbers and for performing dual algebra

License: Other

Julia 100.00%

dualnumbers.jl's Introduction

Build Status

Scope of DualNumbers.jl

The DualNumbers package defines the Dual type to represent dual numbers and supports standard mathematical operations on them. Conversions and promotions are defined to allow performing operations on combinations of dual numbers with predefined Julia numeric types.

Dual numbers extend the real numbers, similar to complex numbers. They adjoin a new element ϵ such that ϵ*ϵ=0, in a similar way that complex numbers adjoin the imaginary unit i with the property i*i=-1. So the typical representation of a dual number takes the form x+y*ϵ, where x and y are real numbers.

Apart from their mathematical role in algebraic and differential geometry (they are mainly interpreted as angles between lines), they also find applications in physics (the real part of a dual represents the bosonic direction, while the epsilon part represents the fermionic direction), in screw theory, in motor and spatial vector algebra, and in computer science due to its relation with the forward mode of automatic differentiation.

The ForwardDiff package implements forward mode automatic differentiation in Julia using several approaches. One of these approaches employs dual numbers. For this reason, the ForwardDiff package relies on DualNumbers. The user is referred to ForwardDiff for some examples on how to perform forward mode automatic differentiation using dual numbers in Julia.

Supported functions

We aim for complete support for Dual types for numerical functions within Julia's Base. Currently, basic mathematical operations and trigonometric functions are supported.

The following functions are specific to dual numbers:

  • dual,
  • dual128,
  • dual64,
  • epsilon,
  • isdual,
  • dual_show,
  • conjdual,
  • absdual,
  • abs2dual.

In some cases the mathematical definition of functions of Dual numbers is in conflict with their use as a drop-in replacement for calculating numerical derivatives, for example, conj, abs and abs2. In these cases, we choose to follow the rule f(x::Dual) = Dual(f(real(x)),epsilon(x)*f'(real(x))), where f' is the derivative of f. The mathematical definitions are available using the functions with the suffix dual. Similarly, comparison operators <, >, and == are overloaded to compare only real components.

A walk-through example

The example below demonstrates basic usage of dual numbers by employing them to perform automatic differentiation. The code for this example can be found in test/automatic_differentiation_test.jl.

First install the package by using the Julia package manager:

Pkg.update()
Pkg.add("DualNumbers")

Then make the package available via

using DualNumbers

Use the dual() function to define the dual number 2+1*du:

x = dual(2, 1)

Define a function that will be differentiated, say

f(x) = x^3

Perform automatic differentiation by passing the dual number x as argument to f:

y = f(x)

Use the functions real() and epsilon() to get the real and imaginary (dual) parts of x, respectively:

println("f(x) = x^3")
println("f(2) = ", real(y))
println("f'(2) = ", epsilon(y))

dualnumbers.jl's People

Contributors

mlubin avatar papamarkou avatar c42f avatar timholy avatar

Watchers

Jake Connor avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.