Average Error: 30.9 → 16.7
Time: 3.1s
Precision: 64
Internal Precision: 128
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -7.61821412696286 \cdot 10^{+150}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -5.536443801166738 \cdot 10^{-261}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 2.727916884694162 \cdot 10^{-303}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 5.667469564790048 \cdot 10^{+145}:\\ \;\;\;\;\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.61821412696286e+150

    1. Initial program 61.3

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

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

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

    if -7.61821412696286e+150 < re < -5.536443801166738e-261 or 2.727916884694162e-303 < re < 5.667469564790048e+145

    1. Initial program 19.6

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

    if -5.536443801166738e-261 < re < 2.727916884694162e-303

    1. Initial program 32.3

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

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

    if 5.667469564790048e+145 < re

    1. Initial program 59.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -7.61821412696286 \cdot 10^{+150}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -5.536443801166738 \cdot 10^{-261}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 2.727916884694162 \cdot 10^{-303}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 5.667469564790048 \cdot 10^{+145}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Reproduce

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

Details

Time bar (total: 2.3s)Debug log

sample40.0ms

Algorithm
intervals
Results
29.0ms256×body80valid

simplify5.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
5.0ms
(log (sqrt (+ (* re re) (* im im))))

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 32.1b

localize27.0ms

Local error

Found 2 expressions with local error:

31.0b
(sqrt (+ (* re re) (* im im)))
0.0b
(+ (* re re) (* im im))

rewrite6.0ms

Algorithm
rewrite-expression-head
Rules
add-log-exp
add-sqr-sqrt
sqrt-prod
add-cube-cbrt
*-un-lft-identity
flip-+
add-exp-log
sqrt-div
add-cbrt-cube
flip3-+
pow1
pow1/2
sum-log
rem-sqrt-square
+-commutative
Counts
2 → 25
Calls
2 calls:
Slowest
3.0ms
(sqrt (+ (* re re) (* im im)))
2.0ms
(+ (* re re) (* im im))

series58.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
41.0ms
(sqrt (+ (* re re) (* im im)))
17.0ms
(+ (* re re) (* im im))

simplify222.0ms

Counts
13 → 31
Calls
13 calls:
Slowest
134.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
41.0ms
(sqrt (+ (pow (* re re) 3) (pow (* im im) 3)))
13.0ms
(* (exp (* re re)) (exp (* im im)))
5.0ms
(+ (pow im 2) (pow re 2))
5.0ms
(+ (pow im 2) (pow re 2))

prune289.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 6.5b

localize9.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Rules
Counts
0 → 0
Calls
0 calls:
Slowest

series0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

simplify0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

prune8.0ms

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 6.5b

localize5.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Rules
Counts
0 → 0
Calls
0 calls:
Slowest

series0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

simplify0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

prune4.0ms

Pruning

4 alts after pruning (1 fresh and 3 done)

Merged error: 6.5b

localize5.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Rules
Counts
0 → 0
Calls
0 calls:
Slowest

series0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

simplify0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

prune1.0ms

Pruning

4 alts after pruning (0 fresh and 4 done)

Merged error: 6.5b

regimes416.0ms

Accuracy

59.8% (9.5b remaining)

Error of 16.7b against oracle of 7.2b and baseline of 30.9b

bsearch175.0ms

end0.0ms

sample1.0s

Algorithm
intervals
Results
879.0ms8000×body80valid