Average Error: 31.1 → 19.2
Time: 2.3m
Precision: 64
Internal Precision: 128
\[\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}\;im \le -2.228097761837566 \cdot 10^{-51}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\log base}\\ \mathbf{elif}\;im \le 1.253012063700988 \cdot 10^{-140}:\\ \;\;\;\;\left(\log \left(\frac{-1}{\sqrt[3]{re}}\right) + \log \left(\frac{1}{\sqrt[3]{re} \cdot \sqrt[3]{re}}\right)\right) \cdot \frac{-1}{\log base}\\ \mathbf{elif}\;im \le 9.918304620781304 \cdot 10^{-17}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\log base}\\ \mathbf{elif}\;im \le 2.172664113277433 \cdot 10^{+21}:\\ \;\;\;\;\left(\log \left(\frac{-1}{\sqrt[3]{re}}\right) + \log \left(\frac{1}{\sqrt[3]{re} \cdot \sqrt[3]{re}}\right)\right) \cdot \frac{-1}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]

Error

Bits error versus re

Bits error versus im

Bits error versus base

Derivation

  1. Split input into 3 regimes
  2. if im < -2.228097761837566e-51 or 1.253012063700988e-140 < im < 9.918304620781304e-17

    1. Initial program 30.7

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

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

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

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log \color{blue}{\left({base}^{1}\right)} \cdot \left(1 \cdot \log base\right)}\]
    6. Applied log-pow30.7

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\left(1 \cdot \log base\right)} \cdot \left(1 \cdot \log base\right)}\]
    7. Applied swap-sqr30.7

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{{\left(re \cdot re + im \cdot im\right)}^{1}}}\right) \cdot \log base}{\left(1 \cdot 1\right) \cdot \left(\log base \cdot \log base\right)}\]
    9. Applied sqrt-pow130.7

      \[\leadsto \frac{\log \color{blue}{\left({\left(re \cdot re + im \cdot im\right)}^{\left(\frac{1}{2}\right)}\right)} \cdot \log base}{\left(1 \cdot 1\right) \cdot \left(\log base \cdot \log base\right)}\]
    10. Applied log-pow30.7

      \[\leadsto \frac{\color{blue}{\left(\frac{1}{2} \cdot \log \left(re \cdot re + im \cdot im\right)\right)} \cdot \log base}{\left(1 \cdot 1\right) \cdot \left(\log base \cdot \log base\right)}\]
    11. Applied associate-*l*30.7

      \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot \left(\log \left(re \cdot re + im \cdot im\right) \cdot \log base\right)}}{\left(1 \cdot 1\right) \cdot \left(\log base \cdot \log base\right)}\]
    12. Applied times-frac30.7

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{1 \cdot 1} \cdot \frac{\log \left(re \cdot re + im \cdot im\right) \cdot \log base}{\log base \cdot \log base}}\]
    13. Simplified30.7

      \[\leadsto \color{blue}{\frac{1}{2}} \cdot \frac{\log \left(re \cdot re + im \cdot im\right) \cdot \log base}{\log base \cdot \log base}\]
    14. Simplified30.7

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

    if -2.228097761837566e-51 < im < 1.253012063700988e-140 or 9.918304620781304e-17 < im < 2.172664113277433e+21

    1. Initial program 25.4

      \[\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. Simplified25.4

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

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

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

      \[\leadsto -\frac{\log \color{blue}{\left(e^{\log \left(\frac{-1}{re}\right)}\right)}}{\log base}\]
    7. Applied rem-log-exp11.2

      \[\leadsto -\frac{\color{blue}{\log \left(\frac{-1}{re}\right)}}{\log base}\]
    8. Using strategy rm
    9. Applied div-inv11.2

      \[\leadsto -\color{blue}{\log \left(\frac{-1}{re}\right) \cdot \frac{1}{\log base}}\]
    10. Using strategy rm
    11. Applied add-cube-cbrt11.3

      \[\leadsto -\log \left(\frac{-1}{\color{blue}{\left(\sqrt[3]{re} \cdot \sqrt[3]{re}\right) \cdot \sqrt[3]{re}}}\right) \cdot \frac{1}{\log base}\]
    12. Applied *-un-lft-identity11.3

      \[\leadsto -\log \left(\frac{\color{blue}{1 \cdot -1}}{\left(\sqrt[3]{re} \cdot \sqrt[3]{re}\right) \cdot \sqrt[3]{re}}\right) \cdot \frac{1}{\log base}\]
    13. Applied times-frac11.3

      \[\leadsto -\log \color{blue}{\left(\frac{1}{\sqrt[3]{re} \cdot \sqrt[3]{re}} \cdot \frac{-1}{\sqrt[3]{re}}\right)} \cdot \frac{1}{\log base}\]
    14. Applied log-prod11.3

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

    if 2.172664113277433e+21 < im

    1. Initial program 40.8

      \[\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. Simplified40.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \le -2.228097761837566 \cdot 10^{-51}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\log base}\\ \mathbf{elif}\;im \le 1.253012063700988 \cdot 10^{-140}:\\ \;\;\;\;\left(\log \left(\frac{-1}{\sqrt[3]{re}}\right) + \log \left(\frac{1}{\sqrt[3]{re} \cdot \sqrt[3]{re}}\right)\right) \cdot \frac{-1}{\log base}\\ \mathbf{elif}\;im \le 9.918304620781304 \cdot 10^{-17}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\log base}\\ \mathbf{elif}\;im \le 2.172664113277433 \cdot 10^{+21}:\\ \;\;\;\;\left(\log \left(\frac{-1}{\sqrt[3]{re}}\right) + \log \left(\frac{1}{\sqrt[3]{re} \cdot \sqrt[3]{re}}\right)\right) \cdot \frac{-1}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]

Reproduce

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