Average Error: 31.8 → 18.3
Time: 6.4s
Precision: binary64
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
\[\begin{array}{l} \mathbf{if}\;re \leq -1.268063321609487 \cdot 10^{+32}:\\ \;\;\;\;\sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \left(\sqrt{0.5} \cdot \left(\left(\log 1 + \log \left(\frac{-1}{re}\right) \cdot -2\right) \cdot {\left(\frac{1}{{\left(\log 10\right)}^{3}}\right)}^{0.25}\right)\right)\\ \mathbf{elif}\;re \leq -4.17385497808198 \cdot 10^{-261}:\\ \;\;\;\;\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.046877101973681 \cdot 10^{-198}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(\left(\log 1 + 2 \cdot \log im\right) \cdot \sqrt{\frac{1}{\log 10}}\right)\\ \mathbf{elif}\;re \leq 5.756838278404119 \cdot 10^{+130}:\\ \;\;\;\;\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{else}:\\ \;\;\;\;\sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \left(\sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \frac{\log 1 + 2 \cdot \log re}{\sqrt{\log 10}}\right)\\ \end{array}\]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\begin{array}{l}
\mathbf{if}\;re \leq -1.268063321609487 \cdot 10^{+32}:\\
\;\;\;\;\sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \left(\sqrt{0.5} \cdot \left(\left(\log 1 + \log \left(\frac{-1}{re}\right) \cdot -2\right) \cdot {\left(\frac{1}{{\left(\log 10\right)}^{3}}\right)}^{0.25}\right)\right)\\

\mathbf{elif}\;re \leq -4.17385497808198 \cdot 10^{-261}:\\
\;\;\;\;\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.046877101973681 \cdot 10^{-198}:\\
\;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(\left(\log 1 + 2 \cdot \log im\right) \cdot \sqrt{\frac{1}{\log 10}}\right)\\

\mathbf{elif}\;re \leq 5.756838278404119 \cdot 10^{+130}:\\
\;\;\;\;\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{else}:\\
\;\;\;\;\sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \left(\sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \frac{\log 1 + 2 \cdot \log re}{\sqrt{\log 10}}\right)\\

\end{array}
double code(double re, double im) {
	return (((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 <= -1.268063321609487e+32)) {
		VAR = ((double) (((double) sqrt((0.5 / ((double) sqrt(((double) log(10.0))))))) * ((double) (((double) sqrt(0.5)) * ((double) (((double) (((double) log(1.0)) + ((double) (((double) log((-1.0 / re))) * -2.0)))) * ((double) pow((1.0 / ((double) pow(((double) log(10.0)), 3.0))), 0.25))))))));
	} else {
		double VAR_1;
		if ((re <= -4.17385497808198e-261)) {
			VAR_1 = ((double) ((0.5 / ((double) sqrt(((double) log(10.0))))) * ((double) (((double) log(((double) (((double) (re * re)) + ((double) (im * im)))))) * (1.0 / ((double) sqrt(((double) log(10.0)))))))));
		} else {
			double VAR_2;
			if ((re <= 2.046877101973681e-198)) {
				VAR_2 = ((double) ((0.5 / ((double) sqrt(((double) log(10.0))))) * ((double) (((double) (((double) log(1.0)) + ((double) (2.0 * ((double) log(im)))))) * ((double) sqrt((1.0 / ((double) log(10.0)))))))));
			} else {
				double VAR_3;
				if ((re <= 5.756838278404119e+130)) {
					VAR_3 = ((double) ((0.5 / ((double) sqrt(((double) log(10.0))))) * ((double) (((double) log(((double) (((double) (re * re)) + ((double) (im * im)))))) * (1.0 / ((double) sqrt(((double) log(10.0)))))))));
				} else {
					VAR_3 = ((double) (((double) sqrt((0.5 / ((double) sqrt(((double) log(10.0))))))) * ((double) (((double) sqrt((0.5 / ((double) sqrt(((double) log(10.0))))))) * (((double) (((double) log(1.0)) + ((double) (2.0 * ((double) log(re)))))) / ((double) sqrt(((double) log(10.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 < -1.2680633216094869e32

    1. Initial program Error: 42.2 bits

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

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

      \[\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-powError: 42.2 bits

      \[\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-fracError: 42.2 bits

      \[\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-sqrtError: 42.2 bits

      \[\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*Error: 42.1 bits

      \[\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. SimplifiedError: 42.1 bits

      \[\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)}\]
    11. Taylor expanded around -inf Error: 11.6 bits

      \[\leadsto \sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \color{blue}{\left(\left(\left(\log 1 - 2 \cdot \log \left(\frac{-1}{re}\right)\right) \cdot \sqrt{0.5}\right) \cdot {\left(\frac{1}{{\left(\log 10\right)}^{3}}\right)}^{0.25}\right)}\]
    12. SimplifiedError: 11.6 bits

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

    if -1.2680633216094869e32 < re < -4.1738549780819797e-261 or 2.046877101973681e-198 < re < 5.75683827840411851e130

    1. Initial program Error: 20.2 bits

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

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

      \[\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-powError: 20.2 bits

      \[\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-fracError: 20.2 bits

      \[\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-invError: 20.1 bits

      \[\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.1738549780819797e-261 < re < 2.046877101973681e-198

    1. Initial program Error: 30.9 bits

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

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

      \[\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-powError: 30.9 bits

      \[\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-fracError: 30.9 bits

      \[\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 0 Error: 34.8 bits

      \[\leadsto \frac{0.5}{\sqrt{\log 10}} \cdot \color{blue}{\left(\sqrt{\frac{1}{\log 10}} \cdot \left(\log 1 + 2 \cdot \log im\right)\right)}\]
    8. SimplifiedError: 34.8 bits

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

    if 5.75683827840411851e130 < re

    1. Initial program Error: 56.9 bits

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

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

      \[\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-powError: 56.9 bits

      \[\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-fracError: 56.9 bits

      \[\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-sqrtError: 56.9 bits

      \[\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*Error: 56.9 bits

      \[\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. SimplifiedError: 56.9 bits

      \[\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)}\]
    11. Taylor expanded around inf Error: 7.8 bits

      \[\leadsto \sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \left(\frac{\color{blue}{\log 1 - 2 \cdot \log \left(\frac{1}{re}\right)}}{\sqrt{\log 10}} \cdot \sqrt{\frac{0.5}{\sqrt{\log 10}}}\right)\]
    12. SimplifiedError: 7.8 bits

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.268063321609487 \cdot 10^{+32}:\\ \;\;\;\;\sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \left(\sqrt{0.5} \cdot \left(\left(\log 1 + \log \left(\frac{-1}{re}\right) \cdot -2\right) \cdot {\left(\frac{1}{{\left(\log 10\right)}^{3}}\right)}^{0.25}\right)\right)\\ \mathbf{elif}\;re \leq -4.17385497808198 \cdot 10^{-261}:\\ \;\;\;\;\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.046877101973681 \cdot 10^{-198}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(\left(\log 1 + 2 \cdot \log im\right) \cdot \sqrt{\frac{1}{\log 10}}\right)\\ \mathbf{elif}\;re \leq 5.756838278404119 \cdot 10^{+130}:\\ \;\;\;\;\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{else}:\\ \;\;\;\;\sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \left(\sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \frac{\log 1 + 2 \cdot \log re}{\sqrt{\log 10}}\right)\\ \end{array}\]

Reproduce

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