Average Error: 32.2 → 18.0
Time: 9.5s
Precision: binary64
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0.0}{\log base \cdot \log base + 0.0 \cdot 0.0}\]
\[\begin{array}{l} \mathbf{if}\;re \le -24361133460477.88:\\ \;\;\;\;\frac{1}{\frac{\log base}{\log 1 - \log \left(\frac{-1}{re}\right)}}\\ \mathbf{elif}\;re \le -1.2300165181090967 \cdot 10^{-307}:\\ \;\;\;\;\frac{1}{\frac{1}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0.0}{\log base \cdot \log base + 0.0 \cdot 0.0}}}\\ \mathbf{elif}\;re \le 4.0841914479429568 \cdot 10^{-190}:\\ \;\;\;\;\frac{\log 1 + \log im}{\log 1 + \log base}\\ \mathbf{elif}\;re \le 2.2360511850626944 \cdot 10^{85}:\\ \;\;\;\;\frac{1}{\frac{1}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0.0}{\log base \cdot \log base + 0.0 \cdot 0.0}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log re}{0 + \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.0}{\log base \cdot \log base + 0.0 \cdot 0.0}
\begin{array}{l}
\mathbf{if}\;re \le -24361133460477.88:\\
\;\;\;\;\frac{1}{\frac{\log base}{\log 1 - \log \left(\frac{-1}{re}\right)}}\\

\mathbf{elif}\;re \le -1.2300165181090967 \cdot 10^{-307}:\\
\;\;\;\;\frac{1}{\frac{1}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0.0}{\log base \cdot \log base + 0.0 \cdot 0.0}}}\\

\mathbf{elif}\;re \le 4.0841914479429568 \cdot 10^{-190}:\\
\;\;\;\;\frac{\log 1 + \log im}{\log 1 + \log base}\\

\mathbf{elif}\;re \le 2.2360511850626944 \cdot 10^{85}:\\
\;\;\;\;\frac{1}{\frac{1}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0.0}{\log base \cdot \log base + 0.0 \cdot 0.0}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\log re}{0 + \log base}\\

\end{array}
double code(double re, double im, double base) {
	return ((double) (((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 VAR;
	if ((re <= -24361133460477.875)) {
		VAR = ((double) (1.0 / ((double) (((double) log(base)) / ((double) (((double) log(1.0)) - ((double) log(((double) (-1.0 / re))))))))));
	} else {
		double VAR_1;
		if ((re <= -1.2300165181090967e-307)) {
			VAR_1 = ((double) (1.0 / ((double) (1.0 / ((double) (((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))))))))));
		} else {
			double VAR_2;
			if ((re <= 4.084191447942957e-190)) {
				VAR_2 = ((double) (((double) (((double) log(1.0)) + ((double) log(im)))) / ((double) (((double) log(1.0)) + ((double) log(base))))));
			} else {
				double VAR_3;
				if ((re <= 2.2360511850626944e+85)) {
					VAR_3 = ((double) (1.0 / ((double) (1.0 / ((double) (((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))))))))));
				} else {
					VAR_3 = ((double) (((double) log(re)) / ((double) (0.0 + ((double) log(base))))));
				}
				VAR_2 = VAR_3;
			}
			VAR_1 = VAR_2;
		}
		VAR = VAR_1;
	}
	return VAR;
}

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 < -24361133460477.88

    1. Initial program 42.3

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0.0}{\log base \cdot \log base + 0.0 \cdot 0.0}\]
    2. Using strategy rm
    3. Applied clear-num42.3

      \[\leadsto \color{blue}{\frac{1}{\frac{\log base \cdot \log base + 0.0 \cdot 0.0}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0.0}}}\]
    4. Taylor expanded around -inf 64.0

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

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

    if -24361133460477.88 < re < -1.2300165181090967e-307 or 4.0841914479429568e-190 < re < 2.2360511850626944e85

    1. Initial program 20.6

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0.0}{\log base \cdot \log base + 0.0 \cdot 0.0}\]
    2. Using strategy rm
    3. Applied clear-num20.6

      \[\leadsto \color{blue}{\frac{1}{\frac{\log base \cdot \log base + 0.0 \cdot 0.0}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0.0}}}\]
    4. Using strategy rm
    5. Applied clear-num20.6

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

    if -1.2300165181090967e-307 < re < 4.0841914479429568e-190

    1. Initial program 32.1

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0.0}{\log base \cdot \log base + 0.0 \cdot 0.0}\]
    2. Taylor expanded around 0 33.6

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

    if 2.2360511850626944e85 < re

    1. Initial program 50.1

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0.0}{\log base \cdot \log base + 0.0 \cdot 0.0}\]
    2. Taylor expanded around inf 10.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -24361133460477.88:\\ \;\;\;\;\frac{1}{\frac{\log base}{\log 1 - \log \left(\frac{-1}{re}\right)}}\\ \mathbf{elif}\;re \le -1.2300165181090967 \cdot 10^{-307}:\\ \;\;\;\;\frac{1}{\frac{1}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0.0}{\log base \cdot \log base + 0.0 \cdot 0.0}}}\\ \mathbf{elif}\;re \le 4.0841914479429568 \cdot 10^{-190}:\\ \;\;\;\;\frac{\log 1 + \log im}{\log 1 + \log base}\\ \mathbf{elif}\;re \le 2.2360511850626944 \cdot 10^{85}:\\ \;\;\;\;\frac{1}{\frac{1}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0.0}{\log base \cdot \log base + 0.0 \cdot 0.0}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log re}{0 + \log base}\\ \end{array}\]

Reproduce

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