Average Error: 30.6 → 16.8
Time: 4.0s
Precision: 64
Internal Precision: 128
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -7.789292292252237 \cdot 10^{+91}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -9.822124712647819 \cdot 10^{-160}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le -6.662904712098817 \cdot 10^{-302}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 3.4365928272036043 \cdot 10^{+131}:\\ \;\;\;\;\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 < -7.789292292252237e+91

    1. Initial program 48.4

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

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

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

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

    if -7.789292292252237e+91 < re < -9.822124712647819e-160 or -6.662904712098817e-302 < re < 3.4365928272036043e+131

    1. Initial program 18.2

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

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

    if -9.822124712647819e-160 < re < -6.662904712098817e-302

    1. Initial program 32.2

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

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

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

    if 3.4365928272036043e+131 < re

    1. Initial program 56.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -7.789292292252237 \cdot 10^{+91}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -9.822124712647819 \cdot 10^{-160}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le -6.662904712098817 \cdot 10^{-302}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 3.4365928272036043 \cdot 10^{+131}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Runtime

Time bar (total: 4.0s)Debug logProfile

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