Average Error: 32.2 → 7.5
Time: 9.3s
Precision: binary64
\[[re, im]=\mathsf{sort}([re, im])\]
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
\[\begin{array}{l} t_0 := \sqrt{\log 10}\\ \mathbf{if}\;im \leq 1.354460185570906 \cdot 10^{-149}:\\ \;\;\;\;\frac{1}{t_0} \cdot \frac{\log \left(-re\right)}{t_0}\\ \mathbf{elif}\;im \leq 5.205359642473407 \cdot 10^{+89}:\\ \;\;\;\;\frac{0.5}{t_0} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log 10}\\ \end{array} \]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\begin{array}{l}
t_0 := \sqrt{\log 10}\\
\mathbf{if}\;im \leq 1.354460185570906 \cdot 10^{-149}:\\
\;\;\;\;\frac{1}{t_0} \cdot \frac{\log \left(-re\right)}{t_0}\\

\mathbf{elif}\;im \leq 5.205359642473407 \cdot 10^{+89}:\\
\;\;\;\;\frac{0.5}{t_0} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{t_0}\\

\mathbf{else}:\\
\;\;\;\;\frac{\log im}{\log 10}\\


\end{array}
(FPCore (re im)
 :precision binary64
 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (sqrt (log 10.0))))
   (if (<= im 1.354460185570906e-149)
     (* (/ 1.0 t_0) (/ (log (- re)) t_0))
     (if (<= im 5.205359642473407e+89)
       (* (/ 0.5 t_0) (/ (log (+ (* re re) (* im im))) t_0))
       (/ (log im) (log 10.0))))))
double code(double re, double im) {
	return log(sqrt((re * re) + (im * im))) / log(10.0);
}
double code(double re, double im) {
	double t_0 = sqrt(log(10.0));
	double tmp;
	if (im <= 1.354460185570906e-149) {
		tmp = (1.0 / t_0) * (log(-re) / t_0);
	} else if (im <= 5.205359642473407e+89) {
		tmp = (0.5 / t_0) * (log((re * re) + (im * im)) / t_0);
	} else {
		tmp = log(im) / log(10.0);
	}
	return tmp;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if im < 1.3544601855709059e-149

    1. Initial program 32.7

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
    2. Taylor expanded around -inf 6.0

      \[\leadsto \frac{\log \color{blue}{\left(-1 \cdot re\right)}}{\log 10} \]
    3. Simplified6.0

      \[\leadsto \frac{\log \color{blue}{\left(-re\right)}}{\log 10} \]
    4. Using strategy rm
    5. Applied add-sqr-sqrt_binary646.0

      \[\leadsto \frac{\log \left(-re\right)}{\color{blue}{\sqrt{\log 10} \cdot \sqrt{\log 10}}} \]
    6. Applied pow1_binary646.0

      \[\leadsto \frac{\log \color{blue}{\left({\left(-re\right)}^{1}\right)}}{\sqrt{\log 10} \cdot \sqrt{\log 10}} \]
    7. Applied log-pow_binary646.0

      \[\leadsto \frac{\color{blue}{1 \cdot \log \left(-re\right)}}{\sqrt{\log 10} \cdot \sqrt{\log 10}} \]
    8. Applied times-frac_binary645.9

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

    if 1.3544601855709059e-149 < im < 5.20535964247340653e89

    1. Initial program 12.0

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary6412.0

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\color{blue}{\sqrt{\log 10} \cdot \sqrt{\log 10}}} \]
    4. Applied pow1/2_binary6412.0

      \[\leadsto \frac{\log \color{blue}{\left({\left(re \cdot re + im \cdot im\right)}^{0.5}\right)}}{\sqrt{\log 10} \cdot \sqrt{\log 10}} \]
    5. Applied log-pow_binary6412.0

      \[\leadsto \frac{\color{blue}{0.5 \cdot \log \left(re \cdot re + im \cdot im\right)}}{\sqrt{\log 10} \cdot \sqrt{\log 10}} \]
    6. Applied times-frac_binary6412.0

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

    if 5.20535964247340653e89 < im

    1. Initial program 49.2

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
    2. Taylor expanded around 0 5.4

      \[\leadsto \frac{\log \color{blue}{im}}{\log 10} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification7.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.354460185570906 \cdot 10^{-149}:\\ \;\;\;\;\frac{1}{\sqrt{\log 10}} \cdot \frac{\log \left(-re\right)}{\sqrt{\log 10}}\\ \mathbf{elif}\;im \leq 5.205359642473407 \cdot 10^{+89}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log 10}\\ \end{array} \]

Reproduce

herbie shell --seed 2021207 
(FPCore (re im)
  :name "math.log10 on complex, real part"
  :precision binary64
  (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))