Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
equivalence between real and complex arithmetic (previously Re: Why FORTRAN)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 26 - 37 of 37 - Collapse all  -  Translate all to Translated (View all originals) < Older 
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ron Shepard  
View profile  
 More options Apr 28 2012, 11:35 am
Newsgroups: comp.lang.fortran
From: Ron Shepard <ron-shep...@NOSPAM.comcast.net>
Date: Sat, 28 Apr 2012 10:35:50 -0500
Local: Sat, Apr 28 2012 11:35 am
Subject: Re: equivalence between real and complex arithmetic (previously Re: Why FORTRAN)
In article <4f9bfc52$0$1385$4fafb...@reader1.news.tin.it>,
 Giorgio Pastore <past...@units.it> wrote:

> In any case, while many dark corners of floating point arithmetic are
> discussed in many books, I do not know a single book explicitly
> mentioning the possibility that  ((1.0,0.0)-(0.1,0.0))/(10.0,0.0) and
> (1.0-0.1)/10.0  (or similar expressions) could be different.

Then they should, because most experienced fortran programmers know
this already.  Even the REAL expression that you give above can
result in different values depending on, for example, optimization
levels.  Or in the context of a more complicated program, the
compiler itself might decide in one case the keep the intermediate
result in an extended precision register in one case, but flush to
memory in order to use that register for another value in another
case.

The complex expression is simply one example of this, the same real
expression embedded within a different context in the program.  The
compiler might well want to use that register for another part of
that complex expression evaluation, flushing the first result to
memory (and truncating its mantissa in the process).

I don't think anyone mentioned this previously, but your original
example:

       discr1 = b1**2 - 4*a1*c1
       xpr1 = ( -b1 + sqrt(discr1) )/(2*a1)
       xpc1 = ( -b1 + sqrt(cmplx(discr1,0.0_rk1) ) )/(2*a1)

demonstrates another kind of programming error.  This is exactly the
WRONG way to compute that root with b1>0 because of the large
roundoff error.  There are several expressions that can be used to
compute that root without that roundoff error.  I assume that was
the point of the original exercise, but as I say, I don't think
anyone mentioned this previously.

$.02 -Ron Shepard


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
glen herrmannsfeldt  
View profile  
 More options Apr 28 2012, 12:03 pm
Newsgroups: comp.lang.fortran
From: glen herrmannsfeldt <g...@ugcs.caltech.edu>
Date: Sat, 28 Apr 2012 16:03:36 +0000 (UTC)
Local: Sat, Apr 28 2012 12:03 pm
Subject: Re: equivalence between real and complex arithmetic (previously Re: Why FORTRAN)

Giorgio Pastore <past...@units.it> wrote:
> On 4/28/12 1:49 PM, robin.vow...@gmail.com wrote:
> ...
>> Before making a statement like that, you ought to correct
>> the program.
> Robin, if you followed the thread, you realize that the mistaken
> expression for kind rk2 does not affect the main issue I was
> discussing.

You have to get used to Robin. That always happens.

-- glen


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Giorgio Pastore  
View profile  
 More options Apr 28 2012, 1:56 pm
Newsgroups: comp.lang.fortran
From: Giorgio Pastore <past...@units.it>
Date: Sat, 28 Apr 2012 19:56:41 +0200
Local: Sat, Apr 28 2012 1:56 pm
Subject: Re: equivalence between real and complex arithmetic (previously Re: Why FORTRAN)
On 4/28/12 5:35 PM, Ron Shepard wrote:

>....  I assume that was
> the point of the original exercise, but as I say, I don't think
> anyone mentioned this previously.

Exactly. I started my post writing explicitly that the problem came from
a program written to illustrate the dangers of subtractive cancellations
for didactic purposes.

The whole discussion has been very interesting and instructive for me.
The reasons for the difference were quite clear to me, although I did
not think to use the -ffloat-store option. Still, it has been the first
time, after years of numerical programming, that I realized that there
is nothing in the standard requiring consistency between real and
complex with zero imaginary part. I guess that, stated this way, most of
my colleagues would be surprised as well. The fact that *after*
thinking a moment the behavior is perfectly understandable, does not
make it trivial at all, in my opinion and my point is that it should
deserve more emphasize than presently. Then, if the emphasis should be
put in books, in the examples of the standard or in compiler doc, it is
probably matter of tastes.

Giorgio


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Why FORTRAN" by Thomas Koenig
Thomas Koenig  
View profile  
 More options Apr 28 2012, 6:23 pm
