Average Error: 32.0 → 17.6
Time: 6.8s
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.831379490668168 \cdot 10^{+128}:\\ \;\;\;\;\frac{\log 1 - \log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;re \leq 4.068189076745448 \cdot 10^{-198}:\\ \;\;\;\;\frac{1}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}} \cdot \frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + 0 \cdot \tan^{-1}_* \frac{im}{re}}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}}\\ \mathbf{elif}\;re \leq 1.4945202169127629 \cdot 10^{-146}:\\ \;\;\;\;\frac{\log 1 + \log im}{\log base}\\ \mathbf{elif}\;re \leq 4.616174933667185 \cdot 10^{+120}:\\ \;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + 0 \cdot \tan^{-1}_* \frac{im}{re}}{0 \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)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}} \cdot \frac{0 \cdot \tan^{-1}_* \frac{im}{re} + \log base \cdot \log re}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}}\\ \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.831379490668168 \cdot 10^{+128}:\\
\;\;\;\;\frac{\log 1 - \log \left(\frac{-1}{re}\right)}{\log base}\\

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

\mathbf{elif}\;re \leq 1.4945202169127629 \cdot 10^{-146}:\\
\;\;\;\;\frac{\log 1 + \log im}{\log base}\\

\mathbf{elif}\;re \leq 4.616174933667185 \cdot 10^{+120}:\\
\;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + 0 \cdot \tan^{-1}_* \frac{im}{re}}{0 \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)}\\

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

\end{array}
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 VAR;
	if ((re <= -1.831379490668168e+128)) {
		VAR = (((double) (((double) log(1.0)) - ((double) log((-1.0 / re))))) / ((double) log(base)));
	} else {
		double VAR_1;
		if ((re <= 4.068189076745448e-198)) {
			VAR_1 = ((double) ((1.0 / ((double) sqrt(((double) (((double) pow(((double) log(base)), 2.0)) + ((double) (0.0 * 0.0))))))) * (((double) (((double) (((double) log(base)) * ((double) log(((double) sqrt(((double) (((double) (re * re)) + ((double) (im * im)))))))))) + ((double) (0.0 * ((double) atan2(im, re)))))) / ((double) sqrt(((double) (((double) pow(((double) log(base)), 2.0)) + ((double) (0.0 * 0.0)))))))));
		} else {
			double VAR_2;
			if ((re <= 1.4945202169127629e-146)) {
				VAR_2 = (((double) (((double) log(1.0)) + ((double) log(im)))) / ((double) log(base)));
			} else {
				double VAR_3;
				if ((re <= 4.616174933667185e+120)) {
					VAR_3 = (((double) (((double) (((double) log(base)) * ((double) log(((double) sqrt(((double) (((double) (re * re)) + ((double) (im * im)))))))))) + ((double) (0.0 * ((double) atan2(im, re)))))) / ((double) (((double) (0.0 * 0.0)) + ((double) (((double) (((double) log(base)) * ((double) log(((double) cbrt(base)))))) + ((double) (2.0 * ((double) (((double) log(base)) * ((double) log(((double) cbrt(base)))))))))))));
				} else {
					VAR_3 = ((double) ((1.0 / ((double) sqrt(((double) (((double) pow(((double) log(base)), 2.0)) + ((double) (0.0 * 0.0))))))) * (((double) (((double) (0.0 * ((double) atan2(im, re)))) + ((double) (((double) log(base)) * ((double) log(re)))))) / ((double) sqrt(((double) (((double) pow(((double) log(base)), 2.0)) + ((double) (0.0 * 0.0)))))))));
				}
				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 5 regimes
  2. if re < -1.8313794906681681e128

    1. Initial program Error: 57.6 bits

      \[\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 Error: 64.0 bits

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

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

    if -1.8313794906681681e128 < re < 4.0681890767454483e-198

    1. Initial program Error: 23.0 bits

      \[\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-sqrtError: 23.0 bits

      \[\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 *-un-lft-identityError: 23.0 bits

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0\right)}}{\sqrt{\log base \cdot \log base + 0 \cdot 0} \cdot \sqrt{\log base \cdot \log base + 0 \cdot 0}}\]
    5. Applied times-fracError: 23.0 bits

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\log base \cdot \log base + 0 \cdot 0}} \cdot \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}}}\]
    6. SimplifiedError: 23.0 bits

      \[\leadsto \color{blue}{\frac{1}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}}} \cdot \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}}\]
    7. SimplifiedError: 23.0 bits

      \[\leadsto \frac{1}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}} \cdot \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}}}\]

    if 4.0681890767454483e-198 < re < 1.49452021691276288e-146

    1. Initial program Error: 28.9 bits

      \[\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 Error: 38.3 bits

      \[\leadsto \color{blue}{\frac{\log 1 + \log im}{\log 1 + \log base}}\]
    3. SimplifiedError: 38.3 bits

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

    if 1.49452021691276288e-146 < re < 4.6161749336671851e120

    1. Initial program Error: 15.9 bits

      \[\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-cbrtError: 15.9 bits

      \[\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-prodError: 15.9 bits

      \[\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-inError: 15.9 bits

      \[\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. SimplifiedError: 15.9 bits

      \[\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 4.6161749336671851e120 < re

    1. Initial program Error: 55.9 bits

      \[\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-sqrtError: 55.9 bits

      \[\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 *-un-lft-identityError: 55.9 bits

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0\right)}}{\sqrt{\log base \cdot \log base + 0 \cdot 0} \cdot \sqrt{\log base \cdot \log base + 0 \cdot 0}}\]
    5. Applied times-fracError: 55.9 bits

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\log base \cdot \log base + 0 \cdot 0}} \cdot \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}}}\]
    6. SimplifiedError: 55.9 bits

      \[\leadsto \color{blue}{\frac{1}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}}} \cdot \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}}\]
    7. SimplifiedError: 55.9 bits

      \[\leadsto \frac{1}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}} \cdot \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}}}\]
    8. Taylor expanded around inf Error: 7.3 bits

      \[\leadsto \frac{1}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}} \cdot \frac{\log \color{blue}{re} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}}\]
  3. Recombined 5 regimes into one program.
  4. Final simplificationError: 17.6 bits

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.831379490668168 \cdot 10^{+128}:\\ \;\;\;\;\frac{\log 1 - \log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;re \leq 4.068189076745448 \cdot 10^{-198}:\\ \;\;\;\;\frac{1}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}} \cdot \frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + 0 \cdot \tan^{-1}_* \frac{im}{re}}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}}\\ \mathbf{elif}\;re \leq 1.4945202169127629 \cdot 10^{-146}:\\ \;\;\;\;\frac{\log 1 + \log im}{\log base}\\ \mathbf{elif}\;re \leq 4.616174933667185 \cdot 10^{+120}:\\ \;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right) + 0 \cdot \tan^{-1}_* \frac{im}{re}}{0 \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)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}} \cdot \frac{0 \cdot \tan^{-1}_* \frac{im}{re} + \log base \cdot \log re}{\sqrt{{\left(\log base\right)}^{2} + 0 \cdot 0}}\\ \end{array}\]

Reproduce

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