Average Error: 31.7 → 7.2
Time: 7.5s
Precision: binary64
\[[re, im]=\mathsf{sort}([re, im])\]
\[\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 1.670968222443666 \cdot 10^{-197}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;im \leq 1.0164079588744982 \cdot 10^{-160}:\\ \;\;\;\;\frac{\log \left(im + 0.5 \cdot \frac{re \cdot re}{im}\right)}{\log base}\\ \mathbf{elif}\;im \leq 1.2659745474754468 \cdot 10^{+79}:\\ \;\;\;\;\frac{\log \left(\sqrt{e^{\log \left(re \cdot re + im \cdot im\right)}}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;-\frac{\log \left(\frac{1}{im}\right)}{\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 1.670968222443666 \cdot 10^{-197}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\

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

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

\mathbf{else}:\\
\;\;\;\;-\frac{\log \left(\frac{1}{im}\right)}{\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 1.670968222443666e-197)
   (/ (log (- re)) (log base))
   (if (<= im 1.0164079588744982e-160)
     (/ (log (+ im (* 0.5 (/ (* re re) im)))) (log base))
     (if (<= im 1.2659745474754468e+79)
       (/ (log (sqrt (exp (log (+ (* re re) (* im im)))))) (log base))
       (- (/ (log (/ 1.0 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 <= 1.670968222443666e-197) {
		tmp = log(-re) / log(base);
	} else if (im <= 1.0164079588744982e-160) {
		tmp = log(im + (0.5 * ((re * re) / im))) / log(base);
	} else if (im <= 1.2659745474754468e+79) {
		tmp = log(sqrt(exp(log((re * re) + (im * im))))) / log(base);
	} else {
		tmp = -(log(1.0 / 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 4 regimes
  2. if im < 1.6709682224436661e-197

    1. Initial program 32.6

      \[\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. Simplified32.5

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

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

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

    if 1.6709682224436661e-197 < im < 1.0164079588744982e-160

    1. Initial program 37.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. Simplified36.9

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

      \[\leadsto \frac{\log \color{blue}{\left(0.5 \cdot \frac{{re}^{2}}{im} + im\right)}}{\log base}\]
    4. Simplified38.7

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

    if 1.0164079588744982e-160 < im < 1.2659745474754468e79

    1. Initial program 10.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. Simplified10.1

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

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

    if 1.2659745474754468e79 < im

    1. Initial program 47.7

      \[\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. Simplified47.7

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

      \[\leadsto \color{blue}{-1 \cdot \frac{\log \left(\frac{1}{im}\right)}{\log base}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification7.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.670968222443666 \cdot 10^{-197}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;im \leq 1.0164079588744982 \cdot 10^{-160}:\\ \;\;\;\;\frac{\log \left(im + 0.5 \cdot \frac{re \cdot re}{im}\right)}{\log base}\\ \mathbf{elif}\;im \leq 1.2659745474754468 \cdot 10^{+79}:\\ \;\;\;\;\frac{\log \left(\sqrt{e^{\log \left(re \cdot re + im \cdot im\right)}}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;-\frac{\log \left(\frac{1}{im}\right)}{\log base}\\ \end{array}\]

Reproduce

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