Average Error: 32.0 → 17.8
Time: 4.1s
Precision: binary64
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
\[\begin{array}{l} \mathbf{if}\;re \leq -1.3699735643448252 \cdot 10^{+94}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(-2 \cdot \left(\log \left(\frac{-1}{re}\right) \cdot \sqrt{\frac{1}{\log 10}}\right)\right)\\ \mathbf{elif}\;re \leq -5.396105895291542 \cdot 10^{-246}:\\ \;\;\;\;\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 4.97977832146901 \cdot 10^{-256}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(2 \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \log im\right)\right)\\ \mathbf{elif}\;re \leq 33696.34187874525:\\ \;\;\;\;\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(2 \cdot \left(\sqrt{\frac{1}{\log 10}} \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 -1.3699735643448252 \cdot 10^{+94}:\\
\;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(-2 \cdot \left(\log \left(\frac{-1}{re}\right) \cdot \sqrt{\frac{1}{\log 10}}\right)\right)\\

\mathbf{elif}\;re \leq -5.396105895291542 \cdot 10^{-246}:\\
\;\;\;\;\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 4.97977832146901 \cdot 10^{-256}:\\
\;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(2 \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \log im\right)\right)\\

\mathbf{elif}\;re \leq 33696.34187874525:\\
\;\;\;\;\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(2 \cdot \left(\sqrt{\frac{1}{\log 10}} \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 -1.3699735643448252e+94)
   (*
    (/ 0.5 (sqrt (log 10.0)))
    (* -2.0 (* (log (/ -1.0 re)) (sqrt (/ 1.0 (log 10.0))))))
   (if (<= re -5.396105895291542e-246)
     (*
      (/ 0.5 (sqrt (log 10.0)))
      (log (pow (+ (* re re) (* im im)) (/ 1.0 (sqrt (log 10.0))))))
     (if (<= re 4.97977832146901e-256)
       (*
        (/ 0.5 (sqrt (log 10.0)))
        (* 2.0 (* (sqrt (/ 1.0 (log 10.0))) (log im))))
       (if (<= re 33696.34187874525)
         (*
          (/ 0.5 (sqrt (log 10.0)))
          (log (pow (+ (* re re) (* im im)) (/ 1.0 (sqrt (log 10.0))))))
         (*
          (/ 0.5 (sqrt (log 10.0)))
          (* 2.0 (* (sqrt (/ 1.0 (log 10.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 tmp;
	if ((re <= -1.3699735643448252e+94)) {
		tmp = ((double) ((0.5 / ((double) sqrt(((double) log(10.0))))) * ((double) (-2.0 * ((double) (((double) log((-1.0 / re))) * ((double) sqrt((1.0 / ((double) log(10.0)))))))))));
	} else {
		double tmp_1;
		if ((re <= -5.396105895291542e-246)) {
			tmp_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 tmp_2;
			if ((re <= 4.97977832146901e-256)) {
				tmp_2 = ((double) ((0.5 / ((double) sqrt(((double) log(10.0))))) * ((double) (2.0 * ((double) (((double) sqrt((1.0 / ((double) log(10.0))))) * ((double) log(im))))))));
			} else {
				double tmp_3;
				if ((re <= 33696.34187874525)) {
					tmp_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 {
					tmp_3 = ((double) ((0.5 / ((double) sqrt(((double) log(10.0))))) * ((double) (2.0 * ((double) (((double) sqrt((1.0 / ((double) log(10.0))))) * ((double) log(re))))))));
				}
				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 < -1.3699735643448252e94

    1. Initial program 50.5

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

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

    if -1.3699735643448252e94 < re < -5.39610589529154205e-246 or 4.9797783214690098e-256 < re < 33696.3418787452465

    1. Initial program 20.7

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary6420.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_binary6420.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_binary6420.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_binary6420.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. Using strategy rm
    8. Applied div-inv_binary6420.6

      \[\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)}\]
    9. Using strategy rm
    10. Applied add-log-exp_binary6420.6

      \[\leadsto \frac{0.5}{\sqrt{\log 10}} \cdot \color{blue}{\log \left(e^{\log \left(re \cdot re + im \cdot im\right) \cdot \frac{1}{\sqrt{\log 10}}}\right)}\]
    11. Simplified20.5

      \[\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 -5.39610589529154205e-246 < re < 4.9797783214690098e-256

    1. Initial program 33.0

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

      \[\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_binary6433.0

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

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

      \[\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 33696.3418787452465 < re

    1. Initial program 41.1

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.3699735643448252 \cdot 10^{+94}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(-2 \cdot \left(\log \left(\frac{-1}{re}\right) \cdot \sqrt{\frac{1}{\log 10}}\right)\right)\\ \mathbf{elif}\;re \leq -5.396105895291542 \cdot 10^{-246}:\\ \;\;\;\;\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 4.97977832146901 \cdot 10^{-256}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \left(2 \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \log im\right)\right)\\ \mathbf{elif}\;re \leq 33696.34187874525:\\ \;\;\;\;\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(2 \cdot \left(\sqrt{\frac{1}{\log 10}} \cdot \log re\right)\right)\\ \end{array}\]

Reproduce

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