
(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 (/ -1.0 (fma d (pow a -1.0) (* c (/ c (fma b (- c) (* a d))))))))
(if (<= c -1.7e+138)
(/ b c)
(if (<= c -6.5e+28)
t_0
(if (<= c -1.05e-145)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
(if (<= c 2.2e-77)
(/ (fma b (/ c d) (- a)) d)
(if (<= c 8e+136) t_0 (/ (- b (/ (* a d) c)) c))))))))
double code(double a, double b, double c, double d) {
double t_0 = -1.0 / fma(d, pow(a, -1.0), (c * (c / fma(b, -c, (a * d)))));
double tmp;
if (c <= -1.7e+138) {
tmp = b / c;
} else if (c <= -6.5e+28) {
tmp = t_0;
} else if (c <= -1.05e-145) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (c <= 2.2e-77) {
tmp = fma(b, (c / d), -a) / d;
} else if (c <= 8e+136) {
tmp = t_0;
} else {
tmp = (b - ((a * d) / c)) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(-1.0 / fma(d, (a ^ -1.0), Float64(c * Float64(c / fma(b, Float64(-c), Float64(a * d)))))) tmp = 0.0 if (c <= -1.7e+138) tmp = Float64(b / c); elseif (c <= -6.5e+28) tmp = t_0; elseif (c <= -1.05e-145) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 2.2e-77) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); elseif (c <= 8e+136) tmp = t_0; else tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(-1.0 / N[(d * N[Power[a, -1.0], $MachinePrecision] + N[(c * N[(c / N[(b * (-c) + N[(a * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.7e+138], N[(b / c), $MachinePrecision], If[LessEqual[c, -6.5e+28], t$95$0, If[LessEqual[c, -1.05e-145], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.2e-77], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8e+136], t$95$0, N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-1}{\mathsf{fma}\left(d, {a}^{-1}, c \cdot \frac{c}{\mathsf{fma}\left(b, -c, a \cdot d\right)}\right)}\\
\mathbf{if}\;c \leq -1.7 \cdot 10^{+138}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -6.5 \cdot 10^{+28}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -1.05 \cdot 10^{-145}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 2.2 \cdot 10^{-77}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{elif}\;c \leq 8 \cdot 10^{+136}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\end{array}
\end{array}
if c < -1.70000000000000006e138Initial program 43.6%
Taylor expanded in c around inf
lower-/.f6487.5
Applied rewrites87.5%
if -1.70000000000000006e138 < c < -6.5000000000000001e28 or 2.20000000000000007e-77 < c < 8.00000000000000047e136Initial program 64.9%
Applied rewrites64.7%
lift-/.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6472.4
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f6472.4
Applied rewrites72.4%
Taylor expanded in a around inf
lower-/.f6488.0
Applied rewrites88.0%
if -6.5000000000000001e28 < c < -1.04999999999999996e-145Initial program 90.4%
if -1.04999999999999996e-145 < c < 2.20000000000000007e-77Initial program 69.3%
Applied rewrites69.3%
lift-/.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6483.7
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f6483.7
Applied rewrites83.7%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6491.0
Applied rewrites91.0%
if 8.00000000000000047e136 < c Initial program 33.8%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6486.1
Applied rewrites86.1%
Final simplification89.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma b (- c) (* a d))))
(if (<= (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) INFINITY)
(/ -1.0 (fma d (/ d t_0) (* c (/ c t_0))))
(/ (fma b (/ c d) (- a)) d))))
double code(double a, double b, double c, double d) {
double t_0 = fma(b, -c, (a * d));
double tmp;
if ((((b * c) - (a * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
tmp = -1.0 / fma(d, (d / t_0), (c * (c / t_0)));
} else {
tmp = fma(b, (c / d), -a) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(b, Float64(-c), Float64(a * d)) tmp = 0.0 if (Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) <= Inf) tmp = Float64(-1.0 / fma(d, Float64(d / t_0), Float64(c * Float64(c / t_0)))); else tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(b * (-c) + N[(a * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(-1.0 / N[(d * N[(d / t$95$0), $MachinePrecision] + N[(c * N[(c / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(b, -c, a \cdot d\right)\\
\mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\frac{-1}{\mathsf{fma}\left(d, \frac{d}{t\_0}, c \cdot \frac{c}{t\_0}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 78.2%
Applied rewrites78.0%
lift-/.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6494.3
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f6494.3
Applied rewrites94.3%
if +inf.0 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 0.0%
Applied rewrites0.0%
lift-/.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f642.8
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f642.8
Applied rewrites2.8%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6458.5
Applied rewrites58.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)) (t_1 (- (* b c) (* a d))))
(if (<= d -4.3e+121)
t_0
(if (<= d -1.1e-15)
(/ t_1 (* d d))
(if (<= d 3.65e-186)
(/ b c)
(if (<= d 1.85e-88)
(/ t_1 (* c c))
(if (<= d 4.5e+139) (* (- 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 t_1 = (b * c) - (a * d);
double tmp;
if (d <= -4.3e+121) {
tmp = t_0;
} else if (d <= -1.1e-15) {
tmp = t_1 / (d * d);
} else if (d <= 3.65e-186) {
tmp = b / c;
} else if (d <= 1.85e-88) {
tmp = t_1 / (c * c);
} else if (d <= 4.5e+139) {
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) t_1 = Float64(Float64(b * c) - Float64(a * d)) tmp = 0.0 if (d <= -4.3e+121) tmp = t_0; elseif (d <= -1.1e-15) tmp = Float64(t_1 / Float64(d * d)); elseif (d <= 3.65e-186) tmp = Float64(b / c); elseif (d <= 1.85e-88) tmp = Float64(t_1 / Float64(c * c)); elseif (d <= 4.5e+139) 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]}, Block[{t$95$1 = N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -4.3e+121], t$95$0, If[LessEqual[d, -1.1e-15], N[(t$95$1 / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.65e-186], N[(b / c), $MachinePrecision], If[LessEqual[d, 1.85e-88], N[(t$95$1 / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.5e+139], 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}\\
t_1 := b \cdot c - a \cdot d\\
\mathbf{if}\;d \leq -4.3 \cdot 10^{+121}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.1 \cdot 10^{-15}:\\
\;\;\;\;\frac{t\_1}{d \cdot d}\\
\mathbf{elif}\;d \leq 3.65 \cdot 10^{-186}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;d \leq 1.85 \cdot 10^{-88}:\\
\;\;\;\;\frac{t\_1}{c \cdot c}\\
\mathbf{elif}\;d \leq 4.5 \cdot 10^{+139}:\\
\;\;\;\;\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 < -4.2999999999999997e121 or 4.4999999999999999e139 < d Initial program 37.9%
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.f6481.0
Applied rewrites81.0%
if -4.2999999999999997e121 < d < -1.09999999999999993e-15Initial program 96.5%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6478.0
Applied rewrites78.0%
if -1.09999999999999993e-15 < d < 3.65e-186Initial program 62.8%
Taylor expanded in c around inf
lower-/.f6469.1
Applied rewrites69.1%
if 3.65e-186 < d < 1.8499999999999999e-88Initial program 87.9%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6473.2
Applied rewrites73.2%
if 1.8499999999999999e-88 < d < 4.4999999999999999e139Initial program 68.7%
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-*.f6458.6
Applied rewrites58.6%
Final simplification71.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)) (t_1 (* (- a) (/ d (fma d d (* c c))))))
(if (<= d -2.5e+78)
t_0
(if (<= d -1e-90)
t_1
(if (<= d 3.65e-186)
(/ b c)
(if (<= d 1.85e-88)
(/ (- (* b c) (* a d)) (* c c))
(if (<= d 4.5e+139) t_1 t_0)))))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double t_1 = -a * (d / fma(d, d, (c * c)));
double tmp;
if (d <= -2.5e+78) {
tmp = t_0;
} else if (d <= -1e-90) {
tmp = t_1;
} else if (d <= 3.65e-186) {
tmp = b / c;
} else if (d <= 1.85e-88) {
tmp = ((b * c) - (a * d)) / (c * c);
} else if (d <= 4.5e+139) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) t_1 = Float64(Float64(-a) * Float64(d / fma(d, d, Float64(c * c)))) tmp = 0.0 if (d <= -2.5e+78) tmp = t_0; elseif (d <= -1e-90) tmp = t_1; elseif (d <= 3.65e-186) tmp = Float64(b / c); elseif (d <= 1.85e-88) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(c * c)); elseif (d <= 4.5e+139) tmp = t_1; else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, Block[{t$95$1 = N[((-a) * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.5e+78], t$95$0, If[LessEqual[d, -1e-90], t$95$1, If[LessEqual[d, 3.65e-186], N[(b / c), $MachinePrecision], If[LessEqual[d, 1.85e-88], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.5e+139], t$95$1, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
t_1 := \left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{if}\;d \leq -2.5 \cdot 10^{+78}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1 \cdot 10^{-90}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 3.65 \cdot 10^{-186}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;d \leq 1.85 \cdot 10^{-88}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c}\\
\mathbf{elif}\;d \leq 4.5 \cdot 10^{+139}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.49999999999999992e78 or 4.4999999999999999e139 < d Initial program 45.5%
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.f6480.9
Applied rewrites80.9%
if -2.49999999999999992e78 < d < -9.99999999999999995e-91 or 1.8499999999999999e-88 < d < 4.4999999999999999e139Initial program 74.7%
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.1
Applied rewrites60.1%
if -9.99999999999999995e-91 < d < 3.65e-186Initial program 60.7%
Taylor expanded in c around inf
lower-/.f6473.0
Applied rewrites73.0%
if 3.65e-186 < d < 1.8499999999999999e-88Initial program 87.9%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6473.2
Applied rewrites73.2%
Final simplification71.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma b (/ c d) (- a)) d)) (t_1 (/ (- b (/ (* a d) c)) c)))
(if (<= c -4.3e+125)
t_1
(if (<= c -8.6e+46)
t_0
(if (<= c -1.05e-145)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
(if (<= c 1.7e+16) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(b, (c / d), -a) / d;
double t_1 = (b - ((a * d) / c)) / c;
double tmp;
if (c <= -4.3e+125) {
tmp = t_1;
} else if (c <= -8.6e+46) {
tmp = t_0;
} else if (c <= -1.05e-145) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (c <= 1.7e+16) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(b, Float64(c / d), Float64(-a)) / d) t_1 = Float64(Float64(b - Float64(Float64(a * d) / c)) / c) tmp = 0.0 if (c <= -4.3e+125) tmp = t_1; elseif (c <= -8.6e+46) tmp = t_0; elseif (c <= -1.05e-145) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 1.7e+16) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -4.3e+125], t$95$1, If[LessEqual[c, -8.6e+46], t$95$0, If[LessEqual[c, -1.05e-145], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.7e+16], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
t_1 := \frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{if}\;c \leq -4.3 \cdot 10^{+125}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -8.6 \cdot 10^{+46}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -1.05 \cdot 10^{-145}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 1.7 \cdot 10^{+16}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -4.30000000000000035e125 or 1.7e16 < c Initial program 48.4%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6483.4
Applied rewrites83.4%
if -4.30000000000000035e125 < c < -8.60000000000000009e46 or -1.04999999999999996e-145 < c < 1.7e16Initial program 65.0%
Applied rewrites65.0%
lift-/.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6477.6
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f6477.6
Applied rewrites77.6%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6487.1
Applied rewrites87.1%
if -8.60000000000000009e46 < c < -1.04999999999999996e-145Initial program 90.6%
Final simplification86.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)) (t_1 (* (- a) (/ d (fma d d (* c c))))))
(if (<= d -2.5e+78)
t_0
(if (<= d -1e-90)
t_1
(if (<= d 4.2e-145) (/ b c) (if (<= d 4.5e+139) t_1 t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double t_1 = -a * (d / fma(d, d, (c * c)));
double tmp;
if (d <= -2.5e+78) {
tmp = t_0;
} else if (d <= -1e-90) {
tmp = t_1;
} else if (d <= 4.2e-145) {
tmp = b / c;
} else if (d <= 4.5e+139) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) t_1 = Float64(Float64(-a) * Float64(d / fma(d, d, Float64(c * c)))) tmp = 0.0 if (d <= -2.5e+78) tmp = t_0; elseif (d <= -1e-90) tmp = t_1; elseif (d <= 4.2e-145) tmp = Float64(b / c); elseif (d <= 4.5e+139) tmp = t_1; else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, Block[{t$95$1 = N[((-a) * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.5e+78], t$95$0, If[LessEqual[d, -1e-90], t$95$1, If[LessEqual[d, 4.2e-145], N[(b / c), $MachinePrecision], If[LessEqual[d, 4.5e+139], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
t_1 := \left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{if}\;d \leq -2.5 \cdot 10^{+78}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1 \cdot 10^{-90}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 4.2 \cdot 10^{-145}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;d \leq 4.5 \cdot 10^{+139}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.49999999999999992e78 or 4.4999999999999999e139 < d Initial program 45.5%
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.f6480.9
Applied rewrites80.9%
if -2.49999999999999992e78 < d < -9.99999999999999995e-91 or 4.19999999999999982e-145 < d < 4.4999999999999999e139Initial program 78.0%
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-*.f6459.4
Applied rewrites59.4%
if -9.99999999999999995e-91 < d < 4.19999999999999982e-145Initial program 63.1%
Taylor expanded in c around inf
lower-/.f6470.3
Applied rewrites70.3%
Final simplification69.5%
(FPCore (a b c d)
:precision binary64
(if (<= c -2.1e+131)
(/ b c)
(if (<= c 1.7e+16)
(/ (fma b (/ c d) (- a)) d)
(if (<= c 7.6e+136) (/ (- (* b c) (* a d)) (* c c)) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.1e+131) {
tmp = b / c;
} else if (c <= 1.7e+16) {
tmp = fma(b, (c / d), -a) / d;
} else if (c <= 7.6e+136) {
tmp = ((b * c) - (a * d)) / (c * c);
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -2.1e+131) tmp = Float64(b / c); elseif (c <= 1.7e+16) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); elseif (c <= 7.6e+136) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(c * c)); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.1e+131], N[(b / c), $MachinePrecision], If[LessEqual[c, 1.7e+16], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 7.6e+136], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.1 \cdot 10^{+131}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 1.7 \cdot 10^{+16}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{elif}\;c \leq 7.6 \cdot 10^{+136}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.09999999999999985e131 or 7.60000000000000029e136 < c Initial program 39.7%
Taylor expanded in c around inf
lower-/.f6483.0
Applied rewrites83.0%
if -2.09999999999999985e131 < c < 1.7e16Initial program 72.0%
Applied rewrites71.9%
lift-/.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6482.3
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f6482.3
Applied rewrites82.3%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6479.2
Applied rewrites79.2%
if 1.7e16 < c < 7.60000000000000029e136Initial program 79.3%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6469.4
Applied rewrites69.4%
Final simplification79.6%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.3e+125) (not (<= c 1.7e+16))) (/ (- 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 <= -4.3e+125) || !(c <= 1.7e+16)) {
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 <= -4.3e+125) || !(c <= 1.7e+16)) 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, -4.3e+125], N[Not[LessEqual[c, 1.7e+16]], $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 -4.3 \cdot 10^{+125} \lor \neg \left(c \leq 1.7 \cdot 10^{+16}\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 < -4.30000000000000035e125 or 1.7e16 < c Initial program 48.4%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6483.4
Applied rewrites83.4%
if -4.30000000000000035e125 < c < 1.7e16Initial program 71.8%
Applied rewrites71.7%
lift-/.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6482.2
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f6482.2
Applied rewrites82.2%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6479.7
Applied rewrites79.7%
Final simplification81.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3.6e+123) (not (<= c 7.1e+16))) (/ b c) (/ (- a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.6e+123) || !(c <= 7.1e+16)) {
tmp = b / c;
} else {
tmp = -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+123)) .or. (.not. (c <= 7.1d+16))) then
tmp = b / c
else
tmp = -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+123) || !(c <= 7.1e+16)) {
tmp = b / c;
} else {
tmp = -a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3.6e+123) or not (c <= 7.1e+16): tmp = b / c else: tmp = -a / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.6e+123) || !(c <= 7.1e+16)) tmp = Float64(b / c); else tmp = Float64(Float64(-a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -3.6e+123) || ~((c <= 7.1e+16))) tmp = b / c; else tmp = -a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.6e+123], N[Not[LessEqual[c, 7.1e+16]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[((-a) / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.6 \cdot 10^{+123} \lor \neg \left(c \leq 7.1 \cdot 10^{+16}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{d}\\
\end{array}
\end{array}
if c < -3.59999999999999998e123 or 7.1e16 < c Initial program 47.9%
Taylor expanded in c around inf
lower-/.f6470.7
Applied rewrites70.7%
if -3.59999999999999998e123 < c < 7.1e16Initial program 72.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.f6460.1
Applied rewrites60.1%
Final simplification64.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.6e+82) (not (<= d 6.4e+173))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.6e+82) || !(d <= 6.4e+173)) {
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.6d+82)) .or. (.not. (d <= 6.4d+173))) 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.6e+82) || !(d <= 6.4e+173)) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.6e+82) or not (d <= 6.4e+173): tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.6e+82) || !(d <= 6.4e+173)) tmp = 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.6e+82) || ~((d <= 6.4e+173))) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.6e+82], N[Not[LessEqual[d, 6.4e+173]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.6 \cdot 10^{+82} \lor \neg \left(d \leq 6.4 \cdot 10^{+173}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -2.5999999999999998e82 or 6.4000000000000005e173 < d Initial program 45.0%
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.f6482.7
Applied rewrites82.7%
Applied rewrites36.7%
if -2.5999999999999998e82 < d < 6.4000000000000005e173Initial program 70.6%
Taylor expanded in c around inf
lower-/.f6447.5
Applied rewrites47.5%
Final simplification44.4%
(FPCore (a b c d) :precision binary64 (/ a d))
double code(double a, double b, double c, double d) {
return a / d;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / d
end function
public static double code(double a, double b, double c, double d) {
return a / d;
}
def code(a, b, c, d): return a / d
function code(a, b, c, d) return Float64(a / d) end
function tmp = code(a, b, c, d) tmp = a / d; end
code[a_, b_, c_, d_] := N[(a / d), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{d}
\end{array}
Initial program 63.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.f6443.2
Applied rewrites43.2%
Applied rewrites12.9%
Final simplification12.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 2024305
(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))))