Average Error: 32.1 → 18.8
Time: 8.6s
Precision: binary64
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
\[\begin{array}{l} \mathbf{if}\;re \le -5.26753219211879359 \cdot 10^{116}:\\ \;\;\;\;\frac{\sqrt{\frac{1}{2}}}{\sqrt{\log 10}} \cdot \frac{\sqrt{\frac{1}{2}}}{\frac{\sqrt{\log 10}}{\log 1 - 2 \cdot \log \left(\frac{-1}{re}\right)}}\\ \mathbf{elif}\;re \le -1.47898343813311881 \cdot 10^{-232}:\\ \;\;\;\;\frac{\sqrt{\frac{1}{2}}}{\frac{\frac{\log 10}{\log \left(re \cdot re + im \cdot im\right)}}{\sqrt{\frac{1}{2}}}}\\ \mathbf{elif}\;re \le 1.99786214231465739 \cdot 10^{-154}:\\ \;\;\;\;\frac{\log im}{\log 10}\\ \mathbf{elif}\;re \le 3.84792093290837512 \cdot 10^{74}:\\ \;\;\;\;\frac{\sqrt{\frac{1}{2}}}{\sqrt{\log 10}} \cdot \frac{\sqrt{\frac{1}{2}}}{\frac{\sqrt{\log 10}}{\log \left(re \cdot re + im \cdot im\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\frac{1}{2}}}{\sqrt{\log 10}} \cdot \frac{\sqrt{\frac{1}{2}}}{\frac{\sqrt{\log 10}}{\log 1 - 2 \cdot \log \left(\frac{1}{re}\right)}}\\ \end{array}\]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\begin{array}{l}
\mathbf{if}\;re \le -5.26753219211879359 \cdot 10^{116}:\\
\;\;\;\;\frac{\sqrt{\frac{1}{2}}}{\sqrt{\log 10}} \cdot \frac{\sqrt{\frac{1}{2}}}{\frac{\sqrt{\log 10}}{\log 1 - 2 \cdot \log \left(\frac{-1}{re}\right)}}\\

\mathbf{elif}\;re \le -1.47898343813311881 \cdot 10^{-232}:\\
\;\;\;\;\frac{\sqrt{\frac{1}{2}}}{\frac{\frac{\log 10}{\log \left(re \cdot re + im \cdot im\right)}}{\sqrt{\frac{1}{2}}}}\\

\mathbf{elif}\;re \le 1.99786214231465739 \cdot 10^{-154}:\\
\;\;\;\;\frac{\log im}{\log 10}\\

\mathbf{elif}\;re \le 3.84792093290837512 \cdot 10^{74}:\\
\;\;\;\;\frac{\sqrt{\frac{1}{2}}}{\sqrt{\log 10}} \cdot \frac{\sqrt{\frac{1}{2}}}{\frac{\sqrt{\log 10}}{\log \left(re \cdot re + im \cdot im\right)}}\\

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

\end{array}
double code(double re, double im) {
	return ((double) (((double) log(((double) sqrt(((double) (((double) (re * re)) + ((double) (im * im)))))))) / ((double) log(10.0))));
}
double code(double re, double im) {
	double VAR;
	if ((re <= -5.2675321921187936e+116)) {
		VAR = ((double) (((double) (((double) sqrt(0.5)) / ((double) sqrt(((double) log(10.0)))))) * ((double) (((double) sqrt(0.5)) / ((double) (((double) sqrt(((double) log(10.0)))) / ((double) (((double) log(1.0)) - ((double) (2.0 * ((double) log(((double) (-1.0 / re))))))))))))));
	} else {
		double VAR_1;
		if ((re <= -1.4789834381331188e-232)) {
			VAR_1 = ((double) (((double) sqrt(0.5)) / ((double) (((double) (((double) log(10.0)) / ((double) log(((double) (((double) (re * re)) + ((double) (im * im)))))))) / ((double) sqrt(0.5))))));
		} else {
			double VAR_2;
			if ((re <= 1.9978621423146574e-154)) {
				VAR_2 = ((double) (((double) log(im)) / ((double) log(10.0))));
			} else {
				double VAR_3;
				if ((re <= 3.847920932908375e+74)) {
					VAR_3 = ((double) (((double) (((double) sqrt(0.5)) / ((double) sqrt(((double) log(10.0)))))) * ((double) (((double) sqrt(0.5)) / ((double) (((double) sqrt(((double) log(10.0)))) / ((double) log(((double) (((double) (re * re)) + ((double) (im * im))))))))))));
				} else {
					VAR_3 = ((double) (((double) (((double) sqrt(0.5)) / ((double) sqrt(((double) log(10.0)))))) * ((double) (((double) sqrt(0.5)) / ((double) (((double) sqrt(((double) log(10.0)))) / ((double) (((double) log(1.0)) - ((double) (2.0 * ((double) log(((double) (1.0 / re))))))))))))));
				}
				VAR_2 = VAR_3;
			}
			VAR_1 = VAR_2;
		}
		VAR = VAR_1;
	}
	return VAR;
}

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 < -5.26753219211879359e116

    1. Initial program 54.4

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{\frac{\log 10}{\log \left(re \cdot re + im \cdot im\right)}}}\]
    6. Using strategy rm
    7. Applied pow154.4

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

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

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

      \[\leadsto \frac{\frac{1}{2}}{\color{blue}{\frac{\sqrt{\log 10}}{1} \cdot \frac{\sqrt{\log 10}}{\log \left(re \cdot re + im \cdot im\right)}}}\]
    11. Applied add-sqr-sqrt54.4

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

      \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{2}}}{\frac{\sqrt{\log 10}}{1}} \cdot \frac{\sqrt{\frac{1}{2}}}{\frac{\sqrt{\log 10}}{\log \left(re \cdot re + im \cdot im\right)}}}\]
    13. Simplified54.4

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

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

    if -5.26753219211879359e116 < re < -1.47898343813311881e-232

    1. Initial program 19.4

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

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

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

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

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

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

    if -1.47898343813311881e-232 < re < 1.99786214231465739e-154

    1. Initial program 32.5

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

      \[\leadsto \frac{\log \color{blue}{im}}{\log 10}\]

    if 1.99786214231465739e-154 < re < 3.84792093290837512e74

    1. Initial program 17.2

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{\frac{\log 10}{\log \left(re \cdot re + im \cdot im\right)}}}\]
    6. Using strategy rm
    7. Applied pow117.2

      \[\leadsto \frac{\frac{1}{2}}{\frac{\log 10}{\log \color{blue}{\left({\left(re \cdot re + im \cdot im\right)}^{1}\right)}}}\]
    8. Applied log-pow17.2

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

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

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

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

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

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

    if 3.84792093290837512e74 < re

    1. Initial program 48.1

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{\frac{\log 10}{\log \left(re \cdot re + im \cdot im\right)}}}\]
    6. Using strategy rm
    7. Applied pow148.1

      \[\leadsto \frac{\frac{1}{2}}{\frac{\log 10}{\log \color{blue}{\left({\left(re \cdot re + im \cdot im\right)}^{1}\right)}}}\]
    8. Applied log-pow48.1

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

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

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{2}}}{\frac{\sqrt{\log 10}}{1}} \cdot \frac{\sqrt{\frac{1}{2}}}{\frac{\sqrt{\log 10}}{\log \left(re \cdot re + im \cdot im\right)}}}\]
    13. Simplified48.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -5.26753219211879359 \cdot 10^{116}:\\ \;\;\;\;\frac{\sqrt{\frac{1}{2}}}{\sqrt{\log 10}} \cdot \frac{\sqrt{\frac{1}{2}}}{\frac{\sqrt{\log 10}}{\log 1 - 2 \cdot \log \left(\frac{-1}{re}\right)}}\\ \mathbf{elif}\;re \le -1.47898343813311881 \cdot 10^{-232}:\\ \;\;\;\;\frac{\sqrt{\frac{1}{2}}}{\frac{\frac{\log 10}{\log \left(re \cdot re + im \cdot im\right)}}{\sqrt{\frac{1}{2}}}}\\ \mathbf{elif}\;re \le 1.99786214231465739 \cdot 10^{-154}:\\ \;\;\;\;\frac{\log im}{\log 10}\\ \mathbf{elif}\;re \le 3.84792093290837512 \cdot 10^{74}:\\ \;\;\;\;\frac{\sqrt{\frac{1}{2}}}{\sqrt{\log 10}} \cdot \frac{\sqrt{\frac{1}{2}}}{\frac{\sqrt{\log 10}}{\log \left(re \cdot re + im \cdot im\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\frac{1}{2}}}{\sqrt{\log 10}} \cdot \frac{\sqrt{\frac{1}{2}}}{\frac{\sqrt{\log 10}}{\log 1 - 2 \cdot \log \left(\frac{1}{re}\right)}}\\ \end{array}\]

Reproduce

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