
(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
(fma (/ c d) (/ c d) -1.0)
a
(* (- b) (- (pow (/ c d) 3.0) (/ c d))))
d))
(t_1 (fma d d (* c c))))
(if (<= d -2.8e+91)
t_0
(if (<= d -2.9e-35)
(* (/ (fma (/ d b) (- a) c) t_1) b)
(if (<= d 4.3e-129)
(/ (- b (/ (* a d) c)) c)
(if (<= d 3.6e+85) (/ (fma (- a) d (* b c)) t_1) t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(fma((c / d), (c / d), -1.0), a, (-b * (pow((c / d), 3.0) - (c / d)))) / d;
double t_1 = fma(d, d, (c * c));
double tmp;
if (d <= -2.8e+91) {
tmp = t_0;
} else if (d <= -2.9e-35) {
tmp = (fma((d / b), -a, c) / t_1) * b;
} else if (d <= 4.3e-129) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 3.6e+85) {
tmp = fma(-a, d, (b * c)) / t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(fma(Float64(c / d), Float64(c / d), -1.0), a, Float64(Float64(-b) * Float64((Float64(c / d) ^ 3.0) - Float64(c / d)))) / d) t_1 = fma(d, d, Float64(c * c)) tmp = 0.0 if (d <= -2.8e+91) tmp = t_0; elseif (d <= -2.9e-35) tmp = Float64(Float64(fma(Float64(d / b), Float64(-a), c) / t_1) * b); elseif (d <= 4.3e-129) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); elseif (d <= 3.6e+85) tmp = Float64(fma(Float64(-a), d, Float64(b * c)) / t_1); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(N[(c / d), $MachinePrecision] * N[(c / d), $MachinePrecision] + -1.0), $MachinePrecision] * a + N[((-b) * N[(N[Power[N[(c / d), $MachinePrecision], 3.0], $MachinePrecision] - N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, Block[{t$95$1 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.8e+91], t$95$0, If[LessEqual[d, -2.9e-35], N[(N[(N[(N[(d / b), $MachinePrecision] * (-a) + c), $MachinePrecision] / t$95$1), $MachinePrecision] * b), $MachinePrecision], If[LessEqual[d, 4.3e-129], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.6e+85], N[(N[((-a) * d + N[(b * c), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{c}{d}, \frac{c}{d}, -1\right), a, \left(-b\right) \cdot \left({\left(\frac{c}{d}\right)}^{3} - \frac{c}{d}\right)\right)}{d}\\
t_1 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
\mathbf{if}\;d \leq -2.8 \cdot 10^{+91}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -2.9 \cdot 10^{-35}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{b}, -a, c\right)}{t\_1} \cdot b\\
\mathbf{elif}\;d \leq 4.3 \cdot 10^{-129}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 3.6 \cdot 10^{+85}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-a, d, b \cdot c\right)}{t\_1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.7999999999999999e91 or 3.5999999999999998e85 < d Initial program 42.8%
Taylor expanded in d around inf
Applied rewrites83.7%
if -2.7999999999999999e91 < d < -2.9000000000000002e-35Initial program 77.0%
Taylor expanded in b around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
associate-*l/N/A
associate-*r/N/A
*-commutativeN/A
distribute-lft-inN/A
lower-*.f64N/A
Applied rewrites82.2%
if -2.9000000000000002e-35 < d < 4.29999999999999981e-129Initial program 67.8%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6491.4
Applied rewrites91.4%
if 4.29999999999999981e-129 < d < 3.5999999999999998e85Initial program 76.9%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-neg.f6476.9
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6476.9
Applied rewrites76.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (* d (/ a c))) c)))
(if (<= c -3.6e+52)
t_0
(if (<= c 2.8e-178)
(/ (- (/ (* b c) d) a) d)
(if (<= c 1.35e+109)
(/ (fma (- a) d (* b c)) (fma d d (* c c)))
t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -3.6e+52) {
tmp = t_0;
} else if (c <= 2.8e-178) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 1.35e+109) {
tmp = fma(-a, d, (b * c)) / fma(d, d, (c * c));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(d * Float64(a / c))) / c) tmp = 0.0 if (c <= -3.6e+52) tmp = t_0; elseif (c <= 2.8e-178) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 1.35e+109) tmp = Float64(fma(Float64(-a), d, Float64(b * c)) / fma(d, d, Float64(c * c))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3.6e+52], t$95$0, If[LessEqual[c, 2.8e-178], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.35e+109], N[(N[((-a) * d + N[(b * c), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -3.6 \cdot 10^{+52}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.8 \cdot 10^{-178}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.35 \cdot 10^{+109}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-a, d, b \cdot c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.6e52 or 1.35000000000000001e109 < c Initial program 43.9%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6478.9
Applied rewrites78.9%
Applied rewrites85.7%
if -3.6e52 < c < 2.80000000000000019e-178Initial program 67.8%
Taylor expanded in c around 0
+-commutativeN/A
fp-cancel-sign-sub-invN/A
unpow2N/A
associate-/r*N/A
metadata-evalN/A
*-lft-identityN/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6479.1
Applied rewrites79.1%
if 2.80000000000000019e-178 < c < 1.35000000000000001e109Initial program 82.8%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-neg.f6482.8
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6482.8
Applied rewrites82.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -2.7e+91)
t_0
(if (<= d 1.55e-17)
(/ (- b (/ (* a d) c)) c)
(if (<= d 1.45e+122) (* (- a) (/ d (fma d d (* c c)))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -2.7e+91) {
tmp = t_0;
} else if (d <= 1.55e-17) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 1.45e+122) {
tmp = -a * (d / fma(d, d, (c * c)));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -2.7e+91) tmp = t_0; elseif (d <= 1.55e-17) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); elseif (d <= 1.45e+122) tmp = Float64(Float64(-a) * Float64(d / fma(d, d, Float64(c * c)))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -2.7e+91], t$95$0, If[LessEqual[d, 1.55e-17], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.45e+122], N[((-a) * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -2.7 \cdot 10^{+91}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.55 \cdot 10^{-17}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.45 \cdot 10^{+122}:\\
\;\;\;\;\left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.7e91 or 1.45e122 < d Initial program 42.3%
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.9
Applied rewrites71.9%
if -2.7e91 < d < 1.5499999999999999e-17Initial program 71.8%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6484.0
Applied rewrites84.0%
if 1.5499999999999999e-17 < d < 1.45e122Initial program 64.4%
Taylor expanded in a around inf
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6460.5
Applied rewrites60.5%
Final simplification76.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -2.7e+91)
t_0
(if (<= d 1.55e-17)
(/ (- b (* d (/ a c))) c)
(if (<= d 1.45e+122) (* (- a) (/ d (fma d d (* c c)))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -2.7e+91) {
tmp = t_0;
} else if (d <= 1.55e-17) {
tmp = (b - (d * (a / c))) / c;
} else if (d <= 1.45e+122) {
tmp = -a * (d / fma(d, d, (c * c)));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -2.7e+91) tmp = t_0; elseif (d <= 1.55e-17) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); elseif (d <= 1.45e+122) tmp = Float64(Float64(-a) * Float64(d / fma(d, d, Float64(c * c)))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -2.7e+91], t$95$0, If[LessEqual[d, 1.55e-17], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.45e+122], N[((-a) * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -2.7 \cdot 10^{+91}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.55 \cdot 10^{-17}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{elif}\;d \leq 1.45 \cdot 10^{+122}:\\
\;\;\;\;\left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.7e91 or 1.45e122 < d Initial program 42.3%
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.9
Applied rewrites71.9%
if -2.7e91 < d < 1.5499999999999999e-17Initial program 71.8%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6484.0
Applied rewrites84.0%
Applied rewrites81.8%
if 1.5499999999999999e-17 < d < 1.45e122Initial program 64.4%
Taylor expanded in a around inf
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6460.5
Applied rewrites60.5%
Final simplification75.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -2.1e+90)
t_0
(if (<= d 8e-18)
(/ b c)
(if (<= d 1.45e+122) (* (- a) (/ d (fma d d (* c c)))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -2.1e+90) {
tmp = t_0;
} else if (d <= 8e-18) {
tmp = b / c;
} else if (d <= 1.45e+122) {
tmp = -a * (d / fma(d, d, (c * c)));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -2.1e+90) tmp = t_0; elseif (d <= 8e-18) tmp = Float64(b / c); elseif (d <= 1.45e+122) tmp = Float64(Float64(-a) * Float64(d / fma(d, d, Float64(c * c)))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -2.1e+90], t$95$0, If[LessEqual[d, 8e-18], N[(b / c), $MachinePrecision], If[LessEqual[d, 1.45e+122], N[((-a) * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -2.1 \cdot 10^{+90}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 8 \cdot 10^{-18}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;d \leq 1.45 \cdot 10^{+122}:\\
\;\;\;\;\left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.09999999999999981e90 or 1.45e122 < d Initial program 42.3%
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.9
Applied rewrites71.9%
if -2.09999999999999981e90 < d < 8.0000000000000006e-18Initial program 71.8%
Taylor expanded in c around inf
lower-/.f6467.9
Applied rewrites67.9%
if 8.0000000000000006e-18 < d < 1.45e122Initial program 64.4%
Taylor expanded in a around inf
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6460.5
Applied rewrites60.5%
Final simplification67.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3.6e+52) (not (<= c 1.1e+49))) (/ (- b (* d (/ a c))) c) (/ (- (/ (* b c) d) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.6e+52) || !(c <= 1.1e+49)) {
tmp = (b - (d * (a / 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 <= (-3.6d+52)) .or. (.not. (c <= 1.1d+49))) then
tmp = (b - (d * (a / 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 <= -3.6e+52) || !(c <= 1.1e+49)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = (((b * c) / d) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3.6e+52) or not (c <= 1.1e+49): tmp = (b - (d * (a / c))) / c else: tmp = (((b * c) / d) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.6e+52) || !(c <= 1.1e+49)) tmp = Float64(Float64(b - Float64(d * Float64(a / 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 <= -3.6e+52) || ~((c <= 1.1e+49))) tmp = (b - (d * (a / c))) / c; else tmp = (((b * c) / d) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.6e+52], N[Not[LessEqual[c, 1.1e+49]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $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 -3.6 \cdot 10^{+52} \lor \neg \left(c \leq 1.1 \cdot 10^{+49}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -3.6e52 or 1.1e49 < c Initial program 48.3%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6477.7
Applied rewrites77.7%
Applied rewrites83.5%
if -3.6e52 < c < 1.1e49Initial program 73.3%
Taylor expanded in c around 0
+-commutativeN/A
fp-cancel-sign-sub-invN/A
unpow2N/A
associate-/r*N/A
metadata-evalN/A
*-lft-identityN/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6475.5
Applied rewrites75.5%
Final simplification79.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.1e+90) (not (<= d 1.55e-17))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.1e+90) || !(d <= 1.55e-17)) {
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 <= (-2.1d+90)) .or. (.not. (d <= 1.55d-17))) 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 <= -2.1e+90) || !(d <= 1.55e-17)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.1e+90) or not (d <= 1.55e-17): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.1e+90) || !(d <= 1.55e-17)) 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 <= -2.1e+90) || ~((d <= 1.55e-17))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.1e+90], N[Not[LessEqual[d, 1.55e-17]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.1 \cdot 10^{+90} \lor \neg \left(d \leq 1.55 \cdot 10^{-17}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -2.09999999999999981e90 or 1.5499999999999999e-17 < d Initial program 50.2%
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.f6462.0
Applied rewrites62.0%
if -2.09999999999999981e90 < d < 1.5499999999999999e-17Initial program 71.8%
Taylor expanded in c around inf
lower-/.f6467.9
Applied rewrites67.9%
Final simplification65.3%
(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.1%
Taylor expanded in c around inf
lower-/.f6444.3
Applied rewrites44.3%
(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 2024337
(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))))