Complex division, imag part

?

Percentage Accurate: 61.5% → 95.0%
Time: 16.8s
Precision: binary64
Cost: 46476

?

\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
\[\begin{array}{l} t_0 := \frac{c}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;d \leq -1.3 \cdot 10^{+154}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -1 \cdot 10^{-180}:\\ \;\;\;\;\mathsf{fma}\left(t_0, t_1, \frac{-a}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}\right)\\ \mathbf{elif}\;d \leq 2 \cdot 10^{-251}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t_0, t_1, \frac{\sqrt{d} \cdot \frac{-a}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}}\right)\\ \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 (/ c (hypot c d))) (t_1 (/ b (hypot c d))))
   (if (<= d -1.3e+154)
     (- (* (/ c d) (/ b d)) (/ a d))
     (if (<= d -1e-180)
       (fma t_0 t_1 (/ (- a) (/ (pow (hypot c d) 2.0) d)))
       (if (<= d 2e-251)
         (/ (- b (/ a (/ c d))) c)
         (fma
          t_0
          t_1
          (/ (* (sqrt d) (/ (- a) (hypot c d))) (/ (hypot c d) (sqrt d)))))))))
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 = c / hypot(c, d);
	double t_1 = b / hypot(c, d);
	double tmp;
	if (d <= -1.3e+154) {
		tmp = ((c / d) * (b / d)) - (a / d);
	} else if (d <= -1e-180) {
		tmp = fma(t_0, t_1, (-a / (pow(hypot(c, d), 2.0) / d)));
	} else if (d <= 2e-251) {
		tmp = (b - (a / (c / d))) / c;
	} else {
		tmp = fma(t_0, t_1, ((sqrt(d) * (-a / hypot(c, d))) / (hypot(c, d) / sqrt(d))));
	}
	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(c / hypot(c, d))
	t_1 = Float64(b / hypot(c, d))
	tmp = 0.0
	if (d <= -1.3e+154)
		tmp = Float64(Float64(Float64(c / d) * Float64(b / d)) - Float64(a / d));
	elseif (d <= -1e-180)
		tmp = fma(t_0, t_1, Float64(Float64(-a) / Float64((hypot(c, d) ^ 2.0) / d)));
	elseif (d <= 2e-251)
		tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c);
	else
		tmp = fma(t_0, t_1, Float64(Float64(sqrt(d) * Float64(Float64(-a) / hypot(c, d))) / Float64(hypot(c, d) / sqrt(d))));
	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[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.3e+154], N[(N[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1e-180], N[(t$95$0 * t$95$1 + N[((-a) / N[(N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2e-251], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(t$95$0 * t$95$1 + N[(N[(N[Sqrt[d], $MachinePrecision] * N[((-a) / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / N[Sqrt[d], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{c}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;d \leq -1.3 \cdot 10^{+154}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\

\mathbf{elif}\;d \leq -1 \cdot 10^{-180}:\\
\;\;\;\;\mathsf{fma}\left(t_0, t_1, \frac{-a}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}\right)\\

\mathbf{elif}\;d \leq 2 \cdot 10^{-251}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_0, t_1, \frac{\sqrt{d} \cdot \frac{-a}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}}\right)\\


\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 11 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Target

Original61.5%
Target99.4%
Herbie95.0%
\[\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 4 regimes
  2. if d < -1.29999999999999994e154

    1. Initial program 23.3%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around 0 72.6%

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \frac{c \cdot b}{{d}^{2}}} \]
    3. Simplified83.5%

      \[\leadsto \color{blue}{\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}} \]
      Step-by-step derivation

      [Start]72.6%

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

      +-commutative [=>]72.6%

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

      mul-1-neg [=>]72.6%

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

      unsub-neg [=>]72.6%

      \[ \color{blue}{\frac{c \cdot b}{{d}^{2}} - \frac{a}{d}} \]

      unpow2 [=>]72.6%

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

      times-frac [=>]83.5%

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

    if -1.29999999999999994e154 < d < -1e-180

    1. Initial program 79.3%

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

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

      [Start]79.3%

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

      div-sub [=>]77.8%

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

      *-commutative [=>]77.8%

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

      add-sqr-sqrt [=>]77.8%

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

      times-frac [=>]78.4%

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

      fma-neg [=>]78.4%

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

      hypot-def [=>]78.4%

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

      hypot-def [=>]89.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}{c \cdot c + d \cdot d}\right) \]

      associate-/l* [=>]93.1%

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

      add-sqr-sqrt [=>]93.1%

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

      pow2 [=>]93.1%

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

      hypot-def [=>]93.1%

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

    if -1e-180 < d < 2.00000000000000003e-251

    1. Initial program 65.9%

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

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

      [Start]65.9%

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

      div-sub [=>]60.2%

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

      *-commutative [=>]60.2%

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

      add-sqr-sqrt [=>]60.2%

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

      times-frac [=>]68.2%

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

      fma-neg [=>]68.2%

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

      hypot-def [=>]68.2%

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

      hypot-def [=>]80.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}{c \cdot c + d \cdot d}\right) \]

      associate-/l* [=>]78.2%

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

      add-sqr-sqrt [=>]78.2%

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

      pow2 [=>]78.2%

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

      hypot-def [=>]78.2%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a \cdot d}{{c}^{2}} + \frac{b}{c}} \]
    4. Simplified80.5%

      \[\leadsto \color{blue}{\frac{b}{c} - \frac{d \cdot a}{c \cdot c}} \]
      Step-by-step derivation

      [Start]80.5%

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

      +-commutative [=>]80.5%

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

      mul-1-neg [=>]80.5%

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

      unsub-neg [=>]80.5%

      \[ \color{blue}{\frac{b}{c} - \frac{a \cdot d}{{c}^{2}}} \]

      *-commutative [<=]80.5%

      \[ \frac{b}{c} - \frac{\color{blue}{d \cdot a}}{{c}^{2}} \]

      unpow2 [=>]80.5%

      \[ \frac{b}{c} - \frac{d \cdot a}{\color{blue}{c \cdot c}} \]
    5. Applied egg-rr98.3%

      \[\leadsto \color{blue}{1 \cdot \frac{b - \frac{d \cdot a}{c}}{c}} \]
      Step-by-step derivation

      [Start]80.5%

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

      *-un-lft-identity [=>]80.5%

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

      associate-/r* [=>]98.3%

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

      sub-div [=>]98.3%

      \[ 1 \cdot \color{blue}{\frac{b - \frac{d \cdot a}{c}}{c}} \]
    6. Simplified98.3%

      \[\leadsto \color{blue}{\frac{b - \frac{a}{\frac{c}{d}}}{c}} \]
      Step-by-step derivation

      [Start]98.3%

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

      *-lft-identity [=>]98.3%

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

      *-commutative [<=]98.3%

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

      associate-/l* [=>]98.3%

      \[ \frac{b - \color{blue}{\frac{a}{\frac{c}{d}}}}{c} \]

    if 2.00000000000000003e-251 < d

    1. Initial program 58.5%

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

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

      [Start]58.5%

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

      div-sub [=>]56.8%

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

      *-commutative [=>]56.8%

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

      add-sqr-sqrt [=>]56.7%

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

      times-frac [=>]60.8%

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

      fma-neg [=>]60.8%

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

      hypot-def [=>]60.8%

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

      hypot-def [=>]74.6%

      \[ \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}{c \cdot c + d \cdot d}\right) \]

      associate-/l* [=>]76.9%

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

      add-sqr-sqrt [=>]76.9%

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

      pow2 [=>]76.9%

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

      hypot-def [=>]76.9%

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

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}} \cdot \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}}}\right) \]
      Step-by-step derivation

      [Start]76.9%

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

      *-un-lft-identity [=>]76.9%

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

      add-sqr-sqrt [=>]76.8%

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

      times-frac [=>]76.8%

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

      unpow2 [=>]76.8%

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

      hypot-udef [=>]76.8%

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

      hypot-udef [=>]76.8%

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

      add-sqr-sqrt [<=]76.8%

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

      +-commutative [<=]76.8%

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

      sqrt-div [=>]76.8%

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

      +-commutative [=>]76.8%

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

      hypot-udef [<=]76.8%

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

      unpow2 [=>]76.8%

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

      hypot-udef [=>]76.8%

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

      hypot-udef [=>]76.8%

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

      add-sqr-sqrt [<=]76.8%

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

      +-commutative [<=]76.8%

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

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

      [Start]96.7%

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

      associate-*l/ [=>]96.7%

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

      *-lft-identity [=>]96.7%

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

      associate-/r/ [=>]96.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.3 \cdot 10^{+154}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -1 \cdot 10^{-180}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}\right)\\ \mathbf{elif}\;d \leq 2 \cdot 10^{-251}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{\sqrt{d} \cdot \frac{-a}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}}\right)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy95.0%
