Average Error: 37.7 → 22.3
Time: 14.0s
Precision: 64
Internal Precision: 128
\[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\]
\[\begin{array}{l} \mathbf{if}\;im \le -7.741829280776554 \cdot 10^{+91}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(-2.0\right) \cdot \left(re + im\right)}\\ \mathbf{elif}\;im \le -3.97963148609671 \cdot 10^{-159}:\\ \;\;\;\;0.5 \cdot \frac{\sqrt{\left(2.0 \cdot im\right) \cdot im}}{\sqrt{\sqrt{im \cdot im + re \cdot re} + re}}\\ \mathbf{elif}\;im \le 3.0351998430093895 \cdot 10^{-166}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(-2 \cdot re\right) \cdot 2.0}\\ \mathbf{elif}\;im \le 7.913867737127792 \cdot 10^{+157}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(\sqrt{im \cdot im + re \cdot re} - re\right) \cdot 2.0}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2.0 \cdot \left(im - re\right)} \cdot 0.5\\ \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 5 regimes
  2. if im < -7.741829280776554e+91

    1. Initial program 48.4

      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\]
    2. Using strategy rm
    3. Applied +-commutative48.4

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right)}\]
    4. Taylor expanded around -inf 9.6

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \color{blue}{\left(-\left(re + im\right)\right)}}\]

    if -7.741829280776554e+91 < im < -3.97963148609671e-159

    1. Initial program 25.4

      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\]
    2. Using strategy rm
    3. Applied flip--34.9

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \color{blue}{\frac{\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im} - re \cdot re}{\sqrt{re \cdot re + im \cdot im} + re}}}\]
    4. Applied associate-*r/34.9

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im} - re \cdot re\right)}{\sqrt{re \cdot re + im \cdot im} + re}}}\]
    5. Applied sqrt-div35.0

      \[\leadsto 0.5 \cdot \color{blue}{\frac{\sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im} - re \cdot re\right)}}{\sqrt{\sqrt{re \cdot re + im \cdot im} + re}}}\]
    6. Simplified25.8

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{im \cdot \left(im \cdot 2.0\right)}}}{\sqrt{\sqrt{re \cdot re + im \cdot im} + re}}\]

    if -3.97963148609671e-159 < im < 3.0351998430093895e-166

    1. Initial program 42.5

      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt43.6

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\color{blue}{\sqrt{\sqrt{re \cdot re + im \cdot im}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}}} - re\right)}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt43.6

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\color{blue}{\left(\sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im}}} \cdot \sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im}}}\right)} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}} - re\right)}\]
    6. Applied associate-*l*43.6

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\color{blue}{\sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im}}} \cdot \left(\sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im}}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}}\right)} - re\right)}\]
    7. Taylor expanded around -inf 34.1

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \color{blue}{\left(-2 \cdot re\right)}}\]

    if 3.0351998430093895e-166 < im < 7.913867737127792e+157

    1. Initial program 24.3

      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\]
    2. Using strategy rm
    3. Applied +-commutative24.3

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right)}\]

    if 7.913867737127792e+157 < im

    1. Initial program 61.3

      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\]
    2. Using strategy rm
    3. Applied +-commutative61.3

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right)}\]
    4. Taylor expanded around inf 7.1

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\color{blue}{im} - re\right)}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification22.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \le -7.741829280776554 \cdot 10^{+91}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(-2.0\right) \cdot \left(re + im\right)}\\ \mathbf{elif}\;im \le -3.97963148609671 \cdot 10^{-159}:\\ \;\;\;\;0.5 \cdot \frac{\sqrt{\left(2.0 \cdot im\right) \cdot im}}{\sqrt{\sqrt{im \cdot im + re \cdot re} + re}}\\ \mathbf{elif}\;im \le 3.0351998430093895 \cdot 10^{-166}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(-2 \cdot re\right) \cdot 2.0}\\ \mathbf{elif}\;im \le 7.913867737127792 \cdot 10^{+157}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(\sqrt{im \cdot im + re \cdot re} - re\right) \cdot 2.0}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2.0 \cdot \left(im - re\right)} \cdot 0.5\\ \end{array}\]

Reproduce

herbie shell --seed 2019010 
(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: 12.8s)Debug log

sample209.0ms

Algorithm
intervals

simplify45.0ms

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

prune14.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 36.3b

localize43.0ms

Local error

Found 4 expressions with local error:

29.5b
(sqrt (+ (* re re) (* im im)))
0.5b
(- (sqrt (+ (* re re) (* im im))) re)
0.0b
(sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))
0.0b
(+ (* re re) (* im im))

rewrite20.0ms

