Average Error: 31.7 → 17.1
Time: 6.2s
Precision: binary64
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
\[\begin{array}{l} \mathbf{if}\;re \leq -1.0759262699953573 \cdot 10^{+106}:\\ \;\;\;\;\frac{\sqrt{0.5}}{\frac{\log 10}{\sqrt{0.5} \cdot \left(\log \left(\frac{-1}{re}\right) \cdot -2\right)}}\\ \mathbf{elif}\;re \leq 8.169445472099669 \cdot 10^{+99}:\\ \;\;\;\;\frac{\sqrt{0.5}}{\frac{\log 10}{\log \left({\left(re \cdot re + im \cdot im\right)}^{\left(\sqrt{0.5}\right)}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{0.5}}{\frac{\log 10}{\sqrt{0.5} \cdot \left(2 \cdot \log re\right)}}\\ \end{array}\]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\begin{array}{l}
\mathbf{if}\;re \leq -1.0759262699953573 \cdot 10^{+106}:\\
\;\;\;\;\frac{\sqrt{0.5}}{\frac{\log 10}{\sqrt{0.5} \cdot \left(\log \left(\frac{-1}{re}\right) \cdot -2\right)}}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{0.5}}{\frac{\log 10}{\sqrt{0.5} \cdot \left(2 \cdot \log re\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.0759262699953573e+106)
   (/ (sqrt 0.5) (/ (log 10.0) (* (sqrt 0.5) (* (log (/ -1.0 re)) -2.0))))
   (if (<= re 8.169445472099669e+99)
     (/
      (sqrt 0.5)
      (/ (log 10.0) (log (pow (+ (* re re) (* im im)) (sqrt 0.5)))))
     (/ (sqrt 0.5) (/ (log 10.0) (* (sqrt 0.5) (* 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.0759262699953573e+106) {
		tmp = sqrt(0.5) / (log(10.0) / (sqrt(0.5) * (log(-1.0 / re) * -2.0)));
	} else if (re <= 8.169445472099669e+99) {
		tmp = sqrt(0.5) / (log(10.0) / log(pow(((re * re) + (im * im)), sqrt(0.5))));
	} else {
		tmp = sqrt(0.5) / (log(10.0) / (sqrt(0.5) * (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.0759262699953573e106

    1. Initial program 53.4

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
    2. Using strategy rm
    3. Applied pow1/2_binary64_15853.4

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

      \[\leadsto \frac{\color{blue}{0.5 \cdot \log \left(re \cdot re + im \cdot im\right)}}{\log 10}\]
    5. Applied associate-/l*_binary64_2353.4

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

      \[\leadsto \frac{\color{blue}{\sqrt{0.5} \cdot \sqrt{0.5}}}{\frac{\log 10}{\log \left(re \cdot re + im \cdot im\right)}}\]
    8. Applied associate-/l*_binary64_2353.3

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

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

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

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

    if -1.0759262699953573e106 < re < 8.16944547209966887e99

    1. Initial program 21.6

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
    2. Using strategy rm
    3. Applied pow1/2_binary64_15821.6

      \[\leadsto \frac{\log \color{blue}{\left({\left(re \cdot re + im \cdot im\right)}^{0.5}\right)}}{\log 10}\]
    4. Applied log-pow_binary64_16721.6

      \[\leadsto \frac{\color{blue}{0.5 \cdot \log \left(re \cdot re + im \cdot im\right)}}{\log 10}\]
    5. Applied associate-/l*_binary64_2321.6

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

      \[\leadsto \frac{\color{blue}{\sqrt{0.5} \cdot \sqrt{0.5}}}{\frac{\log 10}{\log \left(re \cdot re + im \cdot im\right)}}\]
    8. Applied associate-/l*_binary64_2321.5

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

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

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

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

    if 8.16944547209966887e99 < re

    1. Initial program 50.6

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
    2. Using strategy rm
    3. Applied pow1/2_binary64_15850.6

      \[\leadsto \frac{\log \color{blue}{\left({\left(re \cdot re + im \cdot im\right)}^{0.5}\right)}}{\log 10}\]
    4. Applied log-pow_binary64_16750.6

      \[\leadsto \frac{\color{blue}{0.5 \cdot \log \left(re \cdot re + im \cdot im\right)}}{\log 10}\]
    5. Applied associate-/l*_binary64_2350.6

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

      \[\leadsto \frac{\color{blue}{\sqrt{0.5} \cdot \sqrt{0.5}}}{\frac{\log 10}{\log \left(re \cdot re + im \cdot im\right)}}\]
    8. Applied associate-/l*_binary64_2350.5

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

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

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

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

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

Reproduce

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