Average Error: 26.0 → 13.0
Time: 21.0s
Precision: 64
Internal Precision: 128
\[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
\[\begin{array}{l} \mathbf{if}\;y.re \le -5.958224986118704 \cdot 10^{+172}:\\ \;\;\;\;\frac{-x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.re \le 6.6100911784357434 \cdot 10^{+81}:\\ \;\;\;\;\frac{\frac{(y.re \cdot x.re + \left(y.im \cdot x.im\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \end{array}\]

Error

Bits error versus x.re

Bits error versus x.im

Bits error versus y.re

Bits error versus y.im

Derivation

  1. Split input into 3 regimes
  2. if y.re < -5.958224986118704e+172

    1. Initial program 43.4

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified43.4

      \[\leadsto \color{blue}{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt43.4

      \[\leadsto \frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\color{blue}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*} \cdot \sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]
    5. Applied *-un-lft-identity43.4

      \[\leadsto \frac{\color{blue}{1 \cdot (x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*} \cdot \sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    6. Applied times-frac43.4

      \[\leadsto \color{blue}{\frac{1}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}} \cdot \frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]
    7. Simplified43.4

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.im^2 + y.re^2}^*}} \cdot \frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    8. Simplified30.3

      \[\leadsto \frac{1}{\sqrt{y.im^2 + y.re^2}^*} \cdot \color{blue}{\frac{(y.im \cdot x.im + \left(x.re \cdot y.re\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}\]
    9. Using strategy rm
    10. Applied associate-*l/30.2

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{(y.im \cdot x.im + \left(x.re \cdot y.re\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}{\sqrt{y.im^2 + y.re^2}^*}}\]
    11. Simplified30.2

      \[\leadsto \frac{\color{blue}{\frac{(y.re \cdot x.re + \left(x.im \cdot y.im\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}}{\sqrt{y.im^2 + y.re^2}^*}\]
    12. Taylor expanded around -inf 11.7

      \[\leadsto \frac{\color{blue}{-1 \cdot x.re}}{\sqrt{y.im^2 + y.re^2}^*}\]
    13. Simplified11.7

      \[\leadsto \frac{\color{blue}{-x.re}}{\sqrt{y.im^2 + y.re^2}^*}\]

    if -5.958224986118704e+172 < y.re < 6.6100911784357434e+81

    1. Initial program 20.0

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified20.0

      \[\leadsto \color{blue}{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt20.0

      \[\leadsto \frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\color{blue}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*} \cdot \sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]
    5. Applied *-un-lft-identity20.0

      \[\leadsto \frac{\color{blue}{1 \cdot (x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*} \cdot \sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    6. Applied times-frac20.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}} \cdot \frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]
    7. Simplified20.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.im^2 + y.re^2}^*}} \cdot \frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    8. Simplified12.2

      \[\leadsto \frac{1}{\sqrt{y.im^2 + y.re^2}^*} \cdot \color{blue}{\frac{(y.im \cdot x.im + \left(x.re \cdot y.re\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}\]
    9. Using strategy rm
    10. Applied associate-*l/12.0

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{(y.im \cdot x.im + \left(x.re \cdot y.re\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}{\sqrt{y.im^2 + y.re^2}^*}}\]
    11. Simplified12.0

      \[\leadsto \frac{\color{blue}{\frac{(y.re \cdot x.re + \left(x.im \cdot y.im\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}}{\sqrt{y.im^2 + y.re^2}^*}\]

    if 6.6100911784357434e+81 < y.re

    1. Initial program 37.4

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified37.4

      \[\leadsto \color{blue}{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt37.4

      \[\leadsto \frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\color{blue}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*} \cdot \sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]
    5. Applied *-un-lft-identity37.4

      \[\leadsto \frac{\color{blue}{1 \cdot (x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*} \cdot \sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    6. Applied times-frac37.4

      \[\leadsto \color{blue}{\frac{1}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}} \cdot \frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]
    7. Simplified37.4

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.im^2 + y.re^2}^*}} \cdot \frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    8. Simplified24.7

      \[\leadsto \frac{1}{\sqrt{y.im^2 + y.re^2}^*} \cdot \color{blue}{\frac{(y.im \cdot x.im + \left(x.re \cdot y.re\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}\]
    9. Using strategy rm
    10. Applied associate-*l/24.6

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{(y.im \cdot x.im + \left(x.re \cdot y.re\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}{\sqrt{y.im^2 + y.re^2}^*}}\]
    11. Simplified24.6

      \[\leadsto \frac{\color{blue}{\frac{(y.re \cdot x.re + \left(x.im \cdot y.im\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}}{\sqrt{y.im^2 + y.re^2}^*}\]
    12. Using strategy rm
    13. Applied *-un-lft-identity24.6

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot (y.re \cdot x.re + \left(x.im \cdot y.im\right))_*}}{\sqrt{y.im^2 + y.re^2}^*}}{\sqrt{y.im^2 + y.re^2}^*}\]
    14. Applied associate-/l*24.7

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\sqrt{y.im^2 + y.re^2}^*}{(y.re \cdot x.re + \left(x.im \cdot y.im\right))_*}}}}{\sqrt{y.im^2 + y.re^2}^*}\]
    15. Taylor expanded around 0 17.1

      \[\leadsto \frac{\color{blue}{x.re}}{\sqrt{y.im^2 + y.re^2}^*}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -5.958224986118704 \cdot 10^{+172}:\\ \;\;\;\;\frac{-x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.re \le 6.6100911784357434 \cdot 10^{+81}:\\ \;\;\;\;\frac{\frac{(y.re \cdot x.re + \left(y.im \cdot x.im\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \end{array}\]

Reproduce

herbie shell --seed 2019008 +o rules:numerics
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, real part"
  (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))

Details

Time bar (total: 19.7s)Debug log

sample67.0ms

Algorithm
intervals

simplify14.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

14.0ms
(/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im)))

prune31.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 28.3b

localize35.0ms

Local error

Found 3 expressions with local error:

28.3b
(/ (fma x.re y.re (* x.im y.im)) (fma y.im y.im (* y.re y.re)))
0.0b
(fma y.im y.im (* y.re y.re))
0.0b
(fma x.re y.re (* x.im y.im))

rewrite5.0ms

Algorithm
rewrite-expression-head
Counts
3 → 49
Calls

3 calls. Slowest were:

4.0ms
(/ (fma x.re y.re (* x.im y.im)) (fma y.im y.im (* y.re y.re)))
0.0ms
(fma y.im y.im (* y.re y.re))
0.0ms
(fma x.re y.re (* x.im y.im))

series102.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

59.0ms
(/ (fma x.re y.re (* x.im y.im)) (fma y.im y.im (* y.re y.re)))
25.0ms
(fma x.re y.re (* x.im y.im))
18.0ms
(fma y.im y.im (* y.re y.re))

simplify535.0ms

Counts
34 → 58
Calls

34 calls. Slowest were:

211.0ms
(/ (* (* (fma x.re y.re (* x.im y.im)) (fma x.re y.re (* x.im y.im))) (fma x.re y.re (* x.im y.im))) (* (* (fma y.im y.im (* y.re y.re)) (fma y.im y.im (* y.re y.re))) (fma y.im y.im (* y.re y.re))))
41.0ms
(/ (* (cbrt (fma x.re y.re (* x.im y.im))) (cbrt (fma x.re y.re (* x.im y.im)))) (* (cbrt (fma y.im y.im (* y.re y.re))) (cbrt (fma y.im y.im (* y.re y.re)))))
19.0ms
(/ (cbrt (fma x.re y.re (* x.im y.im))) (cbrt (fma y.im y.im (* y.re y.re))))

prune673.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 17.5b

localize37.0ms

Local error

Found 4 expressions with local error:

17.2b
(/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re))
0.2b
(* (/ 1 (hypot y.im y.re)) (/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re)))
0.0b
(/ 1 (hypot y.im y.re))
0.0b
(hypot y.im y.re)

rewrite11.0ms

Algorithm
rewrite-expression-head
Counts
4 → 94
Calls

4 calls. Slowest were:

6.0ms
(* (/ 1 (hypot y.im y.re)) (/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re)))
3.0ms
(/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re))
1.0ms
(/ 1 (hypot y.im y.re))

series284.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

149.0ms
(* (/ 1 (hypot y.im y.re)) (/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re)))
86.0ms
(/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re))
26.0ms
(/ 1 (hypot y.im y.re))
23.0ms
(hypot y.im y.re)

simplify2.1s

Counts
67 → 106
Calls

67 calls. Slowest were:

616.0ms
(* (* (* (/ 1 (hypot y.im y.re)) (/ 1 (hypot y.im y.re))) (/ 1 (hypot y.im y.re))) (* (* (/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re)) (/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re))) (/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re))))
322.0ms
(* (/ 1 (hypot y.im y.re)) (/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re)))
130.0ms
(/ (* (* (fma y.im x.im (* x.re y.re)) (fma y.im x.im (* x.re y.re))) (fma y.im x.im (* x.re y.re))) (* (* (hypot y.im y.re) (hypot y.im y.re)) (hypot y.im y.re)))

prune1.3s

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 7.1b

localize19.0ms

Local error

Found 4 expressions with local error:

17.2b
(/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re))
0.1b
(/ (/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re)) (hypot y.im y.re))
0.0b
(fma y.re x.re (* x.im y.im))
0.0b
(hypot y.im y.re)

rewrite22.0ms

Algorithm
rewrite-expression-head
Counts
4 → 121
Calls

4 calls. Slowest were:

12.0ms
(/ (/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re)) (hypot y.im y.re))
6.0ms
(/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re))
0.0ms
(fma y.re x.re (* x.im y.im))

series308.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

114.0ms
(/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re))
109.0ms
(/ (/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re)) (hypot y.im y.re))
47.0ms
(fma y.re x.re (* x.im y.im))
38.0ms
(hypot y.im y.re)

