Average Error: 31.6 → 18.5
Time: 6.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.506084148724459 \cdot 10^{+120}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;re \leq -6.248145331558188 \cdot 10^{-50}:\\ \;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}{{\left(\log base\right)}^{4} - {0}^{4}} \cdot \left({\left(\log base\right)}^{2} - 0 \cdot 0\right)\\ \mathbf{elif}\;re \leq -1.267660774867362 \cdot 10^{-74}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \mathbf{elif}\;re \leq 1.702622659109618 \cdot 10^{+52}:\\ \;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}{{\left(\log base\right)}^{4} - {0}^{4}} \cdot \left({\left(\log base\right)}^{2} - 0 \cdot 0\right)\\ \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.506084148724459 \cdot 10^{+120}:\\
\;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\

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

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

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

\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.506084148724459e+120)
   (- (/ (log (/ -1.0 re)) (log base)))
   (if (<= re -6.248145331558188e-50)
     (*
      (/
       (+
        (* (log base) (log (sqrt (+ (* re re) (* im im)))))
        (* (atan2 im re) 0.0))
       (- (pow (log base) 4.0) (pow 0.0 4.0)))
      (- (pow (log base) 2.0) (* 0.0 0.0)))
     (if (<= re -1.267660774867362e-74)
       (/ (log im) (log base))
       (if (<= re 1.702622659109618e+52)
         (*
          (/
           (+
            (* (log base) (log (sqrt (+ (* re re) (* im im)))))
            (* (atan2 im re) 0.0))
           (- (pow (log base) 4.0) (pow 0.0 4.0)))
          (- (pow (log base) 2.0) (* 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 <= -1.506084148724459e+120)) {
		tmp = ((double) -((((double) log((-1.0 / re))) / ((double) log(base)))));
	} else {
		double tmp_1;
		if ((re <= -6.248145331558188e-50)) {
			tmp_1 = ((double) ((((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) pow(((double) log(base)), 4.0)) - ((double) pow(0.0, 4.0))))) * ((double) (((double) pow(((double) log(base)), 2.0)) - ((double) (0.0 * 0.0))))));
		} else {
			double tmp_2;
			if ((re <= -1.267660774867362e-74)) {
				tmp_2 = (((double) log(im)) / ((double) log(base)));
			} else {
				double tmp_3;
				if ((re <= 1.702622659109618e+52)) {
					tmp_3 = ((double) ((((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) pow(((double) log(base)), 4.0)) - ((double) pow(0.0, 4.0))))) * ((double) (((double) pow(((double) log(base)), 2.0)) - ((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 < -1.5060841487244589e120

    1. Initial program 55.1

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

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

    if -1.5060841487244589e120 < re < -6.2481453315581876e-50 or -1.267660774867362e-74 < re < 1.70262265910961788e52

    1. Initial program 22.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}\]
    2. Using strategy rm
    3. Applied div-inv_binary6422.4

      \[\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. Simplified22.4

      \[\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} + 0 \cdot 0}}\]
    5. Using strategy rm
    6. Applied flip-+_binary6422.4

      \[\leadsto \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}{\color{blue}{\frac{{\left(\log base\right)}^{2} \cdot {\left(\log base\right)}^{2} - \left(0 \cdot 0\right) \cdot \left(0 \cdot 0\right)}{{\left(\log base\right)}^{2} - 0 \cdot 0}}}\]
    7. Applied associate-/r/_binary6422.4

      \[\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}{\left(\frac{1}{{\left(\log base\right)}^{2} \cdot {\left(\log base\right)}^{2} - \left(0 \cdot 0\right) \cdot \left(0 \cdot 0\right)} \cdot \left({\left(\log base\right)}^{2} - 0 \cdot 0\right)\right)}\]
    8. Applied associate-*r*_binary6422.4

      \[\leadsto \color{blue}{\left(\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}{{\left(\log base\right)}^{2} \cdot {\left(\log base\right)}^{2} - \left(0 \cdot 0\right) \cdot \left(0 \cdot 0\right)}\right) \cdot \left({\left(\log base\right)}^{2} - 0 \cdot 0\right)}\]
    9. Simplified22.4

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

    if -6.2481453315581876e-50 < re < -1.267660774867362e-74

    1. Initial program 18.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. Taylor expanded around 0 39.4

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

    if 1.70262265910961788e52 < re

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.506084148724459 \cdot 10^{+120}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;re \leq -6.248145331558188 \cdot 10^{-50}:\\ \;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}{{\left(\log base\right)}^{4} - {0}^{4}} \cdot \left({\left(\log base\right)}^{2} - 0 \cdot 0\right)\\ \mathbf{elif}\;re \leq -1.267660774867362 \cdot 10^{-74}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \mathbf{elif}\;re \leq 1.702622659109618 \cdot 10^{+52}:\\ \;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}{{\left(\log base\right)}^{4} - {0}^{4}} \cdot \left({\left(\log base\right)}^{2} - 0 \cdot 0\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\log re}{\log base}\\ \end{array}\]

Reproduce

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