Skip to content

Mixed-mode arithmetics for mpc #805

@skirpichev

Description

@skirpichev

I think, we should implement mixed-mode rules for complex arithmetic. Partially, this already acomplished: mpmath has special rules for mpf op mpc cases, for instance mpc_mul_mpf() to multiply a complex z by a real number r component-wise, z*r == mpc(z.real*r, z.imag*r).

But I'm not sure if that implementation is complete, and obviously it has many bugs. A quick example:

>>> 1/mpc(inf, 1)
mpc(real='nan', imag='0.0')
>>> 1/complex('(inf+1j)')
0j

This case is worse than CPython, probably just due to using naive algorithm for complex division (instead of something like Smith's version).

Entirely missing component is an imaginary type, i.e. one that has only imaginary component and no real. See draft CPython proposal: skirpichev/cpython#1

It should be noted, that this issue depends on #167: presence of signed zeros provide more "corner cases" for analytic expressions (like asinh(z)=log(z + sqrt(1 + z**2))). But regardless on this, we already have infinities, that will require special treatment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementnew feature requests (or implementation)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions