Average Error: 32.1 → 7.9
Time: 7.7s
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}\;re \leq -2.849551058941963 \cdot 10^{+146}:\\ \;\;\;\;\log \left(e^{-\frac{\log \left(\frac{-1}{re}\right)}{\log base}}\right)\\ \mathbf{elif}\;re \leq -1.0647680349542202 \cdot 10^{-112}:\\ \;\;\;\;\frac{\log \left(\sqrt{\sqrt[3]{re \cdot re + im \cdot im} \cdot \left(\sqrt[3]{re \cdot re + im \cdot im} \cdot \sqrt[3]{re \cdot re + im \cdot im}\right)}\right)}{\log base}\\ \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 -2.849551058941963 \cdot 10^{+146}:\\
\;\;\;\;\log \left(e^{-\frac{\log \left(\frac{-1}{re}\right)}{\log base}}\right)\\

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

\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 -2.849551058941963e+146)
   (log (exp (- (/ (log (/ -1.0 re)) (log base)))))
   (if (<= re -1.0647680349542202e-112)
     (/
      (log
       (sqrt
        (*
         (cbrt (+ (* re re) (* im im)))
         (* (cbrt (+ (* re re) (* im im))) (cbrt (+ (* re re) (* im im)))))))
      (log base))
     (/ (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 <= -2.849551058941963e+146) {
		tmp = log(exp(-(log(-1.0 / re) / log(base))));
	} else if (re <= -1.0647680349542202e-112) {
		tmp = log(sqrt(cbrt((re * re) + (im * im)) * (cbrt((re * re) + (im * im)) * cbrt((re * re) + (im * im))))) / log(base);
	} 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 < -2.84955105894196315e146

    1. Initial program 62.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. Simplified62.2

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

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

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

      \[\leadsto \color{blue}{\log \left(e^{\frac{\log \left(-re\right)}{\log base}}\right)}\]
    7. Simplified4.3

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

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

    if -2.84955105894196315e146 < re < -1.0647680349542202e-112

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

      \[\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_binary6410.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}\]

    if -1.0647680349542202e-112 < re

    1. Initial program 30.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. Simplified30.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -2.849551058941963 \cdot 10^{+146}:\\ \;\;\;\;\log \left(e^{-\frac{\log \left(\frac{-1}{re}\right)}{\log base}}\right)\\ \mathbf{elif}\;re \leq -1.0647680349542202 \cdot 10^{-112}:\\ \;\;\;\;\frac{\log \left(\sqrt{\sqrt[3]{re \cdot re + im \cdot im} \cdot \left(\sqrt[3]{re \cdot re + im \cdot im} \cdot \sqrt[3]{re \cdot re + im \cdot im}\right)}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]

Reproduce

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