跳到主要内容

東京大学 情報理工学系研究科 コンピュータ科学専攻 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) and sin(α+β)\sin(\alpha+\beta) with cos(α)\cos(\alpha), sin(α)\sin(\alpha), cos(β)\cos(\beta), and sin(β)\sin(\beta).

(2) Suppose 0α<π/20\le\alpha<\pi/2. Express each of cos(α/2)\cos(\alpha/2) and sin(α/2)\sin(\alpha/2) with cos(α)\cos(\alpha) and sin(α)\sin(\alpha).

(3) Suppose 0α<π/20\le\alpha<\pi/2. Consider computing each of cos(α/2)\cos(\alpha/2) and sin(α/2)\sin(\alpha/2) using cos(α)\cos(\alpha) and sin(α)\sin(\alpha) 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 π2i=1Nbi2i\frac{\pi}{2}\sum_{i=1}^{N}b_i2^{-i}, where NN is a natural number and bib_i (i=1,2,,N)(i=1,2,\ldots,N) is either 0 or 1.

(a) For n=1,2,,Nn=1,2,\ldots,N, we define αn=π2i=1nbi2i\alpha_n=\frac{\pi}{2}\sum_{i=1}^{n}b_i2^{-i}. Give expressions to compute cos(αn+1)\cos(\alpha_{n+1}) and sin(αn+1)\sin(\alpha_{n+1}) using cos(αn)\cos(\alpha_n) and sin(αn)\sin(\alpha_n), for n=1,2,,N1n=1,2,\ldots,N-1.

(b) Give an algorithm to compute cos(α)\cos(\alpha) and sin(α)\sin(\alpha) 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} and sinh(α)=eαeα2\sinh(\alpha)=\frac{e^\alpha-e^{-\alpha}}{2}. Suppose that 0x<10\le x<1 and xx is expressed in a binary representation with finite precision. Design an algorithm to compute cosh(xloge2)\cosh(x\log_e2) and sinh(xloge2)\sinh(x\log_e2) 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(α+β)\cos(\alpha+\beta)sin(α+β)\sin(\alpha+\beta)

(2)设 0α<π/20\le\alpha<\pi/2,用 cosα,sinα\cos\alpha,\sin\alpha 表示 cos(α/2)\cos(\alpha/2)sin(α/2)\sin(\alpha/2)

(3)设 0α<π/20\le\alpha<\pi/2。有限精度下,直接使用第(2)问公式在 α\alpha 接近 00 时是否会丢失有效数字?若会,改写公式以避免该问题。

(4)设

α=π2i=1Nbi2i,bi{0,1},\alpha=\frac\pi2\sum_{i=1}^{N}b_i2^{-i},\qquad b_i\in\{0,1\},

其中 NN 为自然数,i=1,,Ni=1,\ldots,N。对 n=1,,Nn=1,\ldots,N,定义 αn=π2i=1nbi2i\alpha_n=\frac\pi2\sum_{i=1}^{n}b_i2^{-i}

  1. n=1,,N1n=1,\ldots,N-1,用 cosαn,sinαn\cos\alpha_n,\sin\alpha_n 表示 cosαn+1,sinαn+1\cos\alpha_{n+1},\sin\alpha_{n+1}
  2. 设计只使用四则运算和开平方计算 cosα,sinα\cos\alpha,\sin\alpha 的算法。

(5)定义 cosha=(ea+ea)/2\cosh a=(e^a+e^{-a})/2sinha=(eaea)/2\sinh a=(e^a-e^{-a})/2。设 0x<10\le x<1 有有限位二进制表示,设计只使用四则运算和开平方计算 cosh(xloge2)\cosh(x\log_e2)sinh(xloge2)\sinh(x\log_e2) 的算法,并简述其过程。

Kai

(1)

cos(α+β)=cosαcosβsinαsinβ,\cos(\alpha+\beta)=\cos\alpha\cos\beta-\sin\alpha\sin\beta,
sin(α+β)=sinαcosβ+cosαsinβ.\sin(\alpha+\beta)=\sin\alpha\cos\beta+\cos\alpha\sin\beta.

(2)

0α/2<π/40\le\alpha/2<\pi/4,两根均取正号:

