
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); 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]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); 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]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ a d) c b) d)))
(if (<= d -3e-71)
t_0
(if (<= d 1.8e-130)
(/ (- a (/ (fma (- b) d (/ (* (* d d) a) c)) c)) c)
(if (<= d 2.05e+105) (/ (fma d b (* c a)) (fma d d (* c c))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma((a / d), c, b) / d;
double tmp;
if (d <= -3e-71) {
tmp = t_0;
} else if (d <= 1.8e-130) {
tmp = (a - (fma(-b, d, (((d * d) * a) / c)) / c)) / c;
} else if (d <= 2.05e+105) {
tmp = fma(d, b, (c * a)) / fma(d, d, (c * c));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(a / d), c, b) / d) tmp = 0.0 if (d <= -3e-71) tmp = t_0; elseif (d <= 1.8e-130) tmp = Float64(Float64(a - Float64(fma(Float64(-b), d, Float64(Float64(Float64(d * d) * a) / c)) / c)) / c); elseif (d <= 2.05e+105) tmp = Float64(fma(d, b, Float64(c * a)) / fma(d, d, Float64(c * c))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -3e-71], t$95$0, If[LessEqual[d, 1.8e-130], N[(N[(a - N[(N[((-b) * d + N[(N[(N[(d * d), $MachinePrecision] * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.05e+105], N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{if}\;d \leq -3 \cdot 10^{-71}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.8 \cdot 10^{-130}:\\
\;\;\;\;\frac{a - \frac{\mathsf{fma}\left(-b, d, \frac{\left(d \cdot d\right) \cdot a}{c}\right)}{c}}{c}\\
\mathbf{elif}\;d \leq 2.05 \cdot 10^{+105}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -3.0000000000000001e-71 or 2.0500000000000001e105 < d Initial program 45.8%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6489.0
Applied rewrites89.0%
if -3.0000000000000001e-71 < d < 1.8000000000000001e-130Initial program 70.5%
Taylor expanded in c around inf
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
unsub-negN/A
mul-1-negN/A
+-commutativeN/A
lower-/.f64N/A
Applied rewrites90.2%
if 1.8000000000000001e-130 < d < 2.0500000000000001e105Initial program 73.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6473.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6473.2
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6473.2
Applied rewrites73.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ a d) c b) d)))
(if (<= d -3e-71)
t_0
(if (<= d 3e-133)
(/ (fma (/ b c) d a) c)
(if (<= d 2.05e+105) (/ (fma d b (* c a)) (fma d d (* c c))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma((a / d), c, b) / d;
double tmp;
if (d <= -3e-71) {
tmp = t_0;
} else if (d <= 3e-133) {
tmp = fma((b / c), d, a) / c;
} else if (d <= 2.05e+105) {
tmp = fma(d, b, (c * a)) / fma(d, d, (c * c));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(a / d), c, b) / d) tmp = 0.0 if (d <= -3e-71) tmp = t_0; elseif (d <= 3e-133) tmp = Float64(fma(Float64(b / c), d, a) / c); elseif (d <= 2.05e+105) tmp = Float64(fma(d, b, Float64(c * a)) / fma(d, d, Float64(c * c))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -3e-71], t$95$0, If[LessEqual[d, 3e-133], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.05e+105], N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{if}\;d \leq -3 \cdot 10^{-71}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 3 \cdot 10^{-133}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{elif}\;d \leq 2.05 \cdot 10^{+105}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -3.0000000000000001e-71 or 2.0500000000000001e105 < d Initial program 45.8%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6489.0
Applied rewrites89.0%
if -3.0000000000000001e-71 < d < 3.00000000000000019e-133Initial program 70.5%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6488.6
Applied rewrites88.6%
if 3.00000000000000019e-133 < d < 2.0500000000000001e105Initial program 73.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6473.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6473.2
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6473.2
Applied rewrites73.2%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma (/ a d) c b) d))) (if (<= d -3e-71) t_0 (if (<= d 1.7e-81) (/ (fma (/ b c) d a) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma((a / d), c, b) / d;
double tmp;
if (d <= -3e-71) {
tmp = t_0;
} else if (d <= 1.7e-81) {
tmp = fma((b / c), d, a) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(a / d), c, b) / d) tmp = 0.0 if (d <= -3e-71) tmp = t_0; elseif (d <= 1.7e-81) tmp = Float64(fma(Float64(b / c), d, a) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -3e-71], t$95$0, If[LessEqual[d, 1.7e-81], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{if}\;d \leq -3 \cdot 10^{-71}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.7 \cdot 10^{-81}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -3.0000000000000001e-71 or 1.6999999999999999e-81 < d Initial program 52.4%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6481.1
Applied rewrites81.1%
if -3.0000000000000001e-71 < d < 1.6999999999999999e-81Initial program 71.4%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6487.0
Applied rewrites87.0%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma (/ a d) c b) d))) (if (<= d -2.6e-71) t_0 (if (<= d 5.5e-82) (/ a c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma((a / d), c, b) / d;
double tmp;
if (d <= -2.6e-71) {
tmp = t_0;
} else if (d <= 5.5e-82) {
tmp = a / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(a / d), c, b) / d) tmp = 0.0 if (d <= -2.6e-71) tmp = t_0; elseif (d <= 5.5e-82) tmp = Float64(a / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.6e-71], t$95$0, If[LessEqual[d, 5.5e-82], N[(a / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{if}\;d \leq -2.6 \cdot 10^{-71}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 5.5 \cdot 10^{-82}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.5999999999999999e-71 or 5.4999999999999998e-82 < d Initial program 52.4%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6481.1
Applied rewrites81.1%
if -2.5999999999999999e-71 < d < 5.4999999999999998e-82Initial program 71.4%
Taylor expanded in c around inf
lower-/.f6474.8
Applied rewrites74.8%
(FPCore (a b c d) :precision binary64 (if (<= d -3e-71) (/ 1.0 (/ d b)) (if (<= d 7.4e-82) (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3e-71) {
tmp = 1.0 / (d / b);
} else if (d <= 7.4e-82) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-3d-71)) then
tmp = 1.0d0 / (d / b)
else if (d <= 7.4d-82) then
tmp = a / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3e-71) {
tmp = 1.0 / (d / b);
} else if (d <= 7.4e-82) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -3e-71: tmp = 1.0 / (d / b) elif d <= 7.4e-82: tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -3e-71) tmp = Float64(1.0 / Float64(d / b)); elseif (d <= 7.4e-82) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -3e-71) tmp = 1.0 / (d / b); elseif (d <= 7.4e-82) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -3e-71], N[(1.0 / N[(d / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7.4e-82], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3 \cdot 10^{-71}:\\
\;\;\;\;\frac{1}{\frac{d}{b}}\\
\mathbf{elif}\;d \leq 7.4 \cdot 10^{-82}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -3.0000000000000001e-71Initial program 51.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6451.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6451.9
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6451.9
Applied rewrites51.9%
Taylor expanded in c around 0
lower-/.f6472.7
Applied rewrites72.7%
Applied rewrites73.1%
if -3.0000000000000001e-71 < d < 7.4000000000000002e-82Initial program 71.4%
Taylor expanded in c around inf
lower-/.f6474.8
Applied rewrites74.8%
if 7.4000000000000002e-82 < d Initial program 52.8%
Taylor expanded in c around 0
lower-/.f6460.0
Applied rewrites60.0%
(FPCore (a b c d) :precision binary64 (if (<= d -3e-71) (/ b d) (if (<= d 7.4e-82) (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3e-71) {
tmp = b / d;
} else if (d <= 7.4e-82) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-3d-71)) then
tmp = b / d
else if (d <= 7.4d-82) then
tmp = a / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3e-71) {
tmp = b / d;
} else if (d <= 7.4e-82) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -3e-71: tmp = b / d elif d <= 7.4e-82: tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -3e-71) tmp = Float64(b / d); elseif (d <= 7.4e-82) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -3e-71) tmp = b / d; elseif (d <= 7.4e-82) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -3e-71], N[(b / d), $MachinePrecision], If[LessEqual[d, 7.4e-82], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3 \cdot 10^{-71}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 7.4 \cdot 10^{-82}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -3.0000000000000001e-71 or 7.4000000000000002e-82 < d Initial program 52.4%
Taylor expanded in c around 0
lower-/.f6465.9
Applied rewrites65.9%
if -3.0000000000000001e-71 < d < 7.4000000000000002e-82Initial program 71.4%
Taylor expanded in c around inf
lower-/.f6474.8
Applied rewrites74.8%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 59.9%
Taylor expanded in c around inf
lower-/.f6440.6
Applied rewrites40.6%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\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}
\end{array}
herbie shell --seed 2024270
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(! :herbie-platform default (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))))