\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}\begin{array}{l}
\mathbf{if}\;re \leq -1.4606828681743375 \cdot 10^{+72}:\\
\;\;\;\;\frac{\frac{0.5}{\log base}}{\frac{-0.5}{\log \left(\frac{-1}{re}\right)}}\\
\mathbf{elif}\;re \leq 8.138679595525005 \cdot 10^{+130}:\\
\;\;\;\;0.5 \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\log base}\\
\mathbf{else}:\\
\;\;\;\;\frac{\log re}{\log base}\\
\end{array}(FPCore (re im base) :precision binary64 (/ (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))
(FPCore (re im base)
:precision binary64
(if (<= re -1.4606828681743375e+72)
(/ (/ 0.5 (log base)) (/ -0.5 (log (/ -1.0 re))))
(if (<= re 8.138679595525005e+130)
(* 0.5 (/ (log (+ (* re re) (* im im))) (log base)))
(/ (log re) (log base)))))double code(double re, double im, double base) {
return ((log(sqrt((re * re) + (im * im))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
}
double code(double re, double im, double base) {
double tmp;
if (re <= -1.4606828681743375e+72) {
tmp = (0.5 / log(base)) / (-0.5 / log(-1.0 / re));
} else if (re <= 8.138679595525005e+130) {
tmp = 0.5 * (log((re * re) + (im * im)) / log(base));
} else {
tmp = log(re) / log(base);
}
return tmp;
}



Bits error versus re



Bits error versus im



Bits error versus base
Results
if re < -1.4606828681743375e72Initial program 47.6
Simplified47.6
rmApplied pow1/2_binary64_15447.6
Applied log-pow_binary64_16347.6
Applied associate-/l*_binary64_2447.6
rmApplied div-inv_binary64_7447.6
Applied associate-/r*_binary64_2347.6
Taylor expanded around -inf 10.1
if -1.4606828681743375e72 < re < 8.1386795955250046e130Initial program 21.6
Simplified21.5
rmApplied pow1_binary64_13521.5
Applied log-pow_binary64_16321.5
Applied pow1/2_binary64_15421.5
Applied log-pow_binary64_16321.5
Applied times-frac_binary64_8321.5
Simplified21.5
if 8.1386795955250046e130 < re Initial program 56.4
Simplified56.3
Taylor expanded around inf 7.3
Final simplification17.3
herbie shell --seed 2020292
(FPCore (re im base)
:name "math.log/2 on complex, real part"
:precision binary64
(/ (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))