技術メモ

役に立てる技術的な何か、時々自分用の覚書。幅広く色々なことに興味があります。

三角関数の公式を覚えるのに全く苦労しなかった話

三角関数の公式を覚えるのが大変だとよく言われるけれど、高校生の頃は実は全く苦労した記憶がないという話。というのも、単に回転行列を覚えるだけだったからだ。


\color{red}{
\left(
\begin{array}{cc}
\mathrm{cos}\theta & -\mathrm{sin}\theta \\
\mathrm{sin}\theta & \mathrm{cos}\theta \\
\end{array}
\right)
}


\color{red}{
\left\{
\begin{array}{1}
 \mathrm{sin}(-\theta) = -\mathrm{sin}\theta\\
 \mathrm{cos}(-\theta) = \mathrm{cos}\theta 
\end{array}
\right.
}

これさえ覚えておけばいい*1


これさえ覚えておけばちょっと計算するだけで加法定理や和積の定理は作れるからだ*2

\displaystyle
\begin{eqnarray}
\left(
\begin{array}{cc}
\mathrm{cos}(\alpha+\beta) & -\mathrm{sin}(\alpha+\beta) \\
\mathrm{sin}(\alpha+\beta) & \mathrm{cos}(\alpha+\beta) \\
\end{array}
\right)
&=&
\left(
\begin{array}{cc}
\mathrm{cos}\alpha & -\mathrm{sin}\alpha \\
\mathrm{sin}\alpha & \mathrm{cos}\alpha \\
\end{array}
\right)
\left(
\begin{array}{cc}
\mathrm{cos}\beta & -\mathrm{sin}\beta \\
\mathrm{sin}\beta & \mathrm{cos}\beta \\
\end{array}
\right)
\\\\&=&
\left(
\begin{array}{cc}
\mathrm{cos}\alpha\mathrm{cos}\beta - \mathrm{sin}\alpha\mathrm{sin}\beta & -\mathrm{sin}\alpha\mathrm{cos}\beta -  \mathrm{sin}\beta\mathrm{cos}\alpha \\
 \mathrm{sin}\alpha\mathrm{cos}\beta +  \mathrm{sin}\beta\mathrm{cos}\alpha &\mathrm{cos}\alpha\mathrm{cos}\beta -  \mathrm{sin}\alpha\mathrm{sin}\beta \\
\end{array}
\right)
\end{eqnarray}



\displaystyle
\begin{eqnarray}
\left(
\begin{array}{cc}
\mathrm{cos}(\alpha-\beta) & -\mathrm{sin}(\alpha-\beta) \\
\mathrm{sin}(\alpha-\beta) & \mathrm{cos}(\alpha-\beta) \\
\end{array}
\right)
&=&
\left(
\begin{array}{cc}
\mathrm{cos}\alpha & -\mathrm{sin}\alpha \\
\mathrm{sin}\alpha & \mathrm{cos}\alpha \\
\end{array}
\right)
\left(
\begin{array}{cc}
\mathrm{cos}\beta & \mathrm{sin}\beta \\
{-\mathrm{sin}}\beta & \mathrm{cos}\beta \\
\end{array}
\right)
\\\\&=&
\left(
\begin{array}{cc}
\mathrm{cos}\alpha\mathrm{cos}\beta + \mathrm{sin}\alpha\mathrm{sin}\beta& -\mathrm{sin}\alpha\mathrm{cos}\beta +  \mathrm{sin}\beta\mathrm{cos}\alpha \\
 \mathrm{sin}\alpha\mathrm{cos}\beta -  \mathrm{sin}\beta\mathrm{cos}\alpha&\mathrm{cos}\alpha\mathrm{cos}\beta +  \mathrm{sin}\alpha\mathrm{sin}\beta \\
\end{array}
\right)
\end{eqnarray}


あとは和積の公式は加法定理を使えばごく自然に求まる。
割とすぐ計算できてしまうので試験中でもとりあえず回転行列を書いて加法定理を確認するようにしていたくらいで、「覚えよう!」と思って加法定理を覚えたことがない。

当たり前にみんな使っている考え方だと思っていたけれど、公式を覚えるのに苦労するという話があったので思い出した。

*1:この3つも図で書けば簡単に思い出せる

*2:数学的な成り立ちから言うと最初に加法定理があって回転行列が導き出せるのだけれど、覚えるという点で見れば回転行列を覚える方が手っ取り早い

置換可能素数

以前の「Nが現れる素数」に続いて面白い素数が紹介されていた。*1

このような素数を求めてみた。

ルール

<ルール>
素数Pに対して下の条件を満たすn(1,2,...9)が存在する。
1. Pの各桁の中にnを含まない。
2. Pの各桁をnで置換した数も全て素数になる。

(タイトルでは置換可能素数と呼んでいるけれど、そういう言葉はないです。)

コード

python3.5.3で動きます

from sympy import isprime
from math import log10, floor

def replace(num, replace_num):
    digits = len(str(num))
    replaced_nums = [str(num) for i in range(digits)]
    for i, replaced_num in enumerate(replaced_nums):
        replaced_num = replaced_num[:i] + str(replace_num) + replaced_num[i+1:]
        replaced_nums[i] = replaced_num
    return replaced_nums

replace_list = [1,3,7,9]
for prime in range(10,100000):
    if not isprime(prime):
        continue
    for replace_num in replace_list:
        if str(replace_num) in str(prime):
            continue
        replaced_nums = replace(prime, replace_num)
        for replaced_num in replaced_nums:
            if not isprime(replaced_num):
                break
        else:
            print("%8d :(%d) "%(prime, replace_num))

結果

11 :(3)
11 :(7)
13 :(7)
17 :(3)
17 :(9)
19 :(7)
31 :(7)
37 :(1)
41 :(3)
41 :(7)
43 :(1)
43 :(7)
47 :(1)
47 :(3)
61 :(7)
67 :(1)
71 :(3)
73 :(1)
79 :(1)
107 :(3)
107 :(9)
109 :(7)
137 :(9)
139 :(7)
167 :(3)
179 :(3)
197 :(3)
251 :(7)
337 :(1)
347 :(9)
409 :(1)
439 :(1)
449 :(3)
499 :(1)
607 :(1)
643 :(7)
709 :(1)
859 :(3)
1013 :(9)
1019 :(3)
1061 :(3)
1433 :(9)
1499 :(3)
1613 :(9)
2089 :(3)
3637 :(1)
3709 :(1)
3767 :(9)
4337 :(9)
4877 :(1)
4933 :(7)
6997 :(1)
7487 :(1)
8623 :(9)
9433 :(1)
9433 :(7)
16901 :(3)
25633 :(9)
36493 :(7)
47717 :(3)
56269 :(3)
76963 :(1)
86269 :(3)