
(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 8 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 -0.0001107)
t_0
(if (<= d 9.5e-64)
(/ (- a (/ (fma (- b) d (/ (* (* d d) a) c)) c)) c)
(if (<= d 1.85e+75) (/ (+ (* b d) (* c a)) (+ (* c c) (* d d))) 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 <= -0.0001107) {
tmp = t_0;
} else if (d <= 9.5e-64) {
tmp = (a - (fma(-b, d, (((d * d) * a) / c)) / c)) / c;
} else if (d <= 1.85e+75) {
tmp = ((b * d) + (c * a)) / ((c * c) + (d * d));
} 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 <= -0.0001107) tmp = t_0; elseif (d <= 9.5e-64) tmp = Float64(Float64(a - Float64(fma(Float64(-b), d, Float64(Float64(Float64(d * d) * a) / c)) / c)) / c); elseif (d <= 1.85e+75) tmp = Float64(Float64(Float64(b * d) + Float64(c * a)) / Float64(Float64(c * c) + Float64(d * d))); 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, -0.0001107], t$95$0, If[LessEqual[d, 9.5e-64], 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, 1.85e+75], N[(N[(N[(b * d), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $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 -0.0001107:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 9.5 \cdot 10^{-64}:\\
\;\;\;\;\frac{a - \frac{\mathsf{fma}\left(-b, d, \frac{\left(d \cdot d\right) \cdot a}{c}\right)}{c}}{c}\\
\mathbf{elif}\;d \leq 1.85 \cdot 10^{+75}:\\
\;\;\;\;\frac{b \cdot d + c \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.10699999999999994e-4 or 1.85000000000000005e75 < d Initial program 55.2%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6486.5
Applied rewrites86.5%
if -1.10699999999999994e-4 < d < 9.50000000000000043e-64Initial program 70.1%
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 rewrites91.6%
if 9.50000000000000043e-64 < d < 1.85000000000000005e75Initial program 91.3%
Final simplification89.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ a d) c b) d)))
(if (<= d -0.0001107)
t_0
(if (<= d 9.5e-64)
(/ (fma (/ b c) d a) c)
(if (<= d 1.85e+75) (/ (+ (* b d) (* c a)) (+ (* c c) (* d d))) 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 <= -0.0001107) {
tmp = t_0;
} else if (d <= 9.5e-64) {
tmp = fma((b / c), d, a) / c;
} else if (d <= 1.85e+75) {
tmp = ((b * d) + (c * a)) / ((c * c) + (d * d));
} 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 <= -0.0001107) tmp = t_0; elseif (d <= 9.5e-64) tmp = Float64(fma(Float64(b / c), d, a) / c); elseif (d <= 1.85e+75) tmp = Float64(Float64(Float64(b * d) + Float64(c * a)) / Float64(Float64(c * c) + Float64(d * d))); 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, -0.0001107], t$95$0, If[LessEqual[d, 9.5e-64], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.85e+75], N[(N[(N[(b * d), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $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 -0.0001107:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 9.5 \cdot 10^{-64}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{elif}\;d \leq 1.85 \cdot 10^{+75}:\\
\;\;\;\;\frac{b \cdot d + c \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.10699999999999994e-4 or 1.85000000000000005e75 < d Initial program 55.2%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6486.5
Applied rewrites86.5%
if -1.10699999999999994e-4 < d < 9.50000000000000043e-64Initial program 70.1%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6490.9
Applied rewrites90.9%
if 9.50000000000000043e-64 < d < 1.85000000000000005e75Initial program 91.3%
Final simplification88.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma c a (* b d))))
(if (<= d -0.0001107)
(/ b d)
(if (<= d 8.8e-244)
(/ a c)
(if (<= d 2.15e-44)
(/ t_0 (* c c))
(if (<= d 4.4e+155) (/ t_0 (* d d)) (/ b d)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(c, a, (b * d));
double tmp;
if (d <= -0.0001107) {
tmp = b / d;
} else if (d <= 8.8e-244) {
tmp = a / c;
} else if (d <= 2.15e-44) {
tmp = t_0 / (c * c);
} else if (d <= 4.4e+155) {
tmp = t_0 / (d * d);
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(c, a, Float64(b * d)) tmp = 0.0 if (d <= -0.0001107) tmp = Float64(b / d); elseif (d <= 8.8e-244) tmp = Float64(a / c); elseif (d <= 2.15e-44) tmp = Float64(t_0 / Float64(c * c)); elseif (d <= 4.4e+155) tmp = Float64(t_0 / Float64(d * d)); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(c * a + N[(b * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -0.0001107], N[(b / d), $MachinePrecision], If[LessEqual[d, 8.8e-244], N[(a / c), $MachinePrecision], If[LessEqual[d, 2.15e-44], N[(t$95$0 / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.4e+155], N[(t$95$0 / N[(d * d), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, a, b \cdot d\right)\\
\mathbf{if}\;d \leq -0.0001107:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 8.8 \cdot 10^{-244}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 2.15 \cdot 10^{-44}:\\
\;\;\;\;\frac{t\_0}{c \cdot c}\\
\mathbf{elif}\;d \leq 4.4 \cdot 10^{+155}:\\
\;\;\;\;\frac{t\_0}{d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.10699999999999994e-4 or 4.4000000000000005e155 < d Initial program 53.5%
Taylor expanded in c around 0
lower-/.f6478.6
Applied rewrites78.6%
if -1.10699999999999994e-4 < d < 8.79999999999999939e-244Initial program 64.8%
Taylor expanded in c around inf
lower-/.f6472.8
Applied rewrites72.8%
if 8.79999999999999939e-244 < d < 2.15000000000000007e-44Initial program 80.8%
Taylor expanded in d around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f6488.8
Applied rewrites88.8%
Taylor expanded in c around 0
Applied rewrites73.9%
if 2.15000000000000007e-44 < d < 4.4000000000000005e155Initial program 79.7%
Taylor expanded in c around inf
lower-/.f6433.1
Applied rewrites33.1%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6466.6
Applied rewrites66.6%
Taylor expanded in d around 0
Applied rewrites65.9%
Final simplification74.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ a d) c b) d)))
(if (<= d -0.0001107)
t_0
(if (<= d 8.8e-244)
(/ a c)
(if (<= d 2.15e-44) (/ (fma c a (* b 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 <= -0.0001107) {
tmp = t_0;
} else if (d <= 8.8e-244) {
tmp = a / c;
} else if (d <= 2.15e-44) {
tmp = fma(c, a, (b * 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 <= -0.0001107) tmp = t_0; elseif (d <= 8.8e-244) tmp = Float64(a / c); elseif (d <= 2.15e-44) tmp = Float64(fma(c, a, Float64(b * 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, -0.0001107], t$95$0, If[LessEqual[d, 8.8e-244], N[(a / c), $MachinePrecision], If[LessEqual[d, 2.15e-44], N[(N[(c * a + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c), $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 -0.0001107:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 8.8 \cdot 10^{-244}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 2.15 \cdot 10^{-44}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.10699999999999994e-4 or 2.15000000000000007e-44 < d Initial program 59.9%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6483.5
Applied rewrites83.5%
if -1.10699999999999994e-4 < d < 8.79999999999999939e-244Initial program 64.8%
Taylor expanded in c around inf
lower-/.f6472.8
Applied rewrites72.8%
if 8.79999999999999939e-244 < d < 2.15000000000000007e-44Initial program 80.8%
Taylor expanded in d around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f6488.8
Applied rewrites88.8%
Taylor expanded in c around 0
Applied rewrites73.9%
Final simplification78.8%
(FPCore (a b c d)
:precision binary64
(if (<= d -0.0001107)
(/ b d)
(if (<= d 8.8e-244)
(/ a c)
(if (<= d 1.2e-42) (/ (fma c a (* b d)) (* c c)) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -0.0001107) {
tmp = b / d;
} else if (d <= 8.8e-244) {
tmp = a / c;
} else if (d <= 1.2e-42) {
tmp = fma(c, a, (b * d)) / (c * c);
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -0.0001107) tmp = Float64(b / d); elseif (d <= 8.8e-244) tmp = Float64(a / c); elseif (d <= 1.2e-42) tmp = Float64(fma(c, a, Float64(b * d)) / Float64(c * c)); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -0.0001107], N[(b / d), $MachinePrecision], If[LessEqual[d, 8.8e-244], N[(a / c), $MachinePrecision], If[LessEqual[d, 1.2e-42], N[(N[(c * a + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.0001107:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 8.8 \cdot 10^{-244}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 1.2 \cdot 10^{-42}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.10699999999999994e-4 or 1.20000000000000001e-42 < d Initial program 59.9%
Taylor expanded in c around 0
lower-/.f6469.3
Applied rewrites69.3%
if -1.10699999999999994e-4 < d < 8.79999999999999939e-244Initial program 64.8%
Taylor expanded in c around inf
lower-/.f6472.8
Applied rewrites72.8%
if 8.79999999999999939e-244 < d < 1.20000000000000001e-42Initial program 80.8%
Taylor expanded in d around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f6488.8
Applied rewrites88.8%
Taylor expanded in c around 0
Applied rewrites73.9%
Final simplification71.1%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma (/ a d) c b) d))) (if (<= d -0.0001107) t_0 (if (<= d 1.2e-42) (/ (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 <= -0.0001107) {
tmp = t_0;
} else if (d <= 1.2e-42) {
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 <= -0.0001107) tmp = t_0; elseif (d <= 1.2e-42) 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, -0.0001107], t$95$0, If[LessEqual[d, 1.2e-42], 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 -0.0001107:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.2 \cdot 10^{-42}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.10699999999999994e-4 or 1.20000000000000001e-42 < d Initial program 59.9%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6483.5
Applied rewrites83.5%
if -1.10699999999999994e-4 < d < 1.20000000000000001e-42Initial program 71.1%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6490.0
Applied rewrites90.0%
(FPCore (a b c d) :precision binary64 (if (<= d -0.0001107) (/ b d) (if (<= d 1.15e-54) (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -0.0001107) {
tmp = b / d;
} else if (d <= 1.15e-54) {
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 <= (-0.0001107d0)) then
tmp = b / d
else if (d <= 1.15d-54) 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 <= -0.0001107) {
tmp = b / d;
} else if (d <= 1.15e-54) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -0.0001107: tmp = b / d elif d <= 1.15e-54: tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -0.0001107) tmp = Float64(b / d); elseif (d <= 1.15e-54) 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 <= -0.0001107) tmp = b / d; elseif (d <= 1.15e-54) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -0.0001107], N[(b / d), $MachinePrecision], If[LessEqual[d, 1.15e-54], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.0001107:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 1.15 \cdot 10^{-54}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.10699999999999994e-4 or 1.1499999999999999e-54 < d Initial program 60.2%
Taylor expanded in c around 0
lower-/.f6468.9
Applied rewrites68.9%
if -1.10699999999999994e-4 < d < 1.1499999999999999e-54Initial program 70.9%
Taylor expanded in c around inf
lower-/.f6470.0
Applied rewrites70.0%
(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 65.0%
Taylor expanded in c around inf
lower-/.f6442.5
Applied rewrites42.5%
(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 2024235
(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))))