Average Error: 31.8 → 18.1
Time: 5.9s
Precision: binary64
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
\[\begin{array}{l} \mathbf{if}\;re \le -9.39078567835485203 \cdot 10^{30}:\\ \;\;\;\;\frac{\frac{1}{2}}{\sqrt{\log 10}} \cdot \left(\left(\log 1 - 2 \cdot \log \left(\frac{-1}{re}\right)\right) \cdot \sqrt{\frac{1}{\log 10}}\right)\\ \mathbf{elif}\;re \le -1.0495086725288259 \cdot 10^{-189}:\\ \;\;\;\;\frac{\frac{1}{2}}{\sqrt{\log 10}} \cdot \log \left({\left(re \cdot re + im \cdot im\right)}^{\left(\frac{1}{\sqrt{\log 10}}\right)}\right)\\ \mathbf{elif}\;re \le 1.3384531643325107 \cdot 10^{-226}:\\ \;\;\;\;\frac{\frac{1}{2}}{\sqrt{\log 10}} \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \left(\log 1 + 2 \cdot \log im\right)\right)\\ \mathbf{elif}\;re \le 3.9154391005694529 \cdot 10^{101}:\\ \;\;\;\;\frac{\frac{1}{2}}{\sqrt{\log 10}} \cdot \log \left({\left(re \cdot re + im \cdot im\right)}^{\left(\frac{1}{\sqrt{\log 10}}\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{2}}{\sqrt{\log 10}} \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \left(\log 1 - \log re \cdot -2\right)\right)\\ \end{array}\]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\begin{array}{l}
\mathbf{if}\;re \le -9.39078567835485203 \cdot 10^{30}:\\
\;\;\;\;\frac{\frac{1}{2}}{\sqrt{\log 10}} \cdot \left(\left(\log 1 - 2 \cdot \log \left(\frac{-1}{re}\right)\right) \cdot \sqrt{\frac{1}{\log 10}}\right)\\

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

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{2}}{\sqrt{\log 10}} \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \left(\log 1 - \log re \cdot -2\right)\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 <= -9.390785678354852e+30)) {
		VAR = ((double) (((double) (0.5 / ((double) sqrt(((double) log(10.0)))))) * ((double) (((double) (((double) log(1.0)) - ((double) (2.0 * ((double) log(((double) (-1.0 / re)))))))) * ((double) sqrt(((double) (1.0 / ((double) log(10.0))))))))));
	} else {
		double VAR_1;
		if ((re <= -1.049508672528826e-189)) {
			VAR_1 = ((double) (((double) (0.5 / ((double) sqrt(((double) log(10.0)))))) * ((double) log(((double) pow(((double) (((double) (re * re)) + ((double) (im * im)))), ((double) (1.0 / ((double) sqrt(((double) log(10.0))))))))))));
		} else {
			double VAR_2;
			if ((re <= 1.3384531643325107e-226)) {
				VAR_2 = ((double) (((double) (0.5 / ((double) sqrt(((double) log(10.0)))))) * ((double) (((double) sqrt(((double) (1.0 / ((double) log(10.0)))))) * ((double) (((double) log(1.0)) + ((double) (2.0 * ((double) log(im))))))))));
			} else {
				double VAR_3;
				if ((re <= 3.915439100569453e+101)) {
					VAR_3 = ((double) (((double) (0.5 / ((double) sqrt(((double) log(10.0)))))) * ((double) log(((double) pow(((double) (((double) (re * re)) + ((double) (im * im)))), ((double) (1.0 / ((double) sqrt(((double) log(10.0))))))))))));
				} else {
					VAR_3 = ((double) (((double) (0.5 / ((double) sqrt(((double) log(10.0)))))) * ((double) (((double) sqrt(((double) (1.0 / ((double) log(10.0)))))) * ((double) (((double) log(1.0)) - ((double) (((double) log(re)) * -2.0))))))));
				}
				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 4 regimes
  2. if re < -9.39078567835485203e30

    1. Initial program 43.1

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

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

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

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

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

    if -9.39078567835485203e30 < re < -1.0495086725288259e-189 or 1.3384531643325107e-226 < re < 3.9154391005694529e101

    1. Initial program 19.3

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

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\color{blue}{\sqrt{\log 10} \cdot \sqrt{\log 10}}}\]
    4. Applied pow1/219.3

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

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

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

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

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

    if -1.0495086725288259e-189 < re < 1.3384531643325107e-226

    1. Initial program 30.0

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

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

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

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

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

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

    if 3.9154391005694529e101 < re

    1. Initial program 52.0

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -9.39078567835485203 \cdot 10^{30}:\\ \;\;\;\;\frac{\frac{1}{2}}{\sqrt{\log 10}} \cdot \left(\left(\log 1 - 2 \cdot \log \left(\frac{-1}{re}\right)\right) \cdot \sqrt{\frac{1}{\log 10}}\right)\\ \mathbf{elif}\;re \le -1.0495086725288259 \cdot 10^{-189}:\\ \;\;\;\;\frac{\frac{1}{2}}{\sqrt{\log 10}} \cdot \log \left({\left(re \cdot re + im \cdot im\right)}^{\left(\frac{1}{\sqrt{\log 10}}\right)}\right)\\ \mathbf{elif}\;re \le 1.3384531643325107 \cdot 10^{-226}:\\ \;\;\;\;\frac{\frac{1}{2}}{\sqrt{\log 10}} \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \left(\log 1 + 2 \cdot \log im\right)\right)\\ \mathbf{elif}\;re \le 3.9154391005694529 \cdot 10^{101}:\\ \;\;\;\;\frac{\frac{1}{2}}{\sqrt{\log 10}} \cdot \log \left({\left(re \cdot re + im \cdot im\right)}^{\left(\frac{1}{\sqrt{\log 10}}\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{2}}{\sqrt{\log 10}} \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \left(\log 1 - \log re \cdot -2\right)\right)\\ \end{array}\]

Reproduce

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