Average Error: 37.7 → 25.8
Time: 14.6s
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.6813385983305504 \cdot 10^{+75}:\\ \;\;\;\;\sqrt{\left(-2 \cdot re\right) \cdot 2.0} \cdot 0.5\\ \mathbf{elif}\;re \le 8.896182596446849 \cdot 10^{-305}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{im \cdot im + re \cdot re} - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{\sqrt{im \cdot \left(2.0 \cdot im\right)}}{\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 3 regimes
  2. if re < -1.6813385983305504e+75

    1. Initial program 44.6

      \[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-sqrt44.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-exp-log45.4

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{\color{blue}{e^{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}} - re\right)}\]
    6. Using strategy rm
    7. Applied pow1/245.4

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{e^{\log \color{blue}{\left({\left(re \cdot re + im \cdot im\right)}^{\frac{1}{2}}\right)}}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}} - re\right)}\]
    8. Applied log-pow45.4

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{e^{\color{blue}{\frac{1}{2} \cdot \log \left(re \cdot re + im \cdot im\right)}}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}} - re\right)}\]
    9. Applied exp-prod45.5

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{\color{blue}{{\left(e^{\frac{1}{2}}\right)}^{\left(\log \left(re \cdot re + im \cdot im\right)\right)}}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}} - re\right)}\]
    10. Taylor expanded around -inf 11.1

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

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

    if -1.6813385983305504e+75 < re < 8.896182596446849e-305

    1. Initial program 21.1

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

    if 8.896182596446849e-305 < re

    1. Initial program 45.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--45.2

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

      \[\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-div45.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.2

      \[\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 3 regimes into one program.
  4. Final simplification25.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -1.6813385983305504 \cdot 10^{+75}:\\ \;\;\;\;\sqrt{\left(-2 \cdot re\right) \cdot 2.0} \cdot 0.5\\ \mathbf{elif}\;re \le 8.896182596446849 \cdot 10^{-305}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{im \cdot im + re \cdot re} - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{\sqrt{im \cdot \left(2.0 \cdot im\right)}}{\sqrt{\sqrt{im \cdot im + re \cdot re} + re}}\\ \end{array}\]

Reproduce

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

sample180.0ms

Algorithm
intervals

simplify75.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

75.0ms
(* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re))))

prune8.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 38.3b

localize38.0ms

Local error

Found 3 expressions with local error:

31.9b
(sqrt (+ (* re re) (* im im)))
0.4b
(- (sqrt (+ (* re re) (* im im))) re)
0.0b
(sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))

rewrite31.0ms

Algorithm
rewrite-expression-head
Counts
3 → 36
Calls

3 calls. Slowest were:

19.0ms
(- (sqrt (+ (* re re) (* im im))) re)
6.0ms
(sqrt (+ (* re re) (* im im)))
4.0ms
(sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))

series175.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

98.0ms
(sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))
48.0ms
(sqrt (+ (* re re) (* im im)))
29.0ms
(- (sqrt (+ (* re re) (* im im))) re)

simplify1.2s

Counts
18 → 45
Calls

18 calls. Slowest were:

634.0ms
(sqrt (* 2.0 (- (pow (sqrt (+ (* re re) (* im im))) 3) (pow re 3))))
301.0ms
(sqrt (* 2.0 (- (* (sqrt (+ (* re re) (* im im))) (sqrt (+ (* re re) (* im im)))) (* re re))))
156.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))

prune492.0ms

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 18.8b

localize18.0ms

Local error

Found 4 expressions with local error:

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

rewrite29.0ms

Algorithm
rewrite-expression-head
Counts
4 → 83
Calls

4 calls. Slowest were:

14.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)))))
2.0ms
(sqrt (+ (* re re) (* im im)))

series106.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

36.0ms
(- (* (sqrt (sqrt (+ (* re re) (* im im)))) (sqrt (sqrt (+ (* re re) (* im im))))) re)
29.0ms
(sqrt (+ (* re re) (* im im)))
21.0ms
(sqrt (+ (* re re) (* im im)))
20.0ms
(* (sqrt (sqrt (+ (* re re) (* im im)))) (sqrt (sqrt (+ (* re re) (* im im)))))

