Average Error: 25.9 → 10.2
Time: 13.8s
Precision: binary64
Cost: 21960
\[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
\[\begin{array}{l} t_0 := \frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{x.im}{y.re} \cdot \frac{y.im}{y.re}\\ \mathbf{elif}\;t_0 \leq 4 \cdot 10^{+266}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{\frac{y.im}{\frac{y.re}{x.im}}}{y.re}\\ \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0
         (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im)))))
   (if (<= t_0 (- INFINITY))
     (+ (/ x.re y.re) (* (/ x.im y.re) (/ y.im y.re)))
     (if (<= t_0 4e+266)
       (/
        (/ (fma x.re y.re (* x.im y.im)) (hypot y.re y.im))
        (hypot y.re y.im))
       (+ (/ x.re y.re) (/ (/ y.im (/ y.re x.im)) y.re))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return ((x_46_re * y_46_re) + (x_46_im * 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) {
	double t_0 = ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = (x_46_re / y_46_re) + ((x_46_im / y_46_re) * (y_46_im / y_46_re));
	} else if (t_0 <= 4e+266) {
		tmp = (fma(x_46_re, y_46_re, (x_46_im * y_46_im)) / hypot(y_46_re, y_46_im)) / hypot(y_46_re, y_46_im);
	} else {
		tmp = (x_46_re / y_46_re) + ((y_46_im / (y_46_re / x_46_im)) / y_46_re);
	}
	return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * 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)
	t_0 = Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im)))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(x_46_re / y_46_re) + Float64(Float64(x_46_im / y_46_re) * Float64(y_46_im / y_46_re)));
	elseif (t_0 <= 4e+266)
		tmp = Float64(Float64(fma(x_46_re, y_46_re, Float64(x_46_im * y_46_im)) / hypot(y_46_re, y_46_im)) / hypot(y_46_re, y_46_im));
	else
		tmp = Float64(Float64(x_46_re / y_46_re) + Float64(Float64(y_46_im / Float64(y_46_re / x_46_im)) / y_46_re));
	end
	return tmp
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * 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_] := Block[{t$95$0 = N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(x$46$re / y$46$re), $MachinePrecision] + N[(N[(x$46$im / y$46$re), $MachinePrecision] * N[(y$46$im / y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 4e+266], N[(N[(N[(x$46$re * y$46$re + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(x$46$re / y$46$re), $MachinePrecision] + N[(N[(y$46$im / N[(y$46$re / x$46$im), $MachinePrecision]), $MachinePrecision] / y$46$re), $MachinePrecision]), $MachinePrecision]]]]
\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\begin{array}{l}
t_0 := \frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;\frac{x.re}{y.re} + \frac{x.im}{y.re} \cdot \frac{y.im}{y.re}\\

\mathbf{elif}\;t_0 \leq 4 \cdot 10^{+266}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{x.re}{y.re} + \frac{\frac{y.im}{\frac{y.re}{x.im}}}{y.re}\\


\end{array}

Error

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (+.f64 (*.f64 x.re y.re) (*.f64 x.im y.im)) (+.f64 (*.f64 y.re y.re) (*.f64 y.im y.im))) < -inf.0

    1. Initial program 64.0

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in y.re around inf 45.7

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{y.im \cdot x.im}{{y.re}^{2}}} \]
    3. Simplified33.2

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im}{y.re} \cdot \frac{y.im}{y.re}} \]
      Proof

      [Start]45.7

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

      *-commutative [<=]45.7

      \[ \frac{x.re}{y.re} + \frac{\color{blue}{x.im \cdot y.im}}{{y.re}^{2}} \]

      unpow2 [=>]45.7

      \[ \frac{x.re}{y.re} + \frac{x.im \cdot y.im}{\color{blue}{y.re \cdot y.re}} \]

      times-frac [=>]33.2

      \[ \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{y.re} \cdot \frac{y.im}{y.re}} \]

    if -inf.0 < (/.f64 (+.f64 (*.f64 x.re y.re) (*.f64 x.im y.im)) (+.f64 (*.f64 y.re y.re) (*.f64 y.im y.im))) < 4.0000000000000001e266

    1. Initial program 11.3

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

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

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

    if 4.0000000000000001e266 < (/.f64 (+.f64 (*.f64 x.re y.re) (*.f64 x.im y.im)) (+.f64 (*.f64 y.re y.re) (*.f64 y.im y.im)))

    1. Initial program 60.9

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in y.re around inf 40.5

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{y.im \cdot x.im}{{y.re}^{2}}} \]
    3. Simplified38.6

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{y.im}{\frac{y.re \cdot y.re}{x.im}}} \]
      Proof

      [Start]40.5

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

      associate-/l* [=>]38.6

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

      unpow2 [=>]38.6

      \[ \frac{x.re}{y.re} + \frac{y.im}{\frac{\color{blue}{y.re \cdot y.re}}{x.im}} \]
    4. Applied egg-rr38.6

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{y.re \cdot y.re} \cdot y.im} \]
    5. Applied egg-rr32.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \leq -\infty:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{x.im}{y.re} \cdot \frac{y.im}{y.re}\\ \mathbf{elif}\;\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \leq 4 \cdot 10^{+266}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{\frac{y.im}{\frac{y.re}{x.im}}}{y.re}\\ \end{array} \]

Alternatives

Alternative 1
Error13.3
Cost1488
\[\begin{array}{l} t_0 := \frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{if}\;y.re \leq -2.3 \cdot 10^{+44}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{y.im}{y.re \cdot \frac{y.re}{x.im}}\\ \mathbf{elif}\;y.re \leq -2.35 \cdot 10^{-47}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y.re \leq 2.05 \cdot 10^{-161}:\\ \;\;\;\;\frac{x.im}{y.im} + \frac{y.re}{y.im} \cdot \frac{x.re}{y.im}\\ \mathbf{elif}\;y.re \leq 2.3 \cdot 10^{+43}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{\frac{y.im}{\frac{y.re}{x.im}}}{y.re}\\ \end{array} \]
Alternative 2
Error15.9
Cost1234
\[\begin{array}{l} \mathbf{if}\;y.re \leq -9.8 \cdot 10^{+27} \lor \neg \left(y.re \leq -1 \cdot 10^{-14} \lor \neg \left(y.re \leq -3.4 \cdot 10^{-47}\right) \land y.re \leq 1.35 \cdot 10^{-18}\right):\\ \;\;\;\;\frac{1}{y.re} \cdot \left(x.re + y.im \cdot \frac{x.im}{y.re}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{y.im} + \frac{y.re}{y.im} \cdot \frac{x.re}{y.im}\\ \end{array} \]
Alternative 3
Error15.9
Cost1233
\[\begin{array}{l} t_0 := \frac{1}{y.re} \cdot \left(x.re + y.im \cdot \frac{x.im}{y.re}\right)\\ \mathbf{if}\;y.re \leq -6.5 \cdot 10^{+27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y.re \leq -8 \cdot 10^{-10}:\\ \;\;\;\;\frac{x.im}{y.im} + \frac{y.re}{y.im} \cdot \frac{x.re}{y.im}\\ \mathbf{elif}\;y.re \leq -1.2 \cdot 10^{-46} \lor \neg \left(y.re \leq 1.3 \cdot 10^{-18}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{y.im} + \frac{\frac{x.re}{y.im}}{\frac{y.im}{y.re}}\\ \end{array} \]
Alternative 4
Error20.5
Cost1232
\[\begin{array}{l} t_0 := \frac{1}{y.re} \cdot \left(x.re + y.im \cdot \frac{x.im}{y.re}\right)\\ \mathbf{if}\;y.im \leq -4 \cdot 10^{+88}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{elif}\;y.im \leq -6.5 \cdot 10^{+23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y.im \leq -8 \cdot 10^{-33}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{elif}\;y.im \leq 0.245:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y.im \leq 2.4 \cdot 10^{+89}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{elif}\;y.im \leq 2.4 \cdot 10^{+114}:\\ \;\;\;\;\frac{x.re}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \end{array} \]
Alternative 5
Error15.9
Cost1232
\[\begin{array}{l} t_0 := \frac{1}{y.re} \cdot \left(x.re + y.im \cdot \frac{x.im}{y.re}\right)\\ \mathbf{if}\;y.re \leq -1.45 \cdot 10^{+28}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y.re \leq -3.5 \cdot 10^{-8}:\\ \;\;\;\;\frac{x.im}{y.im} + \frac{y.re}{y.im} \cdot \frac{x.re}{y.im}\\ \mathbf{elif}\;y.re \leq -3.7 \cdot 10^{-45}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{x.im}{y.re} \cdot \frac{y.im}{y.re}\\ \mathbf{elif}\;y.re \leq 4.2 \cdot 10^{-25}:\\ \;\;\;\;\frac{x.im}{y.im} + \frac{\frac{x.re}{y.im}}{\frac{y.im}{y.re}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error15.9
Cost1232
\[\begin{array}{l} t_0 := \frac{1}{y.re} \cdot \left(x.re + y.im \cdot \frac{x.im}{y.re}\right)\\ \mathbf{if}\;y.re \leq -6.8 \cdot 10^{+30}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y.re \leq -1.75 \cdot 10^{-9}:\\ \;\;\;\;\frac{x.im}{y.im} + \frac{y.re}{y.im} \cdot \frac{x.re}{y.im}\\ \mathbf{elif}\;y.re \leq -3.7 \cdot 10^{-45}:\\ \;\;\;\;\frac{x.re}{y.re} + x.im \cdot \frac{y.im}{y.re \cdot y.re}\\ \mathbf{elif}\;y.re \leq 6 \cdot 10^{-14}:\\ \;\;\;\;\frac{x.im}{y.im} + \frac{\frac{x.re}{y.im}}{\frac{y.im}{y.re}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error16.1
Cost1232
\[\begin{array}{l} \mathbf{if}\;y.re \leq -5.1 \cdot 10^{+29}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{y.im}{y.re \cdot \frac{y.re}{x.im}}\\ \mathbf{elif}\;y.re \leq -4.1 \cdot 10^{-13}:\\ \;\;\;\;\frac{x.im}{y.im} + \frac{y.re}{y.im} \cdot \frac{x.re}{y.im}\\ \mathbf{elif}\;y.re \leq -3.7 \cdot 10^{-45}:\\ \;\;\;\;\frac{x.re}{y.re} + x.im \cdot \frac{y.im}{y.re \cdot y.re}\\ \mathbf{elif}\;y.re \leq 4 \cdot 10^{-24}:\\ \;\;\;\;\frac{x.im}{y.im} + \frac{\frac{x.re}{y.im}}{\frac{y.im}{y.re}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y.re} \cdot \left(x.re + y.im \cdot \frac{x.im}{y.re}\right)\\ \end{array} \]
Alternative 8
Error16.0
Cost1232
\[\begin{array}{l} \mathbf{if}\;y.re \leq -5.5 \cdot 10^{+29}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{y.im}{y.re \cdot \frac{y.re}{x.im}}\\ \mathbf{elif}\;y.re \leq -1.4 \cdot 10^{-9}:\\ \;\;\;\;\frac{x.im}{y.im} + \frac{y.re}{y.im} \cdot \frac{x.re}{y.im}\\ \mathbf{elif}\;y.re \leq -6.5 \cdot 10^{-46}:\\ \;\;\;\;\frac{x.re}{y.re} + x.im \cdot \frac{y.im}{y.re \cdot y.re}\\ \mathbf{elif}\;y.re \leq 1.4 \cdot 10^{-18}:\\ \;\;\;\;\frac{x.im}{y.im} + \frac{\frac{x.re}{y.im}}{\frac{y.im}{y.re}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{\frac{y.im}{\frac{y.re}{x.im}}}{y.re}\\ \end{array} \]
Alternative 9
Error23.0
Cost721
\[\begin{array}{l} \mathbf{if}\;y.re \leq -1.5 \cdot 10^{+24}:\\ \;\;\;\;\frac{x.re}{y.re}\\ \mathbf{elif}\;y.re \leq -3.8 \cdot 10^{-6} \lor \neg \left(y.re \leq -1.25 \cdot 10^{-45}\right) \land y.re \leq 1.55 \cdot 10^{-14}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{y.re}\\ \end{array} \]
Alternative 10
Error37.2
Cost192
\[\frac{x.im}{y.im} \]

Error

Reproduce

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