Average Error: 32.2 → 18.1
Time: 4.4s
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 -7.806590709529468 \cdot 10^{+134}:\\ \;\;\;\;\frac{\log \left(-re\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base}\\ \mathbf{elif}\;re \leq 1.265749424662431 \cdot 10^{+86}:\\ \;\;\;\;\left(\log base \cdot \log base\right) \cdot \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{{\log base}^{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log re}{\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 -7.806590709529468 \cdot 10^{+134}:\\
\;\;\;\;\frac{\log \left(-re\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\log re}{\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 -7.806590709529468e+134)
   (/
    (+ (* (log (- re)) (log base)) (* (atan2 im re) 0.0))
    (* (log base) (log base)))
   (if (<= re 1.265749424662431e+86)
     (*
      (* (log base) (log base))
      (/ (log (sqrt (+ (* re re) (* im im)))) (pow (log base) 3.0)))
     (/ (log re) (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 <= -7.806590709529468e+134) {
		tmp = ((log(-re) * log(base)) + (atan2(im, re) * 0.0)) / (log(base) * log(base));
	} else if (re <= 1.265749424662431e+86) {
		tmp = (log(base) * log(base)) * (log(sqrt((re * re) + (im * im))) / pow(log(base), 3.0));
	} else {
		tmp = log(re) / 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 < -7.80659070952946751e134

    1. Initial program 58.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. Taylor expanded around -inf 8.1

      \[\leadsto \frac{\log \color{blue}{\left(-1 \cdot re\right)} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}\]
    3. Simplified8.1

      \[\leadsto \frac{\log \color{blue}{\left(-re\right)} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}\]

    if -7.80659070952946751e134 < re < 1.2657494246624311e86

    1. Initial program 22.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. Using strategy rm
    3. Applied flip-+_binary6422.3

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\color{blue}{\frac{\left(\log base \cdot \log base\right) \cdot \left(\log base \cdot \log base\right) - \left(0 \cdot 0\right) \cdot \left(0 \cdot 0\right)}{\log base \cdot \log base - 0 \cdot 0}}}\]
    4. Applied associate-/r/_binary6422.4

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\left(\log base \cdot \log base\right) \cdot \left(\log base \cdot \log base\right) - \left(0 \cdot 0\right) \cdot \left(0 \cdot 0\right)} \cdot \left(\log base \cdot \log base - 0 \cdot 0\right)}\]
    5. Simplified22.3

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

    if 1.2657494246624311e86 < re

    1. Initial program 49.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. Simplified49.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -7.806590709529468 \cdot 10^{+134}:\\ \;\;\;\;\frac{\log \left(-re\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base}\\ \mathbf{elif}\;re \leq 1.265749424662431 \cdot 10^{+86}:\\ \;\;\;\;\left(\log base \cdot \log base\right) \cdot \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{{\log base}^{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log re}{\log base}\\ \end{array}\]

Reproduce

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