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

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

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1}_* \frac{im}{re} \cdot 0 + \log base \cdot \log re}{{\left(\log base\right)}^{4} - {0}^{4}} \cdot \left(\log base \cdot \log base - 0 \cdot 0\right)\\

\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 (/ -1.0 re)) (log base)))
   (if (<= re -4.337372021152796e-262)
     (/
      (/
       (+
        (* (log base) (log (sqrt (+ (* re re) (* im im)))))
        (* (atan2 im re) 0.0))
       (sqrt (+ (pow (log base) 2.0) (* 0.0 0.0))))
      (sqrt (+ (* 0.0 0.0) (* (log base) (log base)))))
     (if (<= re 8.950330598317258e-276)
       (/ (log im) (log base))
       (if (<= re 2.5362193761446767e+35)
         (/
          (/
           (+
            (* (log base) (log (sqrt (+ (* re re) (* im im)))))
            (* (atan2 im re) 0.0))
           (sqrt (+ (pow (log base) 2.0) (* 0.0 0.0))))
          (sqrt (+ (* 0.0 0.0) (* (log base) (log base)))))
         (*
          (/
           (+ (* (atan2 im re) 0.0) (* (log base) (log re)))
           (- (pow (log base) 4.0) (pow 0.0 4.0)))
          (- (* (log base) (log base)) (* 0.0 0.0))))))))
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) -((((double) log((-1.0 / re))) / ((double) log(base)))));
	} else {
		double tmp_1;
		if ((re <= -4.337372021152796e-262)) {
			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) sqrt(((double) (((double) pow(((double) log(base)), 2.0)) + ((double) (0.0 * 0.0))))))) / ((double) sqrt(((double) (((double) (0.0 * 0.0)) + ((double) (((double) log(base)) * ((double) log(base)))))))));
		} 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) (((double) log(base)) * ((double) log(((double) sqrt(((double) (((double) (re * re)) + ((double) (im * im)))))))))) + ((double) (((double) atan2(im, re)) * 0.0)))) / ((double) sqrt(((double) (((double) pow(((double) log(base)), 2.0)) + ((double) (0.0 * 0.0))))))) / ((double) sqrt(((double) (((double) (0.0 * 0.0)) + ((double) (((double) log(base)) * ((double) log(base)))))))));
				} else {
					tmp_3 = ((double) ((((double) (((double) (((double) atan2(im, re)) * 0.0)) + ((double) (((double) log(base)) * ((double) log(re)))))) / ((double) (((double) pow(((double) log(base)), 4.0)) - ((double) pow(0.0, 4.0))))) * ((double) (((double) (((double) log(base)) * ((double) log(base)))) - ((double) (0.0 * 0.0))))));
				}
				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. 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. Simplified11.1

      \[\leadsto \color{blue}{-\frac{\log \left(\frac{-1}{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 add-sqr-sqrt_binary6421.9

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

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

      \[\leadsto \frac{\color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}}}}{\sqrt{\log base \cdot \log base + 0 \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. Taylor expanded around 0 30.9

      \[\leadsto \color{blue}{\frac{\log 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. Using strategy rm
    3. Applied flip-+_binary6443.2

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

      \[\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 \cdot \log base\right) \cdot \left(\log base \cdot \log base\right) - \left(0 \cdot 0\right) \cdot \left(0 \cdot 0\right)} \cdot \left(\log base \cdot \log base - 0 \cdot 0\right)}\]
    5. Simplified43.2

      \[\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(\log base \cdot \log base - 0 \cdot 0\right)\]
    6. Taylor expanded around inf 11.7

      \[\leadsto \frac{\log \color{blue}{re} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{{\left(\log base\right)}^{4} - {0}^{4}} \cdot \left(\log base \cdot \log base - 0 \cdot 0\right)\]
  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(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;re \leq -4.337372021152796 \cdot 10^{-262}:\\ \;\;\;\;\frac{\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}}}{\sqrt{0 \cdot 0 + \log base \cdot \log base}}\\ \mathbf{elif}\;re \leq 8.950330598317258 \cdot 10^{-276}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \mathbf{elif}\;re \leq 2.5362193761446767 \cdot 10^{+35}:\\ \;\;\;\;\frac{\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + \tan^{-1}_* \frac{im}{re} \cdot 0}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}}}{\sqrt{0 \cdot 0 + \log base \cdot \log base}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan^{-1}_* \frac{im}{re} \cdot 0 + \log base \cdot \log re}{{\left(\log base\right)}^{4} - {0}^{4}} \cdot \left(\log base \cdot \log base - 0 \cdot 0\right)\\ \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))))