Skip to content

added Logarithmic integral function #500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/functions_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ ncF
expint
expinti
expintx
li
sinint
cosint
```
Expand Down
1 change: 1 addition & 0 deletions docs/src/functions_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Here the *Special Functions* are listed according to the structure of [NIST Digi
| [`expintx(x)`](@ref SpecialFunctions.expintx) | scaled [exponential integral](https://en.wikipedia.org/wiki/Exponential_integral) ``e^z \operatorname{E}_\nu(z)`` |
| [`sinint(x)`](@ref SpecialFunctions.sinint) | [sine integral](https://en.wikipedia.org/wiki/Trigonometric_integral#Sine_integral) ``\operatorname{Si}(x)`` |
| [`cosint(x)`](@ref SpecialFunctions.cosint) | [cosine integral](https://en.wikipedia.org/wiki/Trigonometric_integral#Cosine_integral) ``\operatorname{Ci}(x)`` |
| [`li(x)`](@ref SpecialFunctions.li) | [logarithmic integral function](https://en.wikipedia.org/wiki/Logarithmic_integral_function) ``\operatorname{li}(x)`` |


## Error Functions, Dawson’s and Fresnel Integrals
Expand Down
1 change: 1 addition & 0 deletions src/SpecialFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export
expintx,
sinint,
cosint,
li,
lbinomial

include("bessel.jl")
Expand Down
25 changes: 25 additions & 0 deletions src/expint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,28 @@ function expinti(x::BigFloat)
ccall((:mpfr_eint, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}, Base.MPFR.MPFRRoundingMode), z, x, Base.MPFR.ROUNDING_MODE[])
return z
end

##############################################################################
# Logarithmic integral function li

@doc raw"""
li(x::Real)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a more descriptive name such as logintegral (see https://reference.wolfram.com/language/ref/LogIntegral.html) would be better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

li is the common name in math, we could go logint to match expinti..


Computes the Logarithmic integral function
```math
\operatorname{li}(x) = \int_{0}^x \frac{1}{\ln{t}} \mathrm{d}t,
```
which is equivalent to ``\operatorname{Ei}(\ln{x})`` where
``\operatorname{Ei}`` is the `expinti` function.

External links: [Wikipedia](https://en.wikipedia.org/wiki/Logarithmic_integral_function)
"""
function li(x::Real)
if x < 0
throw(DomainError(x, "negative argument, convert to complex first"))
elseif x == 0
return zero(typeof(x))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return zero(typeof(x))
return zero(float(x))

else
return expinti(log(x))
end
end
10 changes: 10 additions & 0 deletions test/expint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,13 @@ expinti_real(x) = invoke(expinti, Tuple{Real}, x)
end
end
end

@testset "Logarithmic integral function" begin
@test @inferred(li(0.0)) === 0.0 # float 64
@test @inferred(li(0.0f0)) === 0.0f0 # float 32
@test @inferred(li(Float16(0))) === Float16(0) # float 16

@test @inferred(li(1.0)) === -Inf
@test @inferred(li(Inf)) === Inf
@test @inferred(li(2)) ≈ 1.0451637801174927 # this errors idk why
end
Loading