Files
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

244 lines
4.9 KiB
ReStructuredText

Utility functions
===============================================
This page lists functions that perform basic operations
on numbers or aid general programming.
Conversion and printing
-----------------------
:func:`~mpmath.mpmathify` / ``convert()``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.mpmathify
:func:`~mpmath.nstr`
^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.nstr
:func:`~mpmath.nprint`
^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.nprint
:func:`mpmath.mpf.__format__`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.mpf.__format__
:func:`mpmath.mpc.__format__`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.mpc.__format__
Arithmetic operations
---------------------
See also :func:`mpmath.sqrt`, :func:`mpmath.exp` etc., listed
in :doc:`functions/powers`
:func:`~mpmath.fadd`
^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.fadd
:func:`~mpmath.fsub`
^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.fsub
:func:`~mpmath.fneg`
^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.fneg
:func:`~mpmath.fmul`
^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.fmul
:func:`~mpmath.fdiv`
^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.fdiv
:func:`~mpmath.fmod`
^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.fmod
:func:`~mpmath.fsum`
^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.fsum
:func:`~mpmath.fprod`
^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.fprod
:func:`~mpmath.fdot`
^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.fdot
Complex components
------------------
:func:`~mpmath.fabs`
^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.fabs
:func:`~mpmath.sign`
^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.sign
:func:`~mpmath.re`
^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.re
:func:`~mpmath.im`
^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.im
:func:`~mpmath.arg`
^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.arg
:func:`~mpmath.conj`
^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.conj
:func:`~mpmath.polar`
^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.polar
:func:`~mpmath.rect`
^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.rect
Integer and fractional parts
-----------------------------
:func:`~mpmath.floor`
^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.floor
:func:`~mpmath.ceil`
^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.ceil
:func:`~mpmath.nint`
^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.nint
:func:`~mpmath.frac`
^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.frac
Tolerances and approximate comparisons
--------------------------------------
:func:`~mpmath.chop`
^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.chop
:func:`~mpmath.almosteq`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.almosteq
Properties of numbers
-------------------------------------
:func:`~mpmath.isinf`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.isinf
:func:`~mpmath.isnan`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.isnan
:func:`~mpmath.isnormal`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.isnormal
:func:`~mpmath.isfinite`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.isfinite
:func:`~mpmath.isint`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.isint
:func:`~mpmath.ldexp`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.ldexp
:func:`~mpmath.frexp`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.frexp
:func:`~mpmath.mag`
^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.mag
:func:`~mpmath.nint_distance`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.nint_distance
:func:`~mpmath.absmin`
^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.absmin
:func:`~mpmath.absmax`
^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.absmax
Number generation
-----------------
:func:`~mpmath.fraction`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.fraction
:func:`~mpmath.rand`
^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.rand
:func:`~mpmath.arange`
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.arange
:func:`~mpmath.linspace`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.linspace
Precision management
--------------------
:func:`~mpmath.autoprec`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.autoprec
:func:`~mpmath.workprec`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.workprec
:func:`~mpmath.workdps`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.workdps
:func:`~mpmath.extraprec`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.extraprec
:func:`~mpmath.extradps`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.extradps
Performance and debugging
------------------------------------
:func:`~mpmath.memoize`
^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.memoize
:func:`~mpmath.maxcalls`
^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.maxcalls
:func:`~mpmath.monitor`
^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.monitor
:func:`~mpmath.timing`
^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: mpmath.timing