
(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 9 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 (/ (+ (* b d) (* c a)) (+ (* d d) (* c c))))
(t_1 (/ (fma (/ a d) c b) d)))
(if (<= d -9.8e+128)
t_1
(if (<= d -1.5e-101)
t_0
(if (<= d 4e-131)
(/ (fma b (/ d c) a) c)
(if (<= d 1.15e+89) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * d) + (c * a)) / ((d * d) + (c * c));
double t_1 = fma((a / d), c, b) / d;
double tmp;
if (d <= -9.8e+128) {
tmp = t_1;
} else if (d <= -1.5e-101) {
tmp = t_0;
} else if (d <= 4e-131) {
tmp = fma(b, (d / c), a) / c;
} else if (d <= 1.15e+89) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * d) + Float64(c * a)) / Float64(Float64(d * d) + Float64(c * c))) t_1 = Float64(fma(Float64(a / d), c, b) / d) tmp = 0.0 if (d <= -9.8e+128) tmp = t_1; elseif (d <= -1.5e-101) tmp = t_0; elseif (d <= 4e-131) tmp = Float64(fma(b, Float64(d / c), a) / c); elseif (d <= 1.15e+89) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * d), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -9.8e+128], t$95$1, If[LessEqual[d, -1.5e-101], t$95$0, If[LessEqual[d, 4e-131], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.15e+89], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot d + c \cdot a}{d \cdot d + c \cdot c}\\
t_1 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{if}\;d \leq -9.8 \cdot 10^{+128}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -1.5 \cdot 10^{-101}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 4 \cdot 10^{-131}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{elif}\;d \leq 1.15 \cdot 10^{+89}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -9.80000000000000035e128 or 1.1499999999999999e89 < d Initial program 33.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-/.f6485.0
Applied rewrites85.0%
if -9.80000000000000035e128 < d < -1.5000000000000002e-101 or 3.9999999999999999e-131 < d < 1.1499999999999999e89Initial program 79.8%
if -1.5000000000000002e-101 < d < 3.9999999999999999e-131Initial 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-/.f6493.5
Applied rewrites93.5%
Applied rewrites94.7%
Final simplification85.5%
(FPCore (a b c d) :precision binary64 (if (<= c -3e-34) (/ (fma b (/ d c) a) c) (if (<= c 1.25e-51) (/ (fma (/ c d) a b) d) (/ (fma (/ b c) d a) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3e-34) {
tmp = fma(b, (d / c), a) / c;
} else if (c <= 1.25e-51) {
tmp = fma((c / d), a, b) / d;
} else {
tmp = fma((b / c), d, a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -3e-34) tmp = Float64(fma(b, Float64(d / c), a) / c); elseif (c <= 1.25e-51) tmp = Float64(fma(Float64(c / d), a, b) / d); else tmp = Float64(fma(Float64(b / c), d, a) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -3e-34], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.25e-51], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3 \cdot 10^{-34}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{elif}\;c \leq 1.25 \cdot 10^{-51}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\end{array}
\end{array}
if c < -3e-34Initial program 51.2%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6476.4
Applied rewrites76.4%
Applied rewrites76.5%
if -3e-34 < c < 1.25000000000000001e-51Initial program 75.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-/.f6431.2
Applied rewrites31.2%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6482.1
Applied rewrites82.1%
if 1.25000000000000001e-51 < c Initial program 55.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-/.f6480.7
Applied rewrites80.7%
(FPCore (a b c d) :precision binary64 (if (<= c -3e-34) (/ (fma b (/ d c) a) c) (if (<= c 1.25e-51) (/ (fma (/ a d) c b) d) (/ (fma (/ b c) d a) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3e-34) {
tmp = fma(b, (d / c), a) / c;
} else if (c <= 1.25e-51) {
tmp = fma((a / d), c, b) / d;
} else {
tmp = fma((b / c), d, a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -3e-34) tmp = Float64(fma(b, Float64(d / c), a) / c); elseif (c <= 1.25e-51) tmp = Float64(fma(Float64(a / d), c, b) / d); else tmp = Float64(fma(Float64(b / c), d, a) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -3e-34], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.25e-51], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3 \cdot 10^{-34}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{elif}\;c \leq 1.25 \cdot 10^{-51}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\end{array}
\end{array}
if c < -3e-34Initial program 51.2%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6476.4
Applied rewrites76.4%
Applied rewrites76.5%
if -3e-34 < c < 1.25000000000000001e-51Initial program 75.1%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6480.9
Applied rewrites80.9%
if 1.25000000000000001e-51 < c Initial program 55.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-/.f6480.7
Applied rewrites80.7%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma b (/ d c) a) c))) (if (<= c -3e-34) t_0 (if (<= c 1.25e-51) (/ (fma (/ a d) c b) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(b, (d / c), a) / c;
double tmp;
if (c <= -3e-34) {
tmp = t_0;
} else if (c <= 1.25e-51) {
tmp = fma((a / d), c, b) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(b, Float64(d / c), a) / c) tmp = 0.0 if (c <= -3e-34) tmp = t_0; elseif (c <= 1.25e-51) tmp = Float64(fma(Float64(a / d), c, b) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3e-34], t$95$0, If[LessEqual[c, 1.25e-51], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -3 \cdot 10^{-34}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.25 \cdot 10^{-51}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3e-34 or 1.25000000000000001e-51 < c Initial program 53.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-/.f6478.5
Applied rewrites78.5%
Applied rewrites77.9%
if -3e-34 < c < 1.25000000000000001e-51Initial program 75.1%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6480.9
Applied rewrites80.9%
(FPCore (a b c d) :precision binary64 (if (<= d -5.25e+39) (/ b d) (if (<= d 2.05e+124) (/ (fma b (/ d c) a) c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -5.25e+39) {
tmp = b / d;
} else if (d <= 2.05e+124) {
tmp = fma(b, (d / c), a) / c;
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -5.25e+39) tmp = Float64(b / d); elseif (d <= 2.05e+124) tmp = Float64(fma(b, Float64(d / c), a) / c); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -5.25e+39], N[(b / d), $MachinePrecision], If[LessEqual[d, 2.05e+124], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.25 \cdot 10^{+39}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 2.05 \cdot 10^{+124}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -5.25000000000000025e39 or 2.05000000000000001e124 < d Initial program 45.7%
Taylor expanded in c around 0
lower-/.f6474.4
Applied rewrites74.4%
if -5.25000000000000025e39 < d < 2.05000000000000001e124Initial program 73.3%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6474.6
Applied rewrites74.6%
Applied rewrites75.2%
(FPCore (a b c d)
:precision binary64
(if (<= d -2e+41)
(/ b d)
(if (<= d -1.4e-61)
(/ (fma c a (* b d)) (* d d))
(if (<= d 1.75e+91) (/ a c) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2e+41) {
tmp = b / d;
} else if (d <= -1.4e-61) {
tmp = fma(c, a, (b * d)) / (d * d);
} else if (d <= 1.75e+91) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -2e+41) tmp = Float64(b / d); elseif (d <= -1.4e-61) tmp = Float64(fma(c, a, Float64(b * d)) / Float64(d * d)); elseif (d <= 1.75e+91) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -2e+41], N[(b / d), $MachinePrecision], If[LessEqual[d, -1.4e-61], N[(N[(c * a + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.75e+91], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2 \cdot 10^{+41}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -1.4 \cdot 10^{-61}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{d \cdot d}\\
\mathbf{elif}\;d \leq 1.75 \cdot 10^{+91}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -2.00000000000000001e41 or 1.75e91 < d Initial program 45.0%
Taylor expanded in c around 0
lower-/.f6473.5
Applied rewrites73.5%
if -2.00000000000000001e41 < d < -1.4000000000000001e-61Initial program 78.6%
Taylor expanded in c around 0
*-commutativeN/A
lower-*.f6453.8
Applied rewrites53.8%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6441.1
Applied rewrites41.1%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6461.9
Applied rewrites61.9%
if -1.4000000000000001e-61 < d < 1.75e91Initial program 73.8%
Taylor expanded in c around inf
lower-/.f6463.1
Applied rewrites63.1%
Final simplification66.9%
(FPCore (a b c d)
:precision binary64
(if (<= d -2.85e+163)
(/ b d)
(if (<= d -1.6e-57)
(/ (* b d) (fma d d (* c c)))
(if (<= d 1.75e+91) (/ a c) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.85e+163) {
tmp = b / d;
} else if (d <= -1.6e-57) {
tmp = (b * d) / fma(d, d, (c * c));
} else if (d <= 1.75e+91) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -2.85e+163) tmp = Float64(b / d); elseif (d <= -1.6e-57) tmp = Float64(Float64(b * d) / fma(d, d, Float64(c * c))); elseif (d <= 1.75e+91) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.85e+163], N[(b / d), $MachinePrecision], If[LessEqual[d, -1.6e-57], N[(N[(b * d), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.75e+91], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.85 \cdot 10^{+163}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -1.6 \cdot 10^{-57}:\\
\;\;\;\;\frac{b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;d \leq 1.75 \cdot 10^{+91}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -2.8499999999999999e163 or 1.75e91 < d Initial program 33.8%
Taylor expanded in c around 0
lower-/.f6479.4
Applied rewrites79.4%
if -2.8499999999999999e163 < d < -1.6e-57Initial program 74.6%
Taylor expanded in c around 0
*-commutativeN/A
lower-*.f6461.1
Applied rewrites61.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6461.1
Applied rewrites61.1%
if -1.6e-57 < d < 1.75e91Initial program 73.9%
Taylor expanded in c around inf
lower-/.f6462.7
Applied rewrites62.7%
Final simplification66.8%
(FPCore (a b c d) :precision binary64 (if (<= c -3.65e-38) (/ a c) (if (<= c 1.22e-51) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.65e-38) {
tmp = a / c;
} else if (c <= 1.22e-51) {
tmp = b / d;
} else {
tmp = a / c;
}
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 (c <= (-3.65d-38)) then
tmp = a / c
else if (c <= 1.22d-51) then
tmp = b / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.65e-38) {
tmp = a / c;
} else if (c <= 1.22e-51) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3.65e-38: tmp = a / c elif c <= 1.22e-51: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3.65e-38) tmp = Float64(a / c); elseif (c <= 1.22e-51) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -3.65e-38) tmp = a / c; elseif (c <= 1.22e-51) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.65e-38], N[(a / c), $MachinePrecision], If[LessEqual[c, 1.22e-51], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.65 \cdot 10^{-38}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 1.22 \cdot 10^{-51}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -3.65e-38 or 1.21999999999999998e-51 < c Initial program 53.4%
Taylor expanded in c around inf
lower-/.f6461.2
Applied rewrites61.2%
if -3.65e-38 < c < 1.21999999999999998e-51Initial program 74.9%
Taylor expanded in c around 0
lower-/.f6469.6
Applied rewrites69.6%
(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 63.4%
Taylor expanded in c around inf
lower-/.f6442.7
Applied rewrites42.7%
(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 2024249
(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))))