Average Error: 31.9 → 7.3
Time: 5.4s
Precision: binary64
[re im]: =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}\;re \leq -5.468069991666855 \cdot 10^{+134}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;re \leq -5.763545546578137 \cdot 10^{-161}:\\ \;\;\;\;\frac{0.5}{\frac{\log base}{\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}\;re \leq -5.468069991666855 \cdot 10^{+134}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\

\mathbf{elif}\;re \leq -5.763545546578137 \cdot 10^{-161}:\\
\;\;\;\;\frac{0.5}{\frac{\log base}{\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 (<= re -5.468069991666855e+134)
   (/ (log (- re)) (log base))
   (if (<= re -5.763545546578137e-161)
     (/ 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 (re <= -5.468069991666855e+134) {
		tmp = log(-re) / log(base);
	} else if (re <= -5.763545546578137e-161) {
		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 3 regimes
  2. if re < -5.46806999166685469e134

    1. Initial program 58.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. Simplified58.7

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

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

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

    if -5.46806999166685469e134 < re < -5.76354554657813701e-161

    1. Initial program 11.4

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

      \[\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_49911.3

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

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

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

    if -5.76354554657813701e-161 < re

    1. Initial program 32.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. Simplified32.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -5.468069991666855 \cdot 10^{+134}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;re \leq -5.763545546578137 \cdot 10^{-161}:\\ \;\;\;\;\frac{0.5}{\frac{\log base}{\log \left(re \cdot re + im \cdot im\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]

Reproduce

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