Average Error: 37.3 → 13.4
Time: 15.2s
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.3
Target32.2
Herbie13.4
\[\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.3

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

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

    \[\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 2018365 +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: 9.6s)Debug log

start73.0ms

Algorithm
intervals

setup47.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 15.0b

localize25.0ms

Local error

Found 2 expressions with local error:

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

rewrite1.0ms

Algorithm
rewrite-expression-head
Counts
2 → 24
Calls

2 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))

series162.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

121.0ms
(sqrt (fma (hypot re im) 2.0 (* re 2.0)))
40.0ms
(fma (hypot re im) 2.0 (* re 2.0))

simplify58.0ms

Counts
10 → 30
Calls

10 calls. Slowest were:

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

prune398.0ms

Pruning

5 alts after pruning (4 fresh and 1 done)

Merged error: 15.0b

localize20.0ms

Local error

Found 4 expressions with local error:

0.6b
(cbrt (fma (hypot re im) 2.0 (* re 2.0)))
0.6b
(cbrt (fma (hypot re im) 2.0 (* 2.0 re)))
0.5b
(fma (hypot re im) 2.0 (* re 2.0))
0.5b
(fma (hypot re im) 2.0 (* 2.0 re))

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

series361.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

127.0ms
(cbrt (fma (hypot re im) 2.0 (* re 2.0)))
127.0ms
(cbrt (fma (hypot re im) 2.0 (* 2.0 re)))
54.0ms
(fma (hypot re im) 2.0 (* re 2.0))
52.0ms
(fma (hypot re im) 2.0 (* 2.0 re))

simplify827.0ms

Counts
18 → 58
Calls

18 calls. Slowest were:

214.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)))))))))
157.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)))))))))
119.0ms
(exp (* 1/3 (- (+ (log (/ -1 re)) (log 1.0)) (* 2 (log (/ -1 im))))))

prune1.1s

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 15.0b

localize11.0ms

Local error

Found 4 expressions with local error:

3.5b
(expm1 (log1p (fma (hypot re im) 2.0 (* re 2.0))))
0.5b
(fma (hypot re im) 2.0 (* re 2.0))
0.2b
(log1p (fma (hypot re im) 2.0 (* re 2.0)))
0.2b
(sqrt (expm1 (log1p (fma (hypot re im) 2.0 (* re 2.0)))))

rewrite2.0ms

Algorithm
rewrite-expression-head
Counts
4 → 46
Calls

4 calls. Slowest were:

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

series518.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

205.0ms
(expm1 (log1p (fma (hypot re im) 2.0 (* re 2.0))))
204.0ms
(sqrt (expm1 (log1p (fma (hypot re im) 2.0 (* re 2.0)))))
66.0ms
(log1p (fma (hypot re im) 2.0 (* re 2.0)))
44.0ms
(fma (hypot re im) 2.0 (* re 2.0))

simplify1.1s

Counts
18 → 58
Calls

18 calls. Slowest were:

326.0ms
(- (+ (* 0.125 (* (sqrt (/ 1 (- (exp (- (log 4.0) (log (/ 1 re)))) 1))) (/ (exp (- (log 4.0) (log (/ 1 re)))) re))) (sqrt (- (exp (- (log 4.0) (log (/ 1 re)))) 1))) (* 0.0078125 (* (sqrt (/ 1 (pow (- (exp (- (log 4.0) (log (/ 1 re)))) 1) 3))) (/ (pow (exp (- (log 4.0) (log (/ 1 re)))) 2) (pow re 2)))))
295.0ms
(- (+ (* 0.25 (/ 1 re)) (log 4.0)) (+ (* 0.03125 (/ 1 (pow re 2))) (log (/ 1 re))))
161.0ms
(- (+ (* 0.25 (/ (exp (- (log 4.0) (log (/ 1 re)))) re)) (exp (- (log 4.0) (log (/ 1 re))))) 1)

prune890.0ms

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 14.9b

localize20.0ms

Local error

Found 4 expressions with local error:

3.1b
(exp (log (cbrt (fma (hypot re im) 2.0 (* 2.0 re)))))
0.6b
(cbrt (fma (hypot re im) 2.0 (* re 2.0)))
0.6b
(cbrt (fma (hypot re im) 2.0 (* 2.0 re)))
0.5b
(fma (hypot re im) 2.0 (* re 2.0))

rewrite5.0ms

Algorithm
rewrite-expression-head
Counts
4 → 57
Calls

4 calls. Slowest were:

3.0ms
(exp (log (cbrt (fma (hypot re im) 2.0 (* 2.0 re)))))
1.0ms
(cbrt (fma (hypot re im) 2.0 (* re 2.0)))
1.0ms
(cbrt (fma (hypot re im) 2.0 (* 2.0 re)))

series512.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

168.0ms
(exp (log (cbrt (fma (hypot re im) 2.0 (* 2.0 re)))))
159.0ms
(cbrt (fma (hypot re im) 2.0 (* re 2.0)))
133.0ms
(cbrt (fma (hypot re im) 2.0 (* 2.0 re)))
52.0ms
(fma (hypot re im) 2.0 (* re 2.0))

simplify1.4s

Counts
30 → 69
Calls

30 calls. Slowest were:

245.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)))))))))
216.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)))))))))
177.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)))))))))

prune1.4s

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 14.9b

regimes603.0ms

Accuracy

0% (0.0b remaining)

Error of 13.4b against oracle of 13.4b and baseline of 13.4b

bsearch1.0ms