Average Error: 25.4 → 13.5
Time: 19.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 -9.234484326885406 \cdot 10^{+101}:\\ \;\;\;\;\frac{-1}{\sqrt{y.im^2 + y.re^2}^*} \cdot x.im\\ \mathbf{elif}\;y.im \le -1.1521206323075965 \cdot 10^{-237}:\\ \;\;\;\;\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{elif}\;y.im \le -7.3148665069542 \cdot 10^{-292}:\\ \;\;\;\;\frac{-x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.im \le 1.0294661443825063 \cdot 10^{+154}:\\ \;\;\;\;\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 4 regimes
  2. if y.im < -9.234484326885406e+101

    1. Initial program 38.4

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified38.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-sqrt38.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-identity38.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-frac38.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. Simplified38.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.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. Taylor expanded around -inf 16.0

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

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

    if -9.234484326885406e+101 < y.im < -1.1521206323075965e-237 or -7.3148665069542e-292 < y.im < 1.0294661443825063e+154

    1. Initial program 18.4

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified18.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-sqrt18.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-identity18.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-frac18.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. Simplified18.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. 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 -1.1521206323075965e-237 < y.im < -7.3148665069542e-292

    1. Initial program 23.5

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified23.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-sqrt23.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-identity23.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-frac23.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. Simplified23.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. Simplified13.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/13.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. Simplified13.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. Taylor expanded around -inf 30.6

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

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

    if 1.0294661443825063e+154 < y.im

    1. Initial program 43.2

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

      \[\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.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-identity43.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-frac43.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. Simplified43.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. Simplified28.1

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

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

      \[\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 0 12.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \le -9.234484326885406 \cdot 10^{+101}:\\ \;\;\;\;\frac{-1}{\sqrt{y.im^2 + y.re^2}^*} \cdot x.im\\ \mathbf{elif}\;y.im \le -1.1521206323075965 \cdot 10^{-237}:\\ \;\;\;\;\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{elif}\;y.im \le -7.3148665069542 \cdot 10^{-292}:\\ \;\;\;\;\frac{-x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.im \le 1.0294661443825063 \cdot 10^{+154}:\\ \;\;\;\;\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 2019004 +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: 18.0s)Debug log

sample79.0ms

Algorithm
intervals

simplify8.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 30.8b

localize17.0ms

Local error

Found 3 expressions with local error:

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

rewrite4.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 x.re y.re (* x.im y.im))
0.0ms
(fma y.im y.im (* y.re y.re))

series149.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

73.0ms
(/ (fma x.re y.re (* x.im y.im)) (fma y.im y.im (* y.re y.re)))
45.0ms
(fma x.re y.re (* x.im y.im))
31.0ms
(fma y.im y.im (* y.re y.re))

simplify606.0ms

Counts
34 → 58
Calls

34 calls. Slowest were:

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

prune666.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 21.8b

localize24.0ms

Local error

Found 4 expressions with local error:

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

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

series285.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

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

simplify1.9s

Counts
67 → 106
Calls

67 calls. Slowest were:

535.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))))
244.0ms
(* (/ 1 (hypot y.im y.re)) (/ (fma y.im x.im (* x.re y.re)) (hypot y.im y.re)))
158.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.1s

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 8.1b

localize9.0ms

Local error

Found 3 expressions with local error:

21.5b
(/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re))
0.2b
(fma y.re x.re (* x.im y.im))
0.1b
(/ (/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re)) (hypot y.im y.re))

rewrite13.0ms

Algorithm
rewrite-expression-head
Counts
3 → 111
Calls

3 calls. Slowest were:

8.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))
0.0ms
(fma y.re x.re (* x.im y.im))

series210.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

91.0ms
(/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re))
80.0ms
(/ (/ (fma y.re x.re (* x.im y.im)) (hypot y.im y.re)) (hypot y.im y.re))
39.0ms
(fma y.re x.re (* x.im y.im))

simplify3.0s

Counts
132 → 120
Calls

132 calls. Slowest were:

349.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)))
245.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)))
175.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 (8 fresh and 2 done)

Merged error: 3.3b

localize17.0ms

Local error

Found 4 expressions with local error:

22.1b
(cbrt (fma y.im x.im (* x.re y.re)))
22.1b
(cbrt (fma y.im x.im (* x.re y.re)))
22.1b
(cbrt (fma y.im x.im (* x.re y.re)))
4.7b
(* (/ 1 (hypot y.im y.re)) (/ (* (cbrt (fma y.im x.im (* x.re y.re))) (cbrt (fma y.im x.im (* x.re y.re)))) 1))

rewrite16.0ms

Algorithm
rewrite-expression-head
Counts
4 → 64
Calls

4 calls. Slowest were:

14.0ms
(* (/ 1 (hypot y.im y.re)) (/ (* (cbrt (fma y.im x.im (* x.re y.re))) (cbrt (fma y.im x.im (* x.re y.re)))) 1))
1.0ms
(cbrt (fma y.im x.im (* x.re y.re)))
1.0ms
(cbrt (fma y.im x.im (* x.re y.re)))

series659.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

270.0ms
(* (/ 1 (hypot y.im y.re)) (/ (* (cbrt (fma y.im x.im (* x.re y.re))) (cbrt (fma y.im x.im (* x.re y.re)))) 1))
152.0ms
(cbrt (fma y.im x.im (* x.re y.re)))
137.0ms
(cbrt (fma y.im x.im (* x.re y.re)))
100.0ms
(cbrt (fma y.im x.im (* x.re y.re)))

simplify3.8s

Counts
34 → 76
Calls

34 calls. Slowest were:

443.0ms
(* (/ 1 (hypot y.im y.re)) (/ (* (cbrt (fma y.im x.im (* x.re y.re))) (cbrt (fma y.im x.im (* x.re y.re)))) 1))
419.0ms
(exp (* -1/3 (+ (log (/ 1 x.im)) (log (/ 1 y.im)))))
383.0ms
(exp (* -1/3 (+ (log (/ 1 x.im)) (log (/ 1 y.im)))))

prune1.1s

Pruning

10 alts after pruning (7 fresh and 3 done)

Merged error: 3.3b

regimes526.0ms

Accuracy

20.2% (11.4b remaining)

Error of 13.5b against oracle of 2.2b and baseline of 16.4b

bsearch289.0ms

end0.0ms

sample2.0s

Algorithm
intervals