Average Error: 31.9 → 18.0
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 -1.8073559612423165 \cdot 10^{+63}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;re \leq -4.337372021152796 \cdot 10^{-262}:\\ \;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}\\ \mathbf{elif}\;re \leq 8.950330598317258 \cdot 10^{-276}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \mathbf{elif}\;re \leq 2.5362193761446767 \cdot 10^{+35}:\\ \;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}\\ \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 -1.8073559612423165 \cdot 10^{+63}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\

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

\mathbf{elif}\;re \leq 8.950330598317258 \cdot 10^{-276}:\\
\;\;\;\;\frac{\log im}{\log base}\\

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

\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 -1.8073559612423165e+63)
   (/ (log (- re)) (log base))
   (if (<= re -4.337372021152796e-262)
     (/
      (*
       (log (sqrt (+ (* re re) (* im im))))
       (log (sqrt (+ (* re re) (* im im)))))
      (+
       (* (log base) (log (sqrt (+ (* re re) (* im im)))))
       (* (atan2 im re) 0.0)))
     (if (<= re 8.950330598317258e-276)
       (/ (log im) (log base))
       (if (<= re 2.5362193761446767e+35)
         (/
          (*
           (log (sqrt (+ (* re re) (* im im))))
           (log (sqrt (+ (* re re) (* im im)))))
          (+
           (* (log base) (log (sqrt (+ (* re re) (* im im)))))
           (* (atan2 im re) 0.0)))
         (/ (log re) (log base)))))))
double code(double re, double im, double base) {
	return (((double) (((double) (((double) log(((double) sqrt(((double) (((double) (re * re)) + ((double) (im * im)))))))) * ((double) log(base)))) + ((double) (((double) atan2(im, re)) * 0.0)))) / ((double) (((double) (((double) log(base)) * ((double) log(base)))) + ((double) (0.0 * 0.0)))));
}
double code(double re, double im, double base) {
	double tmp;
	if ((re <= -1.8073559612423165e+63)) {
		tmp = (((double) log(((double) -(re)))) / ((double) log(base)));
	} else {
		double tmp_1;
		if ((re <= -4.337372021152796e-262)) {
			tmp_1 = (((double) (((double) log(((double) sqrt(((double) (((double) (re * re)) + ((double) (im * im)))))))) * ((double) log(((double) sqrt(((double) (((double) (re * re)) + ((double) (im * im)))))))))) / ((double) (((double) (((double) log(base)) * ((double) log(((double) sqrt(((double) (((double) (re * re)) + ((double) (im * im)))))))))) + ((double) (((double) atan2(im, re)) * 0.0)))));
		} else {
			double tmp_2;
			if ((re <= 8.950330598317258e-276)) {
				tmp_2 = (((double) log(im)) / ((double) log(base)));
			} else {
				double tmp_3;
				if ((re <= 2.5362193761446767e+35)) {
					tmp_3 = (((double) (((double) log(((double) sqrt(((double) (((double) (re * re)) + ((double) (im * im)))))))) * ((double) log(((double) sqrt(((double) (((double) (re * re)) + ((double) (im * im)))))))))) / ((double) (((double) (((double) log(base)) * ((double) log(((double) sqrt(((double) (((double) (re * re)) + ((double) (im * im)))))))))) + ((double) (((double) atan2(im, re)) * 0.0)))));
				} else {
					tmp_3 = (((double) log(re)) / ((double) log(base)));
				}
				tmp_2 = tmp_3;
			}
			tmp_1 = tmp_2;
		}
		tmp = tmp_1;
	}
	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 4 regimes
  2. if re < -1.80735596124231651e63

    1. Initial program 46.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. Simplified46.2

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

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

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

    if -1.80735596124231651e63 < re < -4.3373720211527962e-262 or 8.9503305983172581e-276 < re < 2.53621937614467668e35

    1. Initial program 21.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. Using strategy rm
    3. Applied div-inv_binary6421.9

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

      \[\leadsto \left(\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0\right) \cdot \color{blue}{\frac{1}{{\left(\log base\right)}^{2}}}\]
    5. Using strategy rm
    6. Applied flip-+_binary6421.9

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

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

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

    if -4.3373720211527962e-262 < re < 8.9503305983172581e-276

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

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

      \[\leadsto \frac{\log \color{blue}{im}}{\log base}\]

    if 2.53621937614467668e35 < re

    1. Initial program 43.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. Simplified43.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.8073559612423165 \cdot 10^{+63}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;re \leq -4.337372021152796 \cdot 10^{-262}:\\ \;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}\\ \mathbf{elif}\;re \leq 8.950330598317258 \cdot 10^{-276}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \mathbf{elif}\;re \leq 2.5362193761446767 \cdot 10^{+35}:\\ \;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log re}{\log base}\\ \end{array}\]

Reproduce

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