Skip to content

Log Minus Digamma function#2957

Merged
burner merged 2 commits intodlang:masterfrom
9il:logmdigamma
Feb 4, 2015
Merged

Log Minus Digamma function#2957
burner merged 2 commits intodlang:masterfrom
9il:logmdigamma

Conversation

@9il
Copy link
Member

@9il 9il commented Feb 4, 2015

digamma(x) is asymptotically equivalent to log(x). logmdigamma(x) computes log(x) - digamma(x) without subtractive cancellation for large x. See also cran.statmod.

Copy link
Member

Choose a reason for hiding this comment

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

float equality comparison feels wrong, even if the unittest works

@burner
Copy link
Member

burner commented Feb 4, 2015

why is it only defined for real, what about float and double. precision isn't everything.

@9il
Copy link
Member Author

9il commented Feb 4, 2015

Because we need a full support of float and double in std.math. For example log defined only for real.

@burner
Copy link
Member

burner commented Feb 4, 2015

Of course, but this is not reason not to start here.

@9il
Copy link
Member Author

9il commented Feb 4, 2015

Generally Yes, but not for std.mathspecial. Make the logmdigamma template is a bad idea. There should be three different functions with different code. logmdigamma code based on digamma code. So float and double support is not a problem of this PR, it is a problem of digamma.

@9il
Copy link
Member Author

9il commented Feb 4, 2015

Furthermore, float and double versions would work slower then real version because both poly and log defined only for real.

@burner
Copy link
Member

burner commented Feb 4, 2015

this could be the start to put some pressure on math and mathspecial to work better with float and double. any start is better than no start

@9il
Copy link
Member Author

9il commented Feb 4, 2015

I have already start (and not only I). See my PRs:
#2508 (merged)
#2548 (blocked)

I have no idea how to make fast float and double versions.
If you want float and double variants of this function please show me the code example.

Note:
DMD can not compile proper code for double and float log functions because it has associative floating point math (like with -ffast-math flag in GCC).
DMD floating point bugs:
https://issues.dlang.org/show_bug.cgi?id=13485
https://issues.dlang.org/show_bug.cgi?id=13548
https://issues.dlang.org/show_bug.cgi?id=13474

@burner
Copy link
Member

burner commented Feb 4, 2015

OK, so lets forget the float and double versions for now.

the code still compares against 0, well 0.0 but the problem is the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd move the declaration of y down here…

@dnadlinger
Copy link
Contributor

@burner: Are you sure this is actually an issue here? The general rules for floating point math notwithstanding, this seems to be special-cased merely to ensure that a special value (0) is mapped to another special value (infinity) in the correct way. Other Phobos special functions are implemented in a similar way, although I didn't actually verify the approximation used here.

@9il
Copy link
Member Author

9il commented Feb 4, 2015

@burner Do you mean that the problem is sign? (+0.0 / -0.0)

@dnadlinger
Copy link
Contributor

@9il: $\Gamma$ and related functions are not exactly my area of expertise, so maybe this is obvious, but what reference did you model the code after, if any? Documenting that might be useful, especially regarding the rather arbitrary cutoff points (10, 1e17).

@9il
Copy link
Member Author

9il commented Feb 4, 2015

@klickverbot : 95% of this code is from digamma. You can find math approximation in http://people.math.sfu.ca/~cbm/aands/abramowitz_and_stegun.pdf, pages 258-259, equations 6.3.6 and 6.3.18.
This code is similar to logmdigamma.R

logmdigamma: fix comprasion

move declarations
@dnadlinger
Copy link
Contributor

Ah okay, thanks. Maybe include these as references in the source code?

@burner
Copy link
Member

burner commented Feb 4, 2015

well than, other than the zero thing the doc is quite sparse. and what about pure safe nothrow

@9il
Copy link
Member Author

9il commented Feb 4, 2015

@burner attributes was defined for all module.

@9il
Copy link
Member Author

9il commented Feb 4, 2015

References added.

@burner
Copy link
Member

burner commented Feb 4, 2015

LGTM

@burner
Copy link
Member

burner commented Feb 4, 2015

Auto-merge toggled on

burner added a commit that referenced this pull request Feb 4, 2015
Log Minus Digamma function
@burner burner merged commit 581f6d0 into dlang:master Feb 4, 2015
@9il 9il deleted the logmdigamma branch February 4, 2015 22:19
@9il
Copy link
Member Author

9il commented Feb 22, 2015

Inverse version of this function #3020.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants