Average Error: 37.7 → 26.0
Time: 15.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 -6.721031304254009 \cdot 10^{+107}:\\ \;\;\;\;\sqrt{\left(-2 \cdot re\right) \cdot 2.0} \cdot 0.5\\ \mathbf{elif}\;re \le 1.8532836327811608 \cdot 10^{-138}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\left(\sqrt{\sqrt{im \cdot im + re \cdot re}} \cdot \sqrt{\sqrt{\sqrt[3]{im \cdot im + re \cdot re}}}\right) \cdot \sqrt{\left|\sqrt[3]{im \cdot im + re \cdot re}\right|} - re\right)}\\ \mathbf{elif}\;re \le 4.953966198300088 \cdot 10^{-106} \lor \neg \left(re \le 3.782709412152994 \cdot 10^{+157}\right) \land re \le 2.0952900608929343 \cdot 10^{+194}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{\sqrt{\left(2.0 \cdot im\right) \cdot im}}{\sqrt{re + \sqrt{im \cdot im + re \cdot 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 < -6.721031304254009e+107

    1. Initial program 51.1

      \[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-sqrt51.1

      \[\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. Taylor expanded around -inf 10.1

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

    if -6.721031304254009e+107 < re < 1.8532836327811608e-138

    1. Initial program 22.9

      \[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-sqrt23.0

      \[\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-cube-cbrt23.1

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{\sqrt{\color{blue}{\left(\sqrt[3]{re \cdot re + im \cdot im} \cdot \sqrt[3]{re \cdot re + im \cdot im}\right) \cdot \sqrt[3]{re \cdot re + im \cdot im}}}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}} - re\right)}\]
    6. Applied sqrt-prod23.1

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{\color{blue}{\sqrt{\sqrt[3]{re \cdot re + im \cdot im} \cdot \sqrt[3]{re \cdot re + im \cdot im}} \cdot \sqrt{\sqrt[3]{re \cdot re + im \cdot im}}}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}} - re\right)}\]
    7. Applied sqrt-prod23.1

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

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

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

    if 1.8532836327811608e-138 < re < 4.953966198300088e-106 or 3.782709412152994e+157 < re < 2.0952900608929343e+194

    1. Initial program 50.4

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

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

    if 4.953966198300088e-106 < re < 3.782709412152994e+157 or 2.0952900608929343e+194 < re

    1. Initial program 51.2

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

      \[\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/51.3

      \[\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-div51.3

      \[\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. Simplified34.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}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification26.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -6.721031304254009 \cdot 10^{+107}:\\ \;\;\;\;\sqrt{\left(-2 \cdot re\right) \cdot 2.0} \cdot 0.5\\ \mathbf{elif}\;re \le 1.8532836327811608 \cdot 10^{-138}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\left(\sqrt{\sqrt{im \cdot im + re \cdot re}} \cdot \sqrt{\sqrt{\sqrt[3]{im \cdot im + re \cdot re}}}\right) \cdot \sqrt{\left|\sqrt[3]{im \cdot im + re \cdot re}\right|} - re\right)}\\ \mathbf{elif}\;re \le 4.953966198300088 \cdot 10^{-106} \lor \neg \left(re \le 3.782709412152994 \cdot 10^{+157}\right) \land re \le 2.0952900608929343 \cdot 10^{+194}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{\sqrt{\left(2.0 \cdot im\right) \cdot im}}{\sqrt{re + \sqrt{im \cdot im + re \cdot re}}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019007 
(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.3s)Debug log

sample201.0ms

Algorithm
intervals

simplify46.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

46.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: 37.1b

localize69.0ms

Local error

Found 4 expressions with local error:

31.1b
(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))

rewrite38.0ms

Algorithm
rewrite-expression-head
Counts
4 → 47
Calls

4 calls. Slowest were:

21.0ms
(- (sqrt (+ (* re re) (* im im))) re)
7.0ms
(sqrt (+ (* re re) (* im im)))
4.0ms
(+ (* re re) (* im im))

series340.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

158.0ms
(sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))
90.0ms
(sqrt (+ (* re re) (* im im)))
66.0ms
(- (sqrt (+ (* re re) (* im im))) re)
25.0ms
(+ (* re re) (* im im))

simplify748.0ms

Counts
22 → 59
Calls

22 calls. Slowest were:

297.0ms
(sqrt (* 2.0 (- (* (sqrt (+ (* re re) (* im im))) (sqrt (+ (* re re) (* im im)))) (* re re))))
211.0ms
(sqrt (* 2.0 (- (pow (sqrt (+ (* re re) (* im im))) 3) (pow re 3))))
129.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))

prune678.0ms

Pruning

6 alts after pruning (6 fresh and 0 done)

Merged error: 16.6b

