Average Error: 37.5 → 25.7
Time: 18.7s
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}\;re \le -1.8650551235017197 \cdot 10^{+148}:\\ \;\;\;\;\sqrt{\left(-2 \cdot re\right) \cdot 2.0} \cdot 0.5\\ \mathbf{elif}\;re \le 7.121039085562552 \cdot 10^{-248}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{im \cdot im + re \cdot re} - re\right)}\\ \mathbf{elif}\;re \le 2.2531080696251418 \cdot 10^{-125}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(im - re\right) \cdot 2.0}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{\sqrt{\left(im \cdot 2.0\right) \cdot im}}{\sqrt{\sqrt{im \cdot im + re \cdot re} + re}}\\ \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 4 regimes
  2. if re < -1.8650551235017197e+148

    1. Initial program 59.3

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

      \[\leadsto 0.5 \cdot \sqrt{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2.0}\]
    3. Taylor expanded around -inf 6.9

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

    if -1.8650551235017197e+148 < re < 7.121039085562552e-248

    1. Initial program 20.5

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

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

    if 7.121039085562552e-248 < re < 2.2531080696251418e-125

    1. Initial program 30.8

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

      \[\leadsto 0.5 \cdot \sqrt{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2.0}\]
    3. Taylor expanded around 0 38.1

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

    if 2.2531080696251418e-125 < re

    1. Initial program 50.8

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

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

      \[\leadsto 0.5 \cdot \sqrt{\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}} \cdot 2.0}\]
    5. Applied associate-*l/50.8

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

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

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{\left(im \cdot 2.0\right) \cdot im}}}{\sqrt{\sqrt{re \cdot re + im \cdot im} + re}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification25.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -1.8650551235017197 \cdot 10^{+148}:\\ \;\;\;\;\sqrt{\left(-2 \cdot re\right) \cdot 2.0} \cdot 0.5\\ \mathbf{elif}\;re \le 7.121039085562552 \cdot 10^{-248}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{im \cdot im + re \cdot re} - re\right)}\\ \mathbf{elif}\;re \le 2.2531080696251418 \cdot 10^{-125}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(im - re\right) \cdot 2.0}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{\sqrt{\left(im \cdot 2.0\right) \cdot im}}{\sqrt{\sqrt{im \cdot im + re \cdot re} + re}}\\ \end{array}\]

Reproduce

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

start356.0ms

Algorithm
intervals

setup93.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 35.8b

localize23.0ms

Local error

Found 4 expressions with local error:

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

rewrite572.0ms

Algorithm
rewrite-expression-head
Counts
4 → 47
Calls

4 calls. Slowest were:

549.0ms
(sqrt (* (- (sqrt (+ (* re re) (* im im))) re) 2.0))
10.0ms
(- (sqrt (+ (* re re) (* im im))) re)
5.0ms
(+ (* re re) (* im im))

series186.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

105.0ms
(sqrt (* (- (sqrt (+ (* re re) (* im im))) re) 2.0))
38.0ms
(sqrt (+ (* re re) (* im im)))
28.0ms
(- (sqrt (+ (* re re) (* im im))) re)
15.0ms
(+ (* re re) (* im im))

simplify746.0ms

Counts
22 → 59
Calls

22 calls. Slowest were:

283.0ms
(sqrt (* (- (* (sqrt (+ (* re re) (* im im))) (sqrt (+ (* re re) (* im im)))) (* re re)) 2.0))
235.0ms
(sqrt (* (- (pow (sqrt (+ (* re re) (* im im))) 3) (pow re 3)) 2.0))
148.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))

prune777.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 15.3b

localize26.0ms

Local error

Found 4 expressions with local error:

28.3b
(sqrt (+ (* re re) (* im im)))
28.3b
(sqrt (+ (* re re) (* im im)))
28.3b
(sqrt (+ (* re re) (* im im)))
0.5b
(- (sqrt (+ (* re re) (* im im))) re)

rewrite29.0ms

Algorithm
rewrite-expression-head
Counts
4 → 53
Calls

4 calls. Slowest were:

15.0ms
(- (sqrt (+ (* re re) (* im im))) re)
7.0ms
(sqrt (+ (* re re) (* im im)))
3.0ms
(sqrt (+ (* re re) (* im im)))

series100.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

29.0ms
(sqrt (+ (* re re) (* im im)))
27.0ms
(- (sqrt (+ (* re re) (* im im))) re)
25.0ms
(sqrt (+ (* re re) (* im im)))
20.0ms
(sqrt (+ (* re re) (* im im)))

simplify613.0ms

Counts
30 → 65
Calls

30 calls. Slowest were:

155.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
138.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
111.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))

prune1.1s

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 15.3b

localize21.0ms

Local error

Found 4 expressions with local error:

29.3b
(cbrt (+ (* re re) (* im im)))
29.3b
(cbrt (+ (* re re) (* im im)))
29.3b
(cbrt (+ (* re re) (* im im)))
28.3b
(sqrt (* (* (cbrt (+ (* re re) (* im im))) (cbrt (+ (* re re) (* im im)))) (cbrt (+ (* re re) (* im im)))))

rewrite15.0ms

Algorithm
rewrite-expression-head
Counts
4 → 74
Calls

4 calls. Slowest were:

9.0ms
(sqrt (* (* (cbrt (+ (* re re) (* im im))) (cbrt (+ (* re re) (* im im)))) (cbrt (+ (* re re) (* im im)))))
1.0ms
(cbrt (+ (* re re) (* im im)))
1.0ms
(cbrt (+ (* re re) (* im im)))

series372.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

128.0ms
(cbrt (+ (* re re) (* im im)))
117.0ms
(cbrt (+ (* re re) (* im im)))
93.0ms
(cbrt (+ (* re re) (* im im)))
33.0ms
(sqrt (* (* (cbrt (+ (* re re) (* im im))) (cbrt (+ (* re re) (* im im)))) (cbrt (+ (* re re) (* im im)))))

simplify3.9s

Counts
54 → 86
Calls

54 calls. Slowest were:

202.0ms
(sqrt (* (* (cbrt (+ (pow (* re re) 3) (pow (* im im) 3))) (cbrt (+ (* re re) (* im im)))) (cbrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))))
184.0ms
(sqrt (* (* (cbrt (+ (* re re) (* im im))) (cbrt (+ (pow (* re re) 3) (pow (* im im) 3)))) (cbrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))))
183.0ms
(sqrt (* (* (cbrt (+ (* re re) (* im im))) (cbrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))) (cbrt (+ (pow (* re re) 3) (pow (* im im) 3)))))

prune1.8s

Pruning

8 alts after pruning (5 fresh and 3 done)

Merged error: 15.3b

localize25.0ms

Local error

Found 4 expressions with local error:

29.3b
(cbrt (+ (* re re) (* im im)))
29.3b
(cbrt (+ (* re re) (* im im)))
28.3b
(sqrt (+ (* re re) (* im im)))
28.3b
(sqrt (+ (* re re) (* im im)))

rewrite9.0ms

Algorithm
rewrite-expression-head
Counts
4 → 54
Calls

4 calls. Slowest were:

3.0ms
(sqrt (+ (* re re) (* im im)))
2.0ms
(sqrt (+ (* re re) (* im im)))
1.0ms
(cbrt (+ (* re re) (* im im)))

series230.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

98.0ms
(cbrt (+ (* re re) (* im im)))
87.0ms
(cbrt (+ (* re re) (* im im)))
25.0ms
(sqrt (+ (* re re) (* im im)))
19.0ms
(sqrt (+ (* re re) (* im im)))

simplify1.1s

Counts
34 → 66
Calls

34 calls. Slowest were:

203.0ms
(cbrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
185.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
185.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))

prune1.3s

Pruning

8 alts after pruning (4 fresh and 4 done)

Merged error: 15.3b

regimes531.0ms

Accuracy

56.3% (9.1b remaining)

Error of 25.7b against oracle of 16.6b and baseline of 37.5b

bsearch219.0ms