Average Error: 30.8 → 16.9
Time: 1.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 -8.035597533454974 \cdot 10^{+155}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \le -1.5293255908602714 \cdot 10^{-113}:\\ \;\;\;\;\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.3440029639975817 \cdot 10^{-158}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \le 1.1171506678820926 \cdot 10^{+34}:\\ \;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base \cdot \log \left(\sqrt[3]{base}\right) + \log base \cdot \log \left(\sqrt[3]{base} \cdot \sqrt[3]{base}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im \cdot \log base}{\log base \cdot \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.035597533454974e+155 or -1.5293255908602714e-113 < im < 1.3440029639975817e-158

    1. Initial program 38.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. Simplified38.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-inv38.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. 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. Simplified20.7

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

    if -8.035597533454974e+155 < im < -1.5293255908602714e-113

    1. Initial program 15.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. Simplified15.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-inv15.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 1.3440029639975817e-158 < im < 1.1171506678820926e+34

    1. Initial program 14.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. Simplified14.8

      \[\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 add-cube-cbrt14.8

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log \color{blue}{\left(\left(\sqrt[3]{base} \cdot \sqrt[3]{base}\right) \cdot \sqrt[3]{base}\right)}}\]
    5. Applied log-prod14.9

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \color{blue}{\left(\log \left(\sqrt[3]{base} \cdot \sqrt[3]{base}\right) + \log \left(\sqrt[3]{base}\right)\right)}}\]
    6. Applied distribute-rgt-in14.9

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

    if 1.1171506678820926e+34 < im

    1. Initial program 43.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. Simplified43.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 12.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \le -8.035597533454974 \cdot 10^{+155}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \le -1.5293255908602714 \cdot 10^{-113}:\\ \;\;\;\;\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.3440029639975817 \cdot 10^{-158}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \le 1.1171506678820926 \cdot 10^{+34}:\\ \;\;\;\;\frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base \cdot \log \left(\sqrt[3]{base}\right) + \log base \cdot \log \left(\sqrt[3]{base} \cdot \sqrt[3]{base}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im \cdot \log base}{\log base \cdot \log base}\\ \end{array}\]

Reproduce

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