28 Commits

Author SHA1 Message Date
Sergey B Kirpichev fb69943530 Use explicit kwargs in public API, where possible
Following functions kept:
```pycon
>>> import inspect
... with_args = []
... with_kwargs = []
... for n in dir(mpmath):
...     m = getattr(mpmath, n)
...     try:
...         s = inspect.signature(m)
...     except:
...         continue
...     if any(_.kind == inspect._ParameterKind.VAR_POSITIONAL for _ in s.parameters.values()):
...         for name in s.parameters:
...             if s.parameters[name].kind == inspect._ParameterKind.VAR_POSITIONAL and name == 'args':
...                 with_args.append(n)
...                 break
...     if any(_.kind == inspect._ParameterKind.VAR_KEYWORD for _ in s.parameters.values()):
...         with_kwargs.append(n)
... print(with_args)
... print(with_kwargs)
...
['arange', 'ellipe', 'ellippi', 'linspace', 'matrix', 'ones', 'timing', 'zeros']
['multiplicity', 'timing']
```

We need support for multiple signatures in the first case.  In the
second - it's impossible to implement these functions without kwargs.

Closes #1056
2026-08-04 06:40:53 +03:00
HeskethGD 1f3e9bf593 Rename Weierstrass parameter converters 2026-07-25 17:32:21 +01:00
HeskethGD 534dd479f0 Expand Weierstrass parameter conversions 2026-07-25 17:32:06 +01:00
HeskethGD 6f2a553551 Add inverse Klein j-function 2026-07-13 16:08:46 +01:00
Warren Weckesser 8d21910bba Implement the modified spherical bessel functions spherical_in() and spherical_kn(). (#1121) 2026-07-08 04:13:53 +03:00
Sergey B Kirpichev 6f1fbd275d Fix repr_dps() to produce a correct estimate
That should work at lest for 32-bit integers.  Though, I think that
the repr/str representation loses all sence for precisions much
less than that ;-)

