Skip to content
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

Support for hypergeometric functions #1383

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft

Conversation

aravindh-krishnamoorthy
Copy link
Collaborator

@aravindh-krishnamoorthy aravindh-krishnamoorthy commented Feb 12, 2025

Note

This PR is still under development.

Introduction

This PR includes support for the following hypergeometric functions:

  • Hypergeometric1F1
  • HypergeometricPFQ
  • MeijerG
  • HypergeometricU

Checklist

  • Functionality and output (see tests)
  • Documentation (valid / in line with MMA)
  • Function attributes (valid / in line with MMA)
  • Special cases (valid / in line with MMA)
  • Special behaviour where z_?RealQ leads to a numerical evaluation (as an earlier MMA alternative to N[]). (z_?MachineNumberQ is used instead of RealQ.)
  • Functions work with Plot[]

Tests

TBD

@aravindh-krishnamoorthy
Copy link
Collaborator Author

I am actually thinking about changing this to a sympy based implementation.

@rocky
Copy link
Member

rocky commented Feb 12, 2025

I am actually thinking about changing this to a sympy based implementation.

SymPy does import mpmath. So in theory SymPy could/should fall back to mpmath. (I don't know if that was always the case in the past when this project first started out.)

I don't know enough about the pros and cons of doing using SymPy over mpmath. Please educate me.

@aravindh-krishnamoorthy
Copy link
Collaborator Author

It'd possibly allow for things like Limit[Hypergeometric1F1[a,b,z], a->0] and hyperexpand to simplify expression involving hypergeometric functions. OTOH, the mpmath version only works with numerical (fp) arguments. I'll check the details out and get back to you soon...

If I do it, I'll also change the existing HypergeometricU function.

@rocky
Copy link
Member

rocky commented Feb 14, 2025

It'd possibly allow for things like Limit[Hypergeometric1F1[a,b,z], a->0] and hyperexpand to simplify expression involving hypergeometric functions. OTOH, the mpmath version only works with numerical (fp) arguments. I'll check the details out and get back to you soon...

While I think adding a SymPy method for Hypergeometric1F1 when a, b, and z are vectors or are symbolic is a great idea, I think in this situation it is better left as a follow-on PR. Here is why...

If doing that would cause the stuff here to be drastically ripped out or changed, then it would make sense to wait. But as best as I can tell that's not likely to happen here. Right?

This PR, I think, is complete by itself and a useful step forward. It is also getting large.

Many small and quicker PRs (assuming we are not just redoing the previous ones because we haven't thought about the bigger picture), are better than one large PR that spans a long time period. Here, I think you outlined the bigger picture, and if I have it right there are two reasonably separable steps to this.

If I do it, I'll also change the existing HypergeometricU function.

Thanks.

summary_text = "Tricomi confluent hypergeometric function"
sympy_name = ""


Copy link
Member

Choose a reason for hiding this comment

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

Please don't revise functions until we've mastered the existing ones.

@@ -117,3 +117,101 @@ class Hypergeometric1F1(MPMathFunction):
}
summary_text = "compute Kummer confluent hypergeometric function"
sympy_name = ""


class MeijerG(MPMathFunction):
Copy link
Member

Choose a reason for hiding this comment

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

Please do not start more functions until we have mastered the ones in progress.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Rocky, please kindly wait with the reviews. I'll let you know once I'm done with this PR and put it out of draft mode. Otherwise, my development flow may be confusing to you.

Copy link
Member

Choose a reason for hiding this comment

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

This is already too large. Please reduce the scope.

Copy link
Member

@rocky rocky Feb 14, 2025

Choose a reason for hiding this comment

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

If you don't want folks to see what's up. People get notifications even when working in draft mode.

Instead, fork the code and work in your private fork. Thanks.

@rocky
Copy link
Member

rocky commented Feb 14, 2025

235cb2f improves things but also has some serious problems. WMA for Hypergeometric functions gives numeric results when numeric arguments are given. So we need to do the same thing.

@aravindh-krishnamoorthy
Copy link
Collaborator Author

235cb2f improves things but also has some serious problems. WMA for Hypergeometric functions gives numeric results when numeric arguments are given. So we need to do the same thing.

Thank you for brining this up. Indeed, I've this on my radar and take care of the compatibility and the flags. Once I'm done, I will flag this PR for review.

Here, plot explicitly requests a numerical evaluation.
"""

attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED | A_READ_PROTECTED
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
attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED | A_READ_PROTECTED
attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED

In contrast to HypergeometricPFQ, WMA does not list this as being ReadProtected.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rocky I've these changes on my radar. Kindly wait until I've marked this PR for review. Before that, I'm just focusing on the important functional aspects. But, I'll fix the documentation and the attributes before completion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For now, I'll limit myself to these four functions, which I will also be needing at work right now. But, eventually, other hypergeometric functions can be implemented just via rules.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll do that later in another PR.

@rocky
Copy link
Member

rocky commented Feb 14, 2025

Note

This PR is still under development.

Introduction

This PR includes support for the following hypergeometric functions:

  • Hypergeometric1F1
  • HypergeometricPFQ
  • MeijerG
  • HypergeometricU

Why include MeijerG and HypergeometricU? What essential features do each of these add above Hypergeometric1F1 and HypegeomtericPFQ?

Also note there is Hypergeometric0F1 and Hypergeometric2F1 which might easily be added later.

@aravindh-krishnamoorthy
Copy link
Collaborator Author

Note
This PR is still under development.

Introduction

This PR includes support for the following hypergeometric functions:

  • Hypergeometric1F1
  • HypergeometricPFQ
  • MeijerG
  • HypergeometricU

Why include MeijerG and HypergeometricU? What essential features do each of these add above Hypergeometric1F1 and HypegeomtericPFQ?

Also note there is Hypergeometric0F1 and Hypergeometric2F1 which might easily be added later.

In fact, as rightly identified by SymPy, good routines for HypergeometricPFQ and MeijerG are sufficient to implement other hypergeometric functions.

Unfortunately, I need Hypergeometric1F1 and HypergeometricU for my work right now and HypergeometricU is symbolically supported in Sympy only via MeijerG.

But then I realised that mpmath has a specialised routine for HypergeometricU. So, am using the current implementation to compare the numerical performance of the mpmath version to that via N[MeijerG]. If I find them to be equivalent, we'll only need HypergeometricPFQ and MeijerG (sympy + mpmath) and the remainder can be implemented via rules.

@rocky
Copy link
Member

rocky commented Feb 14, 2025

In fact, as rightly identified by SymPy, good routines for HypergeometricPFQ and MeijerG are sufficient to implement other hypergeometric functions.

Unfortunately, I need Hypergeometric1F1 and HypergeometricU for my work right now and HypergeometricU is symbolically supported in Sympy only via MeijerG.

But then I realised that mpmath has a specialised routine for HypergeometricU. So, am using the current implementation to compare the numerical performance of the mpmath version to that via N[MeijerG]. If I find them to be equivalent, we'll only need HypergeometricPFQ and MeijerG (sympy + mpmath) and the remainder can be implemented via rules.

Ok - Thanks for the information and explanation.

Aravindh Krishnamoorthy added 2 commits February 14, 2025 15:57
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.

2 participants