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

Bessel and Meijer-G functions added to MpmathPrinter #22506

Merged
merged 1 commit into from Nov 21, 2021

Conversation

scimax
Copy link
Contributor

@scimax scimax commented Nov 16, 2021

Hello everyone,

I was working with some bessel functions, but wanted to export it to mpmath via pretty-printing. However, I realized that some functions were not included in the MpmathPrinter. So I've added those which I needed. Maybe it's also useful for others, but I have to say, I didn't go through all different functions. Is there a need for other functions? Then the PR would just work as a starting point.

Further, is it useful to add a test?

I hope this is helpful for others.

Thanks!

Brief description of what is fixed or changed

  • hyper, meijerg, besselj, bessely, besseli, besselk add to _known_functions_mpmath in pycode printer.

Release Notes

  • printing
    • Meijer-G function and Bessel functions in MpmathPrinter

@sympy-bot
Copy link

sympy-bot commented Nov 16, 2021

Hi, I am the SymPy bot (v162). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • printing
    • Meijer-G function and Bessel functions in MpmathPrinter (#22506 by @scimax)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.10.

Click here to see the pull request description that was parsed.
Hello everyone,

I was working with some bessel functions, but wanted to export it to `mpmath` via pretty-printing. However, I realized that some functions were not included in the `MpmathPrinter`. So I've added those which I needed. Maybe it's also useful for others, but I have to say, I didn't go through all different functions. Is there a need for other functions? Then the PR would just work as a starting point.

Further, is it useful to add a test?

I hope this is helpful for others.

Thanks!

#### Brief description of what is fixed or changed
- `hyper`, `meijerg`, `besselj`, `bessely`, `besseli`, `besselk` add to `_known_functions_mpmath` in pycode printer.

#### Release Notes
<!-- BEGIN RELEASE NOTES -->
* printing
  * Meijer-G function and Bessel functions in MpmathPrinter
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@github-actions
Copy link

Benchmark results from GitHub Actions

Lower numbers are good, higher numbers are bad. A ratio less than 1
means a speed up and greater than 1 means a slowdown. Green lines
beginning with + are slowdowns (the PR is slower then master or
master is slower than the previous release). Red lines beginning
with - are speedups.

Significantly changed benchmark results (PR vs master)

       before           after         ratio
     [02a21dc5]       [619d9493]
+       281±0.3ns        556±100ns     1.98  baseline.TimeBaseline.time_loop10
+        1.13±0μs       4.32±0.1μs     3.82  baseline.TimeBasicGCD.time_gcd
+     2.01±0.01μs       7.82±0.2μs     3.88  core.arit.Time_Arit.time_Add_1x
+      12.5±0.6μs        39.9±10μs     3.20  core.arit.Time_Arit.time_Add_x05
+     2.01±0.01μs         5.01±1μs     2.49  core.arit.Time_Arit.time_Add_x1
+     1.08±0.06μs         3.81±1μs     3.53  core.arit.Time_Arit.time_Add_xy
+        765±10ns       2.59±0.8μs     3.39  core.arit.Time_Arit.time_Add_xyz
+      2.54±0.1μs       5.51±0.7μs     2.17  core.arit.Time_Arit.time_Div_2y
+     1.93±0.01μs         5.44±2μs     2.82  core.arit.Time_Arit.time_Div_xy
-      1.53±0.1μs         381±20ns     0.25  core.expand.TimeExpand.time_expand_nothing_todo
-        26.0±6μs       11.1±0.1μs     0.43  core.expand.TimeExpand.time_expand_power_base
-       41.6±10μs       13.5±0.9μs     0.32  core.expand.TimeExpand.time_expnad_radicals
-        13.0±5ms       5.33±0.3ms     0.41  large_exprs.TimeLargeExpressionOperations.time_free_symbols
+     14.7±0.07ms        28.4±20ms     1.94  physics.mechanics.lagrange.LagrangesMethodMassSpringDamper.time_lagrangesmethod_mass_spring_damper
+        18.6±1μs        46.6±30μs     2.51  polys.TimePolyManyGens.time_is_linear(10)
+        585±40μs       1.39±0.9ms     2.38  polys.TimePolyManyGens.time_is_linear(100)
+         422±2μs        724±300μs     1.71  solve.TimeMatrixArithmetic.time_dense_multiply(6, 5)
-        143±80ms       57.9±0.2ms     0.41  solve.TimeMatrixOperations.time_rref(4, 5)
-       68.3±40ms       32.7±0.2ms     0.48  solve.TimeMatrixPositiveDefinite.time_A_sym_is_positive_definite
-       402±200ms          185±2ms     0.46  solve.TimeMatrixSolve.time_solve('ADJ')
-      1.40±0.9ms          649±2μs     0.46  solve.TimeMatrixSolve.time_solve('LU')
+       108±0.6ms         388±10ms     3.58  sum.TimeSum.time_doit

Significantly changed benchmark results (master vs previous release)

       before           after         ratio
     [907895ac]       [02a21dc5]
+      7.53±0.5μs        16.9±10μs     2.25  core.arit.Time_assumption.time_Add_Mul_is_integer
+        22.9±1μs        42.9±30μs     1.87  core.arit.Time_assumption.time_ncmul
+       377±200ns       1.53±0.1μs     4.05  core.expand.TimeExpand.time_expand_nothing_todo
+         822±3μs       2.38±0.3ms     2.90  cse.TimeCSE.time_cse((2, 11))
-        98.6±8μs        30.0±10μs     0.30  integrate.TimeIntegrationRisch03.time_doit(1)
+      4.69±0.3ms         13.0±5ms     2.78  large_exprs.TimeLargeExpressionOperations.time_free_symbols
+       197±0.6μs        497±300μs     2.52  matrices.TimeMatrixExpression.time_MatMul
+     3.47±0.03μs         7.43±5μs     2.14  matrices.TimeMatrixExpression.time_Mul
+      40.4±0.5μs        86.4±50μs     2.14  matrices.TimeMatrixGetItem.time_ImmutableSparseMatrix_getitem
+      6.43±0.4ms         11.1±2ms     1.72  matrices.TimeMatrixPower.time_Case1

Full benchmark results can be found as artifacts in GitHub Actions
(click on checks at the top of the PR).

@oscargus
Copy link
Contributor

Looks good! Thanks!

I think that there may be some more functions. The best would probably be to go through https://github.com/sympy/sympy/tree/master/sympy/functions/special and https://mpmath.org/doc/current/functions/index.html to check which ones can be added. The error and airy functions for example seems to not be supported.

Regarding tests, I believe that the basic printing functionality is tested for loggamma so should work for other functions in the dict as well, but in case some functions have multiple arguments it can make sense to add a test for that to make sure the arguments ends up in the expected order. (It is quite likely though that they match.)

@oscargus
Copy link
Contributor

I'll merge this for now, but if you continue to add functions, which is appreciated, please add some tests for argument orders. (I guess they are the same as probably whoever wrote the SymPy code was inspired by the mpmath functions.) Thanks!

@oscargus oscargus merged commit ef854da into sympy:master Nov 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants