Average Error: 26.5 → 11.0
Time: 17.7s
Precision: binary64
Cost: 20828
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
\[\begin{array}{l} t_0 := \frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ t_1 := \frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;c \leq -4.490116382232771 \cdot 10^{+114}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;c \leq -5.612379604288589 \cdot 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -4.567322487019083 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -261.0441113546419:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -1 \cdot 10^{-120}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 10^{-152}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{c \cdot \left(a - c \cdot \frac{b}{d}\right)}{d}}{d}\\ \mathbf{elif}\;c \leq 8.79419289432676 \cdot 10^{+153}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{d}{c}}{\frac{c}{b - \frac{a}{\frac{c}{d}}}}\\ \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 (+ (/ b d) (* c (/ (/ a d) d))))
        (t_1 (/ (/ (fma a c (* d b)) (hypot c d)) (hypot c d))))
   (if (<= c -4.490116382232771e+114)
     (+ (/ a c) (* (/ d c) (/ b c)))
     (if (<= c -5.612379604288589e+70)
       t_0
       (if (<= c -4.567322487019083e+29)
         t_1
         (if (<= c -261.0441113546419)
           t_0
           (if (<= c -1e-120)
             t_1
             (if (<= c 1e-152)
               (+ (/ b d) (/ (/ (* c (- a (* c (/ b d)))) d) d))
               (if (<= c 8.79419289432676e+153)
                 t_1
                 (+ (/ a c) (/ (/ d c) (/ c (- b (/ a (/ c d)))))))))))))))
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 = (b / d) + (c * ((a / d) / d));
	double t_1 = (fma(a, c, (d * b)) / hypot(c, d)) / hypot(c, d);
	double tmp;
	if (c <= -4.490116382232771e+114) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (c <= -5.612379604288589e+70) {
		tmp = t_0;
	} else if (c <= -4.567322487019083e+29) {
		tmp = t_1;
	} else if (c <= -261.0441113546419) {
		tmp = t_0;
	} else if (c <= -1e-120) {
		tmp = t_1;
	} else if (c <= 1e-152) {
		tmp = (b / d) + (((c * (a - (c * (b / d)))) / d) / d);
	} else if (c <= 8.79419289432676e+153) {
		tmp = t_1;
	} else {
		tmp = (a / c) + ((d / c) / (c / (b - (a / (c / d)))));
	}
	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(b / d) + Float64(c * Float64(Float64(a / d) / d)))
	t_1 = Float64(Float64(fma(a, c, Float64(d * b)) / hypot(c, d)) / hypot(c, d))
	tmp = 0.0
	if (c <= -4.490116382232771e+114)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (c <= -5.612379604288589e+70)
		tmp = t_0;
	elseif (c <= -4.567322487019083e+29)
		tmp = t_1;
	elseif (c <= -261.0441113546419)
		tmp = t_0;
	elseif (c <= -1e-120)
		tmp = t_1;
	elseif (c <= 1e-152)
		tmp = Float64(Float64(b / d) + Float64(Float64(Float64(c * Float64(a - Float64(c * Float64(b / d)))) / d) / d));
	elseif (c <= 8.79419289432676e+153)
		tmp = t_1;
	else
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) / Float64(c / Float64(b - Float64(a / Float64(c / d))))));
	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[(b / d), $MachinePrecision] + N[(c * N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -4.490116382232771e+114], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -5.612379604288589e+70], t$95$0, If[LessEqual[c, -4.567322487019083e+29], t$95$1, If[LessEqual[c, -261.0441113546419], t$95$0, If[LessEqual[c, -1e-120], t$95$1, If[LessEqual[c, 1e-152], N[(N[(b / d), $MachinePrecision] + N[(N[(N[(c * N[(a - N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 8.79419289432676e+153], t$95$1, N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] / N[(c / N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\
t_1 := \frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;c \leq -4.490116382232771 \cdot 10^{+114}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\

\mathbf{elif}\;c \leq -5.612379604288589 \cdot 10^{+70}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;c \leq -4.567322487019083 \cdot 10^{+29}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;c \leq -1 \cdot 10^{-120}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;c \leq 8.79419289432676 \cdot 10^{+153}:\\
\;\;\;\;t_1\\

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


\end{array}

Error

Target

Original26.5
Target0.4
Herbie11.0
\[\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 5 regimes
  2. if c < -4.490116382232771e114

    1. Initial program 40.3

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

      \[\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))): 2 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 c c) (*.f64 d d)))): 2 points increase in error, 0 points decrease in error
    3. Taylor expanded in c around inf 14.8

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

      \[\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))): 0 points increase in error, 1 points decrease in error
      (+.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 d b) (*.f64 c c))) (/.f64 a c)): 47 points increase in error, 8 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
    5. Applied egg-rr8.8

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

    if -4.490116382232771e114 < c < -5.61237960428858887e70 or -4.5673224870190831e29 < c < -261.04411135464193

    1. Initial program 18.4

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

      \[\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))): 2 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 c c) (*.f64 d d)))): 2 points increase in error, 0 points decrease in error
    3. Taylor expanded in c around 0 47.9

      \[\leadsto \color{blue}{-1 \cdot \frac{{c}^{2} \cdot b}{{d}^{3}} + \left(\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}\right)} \]
    4. Simplified44.6

      \[\leadsto \color{blue}{\frac{b}{d} - \frac{c}{d \cdot d} \cdot \left(\frac{b \cdot c}{d} - a\right)} \]
      Proof
      (-.f64 (/.f64 b d) (*.f64 (/.f64 c (*.f64 d d)) (-.f64 (/.f64 (*.f64 b c) d) a))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 b d) (*.f64 (/.f64 c (Rewrite<= unpow2_binary64 (pow.f64 d 2))) (-.f64 (/.f64 (*.f64 b c) d) a))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 b d) (Rewrite<= distribute-lft-out--_binary64 (-.f64 (*.f64 (/.f64 c (pow.f64 d 2)) (/.f64 (*.f64 b c) d)) (*.f64 (/.f64 c (pow.f64 d 2)) a)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 b d) (-.f64 (*.f64 (/.f64 c (pow.f64 d 2)) (/.f64 (Rewrite=> *-commutative_binary64 (*.f64 c b)) d)) (*.f64 (/.f64 c (pow.f64 d 2)) a))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 b d) (-.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 c (*.f64 c b)) (*.f64 (pow.f64 d 2) d))) (*.f64 (/.f64 c (pow.f64 d 2)) a))): 26 points increase in error, 5 points decrease in error
      (-.f64 (/.f64 b d) (-.f64 (/.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 c c) b)) (*.f64 (pow.f64 d 2) d)) (*.f64 (/.f64 c (pow.f64 d 2)) a))): 12 points increase in error, 1 points decrease in error
      (-.f64 (/.f64 b d) (-.f64 (/.f64 (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 c 2)) b) (*.f64 (pow.f64 d 2) d)) (*.f64 (/.f64 c (pow.f64 d 2)) a))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 b d) (-.f64 (/.f64 (*.f64 (pow.f64 c 2) b) (*.f64 (Rewrite=> unpow2_binary64 (*.f64 d d)) d)) (*.f64 (/.f64 c (pow.f64 d 2)) a))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 b d) (-.f64 (/.f64 (*.f64 (pow.f64 c 2) b) (Rewrite<= unpow3_binary64 (pow.f64 d 3))) (*.f64 (/.f64 c (pow.f64 d 2)) a))): 0 points increase in error, 2 points decrease in error
      (-.f64 (/.f64 b d) (-.f64 (/.f64 (*.f64 (pow.f64 c 2) b) (pow.f64 d 3)) (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 c a) (pow.f64 d 2))))): 3 points increase in error, 6 points decrease in error
      (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 (/.f64 b d) (/.f64 (*.f64 (pow.f64 c 2) b) (pow.f64 d 3))) (/.f64 (*.f64 c a) (pow.f64 d 2)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= unsub-neg_binary64 (+.f64 (/.f64 b d) (neg.f64 (/.f64 (*.f64 (pow.f64 c 2) b) (pow.f64 d 3))))) (/.f64 (*.f64 c a) (pow.f64 d 2))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (/.f64 b d) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 (pow.f64 c 2) b) (pow.f64 d 3))))) (/.f64 (*.f64 c a) (pow.f64 d 2))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.f64 (*.f64 (pow.f64 c 2) b) (pow.f64 d 3))) (/.f64 b d))) (/.f64 (*.f64 c a) (pow.f64 d 2))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+r+_binary64 (+.f64 (*.f64 -1 (/.f64 (*.f64 (pow.f64 c 2) b) (pow.f64 d 3))) (+.f64 (/.f64 b d) (/.f64 (*.f64 c a) (pow.f64 d 2))))): 0 points increase in error, 0 points decrease in error
    5. Taylor expanded in c around 0 43.2

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

      \[\leadsto \frac{b}{d} - \color{blue}{c \cdot \frac{\frac{-a}{d}}{d}} \]
      Proof
      (*.f64 c (/.f64 (/.f64 (neg.f64 a) d) d)): 0 points increase in error, 0 points decrease in error
      (*.f64 c (/.f64 (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 a d))) d)): 0 points increase in error, 0 points decrease in error
      (*.f64 c (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 (/.f64 a d) d)))): 0 points increase in error, 0 points decrease in error
      (*.f64 c (neg.f64 (Rewrite<= associate-/r*_binary64 (/.f64 a (*.f64 d d))))): 28 points increase in error, 19 points decrease in error
      (*.f64 c (neg.f64 (/.f64 a (Rewrite<= unpow2_binary64 (pow.f64 d 2))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 c (/.f64 a (pow.f64 d 2))))): 0 points increase in error, 0 points decrease in error
      (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 a (pow.f64 d 2)) c))): 0 points increase in error, 0 points decrease in error
      (neg.f64 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 a c) (pow.f64 d 2)))): 36 points increase in error, 25 points decrease in error
      (neg.f64 (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 c a)) (pow.f64 d 2))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 c a) (pow.f64 d 2)))): 0 points increase in error, 0 points decrease in error

    if -5.61237960428858887e70 < c < -4.5673224870190831e29 or -261.04411135464193 < c < -9.99999999999999979e-121 or 1.00000000000000007e-152 < c < 8.7941928943267593e153

    1. Initial program 17.4

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

      \[\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))): 2 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 c c) (*.f64 d d)))): 2 points increase in error, 0 points decrease in error
    3. Applied egg-rr11.6

      \[\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-rr11.4

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

    if -9.99999999999999979e-121 < c < 1.00000000000000007e-152

    1. Initial program 24.3

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

      \[\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))): 2 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 c c) (*.f64 d d)))): 2 points increase in error, 0 points decrease in error
    3. Taylor expanded in c around 0 14.9

      \[\leadsto \color{blue}{-1 \cdot \frac{{c}^{2} \cdot b}{{d}^{3}} + \left(\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}\right)} \]
    4. Simplified11.3

      \[\leadsto \color{blue}{\frac{b}{d} - \frac{c}{d \cdot d} \cdot \left(\frac{b \cdot c}{d} - a\right)} \]
      Proof
      (-.f64 (/.f64 b d) (*.f64 (/.f64 c (*.f64 d d)) (-.f64 (/.f64 (*.f64 b c) d) a))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 b d) (*.f64 (/.f64 c (Rewrite<= unpow2_binary64 (pow.f64 d 2))) (-.f64 (/.f64 (*.f64 b c) d) a))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 b d) (Rewrite<= distribute-lft-out--_binary64 (-.f64 (*.f64 (/.f64 c (pow.f64 d 2)) (/.f64 (*.f64 b c) d)) (*.f64 (/.f64 c (pow.f64 d 2)) a)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 b d) (-.f64 (*.f64 (/.f64 c (pow.f64 d 2)) (/.f64 (Rewrite=> *-commutative_binary64 (*.f64 c b)) d)) (*.f64 (/.f64 c (pow.f64 d 2)) a))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 b d) (-.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 c (*.f64 c b)) (*.f64 (pow.f64 d 2) d))) (*.f64 (/.f64 c (pow.f64 d 2)) a))): 26 points increase in error, 5 points decrease in error
      (-.f64 (/.f64 b d) (-.f64 (/.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 c c) b)) (*.f64 (pow.f64 d 2) d)) (*.f64 (/.f64 c (pow.f64 d 2)) a))): 12 points increase in error, 1 points decrease in error
      (-.f64 (/.f64 b d) (-.f64 (/.f64 (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 c 2)) b) (*.f64 (pow.f64 d 2) d)) (*.f64 (/.f64 c (pow.f64 d 2)) a))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 b d) (-.f64 (/.f64 (*.f64 (pow.f64 c 2) b) (*.f64 (Rewrite=> unpow2_binary64 (*.f64 d d)) d)) (*.f64 (/.f64 c (pow.f64 d 2)) a))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 b d) (-.f64 (/.f64 (*.f64 (pow.f64 c 2) b) (Rewrite<= unpow3_binary64 (pow.f64 d 3))) (*.f64 (/.f64 c (pow.f64 d 2)) a))): 0 points increase in error, 2 points decrease in error
      (-.f64 (/.f64 b d) (-.f64 (/.f64 (*.f64 (pow.f64 c 2) b) (pow.f64 d 3)) (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 c a) (pow.f64 d 2))))): 3 points increase in error, 6 points decrease in error
      (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 (/.f64 b d) (/.f64 (*.f64 (pow.f64 c 2) b) (pow.f64 d 3))) (/.f64 (*.f64 c a) (pow.f64 d 2)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= unsub-neg_binary64 (+.f64 (/.f64 b d) (neg.f64 (/.f64 (*.f64 (pow.f64 c 2) b) (pow.f64 d 3))))) (/.f64 (*.f64 c a) (pow.f64 d 2))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (/.f64 b d) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 (pow.f64 c 2) b) (pow.f64 d 3))))) (/.f64 (*.f64 c a) (pow.f64 d 2))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.f64 (*.f64 (pow.f64 c 2) b) (pow.f64 d 3))) (/.f64 b d))) (/.f64 (*.f64 c a) (pow.f64 d 2))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+r+_binary64 (+.f64 (*.f64 -1 (/.f64 (*.f64 (pow.f64 c 2) b) (pow.f64 d 3))) (+.f64 (/.f64 b d) (/.f64 (*.f64 c a) (pow.f64 d 2))))): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr6.6

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

    if 8.7941928943267593e153 < c

    1. Initial program 44.6

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

      \[\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))): 2 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 c c) (*.f64 d d)))): 2 points increase in error, 0 points decrease in error
    3. Applied egg-rr29.4

      \[\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-rr29.3

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

      \[\leadsto \color{blue}{\frac{a}{c} + \left(-1 \cdot \frac{a \cdot {d}^{2}}{{c}^{3}} + \frac{d \cdot b}{{c}^{2}}\right)} \]
    6. Simplified15.3

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{\frac{d}{c}}{c} \cdot \left(b - \frac{d \cdot a}{c}\right)} \]
      Proof
      (+.f64 (/.f64 a c) (*.f64 (/.f64 (/.f64 d c) c) (-.f64 b (/.f64 (*.f64 d a) c)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 a c) (*.f64 (Rewrite<= associate-/r*_binary64 (/.f64 d (*.f64 c c))) (-.f64 b (/.f64 (*.f64 d a) c)))): 21 points increase in error, 5 points decrease in error
      (+.f64 (/.f64 a c) (*.f64 (/.f64 d (Rewrite<= unpow2_binary64 (pow.f64 c 2))) (-.f64 b (/.f64 (*.f64 d a) c)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 a c) (*.f64 (/.f64 d (pow.f64 c 2)) (-.f64 b (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 a d)) c)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 a c) (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 b (/.f64 d (pow.f64 c 2))) (*.f64 (/.f64 (*.f64 a d) c) (/.f64 d (pow.f64 c 2)))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 a c) (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 d (pow.f64 c 2)) b)) (*.f64 (/.f64 (*.f64 a d) c) (/.f64 d (pow.f64 c 2))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 a c) (-.f64 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 d b) (pow.f64 c 2))) (*.f64 (/.f64 (*.f64 a d) c) (/.f64 d (pow.f64 c 2))))): 13 points increase in error, 5 points decrease in error
      (+.f64 (/.f64 a c) (-.f64 (/.f64 (*.f64 d b) (pow.f64 c 2)) (Rewrite<= times-frac_binary64 (/.f64 (*.f64 (*.f64 a d) d) (*.f64 c (pow.f64 c 2)))))): 18 points increase in error, 5 points decrease in error
      (+.f64 (/.f64 a c) (-.f64 (/.f64 (*.f64 d b) (pow.f64 c 2)) (/.f64 (Rewrite<= associate-*r*_binary64 (*.f64 a (*.f64 d d))) (*.f64 c (pow.f64 c 2))))): 8 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 a c) (-.f64 (/.f64 (*.f64 d b) (pow.f64 c 2)) (/.f64 (*.f64 a (Rewrite<= unpow2_binary64 (pow.f64 d 2))) (*.f64 c (pow.f64 c 2))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 a c) (-.f64 (/.f64 (*.f64 d b) (pow.f64 c 2)) (/.f64 (*.f64 a (pow.f64 d 2)) (*.f64 c (Rewrite=> unpow2_binary64 (*.f64 c c)))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 a c) (-.f64 (/.f64 (*.f64 d b) (pow.f64 c 2)) (/.f64 (*.f64 a (pow.f64 d 2)) (Rewrite<= cube-mult_binary64 (pow.f64 c 3))))): 0 points increase in error, 1 points decrease in error
      (+.f64 (/.f64 a c) (Rewrite<= unsub-neg_binary64 (+.f64 (/.f64 (*.f64 d b) (pow.f64 c 2)) (neg.f64 (/.f64 (*.f64 a (pow.f64 d 2)) (pow.f64 c 3)))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 a c) (+.f64 (/.f64 (*.f64 d b) (pow.f64 c 2)) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 a (pow.f64 d 2)) (pow.f64 c 3)))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 a c) (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.f64 (*.f64 a (pow.f64 d 2)) (pow.f64 c 3))) (/.f64 (*.f64 d b) (pow.f64 c 2))))): 0 points increase in error, 0 points decrease in error
    7. Applied egg-rr7.5

      \[\leadsto \frac{a}{c} + \color{blue}{\frac{\frac{d}{c}}{\frac{c}{b - \frac{a}{\frac{c}{d}}}}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification11.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.490116382232771 \cdot 10^{+114}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;c \leq -5.612379604288589 \cdot 10^{+70}:\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ \mathbf{elif}\;c \leq -4.567322487019083 \cdot 10^{+29}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -261.0441113546419:\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ \mathbf{elif}\;c \leq -1 \cdot 10^{-120}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq 10^{-152}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{c \cdot \left(a - c \cdot \frac{b}{d}\right)}{d}}{d}\\ \mathbf{elif}\;c \leq 8.79419289432676 \cdot 10^{+153}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{d}{c}}{\frac{c}{b - \frac{a}{\frac{c}{d}}}}\\ \end{array} \]

Alternatives

Alternative 1
Error11.4
Cost14684
\[\begin{array}{l} t_0 := \frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ t_1 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d \cdot b + c \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;c \leq -4.490116382232771 \cdot 10^{+114}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;c \leq -5.612379604288589 \cdot 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -4.567322487019083 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -261.0441113546419:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -7.860635256967511 \cdot 10^{-91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 10^{-152}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{c \cdot \left(a - c \cdot \frac{b}{d}\right)}{d}}{d}\\ \mathbf{elif}\;c \leq 8.79419289432676 \cdot 10^{+153}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{d}{c}}{\frac{c}{b - \frac{a}{\frac{c}{d}}}}\\ \end{array} \]
Alternative 2
Error13.8
Cost14164
\[\begin{array}{l} t_0 := \frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ t_1 := \frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -4.490116382232771 \cdot 10^{+114}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;c \leq -5.612379604288589 \cdot 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -4.567322487019083 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -261.0441113546419:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -1 \cdot 10^{-120}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;c \leq 10^{-152}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{c \cdot \left(a - c \cdot \frac{b}{d}\right)}{d}}{d}\\ \mathbf{elif}\;c \leq 292215867.85226554:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{d}{c}}{\frac{c}{b - \frac{a}{\frac{c}{d}}}}\\ \end{array} \]
Alternative 3
Error13.8
Cost2012
\[\begin{array}{l} t_0 := \frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ t_1 := \frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -4.490116382232771 \cdot 10^{+114}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;c \leq -5.612379604288589 \cdot 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -4.567322487019083 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -261.0441113546419:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -1 \cdot 10^{-120}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 10^{-152}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{c \cdot \left(a - c \cdot \frac{b}{d}\right)}{d}}{d}\\ \mathbf{elif}\;c \leq 292215867.85226554:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{d}{c}}{\frac{c}{b - \frac{a}{\frac{c}{d}}}}\\ \end{array} \]
Alternative 4
Error17.0
Cost1880
\[\begin{array}{l} t_0 := \frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ t_1 := \frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ t_2 := \frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -4.490116382232771 \cdot 10^{+114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -5.612379604288589 \cdot 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -4.567322487019083 \cdot 10^{+29}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq -261.0441113546419:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -1 \cdot 10^{-120}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 10^{-146}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{c \cdot \left(a - c \cdot \frac{b}{d}\right)}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error18.6
Cost1620
\[\begin{array}{l} t_0 := \frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ t_1 := \frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ t_2 := \frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -4.490116382232771 \cdot 10^{+114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -5.612379604288589 \cdot 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -4.567322487019083 \cdot 10^{+29}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq -261.0441113546419:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -7.860635256967511 \cdot 10^{-91}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 10^{-146}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error19.9
Cost1496
\[\begin{array}{l} t_0 := \frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ t_1 := \frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{if}\;c \leq -4.490116382232771 \cdot 10^{+114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -5.612379604288589 \cdot 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -4.567322487019083 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -261.0441113546419:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -3.226352485438223 \cdot 10^{-47}:\\ \;\;\;\;\frac{c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 10^{-146}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error20.2
Cost1100
\[\begin{array}{l} t_0 := \frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{if}\;c \leq -3.995438488589496 \cdot 10^{+27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -8.504769004369532 \cdot 10^{-72}:\\ \;\;\;\;\frac{c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 3.7 \cdot 10^{-145}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error20.4
Cost968
\[\begin{array}{l} t_0 := \frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{if}\;c \leq -3.226352485438223 \cdot 10^{-47}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 3.7 \cdot 10^{-145}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error21.4
Cost840
\[\begin{array}{l} t_0 := \frac{a + \frac{d \cdot b}{c}}{c}\\ \mathbf{if}\;c \leq -3.226352485438223 \cdot 10^{-47}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 3.7 \cdot 10^{-145}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error25.3
Cost456
\[\begin{array}{l} \mathbf{if}\;c \leq -3.226352485438223 \cdot 10^{-47}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 3.7 \cdot 10^{-145}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
Alternative 11
Error58.8
Cost192
\[\frac{b}{c} \]
Alternative 12
Error59.1
Cost192
\[\frac{a}{d} \]
Alternative 13
Error37.7
Cost192
\[\frac{b}{d} \]

Error

Reproduce

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