東京大学 情報理工学系研究科 コンピュータ科学専攻 2016年8月実施 専門科目II 問題1
Author
祭音Myyura (co-authored with GPT 5.6 SOL)
Description
Answer the following questions.
(1) Express each of cos ( α + β ) \cos(\alpha+\beta) cos ( α + β ) and sin ( α + β ) \sin(\alpha+\beta) sin ( α + β ) with cos ( α ) \cos(\alpha) cos ( α ) , sin ( α ) \sin(\alpha) sin ( α ) , cos ( β ) \cos(\beta) cos ( β ) , and sin ( β ) \sin(\beta) sin ( β ) .
(2) Suppose 0 ≤ α < π / 2 0\le\alpha<\pi/2 0 ≤ α < π /2 . Express each of cos ( α / 2 ) \cos(\alpha/2) cos ( α /2 ) and sin ( α / 2 ) \sin(\alpha/2) sin ( α /2 ) with cos ( α ) \cos(\alpha) cos ( α ) and sin ( α ) \sin(\alpha) sin ( α ) .
(3) Suppose 0 ≤ α < π / 2 0\le\alpha<\pi/2 0 ≤ α < π /2 . Consider computing each of cos ( α / 2 ) \cos(\alpha/2) cos ( α /2 ) and sin ( α / 2 ) \sin(\alpha/2) sin ( α /2 ) using cos ( α ) \cos(\alpha) cos ( α ) and sin ( α ) \sin(\alpha) sin ( α ) with finite precision, by the expressions obtained in Question (2). Is there a risk of losing significant digits when α \alpha α is close to zero? If there is, improve the expressions to avoid this loss.
(4) Suppose that α \alpha α is expressed as π 2 ∑ i = 1 N b i 2 − i \frac{\pi}{2}\sum_{i=1}^{N}b_i2^{-i} 2 π ∑ i = 1 N b i 2 − i , where N N N is a natural number and b i b_i b i ( i = 1 , 2 , … , N ) (i=1,2,\ldots,N) ( i = 1 , 2 , … , N ) is either 0 or 1.
(a) For n = 1 , 2 , … , N n=1,2,\ldots,N n = 1 , 2 , … , N , we define α n = π 2 ∑ i = 1 n b i 2 − i \alpha_n=\frac{\pi}{2}\sum_{i=1}^{n}b_i2^{-i} α n = 2 π ∑ i = 1 n b i 2 − i . Give expressions to compute cos ( α n + 1 ) \cos(\alpha_{n+1}) cos ( α n + 1 ) and sin ( α n + 1 ) \sin(\alpha_{n+1}) sin ( α n + 1 ) using cos ( α n ) \cos(\alpha_n) cos ( α n ) and sin ( α n ) \sin(\alpha_n) sin ( α n ) , for n = 1 , 2 , … , N − 1 n=1,2,\ldots,N-1 n = 1 , 2 , … , N − 1 .
(b) Give an algorithm to compute cos ( α ) \cos(\alpha) cos ( α ) and sin ( α ) \sin(\alpha) sin ( α ) using only the four arithmetic operations ( + , − , × , / ) (+,-,\times,/) ( + , − , × , / ) and the extraction of square root ( ) (\sqrt{\ }) ( ) .
(5) We define cosh ( α ) = e α + e − α 2 \cosh(\alpha)=\frac{e^\alpha+e^{-\alpha}}{2} cosh ( α ) = 2 e α + e − α and sinh ( α ) = e α − e − α 2 \sinh(\alpha)=\frac{e^\alpha-e^{-\alpha}}{2} sinh ( α ) = 2 e α − e − α . Suppose that 0 ≤ x < 1 0\le x<1 0 ≤ x < 1 and x x x is expressed in a binary representation with finite precision. Design an algorithm to compute cosh ( x log e 2 ) \cosh(x\log_e2) cosh ( x log e 2 ) and sinh ( x log e 2 ) \sinh(x\log_e2) sinh ( x log e 2 ) using only the four arithmetic operations ( + , − , × , / ) (+,-,\times,/) ( + , − , × , / ) and the extraction of square root ( ) (\sqrt{\ }) ( ) , and describe an outline of the algorithm.
题目描述
回答下列问题。
(1)用 cos α , sin α , cos β , sin β \cos\alpha,\sin\alpha,\cos\beta,\sin\beta cos α , sin α , cos β , sin β 表示 cos ( α + β ) \cos(\alpha+\beta) cos ( α + β ) 和 sin ( α + β ) \sin(\alpha+\beta) sin ( α + β ) 。
(2)设 0 ≤ α < π / 2 0\le\alpha<\pi/2 0 ≤ α < π /2 ,用 cos α , sin α \cos\alpha,\sin\alpha cos α , sin α 表示 cos ( α / 2 ) \cos(\alpha/2) cos ( α /2 ) 和 sin ( α / 2 ) \sin(\alpha/2) sin ( α /2 ) 。
(3)设 0 ≤ α < π / 2 0\le\alpha<\pi/2 0 ≤ α < π /2 。有限精度下,直接使用第(2)问公式在 α \alpha α 接近 0 0 0 时是否会丢失有效数字?若会,改写公式以避免该问题。
(4)设
α = π 2 ∑ i = 1 N b i 2 − i , b i ∈ { 0 , 1 } , \alpha=\frac\pi2\sum_{i=1}^{N}b_i2^{-i},\qquad b_i\in\{0,1\}, α = 2 π i = 1 ∑ N b i 2 − i , b i ∈ { 0 , 1 } ,
其中 N N N 为自然数,i = 1 , … , N i=1,\ldots,N i = 1 , … , N 。对 n = 1 , … , N n=1,\ldots,N n = 1 , … , N ,定义 α n = π 2 ∑ i = 1 n b i 2 − i \alpha_n=\frac\pi2\sum_{i=1}^{n}b_i2^{-i} α n = 2 π ∑ i = 1 n b i 2 − i 。
对 n = 1 , … , N − 1 n=1,\ldots,N-1 n = 1 , … , N − 1 ,用 cos α n , sin α n \cos\alpha_n,\sin\alpha_n cos α n , sin α n 表示 cos α n + 1 , sin α n + 1 \cos\alpha_{n+1},\sin\alpha_{n+1} cos α n + 1 , sin α n + 1 ;
设计只使用四则运算和开平方计算 cos α , sin α \cos\alpha,\sin\alpha cos α , sin α 的算法。
(5)定义 cosh a = ( e a + e − a ) / 2 \cosh a=(e^a+e^{-a})/2 cosh a = ( e a + e − a ) /2 、sinh a = ( e a − e − a ) / 2 \sinh a=(e^a-e^{-a})/2 sinh a = ( e a − e − a ) /2 。设 0 ≤ x < 1 0\le x<1 0 ≤ x < 1 有有限位二进制表示,设计只使用四则运算和开平方计算 cosh ( x log e 2 ) \cosh(x\log_e2) cosh ( x log e 2 ) 、sinh ( x log e 2 ) \sinh(x\log_e2) sinh ( x log e 2 ) 的算法,并简述其过程。
Kai
(1)
cos ( α + β ) = cos α cos β − sin α sin β , \cos(\alpha+\beta)=\cos\alpha\cos\beta-\sin\alpha\sin\beta, cos ( α + β ) = cos α cos β − sin α sin β ,
sin ( α + β ) = sin α cos β + cos α sin β . \sin(\alpha+\beta)=\sin\alpha\cos\beta+\cos\alpha\sin\beta. sin ( α + β ) = sin α cos β + cos α sin β .
(2)
因 0 ≤ α / 2 < π / 4 0\le\alpha/2<\pi/4 0 ≤ α /2 < π /4 ,两根均取正号:
cos α 2 = 1 + cos α 2 , sin α 2 = 1 − cos α 2 . \cos\frac\alpha2=\sqrt{\frac{1+\cos\alpha}{2}},\qquad
\sin\frac\alpha2=\sqrt{\frac{1-\cos\alpha}{2}}. cos 2 α = 2 1 + cos α , sin 2 α = 2 1 − cos α .
(3)
α ≈ 0 \alpha\approx0 α ≈ 0 时 cos α ≈ 1 \cos\alpha\approx1 cos α ≈ 1 ,计算 1 − cos α 1-\cos\alpha 1 − cos α 会发生相近数相减,导致 sin ( α / 2 ) \sin(\alpha/2) sin ( α /2 ) 丢失有效数字。利用
1 − cos α = sin 2 α 1 + cos α 1-\cos\alpha=\frac{\sin^2\alpha}{1+\cos\alpha} 1 − cos α = 1 + cos α sin 2 α
改写为
sin α 2 = sin α 2 ( 1 + cos α ) . \sin\frac\alpha2=\frac{\sin\alpha}{\sqrt{2(1+\cos\alpha)}}. sin 2 α = 2 ( 1 + cos α ) sin α .
cos ( α / 2 ) \cos(\alpha/2) cos ( α /2 ) 的原公式没有该消减问题。
(4)
令
θ n + 1 = π 2 n + 2 , α n + 1 = α n + b n + 1 θ n + 1 . \theta_{n+1}=\frac{\pi}{2^{n+2}},\qquad
\alpha_{n+1}=\alpha_n+b_{n+1}\theta_{n+1}. θ n + 1 = 2 n + 2 π , α n + 1 = α n + b n + 1 θ n + 1 .
记 C n = cos α n , S n = sin α n , c = cos θ n + 1 , s = sin θ n + 1 C_n=\cos\alpha_n,S_n=\sin\alpha_n,c=\cos\theta_{n+1},s=\sin\theta_{n+1} C n = cos α n , S n = sin α n , c = cos θ n + 1 , s = sin θ n + 1 ,则
( C n + 1 , S n + 1 ) = { ( C n , S n ) , b n + 1 = 0 , ( C n c − S n s , S n c + C n s ) , b n + 1 = 1. (C_{n+1},S_{n+1})=
\begin{cases}
(C_n,S_n),&b_{n+1}=0,\\
(C_nc-S_ns,\ S_nc+C_ns),&b_{n+1}=1.
\end{cases} ( C n + 1 , S n + 1 ) = { ( C n , S n ) , ( C n c − S n s , S n c + C n s ) , b n + 1 = 0 , b n + 1 = 1.
算法从 ( C 0 , S 0 ) = ( 1 , 0 ) (C_0,S_0)=(1,0) ( C 0 , S 0 ) = ( 1 , 0 ) 开始。先置
c 1 = s 1 = 1 2 c_1=s_1=\frac1{\sqrt2} c 1 = s 1 = 2 1
(对应 θ 1 = π / 4 \theta_1=\pi/4 θ 1 = π /4 ),并递推
c i + 1 = 1 + c i 2 , s i + 1 = s i 2 ( 1 + c i ) . c_{i+1}=\sqrt{\frac{1+c_i}{2}},\qquad
s_{i+1}=\frac{s_i}{\sqrt{2(1+c_i)}}. c i + 1 = 2 1 + c i , s i + 1 = 2 ( 1 + c i ) s i .
按 i = 1 , … , N i=1,\ldots,N i = 1 , … , N 依次用上面的加法公式:若 b i = 1 b_i=1 b i = 1 ,就把 ( C , S ) (C,S) ( C , S ) 更新为
( C c i − S s i , S c i + C s i ) (Cc_i-Ss_i,Sc_i+Cs_i) ( C c i − S s i , S c i + C s i ) ;若 b i = 0 b_i=0 b i = 0 则不变。最终 ( C , S ) = ( cos α , sin α ) (C,S)=(\cos\alpha,\sin\alpha) ( C , S ) = ( cos α , sin α ) 。全过程只含四则运算与开平方。
(5)
写成 x = ∑ i = 1 N b i 2 − i x=\sum_{i=1}^{N}b_i2^{-i} x = ∑ i = 1 N b i 2 − i 。从 r 0 = 2 r_0=2 r 0 = 2 开始反复开平方,得到
r i = r i − 1 = 2 2 − i . r_i=\sqrt{r_{i-1}}=2^{2^{-i}}. r i = r i − 1 = 2 2 − i .
令 q = 1 q=1 q = 1 ,对每个 b i = 1 b_i=1 b i = 1 乘上 r i r_i r i ,则
q = ∏ i = 1 N r i b i = 2 x = e x log e 2 . q=\prod_{i=1}^{N}r_i^{b_i}=2^x=e^{x\log_e2}. q = i = 1 ∏ N r i b i = 2 x = e x l o g e 2 .
因此
cosh ( x log e 2 ) = q + q − 1 2 , sinh ( x log e 2 ) = q − q − 1 2 . \cosh(x\log_e2)=\frac{q+q^{-1}}2,\qquad
\sinh(x\log_e2)=\frac{q-q^{-1}}2. cosh ( x log e 2 ) = 2 q + q − 1 , sinh ( x log e 2 ) = 2 q − q − 1 .
若还要避免 x x x 很小时计算 q − q − 1 q-q^{-1} q − q − 1 的相消,可直接递推双曲函数。置
c 0 = cosh ( log 2 ) = 5 4 , s 0 = sinh ( log 2 ) = 3 4 , c_0=\cosh(\log 2)=\frac54,\qquad
s_0=\sinh(\log 2)=\frac34, c 0 = cosh ( log 2 ) = 4 5 , s 0 = sinh ( log 2 ) = 4 3 ,
并用
c i = c i − 1 + 1 2 , s i = s i − 1 2 c i c_i=\sqrt{\frac{c_{i-1}+1}{2}},\qquad
s_i=\frac{s_{i-1}}{2c_i} c i = 2 c i − 1 + 1 , s i = 2 c i s i − 1
得到 c i = cosh ( 2 − i log 2 ) c_i=\cosh(2^{-i}\log 2) c i = cosh ( 2 − i log 2 ) 、s i = sinh ( 2 − i log 2 ) s_i=\sinh(2^{-i}\log 2) s i = sinh ( 2 − i log 2 ) 。从 ( C , S ) = ( 1 , 0 ) (C,S)=(1,0) ( C , S ) = ( 1 , 0 ) 出发,在 b i = 1 b_i=1 b i = 1 时同步更新
( C , S ) ← ( C c i + S s i , S c i + C s i ) . (C,S)\leftarrow(Cc_i+Ss_i,\ Sc_i+Cs_i). ( C , S ) ← ( C c i + S s i , S c i + C s i ) .
最终即得所求的双曲余弦和双曲正弦。该算法仍只用四则运算与开平方,且各步不需要相近数相减。