simplify2.9s

Counts
135 → 133
Calls

135 calls. Slowest were:

265.0ms
(/ (/ (* (* (fma y.re x.re (* x.im y.im)) (fma y.re x.re (* x.im y.im))) (fma y.re x.re (* x.im y.im))) (* (* (hypot y.im y.re) (hypot y.im y.re)) (hypot y.im y.re))) (* (* (hypot y.im y.re) (hypot y.im y.re)) (hypot y.im y.re)))
215.0ms
(/ (* (* (/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re)) (/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re))) (/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re))) (* (* (hypot y.im y.re) (hypot y.im y.re)) (hypot y.im y.re)))
184.0ms
(/ (/ (* (cbrt (fma y.re x.re (* x.im y.im))) (cbrt (fma y.re x.re (* x.im y.im)))) (* (cbrt (hypot y.im y.re)) (cbrt (hypot y.im y.re)))) 1)

prune1.7s

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 1.9b

localize8.0ms

Local error

Found 4 expressions with local error:

17.3b
(/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))
0.2b
(/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im))))
0.1b
(/ (/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))) (hypot y.im y.re))
0.0b
(fma y.re x.re (* x.im y.im))

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
4 → 109
Calls

4 calls. Slowest were:

4.0ms
(/ (/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))) (hypot y.im y.re))
3.0ms
(/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))
1.0ms
(/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im))))

series340.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

121.0ms
(/ (/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))) (hypot y.im y.re))
112.0ms
(/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im))))
68.0ms
(/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))
38.0ms
(fma y.re x.re (* x.im y.im))

simplify5.7s

Counts
92 → 121
Calls

92 calls. Slowest were:

799.0ms
(/ (/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))) (cbrt (hypot y.im y.re)))
444.0ms
(/ (/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))) (cbrt (hypot y.im y.re)))
402.0ms
(/ (/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))) (sqrt (hypot y.im y.re)))

prune1.3s

Pruning

11 alts after pruning (9 fresh and 2 done)

Merged error: 1.9b

regimes366.0ms

Accuracy

25% (10.6b remaining)

Error of 13.0b against oracle of 2.4b and baseline of 16.5b

bsearch134.0ms

end0.0ms

sample1.6s

Algorithm
intervals