Average Error: 25.5 → 12.3
Time: 17.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.re \le -1.0598670353086325 \cdot 10^{+133}:\\ \;\;\;\;\frac{-x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.re \le 2.0830718422818717 \cdot 10^{+146}:\\ \;\;\;\;\frac{\frac{(x.re \cdot y.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 < -1.0598670353086325e+133

    1. Initial program 42.9

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Initial simplification42.9

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

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

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

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

      \[\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. Simplified28.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-*r/28.2

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

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot (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}^*}\]
    13. Simplified28.2

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

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

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

    if -1.0598670353086325e+133 < y.re < 2.0830718422818717e+146

    1. Initial program 18.2

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Initial simplification18.2

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

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

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

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

      \[\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. Simplified11.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-*r/11.7

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

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot (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}^*}\]
    13. Simplified11.6

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

    if 2.0830718422818717e+146 < y.re

    1. Initial program 44.4

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

      \[\leadsto \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-sqrt44.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-identity44.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-frac44.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. Simplified44.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. Simplified28.5

      \[\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-*r/28.5

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

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot (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}^*}\]
    13. Simplified28.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -1.0598670353086325 \cdot 10^{+133}:\\ \;\;\;\;\frac{-x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.re \le 2.0830718422818717 \cdot 10^{+146}:\\ \;\;\;\;\frac{\frac{(x.re \cdot y.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 2018362 +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: 13.7s)Debug log

start86.0ms

Algorithm
intervals

setup29.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 23.8b

localize18.0ms

Local error

Found 2 expressions with local error:

23.8b
(/ (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))

rewrite4.0ms

Algorithm
rewrite-expression-head
Counts
2 → 39
Calls

2 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 x.re y.re (* x.im y.im))

series131.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

85.0ms
(/ (fma x.re y.re (* x.im y.im)) (fma y.im y.im (* y.re y.re)))
46.0ms
(fma x.re y.re (* x.im y.im))

simplify515.0ms

Counts
31 → 45
Calls

31 calls. Slowest were:

215.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))))
29.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)))))
21.0ms
(- (log (fma x.re y.re (* x.im y.im))) (log (fma y.im y.im (* y.re y.re))))

prune547.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 16.3b

localize19.0ms

Local error

Found 4 expressions with local error:

16.0b
(/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re))
0.3b
(fma y.im x.im (* x.re y.re))
0.3b
(* (/ 1 (hypot y.im y.re)) (/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re)))
0.0b
(hypot y.im y.re)

rewrite20.0ms

Algorithm
rewrite-expression-head
Counts
4 → 86
Calls

4 calls. Slowest were:

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

series313.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

165.0ms
(* (/ 1 (hypot y.im y.re)) (/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re)))
68.0ms
(/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re))
41.0ms
(fma y.im x.im (* x.re y.re))
38.0ms
(hypot y.im y.re)

simplify2.1s

Counts
63 → 98
Calls

63 calls. Slowest were:

545.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))))
327.0ms
(* (/ 1 (hypot y.im y.re)) (/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re)))
144.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)) (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: 6.8b

localize10.0ms

Local error

Found 4 expressions with local error:

16.1b
(* (/ 1 (hypot y.im y.re)) (fma y.im x.im (* x.re y.re)))
0.3b
(fma y.im x.im (* x.re y.re))
0.1b
(/ (* (/ 1 (hypot y.im y.re)) (fma y.im x.im (* x.re y.re))) (hypot y.im y.re))
0.0b
(hypot y.im y.re)

rewrite25.0ms

Algorithm
rewrite-expression-head
Counts
4 → 69
Calls

4 calls. Slowest were:

14.0ms
(/ (* (/ 1 (hypot y.im y.re)) (fma y.im x.im (* x.re y.re))) (hypot y.im y.re))
9.0ms
(* (/ 1 (hypot y.im y.re)) (fma y.im x.im (* x.re y.re)))
0.0ms
(fma y.im x.im (* x.re y.re))

series319.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

170.0ms
(/ (* (/ 1 (hypot y.im y.re)) (fma y.im x.im (* x.re y.re))) (hypot y.im y.re))
75.0ms
(* (/ 1 (hypot y.im y.re)) (fma y.im x.im (* x.re y.re)))
41.0ms
(fma y.im x.im (* x.re y.re))
32.0ms
(hypot y.im y.re)

simplify1.8s

Counts
40 → 81
Calls

40 calls. Slowest were:

731.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)) (fma y.im x.im (* x.re y.re))) (fma y.im x.im (* x.re y.re))))
218.0ms
(- (log (* (/ 1 (hypot y.im y.re)) (fma y.im x.im (* x.re y.re)))) (log (hypot y.im y.re)))
155.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)) (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.0s

Pruning

11 alts after pruning (11 fresh and 0 done)

Merged error: 6.7b

localize10.0ms

Local error

Found 4 expressions with local error:

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

rewrite11.0ms

Algorithm
rewrite-expression-head
Counts
4 → 121
Calls

4 calls. Slowest were:

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

series269.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

104.0ms
(/ (/ (fma x.re y.re (* x.im y.im)) (hypot y.im y.re)) (hypot y.im y.re))
98.0ms
(/ (fma x.re y.re (* x.im y.im)) (hypot y.im y.re))
41.0ms
(hypot y.im y.re)
26.0ms
(hypot y.im y.re)

simplify2.9s

Counts
135 → 133
Calls

135 calls. Slowest were:

295.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))) (* (* (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)))
231.0ms
(/ (* (* (/ (fma x.re y.re (* x.im y.im)) (hypot y.im y.re)) (/ (fma x.re y.re (* x.im y.im)) (hypot y.im y.re))) (/ (fma x.re y.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)))
200.0ms
(/ (/ (* (cbrt (fma x.re y.re (* x.im y.im))) (cbrt (fma x.re y.re (* x.im y.im)))) (* (cbrt (hypot y.im y.re)) (cbrt (hypot y.im y.re)))) 1)

prune1.6s

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 2.9b

regimes497.0ms

Accuracy

29.8% (9.8b remaining)

Error of 12.3b against oracle of 2.4b and baseline of 16.4b

bsearch116.0ms