[Matrix-SIG] NumericFix.py

Konrad Hinsen hinsen@cnrs-orleans.fr
Mon, 16 Nov 1998 17:12:58 +0100


> The problem is that in order to get sqrt(-1) one has
> to write sqrt(-1+0j) which, I think, is quite weird.

Well, it may be surprising, but it's the outcome of a design
decision, not a bug. There are good arguments for making the
functions behave like they do, once you consider that most
practical applications do not require complex numbers.

> So, I propose the following fixes in the Numeric module
> that is realized in the file 'NumericFix.py' (see below).

I wouldn't call it a fix, but that's debatable. More importantly,
some of your definitions don't make sense to me:

> def ceil(a):
>     try: return umath.ceil(a)
>     except AttributeError: return umath.ceil(a.real)+1j*umath.ceil(a.imag)
> def floor(a):
>     try: return umath.floor(a)
>     except AttributeError: return umath.floor(a.real)+1j*umath.floor(a.imag)

Both ceil() and floor() make sense only for numbers with an order
relation, i.e. not for complex numbers.

> def fabs(a):
>     try: return umath.fabs(a)
>     except AttributeError: return umath.fabs(a.real)+1j*umath.fabs(a.imag) 

The proper generalization of absolute values to complex
numbers is umath.sqrt(a*conjugate()).

> Numeric.__dict__['sqrt']=sqrt
>...

It's not a good idea to have one module modify another one. This can
create a lot of confusion, because the functions you get depend on
when you import them.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                            | E-Mail: hinsen@cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.55.69
Rue Charles Sadron                       | Fax:  +33-2.38.63.15.17
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais
-------------------------------------------------------------------------------