From: Howard Stearns
Subject: atan specification?
Date: 
Message-ID: <3950E258.8103869E@curl.com>
The ANSI specification for ATAN
(http://www.lisp.org/HyperSpec/Body/fun_asincm_acoscm_atan.html) has a
"Figure 12-15" that indicates results for ATAN with two arguments.

Is this table correct?

It seems to me that in the table (but not in the preceding paragraph)
the terms "x" and "y" should be switched wherever they appear.  

Compare the results, for example, with section 20.11.9 of the Java
Language Spec
(http://java.sun.com/docs/books/jls/html/javalang.doc10.html).

From: Raymond Toy
Subject: Re: atan specification?
Date: 
Message-ID: <4nwvjij4op.fsf@rtp.ericsson.se>
>>>>> "Howard" == Howard Stearns <·······@curl.com> writes:

    Howard> The ANSI specification for ATAN
    Howard> (http://www.lisp.org/HyperSpec/Body/fun_asincm_acoscm_atan.html) has a
    Howard> "Figure 12-15" that indicates results for ATAN with two arguments.

    Howard> Is this table correct?

It looks correct to me.  Clearly if y = 0 and x > 0, the phase of the
complex number x+i*y is 0.

    Howard> It seems to me that in the table (but not in the preceding paragraph)
    Howard> the terms "x" and "y" should be switched wherever they appear.  

    Howard> Compare the results, for example, with section 20.11.9 of the Java
    Howard> Language Spec
    Howard> (http://java.sun.com/docs/books/jls/html/javalang.doc10.html).

I think the confusion here is that Lisp says (atan x y), but most
other languages confusingly say atan2(y, x) to mean the same thing,
and even then, erroneously say atan2(y, x) = atan(y/x).  They really
mean atan2(y, x) = atan(y/x) taking into account the quadrant of the
the point (x, y).


Ray
From: Howard Stearns
Subject: Re: atan specification?
Date: 
Message-ID: <39511387.6772A7FE@curl.com>
I am so confused...

Raymond Toy wrote:
> 
> >>>>> "Howard" == Howard Stearns <·······@curl.com> writes:
> 
>     Howard> The ANSI specification for ATAN
>     Howard> (http://www.lisp.org/HyperSpec/Body/fun_asincm_acoscm_atan.html) has a
>     Howard> "Figure 12-15" that indicates results for ATAN with two arguments.
> 
>     Howard> Is this table correct?
> 
> It looks correct to me.  Clearly if y = 0 and x > 0, the phase of the
> complex number x+i*y is 0.

It isn't clear to me how x+i*y is relevent. (But see below...)

> 
>     Howard> It seems to me that in the table (but not in the preceding paragraph)
>     Howard> the terms "x" and "y" should be switched wherever they appear.
> 
>     Howard> Compare the results, for example, with section 20.11.9 of the Java
>     Howard> Language Spec
>     Howard> (http://java.sun.com/docs/books/jls/html/javalang.doc10.html).
> 
> I think the confusion here is that Lisp says (atan x y), but most
> other languages confusingly say atan2(y, x) to mean the same thing,
> and even then, erroneously say atan2(y, x) = atan(y/x).  They really
> mean atan2(y, x) = atan(y/x) taking into account the quadrant of the
> the point (x, y).

It sounds like you are saying that "two argument atan" are two
different functions in the two languages.  That may be, but I'm having
trouble rectifying that with this:

ANSI CL says:

"atan number1 &optional number2
If both number1 and number2 are supplied for atan, the result is the
arc tangent of number1/number2."

Java Language Spec says:

"atan2(double y, double x)
This method computes an approximation to the arc tangent of the
quotient y/x of the arguments..."

That *seems* to me like they are at least trying to define the same
thing.

Now, there's still a chance that I'm misunderstanding the purpose of
the x,y table in the ANSI spec.  For example, ANSI says 

  "If both are supplied, number2 can be zero provided number1 is not
zero."  

I can't make that sentence fit with the table, which says, 

  "For atan, the signs of number1 (indicated as x) and number2
(indicated as y) are used to derive quadrant information."  It then
goes on to define results for y=0, x=0 in Lisps that support + and -
0.0 (IEEE floats).

These two statements would seem to contradict each other, so I would
very much believe that I'm misunderstanding what the table is meant to
indicate.

> 
> Ray
From: ······@clisp.cons.org
Subject: Re: atan specification?
Date: 
Message-ID: <8ir65k$d46$1@news.u-bordeaux.fr>
> It isn't clear to me how x+i*y is relevent.

Maybe it's time to recall the mathematical definition of (atan y x).
Assuming x and y are not both zero, there exists a unique real number r > 0
and a unique real number alpha, with -pi < alpha < pi, such that

    (= x (* r (cos alpha)))  and  (= y (* r (sin alpha)))

Or, equivalently, written using complex numbers:

    (= (+ x (* i y)) (exp (* i alpha)))

r is easy to compute: it's (sqrt (expt x 2) (expt y 2)).

A 2D diagram may help, too:

                            y

                            ^
                            |
      alpha between 1.57    |       alpha between 0 and 1.57
        and 3.14            |
                            |
                            |
                            |
       alpha = 3.14         |       alpha = 0
      -----------------------------------------> x
       alpha = -3.14        |
                            |
                            |
                            |
      alpha between -3.14   |       alpha between -1.57 and 0
         and -1.57          |
                            |
                            |


Bruno
From: Christopher R. Barry
Subject: Re: atan specification?
Date: 
Message-ID: <87k8fibcpc.fsf@2xtreme.net>
······@clisp.cons.org writes:

> > It isn't clear to me how x+i*y is relevent.
> 
> Maybe it's time to recall the mathematical definition of (atan y x).
> Assuming x and y are not both zero, there exists a unique real number r > 0
> and a unique real number alpha, with -pi < alpha < pi, such that
> 
>     (= x (* r (cos alpha)))  and  (= y (* r (sin alpha)))
> 
> Or, equivalently, written using complex numbers:
> 
>     (= (+ x (* i y)) (exp (* i alpha)))
> 
> r is easy to compute: it's (sqrt (expt x 2) (expt y 2)).

(= r (sqrt (+ (expt x 2) (expt y 2))))

Christopher
From: Reini Urban
Subject: Re: atan specification?
Date: 
Message-ID: <3951cac8.697343747@news>
Christopher R. Barry wrote:
>(= r (sqrt (+ (expt x 2) (expt y 2))))

isn't  (* x x) resp. (* y y) easier to compute or have most EXPT
implementations a better optimization for the special case 2?
--
Reini Urban
http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html
From: Raymond Toy
Subject: Re: atan specification?
Date: 
Message-ID: <4n66r1hmte.fsf@rtp.ericsson.se>
>>>>> "Reini" == Reini Urban <······@sbox.tu-graz.ac.at> writes:

    Reini> Christopher R. Barry wrote:
    >> (= r (sqrt (+ (expt x 2) (expt y 2))))

    Reini> isn't  (* x x) resp. (* y y) easier to compute or have most EXPT
    Reini> implementations a better optimization for the special case 2?

Sounds like a quality of implementation issue.  

I do know, however, that CMUCL will convert (expt x n) to
multiplication for n = 2, 3, and 4.  It also converts (expt x 1/2) to
(sqrt x).

Ray
From: Raymond Toy
Subject: Re: atan specification?
Date: 
Message-ID: <4n1z1qiv1w.fsf@rtp.ericsson.se>
>>>>> "Howard" == Howard Stearns <·······@curl.com> writes:

    Howard> I am so confused...
    Howard> Raymond Toy wrote:
    >> 
    >> I think the confusion here is that Lisp says (atan x y), but most
    >> other languages confusingly say atan2(y, x) to mean the same thing,
    >> and even then, erroneously say atan2(y, x) = atan(y/x).  They really
    >> mean atan2(y, x) = atan(y/x) taking into account the quadrant of the
    >> the point (x, y).

    Howard> It sounds like you are saying that "two argument atan" are two
    Howard> different functions in the two languages.  That may be, but I'm having
    Howard> trouble rectifying that with this:

    Howard> ANSI CL says:

    Howard> "atan number1 &optional number2
    Howard> If both number1 and number2 are supplied for atan, the result is the
    Howard> arc tangent of number1/number2."

    Howard> Java Language Spec says:

    Howard> "atan2(double y, double x)
    Howard> This method computes an approximation to the arc tangent of the
    Howard> quotient y/x of the arguments..."

    Howard> That *seems* to me like they are at least trying to define the same
    Howard> thing.

I'm so embarrassed!  

I missed the statement in ANSI CL you quote above.  I think it's
really (atan y x) = (atan (/ y x)) taking into account what quadrant
the point (x, y) is in.  This makes it consistent with atan2 in C,
Java, and Fortran and this is certainly how Clisp, CMUCL, and
Lispworks work.

I think that's a typo in the ANSI CL.  There's also the same
(consistent) typo in the paragraph just before Fig 12-15. "number1" is
really y and "number2" is really x.

This explains why I almost never use (atan y x).  I almost always do
(atan (complex x y)) or (phase (complex x y)) because I always get
these right. :-)

    Howard> Now, there's still a chance that I'm misunderstanding the purpose of
    Howard> the x,y table in the ANSI spec.  For example, ANSI says 

    Howard>   "If both are supplied, number2 can be zero provided number1 is not
    Howard> zero."  

    Howard> I can't make that sentence fit with the table, which says, 

    Howard>   "For atan, the signs of number1 (indicated as x) and number2
    Howard> (indicated as y) are used to derive quadrant information."  It then
    Howard> goes on to define results for y=0, x=0 in Lisps that support + and -
    Howard> 0.0 (IEEE floats).

    Howard> These two statements would seem to contradict each other, so I would
    Howard> very much believe that I'm misunderstanding what the table is meant to
    Howard> indicate.

My reading of this is that, if you don't have signed IEEE floats,
(atan 0.0 0.0) is not defined as indicated in the table.  If you do,
then you get what the table says.

Ray
From: Raymond Toy
Subject: Re: atan specification?
Date: 
Message-ID: <4nsnu6hfug.fsf@rtp.ericsson.se>
>>>>> "Raymond" == Raymond Toy <···@rtp.ericsson.se> writes:

    Raymond> I think that's a typo in the ANSI CL.  There's also the same
    Raymond> (consistent) typo in the paragraph just before Fig 12-15. "number1" is
    Raymond> really y and "number2" is really x.

I also wanted to say that the example given:

	(/ (atan 1 (sqrt 3)) 6)  =>  0.087266 

indicates it's atan(y/x).

However, I think the example would have been more interesting if it
were multiplying by 6 instead:

	(* (atan 1 (sqrt 3)) 6)  =>  3.14159

0.087266 is just some "random" number.  Most people would be able to
guess what 3.14159 is supposed to mean. :-)

Ray
From: Howard Stearns
Subject: Re: atan specification?
Date: 
Message-ID: <39520F2A.DAF8F1F5@curl.com>
[Bruno, Ray, Christopher, Reini: thank you.  You are scholars and
gentelmen.]

OK, so if I'm finally understanding all this, "Figure 12-15" is
correct, but the relationship between x-y and number-1,number-2 in the
paragraph before is either wrong, or at least confusing (to me).
(http://www.lisp.org/HyperSpec/Body/fun_asincm_acoscm_atan.html)

While I don't want to hash out ANSI J13 issues in the newsgroups, I
would like to offer the following "ammendments" to the spec.  Not as a
proposal who's wording is to be debated, but merely as a sanity check
that I'm understanding this correctly.

1. Change one of the paragraphs to read:

  For a single real argument to atan, the result is a real and lies
between -<PI>/2 and <PI>/2 (both exclusive). For two arguments,
number1 can
be a complex if number2 is not supplied. If both are supplied, number2
can be zero provided that either number1 is not zero or that the
implementation supports plus and minus zero as distinct floating point
values.

2. Change the paragraph immediately before the table to switch x and
y:

  For atan, the signs of number1 (indicated as y) and number2
(indicated as x) are used to derive quadrant information. ...
From: Bruno Haible
Subject: Re: atan specification?
Date: 
Message-ID: <8it83e$670$1@news.u-bordeaux.fr>
Howard Stearns <·······@curl.com> wrote:
>
> 2. Change the paragraph immediately before the table to switch x and
> y:
>
>   For atan, the signs of number1 (indicated as y) and number2
> (indicated as x) are used to derive quadrant information. ...

Right. This is definitely one of the worst typos in the spec.

                Bruno
From: Thomas A. Russ
Subject: Re: atan specification?
Date: 
Message-ID: <ymiem5pfp9l.fsf@sevak.isi.edu>
Raymond Toy <···@rtp.ericsson.se> writes:

> I think the confusion here is that Lisp says (atan x y), but most
> other languages confusingly say atan2(y, x) to mean the same thing,
> and even then, erroneously say atan2(y, x) = atan(y/x).  They really
> mean atan2(y, x) = atan(y/x) taking into account the quadrant of the
> the point (x, y).

And allowing for the case x = 0.

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu