Average Error: 26.1 → 12.7
Time: 19.9s
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 -4.001353954028944 \cdot 10^{+116}:\\ \;\;\;\;\frac{-x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.re \le 1.6521411071335998 \cdot 10^{+156}:\\ \;\;\;\;\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 < -4.001353954028944e+116

    1. Initial program 40.7

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

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

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

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

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

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

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

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

      \[\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 15.6

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

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

    if -4.001353954028944e+116 < y.re < 1.6521411071335998e+156

    1. Initial program 19.3

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

      \[\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-sqrt19.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-identity19.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-frac19.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. Simplified19.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. Simplified11.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/11.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. Simplified11.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}^*}\]
    12. Using strategy rm
    13. Applied *-un-lft-identity11.8

      \[\leadsto \frac{\frac{(y.re \cdot x.re + \left(x.im \cdot y.im\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}{\color{blue}{1 \cdot \sqrt{y.im^2 + y.re^2}^*}}\]
    14. Applied *-un-lft-identity11.8

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

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

      \[\leadsto \color{blue}{1} \cdot \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}^*}\]

    if 1.6521411071335998e+156 < y.re

    1. Initial program 43.9

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Initial simplification43.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-sqrt43.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-identity43.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-frac43.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. Simplified43.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-*l/28.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. Simplified28.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 13.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -4.001353954028944 \cdot 10^{+116}:\\ \;\;\;\;\frac{-x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.re \le 1.6521411071335998 \cdot 10^{+156}:\\ \;\;\;\;\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 2018365 +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: 16.2s)Debug log

start76.0ms

Algorithm
intervals

setup18.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 24.9b

localize33.0ms

Local error

Found 1 expressions with local error:

24.9b
(/ (fma x.re y.re (* x.im y.im)) (fma y.im y.im (* y.re y.re)))

rewrite19.0ms

Algorithm
rewrite-expression-head
Counts
1 → 29
Calls

1 calls. Slowest were:

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

series75.0ms

Counts
1 → 3
Calls

1 calls. Slowest were:

75.0ms
(/ (fma x.re y.re (* x.im y.im)) (fma y.im y.im (* y.re y.re)))

simplify526.0ms

Counts
28 → 32
Calls

28 calls. Slowest were:

236.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))))
23.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)))))
20.0ms
(/ (cbrt (fma x.re y.re (* x.im y.im))) (cbrt (fma y.im y.im (* y.re y.re))))

prune403.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 16.8b

localize31.0ms

Local error

Found 4 expressions with local error:

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

rewrite22.0ms

Algorithm
rewrite-expression-head
Counts
4 → 94
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))
2.0ms
(/ 1 (hypot y.im y.re))

series248.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

119.0ms
(* (/ 1 (hypot y.im y.re)) (/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re)))
75.0ms
(/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re))
27.0ms
(/ 1 (hypot y.im y.re))
26.0ms
(fma y.im x.im (* x.re y.re))

simplify2.5s

Counts
67 → 106
Calls

67 calls. Slowest were:

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

Pruning

11 alts after pruning (11 fresh and 0 done)

Merged error: 6.7b

localize10.0ms

Local error

Found 2 expressions with local error:

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

rewrite14.0ms

Algorithm
rewrite-expression-head
Counts
2 → 101
Calls

2 calls. Slowest were:

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

series174.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

101.0ms
(/ (/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re)) (hypot y.im y.re))
72.0ms
(/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re))

simplify3.3s

Counts
129 → 107
Calls

129 calls. Slowest were:

383.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)))
262.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)))
223.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.4s

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 3.0b

localize3.0ms

Local error

Found 2 expressions with local error:

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

rewrite11.0ms

Algorithm
rewrite-expression-head
Counts
2 → 101
Calls

2 calls. Slowest were:

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

series182.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

100.0ms
(/ (/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re)) (hypot y.im y.re))
82.0ms
(/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re))

simplify3.4s

Counts
129 → 107
Calls

129 calls. Slowest were:

342.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)))
269.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)))
259.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.6s

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 3.0b

regimes439.0ms

Accuracy

26.6% (10.4b remaining)

Error of 12.7b against oracle of 2.3b and baseline of 16.5b

bsearch110.0ms