Average Error: 32.2 → 17.6
Time: 5.0s
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 -6.103568674686091 \cdot 10^{+152}:\\ \;\;\;\;\frac{0.5}{\frac{\log base}{\log \left(\frac{-1}{re}\right) \cdot -2}}\\ \mathbf{elif}\;re \leq 7.28857737127815 \cdot 10^{+119}:\\ \;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{\frac{\log base}{2 \cdot \log re}}\\ \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 -6.103568674686091 \cdot 10^{+152}:\\
\;\;\;\;\frac{0.5}{\frac{\log base}{\log \left(\frac{-1}{re}\right) \cdot -2}}\\

\mathbf{elif}\;re \leq 7.28857737127815 \cdot 10^{+119}:\\
\;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base}\\

\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\frac{\log base}{2 \cdot \log re}}\\

\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 -6.103568674686091e+152)
   (/ 0.5 (/ (log base) (* (log (/ -1.0 re)) -2.0)))
   (if (<= re 7.28857737127815e+119)
     (/
      (+
       (* (log base) (log (sqrt (+ (* re re) (* im im)))))
       (* (atan2 im re) 0.0))
      (* (log base) (log base)))
     (/ 0.5 (/ (log base) (* 2.0 (log re)))))))
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 <= -6.103568674686091e+152) {
		tmp = 0.5 / (log(base) / (log(-1.0 / re) * -2.0));
	} else if (re <= 7.28857737127815e+119) {
		tmp = ((log(base) * log(sqrt((re * re) + (im * im)))) + (atan2(im, re) * 0.0)) / (log(base) * log(base));
	} else {
		tmp = 0.5 / (log(base) / (2.0 * log(re)));
	}
	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 < -6.1035686746860911e152

    1. Initial program 63.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. Simplified63.8

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Using strategy rm
    4. Applied pow1/2_binary6463.8

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

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

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

      \[\leadsto \frac{0.5}{\frac{\log base}{\color{blue}{-2 \cdot \log \left(\frac{-1}{re}\right)}}}\]
    8. Simplified7.5

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

    if -6.1035686746860911e152 < re < 7.28857737127814954e119

    1. Initial program 21.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}\]

    if 7.28857737127814954e119 < re

    1. Initial program 55.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. Simplified55.7

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Using strategy rm
    4. Applied pow1/2_binary6455.7

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

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

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

      \[\leadsto \frac{0.5}{\frac{\log base}{\color{blue}{-2 \cdot \log \left(\frac{1}{re}\right)}}}\]
    8. Simplified8.7

      \[\leadsto \frac{0.5}{\frac{\log base}{\color{blue}{2 \cdot \log re}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification17.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -6.103568674686091 \cdot 10^{+152}:\\ \;\;\;\;\frac{0.5}{\frac{\log base}{\log \left(\frac{-1}{re}\right) \cdot -2}}\\ \mathbf{elif}\;re \leq 7.28857737127815 \cdot 10^{+119}:\\ \;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{\frac{\log base}{2 \cdot \log re}}\\ \end{array}\]

Reproduce

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