
(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
(let* ((t_0 (fma d d (* c c))))
(if (<= c -4e+153)
(/ (fma (- a) (/ d c) b) c)
(if (<= c -2.35e-139)
(fma (/ c t_0) b (* (/ a t_0) (- d)))
(if (<= c 2.45e-110)
(/ (fma b (/ c d) (- a)) d)
(if (<= c 2.2e+23)
(* (/ -1.0 t_0) (fma (- b) c (* d a)))
(fma
(fma
(- (* (/ a (pow c 4.0)) d) (/ b (pow c 3.0)))
d
(/ (/ (- a) c) c))
d
(/ b c))))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double tmp;
if (c <= -4e+153) {
tmp = fma(-a, (d / c), b) / c;
} else if (c <= -2.35e-139) {
tmp = fma((c / t_0), b, ((a / t_0) * -d));
} else if (c <= 2.45e-110) {
tmp = fma(b, (c / d), -a) / d;
} else if (c <= 2.2e+23) {
tmp = (-1.0 / t_0) * fma(-b, c, (d * a));
} else {
tmp = fma(fma((((a / pow(c, 4.0)) * d) - (b / pow(c, 3.0))), d, ((-a / c) / c)), d, (b / c));
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) tmp = 0.0 if (c <= -4e+153) tmp = Float64(fma(Float64(-a), Float64(d / c), b) / c); elseif (c <= -2.35e-139) tmp = fma(Float64(c / t_0), b, Float64(Float64(a / t_0) * Float64(-d))); elseif (c <= 2.45e-110) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); elseif (c <= 2.2e+23) tmp = Float64(Float64(-1.0 / t_0) * fma(Float64(-b), c, Float64(d * a))); else 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)); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -4e+153], N[(N[((-a) * N[(d / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -2.35e-139], N[(N[(c / t$95$0), $MachinePrecision] * b + N[(N[(a / t$95$0), $MachinePrecision] * (-d)), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.45e-110], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.2e+23], N[(N[(-1.0 / t$95$0), $MachinePrecision] * N[((-b) * c + N[(d * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
\mathbf{if}\;c \leq -4 \cdot 10^{+153}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-a, \frac{d}{c}, b\right)}{c}\\
\mathbf{elif}\;c \leq -2.35 \cdot 10^{-139}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{t\_0}, b, \frac{a}{t\_0} \cdot \left(-d\right)\right)\\
\mathbf{elif}\;c \leq 2.45 \cdot 10^{-110}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{elif}\;c \leq 2.2 \cdot 10^{+23}:\\
\;\;\;\;\frac{-1}{t\_0} \cdot \mathsf{fma}\left(-b, c, d \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;\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)\\
\end{array}
\end{array}
if c < -4e153Initial program 32.5%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6483.8
Applied rewrites83.8%
Applied rewrites96.8%
if -4e153 < c < -2.35000000000000014e-139Initial program 72.2%
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 rewrites80.7%
if -2.35000000000000014e-139 < c < 2.4499999999999999e-110Initial program 75.1%
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 rewrites62.4%
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.f6492.3
Applied rewrites92.3%
Taylor expanded in a around 0
Applied rewrites92.3%
Applied rewrites97.4%
if 2.4499999999999999e-110 < c < 2.20000000000000008e23Initial program 87.7%
lift-/.f64N/A
frac-2negN/A
div-invN/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
neg-mul-1N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6487.9
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6487.9
Applied rewrites87.9%
if 2.20000000000000008e23 < c Initial program 43.6%
Taylor expanded in d around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites81.9%
Final simplification88.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma d d (* c c)))
(t_1 (fma (/ c t_0) b (* (/ a t_0) (- d))))
(t_2 (/ (fma (- a) (/ d c) b) c)))
(if (<= c -4e+153)
t_2
(if (<= c -2.35e-139)
t_1
(if (<= c 3.2e-111)
(/ (fma b (/ c d) (- a)) d)
(if (<= c 1.75e+139) t_1 t_2))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = fma((c / t_0), b, ((a / t_0) * -d));
double t_2 = fma(-a, (d / c), b) / c;
double tmp;
if (c <= -4e+153) {
tmp = t_2;
} else if (c <= -2.35e-139) {
tmp = t_1;
} else if (c <= 3.2e-111) {
tmp = fma(b, (c / d), -a) / d;
} else if (c <= 1.75e+139) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = fma(Float64(c / t_0), b, Float64(Float64(a / t_0) * Float64(-d))) t_2 = Float64(fma(Float64(-a), Float64(d / c), b) / c) tmp = 0.0 if (c <= -4e+153) tmp = t_2; elseif (c <= -2.35e-139) tmp = t_1; elseif (c <= 3.2e-111) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); elseif (c <= 1.75e+139) tmp = t_1; else tmp = t_2; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c / t$95$0), $MachinePrecision] * b + N[(N[(a / t$95$0), $MachinePrecision] * (-d)), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[((-a) * N[(d / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -4e+153], t$95$2, If[LessEqual[c, -2.35e-139], t$95$1, If[LessEqual[c, 3.2e-111], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.75e+139], t$95$1, t$95$2]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \mathsf{fma}\left(\frac{c}{t\_0}, b, \frac{a}{t\_0} \cdot \left(-d\right)\right)\\
t_2 := \frac{\mathsf{fma}\left(-a, \frac{d}{c}, b\right)}{c}\\
\mathbf{if}\;c \leq -4 \cdot 10^{+153}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;c \leq -2.35 \cdot 10^{-139}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq 3.2 \cdot 10^{-111}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{elif}\;c \leq 1.75 \cdot 10^{+139}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if c < -4e153 or 1.74999999999999989e139 < c Initial program 33.7%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6479.6
Applied rewrites79.6%
Applied rewrites92.4%
if -4e153 < c < -2.35000000000000014e-139 or 3.1999999999999998e-111 < c < 1.74999999999999989e139Initial program 72.1%
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 rewrites79.0%
if -2.35000000000000014e-139 < c < 3.1999999999999998e-111Initial program 76.1%
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 rewrites61.9%
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.f6493.5
Applied rewrites93.5%
Taylor expanded in a around 0
Applied rewrites93.5%
Applied rewrites98.6%
Final simplification88.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (- a) (/ d c) b) c)))
(if (<= c -1.4e+31)
t_0
(if (<= c 2.45e-110)
(/ (fma b (/ c d) (- a)) d)
(if (<= c 2.9e+53) (/ (- (* b c) (* d a)) (+ (* d d) (* c c))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(-a, (d / c), b) / c;
double tmp;
if (c <= -1.4e+31) {
tmp = t_0;
} else if (c <= 2.45e-110) {
tmp = fma(b, (c / d), -a) / d;
} else if (c <= 2.9e+53) {
tmp = ((b * c) - (d * a)) / ((d * d) + (c * c));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(-a), Float64(d / c), b) / c) tmp = 0.0 if (c <= -1.4e+31) tmp = t_0; elseif (c <= 2.45e-110) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); elseif (c <= 2.9e+53) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / 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[((-a) * N[(d / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.4e+31], t$95$0, If[LessEqual[c, 2.45e-110], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.9e+53], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $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(-a, \frac{d}{c}, b\right)}{c}\\
\mathbf{if}\;c \leq -1.4 \cdot 10^{+31}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.45 \cdot 10^{-110}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{elif}\;c \leq 2.9 \cdot 10^{+53}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.40000000000000008e31 or 2.9000000000000002e53 < c Initial program 42.7%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6472.5
Applied rewrites72.5%
Applied rewrites80.3%
if -1.40000000000000008e31 < c < 2.4499999999999999e-110Initial program 75.4%
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 rewrites69.8%
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.f6485.1
Applied rewrites85.1%
Taylor expanded in a around 0
Applied rewrites85.1%
Applied rewrites88.4%
if 2.4499999999999999e-110 < c < 2.9000000000000002e53Initial program 87.7%
Final simplification85.1%
(FPCore (a b c d)
:precision binary64
(if (<= c -2.6e+65)
(/ b c)
(if (<= c 7.8e-98)
(/ (fma b (/ c d) (- a)) d)
(if (<= c 1.9e+53) (/ (- (* b c) (* d a)) (* c c)) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.6e+65) {
tmp = b / c;
} else if (c <= 7.8e-98) {
tmp = fma(b, (c / d), -a) / d;
} else if (c <= 1.9e+53) {
tmp = ((b * c) - (d * a)) / (c * c);
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -2.6e+65) tmp = Float64(b / c); elseif (c <= 7.8e-98) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); elseif (c <= 1.9e+53) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(c * c)); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.6e+65], N[(b / c), $MachinePrecision], If[LessEqual[c, 7.8e-98], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.9e+53], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.6 \cdot 10^{+65}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 7.8 \cdot 10^{-98}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{+53}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.60000000000000003e65 or 1.89999999999999999e53 < c Initial program 40.4%
Taylor expanded in c around inf
lower-/.f6470.6
Applied rewrites70.6%
if -2.60000000000000003e65 < c < 7.79999999999999943e-98Initial program 75.8%
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 rewrites70.7%
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.f6482.6
Applied rewrites82.6%
Taylor expanded in a around 0
Applied rewrites82.6%
Applied rewrites85.6%
if 7.79999999999999943e-98 < c < 1.89999999999999999e53Initial program 86.6%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6465.6
Applied rewrites65.6%
Final simplification77.6%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.4e+31)
(/ b c)
(if (<= c 6.6e-147)
(/ (- a) d)
(if (<= c 6.8e+131) (* (/ b (fma d d (* c c))) c) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.4e+31) {
tmp = b / c;
} else if (c <= 6.6e-147) {
tmp = -a / d;
} else if (c <= 6.8e+131) {
tmp = (b / fma(d, d, (c * c))) * c;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.4e+31) tmp = Float64(b / c); elseif (c <= 6.6e-147) tmp = Float64(Float64(-a) / d); elseif (c <= 6.8e+131) tmp = Float64(Float64(b / fma(d, d, Float64(c * c))) * c); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.4e+31], N[(b / c), $MachinePrecision], If[LessEqual[c, 6.6e-147], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 6.8e+131], N[(N[(b / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.4 \cdot 10^{+31}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 6.6 \cdot 10^{-147}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 6.8 \cdot 10^{+131}:\\
\;\;\;\;\frac{b}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot c\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.40000000000000008e31 or 6.79999999999999972e131 < c Initial program 43.9%
Taylor expanded in c around inf
lower-/.f6473.8
Applied rewrites73.8%
if -1.40000000000000008e31 < c < 6.59999999999999975e-147Initial program 76.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.f6471.7
Applied rewrites71.7%
if 6.59999999999999975e-147 < c < 6.79999999999999972e131Initial program 71.9%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6458.7
Applied rewrites58.7%
Final simplification69.6%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.4e+31)
(/ b c)
(if (<= c 2.45e-147)
(/ (- a) d)
(if (<= c 9.5e+131) (* (/ c (fma d d (* c c))) b) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.4e+31) {
tmp = b / c;
} else if (c <= 2.45e-147) {
tmp = -a / d;
} else if (c <= 9.5e+131) {
tmp = (c / fma(d, d, (c * c))) * b;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.4e+31) tmp = Float64(b / c); elseif (c <= 2.45e-147) tmp = Float64(Float64(-a) / d); elseif (c <= 9.5e+131) tmp = Float64(Float64(c / fma(d, d, Float64(c * c))) * b); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.4e+31], N[(b / c), $MachinePrecision], If[LessEqual[c, 2.45e-147], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 9.5e+131], N[(N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.4 \cdot 10^{+31}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 2.45 \cdot 10^{-147}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 9.5 \cdot 10^{+131}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.40000000000000008e31 or 9.50000000000000015e131 < c Initial program 43.9%
Taylor expanded in c around inf
lower-/.f6473.8
Applied rewrites73.8%
if -1.40000000000000008e31 < c < 2.45000000000000002e-147Initial program 76.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.f6471.7
Applied rewrites71.7%
if 2.45000000000000002e-147 < c < 9.50000000000000015e131Initial program 71.9%
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 rewrites75.9%
Taylor expanded in a around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6458.7
Applied rewrites58.7%
Final simplification69.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (- a) (/ d c) b) c)))
(if (<= c -1.4e+31)
t_0
(if (<= c 7.8e-98) (/ (fma b (/ c d) (- a)) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(-a, (d / c), b) / c;
double tmp;
if (c <= -1.4e+31) {
tmp = t_0;
} else if (c <= 7.8e-98) {
tmp = fma(b, (c / d), -a) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(-a), Float64(d / c), b) / c) tmp = 0.0 if (c <= -1.4e+31) tmp = t_0; elseif (c <= 7.8e-98) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[((-a) * N[(d / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.4e+31], t$95$0, If[LessEqual[c, 7.8e-98], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(-a, \frac{d}{c}, b\right)}{c}\\
\mathbf{if}\;c \leq -1.4 \cdot 10^{+31}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 7.8 \cdot 10^{-98}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.40000000000000008e31 or 7.79999999999999943e-98 < c Initial program 52.9%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6471.0
Applied rewrites71.0%
Applied rewrites76.6%
if -1.40000000000000008e31 < c < 7.79999999999999943e-98Initial program 75.9%
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 rewrites69.8%
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.f6484.7
Applied rewrites84.7%
Taylor expanded in a around 0
Applied rewrites84.7%
Applied rewrites87.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (/ (* d a) c)) c)))
(if (<= c -1.4e+31)
t_0
(if (<= c 7.8e-98) (/ (fma b (/ c d) (- a)) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (b - ((d * a) / c)) / c;
double tmp;
if (c <= -1.4e+31) {
tmp = t_0;
} else if (c <= 7.8e-98) {
tmp = fma(b, (c / d), -a) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(Float64(d * a) / c)) / c) tmp = 0.0 if (c <= -1.4e+31) tmp = t_0; elseif (c <= 7.8e-98) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.4e+31], t$95$0, If[LessEqual[c, 7.8e-98], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{if}\;c \leq -1.4 \cdot 10^{+31}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 7.8 \cdot 10^{-98}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.40000000000000008e31 or 7.79999999999999943e-98 < c Initial program 52.9%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6471.0
Applied rewrites71.0%
if -1.40000000000000008e31 < c < 7.79999999999999943e-98Initial program 75.9%
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 rewrites69.8%
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.f6484.7
Applied rewrites84.7%
Taylor expanded in a around 0
Applied rewrites84.7%
Applied rewrites87.9%
Final simplification79.1%
(FPCore (a b c d) :precision binary64 (if (<= c -1.4e+31) (/ b c) (if (<= c 4.8e-97) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.4e+31) {
tmp = b / c;
} else if (c <= 4.8e-97) {
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 <= (-1.4d+31)) then
tmp = b / c
else if (c <= 4.8d-97) 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 <= -1.4e+31) {
tmp = b / c;
} else if (c <= 4.8e-97) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.4e+31: tmp = b / c elif c <= 4.8e-97: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.4e+31) tmp = Float64(b / c); elseif (c <= 4.8e-97) 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 <= -1.4e+31) tmp = b / c; elseif (c <= 4.8e-97) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.4e+31], N[(b / c), $MachinePrecision], If[LessEqual[c, 4.8e-97], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.4 \cdot 10^{+31}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 4.8 \cdot 10^{-97}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.40000000000000008e31 or 4.8e-97 < c Initial program 52.9%
Taylor expanded in c around inf
lower-/.f6463.0
Applied rewrites63.0%
if -1.40000000000000008e31 < c < 4.8e-97Initial program 75.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.f6468.2
Applied rewrites68.2%
Final simplification65.5%
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
return b / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = b / c
end function
public static double code(double a, double b, double c, double d) {
return b / c;
}
def code(a, b, c, d): return b / c
function code(a, b, c, d) return Float64(b / c) end
function tmp = code(a, b, c, d) tmp = b / c; end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{c}
\end{array}
Initial program 64.0%
Taylor expanded in c around inf
lower-/.f6441.8
Applied rewrites41.8%
(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 2024308
(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))))