Average Error: 30.7 → 17.0
Time: 4.2s
Precision: 64
Internal Precision: 128
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -5.519739128629427 \cdot 10^{+138}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 3.1350259460850317 \cdot 10^{-292}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 2.2099941931263505 \cdot 10^{-206}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 5.441512886767404 \cdot 10^{+57}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 4 regimes
  2. if re < -5.519739128629427e+138

    1. Initial program 57.8

      \[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
    2. Initial simplification57.8

      \[\leadsto \log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
    3. Taylor expanded around -inf 7.1

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

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

    if -5.519739128629427e+138 < re < 3.1350259460850317e-292 or 2.2099941931263505e-206 < re < 5.441512886767404e+57

    1. Initial program 19.3

      \[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
    2. Initial simplification19.3

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

    if 3.1350259460850317e-292 < re < 2.2099941931263505e-206

    1. Initial program 31.0

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

      \[\leadsto \log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
    3. Taylor expanded around 0 35.9

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

    if 5.441512886767404e+57 < re

    1. Initial program 44.8

      \[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
    2. Initial simplification44.8

      \[\leadsto \log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
    3. Taylor expanded around inf 10.6

      \[\leadsto \log \color{blue}{re}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification17.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -5.519739128629427 \cdot 10^{+138}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 3.1350259460850317 \cdot 10^{-292}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 2.2099941931263505 \cdot 10^{-206}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 5.441512886767404 \cdot 10^{+57}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Runtime

Time bar (total: 4.2s)Debug logProfile

herbie shell --seed 2018349 
(FPCore (re im)
  :name "math.log/1 on complex, real part"
  (log (sqrt (+ (* re re) (* im im)))))