Algorithm
rewrite-expression-head
Rules
add-log-exp
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
add-exp-log
sqrt-div
add-cbrt-cube
pow1
flip--
flip-+
associate-*r/
pow1/2
flip3--
flip3-+
sub-neg
sum-log
rem-sqrt-square
+-commutative
Counts
4 → 47
Calls
4 calls:
Slowest
11.0ms
(- (sqrt (+ (* re re) (* im im))) re)
3.0ms
(sqrt (+ (* re re) (* im im)))
2.0ms
(+ (* re re) (* im im))
2.0ms
(sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))

series229.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
129.0ms
(sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))
48.0ms
(- (sqrt (+ (* re re) (* im im))) re)
27.0ms
(sqrt (+ (* re re) (* im im)))
25.0ms
(+ (* re re) (* im im))

simplify854.0ms

Counts
22 → 59
Calls
22 calls:
Slowest
355.0ms
(sqrt (* 2.0 (- (* (sqrt (+ (* re re) (* im im))) (sqrt (+ (* re re) (* im im)))) (* re re))))
207.0ms
(sqrt (* 2.0 (- (pow (sqrt (+ (* re re) (* im im))) 3) (pow re 3))))
181.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
62.0ms
(sqrt (+ (pow (* re re) 3) (pow (* im im) 3)))
11.0ms
(* (exp (* re re)) (exp (* im im)))

prune614.0ms

Pruning

6 alts after pruning (6 fresh and 0 done)

Merged error: 15.1b

localize20.0ms

Local error

Found 4 expressions with local error:

29.5b
(sqrt (+ (* im im) (* re re)))
0.5b
(- (sqrt (+ (* im im) (* re re))) re)
0.0b
(sqrt (* 2.0 (- (sqrt (+ (* im im) (* re re))) re)))
0.0b
(+ (* im im) (* re re))

rewrite30.0ms

Algorithm
rewrite-expression-head
Rules
add-log-exp
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
add-exp-log
sqrt-div
add-cbrt-cube
pow1
flip--
flip-+
associate-*r/
pow1/2
flip3--
flip3-+
sub-neg
sum-log
rem-sqrt-square
+-commutative
Counts
4 → 47
Calls
4 calls:
Slowest
21.0ms
(- (sqrt (+ (* im im) (* re re))) re)
4.0ms
(sqrt (+ (* im im) (* re re)))
2.0ms
(sqrt (* 2.0 (- (sqrt (+ (* im im) (* re re))) re)))
2.0ms
(+ (* im im) (* re re))

series185.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
117.0ms
(sqrt (* 2.0 (- (sqrt (+ (* im im) (* re re))) re)))
32.0ms
(- (sqrt (+ (* im im) (* re re))) re)
22.0ms
(sqrt (+ (* im im) (* re re)))
14.0ms
(+ (* im im) (* re re))

simplify675.0ms

Counts
22 → 59
Calls
22 calls:
Slowest
300.0ms
(sqrt (* 2.0 (- (* (sqrt (+ (* im im) (* re re))) (sqrt (+ (* im im) (* re re)))) (* re re))))
188.0ms
(sqrt (* 2.0 (- (pow (sqrt (+ (* im im) (* re re))) 3) (pow re 3))))
111.0ms
(sqrt (- (* (* im im) (* im im)) (* (* re re) (* re re))))
38.0ms
(sqrt (+ (pow (* im im) 3) (pow (* re re) 3)))
5.0ms
(sqrt (* (cbrt (+ (* im im) (* re re))) (cbrt (+ (* im im) (* re re)))))

prune609.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 7.4b

localize18.0ms

Local error

Found 4 expressions with local error:

29.5b
(sqrt (+ (* re re) (* im im)))
29.5b
(sqrt (+ (* re re) (* im im)))
8.0b
(- (* (sqrt (sqrt (+ (* re re) (* im im)))) (sqrt (sqrt (+ (* re re) (* im im))))) re)
0.5b
(* (sqrt (sqrt (+ (* re re) (* im im)))) (sqrt (sqrt (+ (* re re) (* im im)))))

rewrite36.0ms

