?

Average Accuracy: 58.3% → 89.2%
Time: 21.3s
Precision: binary64
Cost: 66640

?

\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
\[\begin{array}{l} t_0 := a \cdot \left(d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}\right)\\ t_1 := \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\ t_2 := \sqrt[3]{\frac{c}{\mathsf{hypot}\left(d, c\right)}}\\ t_3 := 0 \cdot t_0 + \left({t_2}^{2} \cdot \left(t_2 \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\right) - t_0\right)\\ \mathbf{if}\;d \leq -1 \cdot 10^{+182}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 1.55 \cdot 10^{-279}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{-103}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 2.05 \cdot 10^{+133}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (* a (* d (pow (hypot d c) -2.0))))
        (t_1 (fma (/ c (hypot c d)) (/ b (hypot c d)) (/ (- a) d)))
        (t_2 (cbrt (/ c (hypot d c))))
        (t_3
         (+ (* 0.0 t_0) (- (* (pow t_2 2.0) (* t_2 (/ b (hypot d c)))) t_0))))
   (if (<= d -1e+182)
     t_1
     (if (<= d 1.55e-279)
       t_3
       (if (<= d 1.7e-103)
         (* (/ 1.0 (hypot c d)) (/ (- (* c b) (* d a)) (hypot c d)))
         (if (<= d 2.05e+133) t_3 t_1))))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
double code(double a, double b, double c, double d) {
	double t_0 = a * (d * pow(hypot(d, c), -2.0));
	double t_1 = fma((c / hypot(c, d)), (b / hypot(c, d)), (-a / d));
	double t_2 = cbrt((c / hypot(d, c)));
	double t_3 = (0.0 * t_0) + ((pow(t_2, 2.0) * (t_2 * (b / hypot(d, c)))) - t_0);
	double tmp;
	if (d <= -1e+182) {
		tmp = t_1;
	} else if (d <= 1.55e-279) {
		tmp = t_3;
	} else if (d <= 1.7e-103) {
		tmp = (1.0 / hypot(c, d)) * (((c * b) - (d * a)) / hypot(c, d));
	} else if (d <= 2.05e+133) {
		tmp = t_3;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(a, b, c, d)
	return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function code(a, b, c, d)
	t_0 = Float64(a * Float64(d * (hypot(d, c) ^ -2.0)))
	t_1 = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(Float64(-a) / d))
	t_2 = cbrt(Float64(c / hypot(d, c)))
	t_3 = Float64(Float64(0.0 * t_0) + Float64(Float64((t_2 ^ 2.0) * Float64(t_2 * Float64(b / hypot(d, c)))) - t_0))
	tmp = 0.0
	if (d <= -1e+182)
		tmp = t_1;
	elseif (d <= 1.55e-279)
		tmp = t_3;
	elseif (d <= 1.7e-103)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(Float64(Float64(c * b) - Float64(d * a)) / hypot(c, d)));
	elseif (d <= 2.05e+133)
		tmp = t_3;
	else
		tmp = t_1;
	end
	return tmp
