Average Error: 31.2 → 12.7
Time: 4.0s
Precision: 64
Internal precision: 384
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.588918563866528 \cdot 10^{+86}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{if}\;re \le -2.321564696919607 \cdot 10^{-245}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right)\\ \mathbf{if}\;re \le -2.837848394186995 \cdot 10^{-306}:\\ \;\;\;\;\log im\\ \mathbf{if}\;re \le 6.000404463137166 \cdot 10^{+126}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Error

Bits error versus re

Bits error versus im

Derivation

  1. Split input into 4 regimes.
  2. if re < -1.588918563866528e+86

    1. Initial program 48.9

      \[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
    2. Applied taylor 0

      \[\leadsto \log \left(-1 \cdot re\right)\]
    3. Taylor expanded around -inf 0

      \[\leadsto \log \color{blue}{\left(-1 \cdot re\right)}\]
    4. Applied simplify 0

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

    if -1.588918563866528e+86 < re < -2.321564696919607e-245 or -2.837848394186995e-306 < re < 6.000404463137166e+126

    1. Initial program 20.0

      \[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]

    if -2.321564696919607e-245 < re < -2.837848394186995e-306

    1. Initial program 32.1

      \[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
    2. Applied taylor 0

      \[\leadsto \log im\]
    3. Taylor expanded around 0 0

      \[\leadsto \log \color{blue}{im}\]

    if 6.000404463137166e+126 < re

    1. Initial program 55.6

      \[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
    2. Applied taylor 0

      \[\leadsto \log re\]
    3. Taylor expanded around inf 0

      \[\leadsto \log \color{blue}{re}\]
  3. Recombined 4 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 4.0s) Debug logProfile

Please include this information when filing a bug report:

herbie shell --seed '#(1064524629 4159152179 2999149171 575749698 4006532819 692958815)'
(FPCore (re im)
  :name "math.log/1 on complex, real part"
  (log (sqrt (+ (* re re) (* im im)))))