Per @encukou suggestion in the C-API WG issue, I’ll update this thread with alternative proposal, i.e. what if we will expose current _Py_c_* functions as public? This is a more conservative solution than proposed in my original post.
Historically, we had above functions as semi-public (quoted from Include/cpython/complexobject.h):
// Operations on complex numbers.
PyAPI_FUNC(Py_complex) _Py_c_sum(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) _Py_c_diff(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) _Py_c_neg(Py_complex);
PyAPI_FUNC(Py_complex) _Py_c_prod(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) _Py_c_quot(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) _Py_c_pow(Py_complex, Py_complex);
PyAPI_FUNC(double) _Py_c_abs(Py_complex);
Note that the _Py_c_abs() is not shown in docs.
I propose following primitives (GSL-like) as a public API:
PyAPI_FUNC(Py_complex) Py_c_add(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) Py_c_add_real(Py_complex, double);
PyAPI_FUNC(Py_complex) Py_c_sub(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) Py_c_sub_real(Py_complex, double);
PyAPI_FUNC(Py_complex) Py_c_neg(Py_complex z); // -z
PyAPI_FUNC(Py_complex) Py_c_mul(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) Py_c_mul_real(Py_complex, double);
PyAPI_FUNC(Py_complex) Py_c_div(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) Py_c_div_real(Py_complex, double);
PyAPI_FUNC(Py_complex) Py_c_inv(Py_complex); // 1/z = 1/(x+iy)=(x-iy)/(x^2+y^2)
This set should be appropriate to implement mathematical functions on top of that. Later it could be extended with primitives for pure-imaginary numbers, e.g.:
PyAPI_FUNC(Py_complex) Py_c_add_imag(Py_complex z, double a); // z + ia
Possible additions:
PyAPI_FUNC(Py_complex) Py_c_abs(Py_complex z);
PyAPI_FUNC(Py_complex) Py_c_arg(Py_complex z); // cmath.phase
PyAPI_FUNC(Py_complex) Py_c_pow(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) Py_c_pow_real(Py_complex, double);
Naming variants: 1) different prefix, e.g. Py_complex_, 2) more verbose names, e.g. subtract instead of sub or negative instead of neg.