Average Error: 37.4 → 13.1
Time: 10.0s
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}^* - re\right) \cdot 2.0} \cdot 0.5\]

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. Initial program 37.4

    \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\]
  2. Simplified13.1

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

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

Reproduce

herbie shell --seed 2019016 +o rules:numerics
(FPCore (re im)
  :name "math.sqrt on complex, imaginary part, im greater than 0 branch"
  (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))

Details

Time bar (total: 8.3s)Debug log

sample247.0ms

Algorithm
intervals
Results
256×(pre true 80)
208×(body real 80)
22×(body real 2560)
11×(body real 1280)
(body real 320)
(body real 640)
(body real 5120)
(body real 160)

simplify60.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
59.0ms
(* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re))))

prune418.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 10.5b

localize29.0ms

Local error

Found 2 expressions with local error:

0.5b
(- (hypot re im) re)
0.0b
(hypot re im)

rewrite10.0ms

Algorithm
rewrite-expression-head
Rules
add-cube-cbrt
fma-neg
*-un-lft-identity
add-sqr-sqrt
add-log-exp
log1p-expm1-u
add-exp-log
add-cbrt-cube
pow1
expm1-log1p-u
flip--
flip3--
sub-neg
hypot-udef
Counts
2 → 26
Calls
2 calls:
Slowest
8.0ms
(- (hypot re im) re)
0.0ms
(hypot re im)

series108.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
59.0ms
(- (hypot re im) re)
48.0ms
(hypot re im)

simplify15.0ms

Counts
8 → 32
Calls
8 calls:
Slowest
3.0ms
(- im re)
2.0ms
(* -1 re)
2.0ms
(* -2 re)
2.0ms
(* (cbrt (hypot re im)) (cbrt (hypot re im)))
1.0ms
(sqrt (hypot re im))

prune317.0ms

Pruning

5 alts after pruning (4 fresh and 1 done)

Merged error: 10.4b

localize27.0ms

Local error

Found 3 expressions with local error:

11.7b
(fma (sqrt (hypot re im)) (sqrt (hypot re im)) (- re))
0.0b
(hypot re im)
0.0b
(hypot re im)

rewrite1.0ms

Algorithm
rewrite-expression-head
Rules
add-log-exp
log1p-expm1-u
add-cube-cbrt
add-exp-log
add-cbrt-cube
*-un-lft-identity
pow1
expm1-log1p-u
add-sqr-sqrt
hypot-udef
fma-udef
Counts
3 → 30
Calls
3 calls:
Slowest
0.0ms
(fma (sqrt (hypot re im)) (sqrt (hypot re im)) (- re))
0.0ms
(hypot re im)
0.0ms
(hypot re im)

series162.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
98.0ms
(fma (sqrt (hypot re im)) (sqrt (hypot re im)) (- re))
38.0ms
(hypot re im)
26.0ms
(hypot re im)

simplify8.0ms

Counts
9 → 39
Calls
9 calls:
Slowest
2.0ms
(- im re)
1.0ms
(* -1 re)
1.0ms
(* -1 re)
1.0ms
im
0.0ms
im

prune524.0ms

Pruning

10 alts after pruning (8 fresh and 2 done)

Merged error: 10.4b

localize37.0ms

Local error

Found 4 expressions with local error:

11.7b
(fma (sqrt (* (* (cbrt (hypot re im)) (cbrt (hypot re im))) (cbrt (hypot re im)))) (sqrt (hypot re im)) (- re))
0.6b
(cbrt (hypot re im))
0.6b
(cbrt (hypot re im))
0.6b
(cbrt (hypot re im))

rewrite4.0ms

Algorithm
rewrite-expression-head
Rules
cbrt-prod
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-log-exp
log1p-expm1-u
add-exp-log
add-cbrt-cube
pow1
expm1-log1p-u
pow1/3
fma-udef
Counts
4 → 49
Calls
4 calls:
Slowest
1.0ms
(cbrt (hypot re im))
1.0ms
(cbrt (hypot re im))
1.0ms
(cbrt (hypot re im))
0.0ms
(fma (sqrt (* (* (cbrt (hypot re im)) (cbrt (hypot re im))) (cbrt (hypot re im)))) (sqrt (hypot re im)) (- re))

