mathjs icon indicating copy to clipboard operation
mathjs copied to clipboard

digamma function with complex argument

Open ticucubot opened this issue 3 years ago • 9 comments

I would need an approximation in terms of elementary functions for digamma(x + i y), x>1/2, smoothly interpolating between small and large |y|

ticucubot avatar Dec 14 '21 13:12 ticucubot

Probably digamma function could be done using this formula: https://en.wikipedia.org/wiki/Digamma_function#Series_formula and for negative real part additional: https://en.wikipedia.org/wiki/Digamma_function#Reflection_formula Although different methods should be tested as well, since i don't think series formula converges too fast, and most likely depends on if input is small/big enough

bartekleon avatar Dec 16 '21 12:12 bartekleon

@ kmdrGroch : Many thanks for your reply. In the meantime I found that the recurrence formula (x -> x + 1) works astonishingly well for y's in the range of my interest, incomparably better than the generalized Puiseux series indicated in a previous posting.

ticucubot avatar Dec 16 '21 13:12 ticucubot

Unfortunatelly we need to do it for everyone, not just you :/ it has to be general and works for all ranges with decent time and approximation. Recurrence formula will most likely fail with Re big enough (I dunno how big Re can get tho). If it's max 20/30 we could use recurrence formula to get to value 0-1 and use series formula for it for example

I have just noticed it works another way around. You want X as big as possible for most of these series...

I guess it could work then.

I believe it would roughly work like:

function digamma(z) {
  if(z.re < 0) return digamma(reflect(z));
  
  if(z.re < 30) return digamma(z + 1) - 1 / z;
  
  return log(z) - 1 / 2z - ....;
}

bartekleon avatar Dec 16 '21 13:12 bartekleon

@ kmdrGroch : Many thanks for your reply. In the meantime I found that the recurrence formula (x -> x + 1) works astonishingly well for y's in the range of my interest, incomparably better than the generalized Puiseux series indicated in a previous posting.

ticucubot avatar Dec 16 '21 21:12 ticucubot

@ kmdrGroch : Thanks again, it is exactly what I meant: shift x (x -> x + 1), then use the lowest terms (log(z) - 1/(2 z) in the asymptotic expansion are sufficient.

ticucubot avatar Dec 16 '21 21:12 ticucubot

Do you know what relative error of this approximation is? Or I should check it?

bartekleon avatar Dec 17 '21 06:12 bartekleon

Please see examples in attchm. Relative errors psi(z) = psi(x + i y), (Re psi_approx/Re psi_exact - 1)*100 and Im psi_approx/Im psi_exact - 1)*100 versus y = Im z at ixed x = Re z .

On Fri, Dec 17, 2021 at 7:40 AM Bartosz Leoniak @.***> wrote:

Do you know what relative error of this approximation is? Or I should check it?

— Reply to this email directly, view it on GitHub https://github.com/josdejong/mathjs/issues/2361#issuecomment-996475309, or unsubscribe https://github.com/notifications/unsubscribe-auth/AP6RPSTPOEDWUSZNLLW7ODLURLLM7ANCNFSM5KA43JJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

ticucubot avatar Dec 17 '21 23:12 ticucubot

@ticucubot you refer to attachments, but that is not supported by mailing a reply in the github issue. Can you explain/attach directly in github please?

josdejong avatar Dec 19 '21 16:12 josdejong

I have mostly implemented this feature. I only need testing it and checking if it's providing good enough approximation. I need to handle edge cases as well. If you know any, please let me know so I can test them as well :) I used method described in my previous comment

bartekleon avatar Dec 20 '21 06:12 bartekleon