Newsgroups: comp.lang.fortran
From: Thomas Koenig <tkoe...@netcologne.de>
Date: Sat, 28 Apr 2012 22:23:33 +0000 (UTC)
Local: Sat, Apr 28 2012 6:23 pm
Subject: Re: Why FORTRAN
John Harper <john.har...@vuw.ac.nz> schrieb:

> I used to show students the perils of misusing floating-point arithmetic by
> getting them to calculate 1 - x + x**2/2! - x**3/3! + ...  for x = 10.0 or
> some such value. (It was many years ago and I don't now remember that
> detail, nor what language and machine we then used.) Of course they got a
> wide variety of answers, none near exp(-x),

For double precision, it is not too bad.

For single precision, the old trick of explicit summation over
alternating terms gives an improvement, but still a wrong answer
by a factor of five:

program main
  implicit none
  integer :: i
  integer, parameter :: rp=selected_real_kind(6)
  real(kind=rp) :: x,s,xp, fak, newterm
  x = 7._rp
  s = 0._rp
  fak = 1._rp
  xp = 1._rp
  do i=0,100,2
     fak = fak*(i+1)
     newterm = xp * (i+1-x)/fak
     if (abs(newterm) < abs(epsilon(s)*s)) exit
     s = newterm + s
     fak = fak*(i+2)
     xp = xp * x**2
  end do
  print *,s
  print *,exp(-x)
end program main


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "equivalence between real and complex arithmetic (previously Re: Why FORTRAN)" by Terence
Terence  
View profile  
 More options Apr 28 2012, 6:25 pm
Newsgroups: comp.lang.fortran
From: "Terence" <tbwri...@bigpond.net.au>
Date: Sun, 29 Apr 2012 08:25:36 +1000
Local: Sat, Apr 28 2012 6:25 pm
Subject: Re: equivalence between real and complex arithmetic (previously Re: Why FORTRAN)
My five cents worth (about 4 UK  pennies in 1945):
My first introduction to commercial use of Fortan was seeing runs of Shell's
UK acounting system being run on our IBM service bureau office 1401 computer
in 1960. (It had a Fortran compiler and ran in 16k. I was in the banking and
stockmarket sales area).Years later I joined Shell and once had a 3-year
stint as an auditor before actually writing accounting systems.

