Average Error: 26.4 → 11.5
Time: 8.4s
Precision: binary64
Cost: 20824
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
\[\begin{array}{l} t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := \mathsf{fma}\left(d, d, c \cdot c\right)\\ \mathbf{if}\;c \leq -4.836137970441789 \cdot 10^{+171}:\\ \;\;\;\;\mathsf{fma}\left(\frac{d}{c}, \frac{b}{c}, \frac{a}{c}\right)\\ \mathbf{elif}\;c \leq -3.925657958005623 \cdot 10^{+128}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{d}, \frac{a}{d}, \frac{b}{d}\right)\\ \mathbf{elif}\;c \leq -4.2080102472304264 \cdot 10^{+61}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{t_1}, a, d \cdot \frac{b}{t_1}\right)\\ \mathbf{elif}\;c \leq -6.0863868367415625 \cdot 10^{-46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 10^{-220}:\\ \;\;\;\;\left(b + \frac{c \cdot a}{d}\right) \cdot \frac{1}{d}\\ \mathbf{elif}\;c \leq 4.274990621935937 \cdot 10^{+42}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{\frac{c}{d}}}{c}\\ \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (* (/ 1.0 (hypot c d)) (/ (fma a c (* d b)) (hypot c d))))
        (t_1 (fma d d (* c c))))
   (if (<= c -4.836137970441789e+171)
     (fma (/ d c) (/ b c) (/ a c))
     (if (<= c -3.925657958005623e+128)
       (fma (/ c d) (/ a d) (/ b d))
       (if (<= c -4.2080102472304264e+61)
         (fma (/ c t_1) a (* d (/ b t_1)))
         (if (<= c -6.0863868367415625e-46)
           t_0
           (if (<= c 1e-220)
             (* (+ b (/ (* c a) d)) (/ 1.0 d))
             (if (<= c 4.274990621935937e+42)
               t_0
               (+ (/ a c) (/ (/ b (/ c d)) c))))))))))
double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
double code(double a, double b, double c, double d) {
	double t_0 = (1.0 / hypot(c, d)) * (fma(a, c, (d * b)) / hypot(c, d));
	double t_1 = fma(d, d, (c * c));
	double tmp;
	if (c <= -4.836137970441789e+171) {
		tmp = fma((d / c), (b / c), (a / c));
	} else if (c <= -3.925657958005623e+128) {
		tmp = fma((c / d), (a / d), (b / d));
	} else if (c <= -4.2080102472304264e+61) {
		tmp = fma((c / t_1), a, (d * (b / t_1)));
	} else if (c <= -6.0863868367415625e-46) {
		tmp = t_0;
	} else if (c <= 1e-220) {
		tmp = (b + ((c * a) / d)) * (1.0 / d);
	} else if (c <= 4.274990621935937e+42) {
		tmp = t_0;
	} else {
		tmp = (a / c) + ((b / (c / d)) / c);
	}
	return tmp;
}
function code(a, b, c, d)
	return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function code(a, b, c, d)
	t_0 = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(d * b)) / hypot(c, d)))
	t_1 = fma(d, d, Float64(c * c))
	tmp = 0.0
	if (c <= -4.836137970441789e+171)
		tmp = fma(Float64(d / c), Float64(b / c), Float64(a / c));
	elseif (c <= -3.925657958005623e+128)
		tmp = fma(Float64(c / d), Float64(a / d), Float64(b / d));
	elseif (c <= -4.2080102472304264e+61)
		tmp = fma(Float64(c / t_1), a, Float64(d * Float64(b / t_1)));
	elseif (c <= -6.0863868367415625e-46)
		tmp = t_0;
	elseif (c <= 1e-220)
		tmp = Float64(Float64(b + Float64(Float64(c * a) / d)) * Float64(1.0 / d));
	elseif (c <= 4.274990621935937e+42)
		tmp = t_0;
	else
		tmp = Float64(Float64(a / c) + Float64(Float64(b / Float64(c / d)) / c));
	end
	return tmp
end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * 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[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -4.836137970441789e+171], N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision] + N[(a / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -3.925657958005623e+128], N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -4.2080102472304264e+61], N[(N[(c / t$95$1), $MachinePrecision] * a + N[(d * N[(b / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -6.0863868367415625e-46], t$95$0, If[LessEqual[c, 1e-220], N[(N[(b + N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] * N[(1.0 / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.274990621935937e+42], t$95$0, N[(N[(a / c), $MachinePrecision] + N[(N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
\mathbf{if}\;c \leq -4.836137970441789 \cdot 10^{+171}:\\
\;\;\;\;\mathsf{fma}\left(\frac{d}{c}, \frac{b}{c}, \frac{a}{c}\right)\\

\mathbf{elif}\;c \leq -3.925657958005623 \cdot 10^{+128}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{d}, \frac{a}{d}, \frac{b}{d}\right)\\

\mathbf{elif}\;c \leq -4.2080102472304264 \cdot 10^{+61}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{t_1}, a, d \cdot \frac{b}{t_1}\right)\\

\mathbf{elif}\;c \leq -6.0863868367415625 \cdot 10^{-46}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;c \leq 10^{-220}:\\
\;\;\;\;\left(b + \frac{c \cdot a}{d}\right) \cdot \frac{1}{d}\\

\mathbf{elif}\;c \leq 4.274990621935937 \cdot 10^{+42}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b}{\frac{c}{d}}}{c}\\


\end{array}

Error

Target

Original26.4
Target0.5
Herbie11.5
\[\begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array} \]

Derivation

  1. Split input into 6 regimes
  2. if c < -4.8361379704417887e171

    1. Initial program 43.2

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Simplified43.2

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      Proof
      (/.f64 (fma.f64 a c (*.f64 b d)) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a c) (*.f64 b d))) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 1 points decrease in error
      (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 c c) (*.f64 d d)))): 1 points increase in error, 0 points decrease in error
    3. Applied egg-rr28.8

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    4. Taylor expanded in c around inf 14.7

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    5. Simplified6.6

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{d}{c}, \frac{b}{c}, \frac{a}{c}\right)} \]
      Proof
      (fma.f64 (/.f64 d c) (/.f64 b c) (/.f64 a c)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (/.f64 d c) (/.f64 b c)) (/.f64 a c))): 2 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 d b) (*.f64 c c))) (/.f64 a c)): 48 points increase in error, 14 points decrease in error
      (+.f64 (/.f64 (*.f64 d b) (Rewrite<= unpow2_binary64 (pow.f64 c 2))) (/.f64 a c)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 a c) (/.f64 (*.f64 d b) (pow.f64 c 2)))): 0 points increase in error, 0 points decrease in error

    if -4.8361379704417887e171 < c < -3.9256579580056227e128

    1. Initial program 38.4

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{d}, \frac{a}{d}, \frac{b}{d}\right)} \]
      Proof
      (fma.f64 (/.f64 c d) (/.f64 a d) (/.f64 b d)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (/.f64 c d) (/.f64 a d)) (/.f64 b d))): 1 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 c a) (*.f64 d d))) (/.f64 b d)): 47 points increase in error, 12 points decrease in error
      (+.f64 (/.f64 (*.f64 c a) (Rewrite<= unpow2_binary64 (pow.f64 d 2))) (/.f64 b d)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 b d) (/.f64 (*.f64 c a) (pow.f64 d 2)))): 0 points increase in error, 0 points decrease in error

    if -3.9256579580056227e128 < c < -4.20801024723042645e61

    1. Initial program 20.0

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Simplified20.0

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      Proof
      (/.f64 (fma.f64 a c (*.f64 b d)) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a c) (*.f64 b d))) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 1 points decrease in error
      (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 c c) (*.f64 d d)))): 1 points increase in error, 0 points decrease in error
    3. Taylor expanded in a around 0 20.0

      \[\leadsto \color{blue}{\frac{d \cdot b}{{d}^{2} + {c}^{2}} + \frac{c \cdot a}{{d}^{2} + {c}^{2}}} \]
    4. Simplified11.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)}, a, d \cdot \frac{b}{\mathsf{fma}\left(d, d, c \cdot c\right)}\right)} \]
      Proof
      (fma.f64 (/.f64 c (fma.f64 d d (*.f64 c c))) a (*.f64 d (/.f64 b (fma.f64 d d (*.f64 c c))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (/.f64 c (fma.f64 d d (Rewrite<= unpow2_binary64 (pow.f64 c 2)))) a (*.f64 d (/.f64 b (fma.f64 d d (*.f64 c c))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (/.f64 c (Rewrite<= fma-def_binary64 (+.f64 (*.f64 d d) (pow.f64 c 2)))) a (*.f64 d (/.f64 b (fma.f64 d d (*.f64 c c))))): 1 points increase in error, 0 points decrease in error
      (fma.f64 (/.f64 c (+.f64 (Rewrite<= unpow2_binary64 (pow.f64 d 2)) (pow.f64 c 2))) a (*.f64 d (/.f64 b (fma.f64 d d (*.f64 c c))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (/.f64 c (+.f64 (pow.f64 d 2) (pow.f64 c 2))) a (*.f64 d (/.f64 b (fma.f64 d d (Rewrite<= unpow2_binary64 (pow.f64 c 2)))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (/.f64 c (+.f64 (pow.f64 d 2) (pow.f64 c 2))) a (*.f64 d (/.f64 b (Rewrite<= fma-def_binary64 (+.f64 (*.f64 d d) (pow.f64 c 2)))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (/.f64 c (+.f64 (pow.f64 d 2) (pow.f64 c 2))) a (*.f64 d (/.f64 b (+.f64 (Rewrite<= unpow2_binary64 (pow.f64 d 2)) (pow.f64 c 2))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (/.f64 c (+.f64 (pow.f64 d 2) (pow.f64 c 2))) a (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 b (+.f64 (pow.f64 d 2) (pow.f64 c 2))) d))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (/.f64 c (+.f64 (pow.f64 d 2) (pow.f64 c 2))) a (Rewrite<= associate-/r/_binary64 (/.f64 b (/.f64 (+.f64 (pow.f64 d 2) (pow.f64 c 2)) d)))): 4 points increase in error, 32 points decrease in error
      (fma.f64 (/.f64 c (+.f64 (pow.f64 d 2) (pow.f64 c 2))) a (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 b d) (+.f64 (pow.f64 d 2) (pow.f64 c 2))))): 53 points increase in error, 2 points decrease in error
      (fma.f64 (/.f64 c (+.f64 (pow.f64 d 2) (pow.f64 c 2))) a (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 d b)) (+.f64 (pow.f64 d 2) (pow.f64 c 2)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (/.f64 c (+.f64 (pow.f64 d 2) (pow.f64 c 2))) a) (/.f64 (*.f64 d b) (+.f64 (pow.f64 d 2) (pow.f64 c 2))))): 1 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 c a) (+.f64 (pow.f64 d 2) (pow.f64 c 2)))) (/.f64 (*.f64 d b) (+.f64 (pow.f64 d 2) (pow.f64 c 2)))): 41 points increase in error, 9 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 (*.f64 d b) (+.f64 (pow.f64 d 2) (pow.f64 c 2))) (/.f64 (*.f64 c a) (+.f64 (pow.f64 d 2) (pow.f64 c 2))))): 0 points increase in error, 0 points decrease in error

    if -4.20801024723042645e61 < c < -6.08638683674156248e-46 or 9.99999999999999992e-221 < c < 4.2749906219359373e42

    1. Initial program 17.2

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Simplified17.2

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      Proof
      (/.f64 (fma.f64 a c (*.f64 b d)) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a c) (*.f64 b d))) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 1 points decrease in error
      (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 c c) (*.f64 d d)))): 1 points increase in error, 0 points decrease in error
    3. Applied egg-rr10.5

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

    if -6.08638683674156248e-46 < c < 9.99999999999999992e-221

    1. Initial program 20.5

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

      \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{{d}^{2}}} \]
    3. Simplified25.9

      \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d}} \]
      Proof
      (*.f64 d d): 0 points increase in error, 0 points decrease in error
      (Rewrite<= unpow2_binary64 (pow.f64 d 2)): 0 points increase in error, 0 points decrease in error
    4. Applied egg-rr18.4

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{d} \cdot \frac{1}{d}} \]
    5. Taylor expanded in a around 0 8.4

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

    if 4.2749906219359373e42 < c

    1. Initial program 36.2

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Simplified36.2

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      Proof
      (/.f64 (fma.f64 a c (*.f64 b d)) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a c) (*.f64 b d))) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 1 points decrease in error
      (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 c c) (*.f64 d d)))): 1 points increase in error, 0 points decrease in error
    3. Applied egg-rr24.2

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    4. Applied egg-rr24.2

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{{\left(\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(a, c, b \cdot d\right)}\right)}^{-1}} \]
    5. Taylor expanded in c around inf 17.9

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    6. Simplified12.7

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{\frac{b}{\frac{c}{d}}}{c}} \]
      Proof
      (+.f64 (/.f64 a c) (/.f64 (/.f64 b (/.f64 c d)) c)): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 a c) (/.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 b d) c)) c)): 24 points increase in error, 9 points decrease in error
      (+.f64 (/.f64 a c) (/.f64 (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 d b)) c) c)): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 a c) (Rewrite<= associate-/r*_binary64 (/.f64 (*.f64 d b) (*.f64 c c)))): 36 points increase in error, 6 points decrease in error
      (+.f64 (/.f64 a c) (/.f64 (*.f64 d b) (Rewrite<= unpow2_binary64 (pow.f64 c 2)))): 0 points increase in error, 0 points decrease in error
  3. Recombined 6 regimes into one program.
  4. Final simplification11.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.836137970441789 \cdot 10^{+171}:\\ \;\;\;\;\mathsf{fma}\left(\frac{d}{c}, \frac{b}{c}, \frac{a}{c}\right)\\ \mathbf{elif}\;c \leq -3.925657958005623 \cdot 10^{+128}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{d}, \frac{a}{d}, \frac{b}{d}\right)\\ \mathbf{elif}\;c \leq -4.2080102472304264 \cdot 10^{+61}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)}, a, d \cdot \frac{b}{\mathsf{fma}\left(d, d, c \cdot c\right)}\right)\\ \mathbf{elif}\;c \leq -6.0863868367415625 \cdot 10^{-46}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq 10^{-220}:\\ \;\;\;\;\left(b + \frac{c \cdot a}{d}\right) \cdot \frac{1}{d}\\ \mathbf{elif}\;c \leq 4.274990621935937 \cdot 10^{+42}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{\frac{c}{d}}}{c}\\ \end{array} \]

Alternatives

Alternative 1
Error23.6
Cost720
\[\begin{array}{l} \mathbf{if}\;c \leq -3.0522014657303375 \cdot 10^{+163}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -8.075702831282139 \cdot 10^{+127}:\\ \;\;\;\;\frac{1}{\frac{d}{b}}\\ \mathbf{elif}\;c \leq -3.132358103555647 \cdot 10^{-25}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 7.959857781549624 \cdot 10^{-21}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Error

Reproduce

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

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

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