
(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 d d (* c c))) (t_1 (/ (fma (/ a d) c b) d)))
(if (<= d -5e+156)
t_1
(if (<= d -4e-73)
(fma a (/ c t_0) (* d (/ b t_0)))
(if (<= d 4.6e+48) (/ (fma (/ d c) b a) c) t_1)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = fma((a / d), c, b) / d;
double tmp;
if (d <= -5e+156) {
tmp = t_1;
} else if (d <= -4e-73) {
tmp = fma(a, (c / t_0), (d * (b / t_0)));
} else if (d <= 4.6e+48) {
tmp = fma((d / c), b, a) / c;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = Float64(fma(Float64(a / d), c, b) / d) tmp = 0.0 if (d <= -5e+156) tmp = t_1; elseif (d <= -4e-73) tmp = fma(a, Float64(c / t_0), Float64(d * Float64(b / t_0))); elseif (d <= 4.6e+48) tmp = Float64(fma(Float64(d / c), b, a) / c); else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -5e+156], t$95$1, If[LessEqual[d, -4e-73], N[(a * N[(c / t$95$0), $MachinePrecision] + N[(d * N[(b / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.6e+48], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{if}\;d \leq -5 \cdot 10^{+156}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -4 \cdot 10^{-73}:\\
\;\;\;\;\mathsf{fma}\left(a, \frac{c}{t\_0}, d \cdot \frac{b}{t\_0}\right)\\
\mathbf{elif}\;d \leq 4.6 \cdot 10^{+48}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -4.99999999999999992e156 or 4.6e48 < d Initial program 35.9%
Taylor expanded in c around 0
+-commutativeN/A
associate-*l/N/A
associate-*l/N/A
unpow2N/A
associate-/r*N/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6483.9
Applied rewrites83.9%
if -4.99999999999999992e156 < d < -3.99999999999999999e-73Initial program 72.5%
Applied rewrites77.8%
if -3.99999999999999999e-73 < d < 4.6e48Initial program 73.1%
Applied rewrites69.2%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6485.6
Applied rewrites85.6%
Final simplification83.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ a d) c b) d)))
(if (<= d -1.12e+83)
t_0
(if (<= d -1.9e-74)
(/ (fma c a (* d b)) (+ (* c c) (* d d)))
(if (<= d 4.6e+48) (/ (fma (/ d c) b 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 <= -1.12e+83) {
tmp = t_0;
} else if (d <= -1.9e-74) {
tmp = fma(c, a, (d * b)) / ((c * c) + (d * d));
} else if (d <= 4.6e+48) {
tmp = fma((d / c), b, 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 <= -1.12e+83) tmp = t_0; elseif (d <= -1.9e-74) tmp = Float64(fma(c, a, Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 4.6e+48) tmp = Float64(fma(Float64(d / c), b, 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, -1.12e+83], t$95$0, If[LessEqual[d, -1.9e-74], N[(N[(c * a + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.6e+48], N[(N[(N[(d / c), $MachinePrecision] * b + 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 -1.12 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.9 \cdot 10^{-74}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, a, d \cdot b\right)}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 4.6 \cdot 10^{+48}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.12e83 or 4.6e48 < d Initial program 40.6%
Taylor expanded in c around 0
+-commutativeN/A
associate-*l/N/A
associate-*l/N/A
unpow2N/A
associate-/r*N/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6481.6
Applied rewrites81.6%
if -1.12e83 < d < -1.8999999999999998e-74Initial program 78.1%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
*-commutativeN/A
remove-double-negN/A
*-commutativeN/A
lift-*.f64N/A
lower-fma.f6478.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6478.2
Applied rewrites78.2%
if -1.8999999999999998e-74 < d < 4.6e48Initial program 73.1%
Applied rewrites69.2%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6485.6
Applied rewrites85.6%
Final simplification83.0%
(FPCore (a b c d)
:precision binary64
(if (<= d -5e+156)
(/ b d)
(if (<= d -1.1e-26)
(* (/ d (fma d d (* c c))) b)
(if (<= d 4.4e+145) (/ (fma (/ d c) b a) c) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -5e+156) {
tmp = b / d;
} else if (d <= -1.1e-26) {
tmp = (d / fma(d, d, (c * c))) * b;
} else if (d <= 4.4e+145) {
tmp = fma((d / c), b, a) / c;
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -5e+156) tmp = Float64(b / d); elseif (d <= -1.1e-26) tmp = Float64(Float64(d / fma(d, d, Float64(c * c))) * b); elseif (d <= 4.4e+145) 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, -5e+156], N[(b / d), $MachinePrecision], If[LessEqual[d, -1.1e-26], N[(N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], If[LessEqual[d, 4.4e+145], 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 -5 \cdot 10^{+156}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -1.1 \cdot 10^{-26}:\\
\;\;\;\;\frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b\\
\mathbf{elif}\;d \leq 4.4 \cdot 10^{+145}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -4.99999999999999992e156 or 4.40000000000000017e145 < d Initial program 32.5%
Taylor expanded in c around 0
lower-/.f6474.3
Applied rewrites74.3%
if -4.99999999999999992e156 < d < -1.1e-26Initial program 75.0%
Applied rewrites79.2%
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-*.f6469.8
Applied rewrites69.8%
if -1.1e-26 < d < 4.40000000000000017e145Initial program 70.0%
Applied rewrites69.0%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6479.1
Applied rewrites79.1%
Final simplification76.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.5e-26) (not (<= d 4.6e+48))) (/ (fma (/ a d) c b) d) (/ (fma (/ d c) b a) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.5e-26) || !(d <= 4.6e+48)) {
tmp = fma((a / d), c, b) / d;
} else {
tmp = fma((d / c), b, a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.5e-26) || !(d <= 4.6e+48)) tmp = Float64(fma(Float64(a / d), c, 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, -4.5e-26], N[Not[LessEqual[d, 4.6e+48]], $MachinePrecision]], N[(N[(N[(a / d), $MachinePrecision] * c + 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 -4.5 \cdot 10^{-26} \lor \neg \left(d \leq 4.6 \cdot 10^{+48}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\end{array}
\end{array}
if d < -4.4999999999999999e-26 or 4.6e48 < d Initial program 46.3%
Taylor expanded in c around 0
+-commutativeN/A
associate-*l/N/A
associate-*l/N/A
unpow2N/A
associate-/r*N/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6479.5
Applied rewrites79.5%
if -4.4999999999999999e-26 < d < 4.6e48Initial program 72.3%
Applied rewrites69.5%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6483.1
Applied rewrites83.1%
Final simplification81.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.5e-26) (not (<= d 4.6e+48))) (/ (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 <= -4.5e-26) || !(d <= 4.6e+48)) {
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 <= -4.5e-26) || !(d <= 4.6e+48)) 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, -4.5e-26], N[Not[LessEqual[d, 4.6e+48]], $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 -4.5 \cdot 10^{-26} \lor \neg \left(d \leq 4.6 \cdot 10^{+48}\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 < -4.4999999999999999e-26 or 4.6e48 < d Initial program 46.3%
Taylor expanded in c around 0
+-commutativeN/A
associate-*l/N/A
associate-*l/N/A
unpow2N/A
associate-/r*N/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6479.5
Applied rewrites79.5%
Applied rewrites78.1%
if -4.4999999999999999e-26 < d < 4.6e48Initial program 72.3%
Applied rewrites69.5%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6483.1
Applied rewrites83.1%
Final simplification80.5%
(FPCore (a b c d)
:precision binary64
(if (<= d -5e+156)
(/ b d)
(if (<= d -2.8e-38)
(* (/ d (fma d d (* c c))) b)
(if (<= d 2.3e-10) (/ a c) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -5e+156) {
tmp = b / d;
} else if (d <= -2.8e-38) {
tmp = (d / fma(d, d, (c * c))) * b;
} else if (d <= 2.3e-10) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -5e+156) tmp = Float64(b / d); elseif (d <= -2.8e-38) tmp = Float64(Float64(d / fma(d, d, Float64(c * c))) * b); elseif (d <= 2.3e-10) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -5e+156], N[(b / d), $MachinePrecision], If[LessEqual[d, -2.8e-38], N[(N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], If[LessEqual[d, 2.3e-10], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5 \cdot 10^{+156}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -2.8 \cdot 10^{-38}:\\
\;\;\;\;\frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b\\
\mathbf{elif}\;d \leq 2.3 \cdot 10^{-10}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -4.99999999999999992e156 or 2.30000000000000007e-10 < d Initial program 38.8%
Taylor expanded in c around 0
lower-/.f6466.8
Applied rewrites66.8%
if -4.99999999999999992e156 < d < -2.8e-38Initial program 75.7%
Applied rewrites79.8%
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-*.f6470.6
Applied rewrites70.6%
if -2.8e-38 < d < 2.30000000000000007e-10Initial program 73.7%
Taylor expanded in c around inf
lower-/.f6468.6
Applied rewrites68.6%
Final simplification68.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.95e-33) (not (<= d 2.3e-10))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.95e-33) || !(d <= 2.3e-10)) {
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 ((d <= (-1.95d-33)) .or. (.not. (d <= 2.3d-10))) 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 ((d <= -1.95e-33) || !(d <= 2.3e-10)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.95e-33) or not (d <= 2.3e-10): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.95e-33) || !(d <= 2.3e-10)) 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 ((d <= -1.95e-33) || ~((d <= 2.3e-10))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.95e-33], N[Not[LessEqual[d, 2.3e-10]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.95 \cdot 10^{-33} \lor \neg \left(d \leq 2.3 \cdot 10^{-10}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -1.94999999999999987e-33 or 2.30000000000000007e-10 < d Initial program 47.9%
Taylor expanded in c around 0
lower-/.f6464.0
Applied rewrites64.0%
if -1.94999999999999987e-33 < d < 2.30000000000000007e-10Initial program 73.7%
Taylor expanded in c around inf
lower-/.f6468.6
Applied rewrites68.6%
Final simplification66.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 59.0%
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 2024343
(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))))