Average Error: 32.5 → 18.2
Time: 9.7s
Precision: binary64
\[\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}\;im \leq -3.912067078968373 \cdot 10^{+109}:\\ \;\;\;\;\frac{0.5}{\frac{\log base}{-2 \cdot \log \left(\frac{-1}{im}\right)}}\\ \mathbf{elif}\;im \leq -3.9713846065782325 \cdot 10^{-292}:\\ \;\;\;\;\frac{\log \left(\sqrt{\sqrt{re \cdot re + im \cdot im}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}}\right)}{\log base}\\ \mathbf{elif}\;im \leq 8.462466084530418 \cdot 10^{-206}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;im \leq 3.45516307946585 \cdot 10^{+57}:\\ \;\;\;\;\frac{0.5}{\log base} \cdot \log \left(re \cdot re + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]
\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}\;im \leq -3.912067078968373 \cdot 10^{+109}:\\
\;\;\;\;\frac{0.5}{\frac{\log base}{-2 \cdot \log \left(\frac{-1}{im}\right)}}\\

\mathbf{elif}\;im \leq -3.9713846065782325 \cdot 10^{-292}:\\
\;\;\;\;\frac{\log \left(\sqrt{\sqrt{re \cdot re + im \cdot im}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}}\right)}{\log base}\\

\mathbf{elif}\;im \leq 8.462466084530418 \cdot 10^{-206}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\

\mathbf{elif}\;im \leq 3.45516307946585 \cdot 10^{+57}:\\
\;\;\;\;\frac{0.5}{\log base} \cdot \log \left(re \cdot re + im \cdot im\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\log im}{\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 (<= im -3.912067078968373e+109)
   (/ 0.5 (/ (log base) (* -2.0 (log (/ -1.0 im)))))
   (if (<= im -3.9713846065782325e-292)
     (/
      (log
       (*
        (sqrt (sqrt (+ (* re re) (* im im))))
        (sqrt (sqrt (+ (* re re) (* im im))))))
      (log base))
     (if (<= im 8.462466084530418e-206)
       (/ (log (- re)) (log base))
       (if (<= im 3.45516307946585e+57)
         (* (/ 0.5 (log base)) (log (+ (* re re) (* im im))))
         (/ (log im) (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 (im <= -3.912067078968373e+109) {
		tmp = 0.5 / (log(base) / (-2.0 * log(-1.0 / im)));
	} else if (im <= -3.9713846065782325e-292) {
		tmp = log(sqrt(sqrt((re * re) + (im * im))) * sqrt(sqrt((re * re) + (im * im)))) / log(base);
	} else if (im <= 8.462466084530418e-206) {
		tmp = log(-re) / log(base);
	} else if (im <= 3.45516307946585e+57) {
		tmp = (0.5 / log(base)) * log((re * re) + (im * im));
	} else {
		tmp = log(im) / log(base);
	}
	return tmp;
}

Error

Bits error versus re

Bits error versus im

Bits error versus base

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 5 regimes
  2. if im < -3.9120670789683728e109

    1. Initial program 53.8

      \[\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}\]
    2. Simplified53.8

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Using strategy rm
    4. Applied pow1/2_binary64_15853.8

      \[\leadsto \frac{\log \color{blue}{\left({\left(re \cdot re + im \cdot im\right)}^{0.5}\right)}}{\log base}\]
    5. Applied log-pow_binary64_16753.8

      \[\leadsto \frac{\color{blue}{0.5 \cdot \log \left(re \cdot re + im \cdot im\right)}}{\log base}\]
    6. Applied associate-/l*_binary64_2353.8

      \[\leadsto \color{blue}{\frac{0.5}{\frac{\log base}{\log \left(re \cdot re + im \cdot im\right)}}}\]
    7. Taylor expanded around -inf 9.5

      \[\leadsto \frac{0.5}{\frac{\log base}{\color{blue}{-2 \cdot \log \left(\frac{-1}{im}\right)}}}\]

    if -3.9120670789683728e109 < im < -3.9713846065782325e-292

    1. Initial program 22.5

      \[\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}\]
    2. Simplified22.4

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt_binary64_10022.4

      \[\leadsto \frac{\log \color{blue}{\left(\sqrt{\sqrt{re \cdot re + im \cdot im}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}}\right)}}{\log base}\]

    if -3.9713846065782325e-292 < im < 8.4624660845304181e-206

    1. Initial program 31.2

      \[\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}\]
    2. Simplified31.1

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Taylor expanded around -inf 32.9

      \[\leadsto \frac{\log \color{blue}{\left(-1 \cdot re\right)}}{\log base}\]

    if 8.4624660845304181e-206 < im < 3.45516307946585019e57

    1. Initial program 19.5

      \[\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}\]
    2. Simplified19.4

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Using strategy rm
    4. Applied pow1/2_binary64_15819.4

      \[\leadsto \frac{\log \color{blue}{\left({\left(re \cdot re + im \cdot im\right)}^{0.5}\right)}}{\log base}\]
    5. Applied log-pow_binary64_16719.4

      \[\leadsto \frac{\color{blue}{0.5 \cdot \log \left(re \cdot re + im \cdot im\right)}}{\log base}\]
    6. Applied associate-/l*_binary64_2319.4

      \[\leadsto \color{blue}{\frac{0.5}{\frac{\log base}{\log \left(re \cdot re + im \cdot im\right)}}}\]
    7. Using strategy rm
    8. Applied associate-/r/_binary64_2419.4

      \[\leadsto \color{blue}{\frac{0.5}{\log base} \cdot \log \left(re \cdot re + im \cdot im\right)}\]

    if 3.45516307946585019e57 < im

    1. Initial program 45.3

      \[\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}\]
    2. Simplified45.3

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Taylor expanded around 0 10.3

      \[\leadsto \frac{\log \color{blue}{im}}{\log base}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification18.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -3.912067078968373 \cdot 10^{+109}:\\ \;\;\;\;\frac{0.5}{\frac{\log base}{-2 \cdot \log \left(\frac{-1}{im}\right)}}\\ \mathbf{elif}\;im \leq -3.9713846065782325 \cdot 10^{-292}:\\ \;\;\;\;\frac{\log \left(\sqrt{\sqrt{re \cdot re + im \cdot im}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}}\right)}{\log base}\\ \mathbf{elif}\;im \leq 8.462466084530418 \cdot 10^{-206}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;im \leq 3.45516307946585 \cdot 10^{+57}:\\ \;\;\;\;\frac{0.5}{\log base} \cdot \log \left(re \cdot re + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]

Reproduce

herbie shell --seed 2021021 
(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))))