Average Error: 32.2 → 17.8
Time: 12.7s
Precision: binary64
Cost: 14146
\[\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}\;im \leq -5.775193541606794 \cdot 10^{+65}:\\ \;\;\;\;\frac{\log \left(-im\right)}{\log base}\\ \mathbf{elif}\;im \leq 6.398018456610941 \cdot 10^{+82}:\\ \;\;\;\;0.5 \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{-0.5 \cdot \frac{\log base}{-\log im}}\\ \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}\;im \leq -5.775193541606794 \cdot 10^{+65}:\\
\;\;\;\;\frac{\log \left(-im\right)}{\log base}\\

\mathbf{elif}\;im \leq 6.398018456610941 \cdot 10^{+82}:\\
\;\;\;\;0.5 \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\log base}\\

\mathbf{else}:\\
\;\;\;\;\frac{0.5}{-0.5 \cdot \frac{\log base}{-\log im}}\\

\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 (<= im -5.775193541606794e+65)
   (/ (log (- im)) (log base))
   (if (<= im 6.398018456610941e+82)
     (* 0.5 (/ (log (+ (* re re) (* im im))) (log base)))
     (/ 0.5 (* -0.5 (/ (log base) (- (log im))))))))
double code(double re, double im, double base) {
	return ((log(sqrt((re * re) + (im * im))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
}
double code(double re, double im, double base) {
	double tmp;
	if (im <= -5.775193541606794e+65) {
		tmp = log(-im) / log(base);
	} else if (im <= 6.398018456610941e+82) {
		tmp = 0.5 * (log((re * re) + (im * im)) / log(base));
	} else {
		tmp = 0.5 / (-0.5 * (log(base) / -log(im)));
	}
	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

Alternatives

Alternative 1
Error17.8
Cost14146
\[\begin{array}{l} \mathbf{if}\;im \leq -1.1003460488858435 \cdot 10^{+66}:\\ \;\;\;\;\frac{\log \left(-im\right)}{\log base}\\ \mathbf{elif}\;im \leq 3.872290499114305 \cdot 10^{+79}:\\ \;\;\;\;\frac{0.5}{\frac{\log base}{\log \left(re \cdot re + im \cdot im\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]
Alternative 2
Error25.5
Cost14532
\[\begin{array}{l} \mathbf{if}\;im \leq -7.602092955966798 \cdot 10^{-69}:\\ \;\;\;\;\frac{\log \left(-im\right)}{\log base}\\ \mathbf{elif}\;im \leq -2.209684678500573 \cdot 10^{-195}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;im \leq -3.1529758544172198 \cdot 10^{-267}:\\ \;\;\;\;\frac{\log re}{\log base}\\ \mathbf{elif}\;im \leq 3.566774754745039 \cdot 10^{+53}:\\ \;\;\;\;\frac{0.5}{\frac{\log base}{\log \left(re \cdot re\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]
Alternative 3
Error25.8
Cost15239
\[\begin{array}{l} \mathbf{if}\;im \leq -6.993069225899243 \cdot 10^{-67}:\\ \;\;\;\;\frac{\log \left(-im\right)}{\log base}\\ \mathbf{elif}\;im \leq -6.356426208317572 \cdot 10^{-194}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;im \leq -3.773241576281863 \cdot 10^{-267}:\\ \;\;\;\;\frac{\log re}{\log base}\\ \mathbf{elif}\;im \leq 3.2243445988748503 \cdot 10^{-267}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;im \leq 6.260590942950154 \cdot 10^{-156}:\\ \;\;\;\;\frac{\log re}{\log base}\\ \mathbf{elif}\;im \leq 2.0817400427423985 \cdot 10^{-108}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;im \leq 3.566774754745039 \cdot 10^{+53}:\\ \;\;\;\;\frac{\log re}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]
Alternative 4
Error26.9
Cost13773
\[\begin{array}{l} \mathbf{if}\;im \leq -4.747324768854928 \cdot 10^{-98}:\\ \;\;\;\;\frac{\log \left(-im\right)}{\log base}\\ \mathbf{elif}\;im \leq 4.1472290625588017 \cdot 10^{-156} \lor \neg \left(im \leq 6.371292140426413 \cdot 10^{-107}\right) \land im \leq 3.566774754745039 \cdot 10^{+53}:\\ \;\;\;\;\frac{\log re}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]
Alternative 5
Error36.5
Cost13634
\[\begin{array}{l} \mathbf{if}\;re \leq -0.009642333378035816:\\ \;\;\;\;-1\\ \mathbf{elif}\;re \leq 7.939738554125723 \cdot 10^{-107}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log re}{\log base}\\ \end{array}\]
Alternative 6
Error43.7
Cost13313
\[\begin{array}{l} \mathbf{if}\;re \leq 5.06454586808178 \cdot 10^{-309}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{\log re}{\log base}\\ \end{array}\]
Alternative 7
Error54.4
Cost385
\[\begin{array}{l} \mathbf{if}\;base \leq 42.7275721746072:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 8
Error57.3
Cost64
\[1\]

Error

Derivation

  1. Split input into 3 regimes
  2. if im < -5.77519354160679366e65

    1. Initial program 46.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. Simplified46.4

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Taylor expanded around -inf 10.0

      \[\leadsto \frac{\log \color{blue}{\left(-1 \cdot im\right)}}{\log base}\]
    4. Simplified10.0

      \[\leadsto \frac{\log \color{blue}{\left(-im\right)}}{\log base}\]
    5. Simplified10.0

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

    if -5.77519354160679366e65 < im < 6.39801845661094094e82

    1. Initial program 22.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. Simplified22.5

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Using strategy rm
    4. Applied pow1_binary64_13922.5

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log \color{blue}{\left({base}^{1}\right)}}\]
    5. Applied log-pow_binary64_16722.5

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\color{blue}{1 \cdot \log base}}\]
    6. Applied pow1/2_binary64_15822.5

      \[\leadsto \frac{\log \color{blue}{\left({\left(re \cdot re + im \cdot im\right)}^{0.5}\right)}}{1 \cdot \log base}\]
    7. Applied log-pow_binary64_16722.5

      \[\leadsto \frac{\color{blue}{0.5 \cdot \log \left(re \cdot re + im \cdot im\right)}}{1 \cdot \log base}\]
    8. Applied times-frac_binary64_8422.5

      \[\leadsto \color{blue}{\frac{0.5}{1} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\log base}}\]
    9. Simplified22.5

      \[\leadsto \color{blue}{0.5} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\log base}\]
    10. Simplified22.5

      \[\leadsto \color{blue}{0.5 \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\log base}}\]

    if 6.39801845661094094e82 < im

    1. Initial program 49.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. Simplified49.3

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Using strategy rm
    4. Applied pow1/2_binary64_15849.3

      \[\leadsto \frac{\log \color{blue}{\left({\left(re \cdot re + im \cdot im\right)}^{0.5}\right)}}{\log base}\]
    5. Applied log-pow_binary64_16749.3

      \[\leadsto \frac{\color{blue}{0.5 \cdot \log \left(re \cdot re + im \cdot im\right)}}{\log base}\]
    6. Applied associate-/l*_binary64_2349.3

      \[\leadsto \color{blue}{\frac{0.5}{\frac{\log base}{\log \left(re \cdot re + im \cdot im\right)}}}\]
    7. Taylor expanded around inf 10.4

      \[\leadsto \frac{0.5}{\color{blue}{-0.5 \cdot \frac{\log base}{\log \left(\frac{1}{im}\right)}}}\]
    8. Simplified10.4

      \[\leadsto \frac{0.5}{\color{blue}{-0.5 \cdot \frac{\log base}{-\log im}}}\]
    9. Simplified10.4

      \[\leadsto \color{blue}{\frac{0.5}{-0.5 \cdot \frac{\log base}{-\log im}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification17.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -5.775193541606794 \cdot 10^{+65}:\\ \;\;\;\;\frac{\log \left(-im\right)}{\log base}\\ \mathbf{elif}\;im \leq 6.398018456610941 \cdot 10^{+82}:\\ \;\;\;\;0.5 \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{-0.5 \cdot \frac{\log base}{-\log im}}\\ \end{array}\]

Reproduce

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