cosα2=1+cosα2,sinα2=1cosα2.\cos\frac\alpha2=\sqrt{\frac{1+\cos\alpha}{2}},\qquad \sin\frac\alpha2=\sqrt{\frac{1-\cos\alpha}{2}}.

(3)

α0\alpha\approx0cosα1\cos\alpha\approx1,计算 1cosα1-\cos\alpha 会发生相近数相减,导致 sin(α/2)\sin(\alpha/2) 丢失有效数字。利用

1cosα=sin2α1+cosα1-\cos\alpha=\frac{\sin^2\alpha}{1+\cos\alpha}

改写为

sinα2=sinα2(1+cosα).\sin\frac\alpha2=\frac{\sin\alpha}{\sqrt{2(1+\cos\alpha)}}.

cos(α/2)\cos(\alpha/2) 的原公式没有该消减问题。

(4)

θn+1=π2n+2,αn+1=αn+bn+1θn+1.\theta_{n+1}=\frac{\pi}{2^{n+2}},\qquad \alpha_{n+1}=\alpha_n+b_{n+1}\theta_{n+1}.

Cn=cosαn,Sn=sinαn,c=cosθn+1,s=sinθn+1C_n=\cos\alpha_n,S_n=\sin\alpha_n,c=\cos\theta_{n+1},s=\sin\theta_{n+1},则

(Cn+1,Sn+1)={(Cn,Sn),bn+1=0,(CncSns, Snc+Cns),bn+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}

算法从 (C0,S0)=(1,0)(C_0,S_0)=(1,0) 开始。先置

c1=s1=12c_1=s_1=\frac1{\sqrt2}

(对应 θ1=π/4\theta_1=\pi/4),并递推

ci+1=1+ci2,si+1=si2(1+ci).c_{i+1}=\sqrt{\frac{1+c_i}{2}},\qquad s_{i+1}=\frac{s_i}{\sqrt{2(1+c_i)}}.

i=1,,Ni=1,\ldots,N 依次用上面的加法公式:若 bi=1b_i=1,就把 (C,S)(C,S) 更新为 (CciSsi,Sci+Csi)(Cc_i-Ss_i,Sc_i+Cs_i);若 bi=0b_i=0 则不变。最终 (C,S)=(cosα,sinα)(C,S)=(\cos\alpha,\sin\alpha)。全过程只含四则运算与开平方。

(5)

写成 x=i=1Nbi2ix=\sum_{i=1}^{N}b_i2^{-i}。从 r0=2r_0=2 开始反复开平方,得到

ri=ri1=22i.r_i=\sqrt{r_{i-1}}=2^{2^{-i}}.

q=1q=1,对每个 bi=1b_i=1 乘上 rir_i,则

q=i=1Nribi=2x=exloge2.q=\prod_{i=1}^{N}r_i^{b_i}=2^x=e^{x\log_e2}.

因此

cosh(xloge2)=q+q12,sinh(xloge2)=qq12.\cosh(x\log_e2)=\frac{q+q^{-1}}2,\qquad \sinh(x\log_e2)=\frac{q-q^{-1}}2.

若还要避免 xx 很小时计算 qq1q-q^{-1} 的相消,可直接递推双曲函数。置

c0=cosh(log2)=54,s0=sinh(log2)=34,c_0=\cosh(\log 2)=\frac54,\qquad s_0=\sinh(\log 2)=\frac34,

并用

ci=ci1+12,si=si12cic_i=\sqrt{\frac{c_{i-1}+1}{2}},\qquad s_i=\frac{s_{i-1}}{2c_i}

得到 ci=cosh(2ilog2)c_i=\cosh(2^{-i}\log 2)si=sinh(2ilog2)s_i=\sinh(2^{-i}\log 2)。从 (C,S)=(1,0)(C,S)=(1,0) 出发,在 bi=1b_i=1 时同步更新

(C,S)(Cci+Ssi, Sci+Csi).(C,S)\leftarrow(Cc_i+Ss_i,\ Sc_i+Cs_i).

最终即得所求的双曲余弦和双曲正弦。该算法仍只用四则运算与开平方,且各步不需要相近数相减。