47 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
Sergey B Kirpichev 2a2de4e7ca Drop mp.THETA_Q_LIM 2026-06-29 03:19:33 +03:00
Sergey B Kirpichev 4118cfd0db Fix signature of root()
Closes #1067
2026-04-17 05:42:03 +03:00
Sergey B Kirpichev 7cf16b7828 Revert "Add isspecial() method for mp/fp contexts, deprecate isnormal()"
This reverts commit e6aa3b46b1.

Subnormals are properly handled by fp.isnormal().  Deprecate
fp.is_special() method.

Fixes #946
2026-02-23 04:08:07 +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 e6aa3b46b1 Add isspecial() method for mp/fp contexts, deprecate isnormal()
Closes #946
2025-04-28 08:36:15 +03:00
Sergey B Kirpichev 4edff338a2 Add exp2() and log2()
Closes #947
2025-04-26 19:10:40 +03:00
Sergey B Kirpichev 515f2a2214 Use correct constructor in series branch of log1p
This amends 7596816

Closes #853
2024-08-30 11:25:15 +03:00
Sergey B Kirpichev 7596816fbe Improve accuracy of log1p() (#803)
Patch, ported from Tim Peters version at: https://github.com/mpmath/mpmath/issues/790#issuecomment-2084094631

Co-authored-by: Tim Peters <tim.peters@gmail.com>
2024-08-02 07:29:15 +03:00
Sergey B Kirpichev c599eb6ec9 Workaround 1/z division for acot/asec/acsc/acoth
Closes #796
2024-04-27 15:50:31 +03:00
Sergey B Kirpichev 101320e477 Change type(foo)(bar) -> aproppriate ctx.mpf/ctx.mpc(bar) calls 2023-09-22 12:04:45 +03:00
Sergey B Kirpichev 920d8ed3e7 Drop micro-optimizations for small rational constants 2023-05-19 07:03:11 +03:00
Sergey B Kirpichev 0efdfeb7cd Drop ctx._mpq 2023-05-19 07:03:11 +03:00
Sergey B Kirpichev 744d44483d Rename rational constants (to be private) 2023-05-19 07:03:11 +03:00
Sergey B Kirpichev 721e2571eb Drop private mpq class, use Rational's provided by backend 2023-05-19 07:03:11 +03:00
Sergey B Kirpichev 5ec9d07dee Reorganize imports in doctests (no star imports) 2023-05-09 07:27:20 +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
Sergey B Kirpichev ef7597994d Return passed in function in defun* decorators
This turn on more doctests, e.g.:

$ py.test mpmath/functions/qfunctions.py
============================= test session starts ==============================
platform linux -- Python 3.7.1, pytest-4.2.0, py-1.7.0, pluggy-0.8.1
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/home/sk/src/mpmath/.hypothesis/examples')
rootdir: /home/sk/src/mpmath, inifile: setup.cfg
plugins: xdist-1.26.1, timeout-1.3.3, forked-1.0.1, cov-2.6.1, hypothesis-4.4.3
collected 4 items

mpmath/functions/qfunctions.py ....                                      [100%]

=========================== 4 passed in 0.49 seconds ===========================

Some doctests were adapted.
2019-02-03 21:14:43 +03:00
fredrik 0a006fe83c implement log1p (issue #420) 2018-12-03 20:47:43 +01:00
Fredrik Johansson 205162278e make acot(0), acoth(0) -> finite result 2016-11-07 18:19:12 +01:00
Sergey B Kirpichev 2b0eb67a22 Don't use asserts in the code (partial fix from sympy/sympy#5090) 2014-04-25 22:11:28 +04:00
Fredrik Johansson b597356632 some basic code for Stirling numbers 2012-12-30 22:54:54 +01:00
Fredrik Johansson 5c8e4aa5b4 import xrange from libmp.backend to work in python 3 2011-01-08 22:54:03 +00:00
Juan Arias de Reyna c58dc54a74 2010-11-06 10:43:53 +00:00
Fredrik Johansson 96be7c17be implement the von Mangoldt function 2010-10-30 20:43:38 +00:00
Fredrik Johansson 27eab13de6 convert line endings in trunk to unix format; rebuild docs 2010-07-28 20:09:06 +00:00
Fredrik Johansson 8ccd827dd5 fix lambertw for py2.5/win where negative zero is unsupported 2010-06-22 17:43:47 +00:00
Fredrik Johansson 1d987b3d2b substantially rewrite lambertw(), particularly improving accuracy and branch selection near the singularity at -1/e and near the branch cuts 2010-06-15 20:15:41 +00:00
Fredrik Johansson 76876e61d5 fix lambertw with huge k 2010-06-14 19:56:41 +00:00
Fredrik Johansson a32f20f8ad new implementation of Airy functions
* rigorous evaluation via hypercomb
* support for arbitrary-order derivatives and integrals
* support for computation of zeros
2010-06-12 20:52:21 +00:00
Fredrik Johansson 61d076b7ad rename modf -> fmod (for consistency, and because the function does not do the same thing as math.modf anyway) 2010-06-02 20:41:25 +00:00
Fredrik Johansson 31824d13ed fix fp.conj for Python 2.4 & 2.5 2010-03-05 07:24:55 +00:00
Fredrik Johansson 8fb6053978 get rid of some of the complaints python -3 has about the code 2010-02-06 20:16:10 +00:00
Fredrik Johansson 09a3e1cd21 consistent line endings 2010-02-04 14:43:01 +00:00
Fredrik Johansson c5d1125530 Reorganization to support the improved Cython backend in Sage. A number of internal methods have been renamed in the process. The patch also contains some other optimizations. 2010-02-03 00:56:42 +00:00
Fredrik Johansson c7f48602f9 faster implementation of fp.zeta for real arguments; eliminate overhead for fast cases in zeta by trying to call _zeta directly; use zeta to compute altzeta in the general case 2010-01-24 22:53:13 +00:00
Fredrik Johansson de403a0b3c improve ci,si,chi,shi for complex arguments by computing them using ei; make ci,si,chi,shi,ei,e1,li work with fp. TODO: implement ei in math2 2010-01-22 12:37:21 +00:00
Fredrik Johansson 73b4ea4820 fix last commit 2010-01-21 21:48:16 +00:00
Fredrik Johansson 63ddc2ad41 use fp.lambertw to generate the initial value for mp.lambertw (gives ~2x speedup at mp.dps = 15) 2010-01-21 21:39:41 +00:00
Fredrik Johansson b3bc19141c Fix compatibility with python 2.4 and python 2.5. Most importantly: to support the fp context, the .real and .imag attributes cannot be used except where the type is guaranteed to be complex 2010-01-21 20:27:22 +00:00
Fredrik Johansson ae83f2a42b optimized zetasum for complex arguments 2010-01-19 12:58:02 +00:00
Fredrik Johansson 889eb7c4a7 unified zeta() and hurwitz(); the implementation now chooses between the Borwein, Euler-Maclaurin, and Riemann-Siegel methods 2010-01-17 18:31:25 +00:00
Fredrik Johansson 947e5c3c3e a few bugfixes for fp.harmonic and fp.digamma; deprecating psi0, psi1 and related function aliases 2010-01-17 17:19:44 +00:00
Fredrik Johansson 079dde1027 move a few methods 2010-01-16 09:56:30 +00:00
Fredrik Johansson 855f62b4c7 provide phase(), polar(), rect() for compatibility with the Python 2.6 cmath module; restore some accidentally deleted docstrings; slightly more sane way to define function aliases 2010-01-15 21:13:56 +00:00
Fredrik Johansson bf716a8b7a split functions.py into smaller pieces 2010-01-12 19:28:32 +00:00
Fredrik Johansson 2413d1a18b moving modules to subdirectories: mpmath/libmp, mpmath/calculus, mpmath/functions 2010-01-12 18:19:42 +00:00