Average Error: 29.3 → 18.9
Time: 12.2s
Precision: 64
Internal Precision: 128
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.758999353527392 \cdot 10^{+183}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le -1.7987418643598683 \cdot 10^{-280}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{elif}\;re \le 2.4967545228125466 \cdot 10^{-154}:\\ \;\;\;\;im\\ \mathbf{elif}\;re \le 1.5179855035704149 \cdot 10^{+116}:\\ \;\;\;\;\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 4 regimes
  2. if re < -1.758999353527392e+183

    1. Initial program 59.1

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt59.1

      \[\leadsto \sqrt{\color{blue}{\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im}}}\]
    4. Applied sqrt-prod59.1

      \[\leadsto \color{blue}{\sqrt{\sqrt{re \cdot re + im \cdot im}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}}}\]
    5. Taylor expanded around -inf 7.0

      \[\leadsto \color{blue}{-1 \cdot re}\]
    6. Simplified7.0

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

    if -1.758999353527392e+183 < re < -1.7987418643598683e-280 or 2.4967545228125466e-154 < re < 1.5179855035704149e+116

    1. Initial program 19.1

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

    if -1.7987418643598683e-280 < re < 2.4967545228125466e-154

    1. Initial program 29.5

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Taylor expanded around 0 35.5

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

    if 1.5179855035704149e+116 < re

    1. Initial program 51.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -1.758999353527392 \cdot 10^{+183}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le -1.7987418643598683 \cdot 10^{-280}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{elif}\;re \le 2.4967545228125466 \cdot 10^{-154}:\\ \;\;\;\;im\\ \mathbf{elif}\;re \le 1.5179855035704149 \cdot 10^{+116}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Reproduce

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

Details

Time bar (total: 11.6s)Debug log

sample21.0ms

Algorithm
intervals

simplify2.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

2.0ms
(sqrt (+ (* re re) (* im im)))

prune5.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 28.7b

localize10.0ms

Local error

Found 2 expressions with local error:

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

rewrite4.0ms

Algorithm
rewrite-expression-head
Counts
2 → 25
Calls

2 calls. Slowest were:

2.0ms
(+ (* re re) (* im im))
2.0ms
(sqrt (+ (* re re) (* im im)))

series62.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

37.0ms
(+ (* re re) (* im im))
24.0ms
(sqrt (+ (* re re) (* im im)))

simplify263.0ms

Counts
13 → 31
Calls

13 calls. Slowest were:

169.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
46.0ms
(sqrt (+ (pow (* re re) 3) (pow (* im im) 3)))
11.0ms
(* (exp (* re re)) (exp (* im im)))

prune254.0ms

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 5.9b

localize14.0ms

Local error

Found 4 expressions with local error:

28.7b
(sqrt (+ (* re re) (* im im)))
28.7b
(sqrt (+ (* re re) (* im im)))
0.6b
(* (sqrt (sqrt (+ (* re re) (* im im)))) (sqrt (sqrt (+ (* re re) (* im im)))))
0.0b
(sqrt (sqrt (+ (* re re) (* im im))))

rewrite33.0ms

Algorithm
rewrite-expression-head
Counts
4 → 90
Calls

4 calls. Slowest were:

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

series191.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

107.0ms
(sqrt (sqrt (+ (* re re) (* im im))))
33.0ms
(sqrt (+ (* re re) (* im im)))
32.0ms
(sqrt (+ (* re re) (* im im)))
19.0ms
(* (sqrt (sqrt (+ (* re re) (* im im)))) (sqrt (sqrt (+ (* re re) (* im im)))))

simplify2.3s

Counts
74 → 102
Calls

74 calls. Slowest were:

226.0ms
(* (sqrt (sqrt (- (* re re) (* im im)))) (sqrt (sqrt (+ (* (* re re) (* re re)) (- (* (* im im) (* im im)) (* (* re re) (* im im)))))))
187.0ms
(* (sqrt (sqrt (+ (* (* re re) (* re re)) (- (* (* im im) (* im im)) (* (* re re) (* im im)))))) (sqrt (sqrt (- (* re re) (* im im)))))
170.0ms
(* (sqrt (sqrt (+ (pow (* re re) 3) (pow (* im im) 3)))) (sqrt (sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))))

