
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * 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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \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 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * 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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \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) c)))
(if (<= c -1.36e+124)
t_0
(if (<= c -8e-65)
(/ (fma (- d) a (* b c)) (fma d d (* c c)))
(if (<= c 2.6e+70) (/ (- (/ (* b c) d) a) d) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(-a, (d / c), b) / c;
double tmp;
if (c <= -1.36e+124) {
tmp = t_0;
} else if (c <= -8e-65) {
tmp = fma(-d, a, (b * c)) / fma(d, d, (c * c));
} else if (c <= 2.6e+70) {
tmp = (((b * c) / d) - a) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(-a), Float64(d / c), b) / c) tmp = 0.0 if (c <= -1.36e+124) tmp = t_0; elseif (c <= -8e-65) tmp = Float64(fma(Float64(-d), a, Float64(b * c)) / fma(d, d, Float64(c * c))); elseif (c <= 2.6e+70) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[((-a) * N[(d / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.36e+124], t$95$0, If[LessEqual[c, -8e-65], N[(N[((-d) * a + N[(b * c), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.6e+70], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(-a, \frac{d}{c}, b\right)}{c}\\
\mathbf{if}\;c \leq -1.36 \cdot 10^{+124}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -8 \cdot 10^{-65}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-d, a, b \cdot c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;c \leq 2.6 \cdot 10^{+70}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.36e124 or 2.6e70 < c Initial program 34.1%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6478.3
Applied rewrites78.3%
Applied rewrites88.5%
if -1.36e124 < c < -7.99999999999999939e-65Initial program 92.2%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6492.2
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6492.2
Applied rewrites92.2%
if -7.99999999999999939e-65 < c < 2.6e70Initial program 76.1%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6488.6
Applied rewrites88.6%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.6e+17) (not (<= c 2.6e+70))) (/ (fma (- a) (/ d c) b) c) (/ (- (/ (* b c) d) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.6e+17) || !(c <= 2.6e+70)) {
tmp = fma(-a, (d / c), b) / c;
} else {
tmp = (((b * c) / d) - a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.6e+17) || !(c <= 2.6e+70)) tmp = Float64(fma(Float64(-a), Float64(d / c), b) / c); else tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.6e+17], N[Not[LessEqual[c, 2.6e+70]], $MachinePrecision]], N[(N[((-a) * N[(d / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.6 \cdot 10^{+17} \lor \neg \left(c \leq 2.6 \cdot 10^{+70}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(-a, \frac{d}{c}, b\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -2.6e17 or 2.6e70 < c Initial program 44.7%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6477.9
Applied rewrites77.9%
Applied rewrites85.3%
if -2.6e17 < c < 2.6e70Initial program 78.6%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6486.2
Applied rewrites86.2%
Final simplification85.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.6e+17) (not (<= c 2.6e+70))) (/ (- b (/ (* a d) c)) c) (/ (- (/ (* b c) d) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.6e+17) || !(c <= 2.6e+70)) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = (((b * c) / d) - a) / 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 <= (-2.6d+17)) .or. (.not. (c <= 2.6d+70))) then
tmp = (b - ((a * d) / c)) / c
else
tmp = (((b * c) / d) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.6e+17) || !(c <= 2.6e+70)) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = (((b * c) / d) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.6e+17) or not (c <= 2.6e+70): tmp = (b - ((a * d) / c)) / c else: tmp = (((b * c) / d) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.6e+17) || !(c <= 2.6e+70)) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); else tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.6e+17) || ~((c <= 2.6e+70))) tmp = (b - ((a * d) / c)) / c; else tmp = (((b * c) / d) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.6e+17], N[Not[LessEqual[c, 2.6e+70]], $MachinePrecision]], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.6 \cdot 10^{+17} \lor \neg \left(c \leq 2.6 \cdot 10^{+70}\right):\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -2.6e17 or 2.6e70 < c Initial program 44.7%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6477.9
Applied rewrites77.9%
if -2.6e17 < c < 2.6e70Initial program 78.6%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6486.2
Applied rewrites86.2%
Final simplification82.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.6e+17) (not (<= c 2.6e+70))) (/ (- b (/ (* a d) c)) c) (/ (fma b (/ c d) (- a)) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.6e+17) || !(c <= 2.6e+70)) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = fma(b, (c / d), -a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.6e+17) || !(c <= 2.6e+70)) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); else tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.6e+17], N[Not[LessEqual[c, 2.6e+70]], $MachinePrecision]], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.6 \cdot 10^{+17} \lor \neg \left(c \leq 2.6 \cdot 10^{+70}\right):\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\end{array}
\end{array}
if c < -2.6e17 or 2.6e70 < c Initial program 44.7%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6477.9
Applied rewrites77.9%
if -2.6e17 < c < 2.6e70Initial program 78.6%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
Applied rewrites74.7%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6474.2
Applied rewrites74.2%
Taylor expanded in c around 0
+-commutativeN/A
*-commutativeN/A
unpow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6484.7
Applied rewrites84.7%
Taylor expanded in d around inf
Applied rewrites86.2%
Final simplification82.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -7.5e+88) (not (<= c 2.1e+53))) (/ b c) (/ (fma b (/ c d) (- a)) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -7.5e+88) || !(c <= 2.1e+53)) {
tmp = b / c;
} else {
tmp = fma(b, (c / d), -a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -7.5e+88) || !(c <= 2.1e+53)) tmp = Float64(b / c); else tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -7.5e+88], N[Not[LessEqual[c, 2.1e+53]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.5 \cdot 10^{+88} \lor \neg \left(c \leq 2.1 \cdot 10^{+53}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\end{array}
\end{array}
if c < -7.50000000000000031e88 or 2.1000000000000002e53 < c Initial program 40.9%
Taylor expanded in c around inf
lower-/.f6476.0
Applied rewrites76.0%
if -7.50000000000000031e88 < c < 2.1000000000000002e53Initial program 78.9%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
Applied rewrites75.9%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6475.5
Applied rewrites75.5%
Taylor expanded in c around 0
+-commutativeN/A
*-commutativeN/A
unpow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6480.5
Applied rewrites80.5%
Taylor expanded in d around inf
Applied rewrites82.0%
Final simplification79.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -1.45e+131)
t_0
(if (<= d -2.6e-25)
(/ (- (* b c) (* a d)) (* d d))
(if (<= d 1.18e+94) (/ b c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -1.45e+131) {
tmp = t_0;
} else if (d <= -2.6e-25) {
tmp = ((b * c) - (a * d)) / (d * d);
} else if (d <= 1.18e+94) {
tmp = b / c;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = -a / d
if (d <= (-1.45d+131)) then
tmp = t_0
else if (d <= (-2.6d-25)) then
tmp = ((b * c) - (a * d)) / (d * d)
else if (d <= 1.18d+94) then
tmp = b / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -1.45e+131) {
tmp = t_0;
} else if (d <= -2.6e-25) {
tmp = ((b * c) - (a * d)) / (d * d);
} else if (d <= 1.18e+94) {
tmp = b / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = -a / d tmp = 0 if d <= -1.45e+131: tmp = t_0 elif d <= -2.6e-25: tmp = ((b * c) - (a * d)) / (d * d) elif d <= 1.18e+94: tmp = b / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -1.45e+131) tmp = t_0; elseif (d <= -2.6e-25) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(d * d)); elseif (d <= 1.18e+94) tmp = Float64(b / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = -a / d; tmp = 0.0; if (d <= -1.45e+131) tmp = t_0; elseif (d <= -2.6e-25) tmp = ((b * c) - (a * d)) / (d * d); elseif (d <= 1.18e+94) tmp = b / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -1.45e+131], t$95$0, If[LessEqual[d, -2.6e-25], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.18e+94], N[(b / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -1.45 \cdot 10^{+131}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -2.6 \cdot 10^{-25}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{d \cdot d}\\
\mathbf{elif}\;d \leq 1.18 \cdot 10^{+94}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.45000000000000005e131 or 1.18000000000000002e94 < d Initial program 51.8%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6473.7
Applied rewrites73.7%
if -1.45000000000000005e131 < d < -2.6e-25Initial program 71.6%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6465.4
Applied rewrites65.4%
if -2.6e-25 < d < 1.18000000000000002e94Initial program 66.8%
Taylor expanded in c around inf
lower-/.f6473.4
Applied rewrites73.4%
Final simplification72.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -6.2e+47) (not (<= d 1.18e+94))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.2e+47) || !(d <= 1.18e+94)) {
tmp = -a / d;
} else {
tmp = b / 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 <= (-6.2d+47)) .or. (.not. (d <= 1.18d+94))) then
tmp = -a / d
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.2e+47) || !(d <= 1.18e+94)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -6.2e+47) or not (d <= 1.18e+94): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -6.2e+47) || !(d <= 1.18e+94)) tmp = Float64(Float64(-a) / d); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -6.2e+47) || ~((d <= 1.18e+94))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6.2e+47], N[Not[LessEqual[d, 1.18e+94]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.2 \cdot 10^{+47} \lor \neg \left(d \leq 1.18 \cdot 10^{+94}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -6.2000000000000001e47 or 1.18000000000000002e94 < d Initial program 56.7%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6471.6
Applied rewrites71.6%
if -6.2000000000000001e47 < d < 1.18000000000000002e94Initial program 67.2%
Taylor expanded in c around inf
lower-/.f6467.8
Applied rewrites67.8%
Final simplification69.5%
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
return b / 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 = b / c
end function
public static double code(double a, double b, double c, double d) {
return b / c;
}
def code(a, b, c, d): return b / c
function code(a, b, c, d) return Float64(b / c) end
function tmp = code(a, b, c, d) tmp = b / c; end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{c}
\end{array}
Initial program 62.4%
Taylor expanded in c around inf
lower-/.f6445.5
Applied rewrites45.5%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (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 = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (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 = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (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(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * 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 = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (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[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * 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{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024317
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))