-
Notifications
You must be signed in to change notification settings - Fork 103
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,7 @@ ncF | |
expint | ||
expinti | ||
expintx | ||
li | ||
sinint | ||
cosint | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,7 @@ export | |
expintx, | ||
sinint, | ||
cosint, | ||
li, | ||
lbinomial | ||
|
||
include("bessel.jl") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
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) | ||
oscardssmith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if x < 0 | ||
throw(DomainError(x, "negative argument, convert to complex first")) | ||
elseif x == 0 | ||
return 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This creates a type instability. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could this solve it?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or simply There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but you probably want |
||
else | ||
return expinti(log(x)) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -245,3 +245,10 @@ expinti_real(x) = invoke(expinti, Tuple{Real}, x) | |||||||||||||||||
end | ||||||||||||||||||
end | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
@testset "Logarithmic integral function" begin | ||||||||||||||||||
@test li(0.0) == 0 | ||||||||||||||||||
@test li(1.0) == -Inf | ||||||||||||||||||
@test li(Inf) === Inf | ||||||||||||||||||
@test li(2) ≈ 1.0451637801174927 | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add tests with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just don't understand why:
in this case is wanted that calling the function with a int returns a float, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is correct. |
||||||||||||||||||
end |
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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..