package hyperdual
import "gonum.org/v1/gonum/num/hyperdual"
Package hyperdual provides the hyperdual numeric type and functions. Hyperdual numbers are an extension of the real numbers in the form a+bϵ₁+bϵ₂+dϵ₁ϵ₂ where ϵ₁^2=0 and ϵ₂^2=0, but ϵ₁≠0, ϵ₂≠0 and ϵ₁ϵ₂≠0.
See https://doi.org/10.2514/6.2011-886 and http://adl.stanford.edu/hyperdual/ for details of their properties and uses.
Index ¶
- type Number
- func Abs(d Number) Number
- func Acos(d Number) Number
- func Acosh(d Number) Number
- func Add(x, y Number) Number
- func Asin(d Number) Number
- func Asinh(d Number) Number
- func Atan(d Number) Number
- func Atanh(d Number) Number
- func Cos(d Number) Number
- func Cosh(d Number) Number
- func Exp(d Number) Number
- func Inv(d Number) Number
- func Log(d Number) Number
- func Mul(x, y Number) Number
- func Pow(d, p Number) Number
- func PowReal(d Number, p float64) Number
- func Scale(f float64, d Number) Number
- func Sin(d Number) Number
- func Sinh(d Number) Number
- func Sqrt(d Number) Number
- func Sub(x, y Number) Number
- func Tan(d Number) Number
- func Tanh(d Number) Number
- func (d Number) Format(fs fmt.State, c rune)
Examples ¶
Types ¶
type Number ¶
type Number struct { Real, E1mag, E2mag, E1E2mag float64 }
Number is a float64 precision hyperdual number.
Code:play
Output:Example (Fike)¶
package main
import (
"fmt"
"gonum.org/v1/gonum/num/hyperdual"
)
func main() {
// Calculate the value and first and second derivatives
// of the function e^x/(sqrt(sin(x)^3 + cos(x)^3)).
fn := func(x hyperdual.Number) hyperdual.Number {
return hyperdual.Mul(
hyperdual.Exp(x),
hyperdual.Inv(hyperdual.Sqrt(
hyperdual.Add(
hyperdual.PowReal(hyperdual.Sin(x), 3),
hyperdual.PowReal(hyperdual.Cos(x), 3)))))
}
v := fn(hyperdual.Number{Real: 1.5, E1mag: 1, E2mag: 1})
fmt.Printf("v=%.4f\n", v)
fmt.Printf("fn(1.5)=%.4f\nfn′(1.5)=%.4f\nfn′′(1.5)=%.4f\n", v.Real, v.E1mag, v.E1E2mag)
}
v=(4.4978+4.0534ϵ₁+4.0534ϵ₂+9.4631ϵ₁ϵ₂)
fn(1.5)=4.4978
fn′(1.5)=4.0534
fn′′(1.5)=9.4631
func Abs ¶
Abs returns the absolute value of d.
func Acos ¶
Acos returns the inverse cosine of d.
Special cases are:
Acos(-1) = (Pi-Infϵ₁-Infϵ₂+Infϵ₁ϵ₂) Acos(1) = (0-Infϵ₁-Infϵ₂-Infϵ₁ϵ₂) Acos(x) = NaN if x < -1 or x > 1
func Acosh ¶
Acosh returns the inverse hyperbolic cosine of d.
Special cases are:
Acosh(+Inf) = +Inf Acosh(1) = (0+Infϵ₁+Infϵ₂-Infϵ₁ϵ₂) Acosh(x) = NaN if x < 1 Acosh(NaN) = NaN
func Add ¶
Add returns the sum of x and y.
func Asin ¶
Asin returns the inverse sine of d.
Special cases are:
Asin(±0) = (±0+Nϵ₁+Nϵ₂±0ϵ₁ϵ₂) Asin(±1) = (±Inf+Infϵ₁+Infϵ₂±Infϵ₁ϵ₂) Asin(x) = NaN if x < -1 or x > 1
func Asinh ¶
Asinh returns the inverse hyperbolic sine of d.
Special cases are:
Asinh(±0) = (±0+Nϵ₁+Nϵ₂∓0ϵ₁ϵ₂) Asinh(±Inf) = ±Inf Asinh(NaN) = NaN
func Atan ¶
Atan returns the inverse tangent of d.
Special cases are:
Atan(±0) = (±0+Nϵ₁+Nϵ₂∓0ϵ₁ϵ₂) Atan(±Inf) = (±Pi/2+0ϵ₁+0ϵ₂∓0ϵ₁ϵ₂)
func Atanh ¶
Atanh returns the inverse hyperbolic tangent of d.
Special cases are:
Atanh(1) = +Inf Atanh(±0) = (±0+Nϵ₁+Nϵ₂±0ϵ₁ϵ₂) Atanh(-1) = -Inf Atanh(x) = NaN if x < -1 or x > 1 Atanh(NaN) = NaN
func Cos ¶
Cos returns the cosine of d.
Special cases are:
Cos(±Inf) = NaN Cos(NaN) = NaN
func Cosh ¶
Cosh returns the hyperbolic cosine of d.
Special cases are:
Cosh(±0) = 1 Cosh(±Inf) = +Inf Cosh(NaN) = NaN
func Exp ¶
Exp returns e**q, the base-e exponential of d.
Special cases are:
Exp(+Inf) = +Inf Exp(NaN) = NaN
Very large values overflow to 0 or +Inf. Very small values underflow to 1.
func Inv ¶
Inv returns the hyperdual inverse of d.
Special cases are:
Inv(±Inf) = ±0-0ϵ₁-0ϵ₂±0ϵ₁ϵ₂ Inv(±0) = ±Inf-Infϵ₁-Infϵ₂±Infϵ₁ϵ₂
func Log ¶
Log returns the natural logarithm of d.
Special cases are:
Log(+Inf) = (+Inf+0ϵ₁+0ϵ₂-0ϵ₁ϵ₂) Log(0) = (-Inf±Infϵ₁±Infϵ₂-Infϵ₁ϵ₂) Log(x < 0) = NaN Log(NaN) = NaN
func Mul ¶
Mul returns the hyperdual product of x and y.
func Pow ¶
Pow returns x**p, the base-x exponential of p.
func PowReal ¶
PowReal returns x**p, the base-x exponential of p.
Special cases are (in order):
PowReal(NaN+xϵ₁+yϵ₂, ±0) = 1+NaNϵ₁+NaNϵ₂+NaNϵ₁ϵ₂ for any x and y PowReal(x, ±0) = 1 for any x PowReal(1+xϵ₁+yϵ₂, z) = 1+xzϵ₁+yzϵ₂+2xyzϵ₁ϵ₂ for any z PowReal(NaN+xϵ₁+yϵ₂, 1) = NaN+xϵ₁+yϵ₂+NaNϵ₁ϵ₂ for any x PowReal(x, 1) = x for any x PowReal(NaN+xϵ₁+xϵ₂, y) = NaN+NaNϵ₁+NaNϵ₂+NaNϵ₁ϵ₂ PowReal(x, NaN) = NaN+NaNϵ₁+NaNϵ₂+NaNϵ₁ϵ₂ PowReal(±0, y) = ±Inf for y an odd integer < 0 PowReal(±0, -Inf) = +Inf PowReal(±0, +Inf) = +0 PowReal(±0, y) = +Inf for finite y < 0 and not an odd integer PowReal(±0, y) = ±0 for y an odd integer > 0 PowReal(±0, y) = +0 for finite y > 0 and not an odd integer PowReal(-1, ±Inf) = 1 PowReal(x+0ϵ₁+0ϵ₂, +Inf) = +Inf+NaNϵ₁+NaNϵ₂+NaNϵ₁ϵ₂ for |x| > 1 PowReal(x+xϵ₁+yϵ₂, +Inf) = +Inf+Infϵ₁+Infϵ₂+NaNϵ₁ϵ₂ for |x| > 1 PowReal(x, -Inf) = +0+NaNϵ₁+NaNϵ₂+NaNϵ₁ϵ₂ for |x| > 1 PowReal(x+yϵ₁+zϵ₂, +Inf) = +0+NaNϵ₁+NaNϵ₂+NaNϵ₁ϵ₂ for |x| < 1 PowReal(x+0ϵ₁+0ϵ₂, -Inf) = +Inf+NaNϵ₁+NaNϵ₂+NaNϵ₁ϵ₂ for |x| < 1 PowReal(x, -Inf) = +Inf-Infϵ₁-Infϵ₂+NaNϵ₁ϵ₂ for |x| < 1 PowReal(+Inf, y) = +Inf for y > 0 PowReal(+Inf, y) = +0 for y < 0 PowReal(-Inf, y) = Pow(-0, -y) PowReal(x, y) = NaN+NaNϵ₁+NaNϵ₂+NaNϵ₁ϵ₂ for finite x < 0 and finite non-integer y
func Scale ¶
Scale returns d scaled by f.
func Sin ¶
Sin returns the sine of d.
Special cases are:
Sin(±0) = (±0+Nϵ₁+Nϵ₂∓0ϵ₁ϵ₂) Sin(±Inf) = NaN Sin(NaN) = NaN
func Sinh ¶
Sinh returns the hyperbolic sine of d.
Special cases are:
Sinh(±0) = (±0+Nϵ₁+Nϵ₂±0ϵ₁ϵ₂) Sinh(±Inf) = ±Inf Sinh(NaN) = NaN
func Sqrt ¶
Sqrt returns the square root of d.
Special cases are:
Sqrt(+Inf) = +Inf Sqrt(±0) = (±0+Infϵ₁+Infϵ₂-Infϵ₁ϵ₂) Sqrt(x < 0) = NaN Sqrt(NaN) = NaN
func Sub ¶
Sub returns the difference of x and y, x-y.
func Tan ¶
Tan returns the tangent of d.
Special cases are:
Tan(±0) = (±0+Nϵ₁+Nϵ₂±0ϵ₁ϵ₂) Tan(±Inf) = NaN Tan(NaN) = NaN
func Tanh ¶
Tanh returns the hyperbolic tangent of d.
Special cases are:
Tanh(±0) = (±0+Nϵ₁+Nϵ₂∓0ϵ₁ϵ₂) Tanh(±Inf) = (±1+0ϵ₁+0ϵ₂∓0ϵ₁ϵ₂) Tanh(NaN) = NaN
func (Number) Format ¶
Format implements fmt.Formatter.
Source Files ¶
doc.go hyperdual.go hyperdual_fike.go hyperdual_hyperbolic.go
- Version
- v0.15.1 (latest)
- Published
- Aug 16, 2024
- Platform
- linux/amd64
- Imports
- 3 packages
- Last checked
- 10 hours ago –
Tools for package owners.