
(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 11 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 d d (* c c))))
(if (<= d -2.9e+112)
(/ (fma (/ a d) c b) d)
(if (<= d -6.2e-156)
(fma a (/ c t_0) (* d (/ b t_0)))
(if (<= d 6.2e-154)
(/ (fma (/ d c) b a) c)
(if (<= d 4.1e+94)
(/ (fma d b (* c a)) t_0)
(/ (fma a (/ c d) b) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double tmp;
if (d <= -2.9e+112) {
tmp = fma((a / d), c, b) / d;
} else if (d <= -6.2e-156) {
tmp = fma(a, (c / t_0), (d * (b / t_0)));
} else if (d <= 6.2e-154) {
tmp = fma((d / c), b, a) / c;
} else if (d <= 4.1e+94) {
tmp = fma(d, b, (c * a)) / t_0;
} else {
tmp = fma(a, (c / d), b) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) tmp = 0.0 if (d <= -2.9e+112) tmp = Float64(fma(Float64(a / d), c, b) / d); elseif (d <= -6.2e-156) tmp = fma(a, Float64(c / t_0), Float64(d * Float64(b / t_0))); elseif (d <= 6.2e-154) tmp = Float64(fma(Float64(d / c), b, a) / c); elseif (d <= 4.1e+94) tmp = Float64(fma(d, b, Float64(c * a)) / t_0); else tmp = Float64(fma(a, Float64(c / d), b) / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.9e+112], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -6.2e-156], N[(a * N[(c / t$95$0), $MachinePrecision] + N[(d * N[(b / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6.2e-154], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 4.1e+94], N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
\mathbf{if}\;d \leq -2.9 \cdot 10^{+112}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{elif}\;d \leq -6.2 \cdot 10^{-156}:\\
\;\;\;\;\mathsf{fma}\left(a, \frac{c}{t\_0}, d \cdot \frac{b}{t\_0}\right)\\
\mathbf{elif}\;d \leq 6.2 \cdot 10^{-154}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{elif}\;d \leq 4.1 \cdot 10^{+94}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\end{array}
\end{array}
if d < -2.9000000000000002e112Initial program 32.2%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6480.2
Applied rewrites80.2%
if -2.9000000000000002e112 < d < -6.1999999999999996e-156Initial program 81.9%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6487.7
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6487.7
Applied rewrites87.7%
if -6.1999999999999996e-156 < d < 6.19999999999999963e-154Initial program 72.2%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6468.9
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6468.9
Applied rewrites68.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6492.9
Applied rewrites92.9%
if 6.19999999999999963e-154 < d < 4.10000000000000031e94Initial program 80.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6480.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6480.9
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6480.9
Applied rewrites80.9%
if 4.10000000000000031e94 < d Initial program 31.6%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6486.3
Applied rewrites86.3%
Applied rewrites86.5%
Final simplification86.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma d b (* c a)) (* d d))))
(if (<= d -1.9e+152)
(/ b d)
(if (<= d -2.65e-87)
t_0
(if (<= d -2.2e-156)
(* (/ c (fma d d (* c c))) a)
(if (<= d 4.8e-115)
(/ (fma c a (* d b)) (* c c))
(if (<= d 1.06e+97) t_0 (/ b d))))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, b, (c * a)) / (d * d);
double tmp;
if (d <= -1.9e+152) {
tmp = b / d;
} else if (d <= -2.65e-87) {
tmp = t_0;
} else if (d <= -2.2e-156) {
tmp = (c / fma(d, d, (c * c))) * a;
} else if (d <= 4.8e-115) {
tmp = fma(c, a, (d * b)) / (c * c);
} else if (d <= 1.06e+97) {
tmp = t_0;
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(d, b, Float64(c * a)) / Float64(d * d)) tmp = 0.0 if (d <= -1.9e+152) tmp = Float64(b / d); elseif (d <= -2.65e-87) tmp = t_0; elseif (d <= -2.2e-156) tmp = Float64(Float64(c / fma(d, d, Float64(c * c))) * a); elseif (d <= 4.8e-115) tmp = Float64(fma(c, a, Float64(d * b)) / Float64(c * c)); elseif (d <= 1.06e+97) tmp = t_0; else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.9e+152], N[(b / d), $MachinePrecision], If[LessEqual[d, -2.65e-87], t$95$0, If[LessEqual[d, -2.2e-156], N[(N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision], If[LessEqual[d, 4.8e-115], N[(N[(c * a + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.06e+97], t$95$0, N[(b / d), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{d \cdot d}\\
\mathbf{if}\;d \leq -1.9 \cdot 10^{+152}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -2.65 \cdot 10^{-87}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -2.2 \cdot 10^{-156}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\
\mathbf{elif}\;d \leq 4.8 \cdot 10^{-115}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, a, d \cdot b\right)}{c \cdot c}\\
\mathbf{elif}\;d \leq 1.06 \cdot 10^{+97}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.9e152 or 1.05999999999999994e97 < d Initial program 27.0%
Taylor expanded in c around 0
lower-/.f6466.3
Applied rewrites66.3%
if -1.9e152 < d < -2.64999999999999993e-87 or 4.80000000000000042e-115 < d < 1.05999999999999994e97Initial program 80.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6480.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6480.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6480.5
Applied rewrites80.5%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6463.4
Applied rewrites63.4%
if -2.64999999999999993e-87 < d < -2.1999999999999999e-156Initial program 72.3%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6492.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6492.4
Applied rewrites92.4%
Taylor expanded in a around inf
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6478.8
Applied rewrites78.8%
if -2.1999999999999999e-156 < d < 4.80000000000000042e-115Initial program 74.7%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6472.2
Applied rewrites72.2%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6472.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6472.2
Applied rewrites72.2%
Final simplification67.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma d d (* c c))))
(if (<= d -3.6e+68)
(/ (fma (/ a d) c b) d)
(if (<= d -6.2e-156)
(* (/ (fma b (/ d a) c) t_0) a)
(if (<= d 6.2e-154)
(/ (fma (/ d c) b a) c)
(if (<= d 4.1e+94)
(/ (fma d b (* c a)) t_0)
(/ (fma a (/ c d) b) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double tmp;
if (d <= -3.6e+68) {
tmp = fma((a / d), c, b) / d;
} else if (d <= -6.2e-156) {
tmp = (fma(b, (d / a), c) / t_0) * a;
} else if (d <= 6.2e-154) {
tmp = fma((d / c), b, a) / c;
} else if (d <= 4.1e+94) {
tmp = fma(d, b, (c * a)) / t_0;
} else {
tmp = fma(a, (c / d), b) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) tmp = 0.0 if (d <= -3.6e+68) tmp = Float64(fma(Float64(a / d), c, b) / d); elseif (d <= -6.2e-156) tmp = Float64(Float64(fma(b, Float64(d / a), c) / t_0) * a); elseif (d <= 6.2e-154) tmp = Float64(fma(Float64(d / c), b, a) / c); elseif (d <= 4.1e+94) tmp = Float64(fma(d, b, Float64(c * a)) / t_0); else tmp = Float64(fma(a, Float64(c / d), b) / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3.6e+68], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -6.2e-156], N[(N[(N[(b * N[(d / a), $MachinePrecision] + c), $MachinePrecision] / t$95$0), $MachinePrecision] * a), $MachinePrecision], If[LessEqual[d, 6.2e-154], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 4.1e+94], N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
\mathbf{if}\;d \leq -3.6 \cdot 10^{+68}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{elif}\;d \leq -6.2 \cdot 10^{-156}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{t\_0} \cdot a\\
\mathbf{elif}\;d \leq 6.2 \cdot 10^{-154}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{elif}\;d \leq 4.1 \cdot 10^{+94}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\end{array}
\end{array}
if d < -3.5999999999999999e68Initial program 41.5%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6479.3
Applied rewrites79.3%
if -3.5999999999999999e68 < d < -6.1999999999999996e-156Initial program 83.8%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6488.9
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6488.9
Applied rewrites88.9%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
associate-/r*N/A
div-add-revN/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6489.1
Applied rewrites89.1%
if -6.1999999999999996e-156 < d < 6.19999999999999963e-154Initial program 72.2%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6468.9
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6468.9
Applied rewrites68.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6492.9
Applied rewrites92.9%
if 6.19999999999999963e-154 < d < 4.10000000000000031e94Initial program 80.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6480.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6480.9
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6480.9
Applied rewrites80.9%
if 4.10000000000000031e94 < d Initial program 31.6%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6486.3
Applied rewrites86.3%
Applied rewrites86.5%
Final simplification85.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma d b (* c a)) (fma d d (* c c)))))
(if (<= d -9.5e+75)
(/ (fma (/ a d) c b) d)
(if (<= d -1.9e-132)
t_0
(if (<= d 6.2e-154)
(/ (fma (/ d c) b a) c)
(if (<= d 4.1e+94) t_0 (/ (fma a (/ c d) b) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, b, (c * a)) / fma(d, d, (c * c));
double tmp;
if (d <= -9.5e+75) {
tmp = fma((a / d), c, b) / d;
} else if (d <= -1.9e-132) {
tmp = t_0;
} else if (d <= 6.2e-154) {
tmp = fma((d / c), b, a) / c;
} else if (d <= 4.1e+94) {
tmp = t_0;
} else {
tmp = fma(a, (c / d), b) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(d, b, Float64(c * a)) / fma(d, d, Float64(c * c))) tmp = 0.0 if (d <= -9.5e+75) tmp = Float64(fma(Float64(a / d), c, b) / d); elseif (d <= -1.9e-132) tmp = t_0; elseif (d <= 6.2e-154) tmp = Float64(fma(Float64(d / c), b, a) / c); elseif (d <= 4.1e+94) tmp = t_0; else tmp = Float64(fma(a, Float64(c / d), b) / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -9.5e+75], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -1.9e-132], t$95$0, If[LessEqual[d, 6.2e-154], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 4.1e+94], t$95$0, N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{if}\;d \leq -9.5 \cdot 10^{+75}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{elif}\;d \leq -1.9 \cdot 10^{-132}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 6.2 \cdot 10^{-154}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{elif}\;d \leq 4.1 \cdot 10^{+94}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\end{array}
\end{array}
if d < -9.50000000000000061e75Initial program 40.5%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6478.9
Applied rewrites78.9%
if -9.50000000000000061e75 < d < -1.8999999999999998e-132 or 6.19999999999999963e-154 < d < 4.10000000000000031e94Initial program 83.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6483.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6483.7
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6483.7
Applied rewrites83.7%
if -1.8999999999999998e-132 < d < 6.19999999999999963e-154Initial program 71.0%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6470.7
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6470.7
Applied rewrites70.7%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6490.6
Applied rewrites90.6%
if 4.10000000000000031e94 < d Initial program 31.6%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6486.3
Applied rewrites86.3%
Applied rewrites86.5%
Final simplification85.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma d d (* c c))))
(if (<= d -1.1e-25)
(/ b d)
(if (<= d -2.2e-156)
(* (/ c t_0) a)
(if (<= d 1.16e-104)
(/ (fma c a (* d b)) (* c c))
(if (<= d 6.9e+137) (* (/ d t_0) b) (/ b d)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double tmp;
if (d <= -1.1e-25) {
tmp = b / d;
} else if (d <= -2.2e-156) {
tmp = (c / t_0) * a;
} else if (d <= 1.16e-104) {
tmp = fma(c, a, (d * b)) / (c * c);
} else if (d <= 6.9e+137) {
tmp = (d / t_0) * b;
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) tmp = 0.0 if (d <= -1.1e-25) tmp = Float64(b / d); elseif (d <= -2.2e-156) tmp = Float64(Float64(c / t_0) * a); elseif (d <= 1.16e-104) tmp = Float64(fma(c, a, Float64(d * b)) / Float64(c * c)); elseif (d <= 6.9e+137) tmp = Float64(Float64(d / t_0) * b); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.1e-25], N[(b / d), $MachinePrecision], If[LessEqual[d, -2.2e-156], N[(N[(c / t$95$0), $MachinePrecision] * a), $MachinePrecision], If[LessEqual[d, 1.16e-104], N[(N[(c * a + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6.9e+137], N[(N[(d / t$95$0), $MachinePrecision] * b), $MachinePrecision], N[(b / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
\mathbf{if}\;d \leq -1.1 \cdot 10^{-25}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -2.2 \cdot 10^{-156}:\\
\;\;\;\;\frac{c}{t\_0} \cdot a\\
\mathbf{elif}\;d \leq 1.16 \cdot 10^{-104}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, a, d \cdot b\right)}{c \cdot c}\\
\mathbf{elif}\;d \leq 6.9 \cdot 10^{+137}:\\
\;\;\;\;\frac{d}{t\_0} \cdot b\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.1000000000000001e-25 or 6.90000000000000039e137 < d Initial program 45.0%
Taylor expanded in c around 0
lower-/.f6462.2
Applied rewrites62.2%
if -1.1000000000000001e-25 < d < -2.1999999999999999e-156Initial program 79.5%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6494.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6494.4
Applied rewrites94.4%
Taylor expanded in a around inf
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6474.2
Applied rewrites74.2%
if -2.1999999999999999e-156 < d < 1.16000000000000001e-104Initial program 75.3%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6470.5
Applied rewrites70.5%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6470.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6470.5
Applied rewrites70.5%
if 1.16000000000000001e-104 < d < 6.90000000000000039e137Initial program 71.4%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6474.0
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6474.0
Applied rewrites74.0%
Taylor expanded in a around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6454.0
Applied rewrites54.0%
Final simplification63.9%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.9e+152)
(/ b d)
(if (<= d -6.8e-46)
(/ (fma d b (* c a)) (* d d))
(if (<= d 1.55e+63) (/ (fma (/ d c) b a) c) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.9e+152) {
tmp = b / d;
} else if (d <= -6.8e-46) {
tmp = fma(d, b, (c * a)) / (d * d);
} else if (d <= 1.55e+63) {
tmp = fma((d / c), b, a) / c;
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -1.9e+152) tmp = Float64(b / d); elseif (d <= -6.8e-46) tmp = Float64(fma(d, b, Float64(c * a)) / Float64(d * d)); elseif (d <= 1.55e+63) tmp = Float64(fma(Float64(d / c), b, a) / c); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.9e+152], N[(b / d), $MachinePrecision], If[LessEqual[d, -6.8e-46], N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.55e+63], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.9 \cdot 10^{+152}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -6.8 \cdot 10^{-46}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{d \cdot d}\\
\mathbf{elif}\;d \leq 1.55 \cdot 10^{+63}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.9e152 or 1.55e63 < d Initial program 32.2%
Taylor expanded in c around 0
lower-/.f6465.4
Applied rewrites65.4%
if -1.9e152 < d < -6.79999999999999992e-46Initial program 81.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6481.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6481.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6481.4
Applied rewrites81.4%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6469.9
Applied rewrites69.9%
if -6.79999999999999992e-46 < d < 1.55e63Initial program 74.9%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6474.2
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6474.2
Applied rewrites74.2%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6477.4
Applied rewrites77.4%
Final simplification72.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -6.8e-46) (not (<= d 4.5e+62))) (/ (fma a (/ c d) b) d) (/ (fma (/ d c) b a) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.8e-46) || !(d <= 4.5e+62)) {
tmp = fma(a, (c / d), b) / d;
} else {
tmp = fma((d / c), b, a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -6.8e-46) || !(d <= 4.5e+62)) tmp = Float64(fma(a, Float64(c / d), b) / d); else tmp = Float64(fma(Float64(d / c), b, a) / c); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6.8e-46], N[Not[LessEqual[d, 4.5e+62]], $MachinePrecision]], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.8 \cdot 10^{-46} \lor \neg \left(d \leq 4.5 \cdot 10^{+62}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\end{array}
\end{array}
if d < -6.79999999999999992e-46 or 4.49999999999999999e62 < d Initial program 49.4%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6479.6
Applied rewrites79.6%
Applied rewrites80.3%
if -6.79999999999999992e-46 < d < 4.49999999999999999e62Initial program 74.9%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6474.2
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6474.2
Applied rewrites74.2%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6477.4
Applied rewrites77.4%
Final simplification78.9%
(FPCore (a b c d) :precision binary64 (if (<= c -1.65e-22) (/ (fma (/ d c) b a) c) (if (<= c 9500.0) (/ (fma a (/ c d) b) d) (/ (fma (/ b c) d a) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.65e-22) {
tmp = fma((d / c), b, a) / c;
} else if (c <= 9500.0) {
tmp = fma(a, (c / d), b) / d;
} else {
tmp = fma((b / c), d, a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.65e-22) tmp = Float64(fma(Float64(d / c), b, a) / c); elseif (c <= 9500.0) tmp = Float64(fma(a, Float64(c / d), b) / d); else tmp = Float64(fma(Float64(b / c), d, a) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.65e-22], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 9500.0], N[(N[(a * N[(c / d), $MachinePrecision] + 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 -1.65 \cdot 10^{-22}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{elif}\;c \leq 9500:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\end{array}
\end{array}
if c < -1.65e-22Initial program 51.2%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6456.6
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6456.6
Applied rewrites56.6%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6474.4
Applied rewrites74.4%
if -1.65e-22 < c < 9500Initial program 73.7%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6480.1
Applied rewrites80.1%
Applied rewrites84.2%
if 9500 < c Initial program 47.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-/.f6472.6
Applied rewrites72.6%
Final simplification79.1%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.1e-25)
(/ b d)
(if (<= d -1.6e-155)
(* (/ c (fma d d (* c c))) a)
(if (<= d 1.32e+19) (/ a c) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.1e-25) {
tmp = b / d;
} else if (d <= -1.6e-155) {
tmp = (c / fma(d, d, (c * c))) * a;
} else if (d <= 1.32e+19) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -1.1e-25) tmp = Float64(b / d); elseif (d <= -1.6e-155) tmp = Float64(Float64(c / fma(d, d, Float64(c * c))) * a); elseif (d <= 1.32e+19) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.1e-25], N[(b / d), $MachinePrecision], If[LessEqual[d, -1.6e-155], N[(N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision], If[LessEqual[d, 1.32e+19], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.1 \cdot 10^{-25}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -1.6 \cdot 10^{-155}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\
\mathbf{elif}\;d \leq 1.32 \cdot 10^{+19}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.1000000000000001e-25 or 1.32e19 < d Initial program 49.1%
Taylor expanded in c around 0
lower-/.f6460.3
Applied rewrites60.3%
if -1.1000000000000001e-25 < d < -1.60000000000000006e-155Initial program 79.5%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6494.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6494.4
Applied rewrites94.4%
Taylor expanded in a around inf
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6474.2
Applied rewrites74.2%
if -1.60000000000000006e-155 < d < 1.32e19Initial program 75.7%
Taylor expanded in c around inf
lower-/.f6462.6
Applied rewrites62.6%
Final simplification62.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2e-32) (not (<= c 3.1e-40))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2e-32) || !(c <= 3.1e-40)) {
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 ((c <= (-2d-32)) .or. (.not. (c <= 3.1d-40))) 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 ((c <= -2e-32) || !(c <= 3.1e-40)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2e-32) or not (c <= 3.1e-40): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2e-32) || !(c <= 3.1e-40)) 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 ((c <= -2e-32) || ~((c <= 3.1e-40))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2e-32], N[Not[LessEqual[c, 3.1e-40]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2 \cdot 10^{-32} \lor \neg \left(c \leq 3.1 \cdot 10^{-40}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -2.00000000000000011e-32 or 3.10000000000000011e-40 < c Initial program 52.7%
Taylor expanded in c around inf
lower-/.f6457.4
Applied rewrites57.4%
if -2.00000000000000011e-32 < c < 3.10000000000000011e-40Initial program 72.8%
Taylor expanded in c around 0
lower-/.f6461.7
Applied rewrites61.7%
Final simplification59.4%
(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 62.1%
Taylor expanded in c around inf
lower-/.f6438.4
Applied rewrites38.4%
(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 2024332
(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))))