
(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 11 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 (/ b d) c (- a)) d)) (t_1 (fma d d (* c c))))
(if (<= d -9.2e+14)
t_0
(if (<= d 7e-145)
(/ (- b (/ (* a d) c)) c)
(if (<= d 7.8e+127) (fma (/ c t_1) b (* (/ a t_1) (- d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma((b / d), c, -a) / d;
double t_1 = fma(d, d, (c * c));
double tmp;
if (d <= -9.2e+14) {
tmp = t_0;
} else if (d <= 7e-145) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 7.8e+127) {
tmp = fma((c / t_1), b, ((a / t_1) * -d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(b / d), c, Float64(-a)) / d) t_1 = fma(d, d, Float64(c * c)) tmp = 0.0 if (d <= -9.2e+14) tmp = t_0; elseif (d <= 7e-145) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); elseif (d <= 7.8e+127) tmp = fma(Float64(c / t_1), b, Float64(Float64(a / t_1) * Float64(-d))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b / d), $MachinePrecision] * c + (-a)), $MachinePrecision] / d), $MachinePrecision]}, Block[{t$95$1 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -9.2e+14], t$95$0, If[LessEqual[d, 7e-145], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 7.8e+127], N[(N[(c / t$95$1), $MachinePrecision] * b + N[(N[(a / t$95$1), $MachinePrecision] * (-d)), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{b}{d}, c, -a\right)}{d}\\
t_1 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
\mathbf{if}\;d \leq -9.2 \cdot 10^{+14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 7 \cdot 10^{-145}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 7.8 \cdot 10^{+127}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{t\_1}, b, \frac{a}{t\_1} \cdot \left(-d\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -9.2e14 or 7.79999999999999962e127 < d Initial program 39.9%
Taylor expanded in c around inf
lower-/.f6420.0
Applied rewrites20.0%
Taylor expanded in d around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
associate-/l*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6483.6
Applied rewrites83.6%
Applied rewrites83.6%
if -9.2e14 < d < 6.99999999999999994e-145Initial program 69.4%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6490.5
Applied rewrites90.5%
if 6.99999999999999994e-145 < d < 7.79999999999999962e127Initial program 83.5%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sub-negN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/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
Applied rewrites87.1%
Final simplification87.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ b d) c (- a)) d)))
(if (<= d -9.2e+14)
t_0
(if (<= d 1.48e-145)
(/ (- b (/ (* a d) c)) c)
(if (<= d 7.8e+127)
(/ (fma (- b) c (* a d)) (- (fma d d (* c c))))
t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma((b / d), c, -a) / d;
double tmp;
if (d <= -9.2e+14) {
tmp = t_0;
} else if (d <= 1.48e-145) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 7.8e+127) {
tmp = fma(-b, c, (a * d)) / -fma(d, d, (c * c));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(b / d), c, Float64(-a)) / d) tmp = 0.0 if (d <= -9.2e+14) tmp = t_0; elseif (d <= 1.48e-145) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); elseif (d <= 7.8e+127) tmp = Float64(fma(Float64(-b), c, Float64(a * d)) / Float64(-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[(N[(b / d), $MachinePrecision] * c + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -9.2e+14], t$95$0, If[LessEqual[d, 1.48e-145], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 7.8e+127], N[(N[((-b) * c + N[(a * d), $MachinePrecision]), $MachinePrecision] / (-N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision])), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{b}{d}, c, -a\right)}{d}\\
\mathbf{if}\;d \leq -9.2 \cdot 10^{+14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.48 \cdot 10^{-145}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 7.8 \cdot 10^{+127}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-b, c, a \cdot d\right)}{-\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -9.2e14 or 7.79999999999999962e127 < d Initial program 39.9%
Taylor expanded in c around inf
lower-/.f6420.0
Applied rewrites20.0%
Taylor expanded in d around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
associate-/l*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6483.6
Applied rewrites83.6%
Applied rewrites83.6%
if -9.2e14 < d < 1.47999999999999995e-145Initial program 69.4%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6490.5
Applied rewrites90.5%
if 1.47999999999999995e-145 < d < 7.79999999999999962e127Initial program 83.5%
lift-/.f64N/A
frac-2negN/A
lower-/.f64N/A
lift--.f64N/A
sub-negN/A
distribute-neg-inN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
remove-double-negN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-neg.f6483.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6483.5
Applied rewrites83.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ b d) c (- a)) d)))
(if (<= d -9.2e+14)
t_0
(if (<= d 1.48e-145)
(/ (- b (/ (* a d) c)) c)
(if (<= d 7.8e+127) (/ (- (* c b) (* a d)) (+ (* d d) (* c c))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma((b / d), c, -a) / d;
double tmp;
if (d <= -9.2e+14) {
tmp = t_0;
} else if (d <= 1.48e-145) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 7.8e+127) {
tmp = ((c * b) - (a * d)) / ((d * d) + (c * c));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(b / d), c, Float64(-a)) / d) tmp = 0.0 if (d <= -9.2e+14) tmp = t_0; elseif (d <= 1.48e-145) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); elseif (d <= 7.8e+127) tmp = Float64(Float64(Float64(c * b) - Float64(a * d)) / Float64(Float64(d * d) + Float64(c * c))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b / d), $MachinePrecision] * c + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -9.2e+14], t$95$0, If[LessEqual[d, 1.48e-145], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 7.8e+127], N[(N[(N[(c * b), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{b}{d}, c, -a\right)}{d}\\
\mathbf{if}\;d \leq -9.2 \cdot 10^{+14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.48 \cdot 10^{-145}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 7.8 \cdot 10^{+127}:\\
\;\;\;\;\frac{c \cdot b - a \cdot d}{d \cdot d + c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -9.2e14 or 7.79999999999999962e127 < d Initial program 39.9%
Taylor expanded in c around inf
lower-/.f6420.0
Applied rewrites20.0%
Taylor expanded in d around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
associate-/l*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6483.6
Applied rewrites83.6%
Applied rewrites83.6%
if -9.2e14 < d < 1.47999999999999995e-145Initial program 69.4%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6490.5
Applied rewrites90.5%
if 1.47999999999999995e-145 < d < 7.79999999999999962e127Initial program 83.5%
Final simplification86.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma c c (* d d))))
(if (<= c -5.5e-36)
(/ b c)
(if (<= c 8.5e-173)
(/ (- a) d)
(if (<= c 1.4e-28)
(* (/ d t_0) (- a))
(if (<= c 1e+137) (* (/ c t_0) b) (/ b c)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(c, c, (d * d));
double tmp;
if (c <= -5.5e-36) {
tmp = b / c;
} else if (c <= 8.5e-173) {
tmp = -a / d;
} else if (c <= 1.4e-28) {
tmp = (d / t_0) * -a;
} else if (c <= 1e+137) {
tmp = (c / t_0) * b;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(c, c, Float64(d * d)) tmp = 0.0 if (c <= -5.5e-36) tmp = Float64(b / c); elseif (c <= 8.5e-173) tmp = Float64(Float64(-a) / d); elseif (c <= 1.4e-28) tmp = Float64(Float64(d / t_0) * Float64(-a)); elseif (c <= 1e+137) tmp = Float64(Float64(c / t_0) * b); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -5.5e-36], N[(b / c), $MachinePrecision], If[LessEqual[c, 8.5e-173], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 1.4e-28], N[(N[(d / t$95$0), $MachinePrecision] * (-a)), $MachinePrecision], If[LessEqual[c, 1e+137], N[(N[(c / t$95$0), $MachinePrecision] * b), $MachinePrecision], N[(b / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, c, d \cdot d\right)\\
\mathbf{if}\;c \leq -5.5 \cdot 10^{-36}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 8.5 \cdot 10^{-173}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 1.4 \cdot 10^{-28}:\\
\;\;\;\;\frac{d}{t\_0} \cdot \left(-a\right)\\
\mathbf{elif}\;c \leq 10^{+137}:\\
\;\;\;\;\frac{c}{t\_0} \cdot b\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -5.49999999999999984e-36 or 1e137 < c Initial program 50.5%
Taylor expanded in c around inf
lower-/.f6474.1
Applied rewrites74.1%
if -5.49999999999999984e-36 < c < 8.4999999999999996e-173Initial program 67.2%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6472.0
Applied rewrites72.0%
if 8.4999999999999996e-173 < c < 1.3999999999999999e-28Initial program 85.8%
Taylor expanded in b around 0
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6467.2
Applied rewrites67.2%
if 1.3999999999999999e-28 < c < 1e137Initial program 60.6%
Taylor expanded in c around inf
lower-/.f6437.3
Applied rewrites37.3%
Taylor expanded in b around inf
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6457.7
Applied rewrites57.7%
Final simplification70.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -8.2e+67)
t_0
(if (<= d 240000000000.0)
(/ (- b (/ (* a d) c)) c)
(if (<= d 5.5e+148) (/ (fma c b (* (- d) a)) (* d d)) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -8.2e+67) {
tmp = t_0;
} else if (d <= 240000000000.0) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 5.5e+148) {
tmp = fma(c, b, (-d * a)) / (d * d);
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -8.2e+67) tmp = t_0; elseif (d <= 240000000000.0) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); elseif (d <= 5.5e+148) tmp = Float64(fma(c, b, Float64(Float64(-d) * a)) / Float64(d * d)); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -8.2e+67], t$95$0, If[LessEqual[d, 240000000000.0], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.5e+148], N[(N[(c * b + N[((-d) * a), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -8.2 \cdot 10^{+67}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 240000000000:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 5.5 \cdot 10^{+148}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, b, \left(-d\right) \cdot a\right)}{d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -8.19999999999999959e67 or 5.5e148 < d Initial program 35.1%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6471.1
Applied rewrites71.1%
if -8.19999999999999959e67 < d < 2.4e11Initial program 71.9%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6481.7
Applied rewrites81.7%
if 2.4e11 < d < 5.5e148Initial program 80.8%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6462.8
Applied rewrites62.8%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-neg.f64N/A
lower-*.f6462.8
Applied rewrites62.8%
Final simplification75.4%
(FPCore (a b c d)
:precision binary64
(if (<= c -5.5e-36)
(/ b c)
(if (<= c 8e-8)
(/ (- a) d)
(if (<= c 1e+137) (* (/ c (fma c c (* d d))) b) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.5e-36) {
tmp = b / c;
} else if (c <= 8e-8) {
tmp = -a / d;
} else if (c <= 1e+137) {
tmp = (c / fma(c, c, (d * d))) * b;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -5.5e-36) tmp = Float64(b / c); elseif (c <= 8e-8) tmp = Float64(Float64(-a) / d); elseif (c <= 1e+137) tmp = Float64(Float64(c / fma(c, c, Float64(d * d))) * b); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.5e-36], N[(b / c), $MachinePrecision], If[LessEqual[c, 8e-8], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 1e+137], N[(N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.5 \cdot 10^{-36}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 8 \cdot 10^{-8}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 10^{+137}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot b\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -5.49999999999999984e-36 or 1e137 < c Initial program 50.5%
Taylor expanded in c around inf
lower-/.f6474.1
Applied rewrites74.1%
if -5.49999999999999984e-36 < c < 8.0000000000000002e-8Initial program 69.9%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6464.7
Applied rewrites64.7%
if 8.0000000000000002e-8 < c < 1e137Initial program 62.0%
Taylor expanded in c around inf
lower-/.f6439.0
Applied rewrites39.0%
Taylor expanded in b around inf
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6462.4
Applied rewrites62.4%
(FPCore (a b c d)
:precision binary64
(if (<= c -5.5e-36)
(/ b c)
(if (<= c 8e-8)
(/ (- a) d)
(if (<= c 5.4e+136) (* (/ b (fma c c (* d d))) c) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.5e-36) {
tmp = b / c;
} else if (c <= 8e-8) {
tmp = -a / d;
} else if (c <= 5.4e+136) {
tmp = (b / fma(c, c, (d * d))) * c;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -5.5e-36) tmp = Float64(b / c); elseif (c <= 8e-8) tmp = Float64(Float64(-a) / d); elseif (c <= 5.4e+136) tmp = Float64(Float64(b / fma(c, c, Float64(d * d))) * c); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.5e-36], N[(b / c), $MachinePrecision], If[LessEqual[c, 8e-8], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 5.4e+136], N[(N[(b / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.5 \cdot 10^{-36}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 8 \cdot 10^{-8}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 5.4 \cdot 10^{+136}:\\
\;\;\;\;\frac{b}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot c\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -5.49999999999999984e-36 or 5.4000000000000003e136 < c Initial program 50.5%
Taylor expanded in c around inf
lower-/.f6474.1
Applied rewrites74.1%
if -5.49999999999999984e-36 < c < 8.0000000000000002e-8Initial program 69.9%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6464.7
Applied rewrites64.7%
if 8.0000000000000002e-8 < c < 5.4000000000000003e136Initial program 62.0%
Taylor expanded in b around inf
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6460.0
Applied rewrites60.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ b d) c (- a)) d)))
(if (<= d -9.2e+14)
t_0
(if (<= d 240000000000.0) (/ (- b (/ (* a d) c)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma((b / d), c, -a) / d;
double tmp;
if (d <= -9.2e+14) {
tmp = t_0;
} else if (d <= 240000000000.0) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(b / d), c, Float64(-a)) / d) tmp = 0.0 if (d <= -9.2e+14) tmp = t_0; elseif (d <= 240000000000.0) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b / d), $MachinePrecision] * c + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -9.2e+14], t$95$0, If[LessEqual[d, 240000000000.0], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{b}{d}, c, -a\right)}{d}\\
\mathbf{if}\;d \leq -9.2 \cdot 10^{+14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 240000000000:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -9.2e14 or 2.4e11 < d Initial program 50.2%
Taylor expanded in c around inf
lower-/.f6422.0
Applied rewrites22.0%
Taylor expanded in d around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
associate-/l*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6481.3
Applied rewrites81.3%
Applied rewrites81.3%
if -9.2e14 < d < 2.4e11Initial program 71.9%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6484.8
Applied rewrites84.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (/ (* c b) d) a) d)))
(if (<= d -9.2e+14)
t_0
(if (<= d 240000000000.0) (/ (- b (/ (* a d) c)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (((c * b) / d) - a) / d;
double tmp;
if (d <= -9.2e+14) {
tmp = t_0;
} else if (d <= 240000000000.0) {
tmp = (b - ((a * d) / c)) / 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 = (((c * b) / d) - a) / d
if (d <= (-9.2d+14)) then
tmp = t_0
else if (d <= 240000000000.0d0) then
tmp = (b - ((a * d) / c)) / 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 = (((c * b) / d) - a) / d;
double tmp;
if (d <= -9.2e+14) {
tmp = t_0;
} else if (d <= 240000000000.0) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (((c * b) / d) - a) / d tmp = 0 if d <= -9.2e+14: tmp = t_0 elif d <= 240000000000.0: tmp = (b - ((a * d) / c)) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(Float64(c * b) / d) - a) / d) tmp = 0.0 if (d <= -9.2e+14) tmp = t_0; elseif (d <= 240000000000.0) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (((c * b) / d) - a) / d; tmp = 0.0; if (d <= -9.2e+14) tmp = t_0; elseif (d <= 240000000000.0) tmp = (b - ((a * d) / c)) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -9.2e+14], t$95$0, If[LessEqual[d, 240000000000.0], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\frac{c \cdot b}{d} - a}{d}\\
\mathbf{if}\;d \leq -9.2 \cdot 10^{+14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 240000000000:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -9.2e14 or 2.4e11 < d Initial program 50.2%
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-*.f6476.8
Applied rewrites76.8%
if -9.2e14 < d < 2.4e11Initial program 71.9%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6484.8
Applied rewrites84.8%
Final simplification80.6%
(FPCore (a b c d) :precision binary64 (if (<= c -5.5e-36) (/ b c) (if (<= c 4.2e+61) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.5e-36) {
tmp = b / c;
} else if (c <= 4.2e+61) {
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 (c <= (-5.5d-36)) then
tmp = b / c
else if (c <= 4.2d+61) 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 (c <= -5.5e-36) {
tmp = b / c;
} else if (c <= 4.2e+61) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -5.5e-36: tmp = b / c elif c <= 4.2e+61: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -5.5e-36) tmp = Float64(b / c); elseif (c <= 4.2e+61) 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 (c <= -5.5e-36) tmp = b / c; elseif (c <= 4.2e+61) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.5e-36], N[(b / c), $MachinePrecision], If[LessEqual[c, 4.2e+61], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.5 \cdot 10^{-36}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 4.2 \cdot 10^{+61}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -5.49999999999999984e-36 or 4.2000000000000002e61 < c Initial program 52.0%
Taylor expanded in c around inf
lower-/.f6471.4
Applied rewrites71.4%
if -5.49999999999999984e-36 < c < 4.2000000000000002e61Initial program 68.5%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6462.1
Applied rewrites62.1%
(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 60.6%
Taylor expanded in c around inf
lower-/.f6443.9
Applied rewrites43.9%
(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 2024284
(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))))