Average Error: 32.4 → 17.5
Time: 3.4s
Precision: binary64
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
\[\begin{array}{l} \mathbf{if}\;re \leq -1.805095199141907 \cdot 10^{+119}:\\ \;\;\;\;\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.6771046228039996 \cdot 10^{+112}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(\log \left(re \cdot re + im \cdot im\right) \cdot \frac{1}{\sqrt{\log 10}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\log re}{\log 10}\\ \end{array}\]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\begin{array}{l}
\mathbf{if}\;re \leq -1.805095199141907 \cdot 10^{+119}:\\
\;\;\;\;\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.6771046228039996 \cdot 10^{+112}:\\
\;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(\log \left(re \cdot re + im \cdot im\right) \cdot \frac{1}{\sqrt{\log 10}}\right)\\

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

\end{array}
(FPCore (re im)
 :precision binary64
 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
(FPCore (re im)
 :precision binary64
 (if (<= re -1.805095199141907e+119)
   (*
    (/ 0.5 (sqrt (log 10.0)))
    (* -2.0 (* (log (/ -1.0 re)) (sqrt (/ 1.0 (log 10.0))))))
   (if (<= re 1.6771046228039996e+112)
     (*
      (/ 0.5 (sqrt (log 10.0)))
      (* (log (+ (* re re) (* im im))) (/ 1.0 (sqrt (log 10.0)))))
     (/ (log re) (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 tmp;
	if (re <= -1.805095199141907e+119) {
		tmp = (0.5 / sqrt(log(10.0))) * (-2.0 * (log(-1.0 / re) * sqrt(1.0 / log(10.0))));
	} else if (re <= 1.6771046228039996e+112) {
		tmp = (0.5 / sqrt(log(10.0))) * (log((re * re) + (im * im)) * (1.0 / sqrt(log(10.0))));
	} else {
		tmp = log(re) / 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 re < -1.80509519914190689e119

    1. Initial program 55.9

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

      \[\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.80509519914190689e119 < re < 1.67710462280399957e112

    1. Initial program 21.8

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

      \[\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_binary6421.8

      \[\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_binary6421.8

      \[\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_binary6421.8

      \[\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 div-inv_binary6421.7

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

    if 1.67710462280399957e112 < re

    1. Initial program 54.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.805095199141907 \cdot 10^{+119}:\\ \;\;\;\;\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.6771046228039996 \cdot 10^{+112}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(\log \left(re \cdot re + im \cdot im\right) \cdot \frac{1}{\sqrt{\log 10}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\log re}{\log 10}\\ \end{array}\]

Reproduce

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