Cost46476
\[\begin{array}{l} t_0 := \frac{c}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;d \leq -1.3 \cdot 10^{+154}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -1 \cdot 10^{-180}:\\ \;\;\;\;\mathsf{fma}\left(t_0, t_1, \frac{-a}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}\right)\\ \mathbf{elif}\;d \leq 2 \cdot 10^{-251}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t_0, t_1, \frac{\sqrt{d} \cdot \frac{-a}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}}\right)\\ \end{array} \]
Alternative 2
Accuracy85.2%
Cost14660
\[\begin{array}{l} t_0 := c \cdot b - d \cdot a\\ \mathbf{if}\;\frac{t_0}{c \cdot c + d \cdot d} \leq 10^{+270}:\\ \;\;\;\;\frac{\frac{t_0}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\ \end{array} \]
Alternative 3
Accuracy78.9%
Cost13900
\[\begin{array}{l} \mathbf{if}\;c \leq -1.28 \cdot 10^{-30}:\\ \;\;\;\;\frac{b}{c} - \frac{\frac{d}{c}}{\frac{c}{a}}\\ \mathbf{elif}\;c \leq 5.5 \cdot 10^{-94}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 1.2 \cdot 10^{+66}:\\ \;\;\;\;\left(c \cdot b - d \cdot a\right) \cdot {\left(\mathsf{hypot}\left(c, d\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 4
Accuracy78.8%
Cost7436
\[\begin{array}{l} \mathbf{if}\;c \leq -6.4 \cdot 10^{-32}:\\ \;\;\;\;\frac{b}{c} - \frac{\frac{d}{c}}{\frac{c}{a}}\\ \mathbf{elif}\;c \leq 1.3 \cdot 10^{-93}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 2.1 \cdot 10^{+66}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 5
Accuracy78.8%
Cost1356
\[\begin{array}{l} t_0 := \frac{b}{c} - \frac{\frac{d}{c}}{\frac{c}{a}}\\ \mathbf{if}\;c \leq -4 \cdot 10^{-30}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 2.3 \cdot 10^{-94}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 1.36 \cdot 10^{+112}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Accuracy75.9%
Cost969
\[\begin{array}{l} \mathbf{if}\;c \leq -2.75 \cdot 10^{-33} \lor \neg \left(c \leq 1.55 \cdot 10^{-65}\right):\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \end{array} \]
Alternative 7
Accuracy76.0%
Cost968
\[\begin{array}{l} \mathbf{if}\;c \leq -6.6 \cdot 10^{-34}:\\ \;\;\;\;\frac{b}{c} - \frac{\frac{d}{c}}{\frac{c}{a}}\\ \mathbf{elif}\;c \leq 3.15 \cdot 10^{-65}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\ \end{array} \]
Alternative 8
Accuracy71.6%
Cost841
\[\begin{array}{l} \mathbf{if}\;d \leq -3.6 \cdot 10^{+115} \lor \neg \left(d \leq 3.1 \cdot 10^{+139}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\ \end{array} \]
Alternative 9
Accuracy63.4%
Cost520
\[\begin{array}{l} \mathbf{if}\;c \leq -66000000:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 8.2 \cdot 10^{-81}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 10
Accuracy10.1%
Cost192
\[\frac{a}{c} \]
Alternative 11
Accuracy43.4%
Cost192
\[\frac{b}{c} \]

Reproduce?

herbie shell --seed 2023263 
(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))))