Average Error: 26.3 → 0.8
Time: 15.1s
Precision: binary64
Cost: 20224
\[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
\[\frac{x.im \cdot \frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - y.im \cdot \frac{x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (/
  (- (* x.im (/ y.re (hypot y.re y.im))) (* y.im (/ x.re (hypot y.im y.re))))
  (hypot y.re y.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return ((x_46_im * (y_46_re / hypot(y_46_re, y_46_im))) - (y_46_im * (x_46_re / hypot(y_46_im, y_46_re)))) / hypot(y_46_re, y_46_im);
}
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return ((x_46_im * (y_46_re / Math.hypot(y_46_re, y_46_im))) - (y_46_im * (x_46_re / Math.hypot(y_46_im, y_46_re)))) / Math.hypot(y_46_re, y_46_im);
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	return ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im))
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	return ((x_46_im * (y_46_re / math.hypot(y_46_re, y_46_im))) - (y_46_im * (x_46_re / math.hypot(y_46_im, y_46_re)))) / math.hypot(y_46_re, y_46_im)
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return Float64(Float64(Float64(x_46_im * y_46_re) - Float64(x_46_re * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im)))
end
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return Float64(Float64(Float64(x_46_im * Float64(y_46_re / hypot(y_46_re, y_46_im))) - Float64(y_46_im * Float64(x_46_re / hypot(y_46_im, y_46_re)))) / hypot(y_46_re, y_46_im))
end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = ((x_46_im * (y_46_re / hypot(y_46_re, y_46_im))) - (y_46_im * (x_46_re / hypot(y_46_im, y_46_re)))) / hypot(y_46_re, y_46_im);
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[(x$46$im * y$46$re), $MachinePrecision] - N[(x$46$re * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[(x$46$im * N[(y$46$re / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(y$46$im * N[(x$46$re / N[Sqrt[y$46$im ^ 2 + y$46$re ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]
\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\frac{x.im \cdot \frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - y.im \cdot \frac{x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 26.3

    \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
  2. Applied egg-rr17.0

    \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}} \]
  3. Applied egg-rr9.6

    \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\mathsf{fma}\left(\frac{x.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{y.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, -\frac{x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right)} \]
  4. Simplified0.9

    \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\left(\frac{x.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{y.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} - \frac{x.re}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.im}}\right)} \]
    Proof
    (-.f64 (*.f64 (/.f64 x.im (sqrt.f64 (hypot.f64 y.re y.im))) (/.f64 y.re (sqrt.f64 (hypot.f64 y.re y.im)))) (/.f64 x.re (/.f64 (hypot.f64 y.re y.im) y.im))): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (/.f64 x.im (sqrt.f64 (hypot.f64 y.re y.im))) (/.f64 y.re (sqrt.f64 (hypot.f64 y.re y.im)))) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x.re y.im) (hypot.f64 y.re y.im)))): 45 points increase in error, 10 points decrease in error
    (Rewrite=> fma-neg_binary64 (fma.f64 (/.f64 x.im (sqrt.f64 (hypot.f64 y.re y.im))) (/.f64 y.re (sqrt.f64 (hypot.f64 y.re y.im))) (neg.f64 (/.f64 (*.f64 x.re y.im) (hypot.f64 y.re y.im))))): 0 points increase in error, 0 points decrease in error
  5. Applied egg-rr10.0

    \[\leadsto \color{blue}{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} + \left(\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(-y.im\right)\right) \cdot \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}} \]
  6. Simplified9.2

    \[\leadsto \color{blue}{\frac{x.im \cdot \frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{y.im \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}} \]
    Proof
    (/.f64 (-.f64 (*.f64 x.im (/.f64 y.re (hypot.f64 y.re y.im))) (/.f64 (*.f64 y.im x.re) (hypot.f64 y.re y.im))) (hypot.f64 y.re y.im)): 0 points increase in error, 0 points decrease in error
    (/.f64 (-.f64 (*.f64 x.im (/.f64 y.re (hypot.f64 y.re y.im))) (Rewrite<= associate-*r/_binary64 (*.f64 y.im (/.f64 x.re (hypot.f64 y.re y.im))))) (hypot.f64 y.re y.im)): 5 points increase in error, 41 points decrease in error
    (/.f64 (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 y.re (hypot.f64 y.re y.im)) x.im)) (*.f64 y.im (/.f64 x.re (hypot.f64 y.re y.im)))) (hypot.f64 y.re y.im)): 0 points increase in error, 0 points decrease in error
    (/.f64 (-.f64 (Rewrite<= associate-/r/_binary64 (/.f64 y.re (/.f64 (hypot.f64 y.re y.im) x.im))) (*.f64 y.im (/.f64 x.re (hypot.f64 y.re y.im)))) (hypot.f64 y.re y.im)): 18 points increase in error, 7 points decrease in error
    (/.f64 (-.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y.re x.im) (hypot.f64 y.re y.im))) (*.f64 y.im (/.f64 x.re (hypot.f64 y.re y.im)))) (hypot.f64 y.re y.im)): 50 points increase in error, 9 points decrease in error
    (/.f64 (-.f64 (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 x.im y.re)) (hypot.f64 y.re y.im)) (*.f64 y.im (/.f64 x.re (hypot.f64 y.re y.im)))) (hypot.f64 y.re y.im)): 0 points increase in error, 0 points decrease in error
    (Rewrite=> div-sub_binary64 (-.f64 (/.f64 (/.f64 (*.f64 x.im y.re) (hypot.f64 y.re y.im)) (hypot.f64 y.re y.im)) (/.f64 (*.f64 y.im (/.f64 x.re (hypot.f64 y.re y.im))) (hypot.f64 y.re y.im)))): 1 points increase in error, 1 points decrease in error
    (Rewrite=> sub-neg_binary64 (+.f64 (/.f64 (/.f64 (*.f64 x.im y.re) (hypot.f64 y.re y.im)) (hypot.f64 y.re y.im)) (neg.f64 (/.f64 (*.f64 y.im (/.f64 x.re (hypot.f64 y.re y.im))) (hypot.f64 y.re y.im))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (/.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 (/.f64 (*.f64 x.im y.re) (hypot.f64 y.re y.im)) 1)) (hypot.f64 y.re y.im)) (neg.f64 (/.f64 (*.f64 y.im (/.f64 x.re (hypot.f64 y.re y.im))) (hypot.f64 y.re y.im)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= associate-*r/_binary64 (*.f64 (/.f64 (*.f64 x.im y.re) (hypot.f64 y.re y.im)) (/.f64 1 (hypot.f64 y.re y.im)))) (neg.f64 (/.f64 (*.f64 y.im (/.f64 x.re (hypot.f64 y.re y.im))) (hypot.f64 y.re y.im)))): 17 points increase in error, 5 points decrease in error
    (+.f64 (*.f64 (/.f64 (*.f64 x.im y.re) (hypot.f64 y.re y.im)) (/.f64 1 (hypot.f64 y.re y.im))) (Rewrite=> distribute-neg-frac_binary64 (/.f64 (neg.f64 (*.f64 y.im (/.f64 x.re (hypot.f64 y.re y.im)))) (hypot.f64 y.re y.im)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (/.f64 (*.f64 x.im y.re) (hypot.f64 y.re y.im)) (/.f64 1 (hypot.f64 y.re y.im))) (/.f64 (Rewrite<= distribute-lft-neg-out_binary64 (*.f64 (neg.f64 y.im) (/.f64 x.re (hypot.f64 y.re y.im)))) (hypot.f64 y.re y.im))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (/.f64 (*.f64 x.im y.re) (hypot.f64 y.re y.im)) (/.f64 1 (hypot.f64 y.re y.im))) (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 x.re (hypot.f64 y.re y.im)) (neg.f64 y.im))) (hypot.f64 y.re y.im))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (/.f64 (*.f64 x.im y.re) (hypot.f64 y.re y.im)) (/.f64 1 (hypot.f64 y.re y.im))) (/.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 (*.f64 (/.f64 x.re (hypot.f64 y.re y.im)) (neg.f64 y.im)) 1)) (hypot.f64 y.re y.im))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (/.f64 (*.f64 x.im y.re) (hypot.f64 y.re y.im)) (/.f64 1 (hypot.f64 y.re y.im))) (Rewrite<= associate-*r/_binary64 (*.f64 (*.f64 (/.f64 x.re (hypot.f64 y.re y.im)) (neg.f64 y.im)) (/.f64 1 (hypot.f64 y.re y.im))))): 18 points increase in error, 8 points decrease in error
  7. Applied egg-rr0.4

    \[\leadsto \frac{x.im \cdot \frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - \color{blue}{\left(0 + \frac{y.im}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot x.re\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} \]
  8. Simplified0.8

    \[\leadsto \frac{x.im \cdot \frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - \color{blue}{y.im \cdot \frac{x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}}{\mathsf{hypot}\left(y.re, y.im\right)} \]
    Proof
    (*.f64 y.im (/.f64 x.re (hypot.f64 y.im y.re))): 0 points increase in error, 0 points decrease in error
    (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y.im x.re) (hypot.f64 y.im y.re))): 76 points increase in error, 34 points decrease in error
    (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 y.im (hypot.f64 y.im y.re)) x.re)): 30 points increase in error, 58 points decrease in error
    (Rewrite<= +-lft-identity_binary64 (+.f64 0 (*.f64 (/.f64 y.im (hypot.f64 y.im y.re)) x.re))): 0 points increase in error, 0 points decrease in error
  9. Final simplification0.8

    \[\leadsto \frac{x.im \cdot \frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - y.im \cdot \frac{x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} \]

Alternatives

Alternative 1
Error16.9
Cost13632
\[\frac{\frac{x.im \cdot y.re - y.im \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} \]
Alternative 2
Error25.9
Cost13504
\[\left(x.im \cdot y.re - y.im \cdot x.re\right) \cdot {\left(\mathsf{hypot}\left(y.re, y.im\right)\right)}^{-2} \]
Alternative 3
Error26.3
Cost7232
\[\frac{x.im \cdot y.re - y.im \cdot x.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \]
Alternative 4
Error26.3
Cost960
\[\frac{x.im \cdot y.re - y.im \cdot x.re}{y.re \cdot y.re + y.im \cdot y.im} \]

Error

Reproduce

herbie shell --seed 2022334 
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, imaginary part"
  :precision binary64
  (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))