これいる?
諸々の形式でのそれっぽい状況における撃墜ケースを挙げる。
f32, f64, f80, f128 はそれぞれ 24-, 53-, 64-, 113-bit 仮数部の二進浮動小数点型、Decimal は Python における Decimal のデフォルトの精度(getcontext().prec = 28)に相当する。
精度が上がると最小反例も大きくなるタイプの問題設定とそうでないものがある。また、定数回の演算によって境界条件(整数との比較など)が成り立たなくなるものを主な対象とし、演算をたくさん繰り返すことにより誤差が累積するものは対象外とする。
撃墜ケースたち
素朴な問題設定における、実数での性質が浮動小数点型で成り立たない例を挙げる。過去の記事を書いたものも多いので、関連するリンクも併せて載せてある。 実際の問題設定においては、期待される値よりも大きくなることで撃墜できる状況と、小さくなることで撃墜できる状況があるため、可能な限り両側についての例を構成した。
約分
$x_0, x_1\in\N$ であって $( (x_1\oslash x_0)\otimes x_0) \ne x_1$ を満たす例。$x_1$ より小さくなる例と大きくなる例をそれぞれ示す。
f32:- $( (13\oslash 11)\otimes 11) = 13 - 2^{-20}$
- $( (7\oslash 13)\otimes 13) = 7 + 2^{-21}$
f64:- $( (15\oslash 11)\otimes 11) = 15 - 2^{-49}$
- $( (7\oslash 25)\otimes 25) = 7 + 2^{-50}$
f80:- $( (13\oslash 11)\otimes 11) = 13 - 2^{-60}$
- $( (7\oslash 13)\otimes 13) = 7 + 2^{-61}$
f128:- $( (15\oslash 11)\otimes 11) = 15 - 2^{-109}$
- $( (11\oslash 19)\otimes 19) = 11 + 2^{-109}$
Decimal- $( (1\oslash 3)\otimes 3) = 1 - 10^{-28}$
- $( (5\oslash 3)\otimes 3) = 5 + 10^{-27}$
整数への変換
十進表記で受け取って $10$ の冪乗を掛けることにより整数への変換を試みた際に誤差が生じる例。各桁数について大小両側を示す。
$1$ 以上の例については以下の通り。
f32:- $\roundcirc{4.01} \otimes 10^{2} = 401 + 2^{-15}$
- $\roundcirc{1.05} \otimes 10^{2} = 105 - 2^{-17}$
- $\roundcirc{1.001} \otimes 10^{3} = 1001 + 2^{-14}$
- $\roundcirc{2.001} \otimes 10^{3} = 2001 - 2^{-13}$
- $\roundcirc{2.0001} \otimes 10^{4} = 20001 - 2^{-9}$
- $\roundcirc{1.0003} \otimes 10^{4} = 10003 + 2^{-10}$
- $\roundcirc{8.00001} \otimes 10^{5} = 800001 - 2^{-4}$
- $\roundcirc{1.00003} \otimes 10^{5} = 100003 + 2^{-7}$
- $\roundcirc{1.000001} \otimes 10^{6} = 1000001 - 2^{-4}$
- $\roundcirc{2.000003} \otimes 10^{6} = 2000003 + 2^{-3}$
f64:- $\roundcirc{2.01} \otimes 10^{2} = 201 - 2^{-45}$
- $\roundcirc{8.05} \otimes 10^{2} = 805 + 2^{-43}$
- $\roundcirc{1.001} \otimes 10^{3} = 1001 - 2^{-43}$
- $\roundcirc{4.001} \otimes 10^{3} = 4001 + 2^{-41}$
- $\roundcirc{2.0001} \otimes 10^{4} = 20001 + 2^{-38}$
- $\roundcirc{1.0009} \otimes 10^{4} = 10009 - 2^{-39}$
- $\roundcirc{4.00001} \otimes 10^{5} = 400001 - 2^{-34}$
- $\roundcirc{2.00003} \otimes 10^{5} = 200003 + 2^{-35}$
- $\roundcirc{1.000001} \otimes 10^{6} = 1000001 - 2^{-33}$
- $\roundcirc{2.000001} \otimes 10^{6} = 2000001 + 2^{-32}$
- $\roundcirc{1.0000002} \otimes 10^{7} = 10000002 - 2^{-29}$
- $\roundcirc{2.0000007} \otimes 10^{7} = 20000007 + 2^{-28}$
- $\roundcirc{8.00000001} \otimes 10^{8} = 800000001 + 2^{-23}$
- $\roundcirc{2.00000003} \otimes 10^{8} = 200000003 - 2^{-25}$
- $\roundcirc{1 + 1\cdot 10^{-9}} \otimes 10^{9} = (1\cdot 10^{9} + 1) + 2^{-23}$
- $\roundcirc{2 + 3\cdot 10^{-9}} \otimes 10^{9} = (2\cdot 10^{9} + 3) - 2^{-22}$
- $\roundcirc{1 + 12\cdot 10^{-10}} \otimes 10^{10} = (1\cdot 10^{10} + 12) + 2^{-19}$
- $\roundcirc{1 + 14\cdot 10^{-10}} \otimes 10^{10} = (1\cdot 10^{10} + 14) - 2^{-19}$
- $\roundcirc{8 + 1\cdot 10^{-11}} \otimes 10^{11} = (8\cdot 10^{11} + 1) - 2^{-13}$
- $\roundcirc{1 + 93\cdot 10^{-11}} \otimes 10^{11} = (1\cdot 10^{11} + 93) + 2^{-16}$
- $\roundcirc{1 + 1\cdot 10^{-12}} \otimes 10^{12} = (1\cdot 10^{12} + 1) + 2^{-13}$
- $\roundcirc{2 + 3\cdot 10^{-12}} \otimes 10^{12} = (2\cdot 10^{12} + 3) - 2^{-12}$
- $\roundcirc{2 + 3\cdot 10^{-13}} \otimes 10^{13} = (2\cdot 10^{13} + 3) + 2^{-8}$
- $\roundcirc{1 + 4\cdot 10^{-13}} \otimes 10^{13} = (1\cdot 10^{13} + 4) - 2^{-9}$
- $\roundcirc{2 + 1\cdot 10^{-14}} \otimes 10^{14} = (2\cdot 10^{14} + 1) + 2^{-5}$
- $\roundcirc{8 + 7\cdot 10^{-14}} \otimes 10^{14} = (8\cdot 10^{14} + 7) - 2^{-3}$
- $\roundcirc{1 + 1\cdot 10^{-15}} \otimes 10^{15} = (1\cdot 10^{15} + 1) + 2^{-3}$
- $\roundcirc{4 + 3\cdot 10^{-15}} \otimes 10^{15} = (4\cdot 10^{15} + 3) - 2^{-1}$
f80:- $\roundcirc{4.01} \otimes 10^{2} = 401 + 2^{-55}$
- $\roundcirc{1.05} \otimes 10^{2} = 105 - 2^{-57}$
- $\roundcirc{1.002} \otimes 10^{3} = 1002 + 2^{-54}$
- $\roundcirc{1.003} \otimes 10^{3} = 1003 - 2^{-54}$
- $\roundcirc{1.0001} \otimes 10^{4} = 10001 + 2^{-50}$
- $\roundcirc{8.0005} \otimes 10^{4} = 80005 - 2^{-47}$
- $\roundcirc{8.00001} \otimes 10^{5} = 800001 - 2^{-44}$
- $\roundcirc{1.00002} \otimes 10^{5} = 100002 + 2^{-47}$
- $\roundcirc{2.000001} \otimes 10^{6} = 2000001 - 2^{-43}$
- $\roundcirc{4.000001} \otimes 10^{6} = 4000001 + 2^{-42}$
- $\roundcirc{1.0000001} \otimes 10^{7} = 10000001 - 2^{-40}$
- $\roundcirc{8.0000011} \otimes 10^{7} = 80000011 + 2^{-37}$
- $\roundcirc{1.00000001} \otimes 10^{8} = 100000001 + 2^{-37}$
- $\roundcirc{4.00000003} \otimes 10^{8} = 400000003 - 2^{-35}$
- $\roundcirc{2 + 1\cdot 10^{-9}} \otimes 10^{9} = (2\cdot 10^{9} + 1) - 2^{-33}$
- $\roundcirc{8 + 1\cdot 10^{-9}} \otimes 10^{9} = (8\cdot 10^{9} + 1) + 2^{-31}$
- $\roundcirc{8 + 1\cdot 10^{-10}} \otimes 10^{10} = (8\cdot 10^{10} + 1) - 2^{-27}$
- $\roundcirc{2 + 3\cdot 10^{-10}} \otimes 10^{10} = (2\cdot 10^{10} + 3) + 2^{-29}$
- $\roundcirc{1 + 1\cdot 10^{-11}} \otimes 10^{11} = (1\cdot 10^{11} + 1) - 2^{-27}$
- $\roundcirc{2 + 3\cdot 10^{-11}} \otimes 10^{11} = (2\cdot 10^{11} + 3) + 2^{-26}$
- $\roundcirc{8 + 1\cdot 10^{-12}} \otimes 10^{12} = (8\cdot 10^{12} + 1) + 2^{-21}$
- $\roundcirc{1 + 8\cdot 10^{-12}} \otimes 10^{12} = (1\cdot 10^{12} + 8) - 2^{-24}$
- $\roundcirc{8 + 3\cdot 10^{-13}} \otimes 10^{13} = (8\cdot 10^{13} + 3) - 2^{-17}$
- $\roundcirc{4 + 5\cdot 10^{-13}} \otimes 10^{13} = (4\cdot 10^{13} + 5) + 2^{-18}$
- $\roundcirc{4 + 1\cdot 10^{-14}} \otimes 10^{14} = (4\cdot 10^{14} + 1) - 2^{-15}$
- $\roundcirc{2 + 3\cdot 10^{-14}} \otimes 10^{14} = (2\cdot 10^{14} + 3) + 2^{-16}$
- $\roundcirc{1 + 1\cdot 10^{-15}} \otimes 10^{15} = (1\cdot 10^{15} + 1) - 2^{-14}$
- $\roundcirc{2 + 1\cdot 10^{-15}} \otimes 10^{15} = (2\cdot 10^{15} + 1) + 2^{-13}$
- $\roundcirc{2 + 3\cdot 10^{-16}} \otimes 10^{16} = (2\cdot 10^{16} + 3) + 2^{-9}$
- $\roundcirc{8 + 5\cdot 10^{-16}} \otimes 10^{16} = (8\cdot 10^{16} + 5) - 2^{-7}$
- $\roundcirc{8 + 1\cdot 10^{-17}} \otimes 10^{17} = (8\cdot 10^{17} + 1) + 2^{-4}$
- $\roundcirc{1 + 2\cdot 10^{-17}} \otimes 10^{17} = (1\cdot 10^{17} + 2) - 2^{-7}$
- $\roundcirc{2 + 1\cdot 10^{-18}} \otimes 10^{18} = (2\cdot 10^{18} + 1) + 2^{-3}$
- $\roundcirc{4 + 1\cdot 10^{-18}} \otimes 10^{18} = (4\cdot 10^{18} + 1) - 2^{-2}$
f128:- $\roundcirc{2.01} \otimes 10^{2} = 201 - 2^{-105}$
- $\roundcirc{8.05} \otimes 10^{2} = 805 + 2^{-103}$
- $\roundcirc{8.001} \otimes 10^{3} = 8001 + 2^{-100}$
- $\roundcirc{1.003} \otimes 10^{3} = 1003 - 2^{-103}$
- $\roundcirc{4.0001} \otimes 10^{4} = 40001 + 2^{-97}$
- $\roundcirc{1.0043} \otimes 10^{4} = 10043 - 2^{-99}$
- $\roundcirc{8.00001} \otimes 10^{5} = 800001 + 2^{-93}$
- $\roundcirc{1.00002} \otimes 10^{5} = 100002 - 2^{-96}$
- $\roundcirc{2.000001} \otimes 10^{6} = 2000001 + 2^{-92}$
- $\roundcirc{4.000001} \otimes 10^{6} = 4000001 - 2^{-91}$
- $\roundcirc{2.0000001} \otimes 10^{7} = 20000001 - 2^{-88}$
- $\roundcirc{8.0000005} \otimes 10^{7} = 80000005 + 2^{-86}$
- $\roundcirc{2.00000001} \otimes 10^{8} = 200000001 + 2^{-85}$
- $\roundcirc{8.00000001} \otimes 10^{8} = 800000001 - 2^{-83}$
- $\roundcirc{1 + 1\cdot 10^{-9}} \otimes 10^{9} = (1\cdot 10^{9} + 1) - 2^{-83}$
- $\roundcirc{1 + 2\cdot 10^{-9}} \otimes 10^{9} = (1\cdot 10^{9} + 2) + 2^{-83}$
- $\roundcirc{2 + 3\cdot 10^{-10}} \otimes 10^{10} = (2\cdot 10^{10} + 3) - 2^{-78}$
- $\roundcirc{1 + 4\cdot 10^{-10}} \otimes 10^{10} = (1\cdot 10^{10} + 4) + 2^{-79}$
- $\roundcirc{2 + 1\cdot 10^{-11}} \otimes 10^{11} = (2\cdot 10^{11} + 1) - 2^{-75}$
- $\roundcirc{8 + 5\cdot 10^{-11}} \otimes 10^{11} = (8\cdot 10^{11} + 5) + 2^{-73}$
- $\roundcirc{1 + 1\cdot 10^{-12}} \otimes 10^{12} = (1\cdot 10^{12} + 1) - 2^{-73}$
- $\roundcirc{4 + 1\cdot 10^{-12}} \otimes 10^{12} = (4\cdot 10^{12} + 1) + 2^{-71}$
- $\roundcirc{2 + 1\cdot 10^{-13}} \otimes 10^{13} = (2\cdot 10^{13} + 1) + 2^{-68}$
- $\roundcirc{1 + 9\cdot 10^{-13}} \otimes 10^{13} = (1\cdot 10^{13} + 9) - 2^{-69}$
- $\roundcirc{1 + 2\cdot 10^{-14}} \otimes 10^{14} = (1\cdot 10^{14} + 2) + 2^{-66}$
- $\roundcirc{1 + 8\cdot 10^{-14}} \otimes 10^{14} = (1\cdot 10^{14} + 8) - 2^{-66}$
- $\roundcirc{1 + 1\cdot 10^{-15}} \otimes 10^{15} = (1\cdot 10^{15} + 1) + 2^{-63}$
- $\roundcirc{4 + 3\cdot 10^{-15}} \otimes 10^{15} = (4\cdot 10^{15} + 3) - 2^{-61}$
- $\roundcirc{8 + 7\cdot 10^{-16}} \otimes 10^{16} = (8\cdot 10^{16} + 7) - 2^{-56}$
- $\roundcirc{1 + 10\cdot 10^{-16}} \otimes 10^{16} = (1\cdot 10^{16} + 10) + 2^{-59}$
- $\roundcirc{8 + 1\cdot 10^{-17}} \otimes 10^{17} = (8\cdot 10^{17} + 1) + 2^{-53}$
- $\roundcirc{2 + 3\cdot 10^{-17}} \otimes 10^{17} = (2\cdot 10^{17} + 3) - 2^{-55}$
- $\roundcirc{1 + 1\cdot 10^{-18}} \otimes 10^{18} = (1\cdot 10^{18} + 1) + 2^{-53}$
- $\roundcirc{8 + 1\cdot 10^{-18}} \otimes 10^{18} = (8\cdot 10^{18} + 1) - 2^{-50}$
- $\roundcirc{1 + 2\cdot 10^{-19}} \otimes 10^{19} = (1\cdot 10^{19} + 2) + 2^{-49}$
- $\roundcirc{8 + 13\cdot 10^{-19}} \otimes 10^{19} = (8\cdot 10^{19} + 13) - 2^{-46}$
- $\roundcirc{8 + 1\cdot 10^{-20}} \otimes 10^{20} = (8\cdot 10^{20} + 1) + 2^{-43}$
- $\roundcirc{2 + 3\cdot 10^{-20}} \otimes 10^{20} = (2\cdot 10^{20} + 3) - 2^{-45}$
- $\roundcirc{2 + 1\cdot 10^{-21}} \otimes 10^{21} = (2\cdot 10^{21} + 1) - 2^{-42}$
- $\roundcirc{1 + 2\cdot 10^{-21}} \otimes 10^{21} = (1\cdot 10^{21} + 2) + 2^{-43}$
- $\roundcirc{1 + 1\cdot 10^{-22}} \otimes 10^{22} = (1\cdot 10^{22} + 1) - 2^{-39}$
- $\roundcirc{4 + 23\cdot 10^{-22}} \otimes 10^{22} = (4\cdot 10^{22} + 23) + 2^{-37}$
- $\roundcirc{8 + 3\cdot 10^{-23}} \otimes 10^{23} = (8\cdot 10^{23} + 3) + 2^{-33}$
- $\roundcirc{1 + 4\cdot 10^{-23}} \otimes 10^{23} = (1\cdot 10^{23} + 4) - 2^{-36}$
- $\roundcirc{1 + 1\cdot 10^{-24}} \otimes 10^{24} = (1\cdot 10^{24} + 1) + 2^{-33}$
- $\roundcirc{8 + 1\cdot 10^{-24}} \otimes 10^{24} = (8\cdot 10^{24} + 1) - 2^{-30}$
- $\roundcirc{2 + 7\cdot 10^{-25}} \otimes 10^{25} = (2\cdot 10^{25} + 7) - 2^{-28}$
- $\roundcirc{8 + 13\cdot 10^{-25}} \otimes 10^{25} = (8\cdot 10^{25} + 13) + 2^{-26}$
- $\roundcirc{1 + 1\cdot 10^{-26}} \otimes 10^{26} = (1\cdot 10^{26} + 1) + 2^{-26}$
- $\roundcirc{4 + 3\cdot 10^{-26}} \otimes 10^{26} = (4\cdot 10^{26} + 3) - 2^{-24}$
- $\roundcirc{2 + 1\cdot 10^{-27}} \otimes 10^{27} = (2\cdot 10^{27} + 1) - 2^{-22}$
- $\roundcirc{1 + 3\cdot 10^{-27}} \otimes 10^{27} = (1\cdot 10^{27} + 3) + 2^{-23}$
- $\roundcirc{8 + 19\cdot 10^{-28}} \otimes 10^{28} = (8\cdot 10^{28} + 19) + 2^{-16}$
- $\roundcirc{1 + 78\cdot 10^{-28}} \otimes 10^{28} = (1\cdot 10^{28} + 78) - 2^{-19}$
- $\roundcirc{2 + 1\cdot 10^{-29}} \otimes 10^{29} = (2\cdot 10^{29} + 1) - 2^{-15}$
- $\roundcirc{8 + 7\cdot 10^{-29}} \otimes 10^{29} = (8\cdot 10^{29} + 7) + 2^{-13}$
- $\roundcirc{1 + 2\cdot 10^{-30}} \otimes 10^{30} = (1\cdot 10^{30} + 2) + 2^{-13}$
- $\roundcirc{2 + 3\cdot 10^{-30}} \otimes 10^{30} = (2\cdot 10^{30} + 3) - 2^{-12}$
- $\roundcirc{2 + 1\cdot 10^{-31}} \otimes 10^{31} = (2\cdot 10^{31} + 1) + 2^{-9}$
- $\roundcirc{1 + 2\cdot 10^{-31}} \otimes 10^{31} = (1\cdot 10^{31} + 2) - 2^{-10}$
- $\roundcirc{8 + 1\cdot 10^{-32}} \otimes 10^{32} = (8\cdot 10^{32} + 1) - 2^{-3}$
- $\roundcirc{1 + 6\cdot 10^{-32}} \otimes 10^{32} = (1\cdot 10^{32} + 6) + 2^{-6}$
- $\roundcirc{2 + 1\cdot 10^{-33}} \otimes 10^{33} = (2\cdot 10^{33} + 1) + 2^{-2}$
- $\roundcirc{1 + 2\cdot 10^{-33}} \otimes 10^{33} = (1\cdot 10^{33} + 2) - 2^{-3}$
また、$1$ 未満の例については以下の通り。
f32:- $\roundcirc{0.15} \otimes 10^{2} = 15 + 2^{-20}$
- $\roundcirc{0.53} \otimes 10^{2} = 53 - 2^{-18}$
- $\roundcirc{0.127} \otimes 10^{3} = 127 + 2^{-17}$
- $\roundcirc{0.251} \otimes 10^{3} = 251 - 2^{-16}$
- $\roundcirc{0.0003} \otimes 10^{4} = 3 + 2^{-22}$
- $\roundcirc{0.0007} \otimes 10^{4} = 7 - 2^{-21}$
- $\roundcirc{0.00015} \otimes 10^{5} = 15 + 2^{-20}$
- $\roundcirc{0.00027} \otimes 10^{5} = 27 - 2^{-19}$
- $\roundcirc{0.000123} \otimes 10^{6} = 123 + 2^{-17}$
- $\roundcirc{0.000247} \otimes 10^{6} = 247 - 2^{-16}$
f64:- $\roundcirc{0.07} \otimes 10^{2} = 7 + 2^{-50}$
- $\roundcirc{0.29} \otimes 10^{2} = 29 - 2^{-48}$
- $\roundcirc{0.0003} \otimes 10^{4} = 3 - 2^{-51}$
- $\roundcirc{0.0051} \otimes 10^{4} = 51 + 2^{-47}$
- $\roundcirc{0.00007} \otimes 10^{5} = 7 - 2^{-50}$
- $\roundcirc{0.00051} \otimes 10^{5} = 51 + 2^{-47}$
- $\roundcirc{0.000123} \otimes 10^{6} = 123 + 2^{-46}$
- $\roundcirc{0.000249} \otimes 10^{6} = 249 - 2^{-45}$
- $\roundcirc{21\cdot 10^{-7}} \otimes 10^{7} = 21 - 2^{-48}$
- $\roundcirc{25\cdot 10^{-7}} \otimes 10^{7} = 25 + 2^{-48}$
- $\roundcirc{3\cdot 10^{-8}} \otimes 10^{8} = 3 - 2^{-51}$
- $\roundcirc{7\cdot 10^{-8}} \otimes 10^{8} = 7 + 2^{-50}$
- $\roundcirc{15\cdot 10^{-9}} \otimes 10^{9} = 15 - 2^{-49}$
- $\roundcirc{61\cdot 10^{-9}} \otimes 10^{9} = 61 + 2^{-47}$
- $\roundcirc{21\cdot 10^{-10}} \otimes 10^{10} = 21 + 2^{-48}$
- $\roundcirc{43\cdot 10^{-10}} \otimes 10^{10} = 43 - 2^{-47}$
- $\roundcirc{1\cdot 10^{-11}} \otimes 10^{11} = 1 - 2^{-53}$
- $\roundcirc{99\cdot 10^{-11}} \otimes 10^{11} = 99 + 2^{-46}$
- $\roundcirc{31\cdot 10^{-12}} \otimes 10^{12} = 31 + 2^{-48}$
- $\roundcirc{61\cdot 10^{-12}} \otimes 10^{12} = 61 - 2^{-47}$
- $\roundcirc{7\cdot 10^{-13}} \otimes 10^{13} = 7 + 2^{-50}$
- $\roundcirc{27\cdot 10^{-13}} \otimes 10^{13} = 27 - 2^{-48}$
- $\roundcirc{7\cdot 10^{-14}} \otimes 10^{14} = 7 + 2^{-50}$
- $\roundcirc{23\cdot 10^{-14}} \otimes 10^{14} = 23 - 2^{-48}$
- $\roundcirc{29\cdot 10^{-15}} \otimes 10^{15} = 29 + 2^{-48}$
- $\roundcirc{115\cdot 10^{-15}} \otimes 10^{15} = 115 - 2^{-46}$
f80:- $\roundcirc{0.15} \otimes 10^{2} = 15 + 2^{-60}$
- $\roundcirc{0.53} \otimes 10^{2} = 53 - 2^{-58}$
- $\roundcirc{0.001} \otimes 10^{3} = 1 - 2^{-64}$
- $\roundcirc{0.253} \otimes 10^{3} = 253 + 2^{-56}$
- $\roundcirc{0.0023} \otimes 10^{4} = 23 + 2^{-59}$
- $\roundcirc{0.0031} \otimes 10^{4} = 31 - 2^{-59}$
- $\roundcirc{0.00013} \otimes 10^{5} = 13 - 2^{-60}$
- $\roundcirc{0.00027} \otimes 10^{5} = 27 + 2^{-59}$
- $\roundcirc{0.000123} \otimes 10^{6} = 123 + 2^{-57}$
- $\roundcirc{0.000125} \otimes 10^{6} = 125 - 2^{-57}$
- $\roundcirc{15\cdot 10^{-7}} \otimes 10^{7} = 15 - 2^{-60}$
- $\roundcirc{21\cdot 10^{-7}} \otimes 10^{7} = 21 + 2^{-59}$
- $\roundcirc{7\cdot 10^{-8}} \otimes 10^{8} = 7 - 2^{-61}$
- $\roundcirc{13\cdot 10^{-8}} \otimes 10^{8} = 13 + 2^{-60}$
- $\roundcirc{31\cdot 10^{-9}} \otimes 10^{9} = 31 - 2^{-59}$
- $\roundcirc{125\cdot 10^{-9}} \otimes 10^{9} = 125 + 2^{-57}$
- $\roundcirc{93\cdot 10^{-10}} \otimes 10^{10} = 93 + 2^{-57}$
- $\roundcirc{101\cdot 10^{-10}} \otimes 10^{10} = 101 - 2^{-57}$
- $\roundcirc{419\cdot 10^{-11}} \otimes 10^{11} = 419 + 2^{-55}$
- $\roundcirc{497\cdot 10^{-11}} \otimes 10^{11} = 497 - 2^{-55}$
- $\roundcirc{31\cdot 10^{-12}} \otimes 10^{12} = 31 + 2^{-59}$
- $\roundcirc{61\cdot 10^{-12}} \otimes 10^{12} = 61 - 2^{-58}$
- $\roundcirc{31\cdot 10^{-13}} \otimes 10^{13} = 31 + 2^{-59}$
- $\roundcirc{45\cdot 10^{-13}} \otimes 10^{13} = 45 - 2^{-58}$
- $\roundcirc{3\cdot 10^{-14}} \otimes 10^{14} = 3 - 2^{-62}$
- $\roundcirc{61\cdot 10^{-14}} \otimes 10^{14} = 61 + 2^{-58}$
- $\roundcirc{15\cdot 10^{-15}} \otimes 10^{15} = 15 - 2^{-60}$
- $\roundcirc{29\cdot 10^{-15}} \otimes 10^{15} = 29 + 2^{-59}$
- $\roundcirc{3\cdot 10^{-16}} \otimes 10^{16} = 3 - 2^{-62}$
- $\roundcirc{195\cdot 10^{-16}} \otimes 10^{16} = 195 + 2^{-56}$
- $\roundcirc{15\cdot 10^{-17}} \otimes 10^{17} = 15 - 2^{-60}$
- $\roundcirc{27\cdot 10^{-17}} \otimes 10^{17} = 27 + 2^{-59}$
- $\roundcirc{7\cdot 10^{-18}} \otimes 10^{18} = 7 - 2^{-61}$
- $\roundcirc{29\cdot 10^{-18}} \otimes 10^{18} = 29 + 2^{-59}$
f128:- $\roundcirc{0.07} \otimes 10^{2} = 7 + 2^{-110}$
- $\roundcirc{0.29} \otimes 10^{2} = 29 - 2^{-108}$
- $\roundcirc{0.001} \otimes 10^{3} = 1 - 2^{-113}$
- $\roundcirc{0.127} \otimes 10^{3} = 127 + 2^{-106}$
- $\roundcirc{0.0015} \otimes 10^{4} = 15 - 2^{-109}$
- $\roundcirc{0.0029} \otimes 10^{4} = 29 + 2^{-108}$
- $\roundcirc{0.00013} \otimes 10^{5} = 13 - 2^{-109}$
- $\roundcirc{0.00027} \otimes 10^{5} = 27 + 2^{-108}$
- $\roundcirc{0.000001} \otimes 10^{6} = 1 - 2^{-113}$
- $\roundcirc{0.000495} \otimes 10^{6} = 495 + 2^{-104}$
- $\roundcirc{11\cdot 10^{-7}} \otimes 10^{7} = 11 + 2^{-109}$
- $\roundcirc{77\cdot 10^{-7}} \otimes 10^{7} = 77 - 2^{-106}$
- $\roundcirc{7\cdot 10^{-8}} \otimes 10^{8} = 7 - 2^{-110}$
- $\roundcirc{15\cdot 10^{-8}} \otimes 10^{8} = 15 + 2^{-109}$
- $\roundcirc{1\cdot 10^{-9}} \otimes 10^{9} = 1 - 2^{-113}$
- $\roundcirc{15\cdot 10^{-9}} \otimes 10^{9} = 15 + 2^{-109}$
- $\roundcirc{3\cdot 10^{-10}} \otimes 10^{10} = 3 - 2^{-111}$
- $\roundcirc{7\cdot 10^{-10}} \otimes 10^{10} = 7 + 2^{-110}$
- $\roundcirc{15\cdot 10^{-11}} \otimes 10^{11} = 15 - 2^{-109}$
- $\roundcirc{27\cdot 10^{-11}} \otimes 10^{11} = 27 + 2^{-108}$
- $\roundcirc{31\cdot 10^{-12}} \otimes 10^{12} = 31 + 2^{-108}$
- $\roundcirc{59\cdot 10^{-12}} \otimes 10^{12} = 59 - 2^{-107}$
- $\roundcirc{5\cdot 10^{-13}} \otimes 10^{13} = 5 + 2^{-110}$
- $\roundcirc{105\cdot 10^{-13}} \otimes 10^{13} = 105 - 2^{-106}$
- $\roundcirc{25\cdot 10^{-14}} \otimes 10^{14} = 25 + 2^{-108}$
- $\roundcirc{29\cdot 10^{-14}} \otimes 10^{14} = 29 - 2^{-108}$
- $\roundcirc{15\cdot 10^{-15}} \otimes 10^{15} = 15 - 2^{-109}$
- $\roundcirc{31\cdot 10^{-15}} \otimes 10^{15} = 31 + 2^{-108}$
- $\roundcirc{3\cdot 10^{-16}} \otimes 10^{16} = 3 - 2^{-111}$
- $\roundcirc{29\cdot 10^{-16}} \otimes 10^{16} = 29 + 2^{-108}$
- $\roundcirc{13\cdot 10^{-17}} \otimes 10^{17} = 13 - 2^{-109}$
- $\roundcirc{23\cdot 10^{-17}} \otimes 10^{17} = 23 + 2^{-108}$
- $\roundcirc{7\cdot 10^{-18}} \otimes 10^{18} = 7 - 2^{-110}$
- $\roundcirc{29\cdot 10^{-18}} \otimes 10^{18} = 29 + 2^{-108}$
- $\roundcirc{19\cdot 10^{-19}} \otimes 10^{19} = 19 - 2^{-108}$
- $\roundcirc{23\cdot 10^{-19}} \otimes 10^{19} = 23 + 2^{-108}$
- $\roundcirc{3\cdot 10^{-20}} \otimes 10^{20} = 3 - 2^{-111}$
- $\roundcirc{23\cdot 10^{-20}} \otimes 10^{20} = 23 + 2^{-108}$
- $\roundcirc{15\cdot 10^{-21}} \otimes 10^{21} = 15 - 2^{-109}$
- $\roundcirc{109\cdot 10^{-21}} \otimes 10^{21} = 109 + 2^{-106}$
- $\roundcirc{43\cdot 10^{-22}} \otimes 10^{22} = 43 - 2^{-107}$
- $\roundcirc{55\cdot 10^{-22}} \otimes 10^{22} = 55 + 2^{-107}$
- $\roundcirc{29\cdot 10^{-23}} \otimes 10^{23} = 29 + 2^{-108}$
- $\roundcirc{51\cdot 10^{-23}} \otimes 10^{23} = 51 - 2^{-107}$
- $\roundcirc{1\cdot 10^{-24}} \otimes 10^{24} = 1 - 2^{-113}$
- $\roundcirc{27\cdot 10^{-24}} \otimes 10^{24} = 27 + 2^{-108}$
- $\roundcirc{103\cdot 10^{-25}} \otimes 10^{25} = 103 + 2^{-106}$
- $\roundcirc{109\cdot 10^{-25}} \otimes 10^{25} = 109 - 2^{-106}$
- $\roundcirc{11\cdot 10^{-26}} \otimes 10^{26} = 11 - 2^{-109}$
- $\roundcirc{353\cdot 10^{-26}} \otimes 10^{26} = 353 + 2^{-104}$
- $\roundcirc{1\cdot 10^{-27}} \otimes 10^{27} = 1 - 2^{-113}$
- $\roundcirc{1657\cdot 10^{-27}} \otimes 10^{27} = 1657 + 2^{-102}$
- $\roundcirc{73\cdot 10^{-28}} \otimes 10^{28} = 73 - 2^{-106}$
- $\roundcirc{369\cdot 10^{-28}} \otimes 10^{28} = 369 + 2^{-104}$
- $\roundcirc{7\cdot 10^{-29}} \otimes 10^{29} = 7 - 2^{-110}$
- $\roundcirc{31\cdot 10^{-29}} \otimes 10^{29} = 31 + 2^{-108}$
- $\roundcirc{15\cdot 10^{-30}} \otimes 10^{30} = 15 - 2^{-109}$
- $\roundcirc{29\cdot 10^{-30}} \otimes 10^{30} = 29 + 2^{-108}$
- $\roundcirc{255\cdot 10^{-31}} \otimes 10^{31} = 255 + 2^{-105}$
- $\roundcirc{507\cdot 10^{-31}} \otimes 10^{31} = 507 - 2^{-104}$
- $\roundcirc{15\cdot 10^{-32}} \otimes 10^{32} = 15 - 2^{-109}$
- $\roundcirc{31\cdot 10^{-32}} \otimes 10^{32} = 31 + 2^{-108}$
- $\roundcirc{13\cdot 10^{-33}} \otimes 10^{33} = 13 - 2^{-109}$
- $\roundcirc{25\cdot 10^{-33}} \otimes 10^{33} = 25 + 2^{-108}$
また謎の定理が出てきました。f64 では下記が成り立つらしいです。
Claim: $\ForallL{x\in[0\lldot 999]}{( (x\oslash 10^3)\otimes 10^3) = x}$.
平方根の和
$x, y\in\N$ であって $\sqrt{x}, \sqrt{y}\notin\N$ であるが $\roundcirc{\sqrt{x}}\oplus\roundcirc{\sqrt{y}} \in\N$ となる例。
f32:- $\roundcirc{\sqrt{874}} \oplus \roundcirc{\sqrt{1118}} = 63$
- $\sqrt{874} + \sqrt{1118} = {\small 62.999997992789941}{\footnotesize 684670036634930{\dots}}$
- $\roundcirc{\sqrt{1432}} \oplus \roundcirc{\sqrt{1694}} = 79$
- $\sqrt{1432} + \sqrt{1694} = {\small 79.000007111362356}{\footnotesize 983672864227084{\dots}}$
- $\roundcirc{\sqrt{874}} \oplus \roundcirc{\sqrt{1118}} = 63$
f64:- $\roundcirc{\sqrt{16740665}} \oplus \roundcirc{\sqrt{16912362}} = 8204$
- $\sqrt{16740665} + \sqrt{16912362} = {\small 8203.999999999999094}{\footnotesize 484527497898279{\dots}}$
- $\roundcirc{\sqrt{16740665}} \oplus \roundcirc{\sqrt{16912362}} = 8204$
大変そうだったので他の型はまだ探していない。最小反例の下界は以前示した。
$x, y, z\in\N$ であって $\sqrt{x}, \sqrt{y}, \sqrt{z}\notin\N$ であるが $\roundcirc{\sqrt{x}}\oplus\roundcirc{\sqrt{y}}\oplus\roundcirc{\sqrt{z}} \in\N$ となる例。 可換ではないので注意が必要だが、ここでは $x\le y\le z$ に限って探索した。
f32:- $\roundcirc{\sqrt{79}} \oplus \roundcirc{\sqrt{136}} \oplus \roundcirc{\sqrt{155}} = 33$
- $\sqrt{79} + \sqrt{136} + \sqrt{155} = {\small 32.99999780499492}{\footnotesize 216667571809728{\dots}}$
- $\roundcirc{\sqrt{56}} \oplus \roundcirc{\sqrt{71}} \oplus \roundcirc{\sqrt{123}} = 27$
- $\sqrt{56} + \sqrt{71} + \sqrt{123} = {\small 27.000001053133658}{\footnotesize 563853237473445{\dots}}$
- $\roundcirc{\sqrt{79}} \oplus \roundcirc{\sqrt{136}} \oplus \roundcirc{\sqrt{155}} = 33$
f64:- $\roundcirc{\sqrt{3619}} \oplus \roundcirc{\sqrt{9711}} \oplus \roundcirc{\sqrt{18577}} = 295$
- $\sqrt{3619} + \sqrt{9711} + \sqrt{18577} = {\small 294.999999999999989}{\footnotesize 686344092579607{\dots}}$
- $\roundcirc{\sqrt{8981}} \oplus \roundcirc{\sqrt{26365}} \oplus \roundcirc{\sqrt{26523}} = 420$
- $\sqrt{8981} + \sqrt{26365} + \sqrt{26523} = {\small 420.000000000000023}{\footnotesize 026456026620227{\dots}}$
- $\roundcirc{\sqrt{3619}} \oplus \roundcirc{\sqrt{9711}} \oplus \roundcirc{\sqrt{18577}} = 295$
等比数列
$x_0, x_1, x_2\in\N$ であって
- $x_1/x_0 = x_2/x_1$,
- $( (x_1\oslash x_0)\otimes x_0) \ne x_1$,
- $( (x_1\oslash x_0)\otimes x_1) \ne x_2$
をすべて満たす例。約分の項目に挙げた例の上位互換。
f32:- $\angled{25, 105, 441}$
- $(105 \oslash 25)\otimes 25 = 105 + 2^{-17}$
- $(105 \oslash 25)\otimes 105 = 441 + 2^{-15}$
- $\angled{81, 45, 25}$
- $(45 \oslash 81)\otimes 81 = 45 - 2^{-18}$
- $(45 \oslash 81)\otimes 45 = 25 - 2^{-19}$
- $\angled{25, 105, 441}$
f64:- $\angled{25, 55, 121}$
- $(55 \oslash 25)\otimes 25 = 55 - 2^{-47}$
- $(55 \oslash 25)\otimes 55 = 121 - 2^{-46}$
- $\angled{169, 195, 225}$
- $(195 \oslash 169)\otimes 169 = 195 + 2^{-45}$
- $(195 \oslash 169)\otimes 195 = 225 + 2^{-45}$
- $\angled{25, 55, 121}$
f80:- $\angled{169, 91, 49}$
- $(91 \oslash 169)\otimes 169 = 91 - 2^{-57}$
- $(91 \oslash 169)\otimes 91 = 49 - 2^{-58}$
- $\angled{81, 171, 361}$
- $(171 \oslash 81)\otimes 81 = 171 + 2^{-56}$
- $(171 \oslash 81)\otimes 171 = 361 + 2^{-55}$
- $\angled{169, 91, 49}$
f128:- $\angled{25, 55, 121}$
- $(55 \oslash 25)\otimes 25 = 55 - 2^{-107}$
- $(55 \oslash 25)\otimes 55 = 121 - 2^{-106}$
- $\angled{169, 195, 225}$
- $(195 \oslash 169)\otimes 169 = 195 + 2^{-105}$
- $(195 \oslash 169)\otimes 195 = 225 + 2^{-105}$
- $\angled{25, 55, 121}$
Decimal:- $\angled{18, 24, 32}$
- $(24\oslash 18)\otimes 18 = 24 - 10^{-26}$
- $(24\oslash 18)\otimes 24 = 32 - 10^{-26}$
- $\angled{18, 30, 50}$
- $(30\oslash 18)\otimes 18 = 30 + 10^{-26}$
- $(30\oslash 18)\otimes 30 = 50 + 10^{-26}$
- $\angled{18, 24, 32}$
比
$x_1, y_1, x_2, y_2\in\N_{\gt 0}$ であって、$x_1/y_1 \ne x_2/y_2$ かつ $x_1\oslash y_1 = x_2\oslash y_2$ である例。 下記の値を $a$ として $a\oslash (a-1) = (a+1)\oslash a$ が成り立つ。
f32:- $2948$
f64:- $67114657$
f80:- $3037041293$
f128:- $72057594227740468$
Decimal:- $31622781975974$
一次関数
さまざまな形があるため割愛。下記を参照。
その他
有理数に関する例を探したいときは Stern–Brocot 木を使うと便利。
知りたい
$\gdef\libmatantwo#1#2{\operatorname{\texttt{a\hspace{-0.06em}t\hspace{-0.08em}a\hspace{-0.04em}n\hspace{-0.04em}2}}(#1, #2)}$
- atan2
- $\arctan(y_1/x_1)\ne\arctan(y_2/x_2)$ だが $\libmatantwo{y_1}{x_1} = \libmatantwo{y_2}{x_2}$ となる例。
long doubleの怪しい偏角ソートって結局のところ撃墜可能なんですか?atan2は correctly rounded を保証するのが大変そうな気がするから、実装によるところも大きそう。
おまけ
参照したくなることがありそうなので Rump’s example。
$$ f(a, b) = 333.75b^6 + a^2 (11a^2b^2 - b^6 - 121b^4 - 2) + 5.5b^8 + \frac a{2b} $$ に対して $f(77617, 33096)$。
たまに思い出しそうなので xkcd 217。
$$ \begin{aligned} e^{\pi} - \pi &= {\small 19.999099979189475}{\footnotesize 767266442984669{\dots}}, \\ \left(9^2 + \frac{19^2}{22}\right)^{1/4} &= {\small 3.141592652582646}{\footnotesize 125206037179644{\dots}}. \end{aligned} $$ 後者は、$\pi^4$ の最良近似分数を考えることで構成できる。
おまけ (2)
glibc 関連のお話。追記です。
処理系によりがちなのと、TMD が解消されて correct rounding が規定されて実装も整った夢の世界では関係なくなる話たちです。
大抵の数学関数は correct rounding ではない実装になっていることが多いです。「相対誤差が $2^{-53}$ より大きくなってもどうでもよくない? correct rounding がそんなにうれしいんですか」と仰る方は多いと思いますが、correct rounding が保証されることの大きい意義として、処理系ごとに好き勝手な値が返ることがなくなるというのがあります。
たとえば、次のようなものが成り立ちます。コンパイル時計算が行われると別の結果になりうるので、再現させる際には気をつけましょう。
sqrt(_) は correct rounding が保証されていますが、cbrt(_) はそうなってはいません。また、pow(_, 0.5) が sqrt(_) と同様であることを期待してはいけず、correctly rounded な平方根の値を得られない例もあります。
sqrt(2921) == 0x1.B05EC632536FBp+5 == 54.04627646748664204778833664022386074066162109375 pow(2921, 0.5) == 0x1.B05EC632536FAp+5 == 54.0462764674866349423609790392220020294189453125
cbrt(15*15*15) == 0x1.DFFFFFFFFFFFFp+3 == 14.9999999999999982236431605997495353221893310546875 cbrt(3*3*3) == 0x1.8000000000001p+1 == 3.000000000000000444089209850062616169452667236328125
また、hypot についても hard-to-round case が知られているようです。
hypot(0x1.000001CC784CBp+52, 0x1.FDD67BCEB35Fp+52) == 0x1.1D400ABA3C4DBp+53
が出力されますが、
$$
\begin{aligned}
&\phantom{{}={}} \texttt{1000001CC784CB}_{(16)}^2 + \texttt{1FDD67BCEB35F}_{(16)}^2 \\
&= \texttt{23A801574789B5}_{(16)}^2 \\
&= (2\cdot \texttt{11D400ABA3C4DA}.\texttt{8}_{(16)})^2
\end{aligned}
$$
となるため、0x1.1D400ABA3C4DAp+53 と丸められるのが正しいです。
core-math/src/binary64/hypot/hypot.wc から拝借しました。atan2 や pow をはじめとする 2 変数関数についてもたくさん載っているほか、binary80 や binary128 についても用意されています。
その手の実装で correctly rounded な値が得られないがちな入力が欲しい場合には有用なことが多いですが、競プロ文脈での撃墜には直接使えない場合が多いんじゃないかなぁと思っています。えびちゃんはわくわくしますが他の人々にはあまり共感を得られない気がしています。勝手にしょんぼり。
あとがき
「誤差で落ちてるのかなあ」と言っている人が手元でケースを作る用にしたり、怪しい解法を落とすケースを作る用にしたり、「そもそもこういう例があるらしい」ということを知ることで変な解法を避ける手助けになればいいかなぁとは思っています。 未来のえびちゃんが Twitter で見かけた他の人の解法を落とすときに使うかもしれません。
double を落とすケースは入れたのに long double を落とすケースは入れておらず、依然として嘘である long double 解法が通ってしまう(+ 正当だと信じている)という不幸はしばしば発生しているので、さまざまな型に対して構成しました。Decimal に関しては、.prec を変えることでいくらでも(実質的に)別の型を作れてしまうので、困ったなぁというところです。.prec を実行時に乱択する解法もありうるかもしれません。そんなことするな。
逆に、「この制約下であればこの解法は正当」の補題たちのまとめも有用そうかもしれません[誰にとって?]。
面白そうな問題設定を見つけたり、Twitter で誰かの解法を落としたら更新するかもしれません。飽きて一生そのままになる可能性もあります。
おわり
おわりです。

