Average Error: 29.7 → 16.2
Time: 2.4s
Precision: 64
Internal Precision: 128
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -2.0059171689987356 \cdot 10^{+152}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 8.497170838155968 \cdot 10^{+123}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;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 3 regimes
  2. if re < -2.0059171689987356e+152

    1. Initial program 58.7

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Taylor expanded around -inf 6.8

      \[\leadsto \color{blue}{-1 \cdot re}\]
    3. Simplified6.8

      \[\leadsto \color{blue}{-re}\]

    if -2.0059171689987356e+152 < re < 8.497170838155968e+123

    1. Initial program 19.4

      \[\sqrt{re \cdot re + im \cdot im}\]

    if 8.497170838155968e+123 < re

    1. Initial program 52.5

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Taylor expanded around inf 9.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -2.0059171689987356 \cdot 10^{+152}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 8.497170838155968 \cdot 10^{+123}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Reproduce

herbie shell --seed 2018362 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))

Details

Time bar (total: 1.1s)Debug log

start59.0ms

Algorithm
intervals

setup18.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 28.3b

localize21.0ms

Local error

Found 2 expressions with local error:

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

rewrite8.0ms

Algorithm
rewrite-expression-head
Counts
2 → 25
Calls

2 calls. Slowest were:

4.0ms
(+ (* re re) (* im im))
3.0ms
(sqrt (+ (* re re) (* im im)))

series57.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

31.0ms
(sqrt (+ (* re re) (* im im)))
25.0ms
(+ (* re re) (* im im))

simplify207.0ms

Counts
13 → 31
Calls

13 calls. Slowest were:

114.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
60.0ms
(sqrt (+ (pow (* re re) 3) (pow (* im im) 3)))
6.0ms
(* (exp (* re re)) (exp (* im im)))

prune243.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 6.2b

localize2.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Counts
0 → 0
Calls

0 calls. Slowest were:

series0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

simplify0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

prune3.0ms

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 6.2b

localize0.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Counts
0 → 0
Calls

0 calls. Slowest were:

series0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

simplify0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

prune2.0ms

Pruning

4 alts after pruning (1 fresh and 3 done)

Merged error: 6.2b

localize0.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Counts
0 → 0
Calls

0 calls. Slowest were:

series0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

simplify0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

prune0.0ms

Pruning

4 alts after pruning (0 fresh and 4 done)

Merged error: 6.2b

regimes344.0ms

Accuracy

59.7% (9.1b remaining)

Error of 16.2b against oracle of 7.1b and baseline of 29.7b

bsearch115.0ms