Average Error: 30.6 → 16.8
Time: 4.2s
Precision: 64
Internal Precision: 576
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -5.536892084933209 \cdot 10^{+91}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -2.786453322648853 \cdot 10^{-243}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 8.606501216036279 \cdot 10^{-297}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 1.6787553883878222 \cdot 10^{+68}:\\ \;\;\;\;\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.536892084933209e+91

    1. Initial program 48.5

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

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

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

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

    if -5.536892084933209e+91 < re < -2.786453322648853e-243 or 8.606501216036279e-297 < re < 1.6787553883878222e+68

    1. Initial program 19.9

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

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

    if -2.786453322648853e-243 < re < 8.606501216036279e-297

    1. Initial program 30.0

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

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

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

    if 1.6787553883878222e+68 < re

    1. Initial program 45.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -5.536892084933209 \cdot 10^{+91}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -2.786453322648853 \cdot 10^{-243}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 8.606501216036279 \cdot 10^{-297}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 1.6787553883878222 \cdot 10^{+68}:\\ \;\;\;\;\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 2018250 
(FPCore (re im)
  :name "math.log/1 on complex, real part"
  (log (sqrt (+ (* re re) (* im im)))))