Average Error: 37.7 → 13.8
Time: 14.4s
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.7
Target32.9
Herbie13.8
\[\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.7

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

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

    \[\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 2018362 +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.2s)Debug log

start77.0ms

Algorithm
intervals

setup29.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 13.3b

localize26.0ms

Local error

Found 3 expressions with local error:

1.0b
(fma (hypot re im) 2.0 (* re 2.0))
0.5b
(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)

series245.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

173.0ms
(sqrt (fma (hypot re im) 2.0 (* re 2.0)))
49.0ms
(fma (hypot re im) 2.0 (* re 2.0))
23.0ms
(hypot re im)

simplify56.0ms

Counts
13 → 43
Calls

13 calls. Slowest were:

18.0ms
(sqrt (* (cbrt (fma (hypot re im) 2.0 (* re 2.0))) (cbrt (fma (hypot re im) 2.0 (* re 2.0)))))
16.0ms
(sqrt (sqrt (fma (hypot re im) 2.0 (* re 2.0))))
9.0ms
(sqrt (fma (hypot re im) 2.0 (* re 2.0)))

prune603.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 13.1b

localize43.0ms

Local error

Found 4 expressions with local error:

1.0b
(fma (hypot re im) 2.0 (* re 2.0))
1.0b
(fma (hypot re im) 2.0 (* 2.0 re))
0.9b
(cbrt (fma (hypot re im) 2.0 (* re 2.0)))
0.9b
(cbrt (fma (hypot re im) 2.0 (* 2.0 re)))

rewrite3.0ms

Algorithm
rewrite-expression-head
Counts
4 → 46
Calls

4 calls. Slowest were:

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

series432.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

178.0ms
(cbrt (fma (hypot re im) 2.0 (* 2.0 re)))
157.0ms
(cbrt (fma (hypot re im) 2.0 (* re 2.0)))
53.0ms
(fma (hypot re im) 2.0 (* 2.0 re))
44.0ms
(fma (hypot re im) 2.0 (* re 2.0))

simplify860.0ms

Counts
18 → 58
Calls

18 calls. Slowest were:

235.0ms
(+ (exp (* 1/3 (+ (log im) (log 2.0)))) (+ (* 0.3333333333333333 (* re (exp (* 1/3 (- (log 2.0) (* 2 (log im))))))) (* 0.05555555555555555 (* (pow re 2) (exp (* 1/3 (- (log 2.0) (* 5 (log im)))))))))
179.0ms
(+ (exp (* 1/3 (+ (log im) (log 2.0)))) (+ (* 0.3333333333333333 (* re (exp (* 1/3 (- (log 2.0) (* 2 (log im))))))) (* 0.05555555555555555 (* (pow re 2) (exp (* 1/3 (- (log 2.0) (* 5 (log im)))))))))
107.0ms
(exp (* 1/3 (- (+ (log (/ -1 re)) (log 1.0)) (* 2 (log (/ -1 im))))))

prune1.2s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 13.1b

localize14.0ms

Local error

Found 4 expressions with local error:

7.8b
(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 (fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0)))
0.0b
(hypot re im)

rewrite7.0ms

Algorithm
rewrite-expression-head
Counts
4 → 66
Calls

4 calls. Slowest were:

5.0ms
(* (sqrt (hypot re im)) (sqrt (hypot re im)))
1.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))

series234.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

130.0ms
(sqrt (fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0)))
49.0ms
(fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0))
30.0ms
(* (sqrt (hypot re im)) (sqrt (hypot re im)))
25.0ms
(hypot re im)

simplify227.0ms

Counts
37 → 78
Calls

37 calls. Slowest were:

83.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)))))
30.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))))
30.0ms
(sqrt (sqrt (fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0))))

prune1.3s

Pruning

13 alts after pruning (12 fresh and 1 done)

Merged error: 13.1b

localize10.0ms

Local error

Found 4 expressions with local error:

7.8b
(fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0))
7.8b
(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)))

rewrite11.0ms

Algorithm
rewrite-expression-head
Counts
4 → 84
Calls

4 calls. Slowest were:

5.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))

series136.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

45.0ms
(fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0))
39.0ms
(fma (* (sqrt (hypot re im)) (sqrt (hypot re im))) 2.0 (* re 2.0))
28.0ms
(* (sqrt (hypot re im)) (sqrt (hypot re im)))
24.0ms
(* (sqrt (hypot re im)) (sqrt (hypot re im)))

simplify102.0ms

Counts
54 → 96
Calls

54 calls. Slowest were:

19.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))))
18.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))))
5.0ms
(+ (* 2.0 re) (* 2.0 im))

prune1.9s

Pruning

13 alts after pruning (11 fresh and 2 done)

Merged error: 13.1b

regimes677.0ms

Accuracy

0% (0.2b remaining)

Error of 13.8b against oracle of 13.6b and baseline of 13.8b

bsearch1.0ms