Average Error: 30.3 → 16.4
Time: 1.6m
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 -9.254070271474318 \cdot 10^{+157}:\\ \;\;\;\;\log \left(-re\right) \cdot \left(\log base \cdot \frac{1}{\log base \cdot \log base}\right)\\ \mathbf{elif}\;im \le -2.8360739299980355 \cdot 10^{-74}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \left(\log base \cdot \frac{1}{\log base \cdot \log base}\right)\\ \mathbf{elif}\;im \le 2.87570452156065 \cdot 10^{-149}:\\ \;\;\;\;\frac{-\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \le 6.978321740802736 \cdot 10^{+74}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \left(\log base \cdot \frac{1}{\log base \cdot \log base}\right)\\ \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 4 regimes
  2. if im < -9.254070271474318e+157

    1. Initial program 62.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. Simplified62.0

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

      \[\leadsto \color{blue}{\left(\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base\right) \cdot \frac{1}{\log base \cdot \log base}}\]
    5. Using strategy rm
    6. Applied associate-*l*62.0

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

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

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

    if -9.254070271474318e+157 < im < -2.8360739299980355e-74 or 2.87570452156065e-149 < im < 6.978321740802736e+74

    1. Initial program 15.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. Simplified15.4

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

      \[\leadsto \color{blue}{\left(\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base\right) \cdot \frac{1}{\log base \cdot \log base}}\]
    5. Using strategy rm
    6. Applied associate-*l*15.4

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

    if -2.8360739299980355e-74 < im < 2.87570452156065e-149

    1. Initial program 26.6

      \[\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. Simplified26.6

      \[\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 div-inv26.6

      \[\leadsto \color{blue}{\left(\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base\right) \cdot \frac{1}{\log base \cdot \log base}}\]
    5. Using strategy rm
    6. Applied associate-*l*26.6

      \[\leadsto \color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \left(\log base \cdot \frac{1}{\log base \cdot \log base}\right)}\]
    7. 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)}}\]
    8. Simplified8.5

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

    if 6.978321740802736e+74 < im

    1. Initial program 45.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \le -9.254070271474318 \cdot 10^{+157}:\\ \;\;\;\;\log \left(-re\right) \cdot \left(\log base \cdot \frac{1}{\log base \cdot \log base}\right)\\ \mathbf{elif}\;im \le -2.8360739299980355 \cdot 10^{-74}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \left(\log base \cdot \frac{1}{\log base \cdot \log base}\right)\\ \mathbf{elif}\;im \le 2.87570452156065 \cdot 10^{-149}:\\ \;\;\;\;\frac{-\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \le 6.978321740802736 \cdot 10^{+74}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \left(\log base \cdot \frac{1}{\log base \cdot \log base}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]

Reproduce

herbie shell --seed 2019091 
(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))))