commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles <gil...@harfang.homelinux.org>
Subject [Math] Re: Proposed changes to Complex method nomenclature
Date Wed, 01 Jun 2016 23:04:40 GMT
Hello.

On Wed, 1 Jun 2016 21:53:59 +0200, Eric Barnhill wrote:
> On 31/05/16 14:12, Gilles wrote:
>>
>>
>> Short as can be and close to math notation.
>>
>> Another possibility may be to keep long names and to add syntactic
>> sugar such as
>> -----
>> public static double im(Complex c) {
>>     return c.getImaginary();
>> }
>> -----
>
> I have been looking at std::complex to get some ideas. Connected to
> the issue (coming soon in another thread) of conforming the Complex 
> to
> C99.
>
> (http://en.cppreference.com/w/cpp/numeric/complex)
>
> Do you see any value in conforming to this reference?

We can't really conform, lacking operator overloading.
The name of the function are fine I think; no need to have long names.
Here it really depends on where to put the emphasis, common usage
or Commons usage (not sure there is such a thing)...

> If so, this
> could mostly be accomplished by adding a few syntactic sugar methods,
> while leaving in longer-name methods that follow the commons style, 
> to
> which I also see benefit.

What are they?
It could help to make up my mind; a priori, I would not create more 
than
one API method.

> These would include real, imag, abs, arg, conj .
>
> Then a few methods are missing which are not much trouble -- log10
> and norm are easy, but I am not familiar with proj, which is only in
> C11 anyway.
>
>>
>>> This leaves only the question of a constructor that takes polar
>>> representations which I think is already well handled by the 
>>> present method
>>> ComplexUtils.polar2Complex, for either Complex or Complex[] .
>>
>> Shall we consider making the constructors "private" and define
>> factory methods (like those currently in "ComplexUtils")?
>>
>> public static Complex createCartesian(double re,
>>                                       double im) {
>>     return new Complex(re, im);
>> }
>>
>> public static Complex createPolar(double r,
>>                                   double theta) {
>>     return new Complex(r * FastMath.cos(theta),
>>                        r * FastMath.sin(theta));
>> }
>>
>
>
>
> It seems to follow the criteria for factory pattern, in that we want
> to give the user ways to create the object that are most convenient
> (cartesian or polar), uncoupled from object structure.
>
>> And suppress the ambiguous methods "createComplex" and
>> "valueOf".
>
> definitely
>
>>
>> Actually I think that only one constructor should stay that
>> is tied to the underlying representation (and for that reason
>> it should not be "public").
>>
>
>
>> What do you think?
>
> I figure one goal is for the Complex to not be much bigger than two
> doubles. So real and imag are probably what should be in the
> structure, with the polar values calculated, and a factory method 
> used
> to construct complex from polar.

Since some computations are more efficient with one representation
and others with the other, how about having "Complex" an interface
with "CartesianComplex" and "PolarComplex" implementations?

Just mentioning: I have no idea whether the added flexibility is
worth it from a performance point-of-view.
It may depend on the application (and I have none in mind).

But perhaps you have some opinion on whether there would be something
to gain especially in computations that involve (large) arrays of
Complex objects.

Regards,
Gilles

>
> Eric
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message