Average Error: 32.2 → 7.4
Time: 7.9s
Precision: binary64
\[[re, im]=\mathsf{sort}([re, im])\]
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}\]
\[\begin{array}{l} \mathbf{if}\;re \leq -1.1064451278764455 \cdot 10^{+77}:\\ \;\;\;\;\log \left(\sqrt[3]{-re}\right) \cdot \frac{2}{\log base} + \log \left({\left(-re\right)}^{\left(\frac{0.3333333333333333}{\log base}\right)}\right)\\ \mathbf{elif}\;re \leq -3.2946587297450698 \cdot 10^{-115}:\\ \;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}
\begin{array}{l}
\mathbf{if}\;re \leq -1.1064451278764455 \cdot 10^{+77}:\\
\;\;\;\;\log \left(\sqrt[3]{-re}\right) \cdot \frac{2}{\log base} + \log \left({\left(-re\right)}^{\left(\frac{0.3333333333333333}{\log base}\right)}\right)\\

\mathbf{elif}\;re \leq -3.2946587297450698 \cdot 10^{-115}:\\
\;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}\\

\mathbf{else}:\\
\;\;\;\;\frac{\log im}{\log base}\\

\end{array}
(FPCore (re im base)
 :precision binary64
 (/
  (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0))
  (+ (* (log base) (log base)) (* 0.0 0.0))))
(FPCore (re im base)
 :precision binary64
 (if (<= re -1.1064451278764455e+77)
   (+
    (* (log (cbrt (- re))) (/ 2.0 (log base)))
    (log (pow (- re) (/ 0.3333333333333333 (log base)))))
   (if (<= re -3.2946587297450698e-115)
     (/ (log (sqrt (+ (* re re) (* im im)))) (log base))
     (/ (log im) (log base)))))
double code(double re, double im, double base) {
	return ((log(sqrt((re * re) + (im * im))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
}
double code(double re, double im, double base) {
	double tmp;
	if (re <= -1.1064451278764455e+77) {
		tmp = (log(cbrt(-re)) * (2.0 / log(base))) + log(pow(-re, (0.3333333333333333 / log(base))));
	} else if (re <= -3.2946587297450698e-115) {
		tmp = log(sqrt((re * re) + (im * im))) / log(base);
	} else {
		tmp = log(im) / log(base);
	}
	return tmp;
}

Error

Bits error versus re

Bits error versus im

Bits error versus base

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if re < -1.10644512787644547e77

    1. Initial program 47.0

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}\]
    2. Simplified47.0

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Taylor expanded around -inf 5.7

      \[\leadsto \frac{\log \color{blue}{\left(-1 \cdot re\right)}}{\log base}\]
    4. Simplified5.7

      \[\leadsto \frac{\log \color{blue}{\left(-re\right)}}{\log base}\]
    5. Using strategy rm
    6. Applied add-log-exp_binary645.8

      \[\leadsto \color{blue}{\log \left(e^{\frac{\log \left(-re\right)}{\log base}}\right)}\]
    7. Simplified5.8

      \[\leadsto \log \color{blue}{\left({\left(-re\right)}^{\left(\frac{1}{\log base}\right)}\right)}\]
    8. Using strategy rm
    9. Applied add-cube-cbrt_binary645.8

      \[\leadsto \log \left({\color{blue}{\left(\left(\sqrt[3]{-re} \cdot \sqrt[3]{-re}\right) \cdot \sqrt[3]{-re}\right)}}^{\left(\frac{1}{\log base}\right)}\right)\]
    10. Applied unpow-prod-down_binary645.9

      \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{-re} \cdot \sqrt[3]{-re}\right)}^{\left(\frac{1}{\log base}\right)} \cdot {\left(\sqrt[3]{-re}\right)}^{\left(\frac{1}{\log base}\right)}\right)}\]
    11. Applied log-prod_binary645.9

      \[\leadsto \color{blue}{\log \left({\left(\sqrt[3]{-re} \cdot \sqrt[3]{-re}\right)}^{\left(\frac{1}{\log base}\right)}\right) + \log \left({\left(\sqrt[3]{-re}\right)}^{\left(\frac{1}{\log base}\right)}\right)}\]
    12. Simplified5.8

      \[\leadsto \color{blue}{\log \left(\sqrt[3]{-re}\right) \cdot \frac{2}{\log base}} + \log \left({\left(\sqrt[3]{-re}\right)}^{\left(\frac{1}{\log base}\right)}\right)\]
    13. Simplified5.7

      \[\leadsto \log \left(\sqrt[3]{-re}\right) \cdot \frac{2}{\log base} + \color{blue}{\frac{\log \left(\sqrt[3]{-re}\right)}{\log base}}\]
    14. Using strategy rm
    15. Applied add-log-exp_binary645.8

      \[\leadsto \log \left(\sqrt[3]{-re}\right) \cdot \frac{2}{\log base} + \color{blue}{\log \left(e^{\frac{\log \left(\sqrt[3]{-re}\right)}{\log base}}\right)}\]
    16. Simplified5.8

      \[\leadsto \log \left(\sqrt[3]{-re}\right) \cdot \frac{2}{\log base} + \log \color{blue}{\left({\left(-re\right)}^{\left(\frac{0.3333333333333333}{\log base}\right)}\right)}\]

    if -1.10644512787644547e77 < re < -3.2946587297450698e-115

    1. Initial program 10.9

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}\]
    2. Simplified10.8

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity_binary6410.8

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{1 \cdot \left(re \cdot re + im \cdot im\right)}}\right)}{\log base}\]

    if -3.2946587297450698e-115 < re

    1. Initial program 31.2

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}\]
    2. Simplified31.2

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Taylor expanded around 0 7.0

      \[\leadsto \frac{\log \color{blue}{im}}{\log base}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification7.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.1064451278764455 \cdot 10^{+77}:\\ \;\;\;\;\log \left(\sqrt[3]{-re}\right) \cdot \frac{2}{\log base} + \log \left({\left(-re\right)}^{\left(\frac{0.3333333333333333}{\log base}\right)}\right)\\ \mathbf{elif}\;re \leq -3.2946587297450698 \cdot 10^{-115}:\\ \;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]

Reproduce

herbie shell --seed 2021175 
(FPCore (re im base)
  :name "math.log/2 on complex, real part"
  :precision binary64
  (/ (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))