Java 7 features

P

Patricia Shanahan

Twisted said:
....
Finally, please stop attacking every post I write, even with "civil"
but critical replies. I have done nothing to deserve such treatment.

I have a degree in mathematics, have worked as a compiler writer, and
spent many years dealing with the vagaries of floating point arithmetic,
especially in conjunction with linear algebra, including issues of what
transformations a compiler can and cannot do without upsetting the end
users. I have programmed in a wide range of languages, including
languages that have data types and operators Java does not support.

You have posted, in an open discussion group, articles in the
intersection between mathematics, programming language design, and
floating point arithmetic. That combination of subjects, given my
background, inevitably interests me.

That is quite enough to "deserve" follow-up articles from me expressing
my opinions where they differ from what you wrote.

This is the last meta-article I will post in this thread, so you can get
the last word and "win" the meta-discussion by a single reply to this
article.

I will continue to write technical articles in the Java 7 features
thread whenever I think I have something to contribute to the
discussion.

Patricia
 
T

Twisted

That is quite enough to "deserve" follow-up articles from me expressing
my opinions where they differ from what you wrote.

I think what bothers me is when it gets into nit-picking territory. In
particular, we're discussing operator overloading translating in a
well-defined, well-specified way into specific method calls.
Particular calling code, plus the same methods implemented with
semantically-identical code on the relevant data types, would behave
consistently across all compliant javacs and JVMs, and you could
always boil it down eventually to IEEE semantics. And use strictfp if
you really felt it necessary. For most situations getting an answer
bracketed to within a certain distance of the exact ideal answer will
suffice.

You might be interested in the JScience third-party library. http://jscience.org/
is the main Web site. There is a "Real" class that represents an error-
bracketed real number, and if the start of a calculation uses
approximations whose error range is known to contain the exact ideal
input value, the output will be a Real object whose error range
contains the exact ideal output value. Of course if the algorithm is
numerically unstable or just very long that error range could be much
wider than the input range, or a NaN might emerge -- meaning that
subtle algorithm problems like that even get exposed. The cost is
speed, as under the hood every operation is actually done on each of
TWO parallel bignums.

As an example, it represents 8 +/- 2 internally as the interval [6,
10]. Add this to 5 +/- 1 or [4, 6] and it gets [10, 16], or 13 +/- 3.
(A Gaussian error version would be nice, where independent errors sum
to the square root of the sum of the squares, admittedly, but that
breaks the guarantee that the genuine answer is somewhere in the
output range and gives you instead a percent confidence; this sort of
error summing is nonetheless quite common in my experience in
engineering and science.)

Some operations end up using FOUR parallel operations mind you -- as
it uses the internal interval endpoints in all four combinations of
low, low; low, high; high, low; and high, high instead of only low,
low and high, high or low, high and high, low in cases less
straightforward than ordinary addition or subtraction respectively.
This is even slower than just using BigDecimal-alikes and praying the
error hasn't grown too large. On the other hand unneeded precision
that is swamped by the known error magnitude is dropped for a
performance boost (it will use fewer mantissa bits to represent each
endpoint as the calculation progresses and the interval widens as a
percentage of value magnitude).

So, I think you might find JScience very interesting indeed if
scientific computation and really accurate numerics is your craving
here. :)
 
P

Patricia Shanahan

Twisted wrote:
....
You might be interested in the JScience third-party library. http://jscience.org/
is the main Web site. There is a "Real" class that represents an error-
bracketed real number, and if the start of a calculation uses
approximations whose error range is known to contain the exact ideal
input value, the output will be a Real object whose error range
contains the exact ideal output value. Of course if the algorithm is
numerically unstable or just very long that error range could be much
wider than the input range, or a NaN might emerge -- meaning that
subtle algorithm problems like that even get exposed. The cost is
speed, as under the hood every operation is actually done on each of
TWO parallel bignums.
....

I've played with interval arithmetic in the past, but without getting
useful results from it. It's an attractive idea because if it gives a
reasonable range you do have certainty of the infinite precision answer
being in the range.

Interval arithmetic can get an over-large range even if the algorithm is
very effective in practice with rounding. The interval arithmetic range
is from the answer that would be produced if every single rounding or
truncation error were in the direction that reduces the final answer to
the answer that would be produced if the all the errors increased it.

