Average Error: 31.8 → 17.8
Time: 3.3s
Precision: binary64
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
\[\begin{array}{l} \mathbf{if}\;re \leq -3.8588398939432175 \cdot 10^{+132}:\\ \;\;\;\;\sqrt{0.5} \cdot \frac{\sqrt{0.5}}{\frac{\log 10}{\log \left(\frac{-1}{re}\right) \cdot -2}}\\ \mathbf{elif}\;re \leq -4.2360820877371696 \cdot 10^{-235}:\\ \;\;\;\;\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{elif}\;re \leq 2.1577752949736062 \cdot 10^{-187}:\\ \;\;\;\;\sqrt{0.5} \cdot \frac{\sqrt{0.5}}{\frac{\log 10}{2 \cdot \log im}}\\ \mathbf{elif}\;re \leq 1.2225237113435466 \cdot 10^{+30}:\\ \;\;\;\;\sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \left(\sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \frac{2 \cdot \log re}{\sqrt{\log 10}}\\ \end{array}\]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\begin{array}{l}
\mathbf{if}\;re \leq -3.8588398939432175 \cdot 10^{+132}:\\
\;\;\;\;\sqrt{0.5} \cdot \frac{\sqrt{0.5}}{\frac{\log 10}{\log \left(\frac{-1}{re}\right) \cdot -2}}\\

\mathbf{elif}\;re \leq -4.2360820877371696 \cdot 10^{-235}:\\
\;\;\;\;\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{elif}\;re \leq 2.1577752949736062 \cdot 10^{-187}:\\
\;\;\;\;\sqrt{0.5} \cdot \frac{\sqrt{0.5}}{\frac{\log 10}{2 \cdot \log im}}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \frac{2 \cdot \log re}{\sqrt{\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 -3.8588398939432175e+132)
   (* (sqrt 0.5) (/ (sqrt 0.5) (/ (log 10.0) (* (log (/ -1.0 re)) -2.0))))
   (if (<= re -4.2360820877371696e-235)
     (*
      (/ 0.5 (sqrt (log 10.0)))
      (* (log (+ (* re re) (* im im))) (/ 1.0 (sqrt (log 10.0)))))
     (if (<= re 2.1577752949736062e-187)
       (* (sqrt 0.5) (/ (sqrt 0.5) (/ (log 10.0) (* 2.0 (log im)))))
       (if (<= re 1.2225237113435466e+30)
         (*
          (sqrt (/ 0.5 (sqrt (log 10.0))))
          (*
           (sqrt (/ 0.5 (sqrt (log 10.0))))
           (/ (log (+ (* re re) (* im im))) (sqrt (log 10.0)))))
         (*
          (/ 0.5 (sqrt (log 10.0)))
          (/ (* 2.0 (log re)) (sqrt (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 <= -3.8588398939432175e+132) {
		tmp = sqrt(0.5) * (sqrt(0.5) / (log(10.0) / (log(-1.0 / re) * -2.0)));
	} else if (re <= -4.2360820877371696e-235) {
		tmp = (0.5 / sqrt(log(10.0))) * (log((re * re) + (im * im)) * (1.0 / sqrt(log(10.0))));
	} else if (re <= 2.1577752949736062e-187) {
		tmp = sqrt(0.5) * (sqrt(0.5) / (log(10.0) / (2.0 * log(im))));
	} else if (re <= 1.2225237113435466e+30) {
		tmp = sqrt(0.5 / sqrt(log(10.0))) * (sqrt(0.5 / sqrt(log(10.0))) * (log((re * re) + (im * im)) / sqrt(log(10.0))));
	} else {
		tmp = (0.5 / sqrt(log(10.0))) * ((2.0 * log(re)) / sqrt(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 5 regimes
  2. if re < -3.8588398939432175e132

    1. Initial program 58.0

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary6458.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_binary6458.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_binary6458.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_binary6458.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. Using strategy rm
    8. Applied *-un-lft-identity_binary6458.0

      \[\leadsto \frac{0.5}{\color{blue}{1 \cdot \sqrt{\log 10}}} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\]
    9. Applied add-sqr-sqrt_binary6458.0

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

      \[\leadsto \color{blue}{\left(\frac{\sqrt{0.5}}{1} \cdot \frac{\sqrt{0.5}}{\sqrt{\log 10}}\right)} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\]
    11. Applied associate-*l*_binary6458.0

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

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

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

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

    if -3.8588398939432175e132 < re < -4.23608208773716957e-235

    1. Initial program 19.2

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

      \[\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_binary6419.2

      \[\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_binary6419.2

      \[\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_binary6419.1

      \[\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_binary6419.0

      \[\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 -4.23608208773716957e-235 < re < 2.15777529497360624e-187

    1. Initial program 33.1

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

      \[\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_binary6433.1

      \[\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_binary6433.1

      \[\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_binary6433.1

      \[\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 *-un-lft-identity_binary6433.1

      \[\leadsto \frac{0.5}{\color{blue}{1 \cdot \sqrt{\log 10}}} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\]
    9. Applied add-sqr-sqrt_binary6433.1

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

      \[\leadsto \color{blue}{\left(\frac{\sqrt{0.5}}{1} \cdot \frac{\sqrt{0.5}}{\sqrt{\log 10}}\right)} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\]
    11. Applied associate-*l*_binary6433.0

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

      \[\leadsto \frac{\sqrt{0.5}}{1} \cdot \color{blue}{\frac{\sqrt{0.5}}{\frac{\log 10}{\log \left(re \cdot re + im \cdot im\right)}}}\]
    13. Taylor expanded around 0 32.7

      \[\leadsto \frac{\sqrt{0.5}}{1} \cdot \frac{\sqrt{0.5}}{\frac{\log 10}{\color{blue}{2 \cdot \log im}}}\]

    if 2.15777529497360624e-187 < re < 1.2225237113435466e30

    1. Initial program 17.8

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

      \[\leadsto \color{blue}{\left(\sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \sqrt{\frac{0.5}{\sqrt{\log 10}}}\right)} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\]
    9. Applied associate-*l*_binary6417.7

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

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

    if 1.2225237113435466e30 < re

    1. Initial program 42.9

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -3.8588398939432175 \cdot 10^{+132}:\\ \;\;\;\;\sqrt{0.5} \cdot \frac{\sqrt{0.5}}{\frac{\log 10}{\log \left(\frac{-1}{re}\right) \cdot -2}}\\ \mathbf{elif}\;re \leq -4.2360820877371696 \cdot 10^{-235}:\\ \;\;\;\;\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{elif}\;re \leq 2.1577752949736062 \cdot 10^{-187}:\\ \;\;\;\;\sqrt{0.5} \cdot \frac{\sqrt{0.5}}{\frac{\log 10}{2 \cdot \log im}}\\ \mathbf{elif}\;re \leq 1.2225237113435466 \cdot 10^{+30}:\\ \;\;\;\;\sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \left(\sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \frac{2 \cdot \log re}{\sqrt{\log 10}}\\ \end{array}\]

Reproduce

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