end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a * N[(d * N[Power[N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[((-a) / d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[(c / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$3 = N[(N[(0.0 * t$95$0), $MachinePrecision] + N[(N[(N[Power[t$95$2, 2.0], $MachinePrecision] * N[(t$95$2 * N[(b / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1e+182], t$95$1, If[LessEqual[d, 1.55e-279], t$95$3, If[LessEqual[d, 1.7e-103], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.05e+133], t$95$3, t$95$1]]]]]]]]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := a \cdot \left(d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}\right)\\
t_1 := \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\
t_2 := \sqrt[3]{\frac{c}{\mathsf{hypot}\left(d, c\right)}}\\
t_3 := 0 \cdot t_0 + \left({t_2}^{2} \cdot \left(t_2 \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\right) - t_0\right)\\
\mathbf{if}\;d \leq -1 \cdot 10^{+182}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d \leq 1.55 \cdot 10^{-279}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;d \leq 1.7 \cdot 10^{-103}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;d \leq 2.05 \cdot 10^{+133}:\\
\;\;\;\;t_3\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error?

Target

Original58.3%
Target99.3%
Herbie89.2%
\[\begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if d < -1.0000000000000001e182 or 2.05000000000000002e133 < d

    1. Initial program 32.6%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Simplified32.6%

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      Proof

      [Start]32.6

      \[ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]

      fma-def [=>]32.6

      \[ \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Applied egg-rr46.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)} \]
      Proof

      [Start]32.6

      \[ \frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \]

      div-sub [=>]32.6

      \[ \color{blue}{\frac{b \cdot c}{\mathsf{fma}\left(c, c, d \cdot d\right)} - \frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]

      *-commutative [=>]32.6

      \[ \frac{\color{blue}{c \cdot b}}{\mathsf{fma}\left(c, c, d \cdot d\right)} - \frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \]

      add-sqr-sqrt [=>]32.6

      \[ \frac{c \cdot b}{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}} - \frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \]

      times-frac [=>]33.0

      \[ \color{blue}{\frac{c}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \cdot \frac{b}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}} - \frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \]

      fma-neg [=>]33.0

      \[ \color{blue}{\mathsf{fma}\left(\frac{c}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}, \frac{b}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}, -\frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right)} \]

      fma-udef [=>]33.0

      \[ \mathsf{fma}\left(\frac{c}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}}, \frac{b}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}, -\frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right) \]

      hypot-def [=>]33.0

      \[ \mathsf{fma}\left(\frac{c}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, \frac{b}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}, -\frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right) \]

      fma-udef [=>]33.0

      \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}}, -\frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right) \]

      hypot-def [=>]46.5

      \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right) \]

      add-sqr-sqrt [=>]46.5

      \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}}\right) \]

      pow2 [=>]46.5

      \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a \cdot d}{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}\right)}^{2}}}\right) \]

      fma-udef [=>]46.5

      \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a \cdot d}{{\left(\sqrt{\color{blue}{c \cdot c + d \cdot d}}\right)}^{2}}\right) \]

      hypot-def [=>]46.5

      \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a \cdot d}{{\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}}\right) \]
    4. Taylor expanded in d around inf 93.2%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{\frac{a}{d}}\right) \]

    if -1.0000000000000001e182 < d < 1.55e-279 or 1.70000000000000001e-103 < d < 2.05000000000000002e133

    1. Initial program 68.3%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Simplified68.3%

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      Proof

      [Start]68.3

      \[ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]

      fma-def [=>]68.3

      \[ \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Applied egg-rr85.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)} \]
      Proof

      [Start]68.3

      \[ \frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \]

      div-sub [=>]68.3

      \[ \color{blue}{\frac{b \cdot c}{\mathsf{fma}\left(c, c, d \cdot d\right)} - \frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]

      *-commutative [=>]68.3

      \[ \frac{\color{blue}{c \cdot b}}{\mathsf{fma}\left(c, c, d \cdot d\right)} - \frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \]

      add-sqr-sqrt [=>]68.3

      \[ \frac{c \cdot b}{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}} - \frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \]

      times-frac [=>]70.8

      \[ \color{blue}{\frac{c}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \cdot \frac{b}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}} - \frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \]

      fma-neg [=>]70.8

      \[ \color{blue}{\mathsf{fma}\left(\frac{c}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}, \frac{b}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}, -\frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right)} \]

      fma-udef [=>]70.8

      \[ \mathsf{fma}\left(\frac{c}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}}, \frac{b}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}, -\frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right) \]

      hypot-def [=>]70.8

      \[ \mathsf{fma}\left(\frac{c}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, \frac{b}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}, -\frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right) \]

      fma-udef [=>]70.8

      \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}}, -\frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right) \]

      hypot-def [=>]85.8

      \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right) \]

      add-sqr-sqrt [=>]85.8

      \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}}\right) \]

      pow2 [=>]85.8

      \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a \cdot d}{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}\right)}^{2}}}\right) \]

      fma-udef [=>]85.8

      \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a \cdot d}{{\left(\sqrt{\color{blue}{c \cdot c + d \cdot d}}\right)}^{2}}\right) \]

      hypot-def [=>]85.8

      \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a \cdot d}{{\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}}\right) \]
    4. Applied egg-rr89.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left({\left(\sqrt[3]{\frac{c}{\mathsf{hypot}\left(d, c\right)}}\right)}^{2}, \sqrt[3]{\frac{c}{\mathsf{hypot}\left(d, c\right)}} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}, -\left(d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}\right) \cdot a\right) + \mathsf{fma}\left(-d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}, a, \left(d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}\right) \cdot a\right)} \]
      Proof

      [Start]85.8

      \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right) \]

      fma-neg [<=]85.8

      \[ \color{blue}{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - \frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]

      div-inv [=>]85.6

      \[ \frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - \color{blue}{\left(a \cdot d\right) \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]

      add-cube-cbrt [=>]85.4

      \[ \color{blue}{\left(\left(\sqrt[3]{\frac{c}{\mathsf{hypot}\left(c, d\right)}} \cdot \sqrt[3]{\frac{c}{\mathsf{hypot}\left(c, d\right)}}\right) \cdot \sqrt[3]{\frac{c}{\mathsf{hypot}\left(c, d\right)}}\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - \left(a \cdot d\right) \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]

      associate-*l* [=>]85.4

      \[ \color{blue}{\left(\sqrt[3]{\frac{c}{\mathsf{hypot}\left(c, d\right)}} \cdot \sqrt[3]{\frac{c}{\mathsf{hypot}\left(c, d\right)}}\right) \cdot \left(\sqrt[3]{\frac{c}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\right)} - \left(a \cdot d\right) \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]

      associate-*l* [=>]89.2

      \[ \left(\sqrt[3]{\frac{c}{\mathsf{hypot}\left(c, d\right)}} \cdot \sqrt[3]{\frac{c}{\mathsf{hypot}\left(c, d\right)}}\right) \cdot \left(\sqrt[3]{\frac{c}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\right) - \color{blue}{a \cdot \left(d \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)} \]

      prod-diff [=>]89.2

      \[ \color{blue}{\mathsf{fma}\left(\sqrt[3]{\frac{c}{\mathsf{hypot}\left(c, d\right)}} \cdot \sqrt[3]{\frac{c}{\mathsf{hypot}\left(c, d\right)}}, \sqrt[3]{\frac{c}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\left(d \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right) \cdot a\right) + \mathsf{fma}\left(-d \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}, a, \left(d \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right) \cdot a\right)} \]
    5. Simplified89.7%

      \[\leadsto \color{blue}{0 \cdot \left(a \cdot \left(d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}\right)\right) + \left({\left(\sqrt[3]{\frac{c}{\mathsf{hypot}\left(d, c\right)}}\right)}^{2} \cdot \left(\frac{b}{\mathsf{hypot}\left(d, c\right)} \cdot \sqrt[3]{\frac{c}{\mathsf{hypot}\left(d, c\right)}}\right) - a \cdot \left(d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}\right)\right)} \]
      Proof

      [Start]89.7

      \[ \mathsf{fma}\left({\left(\sqrt[3]{\frac{c}{\mathsf{hypot}\left(d, c\right)}}\right)}^{2}, \sqrt[3]{\frac{c}{\mathsf{hypot}\left(d, c\right)}} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}, -\left(d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}\right) \cdot a\right) + \mathsf{fma}\left(-d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}, a, \left(d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}\right) \cdot a\right) \]

      +-commutative [=>]89.7

      \[ \color{blue}{\mathsf{fma}\left(-d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}, a, \left(d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}\right) \cdot a\right) + \mathsf{fma}\left({\left(\sqrt[3]{\frac{c}{\mathsf{hypot}\left(d, c\right)}}\right)}^{2}, \sqrt[3]{\frac{c}{\mathsf{hypot}\left(d, c\right)}} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}, -\left(d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}\right) \cdot a\right)} \]

    if 1.55e-279 < d < 1.70000000000000001e-103

    1. Initial program 64.3%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Applied egg-rr78.6%

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}} \]
      Proof

      [Start]64.3

      \[ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]

      *-un-lft-identity [=>]64.3

      \[ \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]

      add-sqr-sqrt [=>]64.3

      \[ \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]

      times-frac [=>]64.3

      \[ \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]

      hypot-def [=>]64.3

      \[ \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]

      hypot-def [=>]78.6

      \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification89.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1 \cdot 10^{+182}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\ \mathbf{elif}\;d \leq 1.55 \cdot 10^{-279}:\\ \;\;\;\;0 \cdot \left(a \cdot \left(d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}\right)\right) + \left({\left(\sqrt[3]{\frac{c}{\mathsf{hypot}\left(d, c\right)}}\right)}^{2} \cdot \left(\sqrt[3]{\frac{c}{\mathsf{hypot}\left(d, c\right)}} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\right) - a \cdot \left(d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}\right)\right)\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{-103}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 2.05 \cdot 10^{+133}:\\ \;\;\;\;0 \cdot \left(a \cdot \left(d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}\right)\right) + \left({\left(\sqrt[3]{\frac{c}{\mathsf{hypot}\left(d, c\right)}}\right)}^{2} \cdot \left(\sqrt[3]{\frac{c}{\mathsf{hypot}\left(d, c\right)}} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\right) - a \cdot \left(d \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy88.5%
Cost33552
\[\begin{array}{l} t_0 := \frac{c}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ t_2 := \mathsf{fma}\left(t_0, t_1, \frac{d \cdot \left(-a\right)}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\ t_3 := \mathsf{fma}\left(t_0, t_1, \frac{-a}{d}\right)\\ \mathbf{if}\;d \leq -8 \cdot 10^{+85}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;d \leq 6 \cdot 10^{-223}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d \leq 1.15 \cdot 10^{-103}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 10^{+84}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 2
Accuracy90.6%
Cost27344
\[\begin{array}{l} t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\ t_1 := \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\ \mathbf{if}\;d \leq -4.2 \cdot 10^{+97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -2.6 \cdot 10^{-149}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{-138}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 4.3 \cdot 10^{+132}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Accuracy86.7%
Cost20496
\[\begin{array}{l} t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\ \mathbf{if}\;d \leq -2.75 \cdot 10^{+82}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -1.55 \cdot 10^{-157}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 5.2 \cdot 10^{-218}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 2.8 \cdot 10^{+82}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Accuracy84.7%
Cost14288
\[\begin{array}{l} t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := \frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\ \mathbf{if}\;c \leq -1.02 \cdot 10^{+130}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -7.2 \cdot 10^{-227}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 7.2 \cdot 10^{-150}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 6.9 \cdot 10^{+81}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Accuracy81.0%
Cost1752
\[\begin{array}{l} t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ t_1 := \frac{b - a \cdot \frac{d}{c}}{c}\\ t_2 := \frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{if}\;d \leq -4.3 \cdot 10^{+153}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d \leq -1.45 \cdot 10^{+133}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -1.1 \cdot 10^{+84}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -1.05 \cdot 10^{-91}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 5.3 \cdot 10^{-58}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 1.1 \cdot 10^{+88}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Accuracy74.5%
Cost1371
\[\begin{array}{l} \mathbf{if}\;d \leq -4.3 \cdot 10^{+153} \lor \neg \left(d \leq -9.5 \cdot 10^{+132}\right) \land \left(d \leq -6.2 \cdot 10^{-65} \lor \neg \left(d \leq 6.6 \cdot 10^{-58}\right) \land \left(d \leq 6500 \lor \neg \left(d \leq 1.95 \cdot 10^{+45}\right)\right)\right):\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \end{array} \]
Alternative 7
Accuracy74.5%
Cost1369
\[\begin{array}{l} t_0 := \frac{b - a \cdot \frac{d}{c}}{c}\\ t_1 := \frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{if}\;d \leq -4.3 \cdot 10^{+153}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -1.45 \cdot 10^{+133}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -6.2 \cdot 10^{-65}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;d \leq 6.6 \cdot 10^{-58} \lor \neg \left(d \leq 2800\right) \land d \leq 1.9 \cdot 10^{+45}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Accuracy74.4%
Cost1368
\[\begin{array}{l} t_0 := \frac{b - a \cdot \frac{d}{c}}{c}\\ t_1 := \frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{if}\;d \leq -9.4 \cdot 10^{+154}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -1.4 \cdot 10^{+133}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -6.2 \cdot 10^{-65}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{-58}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 2800:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{+45}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \end{array} \]
Alternative 9
Accuracy74.5%
Cost1368
\[\begin{array}{l} t_0 := \frac{b - a \cdot \frac{d}{c}}{c}\\ t_1 := \frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{if}\;d \leq -4.3 \cdot 10^{+153}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -1.45 \cdot 10^{+133}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -6.2 \cdot 10^{-65}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 6.6 \cdot 10^{-58}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 11500:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 2.2 \cdot 10^{+45}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \end{array} \]
Alternative 10
Accuracy74.3%
Cost1368
\[\begin{array}{l} t_0 := \frac{b - a \cdot \frac{d}{c}}{c}\\ t_1 := \frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{if}\;d \leq -4.3 \cdot 10^{+153}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -3.25 \cdot 10^{+131}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -6.2 \cdot 10^{-65}:\\ \;\;\;\;b \cdot \frac{\frac{c}{d}}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 6.6 \cdot 10^{-58}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 51000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 2.65 \cdot 10^{+45}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \end{array} \]
Alternative 11
Accuracy75.4%
Cost1234
\[\begin{array}{l} \mathbf{if}\;c \leq -8.5 \cdot 10^{+90} \lor \neg \left(c \leq -4.1 \cdot 10^{+52} \lor \neg \left(c \leq -2.15 \cdot 10^{-29}\right) \land c \leq 1.6 \cdot 10^{+81}\right):\\ \;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \end{array} \]
Alternative 12
Accuracy75.4%
Cost1232
\[\begin{array}{l} t_0 := \frac{b \cdot \frac{c}{d} - a}{d}\\ t_1 := \frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\ \mathbf{if}\;c \leq -4.8 \cdot 10^{+91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -4.5 \cdot 10^{+54}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -2.7 \cdot 10^{-29}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;c \leq 1.28 \cdot 10^{+81}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 13
Accuracy75.1%
Cost1232
\[\begin{array}{l} t_0 := \frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{if}\;c \leq -2.5 \cdot 10^{+91}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c \cdot \frac{c}{a}}\\ \mathbf{elif}\;c \leq -2.1 \cdot 10^{+53}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -2.7 \cdot 10^{-29}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;c \leq 1.9 \cdot 10^{+81}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\ \end{array} \]
Alternative 14
Accuracy74.9%
Cost1232
\[\begin{array}{l} t_0 := \frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{if}\;c \leq -6.8 \cdot 10^{+90}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c \cdot \frac{c}{a}}\\ \mathbf{elif}\;c \leq -4.4 \cdot 10^{+58}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -0.003:\\ \;\;\;\;\frac{c \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.3 \cdot 10^{+81}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\ \end{array} \]
Alternative 15
Accuracy69.4%
Cost841
\[\begin{array}{l} \mathbf{if}\;d \leq -5.3 \cdot 10^{+153} \lor \neg \left(d \leq 1.6 \cdot 10^{+45}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \end{array} \]
Alternative 16
Accuracy63.8%
Cost520
\[\begin{array}{l} \mathbf{if}\;c \leq -0.00145:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 1.9 \cdot 10^{+81}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 17
Accuracy46.0%
Cost457
\[\begin{array}{l} \mathbf{if}\;d \leq -1.05 \cdot 10^{+182} \lor \neg \left(d \leq 1.95 \cdot 10^{+140}\right):\\ \;\;\;\;\frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 18
Accuracy13.9%
Cost456
\[\begin{array}{l} \mathbf{if}\;d \leq -1 \cdot 10^{+182}:\\ \;\;\;\;\frac{a}{d}\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{+25}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{d}\\ \end{array} \]
Alternative 19
Accuracy8.3%
Cost192
\[\frac{a}{c} \]

Error

Reproduce?

herbie shell --seed 2023151 
(FPCore (a b c d)
  :name "Complex division, imag part"
  :precision binary64

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))

  (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))