Average Error: 31.7 → 17.9
Time: 6.0s
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}\;re \leq -3.4367372751557022 \cdot 10^{+103}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;re \leq -1.1819915383869406 \cdot 10^{-181}:\\ \;\;\;\;\frac{\log \left(\left|\sqrt[3]{re \cdot re + im \cdot im}\right| \cdot \sqrt{\sqrt[3]{re \cdot re + im \cdot im}}\right)}{\log base}\\ \mathbf{elif}\;re \leq 8.172516521987715 \cdot 10^{-172}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \mathbf{elif}\;re \leq 3.706762994210151 \cdot 10^{+72}:\\ \;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{\log base} \cdot \left(2 \cdot \log re\right)\\ \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}\;re \leq -3.4367372751557022 \cdot 10^{+103}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\

\mathbf{elif}\;re \leq -1.1819915383869406 \cdot 10^{-181}:\\
\;\;\;\;\frac{\log \left(\left|\sqrt[3]{re \cdot re + im \cdot im}\right| \cdot \sqrt{\sqrt[3]{re \cdot re + im \cdot im}}\right)}{\log base}\\

\mathbf{elif}\;re \leq 8.172516521987715 \cdot 10^{-172}:\\
\;\;\;\;\frac{\log im}{\log base}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\log base} \cdot \left(2 \cdot \log re\right)\\

\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 -3.4367372751557022e+103)
   (/ (log (- re)) (log base))
   (if (<= re -1.1819915383869406e-181)
     (/
      (log
       (*
        (fabs (cbrt (+ (* re re) (* im im))))
        (sqrt (cbrt (+ (* re re) (* im im))))))
      (log base))
     (if (<= re 8.172516521987715e-172)
       (/ (log im) (log base))
       (if (<= re 3.706762994210151e+72)
         (/ (log (sqrt (+ (* re re) (* im im)))) (log base))
         (* (/ 0.5 (log base)) (* 2.0 (log re))))))))
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 <= -3.4367372751557022e+103) {
		tmp = log(-re) / log(base);
	} else if (re <= -1.1819915383869406e-181) {
		tmp = log(fabs(cbrt((re * re) + (im * im))) * sqrt(cbrt((re * re) + (im * im)))) / log(base);
	} else if (re <= 8.172516521987715e-172) {
		tmp = log(im) / log(base);
	} else if (re <= 3.706762994210151e+72) {
		tmp = log(sqrt((re * re) + (im * im))) / log(base);
	} else {
		tmp = (0.5 / log(base)) * (2.0 * log(re));
	}
	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 re < -3.4367372751557022e103

    1. Initial program 52.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. Simplified52.5

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

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

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

    if -3.4367372751557022e103 < re < -1.1819915383869406e-181

    1. Initial program 17.9

      \[\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. Simplified17.9

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{\left(\sqrt[3]{re \cdot re + im \cdot im} \cdot \sqrt[3]{re \cdot re + im \cdot im}\right) \cdot \sqrt[3]{re \cdot re + im \cdot im}}}\right)}{\log base}\]
    5. Applied sqrt-prod_binary64_43517.9

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

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

    if -1.1819915383869406e-181 < re < 8.1725165219877145e-172

    1. Initial program 31.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. Simplified31.2

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

      \[\leadsto \frac{\log \color{blue}{im}}{\log base}\]

    if 8.1725165219877145e-172 < re < 3.7067629942101506e72

    1. Initial program 16.0

      \[\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. Simplified16.0

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

    if 3.7067629942101506e72 < re

    1. Initial program 46.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. Simplified46.2

      \[\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_49946.2

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

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

      \[\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_36546.2

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

      \[\leadsto \frac{0.5}{\log base} \cdot \color{blue}{\left(-2 \cdot \log \left(\frac{1}{re}\right)\right)}\]
    10. Simplified10.3

      \[\leadsto \frac{0.5}{\log base} \cdot \color{blue}{\left(2 \cdot \log re\right)}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification17.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -3.4367372751557022 \cdot 10^{+103}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;re \leq -1.1819915383869406 \cdot 10^{-181}:\\ \;\;\;\;\frac{\log \left(\left|\sqrt[3]{re \cdot re + im \cdot im}\right| \cdot \sqrt{\sqrt[3]{re \cdot re + im \cdot im}}\right)}{\log base}\\ \mathbf{elif}\;re \leq 8.172516521987715 \cdot 10^{-172}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \mathbf{elif}\;re \leq 3.706762994210151 \cdot 10^{+72}:\\ \;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{\log base} \cdot \left(2 \cdot \log re\right)\\ \end{array}\]

Reproduce

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