Average Error: 26.3 → 13.2
Time: 21.4s
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.im \le -8.346460948837449 \cdot 10^{+220}:\\ \;\;\;\;\frac{-x.im}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.im \le 1.0043357683224773 \cdot 10^{+119}:\\ \;\;\;\;\frac{\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}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\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.im < -8.346460948837449e+220

    1. Initial program 42.5

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified42.5

      \[\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-sqrt42.5

      \[\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-identity42.5

      \[\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-frac42.5

      \[\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. Simplified42.5

      \[\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. Simplified32.6

      \[\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/32.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. Simplified32.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 clear-num32.6

      \[\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}^*}\]
    14. Taylor expanded around -inf 11.2

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

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

    if -8.346460948837449e+220 < y.im < 1.0043357683224773e+119

    1. Initial program 21.3

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified21.3

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

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

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

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

      \[\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.9

      \[\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.8

      \[\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.8

      \[\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 1.0043357683224773e+119 < y.im

    1. Initial program 40.6

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified40.6

      \[\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-sqrt40.6

      \[\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-identity40.6

      \[\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-frac40.6

      \[\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. Simplified40.6

      \[\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. Simplified26.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/26.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. Simplified26.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. Using strategy rm
    13. Applied clear-num26.2

      \[\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}^*}\]
    14. Taylor expanded around inf 15.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \le -8.346460948837449 \cdot 10^{+220}:\\ \;\;\;\;\frac{-x.im}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.im \le 1.0043357683224773 \cdot 10^{+119}:\\ \;\;\;\;\frac{\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}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\sqrt{y.im^2 + y.re^2}^*}\\ \end{array}\]

Reproduce

herbie shell --seed 2019005 +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: 20.1s)Debug log

sample66.0ms

Algorithm
intervals

simplify15.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune21.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 23.6b

localize33.0ms

Local error

Found 2 expressions with local error:

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

rewrite8.0ms

Algorithm
rewrite-expression-head
Counts
2 → 39
Calls

2 calls. Slowest were:

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

series155.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

111.0ms
(/ (fma x.re y.re (* x.im y.im)) (fma y.im y.im (* y.re y.re)))
43.0ms
(fma x.re y.re (* x.im y.im))

simplify618.0ms

Counts
31 → 45
Calls

31 calls. Slowest were:

223.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)))))
32.0ms
(/ (* (cbrt (fma x.re y.re (* x.im y.im))) (cbrt (fma x.re y.re (* x.im y.im)))) 1)

prune647.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 14.7b

localize36.0ms

Local error

Found 4 expressions with local error:

14.4b
(/ (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.2b
(fma y.im x.im (* x.re y.re))
0.0b
(hypot y.im y.re)

rewrite22.0ms

Algorithm
rewrite-expression-head
Counts
4 → 86
Calls

4 calls. Slowest were:

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

series285.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

132.0ms
(* (/ 1 (hypot y.im y.re)) (/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re)))
72.0ms
(/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re))
44.0ms
(fma y.im x.im (* x.re y.re))
37.0ms
(hypot y.im y.re)

simplify2.1s

Counts
63 → 98
Calls

63 calls. Slowest were:

568.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))))
313.0ms
(* (/ 1 (hypot y.im y.re)) (/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re)))
154.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

11 alts after pruning (11 fresh and 0 done)

Merged error: 5.5b

localize20.0ms

Local error

Found 4 expressions with local error:

14.4b
(/ (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
(hypot y.im y.re)
0.0b
(hypot y.im y.re)

rewrite16.0ms

Algorithm
rewrite-expression-head
Counts
4 → 121
Calls

4 calls. Slowest were:

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

series231.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

95.0ms
(/ (/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re)) (hypot y.im y.re))
83.0ms
(/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re))
29.0ms
(hypot y.im y.re)
23.0ms
(hypot y.im y.re)

simplify3.1s

Counts
135 → 133
Calls

135 calls. Slowest were:

369.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)))
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)
178.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)))

prune1.8s

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 3.0b

localize13.0ms

Local error

Found 4 expressions with local error:

14.5b
(/ (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
(hypot y.im y.re)

rewrite20.0ms

Algorithm
rewrite-expression-head
Counts
4 → 109
Calls

4 calls. Slowest were:

8.0ms
(/ (/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))) (hypot y.im y.re))
7.0ms
(/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))
3.0ms
(/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im))))

series343.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

132.0ms
(/ (/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))) (hypot y.im y.re))
104.0ms
(/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im))))
74.0ms
(/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))
33.0ms
(hypot y.im y.re)

simplify5.2s

Counts
92 → 121
Calls

92 calls. Slowest were:

392.0ms
(/ (/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))) (sqrt (hypot y.im y.re)))
371.0ms
(/ (/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))) (cbrt (hypot y.im y.re)))
361.0ms
(/ (/ 1 (/ (hypot y.im y.re) (fma y.re x.re (* x.im y.im)))) (sqrt (hypot y.im y.re)))

prune1.5s

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 3.0b

regimes418.0ms

Accuracy

24.7% (10.5b remaining)

Error of 13.2b against oracle of 2.7b and baseline of 16.6b

bsearch95.0ms

end0.0ms

sample1.9s

Algorithm
intervals