Average Error: 37.5 → 13.2
Time: 14.1s
Precision: 64
Internal Precision: 128
\[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\]
\[\sqrt{(\left(\sqrt{re^2 + im^2}^*\right) \cdot 2.0 + \left(re \cdot 2.0\right))_*} \cdot 0.5\]

Error

Bits error versus re

Bits error versus im

Target

Original37.5
Target32.6
Herbie13.2
\[\begin{array}{l} \mathbf{if}\;re \lt 0:\\ \;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{im \cdot im}{\sqrt{re \cdot re + im \cdot im} - re}}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\ \end{array}\]

Derivation

  1. Initial program 37.5

    \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\]
  2. Initial simplification13.2

    \[\leadsto 0.5 \cdot \sqrt{(\left(\sqrt{re^2 + im^2}^*\right) \cdot 2.0 + \left(re \cdot 2.0\right))_*}\]
  3. Final simplification13.2

    \[\leadsto \sqrt{(\left(\sqrt{re^2 + im^2}^*\right) \cdot 2.0 + \left(re \cdot 2.0\right))_*} \cdot 0.5\]

Reproduce

herbie shell --seed 2018360 +o rules:numerics
(FPCore (re im)
  :name "math.sqrt on complex, real part"

  :herbie-target
  (if (< re 0) (* 0.5 (* (sqrt 2) (sqrt (/ (* im im) (- (sqrt (+ (* re re) (* im im))) re))))) (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))

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

Details

Time bar (total: 8.5s)Debug log

start66.0ms

Algorithm
intervals

setup49.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 10.4b

localize15.0ms

Local error

Found 3 expressions with local error:

0.7b
(fma (hypot re im) 2.0 (* re 2.0))
0.0b
(sqrt (fma (hypot re im) 2.0 (* re 2.0)))
0.0b
(hypot re im)

rewrite2.0ms

Algorithm
rewrite-expression-head
Counts
3 → 34
Calls

3 calls. Slowest were:

1.0ms
(sqrt (fma (hypot re im) 2.0 (* re 2.0)))
0.0ms
(fma (hypot re im) 2.0 (* re 2.0))
0.0ms
(hypot re im)

series223.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

145.0ms
(sqrt (fma (hypot re im) 2.0 (* re 2.0)))
54.0ms
(fma (hypot re im) 2.0 (* re 2.0))
25.0ms
(hypot re im)

simplify69.0ms

Counts
13 → 43
Calls

13 calls. Slowest were:

16.0ms
(sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0))))
15.0ms
(sqrt (fma (hypot re im) 2.0 (* re 2.0)))
14.0ms
(sqrt (* (cbrt (fma (hypot re im) 2.0 (* re 2.0))) (cbrt (fma (hypot re im) 2.0 (* re 2.0)))))

prune569.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 10.3b

localize9.0ms

Local error

Found 4 expressions with local error:

0.7b
(fma (hypot re im) 2.0 (* re 2.0))
0.7b
(fma (hypot re im) 2.0 (* re 2.0))
0.5b
(* (sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0)))) (sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0)))))
0.2b
(sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0))))

rewrite8.0ms

Algorithm
rewrite-expression-head
Counts
4 → 76
Calls

4 calls. Slowest were:

6.0ms
(* (sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0)))) (sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0)))))
1.0ms
(sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0))))
0.0ms
(fma (hypot re im) 2.0 (* re 2.0))

series405.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

154.0ms
(* (sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0)))) (sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0)))))
143.0ms
(sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0))))
56.0ms
(fma (hypot re im) 2.0 (* re 2.0))
51.0ms
(fma (hypot re im) 2.0 (* re 2.0))

simplify1.2s

Counts
48 → 88
Calls

48 calls. Slowest were:

409.0ms
(exp (* 1/4 (- (+ (log (/ -1 re)) (log 1.0)) (* 2 (log (/ -1 im))))))
199.0ms
(+ (* 0.03125 (* (pow re 2) (exp (* 1/4 (- (log 2.0) (* 7 (log im))))))) (+ (* 0.25 (* re (exp (* 1/4 (- (log 2.0) (* 3 (log im))))))) (exp (* 1/4 (+ (log im) (log 2.0))))))
114.0ms
(* (* (* (sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0)))) (sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0))))) (sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0))))) (* (* (sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0)))) (sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0))))) (sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0))))))

prune1.4s

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 10.3b

localize20.0ms

Local error

Found 4 expressions with local error:

5.1b
(fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0))
0.5b
(* (sqrt (hypot re im)) (sqrt (hypot re im)))
0.0b
(sqrt (fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0)))
0.0b
(hypot re im)

rewrite13.0ms

Algorithm
rewrite-expression-head
Counts
4 → 66
Calls

4 calls. Slowest were:

9.0ms
(* (sqrt (hypot re im)) (sqrt (hypot re im)))
2.0ms
(sqrt (fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0)))
0.0ms
(fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0))

series262.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

144.0ms
(sqrt (fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0)))
55.0ms
(fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0))
38.0ms
(hypot re im)
25.0ms
(* (sqrt (hypot re im)) (sqrt (hypot re im)))

simplify113.0ms

Counts
37 → 78
Calls

37 calls. Slowest were:

29.0ms
(* (* (* (sqrt (hypot re im)) (sqrt (hypot re im))) (sqrt (hypot re im))) (* (* (sqrt (hypot re im)) (sqrt (hypot re im))) (sqrt (hypot re im))))
14.0ms
(sqrt (* (cbrt (fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0))) (cbrt (fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0)))))
13.0ms
(sqrt (sqrt (fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0))))

prune1.1s

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 10.2b

localize17.0ms

Local error

Found 4 expressions with local error:

5.1b
(fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0))
5.1b
(fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0))
0.5b
(* (sqrt (hypot re im)) (sqrt (hypot re im)))
0.5b
(* (sqrt (hypot re im)) (sqrt (hypot re im)))

rewrite16.0ms

Algorithm
rewrite-expression-head
Counts
4 → 84
Calls

4 calls. Slowest were:

10.0ms
(* (sqrt (hypot re im)) (sqrt (hypot re im)))
5.0ms
(* (sqrt (hypot re im)) (sqrt (hypot re im)))
0.0ms
(fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0))

series164.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

44.0ms
(fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0))
42.0ms
(fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0))
39.0ms
(* (sqrt (hypot re im)) (sqrt (hypot re im)))
39.0ms
(* (sqrt (hypot re im)) (sqrt (hypot re im)))

simplify125.0ms

Counts
54 → 96
Calls

54 calls. Slowest were:

33.0ms
(* (* (* (sqrt (hypot re im)) (sqrt (hypot re im))) (sqrt (hypot re im))) (* (* (sqrt (hypot re im)) (sqrt (hypot re im))) (sqrt (hypot re im))))
17.0ms
(* (* (* (sqrt (hypot re im)) (sqrt (hypot re im))) (sqrt (hypot re im))) (* (* (sqrt (hypot re im)) (sqrt (hypot re im))) (sqrt (hypot re im))))
6.0ms
(+ (* 2.0 re) (* 2.0 im))

prune1.8s

Pruning

11 alts after pruning (9 fresh and 2 done)

Merged error: 10.2b

regimes842.0ms

Accuracy

0% (0.2b remaining)

Error of 13.2b against oracle of 13.0b and baseline of 13.2b

bsearch2.0ms