Average Error: 32.7 → 18.2
Time: 4.3s
Precision: binary64
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
\[\begin{array}{l} \mathbf{if}\;re \leq -6.320249547149809 \cdot 10^{+143}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log 10}\\ \mathbf{elif}\;re \leq -5.3392694545660306 \cdot 10^{-201}:\\ \;\;\;\;\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 1.062658705492185 \cdot 10^{-196}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(2 \cdot \left(\log im \cdot \sqrt{\frac{1}{\log 10}}\right)\right)\\ \mathbf{elif}\;re \leq 1.5937983800646182 \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{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 -6.320249547149809 \cdot 10^{+143}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log 10}\\

\mathbf{elif}\;re \leq -5.3392694545660306 \cdot 10^{-201}:\\
\;\;\;\;\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 1.062658705492185 \cdot 10^{-196}:\\
\;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(2 \cdot \left(\log im \cdot \sqrt{\frac{1}{\log 10}}\right)\right)\\

\mathbf{elif}\;re \leq 1.5937983800646182 \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{2 \cdot \log re}{\sqrt{\log 10}}\right)\\

\end{array}
(FPCore (re im)
 :precision binary64
 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
(FPCore (re im)
 :precision binary64
 (if (<= re -6.320249547149809e+143)
   (/ (log (- re)) (log 10.0))
   (if (<= re -5.3392694545660306e-201)
     (*
      (/ 0.5 (sqrt (log 10.0)))
      (* (log (+ (* re re) (* im im))) (/ 1.0 (sqrt (log 10.0)))))
     (if (<= re 1.062658705492185e-196)
       (*
        (/ 0.5 (sqrt (log 10.0)))
        (* 2.0 (* (log im) (sqrt (/ 1.0 (log 10.0))))))
       (if (<= re 1.5937983800646182e+130)
         (*
          (/ 0.5 (sqrt (log 10.0)))
          (* (log (+ (* re re) (* im im))) (/ 1.0 (sqrt (log 10.0)))))
         (*
          (sqrt (/ 0.5 (sqrt (log 10.0))))
          (*
           (sqrt (/ 0.5 (sqrt (log 10.0))))
           (/ (* 2.0 (log re)) (sqrt (log 10.0))))))))))
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 tmp;
	if ((re <= -6.320249547149809e+143)) {
		tmp = (((double) log(((double) -(re)))) / ((double) log(10.0)));
	} else {
		double tmp_1;
		if ((re <= -5.3392694545660306e-201)) {
			tmp_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 tmp_2;
			if ((re <= 1.062658705492185e-196)) {
				tmp_2 = ((double) ((0.5 / ((double) sqrt(((double) log(10.0))))) * ((double) (2.0 * ((double) (((double) log(im)) * ((double) sqrt((1.0 / ((double) log(10.0)))))))))));
			} else {
				double tmp_3;
				if ((re <= 1.5937983800646182e+130)) {
					tmp_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 {
					tmp_3 = ((double) (((double) sqrt((0.5 / ((double) sqrt(((double) log(10.0))))))) * ((double) (((double) sqrt((0.5 / ((double) sqrt(((double) log(10.0))))))) * (((double) (2.0 * ((double) log(re)))) / ((double) sqrt(((double) log(10.0)))))))));
				}
				tmp_2 = tmp_3;
			}
			tmp_1 = tmp_2;
		}
		tmp = tmp_1;
	}
	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 4 regimes
  2. if re < -6.32024954714980922e143

    1. Initial program 61.7

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

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

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

    if -6.32024954714980922e143 < re < -5.3392694545660306e-201 or 1.06265870549218496e-196 < re < 1.5937983800646182e130

    1. Initial program 18.3

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary6418.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/2_binary6418.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-pow_binary6418.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-frac_binary6418.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. Using strategy rm
    8. Applied div-inv_binary6418.2

      \[\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 -5.3392694545660306e-201 < re < 1.06265870549218496e-196

    1. Initial program 32.7

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

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

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

    if 1.5937983800646182e130 < re

    1. Initial program 58.3

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

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

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

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

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

      \[\leadsto \sqrt{\frac{0.5}{\sqrt{\log 10}}} \cdot \left(\frac{\color{blue}{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 simplification18.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -6.320249547149809 \cdot 10^{+143}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log 10}\\ \mathbf{elif}\;re \leq -5.3392694545660306 \cdot 10^{-201}:\\ \;\;\;\;\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 1.062658705492185 \cdot 10^{-196}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(2 \cdot \left(\log im \cdot \sqrt{\frac{1}{\log 10}}\right)\right)\\ \mathbf{elif}\;re \leq 1.5937983800646182 \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{2 \cdot \log re}{\sqrt{\log 10}}\right)\\ \end{array}\]

Reproduce

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