Average Error: 32.9 → 7.3
Time: 13.6s
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} t_0 := \log \left(\frac{1}{base}\right)\\ \mathbf{if}\;re \leq -1.2172902275687481 \cdot 10^{+98}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right) \cdot \sqrt[3]{-1}}{t_0}\\ \mathbf{elif}\;re \leq -1.2637342420410735 \cdot 10^{-145}:\\ \;\;\;\;-\frac{\log \left(\sqrt{{re}^{2} + {im}^{2}}\right)}{t_0}\\ \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}
t_0 := \log \left(\frac{1}{base}\right)\\
\mathbf{if}\;re \leq -1.2172902275687481 \cdot 10^{+98}:\\
\;\;\;\;-\frac{\log \left(\frac{-1}{re}\right) \cdot \sqrt[3]{-1}}{t_0}\\

\mathbf{elif}\;re \leq -1.2637342420410735 \cdot 10^{-145}:\\
\;\;\;\;-\frac{\log \left(\sqrt{{re}^{2} + {im}^{2}}\right)}{t_0}\\

\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
 (let* ((t_0 (log (/ 1.0 base))))
   (if (<= re -1.2172902275687481e+98)
     (- (/ (* (log (/ -1.0 re)) (cbrt -1.0)) t_0))
     (if (<= re -1.2637342420410735e-145)
       (- (/ (log (sqrt (+ (pow re 2.0) (pow im 2.0)))) t_0))
       (- (/ (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 t_0 = log(1.0 / base);
	double tmp;
	if (re <= -1.2172902275687481e+98) {
		tmp = -((log(-1.0 / re) * cbrt(-1.0)) / t_0);
	} else if (re <= -1.2637342420410735e-145) {
		tmp = -(log(sqrt(pow(re, 2.0) + pow(im, 2.0))) / t_0);
	} 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 3 regimes
  2. if re < -1.2172902275687481e98

    1. Initial program 50.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. Simplified50.8

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

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

      \[\leadsto \frac{\log \color{blue}{\left(-re\right)}}{\log base} \]
    5. Using strategy rm
    6. Applied add-cbrt-cube_binary645.3

      \[\leadsto \color{blue}{\sqrt[3]{\left(\frac{\log \left(-re\right)}{\log base} \cdot \frac{\log \left(-re\right)}{\log base}\right) \cdot \frac{\log \left(-re\right)}{\log base}}} \]
    7. Simplified5.3

      \[\leadsto \sqrt[3]{\color{blue}{{\left(\frac{\log \left(-re\right)}{\log base}\right)}^{3}}} \]
    8. Taylor expanded around -inf 5.3

      \[\leadsto \sqrt[3]{\color{blue}{-1 \cdot \frac{{\log \left(\frac{-1}{re}\right)}^{3}}{{\log base}^{3}}}} \]
    9. Simplified5.3

      \[\leadsto \sqrt[3]{\color{blue}{-\frac{{\log \left(\frac{-1}{re}\right)}^{3}}{{\log base}^{3}}}} \]
    10. Taylor expanded around inf 5.0

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

    if -1.2172902275687481e98 < re < -1.2637342420410735e-145

    1. Initial program 11.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. Simplified11.8

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

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

    if -1.2637342420410735e-145 < re

    1. Initial program 33.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. Simplified33.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.2172902275687481 \cdot 10^{+98}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right) \cdot \sqrt[3]{-1}}{\log \left(\frac{1}{base}\right)}\\ \mathbf{elif}\;re \leq -1.2637342420410735 \cdot 10^{-145}:\\ \;\;\;\;-\frac{\log \left(\sqrt{{re}^{2} + {im}^{2}}\right)}{\log \left(\frac{1}{base}\right)}\\ \mathbf{else}:\\ \;\;\;\;-\frac{\log \left(\frac{1}{im}\right)}{\log base}\\ \end{array} \]

Reproduce

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