Average Error: 31.5 → 18.2
Time: 5.5s
Precision: binary64
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
\[\begin{array}{l} \mathbf{if}\;re \leq -5.2032752033560465 \cdot 10^{+103}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(\left(\log 1 + \log \left(\frac{-1}{re}\right) \cdot -2\right) \cdot \sqrt{\frac{1}{\log 10}}\right)\\ \mathbf{elif}\;re \leq -1.0928214580192916 \cdot 10^{-154}:\\ \;\;\;\;\frac{0.5}{\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 \leq 2.4695374740654386 \cdot 10^{-180}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \left(\log 1 + 2 \cdot \log im\right)\right)\\ \mathbf{elif}\;re \leq 8.833768332896172 \cdot 10^{+88}:\\ \;\;\;\;\frac{0.5}{\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{0.5}{\sqrt{\log 10}} \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \left(\log 1 + 2 \cdot \log re\right)\right)\\ \end{array}\]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\begin{array}{l}
\mathbf{if}\;re \leq -5.2032752033560465 \cdot 10^{+103}:\\
\;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(\left(\log 1 + \log \left(\frac{-1}{re}\right) \cdot -2\right) \cdot \sqrt{\frac{1}{\log 10}}\right)\\

\mathbf{elif}\;re \leq -1.0928214580192916 \cdot 10^{-154}:\\
\;\;\;\;\frac{0.5}{\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 \leq 2.4695374740654386 \cdot 10^{-180}:\\
\;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \left(\log 1 + 2 \cdot \log im\right)\right)\\

\mathbf{elif}\;re \leq 8.833768332896172 \cdot 10^{+88}:\\
\;\;\;\;\frac{0.5}{\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{0.5}{\sqrt{\log 10}} \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \left(\log 1 + 2 \cdot \log re\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 -5.2032752033560465e+103)
   (*
    (/ 0.5 (sqrt (log 10.0)))
    (* (+ (log 1.0) (* (log (/ -1.0 re)) -2.0)) (sqrt (/ 1.0 (log 10.0)))))
   (if (<= re -1.0928214580192916e-154)
     (*
      (/ 0.5 (sqrt (log 10.0)))
      (log (pow (+ (* re re) (* im im)) (/ 1.0 (sqrt (log 10.0))))))
     (if (<= re 2.4695374740654386e-180)
       (*
        (/ 0.5 (sqrt (log 10.0)))
        (* (sqrt (/ 1.0 (log 10.0))) (+ (log 1.0) (* 2.0 (log im)))))
       (if (<= re 8.833768332896172e+88)
         (*
          (/ 0.5 (sqrt (log 10.0)))
          (log (pow (+ (* re re) (* im im)) (/ 1.0 (sqrt (log 10.0))))))
         (*
          (/ 0.5 (sqrt (log 10.0)))
          (* (sqrt (/ 1.0 (log 10.0))) (+ (log 1.0) (* 2.0 (log re))))))))))
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 <= -5.2032752033560465e+103)) {
		VAR = ((double) ((0.5 / ((double) sqrt(((double) log(10.0))))) * ((double) (((double) (((double) log(1.0)) + ((double) (((double) log((-1.0 / re))) * -2.0)))) * ((double) sqrt((1.0 / ((double) log(10.0)))))))));
	} else {
		double VAR_1;
		if ((re <= -1.0928214580192916e-154)) {
			VAR_1 = ((double) ((0.5 / ((double) sqrt(((double) log(10.0))))) * ((double) log(((double) pow(((double) (((double) (re * re)) + ((double) (im * im)))), (1.0 / ((double) sqrt(((double) log(10.0)))))))))));
		} else {
			double VAR_2;
			if ((re <= 2.4695374740654386e-180)) {
				VAR_2 = ((double) ((0.5 / ((double) sqrt(((double) log(10.0))))) * ((double) (((double) sqrt((1.0 / ((double) log(10.0))))) * ((double) (((double) log(1.0)) + ((double) (2.0 * ((double) log(im))))))))));
			} else {
				double VAR_3;
				if ((re <= 8.833768332896172e+88)) {
					VAR_3 = ((double) ((0.5 / ((double) sqrt(((double) log(10.0))))) * ((double) log(((double) pow(((double) (((double) (re * re)) + ((double) (im * im)))), (1.0 / ((double) sqrt(((double) log(10.0)))))))))));
				} else {
					VAR_3 = ((double) ((0.5 / ((double) sqrt(((double) log(10.0))))) * ((double) (((double) sqrt((1.0 / ((double) log(10.0))))) * ((double) (((double) log(1.0)) + ((double) (2.0 * ((double) log(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 4 regimes
  2. if re < -5.2032752033560465e103

    1. Initial program 51.5

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

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

      \[\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-pow51.5

      \[\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-frac51.5

      \[\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 -inf 9.0

      \[\leadsto \frac{0.5}{\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. Simplified9.0

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

    if -5.2032752033560465e103 < re < -1.09282145801929164e-154 or 2.46953747406543856e-180 < re < 8.8337683328961723e88

    1. Initial program 16.7

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

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

      \[\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-pow16.7

      \[\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-frac16.6

      \[\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-log-exp16.6

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

      \[\leadsto \frac{0.5}{\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.09282145801929164e-154 < re < 2.46953747406543856e-180

    1. Initial program 31.3

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

      \[\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-pow31.3

      \[\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-frac31.3

      \[\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 34.1

      \[\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. Simplified34.1

      \[\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 8.8337683328961723e88 < re

    1. Initial program 49.5

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

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

      \[\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-pow49.5

      \[\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-frac49.5

      \[\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 inf 9.6

      \[\leadsto \frac{0.5}{\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. Simplified9.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -5.2032752033560465 \cdot 10^{+103}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(\left(\log 1 + \log \left(\frac{-1}{re}\right) \cdot -2\right) \cdot \sqrt{\frac{1}{\log 10}}\right)\\ \mathbf{elif}\;re \leq -1.0928214580192916 \cdot 10^{-154}:\\ \;\;\;\;\frac{0.5}{\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 \leq 2.4695374740654386 \cdot 10^{-180}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \left(\log 1 + 2 \cdot \log im\right)\right)\\ \mathbf{elif}\;re \leq 8.833768332896172 \cdot 10^{+88}:\\ \;\;\;\;\frac{0.5}{\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{0.5}{\sqrt{\log 10}} \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \left(\log 1 + 2 \cdot \log re\right)\right)\\ \end{array}\]

Reproduce

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