You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gilles Sadowski <gi...@harfang.homelinux.org> on 2011/09/03 23:17:53 UTC
Re: [math] Complex division
On Sat, Sep 03, 2011 at 08:10:59AM -0700, Phil Steitz wrote:
> On 9/3/11 2:30 AM, Gilles (JIRA) wrote:
> > [ https://issues.apache.org/jira/browse/MATH-657?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13096621#comment-13096621 ]
> >
> > Gilles commented on MATH-657:
> > -----------------------------
> >
> > I've just posted a mail on "dev".
>
> Should be discussed on the dev list.
That's why I posted the mail referred to above...
> We should not be trying to
> have discussions on API changes on JIRA tickets. That is not what
> JIRA is for.
Hmm, I thought I was doing the right thing by following the example of
https://issues.apache.org/jira/browse/MATH-164
By the way, it shows that following a older dicussion on JIRA is much more
convenient than hopping from one post to another on ML archive, with the
myriad of quotes, double-quotes, triple-quotes, ...
> It is an unwritten (well, probably is actually written
> down somewhere by now) rule @apache that if a decision "did not
> happen on the dev list, then it did not happen." We should be
> talking about API design issues on this list, not opening JIRAs each
> time we think an API should be changed and trying to have the
> discussion on the JIRA ticket.
Sorry if I broke an old and venerable rule. It was not the intention;
for me, it was just solving a trivial bug in the same manner I did already
before, and not a unilateral decision to "change the API".
> >
> > IMO, the main argument is consistency. Also with how reals (i.e. {{double}}) work; IIUC, MATH-164 triggered a change for that same reason.
> >
> > Arne Plöse is a user and [reported|MATH-620] that the previous behaviour was not fine for him.
>
> What exactly was the practical problem? Arne, care to elaborate?
Not wanting to answer for Arne; just my own two cents: Why not give the
right answer?
Maybe that we can _decide_ that any manipulation of a "Complex" instance
containing infinities is mildly meaningless (in the applications where CM
is used) and return NaN for any operation involving them (?). That would
probably simplify several methods (and make them more efficient). Unless I'm
mistaken that would just cost a comment like
"Manipulating instances with infinities will result in undefined results."
> >
> > I don't think that this one change can have a discernible performance impact.
> > It might not be necessary to map all {{Complex}} instances that have an infinite component to a single object. I pointed it as a convenient justification for fixing a bug
>
> Not so clear it is a "bug" - the only way to characterize it as such
> is to model the space as compactified.
As you say yourself below, having an INF is to assume that the "Complex"
class represents elements from C U {"point at infinity"}. At least that's
how I interpret it.
Had there not be a special handling of instances that have an infinity in
their real or imaginary part, I'd say that the NaN result would be normal,
as the output of the computational formulae.
But this would entail to let operations produce their expected results,
which is not the case with "z.multiply(z)", as reported by Arne:
https://issues.apache.org/jira/browse/MATH-620?focusedCommentId=13096432&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13096432
> I notice now that multiply sort of behaves this way, and as I said
> on the ticket, we have already defined "INF" so an argument could be
> made that we are partly there already. I would like to understand
> the practical arguments pro and con - and by "practical" I mean
> examples of how the proposed change and any others impact actual
> uses of the class in applications. I have reviewed my own
> applications and for those, there is no immediate impact (other than
> performance hit in division and complex construction),
Did you measure it?
Are you sure that performance is not _improved_ for division? :-)
> but I worry a
> little about losing the ability to represent directed infinities if
> we decide to really aim for "consistency" here.
What are the use-cases for those?
When looking for references, I only stumbled on the usefulness of _one_
"point at infinity".
> I guess we could
> retain directed infinities by adding a directed INF with an argument
> attribute, but that would again add overhead to several operations.
If you have applications that deal with any "directed" infinities, don't you
need polar coordinates too? That seems to be missing in class Complex
(talking about new API...).
Then, would the "argument attribute" be the angle?
>
> At this point, I would like to see r1164756 reverted until we have
> agreed on this change.
Well, that is done. And, IMHO, there is an identified bug (or at least
an inconsistency worth removing) there. I would like to see use cases that
justify keeping the inconsistency. A mathematical explanation will do too
;-).
Thanks,
Gilles
P.S. I've just seen that you completely removed changes that I find useful
_independently_ of the decision to change or not the behaviour of
division by zero:
* factoring out multiple tests into separate test methods,
* keeping track of test cases that correspond to an issue, and
* using a flag "isZero" in the "divide" method.
Thus, they were left on purpose, as supposed enhancements similar to
those which several people commit informally from time to time.
Is it customary to pull the rug out from under someone's feet?
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] Complex division
Posted by Phil Steitz <ph...@gmail.com>.
On 9/4/11 6:01 AM, Gilles Sadowski wrote:
>>> [...]
>> The hit is in the constructor, where every complex instance has to
>> run the code to set the property.
> In fact, not only! If one can trust the mini-benchmark performed with
> "PerfTestUtils", the constructor with the additional flag is 2% slower.
> But using the flag in "divide" makes it also _slower_ (3 per 1000 even for
> division by zero), contrary to my expectations. [All of these operations
> taking the order of 10 to 60 microseconds, relativizing the loss of
> performance.]
The constructor hit is what I was most worried about, since it
impacts every instantiation. The other thing that I was thinking
explains the counter-intuitive result on the flag. Assuming you are
using stochastically generated values, the probability that the
first comparison in the flag-less code will succeed is miniscule
(zero actually, mathemtically but 1/(number of representable
doubles) in practice), so given the short-circuit evaluation and the
fact that a double equality check is probably optimized to be not
much if at all more expensive than a test on a boolean, it makes
sense that adding the flag won't improve performance in most cases
and the overhead of the method call to read it might actually
hurt. This is a little unfair because I expect exact 0's to be
more likely in practice.
Phil
>
>>>> This, btw, is yet another reason to separate commits.
>>> OK, I take this as: You would have only "cleanly reverted" the Javadoc
>>> change, if it would have been separate. I'll thus commit back the rest.
>> Please do not add back the extra property.
> I apologize for not having heeded to the advice that timing results do not
> always agree with what the code would seem to imply for a naive reader.
>
> [A wild guess would be that comparing with 0.0 is more apt to optimization
> by the JVM than a boolean check (?). Or could it vary from processor to
> processor and from JVM to JVM and from JVM version to JVM version? Then,
> if we are below some reasonable performance quality (i.e. relative to all
> the other operations required from an "average" and "useful" application);
> I think that it is all the more worth improving the consistency of the
> "Complex" class (even if just to avoid those time-consuming discussions to
> pop up again in the future!).]
>
> It would be useful to hear others on this last point, in order to start (or
> not) a reflexion on a global policy for code improvement along several axes
> (consistency vs performance vs readability vs self-documenting vs ...) which
> would maybe result in objective rules that will help to decide whether a
> change is acceptable, based on clearly defined trade-offs.
> That would hopefully be helpful to avoid such situations where one makes a
> change because he likes it, and another refuses the change because he does
> not like it; if you see what I mean.
>
> In my opinion, a necessary step in that direction would be to set up a
> "framework" for performance tests with baseline acceptable values for
> selected sets of realistic use-cases. I think that many committers here
> could readily come up with such use-cases.
>
>
> Gilles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] Complex division
Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
> > [...]
>
> The hit is in the constructor, where every complex instance has to
> run the code to set the property.
In fact, not only! If one can trust the mini-benchmark performed with
"PerfTestUtils", the constructor with the additional flag is 2% slower.
But using the flag in "divide" makes it also _slower_ (3 per 1000 even for
division by zero), contrary to my expectations. [All of these operations
taking the order of 10 to 60 microseconds, relativizing the loss of
performance.]
> >
> >> This, btw, is yet another reason to separate commits.
> > OK, I take this as: You would have only "cleanly reverted" the Javadoc
> > change, if it would have been separate. I'll thus commit back the rest.
>
> Please do not add back the extra property.
I apologize for not having heeded to the advice that timing results do not
always agree with what the code would seem to imply for a naive reader.
[A wild guess would be that comparing with 0.0 is more apt to optimization
by the JVM than a boolean check (?). Or could it vary from processor to
processor and from JVM to JVM and from JVM version to JVM version? Then,
if we are below some reasonable performance quality (i.e. relative to all
the other operations required from an "average" and "useful" application);
I think that it is all the more worth improving the consistency of the
"Complex" class (even if just to avoid those time-consuming discussions to
pop up again in the future!).]
It would be useful to hear others on this last point, in order to start (or
not) a reflexion on a global policy for code improvement along several axes
(consistency vs performance vs readability vs self-documenting vs ...) which
would maybe result in objective rules that will help to decide whether a
change is acceptable, based on clearly defined trade-offs.
That would hopefully be helpful to avoid such situations where one makes a
change because he likes it, and another refuses the change because he does
not like it; if you see what I mean.
In my opinion, a necessary step in that direction would be to set up a
"framework" for performance tests with baseline acceptable values for
selected sets of realistic use-cases. I think that many committers here
could readily come up with such use-cases.
Gilles
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] Complex division
Posted by Phil Steitz <ph...@gmail.com>.
On 9/4/11 7:22 AM, Gilles Sadowski wrote:
> Hello Luc.
>
>>>>> [...]
>>>>>> The mathematical question is do we view our class as representing
>>>>>> the extended complex numbers. If we agree that the answer to that
>>>>>> question is yes,
>>>>> If you say "no", then my understanding is that the "Complex" class does not
>>>>> represent the complex number concept, unless *all* operation that encounter
>>>>> infinities result in "undefined behaviour" (i.e. return NaN).
>>>> Not necessarily. The Complex field does not include any "point at
>>>> infinity." There is a topological space that can be formed from the
>>>> Complex numbers by adding a point at infinity and extending
>>>> functions to include that point. This is what is sometimes called
>>>> the extended complex numbers and a common topology for the space is
>>>> represented by the Riemann Sphere. It is not obvious to me that it
>>>> is best for us to try to model this (sorry to repeat myself, but
>>>> this is the key point). If you really want to be *consistent* and
>>>> insist that it is a *bug* to return NaN for division by complex
>>>> zero, then you are insisting that we adopt this view. To be
>>>> consistent in that view, we need to change equals, all arithmetic
>>>> operations, and the exponential and trig functions as well. Our
>>>> implementations of those functions are based loosely on C99x, which
>>>> does not consistently represent the compactified space.
>>> No, I'm not insisting that we adopt one or the other view. I'm insisting
>>> that by having an "INF", it looks like the class represents the extended
>>> complex numbers. In which case, it is a bug.
>>> My main point is to not treat only _selected_ infinities as equal, but
>>> either not treat any infinities at all (complex field; doing as if Java
>>> did not provide "Double.POSITIVE_INFINITY") or treat them _all_ to be equal
>>> (compactified sphere; consistency with Java "double"; self-consistency).
>>>
>>>>>> The added "isZero" attribute is part of the performance
>>>>>> hit.
>>>>> Really? How much? What tests? Can I emit the possibility that testing a
>>>>> "boolean" might be a tiny bit faster than testing equality with "0.0"
>>>>> twice?
>>>> The hit is in the constructor, where every complex instance has to
>>>> run the code to set the property.
>>>>>> This, btw, is yet another reason to separate commits.
>>>>> OK, I take this as: You would have only "cleanly reverted" the Javadoc
>>>>> change, if it would have been separate. I'll thus commit back the rest.
>>>> Please do not add back the extra property.
>>> If performance is so central that you can't suffer an additional flag, we
>>> should *seriously* consider dropping the other two flags "isNaN" and
>>> "isInfinite" and let the computational formulae do their work: In most
>>> use cases, the result will be correct (at least, as correct as returning NaN
>>> for division by zero) and the performance will be *greatly* enhanced
>>> (comparing to the cost of my additional flag which you seem to consider as
>>> the straw that broke the camel's back).
>> I'm on the fence on this. I like both specific handling on
>> infinities and NaN, and performances. In fact, I would very much
>> like to have a complex primitive type directly supported by the
>> language and following C99 conventions, but it does not seem to
>> happen anytime.
>>
>> In the recent changes in [math], we have introduced several features
>> to deal with infinities and NaNs, so I guess our current focus is
>> towards completeness and the extended Complex set is the more
>> consistent with this.
> I'd just like to remind, after all the fuss, that the crux of the matter
> (leaving aside the additional flag issue) was to replace:
> ---CUT---
> final double c = divisor.getReal();
> final double d = divisor.getImaginary();
> if (c == 0.0 && d == 0.0) {
> return NaN;
> }
> ---CUT---
> with
> ---CUT---
> final double c = divisor.getReal();
> final double d = divisor.getImaginary();
> if (c == 0.0 && d == 0.0) {
> return (real == 0.0 && imaginary == 0.0) ? NaN : INF;
> }
> ---CUT---
>
> How this change could hurt existing users of "Complex" (and require a
> "clean" revert and endless arguing) is beyond me. There was a test case
> exercising the new behaviour and the old behaviour could be recovered easily
> if, in the end, the unobvious/inconsistent behaviour was to be retained
> (which would have entailed the addition in the Javadoc of a complete
> explanation as to why it was decided to be so).
>
>>> Please explain the rationale behind your insistence for not fixing this tiny
>>> issue (I don't mean going for complete consistency with the "compactified"
>>> view but just return INF for division by zero) on the basis of performance
>>> but find it nice to have dozens of unnecessary checks (because they are
>>> useful only for limiting cases similar to division by zero).
>>>
>>> Let me add that I find quite rude your indiscriminate reverting of my
>>> work. Whatever criticism you have with my additions in the "main" area, that
>>> did not mean that you could erase the changes in the "test" area.
>>> As for your rule with "-1 a commit" I maintain that it was not warranted
>>> here, where you could simply remind me to change what had to be, without
>>> touching the rest. That would just mean being polite. There are recent
>>> examples where changes were made without a JIRA issue and without discussion
>>> here; what would you say if I were to go and revert those just because there
>>> is such a rule?
>>> I would also be glad to read the opinion of others on this administrative
>>> question.
>> Please, don't overreact on this, both of you.
>>
>> All of us, Gilles, Phil, Bill, Mikkel, Greg, Sébastien, Ted, Dietmar
>> and others are trying to have a good math library. All of us have
>> different goals, different main topics of interest and different
>> views. There are far more things we share than things we disagree
>> upon and we should focus on these commons things.
>>
>> *Nobody* should take a different view, or a criticism, or even a -1
>> as a personal aggression.
> I took it so because I've never seen such a thing occur for anyone else.
> Was there a security breach that warranted the urgent deletion?
I apologize, Gilles. I honestly thought I was helping. By not just
doing a revision-based revert, you missed the javadoc change that
left the code in an inconsistent state. I did not think you would
be offended by this. I am sorry.
>
>> Text-based exchanges on a mailing list
>> lack tone, gesture, behavior that help understand the state of mind
>> of the peer with which we discuss.
> This is all the more reason to be careful about one's actions. Minimal
> respect for other team members should refrain from deleting their work,
> even if the usefulness is dubious.
>
>> I have met both of you
>> personally; I appreciate both of you. I know for sure that we go
>> forward much efficiently when we cool down than when we argue on
>> personal or behavioral ground.
> I agree; thank you for those appeasing words.
>
>
> Best regards,
> Gilles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] Complex division
Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
Hello Luc.
> >>>[...]
> >>>>The mathematical question is do we view our class as representing
> >>>>the extended complex numbers. If we agree that the answer to that
> >>>>question is yes,
> >>>If you say "no", then my understanding is that the "Complex" class does not
> >>>represent the complex number concept, unless *all* operation that encounter
> >>>infinities result in "undefined behaviour" (i.e. return NaN).
> >>
> >>Not necessarily. The Complex field does not include any "point at
> >>infinity." There is a topological space that can be formed from the
> >>Complex numbers by adding a point at infinity and extending
> >>functions to include that point. This is what is sometimes called
> >>the extended complex numbers and a common topology for the space is
> >>represented by the Riemann Sphere. It is not obvious to me that it
> >>is best for us to try to model this (sorry to repeat myself, but
> >>this is the key point). If you really want to be *consistent* and
> >>insist that it is a *bug* to return NaN for division by complex
> >>zero, then you are insisting that we adopt this view. To be
> >>consistent in that view, we need to change equals, all arithmetic
> >>operations, and the exponential and trig functions as well. Our
> >>implementations of those functions are based loosely on C99x, which
> >>does not consistently represent the compactified space.
> >
> >No, I'm not insisting that we adopt one or the other view. I'm insisting
> >that by having an "INF", it looks like the class represents the extended
> >complex numbers. In which case, it is a bug.
> >My main point is to not treat only _selected_ infinities as equal, but
> >either not treat any infinities at all (complex field; doing as if Java
> >did not provide "Double.POSITIVE_INFINITY") or treat them _all_ to be equal
> >(compactified sphere; consistency with Java "double"; self-consistency).
> >
> >>>>The added "isZero" attribute is part of the performance
> >>>>hit.
> >>>Really? How much? What tests? Can I emit the possibility that testing a
> >>>"boolean" might be a tiny bit faster than testing equality with "0.0"
> >>>twice?
> >>
> >>The hit is in the constructor, where every complex instance has to
> >>run the code to set the property.
> >>>
> >>>>This, btw, is yet another reason to separate commits.
> >>>OK, I take this as: You would have only "cleanly reverted" the Javadoc
> >>>change, if it would have been separate. I'll thus commit back the rest.
> >>
> >>Please do not add back the extra property.
> >
> >If performance is so central that you can't suffer an additional flag, we
> >should *seriously* consider dropping the other two flags "isNaN" and
> >"isInfinite" and let the computational formulae do their work: In most
> >use cases, the result will be correct (at least, as correct as returning NaN
> >for division by zero) and the performance will be *greatly* enhanced
> >(comparing to the cost of my additional flag which you seem to consider as
> >the straw that broke the camel's back).
>
> I'm on the fence on this. I like both specific handling on
> infinities and NaN, and performances. In fact, I would very much
> like to have a complex primitive type directly supported by the
> language and following C99 conventions, but it does not seem to
> happen anytime.
>
> In the recent changes in [math], we have introduced several features
> to deal with infinities and NaNs, so I guess our current focus is
> towards completeness and the extended Complex set is the more
> consistent with this.
I'd just like to remind, after all the fuss, that the crux of the matter
(leaving aside the additional flag issue) was to replace:
---CUT---
final double c = divisor.getReal();
final double d = divisor.getImaginary();
if (c == 0.0 && d == 0.0) {
return NaN;
}
---CUT---
with
---CUT---
final double c = divisor.getReal();
final double d = divisor.getImaginary();
if (c == 0.0 && d == 0.0) {
return (real == 0.0 && imaginary == 0.0) ? NaN : INF;
}
---CUT---
How this change could hurt existing users of "Complex" (and require a
"clean" revert and endless arguing) is beyond me. There was a test case
exercising the new behaviour and the old behaviour could be recovered easily
if, in the end, the unobvious/inconsistent behaviour was to be retained
(which would have entailed the addition in the Javadoc of a complete
explanation as to why it was decided to be so).
> >
> >Please explain the rationale behind your insistence for not fixing this tiny
> >issue (I don't mean going for complete consistency with the "compactified"
> >view but just return INF for division by zero) on the basis of performance
> >but find it nice to have dozens of unnecessary checks (because they are
> >useful only for limiting cases similar to division by zero).
> >
> >Let me add that I find quite rude your indiscriminate reverting of my
> >work. Whatever criticism you have with my additions in the "main" area, that
> >did not mean that you could erase the changes in the "test" area.
> >As for your rule with "-1 a commit" I maintain that it was not warranted
> >here, where you could simply remind me to change what had to be, without
> >touching the rest. That would just mean being polite. There are recent
> >examples where changes were made without a JIRA issue and without discussion
> >here; what would you say if I were to go and revert those just because there
> >is such a rule?
> >I would also be glad to read the opinion of others on this administrative
> >question.
>
> Please, don't overreact on this, both of you.
>
> All of us, Gilles, Phil, Bill, Mikkel, Greg, Sébastien, Ted, Dietmar
> and others are trying to have a good math library. All of us have
> different goals, different main topics of interest and different
> views. There are far more things we share than things we disagree
> upon and we should focus on these commons things.
>
> *Nobody* should take a different view, or a criticism, or even a -1
> as a personal aggression.
I took it so because I've never seen such a thing occur for anyone else.
Was there a security breach that warranted the urgent deletion?
> Text-based exchanges on a mailing list
> lack tone, gesture, behavior that help understand the state of mind
> of the peer with which we discuss.
This is all the more reason to be careful about one's actions. Minimal
respect for other team members should refrain from deleting their work,
even if the usefulness is dubious.
> I have met both of you
> personally; I appreciate both of you. I know for sure that we go
> forward much efficiently when we cool down than when we argue on
> personal or behavioral ground.
I agree; thank you for those appeasing words.
Best regards,
Gilles
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] Complex division
Posted by Phil Steitz <ph...@gmail.com>.
On 9/4/11 4:50 AM, Luc Maisonobe wrote:
> Hi Gilles,
>
> Le 04/09/2011 12:28, Gilles Sadowski a écrit :
>>>> [...]
>>>>> The mathematical question is do we view our class as representing
>>>>> the extended complex numbers. If we agree that the answer to
>>>>> that
>>>>> question is yes,
>>>> If you say "no", then my understanding is that the "Complex"
>>>> class does not
>>>> represent the complex number concept, unless *all* operation
>>>> that encounter
>>>> infinities result in "undefined behaviour" (i.e. return NaN).
>>>
>>> Not necessarily. The Complex field does not include any "point at
>>> infinity." There is a topological space that can be formed from
>>> the
>>> Complex numbers by adding a point at infinity and extending
>>> functions to include that point. This is what is sometimes called
>>> the extended complex numbers and a common topology for the space is
>>> represented by the Riemann Sphere. It is not obvious to me that it
>>> is best for us to try to model this (sorry to repeat myself, but
>>> this is the key point). If you really want to be *consistent* and
>>> insist that it is a *bug* to return NaN for division by complex
>>> zero, then you are insisting that we adopt this view. To be
>>> consistent in that view, we need to change equals, all arithmetic
>>> operations, and the exponential and trig functions as well. Our
>>> implementations of those functions are based loosely on C99x, which
>>> does not consistently represent the compactified space.
>>
>> No, I'm not insisting that we adopt one or the other view. I'm
>> insisting
>> that by having an "INF", it looks like the class represents the
>> extended
>> complex numbers. In which case, it is a bug.
>> My main point is to not treat only _selected_ infinities as
>> equal, but
>> either not treat any infinities at all (complex field; doing as
>> if Java
>> did not provide "Double.POSITIVE_INFINITY") or treat them _all_
>> to be equal
>> (compactified sphere; consistency with Java "double";
>> self-consistency).
>>
>>>>> The added "isZero" attribute is part of the performance
>>>>> hit.
>>>> Really? How much? What tests? Can I emit the possibility that
>>>> testing a
>>>> "boolean" might be a tiny bit faster than testing equality with
>>>> "0.0"
>>>> twice?
>>>
>>> The hit is in the constructor, where every complex instance has to
>>> run the code to set the property.
>>>>
>>>>> This, btw, is yet another reason to separate commits.
>>>> OK, I take this as: You would have only "cleanly reverted" the
>>>> Javadoc
>>>> change, if it would have been separate. I'll thus commit back
>>>> the rest.
>>>
>>> Please do not add back the extra property.
>>
>> If performance is so central that you can't suffer an additional
>> flag, we
>> should *seriously* consider dropping the other two flags "isNaN" and
>> "isInfinite" and let the computational formulae do their work: In
>> most
>> use cases, the result will be correct (at least, as correct as
>> returning NaN
>> for division by zero) and the performance will be *greatly* enhanced
>> (comparing to the cost of my additional flag which you seem to
>> consider as
>> the straw that broke the camel's back).
>
> I'm on the fence on this. I like both specific handling on
> infinities and NaN, and performances. In fact, I would very much
> like to have a complex primitive type directly supported by the
> language and following C99 conventions, but it does not seem to
> happen anytime.
>
> In the recent changes in [math], we have introduced several
> features to deal with infinities and NaNs, so I guess our current
> focus is towards completeness and the extended Complex set is the
> more consistent with this.
I am not so sure this is the best path and I am now wondering
whether it may be best to revert to the "use simple computational
formulas and let the chips fall where they may" approach that we
used to have. The reason for this is that when you peel the onion,
you find a whole lot of changes necessary to try to model the
compactified space with any kind of mathematical reasonableness.
Also, as Gilles points out, we have already added a fair amount of
ad hoc stuff that has a performance cost. Finally, C99x does not
do really do this and I worry about apps that really do want to
maintain distinct infinities. Its too bad we don't have more vocal
users who actually use this class in applications or any of the
contributors to C99x who can chime in here.
I know the new C++ spec was just ratified and I am not sure what the
status of Annex G ended up there. When I last checked, it had not
been accepted as a standard yet and it was not universally loved.
Does anyone know? Here is a public link to a fairly recent draft
[1]. There is also a fair amount of publicly available commentary
(e.g. [2], [3], [4]). The draft spec is a little vague, but if you
read the sample code, it looks like the intent for z/0 is to return
a signed infinity (so my recollection that they are not really
"simply" modelling the Riemann sphere is correct). There are some
(apparently) strange treatments of NaNs as well - "recovering"
infinities from them and collapsing some values onto inf + infi.
The discussion in [2] brings out a little of the futility of trying
to maintain complete mathematical consistency when implementing
Complex functions in finite value spaces. This is what led me to
the conclusion back in the 1.x days that it would be best to just
stick with simple formulas and document clearly exactly what we compute.
I guess another option is to do what some C compilers do, which is
to enable some sort of "strict" compile time flag that could be
turned on for strict spec compliance and off for performance.
Another piece of research that we could do here is to look at what
gcc and python and other packages do. I did a comparison against R
and Colt before 1.1 [5], but I notice now that the current version
of R is a little less "NaN-happy."
Phil
[1] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1494.pdf
[2] http://drdobbs.com/cpp/184404993
[3] ftp://ftp.win.ua.ac.be/pub/preprints/03/criticism.pdf
[4] http://www-uxsup.csx.cam.ac.uk/courses/Arithmetic/paper_99.pdf
[5] http://wiki.apache.org/commons/math/1.1ReleasePlan
>
>>
>> Please explain the rationale behind your insistence for not
>> fixing this tiny
>> issue (I don't mean going for complete consistency with the
>> "compactified"
>> view but just return INF for division by zero) on the basis of
>> performance
>> but find it nice to have dozens of unnecessary checks (because
>> they are
>> useful only for limiting cases similar to division by zero).
>>
>> Let me add that I find quite rude your indiscriminate reverting
>> of my
>> work. Whatever criticism you have with my additions in the "main"
>> area, that
>> did not mean that you could erase the changes in the "test" area.
>> As for your rule with "-1 a commit" I maintain that it was not
>> warranted
>> here, where you could simply remind me to change what had to be,
>> without
>> touching the rest. That would just mean being polite. There are
>> recent
>> examples where changes were made without a JIRA issue and without
>> discussion
>> here; what would you say if I were to go and revert those just
>> because there
>> is such a rule?
>> I would also be glad to read the opinion of others on this
>> administrative
>> question.
>
> Please, don't overreact on this, both of you.
>
> All of us, Gilles, Phil, Bill, Mikkel, Greg, Sébastien, Ted,
> Dietmar and others are trying to have a good math library. All of
> us have different goals, different main topics of interest and
> different views. There are far more things we share than things we
> disagree upon and we should focus on these commons things.
>
> *Nobody* should take a different view, or a criticism, or even a
> -1 as a personal aggression. Text-based exchanges on a mailing
> list lack tone, gesture, behavior that help understand the state
> of mind of the peer with which we discuss. I have met both of you
> personally; I appreciate both of you. I know for sure that we go
> forward much efficiently when we cool down than when we argue on
> personal or behavioral ground.
>
> Luc
>
>>
>>>> [...]
>>
>> Gilles
>>
>> ---------------------------------------------------------------------
>>
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] Complex division
Posted by Luc Maisonobe <Lu...@free.fr>.
Hi Gilles,
Le 04/09/2011 12:28, Gilles Sadowski a écrit :
>>> [...]
>>>> The mathematical question is do we view our class as representing
>>>> the extended complex numbers. If we agree that the answer to that
>>>> question is yes,
>>> If you say "no", then my understanding is that the "Complex" class does not
>>> represent the complex number concept, unless *all* operation that encounter
>>> infinities result in "undefined behaviour" (i.e. return NaN).
>>
>> Not necessarily. The Complex field does not include any "point at
>> infinity." There is a topological space that can be formed from the
>> Complex numbers by adding a point at infinity and extending
>> functions to include that point. This is what is sometimes called
>> the extended complex numbers and a common topology for the space is
>> represented by the Riemann Sphere. It is not obvious to me that it
>> is best for us to try to model this (sorry to repeat myself, but
>> this is the key point). If you really want to be *consistent* and
>> insist that it is a *bug* to return NaN for division by complex
>> zero, then you are insisting that we adopt this view. To be
>> consistent in that view, we need to change equals, all arithmetic
>> operations, and the exponential and trig functions as well. Our
>> implementations of those functions are based loosely on C99x, which
>> does not consistently represent the compactified space.
>
> No, I'm not insisting that we adopt one or the other view. I'm insisting
> that by having an "INF", it looks like the class represents the extended
> complex numbers. In which case, it is a bug.
> My main point is to not treat only _selected_ infinities as equal, but
> either not treat any infinities at all (complex field; doing as if Java
> did not provide "Double.POSITIVE_INFINITY") or treat them _all_ to be equal
> (compactified sphere; consistency with Java "double"; self-consistency).
>
>>>> The added "isZero" attribute is part of the performance
>>>> hit.
>>> Really? How much? What tests? Can I emit the possibility that testing a
>>> "boolean" might be a tiny bit faster than testing equality with "0.0"
>>> twice?
>>
>> The hit is in the constructor, where every complex instance has to
>> run the code to set the property.
>>>
>>>> This, btw, is yet another reason to separate commits.
>>> OK, I take this as: You would have only "cleanly reverted" the Javadoc
>>> change, if it would have been separate. I'll thus commit back the rest.
>>
>> Please do not add back the extra property.
>
> If performance is so central that you can't suffer an additional flag, we
> should *seriously* consider dropping the other two flags "isNaN" and
> "isInfinite" and let the computational formulae do their work: In most
> use cases, the result will be correct (at least, as correct as returning NaN
> for division by zero) and the performance will be *greatly* enhanced
> (comparing to the cost of my additional flag which you seem to consider as
> the straw that broke the camel's back).
I'm on the fence on this. I like both specific handling on infinities
and NaN, and performances. In fact, I would very much like to have a
complex primitive type directly supported by the language and following
C99 conventions, but it does not seem to happen anytime.
In the recent changes in [math], we have introduced several features to
deal with infinities and NaNs, so I guess our current focus is towards
completeness and the extended Complex set is the more consistent with this.
>
> Please explain the rationale behind your insistence for not fixing this tiny
> issue (I don't mean going for complete consistency with the "compactified"
> view but just return INF for division by zero) on the basis of performance
> but find it nice to have dozens of unnecessary checks (because they are
> useful only for limiting cases similar to division by zero).
>
> Let me add that I find quite rude your indiscriminate reverting of my
> work. Whatever criticism you have with my additions in the "main" area, that
> did not mean that you could erase the changes in the "test" area.
> As for your rule with "-1 a commit" I maintain that it was not warranted
> here, where you could simply remind me to change what had to be, without
> touching the rest. That would just mean being polite. There are recent
> examples where changes were made without a JIRA issue and without discussion
> here; what would you say if I were to go and revert those just because there
> is such a rule?
> I would also be glad to read the opinion of others on this administrative
> question.
Please, don't overreact on this, both of you.
All of us, Gilles, Phil, Bill, Mikkel, Greg, Sébastien, Ted, Dietmar and
others are trying to have a good math library. All of us have different
goals, different main topics of interest and different views. There are
far more things we share than things we disagree upon and we should
focus on these commons things.
*Nobody* should take a different view, or a criticism, or even a -1 as a
personal aggression. Text-based exchanges on a mailing list lack tone,
gesture, behavior that help understand the state of mind of the peer
with which we discuss. I have met both of you personally; I appreciate
both of you. I know for sure that we go forward much efficiently when we
cool down than when we argue on personal or behavioral ground.
Luc
>
>>> [...]
>
> Gilles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] Complex division
Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
> > [...]
> >> The mathematical question is do we view our class as representing
> >> the extended complex numbers. If we agree that the answer to that
> >> question is yes,
> > If you say "no", then my understanding is that the "Complex" class does not
> > represent the complex number concept, unless *all* operation that encounter
> > infinities result in "undefined behaviour" (i.e. return NaN).
>
> Not necessarily. The Complex field does not include any "point at
> infinity." There is a topological space that can be formed from the
> Complex numbers by adding a point at infinity and extending
> functions to include that point. This is what is sometimes called
> the extended complex numbers and a common topology for the space is
> represented by the Riemann Sphere. It is not obvious to me that it
> is best for us to try to model this (sorry to repeat myself, but
> this is the key point). If you really want to be *consistent* and
> insist that it is a *bug* to return NaN for division by complex
> zero, then you are insisting that we adopt this view. To be
> consistent in that view, we need to change equals, all arithmetic
> operations, and the exponential and trig functions as well. Our
> implementations of those functions are based loosely on C99x, which
> does not consistently represent the compactified space.
No, I'm not insisting that we adopt one or the other view. I'm insisting
that by having an "INF", it looks like the class represents the extended
complex numbers. In which case, it is a bug.
My main point is to not treat only _selected_ infinities as equal, but
either not treat any infinities at all (complex field; doing as if Java
did not provide "Double.POSITIVE_INFINITY") or treat them _all_ to be equal
(compactified sphere; consistency with Java "double"; self-consistency).
> >> The added "isZero" attribute is part of the performance
> >> hit.
> > Really? How much? What tests? Can I emit the possibility that testing a
> > "boolean" might be a tiny bit faster than testing equality with "0.0"
> > twice?
>
> The hit is in the constructor, where every complex instance has to
> run the code to set the property.
> >
> >> This, btw, is yet another reason to separate commits.
> > OK, I take this as: You would have only "cleanly reverted" the Javadoc
> > change, if it would have been separate. I'll thus commit back the rest.
>
> Please do not add back the extra property.
If performance is so central that you can't suffer an additional flag, we
should *seriously* consider dropping the other two flags "isNaN" and
"isInfinite" and let the computational formulae do their work: In most
use cases, the result will be correct (at least, as correct as returning NaN
for division by zero) and the performance will be *greatly* enhanced
(comparing to the cost of my additional flag which you seem to consider as
the straw that broke the camel's back).
Please explain the rationale behind your insistence for not fixing this tiny
issue (I don't mean going for complete consistency with the "compactified"
view but just return INF for division by zero) on the basis of performance
but find it nice to have dozens of unnecessary checks (because they are
useful only for limiting cases similar to division by zero).
Let me add that I find quite rude your indiscriminate reverting of my
work. Whatever criticism you have with my additions in the "main" area, that
did not mean that you could erase the changes in the "test" area.
As for your rule with "-1 a commit" I maintain that it was not warranted
here, where you could simply remind me to change what had to be, without
touching the rest. That would just mean being polite. There are recent
examples where changes were made without a JIRA issue and without discussion
here; what would you say if I were to go and revert those just because there
is such a rule?
I would also be glad to read the opinion of others on this administrative
question.
> > [...]
Gilles
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] Complex division
Posted by Phil Steitz <ph...@gmail.com>.
On 9/3/11 5:06 PM, Gilles Sadowski wrote:
>> The problem is that it is not obvious that INF is "the right answer."
> The real problem is *inconsistency*.
> The current code chooses to consider a point at infinity for some situations
> but not for others. It is thus quite understandable that people are
> wondering what is going on with some limiting cases, like using infinities:
> They assume something to understand one result, and the opposite assumption
> must be made to understand another.
>
> You are making the same kind of argument as for "RegulaFalsiSolver" which
> boils down to "The Javadoc says so and so, and the code is good enough for
> me."
> As Sebb (IIRC) pointed out in another discussion, when unobvious results
> are returned, their documentation should mention the rationale that led to
> the chosen behaviour, because this
> ---
> If {@code divisor} equals {@link #ZERO}, {@link #NaN} is returned.
> ---
> simply looks wrong, unless you are going to maintain that it is perfectly
> reasonable and completely obvious that this test:
> -----
> final double rAsComplex = Complex.ONE.divide(Complex.ZERO).getReal();
> final double rAsDouble = 1d / 0d;
> Assert.assertEquals(rAsComplex, rAsDouble, 0);
> -----
> should fail.
>
> I maintain that this is an obvious and trivial *bug*. And, however happy the
> current users of the class are, it should be fixed.
>
>>> Maybe that we can _decide_ that any manipulation of a "Complex" instance
>>> containing infinities is mildly meaningless (in the applications where CM
>>> is used) and return NaN for any operation involving them (?). That would
>>> probably simplify several methods (and make them more efficient). Unless I'm
>>> mistaken that would just cost a comment like
>>> "Manipulating instances with infinities will result in undefined results."
>> That is a defensible view. See comments below.
> This at least is *consistent*, saying that
> "We don't handle infinities. Period."
> while the current code is confusing.
>
> Once again, a user is asking for information about a strange behaviour, and
> you insist that he justifies further his request. His issue could be just
> that: Inconsistency.
>
> Now, if the justification is efficiency. Then why not go for it, and just
> not care for infinities, checking for NaN, and tell it explicitly:
> "We don't handle infinities because in most use cases, the efficiency cost
> is not worth it."
>
>>>>> I don't think that this one change can have a discernible performance impact.
>>>>> It might not be necessary to map all {{Complex}} instances that have an infinite component to a single object. I pointed it as a convenient justification for fixing a bug
>>>> Not so clear it is a "bug" - the only way to characterize it as such
>>>> is to model the space as compactified.
>>> As you say yourself below, having an INF is to assume that the "Complex"
>>> class represents elements from C U {"point at infinity"}. At least that's
>>> how I interpret it.
>>> Had there not be a special handling of instances that have an infinity in
>>> their real or imaginary part, I'd say that the NaN result would be normal,
>>> as the output of the computational formulae.
>>> But this would entail to let operations produce their expected results,
>>> which is not the case with "z.multiply(z)", as reported by Arne:
>>> https://issues.apache.org/jira/browse/MATH-620?focusedCommentId=13096432&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13096432
>>>
>>>> I notice now that multiply sort of behaves this way, and as I said
>>>> on the ticket, we have already defined "INF" so an argument could be
>>>> made that we are partly there already. I would like to understand
>>>> the practical arguments pro and con - and by "practical" I mean
>>>> examples of how the proposed change and any others impact actual
>>>> uses of the class in applications. I have reviewed my own
>>>> applications and for those, there is no immediate impact (other than
>>>> performance hit in division and complex construction),
>>> Did you measure it?
>>> Are you sure that performance is not _improved_ for division? :-)
>>>
>>>> but I worry a
>>>> little about losing the ability to represent directed infinities if
>>>> we decide to really aim for "consistency" here.
>>> What are the use-cases for those?
>>> When looking for references, I only stumbled on the usefulness of _one_
>>> "point at infinity".
>> When a sequence of iterates diverges in modulus to infinity, it
>> might in some cases be useful to know that the divergence was along
>> a specific vector, like for example the real or imaginary axis. I
>> have - almost - needed this in applications that track orbits of
>> points under iterated functions, but I don't have a specific
>> application use case for this personally.
>>>> I guess we could
>>>> retain directed infinities by adding a directed INF with an argument
>>>> attribute, but that would again add overhead to several operations.
>>> If you have applications that deal with any "directed" infinities, don't you
>>> need polar coordinates too? That seems to be missing in class Complex
>>> (talking about new API...).
>>> Then, would the "argument attribute" be the angle?
>> Yes, the argument would effectively be the angle.
>>>> At this point, I would like to see r1164756 reverted until we have
>>>> agreed on this change.
>>> Well, that is done. And, IMHO, there is an identified bug (or at least
>>> an inconsistency worth removing) there. I would like to see use cases that
>>> justify keeping the inconsistency. A mathematical explanation will do too
>>> ;-).
>> The mathematical question is do we view our class as representing
>> the extended complex numbers. If we agree that the answer to that
>> question is yes,
> If you say "no", then my understanding is that the "Complex" class does not
> represent the complex number concept, unless *all* operation that encounter
> infinities result in "undefined behaviour" (i.e. return NaN).
Not necessarily. The Complex field does not include any "point at
infinity." There is a topological space that can be formed from the
Complex numbers by adding a point at infinity and extending
functions to include that point. This is what is sometimes called
the extended complex numbers and a common topology for the space is
represented by the Riemann Sphere. It is not obvious to me that it
is best for us to try to model this (sorry to repeat myself, but
this is the key point). If you really want to be *consistent* and
insist that it is a *bug* to return NaN for division by complex
zero, then you are insisting that we adopt this view. To be
consistent in that view, we need to change equals, all arithmetic
operations, and the exponential and trig functions as well. Our
implementations of those functions are based loosely on C99x, which
does not consistently represent the compactified space.
> As that would arguably be considered not backward-compatible, that leaves
> only "yes" as the answer.
>
>> then "the right answer" for the one division
>> instance being considered here is to return INF. If we don't, then
>> NaN is a better answer. If we agree yes, then we should also modify
>> equals and there are likely other changes required to other
>> arithmetic operations.
> That would certainly be more consistent with how a "double" represent a real
> number. At which point I'm repeating that you chose to do so in MATH-164; so
> why would it be different now?
> The code is inconsistent and, judging how MATH-164 was resolved and you want
> to resolve this issue, the CM's decision-making process seems to be also.
>
>> IIRC, we tried to find a compromise between efficiency, ease of
>> understanding the javadoc, C99x compliance and mathematical
>> correctness when defining the contracts for the complex arithmetic
>> operations that are documented in the javadoc now. We could fiddle
>> with these contracts endlessly and add lots more ad hoc tests and
>> attributes to try to make them "more correct" or "consistent with X"
>> where X can be defined variously as "the way Doubles work", "IEEE
>> Floating Point specs," "C specs" or your favorite other package.
>> Given that changes carry a cost for all users of the current code, I
>> think the onus is on those who want to make changes to explain in
>> practical terms why the proposed change is worth making. I don't
>> (yet) see this one as worth making. What would be really great
>> would be some input from users who can provide examples why
>> different contracts would be more (or less) useful in applications.
> I'm talking about self-consistency. That could mean: Avoid contradicting
> behaviours that need confusing documentation.
Sorry, I disagree. I personally don't think it is possible to have
complete "consistency" in the way that you seem to want. I am sure
you could find "inconsistency" in the C99x spec or pretty much any
implementation, even after convoluting the javadoc and killing
performance. If others agree with your view, then we can change the
contracts and implementation. But I really would like to know what
the practical reason is.
>
>>>
>>> Thanks,
>>> Gilles
>>>
>>> P.S. I've just seen that you completely removed changes that I find useful
>>> _independently_ of the decision to change or not the behaviour of
>>> division by zero:
>>> * factoring out multiple tests into separate test methods,
>>> * keeping track of test cases that correspond to an issue, and
>>> * using a flag "isZero" in the "divide" method.
>>> Thus, they were left on purpose, as supposed enhancements similar to
>>> those which several people commit informally from time to time.
>>> Is it customary to pull the rug out from under someone's feet?
>> I asked that the commit be reverted.
> The change of behaviour was reverted; I just forgot to change back the
> Javadoc accordingly.
>
>> I just completed the reversion
>> because I saw that the javadoc contract change had not been
>> reverted. I just used svn merge with revision numbers to do a clean
>> revert.
> Why was a "clean revert" necessary?
> My changes were not a mistake, to be treated as they never occurred.
> Could I respectfully request that you let the concerned people do the
> cleanup instead of forcefully (pardon, "cleanly") erase their work?
Here is how it works. Any committer can -1 a commit. When that
happens, the commit gets reverted. To do that, it is easiest to
just use svn merge with revision numbers. I just completed the
reversion.
>> The added "isZero" attribute is part of the performance
>> hit.
> Really? How much? What tests? Can I emit the possibility that testing a
> "boolean" might be a tiny bit faster than testing equality with "0.0" twice?
The hit is in the constructor, where every complex instance has to
run the code to set the property.
>
>> This, btw, is yet another reason to separate commits.
> OK, I take this as: You would have only "cleanly reverted" the Javadoc
> change, if it would have been separate. I'll thus commit back the rest.
Please do not add back the extra property.
Phil
>
>
> Gilles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] Complex division
Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
>
> The problem is that it is not obvious that INF is "the right answer."
The real problem is *inconsistency*.
The current code chooses to consider a point at infinity for some situations
but not for others. It is thus quite understandable that people are
wondering what is going on with some limiting cases, like using infinities:
They assume something to understand one result, and the opposite assumption
must be made to understand another.
You are making the same kind of argument as for "RegulaFalsiSolver" which
boils down to "The Javadoc says so and so, and the code is good enough for
me."
As Sebb (IIRC) pointed out in another discussion, when unobvious results
are returned, their documentation should mention the rationale that led to
the chosen behaviour, because this
---
If {@code divisor} equals {@link #ZERO}, {@link #NaN} is returned.
---
simply looks wrong, unless you are going to maintain that it is perfectly
reasonable and completely obvious that this test:
-----
final double rAsComplex = Complex.ONE.divide(Complex.ZERO).getReal();
final double rAsDouble = 1d / 0d;
Assert.assertEquals(rAsComplex, rAsDouble, 0);
-----
should fail.
I maintain that this is an obvious and trivial *bug*. And, however happy the
current users of the class are, it should be fixed.
> > Maybe that we can _decide_ that any manipulation of a "Complex" instance
> > containing infinities is mildly meaningless (in the applications where CM
> > is used) and return NaN for any operation involving them (?). That would
> > probably simplify several methods (and make them more efficient). Unless I'm
> > mistaken that would just cost a comment like
> > "Manipulating instances with infinities will result in undefined results."
>
> That is a defensible view. See comments below.
This at least is *consistent*, saying that
"We don't handle infinities. Period."
while the current code is confusing.
Once again, a user is asking for information about a strange behaviour, and
you insist that he justifies further his request. His issue could be just
that: Inconsistency.
Now, if the justification is efficiency. Then why not go for it, and just
not care for infinities, checking for NaN, and tell it explicitly:
"We don't handle infinities because in most use cases, the efficiency cost
is not worth it."
> >
> >>> I don't think that this one change can have a discernible performance impact.
> >>> It might not be necessary to map all {{Complex}} instances that have an infinite component to a single object. I pointed it as a convenient justification for fixing a bug
> >> Not so clear it is a "bug" - the only way to characterize it as such
> >> is to model the space as compactified.
> > As you say yourself below, having an INF is to assume that the "Complex"
> > class represents elements from C U {"point at infinity"}. At least that's
> > how I interpret it.
> > Had there not be a special handling of instances that have an infinity in
> > their real or imaginary part, I'd say that the NaN result would be normal,
> > as the output of the computational formulae.
> > But this would entail to let operations produce their expected results,
> > which is not the case with "z.multiply(z)", as reported by Arne:
> > https://issues.apache.org/jira/browse/MATH-620?focusedCommentId=13096432&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13096432
> >
> >> I notice now that multiply sort of behaves this way, and as I said
> >> on the ticket, we have already defined "INF" so an argument could be
> >> made that we are partly there already. I would like to understand
> >> the practical arguments pro and con - and by "practical" I mean
> >> examples of how the proposed change and any others impact actual
> >> uses of the class in applications. I have reviewed my own
> >> applications and for those, there is no immediate impact (other than
> >> performance hit in division and complex construction),
> > Did you measure it?
> > Are you sure that performance is not _improved_ for division? :-)
> >
> >> but I worry a
> >> little about losing the ability to represent directed infinities if
> >> we decide to really aim for "consistency" here.
> > What are the use-cases for those?
> > When looking for references, I only stumbled on the usefulness of _one_
> > "point at infinity".
>
> When a sequence of iterates diverges in modulus to infinity, it
> might in some cases be useful to know that the divergence was along
> a specific vector, like for example the real or imaginary axis. I
> have - almost - needed this in applications that track orbits of
> points under iterated functions, but I don't have a specific
> application use case for this personally.
> >
> >> I guess we could
> >> retain directed infinities by adding a directed INF with an argument
> >> attribute, but that would again add overhead to several operations.
> > If you have applications that deal with any "directed" infinities, don't you
> > need polar coordinates too? That seems to be missing in class Complex
> > (talking about new API...).
> > Then, would the "argument attribute" be the angle?
>
> Yes, the argument would effectively be the angle.
> >
> >> At this point, I would like to see r1164756 reverted until we have
> >> agreed on this change.
> > Well, that is done. And, IMHO, there is an identified bug (or at least
> > an inconsistency worth removing) there. I would like to see use cases that
> > justify keeping the inconsistency. A mathematical explanation will do too
> > ;-).
>
> The mathematical question is do we view our class as representing
> the extended complex numbers. If we agree that the answer to that
> question is yes,
If you say "no", then my understanding is that the "Complex" class does not
represent the complex number concept, unless *all* operation that encounter
infinities result in "undefined behaviour" (i.e. return NaN).
As that would arguably be considered not backward-compatible, that leaves
only "yes" as the answer.
> then "the right answer" for the one division
> instance being considered here is to return INF. If we don't, then
> NaN is a better answer. If we agree yes, then we should also modify
> equals and there are likely other changes required to other
> arithmetic operations.
That would certainly be more consistent with how a "double" represent a real
number. At which point I'm repeating that you chose to do so in MATH-164; so
why would it be different now?
The code is inconsistent and, judging how MATH-164 was resolved and you want
to resolve this issue, the CM's decision-making process seems to be also.
> IIRC, we tried to find a compromise between efficiency, ease of
> understanding the javadoc, C99x compliance and mathematical
> correctness when defining the contracts for the complex arithmetic
> operations that are documented in the javadoc now. We could fiddle
> with these contracts endlessly and add lots more ad hoc tests and
> attributes to try to make them "more correct" or "consistent with X"
> where X can be defined variously as "the way Doubles work", "IEEE
> Floating Point specs," "C specs" or your favorite other package.
> Given that changes carry a cost for all users of the current code, I
> think the onus is on those who want to make changes to explain in
> practical terms why the proposed change is worth making. I don't
> (yet) see this one as worth making. What would be really great
> would be some input from users who can provide examples why
> different contracts would be more (or less) useful in applications.
I'm talking about self-consistency. That could mean: Avoid contradicting
behaviours that need confusing documentation.
>
> >
> >
> > Thanks,
> > Gilles
> >
> > P.S. I've just seen that you completely removed changes that I find useful
> > _independently_ of the decision to change or not the behaviour of
> > division by zero:
> > * factoring out multiple tests into separate test methods,
> > * keeping track of test cases that correspond to an issue, and
> > * using a flag "isZero" in the "divide" method.
> > Thus, they were left on purpose, as supposed enhancements similar to
> > those which several people commit informally from time to time.
> > Is it customary to pull the rug out from under someone's feet?
>
> I asked that the commit be reverted.
The change of behaviour was reverted; I just forgot to change back the
Javadoc accordingly.
> I just completed the reversion
> because I saw that the javadoc contract change had not been
> reverted. I just used svn merge with revision numbers to do a clean
> revert.
Why was a "clean revert" necessary?
My changes were not a mistake, to be treated as they never occurred.
Could I respectfully request that you let the concerned people do the
cleanup instead of forcefully (pardon, "cleanly") erase their work?
> The added "isZero" attribute is part of the performance
> hit.
Really? How much? What tests? Can I emit the possibility that testing a
"boolean" might be a tiny bit faster than testing equality with "0.0" twice?
> This, btw, is yet another reason to separate commits.
OK, I take this as: You would have only "cleanly reverted" the Javadoc
change, if it would have been separate. I'll thus commit back the rest.
Gilles
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] Complex division
Posted by Phil Steitz <ph...@gmail.com>.
On 9/3/11 2:17 PM, Gilles Sadowski wrote:
> On Sat, Sep 03, 2011 at 08:10:59AM -0700, Phil Steitz wrote:
>> On 9/3/11 2:30 AM, Gilles (JIRA) wrote:
>>> [ https://issues.apache.org/jira/browse/MATH-657?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13096621#comment-13096621 ]
>>>
>>> Gilles commented on MATH-657:
>>> -----------------------------
>>>
>>> I've just posted a mail on "dev".
>> Should be discussed on the dev list.
> That's why I posted the mail referred to above...
>
>> We should not be trying to
>> have discussions on API changes on JIRA tickets. That is not what
>> JIRA is for.
> Hmm, I thought I was doing the right thing by following the example of
> https://issues.apache.org/jira/browse/MATH-164
>
> By the way, it shows that following a older dicussion on JIRA is much more
> convenient than hopping from one post to another on ML archive, with the
> myriad of quotes, double-quotes, triple-quotes, ...
>
>> It is an unwritten (well, probably is actually written
>> down somewhere by now) rule @apache that if a decision "did not
>> happen on the dev list, then it did not happen." We should be
>> talking about API design issues on this list, not opening JIRAs each
>> time we think an API should be changed and trying to have the
>> discussion on the JIRA ticket.
> Sorry if I broke an old and venerable rule. It was not the intention;
> for me, it was just solving a trivial bug in the same manner I did already
> before, and not a unilateral decision to "change the API".
>
>>> IMO, the main argument is consistency. Also with how reals (i.e. {{double}}) work; IIUC, MATH-164 triggered a change for that same reason.
>>>
>>> Arne Plöse is a user and [reported|MATH-620] that the previous behaviour was not fine for him.
>> What exactly was the practical problem? Arne, care to elaborate?
> Not wanting to answer for Arne; just my own two cents: Why not give the
> right answer?
The problem is that it is not obvious that INF is "the right answer."
> Maybe that we can _decide_ that any manipulation of a "Complex" instance
> containing infinities is mildly meaningless (in the applications where CM
> is used) and return NaN for any operation involving them (?). That would
> probably simplify several methods (and make them more efficient). Unless I'm
> mistaken that would just cost a comment like
> "Manipulating instances with infinities will result in undefined results."
That is a defensible view. See comments below.
>
>>> I don't think that this one change can have a discernible performance impact.
>>> It might not be necessary to map all {{Complex}} instances that have an infinite component to a single object. I pointed it as a convenient justification for fixing a bug
>> Not so clear it is a "bug" - the only way to characterize it as such
>> is to model the space as compactified.
> As you say yourself below, having an INF is to assume that the "Complex"
> class represents elements from C U {"point at infinity"}. At least that's
> how I interpret it.
> Had there not be a special handling of instances that have an infinity in
> their real or imaginary part, I'd say that the NaN result would be normal,
> as the output of the computational formulae.
> But this would entail to let operations produce their expected results,
> which is not the case with "z.multiply(z)", as reported by Arne:
> https://issues.apache.org/jira/browse/MATH-620?focusedCommentId=13096432&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13096432
>
>> I notice now that multiply sort of behaves this way, and as I said
>> on the ticket, we have already defined "INF" so an argument could be
>> made that we are partly there already. I would like to understand
>> the practical arguments pro and con - and by "practical" I mean
>> examples of how the proposed change and any others impact actual
>> uses of the class in applications. I have reviewed my own
>> applications and for those, there is no immediate impact (other than
>> performance hit in division and complex construction),
> Did you measure it?
> Are you sure that performance is not _improved_ for division? :-)
>
>> but I worry a
>> little about losing the ability to represent directed infinities if
>> we decide to really aim for "consistency" here.
> What are the use-cases for those?
> When looking for references, I only stumbled on the usefulness of _one_
> "point at infinity".
When a sequence of iterates diverges in modulus to infinity, it
might in some cases be useful to know that the divergence was along
a specific vector, like for example the real or imaginary axis. I
have - almost - needed this in applications that track orbits of
points under iterated functions, but I don't have a specific
application use case for this personally.
>
>> I guess we could
>> retain directed infinities by adding a directed INF with an argument
>> attribute, but that would again add overhead to several operations.
> If you have applications that deal with any "directed" infinities, don't you
> need polar coordinates too? That seems to be missing in class Complex
> (talking about new API...).
> Then, would the "argument attribute" be the angle?
Yes, the argument would effectively be the angle.
>
>> At this point, I would like to see r1164756 reverted until we have
>> agreed on this change.
> Well, that is done. And, IMHO, there is an identified bug (or at least
> an inconsistency worth removing) there. I would like to see use cases that
> justify keeping the inconsistency. A mathematical explanation will do too
> ;-).
The mathematical question is do we view our class as representing
the extended complex numbers. If we agree that the answer to that
question is yes, then "the right answer" for the one division
instance being considered here is to return INF. If we don't, then
NaN is a better answer. If we agree yes, then we should also modify
equals and there are likely other changes required to other
arithmetic operations.
IIRC, we tried to find a compromise between efficiency, ease of
understanding the javadoc, C99x compliance and mathematical
correctness when defining the contracts for the complex arithmetic
operations that are documented in the javadoc now. We could fiddle
with these contracts endlessly and add lots more ad hoc tests and
attributes to try to make them "more correct" or "consistent with X"
where X can be defined variously as "the way Doubles work", "IEEE
Floating Point specs," "C specs" or your favorite other package.
Given that changes carry a cost for all users of the current code, I
think the onus is on those who want to make changes to explain in
practical terms why the proposed change is worth making. I don't
(yet) see this one as worth making. What would be really great
would be some input from users who can provide examples why
different contracts would be more (or less) useful in applications.
>
>
> Thanks,
> Gilles
>
> P.S. I've just seen that you completely removed changes that I find useful
> _independently_ of the decision to change or not the behaviour of
> division by zero:
> * factoring out multiple tests into separate test methods,
> * keeping track of test cases that correspond to an issue, and
> * using a flag "isZero" in the "divide" method.
> Thus, they were left on purpose, as supposed enhancements similar to
> those which several people commit informally from time to time.
> Is it customary to pull the rug out from under someone's feet?
I asked that the commit be reverted. I just completed the reversion
because I saw that the javadoc contract change had not been
reverted. I just used svn merge with revision numbers to do a clean
revert. The added "isZero" attribute is part of the performance
hit. This, btw, is yet another reason to separate commits.
Phil
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org