Skip to content

pow() docs shouldn't require numeric arguments #130102

@skirpichev

Description

@skirpichev

Currently, the second paragraph of docs starts with "The arguments must have numeric types." That seems to be too restrictive and many third-party packages already break this rule. E.g. SymPy support arbitrary symbolic expressions:

In [1]: pow(x, y)
Out[1]: 
 y
x 

In [2]: pow(x, y, z)
Out[2]: 
 y      
x  mod z

Diofant also uses both forms for polynomial arithmetic:

In [1]: R, x = ring('x', QQ)

In [2]: pow(x + 1, 7, 2*x**2 - 1)
Out[2]: 239/8*x + 169/8

In [3]: ((x + 1)**7) % (2*x**2 - 1)
Out[3]: 239/8*x + 169/8

In [4]: (x + 1)**2
Out[4]: x**2 + 2*x + 1

In [5]: pow(x + 1, 2)
Out[5]: x**2 + 2*x + 1

I suggest to drop this requirement. In fact, first paragraph already mention equivalents for two-arg and three-arg versions of the pow(). We can rephrase it like this: "Return base to the power exp, an equivalent to base**exp; if mod is present, return base to the power exp, modulo mod, an equivalent to (base**exp) % mod (but computed more efficiently)."

The third paragraph also might instead specify requirements for the mod in case of integer base and exponent, not just for builtin int's.

Metadata

Metadata

Assignees

Labels

docsDocumentation in the Doc dir

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy