diff --git a/base/docs/helpdb/Base.jl b/base/docs/helpdb/Base.jl index 9a08432feec8e..13b8490384b9b 100644 --- a/base/docs/helpdb/Base.jl +++ b/base/docs/helpdb/Base.jl @@ -22,13 +22,6 @@ tab-delimited text to `f` by either `writedlm(f, [x y])` or by `writedlm(f, zip( """ writedlm -""" - digamma(x) - -Compute the digamma function of `x` (the logarithmic derivative of `gamma(x)`) -""" -digamma - """ fill!(A, x) @@ -523,13 +516,6 @@ A string giving the literal bit representation of a number. """ bits -""" - invdigamma(x) - -Compute the inverse digamma function of `x`. -""" -invdigamma - """ getindex(type[, elements...]) @@ -609,13 +595,6 @@ used as the final delimiter instead of `delim`. """ join(io, items, delim, last) -""" - lfact(x) - -Compute the logarithmic factorial of `x` -""" -lfact - """ deconv(b,a) @@ -1007,15 +986,6 @@ Test whether a matrix is lower triangular. """ istril -""" - lgamma(x) - -Compute the logarithm of the absolute value of [`gamma`](:func:`gamma`) for -[`Real`](:obj:`Real`) `x`, while for [`Complex`](:obj:`Complex`) `x` it computes the -logarithm of `gamma(x)`. -""" -lgamma - """ bin(n, [pad]) @@ -1445,13 +1415,6 @@ Close an I/O stream. Performs a `flush` first. """ close(stream::IO) -""" - cospi(x) - -Compute ``\\cos(\\pi x)`` more accurately than `cos(pi*x)`, especially for large `x`. -""" -cospi - """ parentindexes(A) @@ -2420,13 +2383,6 @@ Bessel function of the first kind of order 1, ``J_1(x)``. """ besselj1 -""" - sinpi(x) - -Compute ``\\sin(\\pi x)`` more accurately than `sin(pi*x)`, especially for large `x`. -""" -sinpi - """ select!(v, k, [by=,] [lt=,] [rev=false]) @@ -2872,13 +2828,6 @@ Seek a stream to the given position. """ seek -""" - acosd(x) - -Compute the inverse cosine of `x`, where the output is in degrees. -""" -acosd - """ triu(M) @@ -3013,13 +2962,6 @@ Equivalent to `stat(file).size`. """ filesize -""" - sinc(x) - -Compute ``\\sin(\\pi x) / (\\pi x)`` if ``x \\neq 0``, and ``1`` if ``x = 0``. -""" -sinc - """ cglobal((symbol, library) [, type=Void]) @@ -3650,13 +3592,6 @@ Returns the smallest eigenvalue of `A`. """ eigmin -""" - acscd(x) - -Compute the inverse cosecant of `x`, where the output is in degrees. -""" -acscd - """ ltoh(x) @@ -4142,13 +4077,6 @@ is `-1` the corresponding ID will not change. Only integer `owner`s and `group`s """ chown -""" - gamma(x) - -Compute the gamma function of `x`. -""" -gamma - """ sin(x) @@ -4855,13 +4783,6 @@ For more information, see [^issue8859], [^B96], [^S84], [^KY88]. """ pinv -""" - asecd(x) - -Compute the inverse secant of `x`, where the output is in degrees. -""" -asecd - """ readbytes!(stream::IO, b::AbstractVector{UInt8}, nb=length(b); all=true) @@ -4888,13 +4809,6 @@ descriptive error string. """ ArgumentError -""" - atand(x) - -Compute the inverse tangent of `x`, where the output is in degrees. -""" -atand - """ KeyError(key) @@ -5062,13 +4976,6 @@ Test whether a matrix is Hermitian. """ ishermitian -""" - sind(x) - -Compute sine of `x`, where `x` is in degrees. -""" -sind - """ min(x, y, ...) @@ -5380,14 +5287,6 @@ two strings. For example """ join(strings, delim, last) -""" - polygamma(m, x) - -Compute the polygamma function of order `m` of argument `x` (the `(m+1)th` derivative of the -logarithm of `gamma(x)`) -""" -polygamma - """ isless(x, y) @@ -6055,13 +5954,6 @@ Returns `string` with all characters converted to uppercase. """ uppercase -""" - cosd(x) - -Compute cosine of `x`, where `x` is in degrees. -""" -cosd - """ cycle(iter) @@ -6500,13 +6392,6 @@ lengths of dimensions you asked for. """ size -""" - trigamma(x) - -Compute the trigamma function of `x` (the logarithmic second derivative of `gamma(x)`). -""" -trigamma - """ findmin(A, dims) -> (minval, index) @@ -7188,13 +7073,6 @@ but throws an error for unordered arguments. """ cmp -""" - tand(x) - -Compute tangent of `x`, where `x` is in degrees. -""" -tand - """ issorted(v, [by=,] [lt=,] [rev=false]) @@ -7583,14 +7461,6 @@ Test whether any values along the given dimensions of an array are `true`. """ any(::AbstractArray,dims) -""" - cosc(x) - -Compute ``\\cos(\\pi x) / x - \\sin(\\pi x) / (\\pi x^2)`` if ``x \\neq 0``, and ``0`` if -``x = 0``. This is the derivative of `sinc(x)`. -""" -cosc - """ getkey(collection, key, default) @@ -7612,13 +7482,6 @@ For matrices or vectors ``A`` and ``B``, calculates ``Aᴴ Bᴴ``. """ Ac_mul_Bc -""" - acotd(x) - -Compute the inverse cotangent of `x`, where the output is in degrees. -""" -acotd - """ zeros(type, dims) @@ -8313,13 +8176,6 @@ julia> f(apple) """ :@enum -""" - asind(x) - -Compute the inverse sine of `x`, where the output is in degrees. -""" -asind - """ widemul(x, y) diff --git a/base/special/gamma.jl b/base/special/gamma.jl index e1bbe630f1e33..083ad14c30fdb 100644 --- a/base/special/gamma.jl +++ b/base/special/gamma.jl @@ -2,6 +2,12 @@ gamma(x::Float64) = nan_dom_err(ccall((:tgamma,libm), Float64, (Float64,), x), x) gamma(x::Float32) = nan_dom_err(ccall((:tgammaf,libm), Float32, (Float32,), x), x) + +""" + gamma(x) + +Compute the gamma function of `x`. +""" gamma(x::Real) = gamma(float(x)) @vectorize_1arg Number gamma @@ -19,6 +25,11 @@ lgamma_r(x::Real) = lgamma_r(float(x)) lgamma_r(x::Number) = lgamma(x), 1 # lgamma does not take abs for non-real x "`lgamma_r(x)`: return L,s such that `gamma(x) = s * exp(L)`" lgamma_r +""" + lfact(x) + +Compute the logarithmic factorial of `x` +""" lfact(x::Real) = (x<=1 ? zero(float(x)) : lgamma(x+one(x))) @vectorize_1arg Number lfact @@ -47,6 +58,13 @@ function clgamma_lanczos(z) return log(zz) - temp end +""" + lgamma(x) + +Compute the logarithm of the absolute value of [`gamma`](:func:`gamma`) for +[`Real`](:obj:`Real`) `x`, while for [`Complex`](:obj:`Complex`) `x` it computes the +logarithm of `gamma(x)`. +""" function lgamma(z::Complex) if real(z) <= 0.5 a = clgamma_lanczos(1-z) @@ -69,6 +87,11 @@ gamma(z::Complex) = exp(lgamma(z)) # const A002445 = [1,6,30,42,30,66,2730,6,510,798,330,138,2730,6,870,14322,510,6,1919190,6,13530] # const bernoulli = A000367 .// A002445 # even-index Bernoulli numbers +""" + digamma(x) + +Compute the digamma function of `x` (the logarithmic derivative of `gamma(x)`) +""" function digamma(z::Union{Float64,Complex{Float64}}) # Based on eq. (12), without looking at the accompanying source # code, of: K. S. Kölbig, "Programs for computing the logarithm of @@ -98,6 +121,11 @@ function digamma(z::Union{Float64,Complex{Float64}}) ψ -= t * @evalpoly(t,0.08333333333333333,-0.008333333333333333,0.003968253968253968,-0.004166666666666667,0.007575757575757576,-0.021092796092796094,0.08333333333333333,-0.4432598039215686) end +""" + trigamma(x) + +Compute the trigamma function of `x` (the logarithmic second derivative of `gamma(x)`). +""" function trigamma(z::Union{Float64,Complex{Float64}}) # via the derivative of the Kölbig digamma formulation x = real(z) @@ -360,6 +388,12 @@ function zeta(s::Union{Int,Float64,Complex{Float64}}, return ζ end +""" + polygamma(m, x) + +Compute the polygamma function of order `m` of argument `x` (the `(m+1)th` derivative of the +logarithm of `gamma(x)`) +""" function polygamma(m::Integer, z::Union{Float64,Complex{Float64}}) m == 0 && return digamma(z) m == 1 && return trigamma(z) @@ -445,6 +479,12 @@ function invdigamma(y::Float64) return x_new end invdigamma(x::Float32) = Float32(invdigamma(Float64(x))) + +""" + invdigamma(x) + +Compute the inverse digamma function of `x`. +""" invdigamma(x::Real) = invdigamma(Float64(x)) @vectorize_1arg Real invdigamma diff --git a/base/special/trig.jl b/base/special/trig.jl index ab1ac1b4efafe..087f2ad0338e6 100644 --- a/base/special/trig.jl +++ b/base/special/trig.jl @@ -98,7 +98,11 @@ mulpi_ext(x::Float32) = DoubleFloat32(pi*Float64(x)) mulpi_ext(x::Rational) = mulpi_ext(float(x)) mulpi_ext(x::Real) = pi*x # Fallback +""" + sinpi(x) +Compute ``\\sin(\\pi x)`` more accurately than `sin(pi*x)`, especially for large `x`. +""" function sinpi{T<:AbstractFloat}(x::T) if !isfinite(x) isnan(x) && return x @@ -157,6 +161,11 @@ function sinpi{T<:Real}(x::T) end end +""" + cospi(x) + +Compute ``\\cos(\\pi x)`` more accurately than `cos(pi*x)`, especially for large `x`. +""" function cospi{T<:AbstractFloat}(x::T) if !isfinite(x) isnan(x) && return x @@ -278,13 +287,23 @@ end @vectorize_1arg Number sinpi @vectorize_1arg Number cospi +""" + sinc(x) +Compute ``\\sin(\\pi x) / (\\pi x)`` if ``x \\neq 0``, and ``1`` if ``x = 0``. +""" sinc(x::Number) = x==0 ? one(x) : oftype(x,sinpi(x)/(pi*x)) sinc(x::Integer) = x==0 ? one(x) : zero(x) sinc{T<:Integer}(x::Complex{T}) = sinc(float(x)) sinc(x::Real) = x==0 ? one(x) : isinf(x) ? zero(x) : sinpi(x)/(pi*x) @vectorize_1arg Number sinc +""" + cosc(x) + +Compute ``\\cos(\\pi x) / x - \\sin(\\pi x) / (\\pi x^2)`` if ``x \\neq 0``, and ``0`` if +``x = 0``. This is the derivative of `sinc(x)`. +""" cosc(x::Number) = x==0 ? zero(x) : oftype(x,(cospi(x)-sinpi(x)/(pi*x))/x) cosc(x::Integer) = cosc(float(x)) cosc{T<:Integer}(x::Complex{T}) = cosc(float(x)) @@ -389,16 +408,23 @@ end tand(x::Real) = sind(x) / cosd(x) @vectorize_1arg Real tand -for (fd, f) in ((:sind, :sin), (:cosd, :cos), (:tand, :tan)) +for (fd, f, fn) in ((:sind, :sin, "sine"), (:cosd, :cos, "cosine"), (:tand, :tan, "tangent")) + name = string(fd) @eval begin - ($fd)(z) = ($f)(deg2rad(z)) + @doc """ + $($name)(x) + Compute $($fn) of `x`, where `x` is in degrees. """ ($fd)(z) = ($f)(deg2rad(z)) end end -for (fd, f) in ((:asind, :asin), (:acosd, :acos), (:atand, :atan), - (:asecd, :asec), (:acscd, :acsc), (:acotd, :acot)) +for (fd, f, fn) in ((:asind, :asin, "sine"), (:acosd, :acos, "cosine"), (:atand, :atan, "tangent"), + (:asecd, :asec, "secant"), (:acscd, :acsc, "cosecant"), (:acotd, :acot, "cotangent")) + name = string(fd) @eval begin - ($fd)(y) = rad2deg(($f)(y)) + @doc """ + $($name)(x) + + Compute the inverse $($fn) of `x`, where the output is in degrees. """ ($fd)(y) = rad2deg(($f)(y)) @vectorize_1arg Real $fd end end