series469.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
121.0ms
(cbrt (hypot re im))
121.0ms
(fma (sqrt (* (* (cbrt (hypot re im)) (cbrt (hypot re im))) (cbrt (hypot re im)))) (sqrt (hypot re im)) (- re))
116.0ms
(cbrt (hypot re im))
111.0ms
(cbrt (hypot re im))

simplify164.0ms

Counts
21 → 61
Calls
21 calls:
Slowest
51.0ms
(+ (* 1/6 (* (pow re 2) (pow (/ 1 (pow im 5)) 1/3))) (pow im 1/3))
48.0ms
(+ (* 1/6 (* (pow re 2) (pow (/ 1 (pow im 5)) 1/3))) (pow im 1/3))
28.0ms
(+ (* 1/6 (* (pow re 2) (pow (/ 1 (pow im 5)) 1/3))) (pow im 1/3))
4.0ms
(pow (/ 1 re) -1/3)
4.0ms
(pow (/ 1 re) -1/3)

prune1.1s

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 10.4b

localize31.0ms

Local error

Found 4 expressions with local error:

8.0b
(+ (* (sqrt (* (* (cbrt (hypot re im)) (cbrt (hypot re im))) (cbrt (hypot re im)))) (sqrt (hypot re im))) (- re))
0.6b
(cbrt (hypot re im))
0.6b
(cbrt (hypot re im))
0.6b
(cbrt (hypot re im))

rewrite30.0ms

Algorithm
rewrite-expression-head
Rules
cbrt-prod
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-log-exp
log1p-expm1-u
add-exp-log
add-cbrt-cube
pow1
expm1-log1p-u
pow1/3
flip-+
unsub-neg
flip3-+
fma-def
sum-log
associate-+r-
+-commutative
neg-sub0
Counts
4 → 56
Calls
4 calls:
Slowest
26.0ms
(+ (* (sqrt (* (* (cbrt (hypot re im)) (cbrt (hypot re im))) (cbrt (hypot re im)))) (sqrt (hypot re im))) (- re))
1.0ms
(cbrt (hypot re im))
1.0ms
(cbrt (hypot re im))
1.0ms
(cbrt (hypot re im))

series314.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
99.0ms
(cbrt (hypot re im))
98.0ms
(cbrt (hypot re im))
86.0ms
(cbrt (hypot re im))
30.0ms
(+ (* (sqrt (* (* (cbrt (hypot re im)) (cbrt (hypot re im))) (cbrt (hypot re im)))) (sqrt (hypot re im))) (- re))

simplify233.0ms

Counts
23 → 68
Calls
23 calls:
Slowest
62.0ms
(* (exp (* (sqrt (* (* (cbrt (hypot re im)) (cbrt (hypot re im))) (cbrt (hypot re im)))) (sqrt (hypot re im)))) (exp (- re)))
52.0ms
(+ (* 1/6 (* (pow re 2) (pow (/ 1 (pow im 5)) 1/3))) (pow im 1/3))
49.0ms
(+ (* 1/6 (* (pow re 2) (pow (/ 1 (pow im 5)) 1/3))) (pow im 1/3))
25.0ms
(+ (* 1/6 (* (pow re 2) (pow (/ 1 (pow im 5)) 1/3))) (pow im 1/3))
4.0ms
(sqrt (* (* (cbrt (hypot re im)) (cbrt (hypot re im))) (cbrt (hypot re im))))

prune997.0ms

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 10.4b

regimes226.0ms

Accuracy

0% (0.2b remaining)

Error of 13.1b against oracle of 12.9b and baseline of 13.1b

bsearch1.0ms

end0.0ms

sample2.8s

Algorithm
intervals
Results
8000×(pre true 80)
6040×(body real 80)
680×(body real 2560)
480×(body real 1280)
281×(body real 640)
281×(body real 5120)
158×(body real 320)
80×(body real 160)