Average Error: 31.0 → 17.7
Time: 5.9s
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 -3.3734405662222592 \cdot 10^{+121}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;re \leq -7.823143127285978 \cdot 10^{-193}:\\ \;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}{\left(\log base \cdot \log \left(\sqrt[3]{base}\right) + 2 \cdot \left(\log base \cdot \log \left(\sqrt[3]{base}\right)\right)\right) + 0 \cdot 0}\\ \mathbf{elif}\;re \leq -1.5821814501140232 \cdot 10^{-267}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \mathbf{elif}\;re \leq 800712819.842004:\\ \;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}{\left(\log base \cdot \log \left(\sqrt[3]{base}\right) + 2 \cdot \left(\log base \cdot \log \left(\sqrt[3]{base}\right)\right)\right) + 0 \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 -3.3734405662222592 \cdot 10^{+121}:\\
\;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\

\mathbf{elif}\;re \leq -7.823143127285978 \cdot 10^{-193}:\\
\;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}{\left(\log base \cdot \log \left(\sqrt[3]{base}\right) + 2 \cdot \left(\log base \cdot \log \left(\sqrt[3]{base}\right)\right)\right) + 0 \cdot 0}\\

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

\mathbf{elif}\;re \leq 800712819.842004:\\
\;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}{\left(\log base \cdot \log \left(\sqrt[3]{base}\right) + 2 \cdot \left(\log base \cdot \log \left(\sqrt[3]{base}\right)\right)\right) + 0 \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 -3.3734405662222592e+121)
   (- (/ (log (/ -1.0 re)) (log base)))
   (if (<= re -7.823143127285978e-193)
     (/
      (+
       (* (log base) (log (sqrt (+ (* re re) (* im im)))))
       (* (atan2 im re) 0.0))
      (+
       (+
        (* (log base) (log (cbrt base)))
        (* 2.0 (* (log base) (log (cbrt base)))))
       (* 0.0 0.0)))
     (if (<= re -1.5821814501140232e-267)
       (/ (log im) (log base))
       (if (<= re 800712819.842004)
         (/
          (+
           (* (log base) (log (sqrt (+ (* re re) (* im im)))))
           (* (atan2 im re) 0.0))
          (+
           (+
            (* (log base) (log (cbrt base)))
            (* 2.0 (* (log base) (log (cbrt base)))))
           (* 0.0 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 <= -3.3734405662222592e+121)) {
		tmp = ((double) -((((double) log((-1.0 / re))) / ((double) log(base)))));
	} else {
		double tmp_1;
		if ((re <= -7.823143127285978e-193)) {
			tmp_1 = (((double) (((double) (((double) log(base)) * ((double) log(((double) sqrt(((double) (((double) (re * re)) + ((double) (im * im)))))))))) + ((double) (((double) atan2(im, re)) * 0.0)))) / ((double) (((double) (((double) (((double) log(base)) * ((double) log(((double) cbrt(base)))))) + ((double) (2.0 * ((double) (((double) log(base)) * ((double) log(((double) cbrt(base)))))))))) + ((double) (0.0 * 0.0)))));
		} else {
			double tmp_2;
			if ((re <= -1.5821814501140232e-267)) {
				tmp_2 = (((double) log(im)) / ((double) log(base)));
			} else {
				double tmp_3;
				if ((re <= 800712819.842004)) {
					tmp_3 = (((double) (((double) (((double) log(base)) * ((double) log(((double) sqrt(((double) (((double) (re * re)) + ((double) (im * im)))))))))) + ((double) (((double) atan2(im, re)) * 0.0)))) / ((double) (((double) (((double) (((double) log(base)) * ((double) log(((double) cbrt(base)))))) + ((double) (2.0 * ((double) (((double) log(base)) * ((double) log(((double) cbrt(base)))))))))) + ((double) (0.0 * 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 < -3.37344056622225924e121

    1. Initial program 55.5

      \[\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 64.0

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

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

    if -3.37344056622225924e121 < re < -7.82314312728597759e-193 or -1.58218145011402322e-267 < re < 800712819.842003942

    1. Initial program 20.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. Using strategy rm
    3. Applied add-cube-cbrt_binary6420.8

      \[\leadsto \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 \color{blue}{\left(\left(\sqrt[3]{base} \cdot \sqrt[3]{base}\right) \cdot \sqrt[3]{base}\right)} + 0 \cdot 0}\]
    4. Applied log-prod_binary6420.8

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

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

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

    if -7.82314312728597759e-193 < re < -1.58218145011402322e-267

    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. Taylor expanded around 0 33.6

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

    if 800712819.842003942 < re

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

      \[\leadsto \color{blue}{\frac{\log \left(\frac{1}{re}\right)}{\log \left(\frac{1}{base}\right)}}\]
    3. Simplified12.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -3.3734405662222592 \cdot 10^{+121}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;re \leq -7.823143127285978 \cdot 10^{-193}:\\ \;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}{\left(\log base \cdot \log \left(\sqrt[3]{base}\right) + 2 \cdot \left(\log base \cdot \log \left(\sqrt[3]{base}\right)\right)\right) + 0 \cdot 0}\\ \mathbf{elif}\;re \leq -1.5821814501140232 \cdot 10^{-267}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \mathbf{elif}\;re \leq 800712819.842004:\\ \;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}{\left(\log base \cdot \log \left(\sqrt[3]{base}\right) + 2 \cdot \left(\log base \cdot \log \left(\sqrt[3]{base}\right)\right)\right) + 0 \cdot 0}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log re}{\log base}\\ \end{array}\]

Reproduce

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