Average Error: 31.6 → 18.1
Time: 7.0s
Precision: binary64
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
\[\begin{array}{l} \mathbf{if}\;re \leq -2.092298405732528 \cdot 10^{+120}:\\ \;\;\;\;\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 -3.0666539773149642 \cdot 10^{-304}:\\ \;\;\;\;\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.37904483532928 \cdot 10^{-146}:\\ \;\;\;\;\frac{\log im}{\log 10}\\ \mathbf{elif}\;re \leq 5.659830230443159 \cdot 10^{+152}:\\ \;\;\;\;\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}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(\sqrt{0.5} \cdot \frac{\log 1 + 2 \cdot \log re}{\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 -2.092298405732528 \cdot 10^{+120}:\\
\;\;\;\;\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 -3.0666539773149642 \cdot 10^{-304}:\\
\;\;\;\;\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.37904483532928 \cdot 10^{-146}:\\
\;\;\;\;\frac{\log im}{\log 10}\\

\mathbf{elif}\;re \leq 5.659830230443159 \cdot 10^{+152}:\\
\;\;\;\;\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}:\\
\;\;\;\;\sqrt{0.5} \cdot \left(\sqrt{0.5} \cdot \frac{\log 1 + 2 \cdot \log re}{\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 -2.092298405732528e+120)
   (*
    (/ 0.5 (sqrt (log 10.0)))
    (* (+ (log 1.0) (* (log (/ -1.0 re)) -2.0)) (sqrt (/ 1.0 (log 10.0)))))
   (if (<= re -3.0666539773149642e-304)
     (*
      (/ 0.5 (sqrt (log 10.0)))
      (log (pow (+ (* re re) (* im im)) (/ 1.0 (sqrt (log 10.0))))))
     (if (<= re 4.37904483532928e-146)
       (/ (log im) (log 10.0))
       (if (<= re 5.659830230443159e+152)
         (*
          (/ 0.5 (sqrt (log 10.0)))
          (log (pow (+ (* re re) (* im im)) (/ 1.0 (sqrt (log 10.0))))))
         (*
          (sqrt 0.5)
          (* (sqrt 0.5) (/ (+ (log 1.0) (* 2.0 (log re))) (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 <= -2.092298405732528e+120)) {
		tmp = ((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 tmp_1;
		if ((re <= -3.0666539773149642e-304)) {
			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.37904483532928e-146)) {
				tmp_2 = (((double) log(im)) / ((double) log(10.0)));
			} else {
				double tmp_3;
				if ((re <= 5.659830230443159e+152)) {
					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) (((double) sqrt(0.5)) * ((double) (((double) sqrt(0.5)) * (((double) (((double) log(1.0)) + ((double) (2.0 * ((double) log(re)))))) / ((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 < -2.09229840573252802e120

    1. Initial program Error: 55.6 bits

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrtError: 55.6 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: 55.6 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: 55.6 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: 55.6 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 -inf Error: 9.0 bits

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

      \[\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 -2.09229840573252802e120 < re < -3.06665397731496424e-304 or 4.37904483532927964e-146 < re < 5.6598302304431586e152

    1. Initial program Error: 19.0 bits

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

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

      \[\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 -3.06665397731496424e-304 < re < 4.37904483532927964e-146

    1. Initial program Error: 31.2 bits

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
    2. Taylor expanded around 0 Error: 34.9 bits

      \[\leadsto \frac{\log \color{blue}{im}}{\log 10}\]

    if 5.6598302304431586e152 < re

    1. Initial program Error: 63.9 bits

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrtError: 63.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: 63.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: 63.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: 63.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 *-un-lft-identityError: 63.9 bits

      \[\leadsto \frac{0.5}{\color{blue}{1 \cdot \sqrt{\log 10}}} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\]
    9. Applied add-sqr-sqrtError: 63.9 bits

      \[\leadsto \frac{\color{blue}{\sqrt{0.5} \cdot \sqrt{0.5}}}{1 \cdot \sqrt{\log 10}} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\]
    10. Applied times-fracError: 63.9 bits

      \[\leadsto \color{blue}{\left(\frac{\sqrt{0.5}}{1} \cdot \frac{\sqrt{0.5}}{\sqrt{\log 10}}\right)} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\]
    11. Applied associate-*l*Error: 63.9 bits

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

      \[\leadsto \frac{\sqrt{0.5}}{1} \cdot \color{blue}{\frac{\sqrt{0.5}}{\frac{\log 10}{\log \left(re \cdot re + im \cdot im\right)}}}\]
    13. Taylor expanded around inf Error: 7.3 bits

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -2.092298405732528 \cdot 10^{+120}:\\ \;\;\;\;\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 -3.0666539773149642 \cdot 10^{-304}:\\ \;\;\;\;\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.37904483532928 \cdot 10^{-146}:\\ \;\;\;\;\frac{\log im}{\log 10}\\ \mathbf{elif}\;re \leq 5.659830230443159 \cdot 10^{+152}:\\ \;\;\;\;\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}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(\sqrt{0.5} \cdot \frac{\log 1 + 2 \cdot \log re}{\log 10}\right)\\ \end{array}\]

Reproduce

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