Average Error: 31.6 → 17.3
Time: 1.2m
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 -8.367206787019339 \cdot 10^{+158}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \le -6.1852802060230526 \cdot 10^{-114}:\\ \;\;\;\;\left(\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)\right) \cdot \frac{1}{\log base \cdot \log base}\\ \mathbf{elif}\;im \le 1.133776848209156 \cdot 10^{-173}:\\ \;\;\;\;\frac{\log \left(-re\right) \cdot \log base}{\log base \cdot \log base}\\ \mathbf{elif}\;im \le 7.312099337350854 \cdot 10^{+61}:\\ \;\;\;\;\left(\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)\right) \cdot \frac{1}{\log base \cdot \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 4 regimes
  2. if im < -8.367206787019339e+158

    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. 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)}}\]
    6. Simplified50.6

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

    if -8.367206787019339e+158 < im < -6.1852802060230526e-114 or 1.133776848209156e-173 < im < 7.312099337350854e+61

    1. Initial program 16.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. Simplified16.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-inv16.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}}\]

    if -6.1852802060230526e-114 < im < 1.133776848209156e-173

    1. Initial program 28.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. Simplified28.7

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

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

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

    if 7.312099337350854e+61 < im

    1. Initial program 45.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. Simplified45.9

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

      \[\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. Taylor expanded around 0 10.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \le -8.367206787019339 \cdot 10^{+158}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \le -6.1852802060230526 \cdot 10^{-114}:\\ \;\;\;\;\left(\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)\right) \cdot \frac{1}{\log base \cdot \log base}\\ \mathbf{elif}\;im \le 1.133776848209156 \cdot 10^{-173}:\\ \;\;\;\;\frac{\log \left(-re\right) \cdot \log base}{\log base \cdot \log base}\\ \mathbf{elif}\;im \le 7.312099337350854 \cdot 10^{+61}:\\ \;\;\;\;\left(\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)\right) \cdot \frac{1}{\log base \cdot \log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]

Reproduce

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