localize23.0ms

Local error

Found 4 expressions with local error:

31.1b
(sqrt (+ (* re re) (* im im)))
31.1b
(sqrt (+ (* re re) (* im im)))
7.8b
(- (* (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)))))

rewrite46.0ms

Algorithm
rewrite-expression-head
Counts
4 → 83
Calls

4 calls. Slowest were:

20.0ms
(- (* (sqrt (sqrt (+ (* re re) (* im im)))) (sqrt (sqrt (+ (* re re) (* im im))))) re)
17.0ms
(* (sqrt (sqrt (+ (* re re) (* im im)))) (sqrt (sqrt (+ (* re re) (* im im)))))
3.0ms
(sqrt (+ (* re re) (* im im)))

series140.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

43.0ms
(- (* (sqrt (sqrt (+ (* re re) (* im im)))) (sqrt (sqrt (+ (* re re) (* im im))))) re)
34.0ms
(sqrt (+ (* re re) (* im im)))
33.0ms
(* (sqrt (sqrt (+ (* re re) (* im im)))) (sqrt (sqrt (+ (* re re) (* im im)))))
30.0ms
(sqrt (+ (* re re) (* im im)))

simplify2.1s

Counts
64 → 95
Calls

64 calls. Slowest were:

217.0ms
(* (sqrt (sqrt (- (* re re) (* im im)))) (sqrt (sqrt (+ (* (* re re) (* re re)) (- (* (* im im) (* im im)) (* (* re re) (* im im)))))))
173.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
166.0ms
(* (sqrt (sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))) (sqrt (sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))))

prune1.3s

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 16.6b

localize62.0ms

Local error

Found 4 expressions with local error:

32.1b
(cbrt (+ (* re re) (* im im)))
32.1b
(cbrt (+ (* re re) (* im im)))
31.1b
(sqrt (+ (* re re) (* im im)))
8.0b
(- (* (sqrt (fabs (cbrt (+ (* re re) (* im im))))) (* (sqrt (sqrt (cbrt (+ (* re re) (* im im))))) (sqrt (sqrt (+ (* re re) (* im im)))))) re)

rewrite47.0ms

Algorithm
rewrite-expression-head
Counts
4 → 51
Calls

4 calls. Slowest were:

36.0ms
(- (* (sqrt (fabs (cbrt (+ (* re re) (* im im))))) (* (sqrt (sqrt (cbrt (+ (* re re) (* im im))))) (sqrt (sqrt (+ (* re re) (* im im)))))) re)
4.0ms
(sqrt (+ (* re re) (* im im)))
3.0ms
(cbrt (+ (* re re) (* im im)))

series409.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

130.0ms
(cbrt (+ (* re re) (* im im)))
128.0ms
(- (* (sqrt (fabs (cbrt (+ (* re re) (* im im))))) (* (sqrt (sqrt (cbrt (+ (* re re) (* im im))))) (sqrt (sqrt (+ (* re re) (* im im)))))) re)
119.0ms
(cbrt (+ (* re re) (* im im)))
32.0ms
(sqrt (+ (* re re) (* im im)))

simplify957.0ms

Counts
28 → 63
Calls

28 calls. Slowest were:

244.0ms
(- (+ (* 1/3 (* (pow re 2) (* (sqrt (fabs (pow (+ (pow im 2) (pow re 2)) 1/3))) (pow (/ 1 (pow im 4)) 1/3)))) (* (sqrt (fabs (pow (+ (pow im 2) (pow re 2)) 1/3))) (pow (pow im 2) 1/3))) re)
146.0ms
(cbrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
143.0ms
(cbrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))

prune1.2s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 16.6b

localize29.0ms

Local error

Found 4 expressions with local error:

31.1b
(sqrt (+ (* re re) (* im im)))
31.1b
(sqrt (+ (* re re) (* im im)))
31.1b
(sqrt (+ (* re re) (* im im)))
31.1b
(sqrt (+ (* re re) (* im im)))

rewrite9.0ms

Algorithm
rewrite-expression-head
Counts
4 → 56
Calls

4 calls. Slowest were:

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

series91.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

28.0ms
(sqrt (+ (* re re) (* im im)))
23.0ms
(sqrt (+ (* re re) (* im im)))
20.0ms
(sqrt (+ (* re re) (* im im)))
19.0ms
(sqrt (+ (* re re) (* im im)))

simplify850.0ms

Counts
36 → 68
Calls

36 calls. Slowest were:

167.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
148.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
125.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))

prune1.2s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 16.6b

regimes447.0ms

Accuracy

58.9% (8.4b remaining)

Error of 26.0b against oracle of 17.5b and baseline of 38.1b

bsearch549.0ms

end0.0ms

sample2.6s

Algorithm
intervals