From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,630a2b21ae50610a,start X-Google-Attributes: gid103376,public From: jvl@ocsystems.com (Joel VanLaven) Subject: Math error in Annex G ??? Date: 1996/07/24 Message-ID: <1996Jul24.214556.24621@ocsystems.com>#1/1 X-Deja-AN: 170000631 organization: OC Systems, Inc. newsgroups: comp.lang.ada Date: 1996-07-24T00:00:00+00:00 List-Id: I was implementing complex types from Annex G in the LRM as a way to learn some Ada95 when I ran into something that I am sure is incorrect. It has to do with exponentiation of a complex number by a negative integer by going through polar. Essentially it says that exponentiation can be significantly improved by converting to polar, using a polar exponentiation trick, and then converting back. That is fine, and I knew about that even without the LRM mentioning it. The problem is that the method that they give for exponentiation with the polar of a complex number is wrong for negative exponents. The LRM says (liberty taken with spacing): "... exponentiating the modulus by the given exponent; multiplying the argument by the given exponent, when the exponent is positive, or dividing the argument by the absolute value of the given exponent, when the exponent is negative; ..." Translating to mathese: if n > 0 then (r,theta)**n=(r**n,n*theta) if n < 0 then (r,theta)**n=(r**n,theta/abs(n)) but i**(-1) = 1/i = -i and i**(-1) = (1,pi/2)**(-1) ?=? (1**(-1),(pi/2)/abs(-1)) = (1.pi/2) = i obviously something is wrong there. I am almost positive that the desired math is: for all n (r,theta)**n=(r**n,n*theta) this comes about from how * works for polar complex numbers, namely: (r1,th1)*(r2,th2)=(r1*r2,th1+th2) this will prove it by induction for positive n as follows: -- base case (r,th)**1 = (r,th) = (r**1,1*th) --inductive case if (r,th)**n=(r**n,n*th) then (r,th)**(n+1)=((r,th)**n)*(r,th) = (r**n,n*th)*(r,th) = ((r**n)*r,(n*th)+th) = (r**(n+1),(n+1)*th) Proven. for negative n, simply use the polar definition of * and the part for positive n as follows: (r',th') = (r,th)**(-n) = 1/((r,th)**n) = 1/(r**n,n*th) (r',th')*(r**n,n*th) = 1 = (1,0) (r'*(r**n),th'+(n*th)) = (1,0) r'*(r**n) = 1 and th'+(n*th) = 0 r' = 1/(r**n) = r**(-n) and th' = -(n*th) = (-n)*th (r,th)**(-n) = (r',th') = (r**(-n),(-n)*th) Proven. I have purposely not dealt with 0 exponents as they were not included in this part of the LRM but mathematically it works the same way. I submitted this to ada-comment a week ago, but I have a feeling that comp.lang.ada might be a little more active... If anyone can show me that the LRM is correct I'd love to see it. I am practically positive that the LRM is just plain wrong math-wise, but all proofs can have flaws, so if you want to give your complex arithmetic skills a whirl, have at it. -- Joel