Average Error: 32.4 → 7.5
Time: 10.2s
Precision: binary64
\[[re, im]=\mathsf{sort}([re, im])\]
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
\[\begin{array}{l} \mathbf{if}\;re \leq -8.383593090521001 \cdot 10^{+110}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log 10}\\ \mathbf{elif}\;re \leq -8.647414243699812 \cdot 10^{-165}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{\log 10}} \cdot \log \left({im}^{\left(\frac{1}{\sqrt{\log 10}}\right)}\right)\\ \end{array}\]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\begin{array}{l}
\mathbf{if}\;re \leq -8.383593090521001 \cdot 10^{+110}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log 10}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{\log 10}} \cdot \log \left({im}^{\left(\frac{1}{\sqrt{\log 10}}\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 -8.383593090521001e+110)
   (/ (log (- re)) (log 10.0))
   (if (<= re -8.647414243699812e-165)
     (*
      (/ 0.5 (sqrt (log 10.0)))
      (/ (log (+ (* re re) (* im im))) (sqrt (log 10.0))))
     (* (/ 1.0 (sqrt (log 10.0))) (log (pow im (/ 1.0 (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 <= -8.383593090521001e+110) {
		tmp = log(-re) / log(10.0);
	} else if (re <= -8.647414243699812e-165) {
		tmp = (0.5 / sqrt(log(10.0))) * (log((re * re) + (im * im)) / sqrt(log(10.0)));
	} else {
		tmp = (1.0 / sqrt(log(10.0))) * log(pow(im, (1.0 / 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 3 regimes
  2. if re < -8.3835930905210013e110

    1. Initial program 53.2

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

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

    if -8.3835930905210013e110 < re < -8.64741424369981227e-165

    1. Initial program 12.2

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

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

    if -8.64741424369981227e-165 < re

    1. Initial program 32.9

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

      \[\leadsto \color{blue}{-1 \cdot \frac{\log \left(\frac{1}{im}\right)}{\log 10}}\]
    3. Simplified5.2

      \[\leadsto \color{blue}{\frac{\log im}{\log 10}}\]
    4. Using strategy rm
    5. Applied add-cbrt-cube_binary64_7965.2

      \[\leadsto \color{blue}{\sqrt[3]{\left(\frac{\log im}{\log 10} \cdot \frac{\log im}{\log 10}\right) \cdot \frac{\log im}{\log 10}}}\]
    6. Simplified5.2

      \[\leadsto \sqrt[3]{\color{blue}{{\left(\frac{\log im}{\log 10}\right)}^{3}}}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt_binary64_7825.2

      \[\leadsto \sqrt[3]{{\left(\frac{\log im}{\color{blue}{\sqrt{\log 10} \cdot \sqrt{\log 10}}}\right)}^{3}}\]
    9. Applied pow1_binary64_8215.2

      \[\leadsto \sqrt[3]{{\left(\frac{\log \color{blue}{\left({im}^{1}\right)}}{\sqrt{\log 10} \cdot \sqrt{\log 10}}\right)}^{3}}\]
    10. Applied log-pow_binary64_8495.2

      \[\leadsto \sqrt[3]{{\left(\frac{\color{blue}{1 \cdot \log im}}{\sqrt{\log 10} \cdot \sqrt{\log 10}}\right)}^{3}}\]
    11. Applied times-frac_binary64_7665.2

      \[\leadsto \sqrt[3]{{\color{blue}{\left(\frac{1}{\sqrt{\log 10}} \cdot \frac{\log im}{\sqrt{\log 10}}\right)}}^{3}}\]
    12. Applied unpow-prod-down_binary64_8395.2

      \[\leadsto \sqrt[3]{\color{blue}{{\left(\frac{1}{\sqrt{\log 10}}\right)}^{3} \cdot {\left(\frac{\log im}{\sqrt{\log 10}}\right)}^{3}}}\]
    13. Applied cbrt-prod_binary64_7915.2

      \[\leadsto \color{blue}{\sqrt[3]{{\left(\frac{1}{\sqrt{\log 10}}\right)}^{3}} \cdot \sqrt[3]{{\left(\frac{\log im}{\sqrt{\log 10}}\right)}^{3}}}\]
    14. Simplified5.2

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\log 10}}} \cdot \sqrt[3]{{\left(\frac{\log im}{\sqrt{\log 10}}\right)}^{3}}\]
    15. Simplified5.1

      \[\leadsto \frac{1}{\sqrt{\log 10}} \cdot \color{blue}{\frac{\log im}{\sqrt{\log 10}}}\]
    16. Using strategy rm
    17. Applied add-log-exp_binary64_7995.1

      \[\leadsto \frac{1}{\sqrt{\log 10}} \cdot \color{blue}{\log \left(e^{\frac{\log im}{\sqrt{\log 10}}}\right)}\]
    18. Simplified4.9

      \[\leadsto \frac{1}{\sqrt{\log 10}} \cdot \log \color{blue}{\left({im}^{\left(\frac{1}{\sqrt{\log 10}}\right)}\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification7.5

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

Reproduce

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