In practice, there may be no input to the algorithm that produces that
effect, or such inputs may be a vanishingly tiny subset of possible inputs.
(A Gaussian error version would be nice, where independent errors sum
to the square root of the sum of the squares, admittedly, but that
breaks the guarantee that the genuine answer is somewhere in the
output range and gives you instead a percent confidence; this sort of
error summing is nonetheless quite common in my experience in
engineering and science.)

Indeed. Much of numerical analysis is based on treating rounding and
truncation errors as random variables, and estimating probabilities of
the answer being wrong by more than a specified amount.

Incidentally, relative to the "Discussion of why java.lang.Number does
not implement Comparable" thread, do you think Interval should extend
Number?

Patricia
 
T

Twisted

Incidentally, relative to the "Discussion of why java.lang.Number does
not implement Comparable" thread, do you think Interval should extend
Number?

If it's meant to represent a number with error bars the answer would
have to be "maybe" or perhaps "it depends". :)

Making it Comparable is a definite issue. It's a "fuzzy number" and
perhaps it should really implement a FuzzyComparable, maybe contracted
to return an enum with values of DEFINITELY_LESS, MAYBE_THE_SAME, and
DEFINITELY_MORE, or just -1, 0, or 1 but with 0 understood not to
guarantee strict equality.

(I'd specify the return value to be -1, 0, or 1 in the latter case to
push people to write code like (foo < bar)?-1:((foo > bar)?1:0) and
not the sloppy foo - bar which is so tempting when implementing
Comparable but so susceptible to overflow bugs if the numerical type
is of limited range.)

A whole new set of classes might be best, rather than using many or
even any of the standard library, to deal with error-bracketed values
or anything needing engineering-level confidence in its accuracy.
Again you should check out JScience which may be part of the way
there, and it's open source and its developers are fairly open to
feedback (I suggested an algorithmic improvement to their GCD on
LargeInteger a while ago, which they said would probably see the light
of day in a future version) -- you could possibly be a valued
contributor with your particular areas of knowledge, and you might get
to steer it somewhat in the direction of what you seem to desire from
such a class library.
 
K

~kurt

Twisted said:
I'm not sure where this is coming from. AFAICT, 90+% of all Java
coding is network client/server stuff with no exponentiation
whatsoever, so the demand for such an operator in Java seems low. I

I imagine this is for a few reasons. First, Java was slow, and is still
*viewed* as being slow by the scientific/engineering community. Second,
Java was not math friendly as I remember quite a few papers from years ago
complaining how it didn't adhere to various standards. Third, Java is not
viewed as stable in the scientific and engineering community. The first
two items have been pretty much cleared up. The third - I have no idea.
I am, however, seeing it used more and more when it comes to building
analysis/modeling tools. Still, java is not viewed as the language to do
any type of engineering work, which I think is unfortunate because
I'm really surprised as to how fast I can put together relatively bug free
code. I mean, I'm not using the debugger much at all to figure out where
I made a mistake.

- Kurt
 
K

~kurt

Patricia Shanahan said:
I will continue to write technical articles in the Java 7 features
thread whenever I think I have something to contribute to the
discussion.

For whatever it is worth, I find most of your explanations educational.

- Kurt
 
R

Roedy Green

Exponentiation doesn't correspond to any Java operator, and
subtraction can be implemented as addition with one argument negated.
But it has to be the second operator that is negated. It is
asymmetric. That is what non-commutative means -- order matters.
a + b == b + a but a - b != b - a in general.
 
L

Lew

~kurt said:
For whatever it is worth, I find most of your explanations educational.

I venture to say that Patricia is one of the most respected contributors in
these parts. Wisdom, knowledge and patience in abundance - she's a rare treasure.
 
T

Twisted


Boy, am I getting SICK of attack posts responding to just about every
single post I write lately. What is it -- pick on Twisted week or
something?
...it has to be the second operator that is negated. It is
asymmetric.

So?

Whereas

5 - foobar

could not be translated sensibly as foobar.subtract(5) without getting
it wrong, it CAN be translated as foobar.subtract(5).negate(), or as
foobar.negate().add(5). The compiler would be smart enough to know
this. I'm fairly sure I said as much in an earlier post in this
thread, too.

