• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

JuliaDiff/DualNumbers.jl: Julia package for representing dual numbers and for pe ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

JuliaDiff/DualNumbers.jl

开源软件地址:

https://github.com/JuliaDiff/DualNumbers.jl

开源编程语言:

Julia 100.0%

开源软件介绍:

Build Status codecov

Scope of DualNumbers.jl

The DualNumbers Julia 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. Duality can further extend complex numbers by adjoining one new element to each of the real and imaginary parts.

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.

For the purpose of forward-mode automatic differentiation, this package is superseded by ForwardDiff.

DualNumbers does not have an active maintainer.

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,
  • realpart,
  • dualpart,
  • epsilon,
  • isdual,
  • dual_show,
  • conjdual,
  • absdual,
  • abs2dual.

The dual number f(a+bɛ) is defined by the limit:

f(a+bɛ) := f(a) + lim_{h→0} (f(a + bɛh) - f(a))/h .

For complex differentiable functions, this is equivalent to differentiation:

f(a+bɛ) := f(a) + b f'(a) ɛ.

For functions that are not complex differentiable, the dual part returns the limit and can be identified with a directional derivative in .

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. The mathematical definitions are available using the functions with the suffix dual. Similarly, comparison operators <, >, and == are overloaded to compare only value 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() constructor to define the dual number 2+1*ɛ:

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 realpart and dualpart to get the concrete and dual parts of x, respectively:

println("f(x) = x^3")
println("f(2) = ", realpart(y))
println("f'(2) = ", dualpart(y))



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap