Average Error: 32.0 → 9.3
Time: 7.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} \mathbf{if}\;im \leq 1.413754253679529 \cdot 10^{-168}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;im \leq 1.6664187845870407 \cdot 10^{-131}:\\ \;\;\;\;\frac{\log \left(im + 0.5 \cdot \frac{re \cdot re}{im}\right)}{\log base}\\ \mathbf{elif}\;im \leq 4.608408956128725 \cdot 10^{-66}:\\ \;\;\;\;\frac{1}{\frac{\log base}{\log \left(-re\right)}}\\ \mathbf{elif}\;im \leq 3.5143106717443304 \cdot 10^{+63}:\\ \;\;\;\;0.5 \cdot \frac{\log \left(re \cdot re + im \cdot im\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}\;im \leq 1.413754253679529 \cdot 10^{-168}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\

\mathbf{elif}\;im \leq 1.6664187845870407 \cdot 10^{-131}:\\
\;\;\;\;\frac{\log \left(im + 0.5 \cdot \frac{re \cdot re}{im}\right)}{\log base}\\

\mathbf{elif}\;im \leq 4.608408956128725 \cdot 10^{-66}:\\
\;\;\;\;\frac{1}{\frac{\log base}{\log \left(-re\right)}}\\

\mathbf{elif}\;im \leq 3.5143106717443304 \cdot 10^{+63}:\\
\;\;\;\;0.5 \cdot \frac{\log \left(re \cdot re + im \cdot im\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 (<= im 1.413754253679529e-168)
   (/ (log (- re)) (log base))
   (if (<= im 1.6664187845870407e-131)
     (/ (log (+ im (* 0.5 (/ (* re re) im)))) (log base))
     (if (<= im 4.608408956128725e-66)
       (/ 1.0 (/ (log base) (log (- re))))
       (if (<= im 3.5143106717443304e+63)
         (* 0.5 (/ (log (+ (* 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 (im <= 1.413754253679529e-168) {
		tmp = log(-re) / log(base);
	} else if (im <= 1.6664187845870407e-131) {
		tmp = log(im + (0.5 * ((re * re) / im))) / log(base);
	} else if (im <= 4.608408956128725e-66) {
		tmp = 1.0 / (log(base) / log(-re));
	} else if (im <= 3.5143106717443304e+63) {
		tmp = 0.5 * (log((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 5 regimes
  2. if im < 1.41375425367952904e-168

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

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

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

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

    if 1.41375425367952904e-168 < im < 1.6664187845870407e-131

    1. Initial program 17.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. Simplified17.9

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

      \[\leadsto \frac{\log \color{blue}{\left(0.5 \cdot \frac{{re}^{2}}{im} + im\right)}}{\log base}\]
    4. Simplified35.7

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

    if 1.6664187845870407e-131 < im < 4.6084089561287249e-66

    1. Initial program 12.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. Simplified12.5

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

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

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

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

    if 4.6084089561287249e-66 < im < 3.5143106717443304e63

    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. Using strategy rm
    4. Applied pow1_binary6411.8

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

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\color{blue}{1 \cdot \log base}}\]
    6. Applied pow1_binary6411.8

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{{\left(re \cdot re + im \cdot im\right)}^{1}}}\right)}{1 \cdot \log base}\]
    7. Applied sqrt-pow1_binary6411.8

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

      \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot \log \left(re \cdot re + im \cdot im\right)}}{1 \cdot \log base}\]
    9. Applied times-frac_binary6411.8

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

    if 3.5143106717443304e63 < im

    1. Initial program 45.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. Simplified45.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.413754253679529 \cdot 10^{-168}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;im \leq 1.6664187845870407 \cdot 10^{-131}:\\ \;\;\;\;\frac{\log \left(im + 0.5 \cdot \frac{re \cdot re}{im}\right)}{\log base}\\ \mathbf{elif}\;im \leq 4.608408956128725 \cdot 10^{-66}:\\ \;\;\;\;\frac{1}{\frac{\log base}{\log \left(-re\right)}}\\ \mathbf{elif}\;im \leq 3.5143106717443304 \cdot 10^{+63}:\\ \;\;\;\;0.5 \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]

Alternatives

Reproduce

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