Average Error: 32.1 → 17.4
Time: 6.8s
Precision: binary64
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
\[\begin{array}{l} \mathbf{if}\;re \leq -1.297222298515406 \cdot 10^{+56}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(-2 \cdot \left(\log \left(\frac{-1}{re}\right) \cdot \sqrt{\frac{1}{\log 10}}\right)\right)\\ \mathbf{elif}\;re \leq 1.8765422039829392 \cdot 10^{+58}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \log \left({\left(re \cdot re + im \cdot im\right)}^{\left(\frac{1}{\sqrt{\log 10}}\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \left(2 \cdot \log re\right)\right)\\ \end{array}\]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\begin{array}{l}
\mathbf{if}\;re \leq -1.297222298515406 \cdot 10^{+56}:\\
\;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(-2 \cdot \left(\log \left(\frac{-1}{re}\right) \cdot \sqrt{\frac{1}{\log 10}}\right)\right)\\

\mathbf{elif}\;re \leq 1.8765422039829392 \cdot 10^{+58}:\\
\;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \log \left({\left(re \cdot re + im \cdot im\right)}^{\left(\frac{1}{\sqrt{\log 10}}\right)}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \left(2 \cdot \log re\right)\right)\\

\end{array}
(FPCore (re im)
 :precision binary64
 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
(FPCore (re im)
 :precision binary64
 (if (<= re -1.297222298515406e+56)
   (*
    (/ 0.5 (sqrt (log 10.0)))
    (* -2.0 (* (log (/ -1.0 re)) (sqrt (/ 1.0 (log 10.0))))))
   (if (<= re 1.8765422039829392e+58)
     (*
      (/ 0.5 (sqrt (log 10.0)))
      (log (pow (+ (* re re) (* im im)) (/ 1.0 (sqrt (log 10.0))))))
     (*
      (/ 0.5 (sqrt (log 10.0)))
      (* (sqrt (/ 1.0 (log 10.0))) (* 2.0 (log re)))))))
double code(double re, double im) {
	return log(sqrt((re * re) + (im * im))) / log(10.0);
}
double code(double re, double im) {
	double tmp;
	if (re <= -1.297222298515406e+56) {
		tmp = (0.5 / sqrt(log(10.0))) * (-2.0 * (log(-1.0 / re) * sqrt(1.0 / log(10.0))));
	} else if (re <= 1.8765422039829392e+58) {
		tmp = (0.5 / sqrt(log(10.0))) * log(pow(((re * re) + (im * im)), (1.0 / sqrt(log(10.0)))));
	} else {
		tmp = (0.5 / sqrt(log(10.0))) * (sqrt(1.0 / log(10.0)) * (2.0 * log(re)));
	}
	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 re < -1.29722229851540604e56

    1. Initial program 46.0

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary64_10046.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_binary64_15846.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_binary64_16746.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_binary64_8446.0

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

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

    if -1.29722229851540604e56 < re < 1.87654220398293925e58

    1. Initial program 22.4

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

      \[\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_binary64_15822.4

      \[\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_binary64_16722.4

      \[\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_binary64_8422.4

      \[\leadsto \color{blue}{\frac{0.5}{\sqrt{\log 10}} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}}\]
    7. Using strategy rm
    8. Applied add-log-exp_binary64_11722.4

      \[\leadsto \frac{0.5}{\sqrt{\log 10}} \cdot \color{blue}{\log \left(e^{\frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}}\right)}\]
    9. Simplified22.2

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

    if 1.87654220398293925e58 < re

    1. Initial program 45.9

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

      \[\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_binary64_15845.9

      \[\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_binary64_16745.9

      \[\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_binary64_8445.9

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

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

      \[\leadsto \frac{0.5}{\sqrt{\log 10}} \cdot \color{blue}{\left(\left(2 \cdot \log re\right) \cdot \sqrt{\frac{1}{\log 10}}\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification17.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.297222298515406 \cdot 10^{+56}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(-2 \cdot \left(\log \left(\frac{-1}{re}\right) \cdot \sqrt{\frac{1}{\log 10}}\right)\right)\\ \mathbf{elif}\;re \leq 1.8765422039829392 \cdot 10^{+58}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \log \left({\left(re \cdot re + im \cdot im\right)}^{\left(\frac{1}{\sqrt{\log 10}}\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \left(2 \cdot \log re\right)\right)\\ \end{array}\]

Reproduce

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