simplify2.1s

Counts
64 → 95
Calls

64 calls. Slowest were:

234.0ms
(* (sqrt (sqrt (- (* re re) (* im im)))) (sqrt (sqrt (+ (* (* re re) (* re re)) (- (* (* im im) (* im im)) (* (* re re) (* im im)))))))
201.0ms
(* (sqrt (sqrt (+ (* (* re re) (* re re)) (- (* (* im im) (* im im)) (* (* re re) (* im im)))))) (sqrt (sqrt (- (* re re) (* im im)))))
187.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)))))))

prune1.3s

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 18.8b

localize22.0ms

Local error

Found 4 expressions with local error:

31.9b
(sqrt (+ (* re re) (* im im)))
31.9b
(sqrt (+ (* re re) (* im im)))
12.8b
(- (* (sqrt (exp (log (sqrt (+ (* re re) (* im im)))))) (sqrt (sqrt (+ (* re re) (* im im))))) re)
5.9b
(exp (log (sqrt (+ (* re re) (* im im)))))

rewrite25.0ms

Algorithm
rewrite-expression-head
Counts
4 → 60
Calls

4 calls. Slowest were:

14.0ms
(- (* (sqrt (exp (log (sqrt (+ (* re re) (* im im)))))) (sqrt (sqrt (+ (* re re) (* im im))))) re)
5.0ms
(sqrt (+ (* re re) (* im im)))
3.0ms
(exp (log (sqrt (+ (* re re) (* im im)))))

series84.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

24.0ms
(- (* (sqrt (exp (log (sqrt (+ (* re re) (* im im)))))) (sqrt (sqrt (+ (* re re) (* im im))))) re)
22.0ms
(sqrt (+ (* re re) (* im im)))
20.0ms
(exp (log (sqrt (+ (* re re) (* im im)))))
18.0ms
(sqrt (+ (* re re) (* im im)))

simplify605.0ms

Counts
38 → 72
Calls

38 calls. Slowest were:

154.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
123.0ms
(exp (log (sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))))
99.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))

prune1.0s

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 18.8b

localize59.0ms

Local error

Found 4 expressions with local error:

33.2b
(log (+ (* re re) (* im im)))
31.9b
(sqrt (+ (* re re) (* im im)))
12.5b
(- (* (sqrt (pow (exp 1/2) (log (+ (* re re) (* im im))))) (sqrt (sqrt (+ (* re re) (* im im))))) re)
6.4b
(pow (exp 1/2) (log (+ (* re re) (* im im))))

rewrite36.0ms

Algorithm
rewrite-expression-head
Counts
4 → 61
Calls

4 calls. Slowest were:

22.0ms
(- (* (sqrt (pow (exp 1/2) (log (+ (* re re) (* im im))))) (sqrt (sqrt (+ (* re re) (* im im))))) re)
6.0ms
(pow (exp 1/2) (log (+ (* re re) (* im im))))
4.0ms
(sqrt (+ (* re re) (* im im)))

series362.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

171.0ms
(- (* (sqrt (pow (exp 1/2) (log (+ (* re re) (* im im))))) (sqrt (sqrt (+ (* re re) (* im im))))) re)
119.0ms
(pow (exp 1/2) (log (+ (* re re) (* im im))))
41.0ms
(log (+ (* re re) (* im im)))
31.0ms
(sqrt (+ (* re re) (* im im)))

simplify825.0ms

Counts
38 → 73
Calls

38 calls. Slowest were:

176.0ms
(pow (exp 1/2) (log (+ (* (* re re) (* re re)) (- (* (* im im) (* im im)) (* (* re re) (* im im))))))
142.0ms
(sqrt (- (* (* re re) (* re re)) (* (* im im) (* im im))))
120.0ms
(log (- (* (* re re) (* re re)) (* (* im im) (* im im))))

prune1.2s

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 18.8b

regimes564.0ms

Accuracy

59.3% (8.2b remaining)

Error of 25.8b against oracle of 17.6b and baseline of 37.7b

bsearch130.0ms

end0.0ms

sample3.0s

Algorithm
intervals