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
Changes from 1 commit
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
17 changes: 11 additions & 6 deletions mathics/builtin/specialfns/hypergeom.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@

import mpmath
import sympy
from mathics.core.convert.mpmath import from_mpmath
from mathics.core.convert.sympy import from_sympy

from mathics.core.attributes import (
A_LISTABLE,
A_N_HOLD_FIRST,
A_NUMERIC_FUNCTION,
A_PROTECTED,
A_READ_PROTECTED,
)
from mathics.core.builtin import SympyFunction, MPMathFunction
from mathics.core.builtin import MPMathFunction, SympyFunction
from mathics.core.convert.mpmath import from_mpmath
from mathics.core.convert.sympy import from_sympy
from mathics.core.evaluation import Evaluation


class HypergeometricPFQ(MPMathFunction):
"""
<url>
Expand Down Expand Up @@ -71,10 +73,13 @@ def eval_numeric(self, a, b, z, evaluation: Evaluation):
def eval_N(self, a, b, z, evaluation: Evaluation):
"N[HypergeometricPFQ[a_, b_, z_]]"
try:
return from_mpmath(mpmath.hyper(a.to_python(), b.to_python(), z.to_python()))
return from_mpmath(
mpmath.hyper(a.to_python(), b.to_python(), z.to_python())
)
except Exception:
pass


class Hypergeometric1F1(MPMathFunction):
"""
<url>
Expand All @@ -88,10 +93,10 @@ class Hypergeometric1F1(MPMathFunction):
= 4.07742
>> Hypergeometric1F1[a, b, z]
= HypergeometricPFQ[{a}, {b}, z]

Plot 'M'[3, 2, x] from 0 to 2 in steps of 0.5:
>> Plot[Hypergeometric1F1[3, 2, x], {x, 0.5, 2}]
= -Graphics-
= -Graphics-
"""

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.

Expand Down