The point I'm getting to is that in all companies I worked in over 50 years,
the accounting (especially my own later comercial systems) was usually
written in Fortran (unless PL/1). The maths was always devoid of floating
point operations, being done entirely in integer arithmetic (based on
pennies in the UK and cents in USA, Caribbean and Central America, and, I
guess, every where else with decimal monetary systems. (I have a life-time
set of discovered-fraud stories about currency exchange accounting).

In survey software you HAVE to use integers to get the row, column and grand
totals to correlate.
The fun starts when percentage-based tables, so loved by Ad. sales
directors, also had to add up exactly. (There's a running-error propagation
and absorbance algorithm to handle that).


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Why FORTRAN" by robin.vow...@gmail.com
robin.vow...@gmail.com  
View profile  
 More options Apr 29 2012, 8:14 am
Newsgroups: comp.lang.fortran
From: robin.vow...@gmail.com
Date: Sun, 29 Apr 2012 05:14:14 -0700 (PDT)
Local: Sun, Apr 29 2012 8:14 am
Subject: Re: Why FORTRAN


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "equivalence between real and complex arithmetic (previously Re: Why FORTRAN)" by robin.vow...@gmail.com
robin.vow...@gmail.com  
View profile  
 More options Apr 29 2012, 11:56 am
Newsgroups: comp.lang.fortran
From: robin.vow...@gmail.com
Date: Sun, 29 Apr 2012 08:56:34 -0700 (PDT)
Local: Sun, Apr 29 2012 11:56 am
Subject: Re: equivalence between real and complex arithmetic (previously Re: Why FORTRAN)

On Sunday, 29 April 2012 02:03:36 UTC+10, glen herrmannsfeldt  wrote:
> Giorgio Pastore
>  wrote:
> > On 4/28/12 1:49 PM, robin.vow...@gmail.com wrote:
> > ...
> >> Before making a statement like that, you ought to correct
> >> the program.

> > Robin, if you followed the thread, you realize that the mistaken
> > expression for kind rk2 does not affect the main issue I was
> > discussing.

> You have to get used to Robin. That always happens.

Snide remarks are unbecoming.
Especially when your response is to a remark that is incorrect.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Why FORTRAN" by robin.vow...@gmail.com
robin.vow...@gmail.com  
View profile  
 More options Apr 29 2012, 12:04 pm
Newsgroups: comp.lang.fortran
From: robin.vow...@gmail.com
Date: Sun, 29 Apr 2012 09:04:26 -0700 (PDT)
Local: Sun, Apr 29 2012 12:04 pm
Subject: Re: Why FORTRAN
On Sunday, 29 April 2012 22:14:14 UTC+10, robin....@gmail.com

I thought that it wasn't possible for software to be worse than
Micro$oft's, but Google has managed it.

Google posted a response that I cancelled, and failed to post a response to
another article that I posted.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "equivalence between real and complex arithmetic (previously Re: Why FORTRAN)" by robin.vow...@gmail.com
robin.vow...@gmail.com  
View profile  
 More options Apr 29 2012, 11:53 am
Newsgroups: comp.lang.fortran
From: robin.vow...@gmail.com
Date: Sun, 29 Apr 2012 08:53:46 -0700 (PDT)
Local: Sun, Apr 29 2012 11:53 am
Subject: Re: equivalence between real and complex arithmetic (previously Re: Why FORTRAN)

On Sunday, 29 April 2012 00:14:56 UTC+10, Giorgio Pastore  wrote:
> On 4/28/12 1:49 PM, robin.vow...@gmail.com wrote:
> ...
> > Before making a statement like that, you ought to correct
> > the program.

> Robin, if you followed the thread, you realize that the mistaken
> expression for kind rk2 does not affect the main issue I was discussing.

In you post, you were concerned with differences between
the result of a Real computation, and an identical computation
using Complex arithmetic.

You even suggested that there was a fault in library routine(s).

>However, with my big surprise, gfortran 4.4,4.5, 4.6 and 4.7 on ubuntu
>boxes give different results if one works with real or complex
>variables. In particular the real results is definitely more accurate
>than the complex one.
>I suspect something went wrong with the last gfortran distributions or
>the related libraries.

Since one of your computations - which contained an error - produced an
expected result, you concluded incorrectly that the program worked.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
robert.corb...@oracle.com  
View profile  
 More options May 1 2012, 12:18 am
Newsgroups: comp.lang.fortran
From: robert.corb...@oracle.com
Date: Mon, 30 Apr 2012 21:18:21 -0700 (PDT)
Local: Tues, May 1 2012 12:18 am
Subject: Re: equivalence between real and complex arithmetic (previously Re: Why FORTRAN)
On Apr 27, 10:39 pm, Giorgio Pastore <past...@units.it> wrote:

The Fortran standard includes the mathematical equivalence rule, which
allows
any expression to be replaced with a mathematically equivalent
expression.
That rule effectively means you cannot trust the result of evaluating
an
expression.  In the past, the power of optimizers was very limited,
which
protected users more than they knew.  Over time, optimizers have
become
far more aggressive, and programs that used to work without problems
now
produce compromised results.

Robert Corbett


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas Jahns  
View profile  
 More options May 2 2012, 7:30 am
Newsgroups: comp.lang.fortran
From: Thomas Jahns <ja...@idontlikespam.dkrz.de>
Date: Wed, 02 May 2012 13:30:15 +0200
Local: Wed, May 2 2012 7:30 am
Subject: Re: equivalence between real and complex arithmetic (previously Re: Why FORTRAN)
On 04/28/2012 07:39 AM, Giorgio Pastore wrote:

> On 4/28/12 2:48 AM, Steven G. Kargl wrote:
> ...
>> You failed to identify the hardware you used, but I suspect it is
>> i686 compatible.

> You are right. It is i686 compatible.

>> If it is, then the answer is (1) get better
>> hardware or (2) use -ffloat-store if you don't want intermediate
>> results stored in FPU 80-bit registers.  On my i686-*-freebsd system,

One might also consider adjusting the default FPU precision or force the
compiler to use SSE operations (which will typically match the desired
precision). For gfortran, the -mpc64 option will usually result in the desired
precision without costly forcing register contents to memory.

If computations in multiple precisions are desired in a single program instead,
one needs to emit corresponding control register changes before issuing the
operation.

x86_64 aka amd64 does not exhibit this particular problem as severely, because
FP operations use the SSE registers by default.

Thomas Jahns


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Qolin  
View profile  
 More options May 6 2012, 4:11 pm
Newsgroups: comp.lang.fortran
From: "Qolin" <no...@nowhere.com>
Date: Sun, 6 May 2012 21:11:00 +0100
Subject: Re: equivalence between real and complex arithmetic (previously Re: Why FORTRAN)

robin.vow...@gmail.com wrote in message

news:6663432.360.1335714994206.JavaMail.geo-discussion-forums@pbbpz9...

...As does that.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages < Older 
« Back to Discussions « Newer topic     Older topic »