complex arithmetic and mathematical functions

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

complex arithmetic and mathematical functions

Nicolas Cellier-3
Hello, i propose some extensions to Complex class.


First, a convenient creation message:

 (a i: b) is same as (a + b i)
 except it will not involve any operation, coercion etc... (Try operating on
long collections of Complex)
 It produces code much shorter than (Complex real: a imaginary: b) found
everywhere inside Complex class.
 Think of (a@b) and (Point x: a y: b).

 (aComplex i) has same meaning as (aNumber i) : it is multiply by (1 i).
 This one does exist in VW AT-Numerics for example and seems obvious.

Then, some functions arcCos arcSin arcTan argCosh argSinh argTanh arcTan: tanh

I also modified cos, sin, cosh and sinh only for having things like
 (2 + 0 i) sin imaginary isZero
Most definitions were taken from netlib SLATEC FORTRAN library.

I also propose these extensions in Number: sinh cosh tanh argSinh argCosh
argTanh (some exist in Complex but not in Number...).
Further work: put some optional primitive in Float...

I also propose adding a new exception DomainError. This can enable trapping
(-1 sqrt) and answering a complex result for example. (Further work to
connect this exception if accepted)

Then a #absSecure like there is a #divideFastAndSecureBy: will avoid
overflow/underflow in intermediate results.
Shouldn't these two become the default implementation ?

Then a #conjugated is missing.
Should we implement a (conjugated ^self) in Number ???

Last, raisedTo: and raisedToInteger: have to be implemented again in
Complex... This will be the case for a lot of arithmetic classes. (Quaternion
Matrix Polynomial...)
I see two better solutions
 1) make an ArithmeticValue common superclass like in VW
 2) use Traits to factor common protocol for commutative rings, fields, etc...
What are your plans about it ?

Once again, i am too long, bye.

ComplexFunctions.1.cs (17K) Download Attachment