Average Error: 30.2 → 16.9
Time: 3.9s
Precision: 64
Internal Precision: 128
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.9364774160021398 \cdot 10^{+120}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -2.9339755235237833 \cdot 10^{-189}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 1.4935847129797585 \cdot 10^{-169}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 1.5586682963470567 \cdot 10^{+111}:\\ \;\;\;\;\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 < -1.9364774160021398e+120

    1. Initial program 53.9

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

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

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

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

    if -1.9364774160021398e+120 < re < -2.9339755235237833e-189 or 1.4935847129797585e-169 < re < 1.5586682963470567e+111

    1. Initial program 15.5

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

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

    if -2.9339755235237833e-189 < re < 1.4935847129797585e-169

    1. Initial program 30.3

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

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

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

    if 1.5586682963470567e+111 < re

    1. Initial program 51.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -1.9364774160021398 \cdot 10^{+120}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -2.9339755235237833 \cdot 10^{-189}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 1.4935847129797585 \cdot 10^{-169}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 1.5586682963470567 \cdot 10^{+111}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Runtime

Time bar (total: 3.9s)Debug logProfile

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