?

Average Error: 41.11% → 17.93%
Time: 15.1s
Precision: binary64
Cost: 21260

?

\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
\[\begin{array}{l} t_0 := \frac{\frac{b}{\frac{d}{c}} - a}{d}\\ t_1 := c \cdot b - d \cdot a\\ t_2 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ t_3 := \mathsf{fma}\left(d, d, c \cdot c\right)\\ \mathbf{if}\;c \leq -1.4 \cdot 10^{+138}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{elif}\;c \leq -1.85 \cdot 10^{+60}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.05 \cdot 10^{+37}:\\ \;\;\;\;t_2 \cdot \frac{t_1 + 2 \cdot \left(2 \cdot \mathsf{fma}\left(-d, a, d \cdot a\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -38000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -2.4 \cdot 10^{-123}:\\ \;\;\;\;t_2 \cdot \frac{t_1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq 2.15 \cdot 10^{-108}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 1.15 \cdot 10^{+142}:\\ \;\;\;\;b \cdot \frac{c}{t_3} - d \cdot \frac{a}{t_3}\\ \mathbf{else}:\\ \;\;\;\;t_2 \cdot \left(b - \frac{d \cdot a}{c}\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 (/ (- (/ b (/ d c)) a) d))
        (t_1 (- (* c b) (* d a)))
        (t_2 (/ 1.0 (hypot c d)))
        (t_3 (fma d d (* c c))))
   (if (<= c -1.4e+138)
     (- (/ b c) (* (/ d c) (/ a c)))
     (if (<= c -1.85e+60)
       (* (/ c (hypot c d)) (/ b (hypot c d)))
       (if (<= c -1.05e+37)
         (* t_2 (/ (+ t_1 (* 2.0 (* 2.0 (fma (- d) a (* d a))))) (hypot c d)))
         (if (<= c -38000000000.0)
           t_0
           (if (<= c -2.4e-123)
             (* t_2 (/ t_1 (hypot c d)))
             (if (<= c 2.15e-108)
               t_0
               (if (<= c 1.15e+142)
                 (- (* b (/ c t_3)) (* d (/ a t_3)))
                 (* t_2 (- b (/ (* d a) c))))))))))))
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 = ((b / (d / c)) - a) / d;
	double t_1 = (c * b) - (d * a);
	double t_2 = 1.0 / hypot(c, d);
	double t_3 = fma(d, d, (c * c));
	double tmp;
	if (c <= -1.4e+138) {
		tmp = (b / c) - ((d / c) * (a / c));
	} else if (c <= -1.85e+60) {
		tmp = (c / hypot(c, d)) * (b / hypot(c, d));
	} else if (c <= -1.05e+37) {
		tmp = t_2 * ((t_1 + (2.0 * (2.0 * fma(-d, a, (d * a))))) / hypot(c, d));
	} else if (c <= -38000000000.0) {
		tmp = t_0;
	} else if (c <= -2.4e-123) {
		tmp = t_2 * (t_1 / hypot(c, d));
	} else if (c <= 2.15e-108) {
		tmp = t_0;
	} else if (c <= 1.15e+142) {
		tmp = (b * (c / t_3)) - (d * (a / t_3));
	} else {
		tmp = t_2 * (b - ((d * a) / c));
	}
	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(Float64(Float64(b / Float64(d / c)) - a) / d)
	t_1 = Float64(Float64(c * b) - Float64(d * a))
	t_2 = Float64(1.0 / hypot(c, d))
	t_3 = fma(d, d, Float64(c * c))
	tmp = 0.0
	if (c <= -1.4e+138)
		tmp = Float64(Float64(b / c) - Float64(Float64(d / c) * Float64(a / c)));
	elseif (c <= -1.85e+60)
		tmp = Float64(Float64(c / hypot(c, d)) * Float64(b / hypot(c, d)));
	elseif (c <= -1.05e+37)
		tmp = Float64(t_2 * Float64(Float64(t_1 + Float64(2.0 * Float64(2.0 * fma(Float64(-d), a, Float64(d * a))))) / hypot(c, d)));
	elseif (c <= -38000000000.0)
		tmp = t_0;
	elseif (c <= -2.4e-123)
		tmp = Float64(t_2 * Float64(t_1 / hypot(c, d)));
	elseif (c <= 2.15e-108)
		tmp = t_0;
	elseif (c <= 1.15e+142)
		tmp = Float64(Float64(b * Float64(c / t_3)) - Float64(d * Float64(a / t_3)));
	else
		tmp = Float64(t_2 * Float64(b - Float64(Float64(d * a) / c)));
	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[(N[(N[(b / N[(d / c), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.4e+138], N[(N[(b / c), $MachinePrecision] - N[(N[(d / c), $MachinePrecision] * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.85e+60], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.05e+37], N[(t$95$2 * N[(N[(t$95$1 + N[(2.0 * N[(2.0 * N[((-d) * a + N[(d * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -38000000000.0], t$95$0, If[LessEqual[c, -2.4e-123], N[(t$95$2 * N[(t$95$1 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.15e-108], t$95$0, If[LessEqual[c, 1.15e+142], N[(N[(b * N[(c / t$95$3), $MachinePrecision]), $MachinePrecision] - N[(d * N[(a / t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$2 * N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]]]]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{\frac{b}{\frac{d}{c}} - a}{d}\\
t_1 := c \cdot b - d \cdot a\\
t_2 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
t_3 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
\mathbf{if}\;c \leq -1.4 \cdot 10^{+138}:\\
\;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\

\mathbf{elif}\;c \leq -1.85 \cdot 10^{+60}:\\
\;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -1.05 \cdot 10^{+37}:\\
\;\;\;\;t_2 \cdot \frac{t_1 + 2 \cdot \left(2 \cdot \mathsf{fma}\left(-d, a, d \cdot a\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -38000000000:\\
\;\;\;\;t_0\\

\mathbf{elif}\;c \leq -2.4 \cdot 10^{-123}:\\
\;\;\;\;t_2 \cdot \frac{t_1}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq 2.15 \cdot 10^{-108}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;c \leq 1.15 \cdot 10^{+142}:\\
\;\;\;\;b \cdot \frac{c}{t_3} - d \cdot \frac{a}{t_3}\\

\mathbf{else}:\\
\;\;\;\;t_2 \cdot \left(b - \frac{d \cdot a}{c}\right)\\


\end{array}

Error?

Target

Original41.11%
Target0.66%
Herbie17.93%
\[\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 7 regimes
  2. if c < -1.4e138

    1. Initial program 68.52

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around inf 22.41

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

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

      [Start]22.41

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

      +-commutative [=>]22.41

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

      mul-1-neg [=>]22.41

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

      unsub-neg [=>]22.41

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

      *-commutative [=>]22.41

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

      unpow2 [=>]22.41

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

      times-frac [=>]10.84

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

    if -1.4e138 < c < -1.84999999999999994e60

    1. Initial program 34.01

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in b around inf 48.53

      \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} \]
    3. Applied egg-rr31.47

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

    if -1.84999999999999994e60 < c < -1.0500000000000001e37

    1. Initial program 25.29

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

      \[\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)}} \]
    3. Applied egg-rr18.46

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

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

      [Start]18.46

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

      *-commutative [=>]18.46

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

      count-2 [=>]18.46

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

      count-2 [=>]18.46

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

    if -1.0500000000000001e37 < c < -3.8e10 or -2.4e-123 < c < 2.15e-108

    1. Initial program 33.21

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

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

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

      [Start]20.48

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

      +-commutative [=>]20.48

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

      mul-1-neg [=>]20.48

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

      unsub-neg [=>]20.48

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

      associate-/l* [=>]25.19

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

      unpow2 [=>]25.19

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

      associate-/r/ [=>]21.72

      \[ \color{blue}{\frac{c}{d \cdot d} \cdot b} - \frac{a}{d} \]
    4. Applied egg-rr16.07

      \[\leadsto \color{blue}{{\left(\frac{d}{c} \cdot d\right)}^{-1}} \cdot b - \frac{a}{d} \]
    5. Taylor expanded in d around 0 20.48

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \frac{c \cdot b}{{d}^{2}}} \]
    6. Simplified14.87

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

      [Start]20.48

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

      unpow2 [=>]20.48

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

      associate-*l/ [<=]21.72

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

      associate-*r/ [=>]21.72

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

      associate-*l/ [<=]21.96

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

      metadata-eval [<=]21.96

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

      distribute-neg-frac [<=]21.96

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

      distribute-lft-neg-out [=>]21.96

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

      distribute-rgt-neg-out [<=]21.96

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

      associate-*l/ [=>]20.72

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

      /-rgt-identity [<=]20.72

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

      associate-/r/ [<=]20.73

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

      associate-/r/ [=>]15.13

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

      *-commutative [=>]15.13

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

      associate-*r/ [<=]15.05

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

      *-commutative [<=]15.05

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

      distribute-lft-in [<=]15.05

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

      +-commutative [<=]15.05

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

      associate-*l/ [=>]14.78

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

    if -3.8e10 < c < -2.4e-123

    1. Initial program 23.87

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

      \[\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)}} \]

    if 2.15e-108 < c < 1.15000000000000001e142

    1. Initial program 27.76

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

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

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

      [Start]27.77

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

      mul-1-neg [=>]27.77

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

      unsub-neg [=>]27.77

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

      associate-/l* [=>]25.75

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

      associate-/r/ [=>]22.32

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

      unpow2 [=>]22.32

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

      unpow2 [=>]22.32

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

      fma-udef [<=]22.32

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

      associate-/l* [=>]19.57

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

      associate-/r/ [=>]22.38

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

      unpow2 [=>]22.38

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

      unpow2 [=>]22.38

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

      fma-udef [<=]22.38

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

    if 1.15000000000000001e142 < c

    1. Initial program 68.38

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

      \[\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)}} \]
    3. Taylor expanded in c around inf 19.53

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-1 \cdot \frac{a \cdot d}{c} + b\right)} \]
  3. Recombined 7 regimes into one program.
  4. Final simplification17.93

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.4 \cdot 10^{+138}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{elif}\;c \leq -1.85 \cdot 10^{+60}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.05 \cdot 10^{+37}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\left(c \cdot b - d \cdot a\right) + 2 \cdot \left(2 \cdot \mathsf{fma}\left(-d, a, d \cdot a\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -38000000000:\\ \;\;\;\;\frac{\frac{b}{\frac{d}{c}} - a}{d}\\ \mathbf{elif}\;c \leq -2.4 \cdot 10^{-123}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq 2.15 \cdot 10^{-108}:\\ \;\;\;\;\frac{\frac{b}{\frac{d}{c}} - a}{d}\\ \mathbf{elif}\;c \leq 1.15 \cdot 10^{+142}:\\ \;\;\;\;b \cdot \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} - d \cdot \frac{a}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - \frac{d \cdot a}{c}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error17.95%
Cost14940
\[\begin{array}{l} t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\ t_1 := \frac{\frac{b}{\frac{d}{c}} - a}{d}\\ t_2 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ t_3 := t_2 \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;c \leq -2.6 \cdot 10^{+135}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{elif}\;c \leq -2 \cdot 10^{+60}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.06 \cdot 10^{+37}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \leq -16600000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -1.7 \cdot 10^{-123}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \leq 1.1 \cdot 10^{-107}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 8.5 \cdot 10^{+141}:\\ \;\;\;\;b \cdot \frac{c}{t_0} - d \cdot \frac{a}{t_0}\\ \mathbf{else}:\\ \;\;\;\;t_2 \cdot \left(b - \frac{d \cdot a}{c}\right)\\ \end{array} \]
Alternative 2
Error17.3%
Cost14684
\[\begin{array}{l} t_0 := \frac{\frac{b}{\frac{d}{c}} - a}{d}\\ t_1 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ t_2 := t_1 \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;c \leq -1.3 \cdot 10^{+140}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{elif}\;c \leq -2 \cdot 10^{+60}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.05 \cdot 10^{+37}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq -38000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -7.5 \cdot 10^{-117}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 2.25 \cdot 10^{-113}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 1.08 \cdot 10^{+117}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \left(b - \frac{d \cdot a}{c}\right)\\ \end{array} \]
Alternative 3
Error19.27%
Cost14168
\[\begin{array}{l} t_0 := \frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -3.6 \cdot 10^{+139}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{elif}\;c \leq -1.2 \cdot 10^{+56}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -6.6 \cdot 10^{-53}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 2.2 \cdot 10^{-36}:\\ \;\;\;\;\frac{\frac{b}{\frac{d}{c}} - a}{d}\\ \mathbf{elif}\;c \leq 1.6 \cdot 10^{+90}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 3.3 \cdot 10^{+168}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - \frac{d \cdot a}{c}\right)\\ \end{array} \]
Alternative 4
Error23.69%
Cost7696
\[\begin{array}{l} t_0 := \frac{c}{\frac{d}{b}}\\ \mathbf{if}\;d \leq -27000000:\\ \;\;\;\;\frac{t_0}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 1.3 \cdot 10^{-36}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;d \leq 46000000:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 5.5 \cdot 10^{+89}:\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{\frac{a}{\frac{c}{d}}}{c}, \frac{b}{c}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(t_0 - a\right)\\ \end{array} \]
Alternative 5
Error25.91%
Cost7632
\[\begin{array}{l} t_0 := \frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{if}\;d \leq -1100:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}}}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 1.25 \cdot 10^{-38}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 800000000000:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 5.2 \cdot 10^{+89}:\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{\frac{a}{\frac{c}{d}}}{c}, \frac{b}{c}\right)\\ \mathbf{elif}\;d \leq 5.7 \cdot 10^{+181} \lor \neg \left(d \leq 5.2 \cdot 10^{+213}\right):\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error25.85%
Cost1369
\[\begin{array}{l} t_0 := \frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{if}\;d \leq -280000:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}}}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 3.9 \cdot 10^{-38}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 4.5 \cdot 10^{+19}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.95 \cdot 10^{+89}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{elif}\;d \leq 5.7 \cdot 10^{+181} \lor \neg \left(d \leq 5.2 \cdot 10^{+213}\right):\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error27.28%
Cost1106
\[\begin{array}{l} \mathbf{if}\;d \leq -160000000 \lor \neg \left(d \leq 1.55 \cdot 10^{+90}\right) \land \left(d \leq 5.7 \cdot 10^{+181} \lor \neg \left(d \leq 5.2 \cdot 10^{+213}\right)\right):\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \]
Alternative 8
Error27.14%
Cost1105
\[\begin{array}{l} \mathbf{if}\;d \leq -3100000:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}}}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 1.05 \cdot 10^{+90} \lor \neg \left(d \leq 5.7 \cdot 10^{+181}\right) \land d \leq 5.2 \cdot 10^{+213}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \end{array} \]
Alternative 9
Error29.5%
Cost841
\[\begin{array}{l} \mathbf{if}\;c \leq -2.45 \cdot 10^{+37} \lor \neg \left(c \leq 5.5 \cdot 10^{-34}\right):\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \]
Alternative 10
Error35.79%
Cost520
\[\begin{array}{l} \mathbf{if}\;c \leq -1.36 \cdot 10^{+38}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 3.7 \cdot 10^{-35}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 11
Error58.22%
Cost192
\[\frac{b}{c} \]

Error

Reproduce?

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