Algorithm
rewrite-expression-head
Rules
28×sqrt-div
24×sqrt-prod
14×add-sqr-sqrt
12×add-cube-cbrt
12×*-un-lft-identity
associate-*l*
associate-*r*
pow1
flip-+
flip3-+
add-exp-log
pow1/2
add-cbrt-cube
add-log-exp
frac-times
pow-prod-up
associate-*r/
associate-*l/
pow-prod-down
rem-sqrt-square
flip--
cbrt-unprod
*-commutative
prod-exp
sqrt-unprod
flip3--
pow-plus
rem-square-sqrt
sub-neg
pow2
Counts
4 → 83
Calls
4 calls:
Slowest
17.0ms
(- (* (sqrt (sqrt (+ (* re re) (* im im)))) (sqrt (sqrt (+ (* re re) (* im im))))) re)
10.0ms
(* (sqrt (sqrt (+ (* re re) (* im im)))) (sqrt (sqrt (+ (* re re) (* im im)))))
4.0ms
(sqrt (+ (* re re) (* im im)))
4.0ms
(sqrt (+ (* re re) (* im im)))

series119.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
37.0ms
(- (* (sqrt (sqrt (+ (* re re) (* im im)))) (sqrt (sqrt (+ (* re re) (* im im))))) re)
36.0ms
(sqrt (+ (* re re) (* im im)))
25.0ms
(* (sqrt (sqrt (+ (* re re) (* im im)))) (sqrt (sqrt (+ (* re re) (* im im)))))
20.0ms
(sqrt (+ (* re re) (* im im)))

simplify2.1s

Counts
64 → 95
Calls
64 calls:
Slowest
216.0ms
(sqrt (sqrt (+ (* (* re re) (* re re)) (- (* (* im im) (* im im)) (* (* re re) (* im im))))))
192.0ms
(* (sqrt (sqrt (+ (* (* re re) (* re re)) (- (* (* im im) (* im im)) (* (* re re) (* im im)))))) (sqrt (sqrt (- (* re re) (* im im)))))
172.0ms
(* (sqrt (sqrt (+ (* (* re re) (* re re)) (- (* (* im im) (* im im)) (* (* re re) (* im im)))))) (sqrt (sqrt (+ (* (* re re) (* re re)) (- (* (* im im) (* im im)) (* (* re re) (* im im)))))))
169.0ms
(* (sqrt (sqrt (- (* re re) (* im im)))) (sqrt (sqrt (+ (* (* re re) (* re re)) (- (* (* im im) (* im im)) (* (* re re) (* im im)))))))
162.0ms
(* (sqrt (sqrt (+ (pow (* re re) 3) (pow (* im im) 3)))) (sqrt (sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))))

prune1.3s

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 7.4b

localize29.0ms

Local error

Found 4 expressions with local error:

29.5b
(sqrt (+ (* re re) (* im im)))
29.5b
(sqrt (+ (* re re) (* im im)))
29.5b
(sqrt (+ (* re re) (* im im)))
8.7b
(- (* (sqrt (sqrt (sqrt (+ (* re re) (* im im))))) (* (sqrt (sqrt (sqrt (+ (* re re) (* im im))))) (sqrt (sqrt (+ (* re re) (* im im)))))) re)

rewrite44.0ms

Algorithm
rewrite-expression-head
Rules
10×add-sqr-sqrt
sqrt-prod
add-cube-cbrt
*-un-lft-identity
sqrt-div
add-log-exp
add-exp-log
add-cbrt-cube
pow1
flip-+
pow1/2
flip3-+
rem-sqrt-square
flip--
flip3--
sub-neg
Counts
4 → 53
Calls
4 calls:
Slowest
38.0ms
(- (* (sqrt (sqrt (sqrt (+ (* re re) (* im im))))) (* (sqrt (sqrt (sqrt (+ (* re re) (* im im))))) (sqrt (sqrt (+ (* re re) (* im im)))))) re)
2.0ms
(sqrt (+ (* re re) (* im im)))
2.0ms
(sqrt (+ (* re re) (* im im)))
2.0ms
(sqrt (+ (* re re) (* im im)))

series118.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
42.0ms
(- (* (sqrt (sqrt (sqrt (+ (* re re) (* im im))))) (* (sqrt (sqrt (sqrt (+ (* re re) (* im im))))) (sqrt (sqrt (+ (* re re) (* im im)))))) re)
30.0ms
(sqrt (+ (* re re) (* im im)))
26.0ms
(sqrt (+ (* re re) (* im im)))
19.0ms
(sqrt (+ (* re re) (* im im)))

simplify575.0ms

Counts
30 → 65
Calls
30 calls:
Slowest
137.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
120.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
114.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
65.0ms
(sqrt (+ (pow (* re re) 3) (pow (* im im) 3)))
47.0ms
(sqrt (+ (pow (* re re) 3) (pow (* im im) 3)))

prune1.1s

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 7.4b

regimes492.0ms

Accuracy

55.2% (12.5b remaining)

Error of 22.3b against oracle of 9.7b and baseline of 37.7b

bsearch351.0ms

end0.0ms

sample3.0s

Algorithm
intervals