prune873.0ms

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 5.9b

localize10.0ms

Local error

Found 4 expressions with local error:

29.6b
(cbrt (+ (* re re) (* im im)))
29.6b
(cbrt (+ (* re re) (* im im)))
0.3b
(* (fabs (cbrt (+ (* re re) (* im im)))) (sqrt (cbrt (+ (* re re) (* im im)))))
0.1b
(sqrt (cbrt (+ (* re re) (* im im))))

rewrite24.0ms

Algorithm
rewrite-expression-head
Counts
4 → 69
Calls

4 calls. Slowest were:

13.0ms
(* (fabs (cbrt (+ (* re re) (* im im)))) (sqrt (cbrt (+ (* re re) (* im im)))))
4.0ms
(sqrt (cbrt (+ (* re re) (* im im))))
3.0ms
(cbrt (+ (* re re) (* im im)))

series487.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

136.0ms
(* (fabs (cbrt (+ (* re re) (* im im)))) (sqrt (cbrt (+ (* re re) (* im im)))))
119.0ms
(cbrt (+ (* re re) (* im im)))
119.0ms
(cbrt (+ (* re re) (* im im)))
112.0ms
(sqrt (cbrt (+ (* re re) (* im im))))

simplify1.4s

Counts
48 → 81
Calls

48 calls. Slowest were:

222.0ms
(+ (* (fabs (pow (+ (pow im 2) (pow re 2)) 1/3)) (pow im 1/3)) (* 1/6 (* (* (pow re 2) (fabs (pow (+ (pow im 2) (pow re 2)) 1/3))) (pow (/ 1 (pow im 5)) 1/3))))
182.0ms
(cbrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
160.0ms
(sqrt (cbrt (+ (* (* re re) (* re re)) (- (* (* im im) (* im im)) (* (* re re) (* im im))))))

prune973.0ms

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 5.9b

localize13.0ms

Local error

Found 4 expressions with local error:

29.6b
(cbrt (+ (* re re) (* im im)))
29.6b
(cbrt (+ (* re re) (* im im)))
5.9b
(exp (+ (log (fabs (cbrt (+ (* re re) (* im im))))) (log (sqrt (cbrt (+ (* re re) (* im im)))))))
0.3b
(+ (log (fabs (cbrt (+ (* re re) (* im im))))) (log (sqrt (cbrt (+ (* re re) (* im im))))))

rewrite37.0ms

Algorithm
rewrite-expression-head
Counts
4 → 74
Calls

4 calls. Slowest were:

18.0ms
(exp (+ (log (fabs (cbrt (+ (* re re) (* im im))))) (log (sqrt (cbrt (+ (* re re) (* im im)))))))
14.0ms
(+ (log (fabs (cbrt (+ (* re re) (* im im))))) (log (sqrt (cbrt (+ (* re re) (* im im))))))
1.0ms
(cbrt (+ (* re re) (* im im)))

series561.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

222.0ms
(exp (+ (log (fabs (cbrt (+ (* re re) (* im im))))) (log (sqrt (cbrt (+ (* re re) (* im im)))))))
139.0ms
(+ (log (fabs (cbrt (+ (* re re) (* im im))))) (log (sqrt (cbrt (+ (* re re) (* im im))))))
103.0ms
(cbrt (+ (* re re) (* im im)))
96.0ms
(cbrt (+ (* re re) (* im im)))

simplify1.3s

Counts
53 → 86
Calls

53 calls. Slowest were:

213.0ms
(log (sqrt (cbrt (+ (* (* re re) (* re re)) (- (* (* im im) (* im im)) (* (* re re) (* im im)))))))
150.0ms
(cbrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
137.0ms
(exp (+ (log (fabs (cbrt (+ (* re re) (* im im))))) (log (sqrt (cbrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))))))

prune1.2s

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 5.9b

regimes577.0ms

Accuracy

47.7% (11.4b remaining)

Error of 18.9b against oracle of 7.5b and baseline of 29.3b

bsearch162.0ms

end0.0ms

sample883.0ms

Algorithm
intervals