Closes #1116
2026-07-01 05:36:13 +03:00
Graham Hesketh aa205a2821 Add Weierstrass elliptic functions (#1113)
* Weierstrass $\wp$: `weierp`
* inverse Weierstrass $\wp$: `weierpinv`
* derivative of Weierstrass $\wp$: `weierpprime`
* Weierstrass zeta: `weierzeta`
* Weierstrass sigma: `weiersigma`

Also adds parameter conversion functions:

* Weierstrass invariants $g_2, g_3$: `weierinvariants`
* half-periods $\omega_1, \omega_2$: `weierhalfperiods`

The idea for this PR was inspired by the `pyweierstrass` package by @stla / Stéphane Laurent:

* https://pyweierstrass.readthedocs.io/en/latest/
* https://github.com/stla/pyweierstrass

The code implementation in this PR is different to that in `pyweierstrass` although both packages derive from similar well known mathematical formulas. Differences between `pyweierstrass` and this `mpmath` implementation include but are not limited to:

* function names adapted to `mpmath` conventions;
* tau normalization: `tau` specifies the normalized period lattice `(1, tau)`, corresponding to half-periods `(1/2, tau/2)`; this differs from `pyweierstrass`, where `tau` denotes half-periods `(1, tau)`;
* support for disambiguating inverse values of Weierstrass $\wp$ by optionally passing the corresponding derivative value;
* internal refactoring of helper functions for integration with `mpmath`.

Dedicated to Stéphane Laurent who opened the original PR to request this functionality in `mpmath` and whose `pyweierstrass` package provided great utility to the author of this PR in the years since.

Co-authored-by: Stéphane Laurent <stla@users.noreply.github.com>

Closes #612
2026-06-30 03:43:58 +03:00
Hongren Zheng 9ac078ca7c Add Fox H-function with rational A and B parameters (#982)
Closes #980
2025-07-27 19:03:23 +03:00
Sergey B Kirpichev 8778568951 Avoid using ";" in doctests, esp with side effects
The new CPython repl hide all output, except for the last statement.
See https://github.com/python/cpython/issues/131217.
2025-05-01 10:41:48 +03:00
Sergey B Kirpichev 4edff338a2 Add exp2() and log2()
Closes #947
2025-04-26 19:10:40 +03:00
Sergey B Kirpichev 5294dd9ddd Support spherical Bessel functions (jn/yn)
Naming scheme follows to SciPy.  Closes #319
2025-04-02 07:12:47 +03:00
Sergey B Kirpichev 380f2f30d5 Cleanup docs for functions (using better signatures) 2025-01-22 09:17:21 +03:00
Sergey B Kirpichev 76e8750282 Remove elliptic module from index, add Index to the toctree 2024-01-19 10:49:11 +03:00
Sergey B Kirpichev 0806b14b21 Expose lower/upper_gamma functions
Closes #738
2023-12-01 07:12:36 +03:00
Sergey B Kirpichev 7abcec1571 Drop some redundant signatures in autofunction directives 2023-10-27 05:03:37 +03:00
Sergey B Kirpichev 21f791e4b6 Add `plus` flag to select the B_1 sign convention for bernoulli/bernfrac 2023-10-07 09:45:21 +03:00
Sergey B Kirpichev da36d96055 Reorganize imports in docs/ (no star imports) 2023-05-09 07:27:20 +03:00
Sergey B Kirpichev 0c1a5d4f44 Fix sphinx warnings with nitpicky=True
Closes #627
2023-04-30 08:54:20 +03:00
Sergey B Kirpichev 57efbdc101 Drop resetting globals (mp.prec and so on) in doctests 2023-04-20 12:55:47 +03:00
Fangchen Li dfc289289d Drop py2 support (#629)
* remove xrange compat shim
* remove str compat shim
* remove exec compat shim
* remove object from class defination
* remove misc workarounds for python versions <3.5
* remove __future__ imports
* update readme
* Update setup.cfg

Closes #594

Co-authored-by: Fredrik Johansson <fredrik.johansson@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Colin B. Macdonald <cbm@m.fsf.org>
2023-03-30 04:50:18 +03:00
Fredrik Johansson b7c15d668c include signals documentation; remove duplicate docstrings 2022-11-07 10:43:28 +01:00
Fredrik Johansson 1b476ea230 update doc building instructions 2022-11-07 10:34:24 +01:00
Deyan Mihaylov 7cd161aef0 Add wrappers and fix documentation 2022-08-22 02:30:21 +02:00
Tina Yu d0135b941f The following things:
Adjusted function parameters to include an independent variable, t. Added other variations of each wave function. For square wave, added functions "squarew_floor" and "squarew_floorex". For triangle wave, added "trianglew_saw" function. For sawtooth, added functions "sawtoothw_mod" and "sawtoothw_floor".

The following things:
Added definitions, descriptions, and examples to functions "squarew", "squarew_floor", "squarew_floorex", "trianglew", "trianglew_saw", "sawtoothw", "sawtoothw_mod", "sawtooth_floor". Also added order of increasing run time for each type of signal wave.

Added logistic sigmoid function to signal.py file as well as the signal.txt file. Corrected examples in the signal.py file so that the period of each example is 2. Also, the last example of each function was correct so that input parameter t is 2 rather than 1.

Fixed typo from squarew_floorex to squarew_floor_ex

Tested the run time of all functions using 200 dps with t = 1.111111... Results were written under each function, giving both the function's return value as well as the run times.

Added type hints to all functions.

Added test file for signal.py.

Added unit triangle function to signal.txt and signal.py. Also added type hints to signal.txt and corrected sigmoid function in signal.py.

Added back signal.txt.

Changed signal files to be named signals.py and signals.txt.

Added unit triangle to test.py and fixed minor typos in docstrings.

Added 'triangle_wave' and 'sawtooth_wave'. Corrected sawtooth functions.

Removed extra wave functions and named remaining functions as squarew, trianglew, and sawtoothw. Added minor edits to function docstrings.

Removed test.py.

Corrected arguments to match those in signals.py.

Changed 'return 0' to 'return ctx.zero' and changed 'sigmoidw' to 'sigmoid'. Also changed 'signals.txt' to an rst file to match original repository.
2022-08-19 00:53:33 +02:00
Nike Dattani 26ed58a096 Added signal.txt with basic "template" including:
square wave, triangle wave, sawtooth wave as a function of amplitude and period, but with really just meant as a template (largely copied from bessel.txt) from which Tina can do her work.

Added the following to mpmath/__init__.py

squarew = mp.squarew
trianglew = mp.trianglew
sawtoothw = mp.sawtoothw
unit_triangle = mp.unit_triangle
sigmoidw = mp.sigmoidw

This block was added to the bottom of the list of functions which began with "sqrt = mp.sqrt" and went up to "stirling2 = mp.stirling2".
2022-08-19 00:51:37 +02:00
Sergey B Kirpichev a5c95a8fbc Fix ~250 broken references in sphinx docs 2021-03-27 01:14:07 +03:00
Sergey B Kirpichev 4a2a320efc Add missing references
Note, that this changes sphinx docs for some constants.  Unfortunately,
there is no other way to display verbose docstrings for pi and euler.
2021-03-27 01:14:07 +03:00
Sergey B Kirpichev a9550c2b70 Reorganize docs (doc/source/ -> docs/, *.txt -> *.rst)
Structure now more closely follow https://packaging.python.org/

To build docs:

    python setup.py build_sphinx -c docs -b html,latex
    make -C build/sphinx/latex all-pdf
2021-03-27 01:14:07 +03:00