
(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 10 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
(if (<= c -2.35e+113)
(fma
(fma (- (* (/ a (pow c 4.0)) d) (/ b (pow c 3.0))) d (/ (/ (- a) c) c))
d
(/ b c))
(if (<= c -2.6e+19)
(* (/ c (fma c c (* d d))) b)
(if (<= c 5.05e-141)
(/ (- (/ (* b c) d) a) d)
(if (<= c 1.4e+70)
(/ (fma (- d) a (* b c)) (fma d d (* c c)))
(/ (- b (* (/ a c) d)) c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.35e+113) {
tmp = fma(fma((((a / pow(c, 4.0)) * d) - (b / pow(c, 3.0))), d, ((-a / c) / c)), d, (b / c));
} else if (c <= -2.6e+19) {
tmp = (c / fma(c, c, (d * d))) * b;
} else if (c <= 5.05e-141) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 1.4e+70) {
tmp = fma(-d, a, (b * c)) / fma(d, d, (c * c));
} else {
tmp = (b - ((a / c) * d)) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -2.35e+113) tmp = fma(fma(Float64(Float64(Float64(a / (c ^ 4.0)) * d) - Float64(b / (c ^ 3.0))), d, Float64(Float64(Float64(-a) / c) / c)), d, Float64(b / c)); elseif (c <= -2.6e+19) tmp = Float64(Float64(c / fma(c, c, Float64(d * d))) * b); elseif (c <= 5.05e-141) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 1.4e+70) tmp = Float64(fma(Float64(-d), a, Float64(b * c)) / fma(d, d, Float64(c * c))); else tmp = Float64(Float64(b - Float64(Float64(a / c) * d)) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.35e+113], N[(N[(N[(N[(N[(a / N[Power[c, 4.0], $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision] - N[(b / N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * d + N[(N[((-a) / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] * d + N[(b / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -2.6e+19], N[(N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], If[LessEqual[c, 5.05e-141], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.4e+70], N[(N[((-d) * a + N[(b * c), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.35 \cdot 10^{+113}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\frac{a}{{c}^{4}} \cdot d - \frac{b}{{c}^{3}}, d, \frac{\frac{-a}{c}}{c}\right), d, \frac{b}{c}\right)\\
\mathbf{elif}\;c \leq -2.6 \cdot 10^{+19}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot b\\
\mathbf{elif}\;c \leq 5.05 \cdot 10^{-141}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.4 \cdot 10^{+70}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-d, a, b \cdot c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{c} \cdot d}{c}\\
\end{array}
\end{array}
if c < -2.3499999999999999e113Initial program 38.0%
Taylor expanded in d around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites93.6%
if -2.3499999999999999e113 < c < -2.6e19Initial program 89.6%
Taylor expanded in c around inf
lower-/.f6475.3
Applied rewrites75.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-*.f6494.7
Applied rewrites94.7%
if -2.6e19 < c < 5.05000000000000014e-141Initial program 67.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-*.f6484.4
Applied rewrites84.4%
if 5.05000000000000014e-141 < c < 1.39999999999999995e70Initial program 83.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6483.8
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6483.8
Applied rewrites83.8%
if 1.39999999999999995e70 < c Initial program 41.5%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6487.0
Applied rewrites87.0%
Applied rewrites89.1%
Final simplification87.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (* (/ a c) d)) c)))
(if (<= c -7.5e+113)
t_0
(if (<= c -2.6e+19)
(* (/ c (fma c c (* d d))) b)
(if (<= c 5.05e-141)
(/ (- (/ (* b c) d) a) d)
(if (<= c 1.4e+70)
(/ (fma (- d) a (* b c)) (fma d d (* c c)))
t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = (b - ((a / c) * d)) / c;
double tmp;
if (c <= -7.5e+113) {
tmp = t_0;
} else if (c <= -2.6e+19) {
tmp = (c / fma(c, c, (d * d))) * b;
} else if (c <= 5.05e-141) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 1.4e+70) {
tmp = fma(-d, a, (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(Float64(a / c) * d)) / c) tmp = 0.0 if (c <= -7.5e+113) tmp = t_0; elseif (c <= -2.6e+19) tmp = Float64(Float64(c / fma(c, c, Float64(d * d))) * b); elseif (c <= 5.05e-141) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 1.4e+70) tmp = Float64(fma(Float64(-d), a, 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[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -7.5e+113], t$95$0, If[LessEqual[c, -2.6e+19], N[(N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], If[LessEqual[c, 5.05e-141], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.4e+70], N[(N[((-d) * a + 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 - \frac{a}{c} \cdot d}{c}\\
\mathbf{if}\;c \leq -7.5 \cdot 10^{+113}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -2.6 \cdot 10^{+19}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot b\\
\mathbf{elif}\;c \leq 5.05 \cdot 10^{-141}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.4 \cdot 10^{+70}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-d, a, b \cdot c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -7.5000000000000001e113 or 1.39999999999999995e70 < c Initial program 40.1%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6488.9
Applied rewrites88.9%
Applied rewrites90.2%
if -7.5000000000000001e113 < c < -2.6e19Initial program 89.6%
Taylor expanded in c around inf
lower-/.f6475.3
Applied rewrites75.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-*.f6494.7
Applied rewrites94.7%
if -2.6e19 < c < 5.05000000000000014e-141Initial program 67.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-*.f6484.4
Applied rewrites84.4%
if 5.05000000000000014e-141 < c < 1.39999999999999995e70Initial program 83.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6483.8
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6483.8
Applied rewrites83.8%
Final simplification87.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (* (/ a c) d)) c)))
(if (<= c -7.5e+113)
t_0
(if (<= c -2.6e+19)
(* (/ c (fma c c (* d d))) b)
(if (<= c 3800.0) (/ (- (/ (* b c) d) a) d) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b - ((a / c) * d)) / c;
double tmp;
if (c <= -7.5e+113) {
tmp = t_0;
} else if (c <= -2.6e+19) {
tmp = (c / fma(c, c, (d * d))) * b;
} else if (c <= 3800.0) {
tmp = (((b * c) / d) - a) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(Float64(a / c) * d)) / c) tmp = 0.0 if (c <= -7.5e+113) tmp = t_0; elseif (c <= -2.6e+19) tmp = Float64(Float64(c / fma(c, c, Float64(d * d))) * b); elseif (c <= 3800.0) 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[(b - N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -7.5e+113], t$95$0, If[LessEqual[c, -2.6e+19], N[(N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], If[LessEqual[c, 3800.0], 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{b - \frac{a}{c} \cdot d}{c}\\
\mathbf{if}\;c \leq -7.5 \cdot 10^{+113}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -2.6 \cdot 10^{+19}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot b\\
\mathbf{elif}\;c \leq 3800:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -7.5000000000000001e113 or 3800 < c Initial program 46.7%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6485.4
Applied rewrites85.4%
Applied rewrites86.5%
if -7.5000000000000001e113 < c < -2.6e19Initial program 89.6%
Taylor expanded in c around inf
lower-/.f6475.3
Applied rewrites75.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-*.f6494.7
Applied rewrites94.7%
if -2.6e19 < c < 3800Initial program 70.8%
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-*.f6477.4
Applied rewrites77.4%
Final simplification82.2%
(FPCore (a b c d)
:precision binary64
(if (<= c -2.6e+19)
(/ b c)
(if (<= c 1.02e-136)
(/ (- a) d)
(if (<= c 5.2e+128) (* (/ c (fma c c (* d d))) b) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.6e+19) {
tmp = b / c;
} else if (c <= 1.02e-136) {
tmp = -a / d;
} else if (c <= 5.2e+128) {
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 <= -2.6e+19) tmp = Float64(b / c); elseif (c <= 1.02e-136) tmp = Float64(Float64(-a) / d); elseif (c <= 5.2e+128) 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, -2.6e+19], N[(b / c), $MachinePrecision], If[LessEqual[c, 1.02e-136], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 5.2e+128], 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 -2.6 \cdot 10^{+19}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 1.02 \cdot 10^{-136}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 5.2 \cdot 10^{+128}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot b\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.6e19 or 5.2e128 < c Initial program 46.7%
Taylor expanded in c around inf
lower-/.f6480.2
Applied rewrites80.2%
if -2.6e19 < c < 1.0200000000000001e-136Initial program 67.1%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6467.1
Applied rewrites67.1%
if 1.0200000000000001e-136 < c < 5.2e128Initial program 82.4%
Taylor expanded in c around inf
lower-/.f6433.9
Applied rewrites33.9%
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-*.f6455.5
Applied rewrites55.5%
(FPCore (a b c d)
:precision binary64
(if (<= c -2.6e+19)
(/ b c)
(if (<= c 2.8e-120)
(/ (- a) d)
(if (<= c 1.7e+122) (* (/ b (fma c c (* d d))) c) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.6e+19) {
tmp = b / c;
} else if (c <= 2.8e-120) {
tmp = -a / d;
} else if (c <= 1.7e+122) {
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 <= -2.6e+19) tmp = Float64(b / c); elseif (c <= 2.8e-120) tmp = Float64(Float64(-a) / d); elseif (c <= 1.7e+122) 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, -2.6e+19], N[(b / c), $MachinePrecision], If[LessEqual[c, 2.8e-120], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 1.7e+122], 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 -2.6 \cdot 10^{+19}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 2.8 \cdot 10^{-120}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 1.7 \cdot 10^{+122}:\\
\;\;\;\;\frac{b}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot c\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.6e19 or 1.7e122 < c Initial program 46.7%
Taylor expanded in c around inf
lower-/.f6480.2
Applied rewrites80.2%
if -2.6e19 < c < 2.79999999999999994e-120Initial program 67.6%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6465.3
Applied rewrites65.3%
if 2.79999999999999994e-120 < c < 1.7e122Initial program 83.1%
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-*.f6453.2
Applied rewrites53.2%
(FPCore (a b c d) :precision binary64 (if (<= d -7e+34) (/ (fma (/ c d) b (- a)) d) (if (<= d 1.8e+90) (/ (- b (/ (* d a) c)) c) (/ (- (/ (* b c) d) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -7e+34) {
tmp = fma((c / d), b, -a) / d;
} else if (d <= 1.8e+90) {
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 (d <= -7e+34) tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d); elseif (d <= 1.8e+90) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); else tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -7e+34], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.8e+90], N[(N[(b - N[(N[(d * a), $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}\;d \leq -7 \cdot 10^{+34}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\
\mathbf{elif}\;d \leq 1.8 \cdot 10^{+90}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\end{array}
\end{array}
if d < -6.99999999999999996e34Initial program 53.9%
Taylor expanded in c around inf
lower-/.f6423.7
Applied rewrites23.7%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
sub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6481.9
Applied rewrites81.9%
if -6.99999999999999996e34 < d < 1.8e90Initial program 73.4%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6479.7
Applied rewrites79.7%
if 1.8e90 < d Initial program 40.0%
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-*.f6482.5
Applied rewrites82.5%
Final simplification80.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -1.02e+40)
t_0
(if (<= d 3.3e+133) (/ (- b (/ (* d a) c)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -1.02e+40) {
tmp = t_0;
} else if (d <= 3.3e+133) {
tmp = (b - ((d * a) / 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 = -a / d
if (d <= (-1.02d+40)) then
tmp = t_0
else if (d <= 3.3d+133) then
tmp = (b - ((d * a) / 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 = -a / d;
double tmp;
if (d <= -1.02e+40) {
tmp = t_0;
} else if (d <= 3.3e+133) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = -a / d tmp = 0 if d <= -1.02e+40: tmp = t_0 elif d <= 3.3e+133: tmp = (b - ((d * a) / 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 <= -1.02e+40) tmp = t_0; elseif (d <= 3.3e+133) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / 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.02e+40) tmp = t_0; elseif (d <= 3.3e+133) tmp = (b - ((d * a) / c)) / 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.02e+40], t$95$0, If[LessEqual[d, 3.3e+133], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -1.02 \cdot 10^{+40}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 3.3 \cdot 10^{+133}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.02e40 or 3.3e133 < d Initial program 48.2%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6471.8
Applied rewrites71.8%
if -1.02e40 < d < 3.3e133Initial program 72.8%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6478.1
Applied rewrites78.1%
Final simplification75.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -1.02e+40)
t_0
(if (<= d 5.4e+134) (/ (- b (* (/ a c) d)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -1.02e+40) {
tmp = t_0;
} else if (d <= 5.4e+134) {
tmp = (b - ((a / c) * d)) / 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.02d+40)) then
tmp = t_0
else if (d <= 5.4d+134) then
tmp = (b - ((a / c) * d)) / 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.02e+40) {
tmp = t_0;
} else if (d <= 5.4e+134) {
tmp = (b - ((a / c) * d)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = -a / d tmp = 0 if d <= -1.02e+40: tmp = t_0 elif d <= 5.4e+134: tmp = (b - ((a / c) * d)) / 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.02e+40) tmp = t_0; elseif (d <= 5.4e+134) tmp = Float64(Float64(b - Float64(Float64(a / c) * d)) / 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.02e+40) tmp = t_0; elseif (d <= 5.4e+134) tmp = (b - ((a / c) * d)) / 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.02e+40], t$95$0, If[LessEqual[d, 5.4e+134], N[(N[(b - N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -1.02 \cdot 10^{+40}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 5.4 \cdot 10^{+134}:\\
\;\;\;\;\frac{b - \frac{a}{c} \cdot d}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.02e40 or 5.4e134 < d Initial program 48.2%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6471.8
Applied rewrites71.8%
if -1.02e40 < d < 5.4e134Initial program 72.8%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6478.1
Applied rewrites78.1%
Applied rewrites76.3%
Final simplification74.5%
(FPCore (a b c d) :precision binary64 (if (<= c -2.6e+19) (/ b c) (if (<= c 1.05e-52) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.6e+19) {
tmp = b / c;
} else if (c <= 1.05e-52) {
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 <= (-2.6d+19)) then
tmp = b / c
else if (c <= 1.05d-52) 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 <= -2.6e+19) {
tmp = b / c;
} else if (c <= 1.05e-52) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.6e+19: tmp = b / c elif c <= 1.05e-52: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.6e+19) tmp = Float64(b / c); elseif (c <= 1.05e-52) 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 <= -2.6e+19) tmp = b / c; elseif (c <= 1.05e-52) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.6e+19], N[(b / c), $MachinePrecision], If[LessEqual[c, 1.05e-52], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.6 \cdot 10^{+19}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 1.05 \cdot 10^{-52}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.6e19 or 1.0499999999999999e-52 < c Initial program 55.9%
Taylor expanded in c around inf
lower-/.f6467.5
Applied rewrites67.5%
if -2.6e19 < c < 1.0499999999999999e-52Initial program 70.7%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6463.3
Applied rewrites63.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 63.0%
Taylor expanded in c around inf
lower-/.f6445.0
Applied rewrites45.0%
(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 2024255
(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))))