Average Error: 31.0 → 17.6
Time: 7.4s
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.5736914859440464 \cdot 10^{+121}:\\ \;\;\;\;\frac{\log 1 - \log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;re \leq -7.823143127285978 \cdot 10^{-193}:\\ \;\;\;\;\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 -2.1434906871881392 \cdot 10^{-263}:\\ \;\;\;\;\frac{\log 1 + \log im}{\log base}\\ \mathbf{elif}\;re \leq 800712819.842004:\\ \;\;\;\;\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{\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.5736914859440464 \cdot 10^{+121}:\\
\;\;\;\;\frac{\log 1 - \log \left(\frac{-1}{re}\right)}{\log base}\\

\mathbf{elif}\;re \leq -7.823143127285978 \cdot 10^{-193}:\\
\;\;\;\;\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 -2.1434906871881392 \cdot 10^{-263}:\\
\;\;\;\;\frac{\log 1 + \log im}{\log base}\\

\mathbf{elif}\;re \leq 800712819.842004:\\
\;\;\;\;\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{\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.5736914859440464e+121)
   (/ (- (log 1.0) (log (/ -1.0 re))) (log base))
   (if (<= re -7.823143127285978e-193)
     (/
      (/
       (+
        (* (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 -2.1434906871881392e-263)
       (/ (+ (log 1.0) (log im)) (log base))
       (if (<= re 800712819.842004)
         (/
          (/
           (+
            (* (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)))))
         (/ (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.5736914859440464e+121)) {
		tmp = (((double) (((double) log(1.0)) - ((double) log((-1.0 / re))))) / ((double) log(base)));
	} else {
		double tmp_1;
		if ((re <= -7.823143127285978e-193)) {
			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 <= -2.1434906871881392e-263)) {
				tmp_2 = (((double) (((double) log(1.0)) + ((double) log(im)))) / ((double) log(base)));
			} else {
				double tmp_3;
				if ((re <= 800712819.842004)) {
					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) 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.57369148594404645e121

    1. Initial program Error: 55.4 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.3 bits

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

    if -1.57369148594404645e121 < re < -7.82314312728597759e-193 or -2.14349068718813924e-263 < re < 800712819.842003942

    1. Initial program Error: 20.8 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: 20.8 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 associate-/r*Error: 20.8 bits

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

      \[\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 -7.82314312728597759e-193 < re < -2.14349068718813924e-263

    1. Initial program Error: 32.7 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: 33.1 bits

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

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

    if 800712819.842003942 < re

    1. Initial program Error: 39.2 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: 12.4 bits

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

      \[\leadsto \color{blue}{\frac{\log re}{\log base}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplificationError: 17.6 bits

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.5736914859440464 \cdot 10^{+121}:\\ \;\;\;\;\frac{\log 1 - \log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;re \leq -7.823143127285978 \cdot 10^{-193}:\\ \;\;\;\;\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 -2.1434906871881392 \cdot 10^{-263}:\\ \;\;\;\;\frac{\log 1 + \log im}{\log base}\\ \mathbf{elif}\;re \leq 800712819.842004:\\ \;\;\;\;\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{\log re}{\log base}\\ \end{array}\]

Reproduce

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