The more fully general way though is to introduce first-class pairs
somehow.
 
R

Roedy Green

Boy, am I getting SICK of attack posts responding to just about every
single post I write lately. What is it -- pick on Twisted week or
something?

I did not mention your name, or say anything about you. There was no
attack.
 
R

Roedy Green

Finally, please stop attacking every post I write, even with "civil"
but critical replies. I have done nothing to deserve such treatment.

The word "attack" means verb 1 take aggressive action against. 2 (of a
disease, chemical, etc.) act harmfully on. 3 criticize or oppose
fiercely and publicly. 4 begin to deal with (a problem or task) in a
determined way. 5 (in sport) attempt to score goals or points.

At most someone has disagreed with you. Demanding that others agree
with you is rather arrogant. Usually only religious leaders or kings
can pull that off -- agree with me, not because my logic persuades,
but because of my status.
 
R

Roedy Green

Finally, please stop attacking every post I write, even with "civil"
but critical replies. I have done nothing to deserve such treatment.

If you post in a public forum, you are REQUESTING people to post their
thoughts on what you said. Even if you don't want them, you will get
them. That is what a forum is for.

forum : noun (pl. forums) 1 a meeting or medium for an exchange of
views.
 
T

Twisted

The word "attack" means verb 1 take aggressive action against. 2 (of a
disease, chemical, etc.) act harmfully on. 3 criticize or oppose
fiercely and publicly. 4 begin to deal with (a problem or task) in a
determined way. 5 (in sport) attempt to score goals or points.

Yes, and 3 (and possibly 5) would seem to apply in this instance. I
certainly seem to be being "opposed fiercely and publicly" almost
every time I hit Send this last couple weeks, and I don't particularly
care for it.
 
T

Twisted

If you post in a public forum, you are REQUESTING people to post their
thoughts on what you said.

I certainly seem to be being "opposed fiercely and publicly" almost
every time I hit Send this last couple weeks, and I don't particularly
care for it.
 
T

Twisted

I did not mention your name, or say anything about you. There was no
attack.

I certainly seem to be being "opposed fiercely and publicly" almost
every time I hit Send this last couple weeks, and I don't particularly
care for it.
 
R

Roedy Green

I certainly seem to be being "opposed fiercely and publicly" almost
every time I hit Send this last couple weeks, and I don't particularly
care for it.

I think you are overreacting. The debate has been unusually
gentlemanly. You are not being picked on. People are usually much more
blunt on the net than in person. If you use face to face standards,
you will soon be ready to strangle.
 
R

Roedy Green

I certainly seem to be being "opposed fiercely and publicly" almost
every time I hit Send this last couple weeks,

Please quote the fiercest attack. Was it a disagreement with your
opinion? A comment about you? A patronising remark?
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

~kurt said:
Huh? It gets used all the time, depending on what type of work you
do. It would really clean up some code. Although, at least having
a '%' operator, instead of a method call, cleans things up some.
But, I would give up '%' for "**" any day.

It is much more common to have a modulus operator than a
power operator.

Fortran and VB are the only ones I can remember with a
power operator.

Arne
 
R

Roedy Green

Fortran and VB are the only ones I can remember with a
power operator.

PL/I, FORTRAN, Python, Ruby, Ada, Algol-68 have **
Some Pascals have a pow operator
Algol-60 had up arrow, or various ad hoc representations.
Excel uses ^
IIRC even ActV on my LGP-30 (0-ram 4K drum) had one, but I can't
recall what it was.
 
D

Daniel Dyer

PL/I, FORTRAN, Python, Ruby, Ada, Algol-68 have **
Some Pascals have a pow operator

Turbo Pascal used ^
Algol-60 had up arrow, or various ad hoc representations.
Excel uses ^
IIRC even ActV on my LGP-30 (0-ram 4K drum) had one, but I can't
recall what it was.

Haskell (^), Groovy (**) and (I think) Prolog also have the operator.

But Arne's point is still valid, I don't think any of those languages lack
a modulus/remainder operator. It mainly seems to be descendents of C
(where ^ is XOR) that are lacking the power operator.

Dan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,802
Messages
2,569,662
Members
45,433
Latest member
andrewartemow

Latest Threads

Top