
(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))) (t_1 (fma (/ c t_0) b (* (/ a t_0) (- d)))))
(if (<= d -1.62e+106)
(/ (fma (/ b d) c (- a)) d)
(if (<= d -3.2e-106)
t_1
(if (<= d 4.5e-109)
(/ (- b (/ (* a d) c)) c)
(if (<= d 4.8e+114) t_1 (fma (/ c d) (/ b d) (/ (- a) d))))))))
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 tmp;
if (d <= -1.62e+106) {
tmp = fma((b / d), c, -a) / d;
} else if (d <= -3.2e-106) {
tmp = t_1;
} else if (d <= 4.5e-109) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 4.8e+114) {
tmp = t_1;
} else {
tmp = fma((c / d), (b / d), (-a / d));
}
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))) tmp = 0.0 if (d <= -1.62e+106) tmp = Float64(fma(Float64(b / d), c, Float64(-a)) / d); elseif (d <= -3.2e-106) tmp = t_1; elseif (d <= 4.5e-109) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); elseif (d <= 4.8e+114) tmp = t_1; else tmp = fma(Float64(c / d), Float64(b / d), Float64(Float64(-a) / d)); 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]}, If[LessEqual[d, -1.62e+106], N[(N[(N[(b / d), $MachinePrecision] * c + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -3.2e-106], t$95$1, If[LessEqual[d, 4.5e-109], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 4.8e+114], t$95$1, N[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision] + N[((-a) / d), $MachinePrecision]), $MachinePrecision]]]]]]]
\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)\\
\mathbf{if}\;d \leq -1.62 \cdot 10^{+106}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{d}, c, -a\right)}{d}\\
\mathbf{elif}\;d \leq -3.2 \cdot 10^{-106}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 4.5 \cdot 10^{-109}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 4.8 \cdot 10^{+114}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{d}, \frac{b}{d}, \frac{-a}{d}\right)\\
\end{array}
\end{array}
if d < -1.62e106Initial program 43.9%
Taylor expanded in c around inf
lower-/.f6419.1
Applied rewrites19.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
sub-negN/A
mul-1-negN/A
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6479.1
Applied rewrites79.1%
Applied rewrites84.5%
if -1.62e106 < d < -3.2e-106 or 4.5000000000000001e-109 < d < 4.8e114Initial program 75.3%
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 rewrites81.6%
if -3.2e-106 < d < 4.5000000000000001e-109Initial program 74.4%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6493.4
Applied rewrites93.4%
if 4.8e114 < d Initial program 19.1%
Taylor expanded in c around inf
lower-/.f6410.0
Applied rewrites10.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
sub-negN/A
mul-1-negN/A
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6482.0
Applied rewrites82.0%
Applied rewrites89.2%
Final simplification87.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)) (t_1 (* (/ d (fma c c (* d d))) (- a))))
(if (<= d -3.2e+133)
t_0
(if (<= d -2.25e-74)
t_1
(if (<= d 1.4e-111) (/ b c) (if (<= d 3.9e+96) t_1 t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double t_1 = (d / fma(c, c, (d * d))) * -a;
double tmp;
if (d <= -3.2e+133) {
tmp = t_0;
} else if (d <= -2.25e-74) {
tmp = t_1;
} else if (d <= 1.4e-111) {
tmp = b / c;
} else if (d <= 3.9e+96) {
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(d / fma(c, c, Float64(d * d))) * Float64(-a)) tmp = 0.0 if (d <= -3.2e+133) tmp = t_0; elseif (d <= -2.25e-74) tmp = t_1; elseif (d <= 1.4e-111) tmp = Float64(b / c); elseif (d <= 3.9e+96) 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[(N[(d / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision]}, If[LessEqual[d, -3.2e+133], t$95$0, If[LessEqual[d, -2.25e-74], t$95$1, If[LessEqual[d, 1.4e-111], N[(b / c), $MachinePrecision], If[LessEqual[d, 3.9e+96], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
t_1 := \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \left(-a\right)\\
\mathbf{if}\;d \leq -3.2 \cdot 10^{+133}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -2.25 \cdot 10^{-74}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 1.4 \cdot 10^{-111}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;d \leq 3.9 \cdot 10^{+96}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -3.19999999999999997e133 or 3.9e96 < d Initial program 26.1%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6466.6
Applied rewrites66.6%
if -3.19999999999999997e133 < d < -2.25e-74 or 1.39999999999999998e-111 < d < 3.9e96Initial program 76.0%
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.8
Applied rewrites67.8%
if -2.25e-74 < d < 1.39999999999999998e-111Initial program 75.5%
Taylor expanded in c around inf
lower-/.f6472.0
Applied rewrites72.0%
Final simplification68.9%
(FPCore (a b c d)
:precision binary64
(if (<= d -3.7e+109)
(/ (fma (/ c d) b (- a)) d)
(if (<= d -1.9e-104)
(/ (- (* c b) (* a d)) (+ (* d d) (* c c)))
(if (<= d 1.4e-13)
(/ (- b (/ (* a d) c)) c)
(/ (fma (/ b d) c (- a)) d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3.7e+109) {
tmp = fma((c / d), b, -a) / d;
} else if (d <= -1.9e-104) {
tmp = ((c * b) - (a * d)) / ((d * d) + (c * c));
} else if (d <= 1.4e-13) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = fma((b / d), c, -a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -3.7e+109) tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d); elseif (d <= -1.9e-104) tmp = Float64(Float64(Float64(c * b) - Float64(a * d)) / Float64(Float64(d * d) + Float64(c * c))); elseif (d <= 1.4e-13) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); else tmp = Float64(fma(Float64(b / d), c, Float64(-a)) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -3.7e+109], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -1.9e-104], N[(N[(N[(c * b), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.4e-13], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(b / d), $MachinePrecision] * c + (-a)), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.7 \cdot 10^{+109}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\
\mathbf{elif}\;d \leq -1.9 \cdot 10^{-104}:\\
\;\;\;\;\frac{c \cdot b - a \cdot d}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;d \leq 1.4 \cdot 10^{-13}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{d}, c, -a\right)}{d}\\
\end{array}
\end{array}
if d < -3.7000000000000002e109Initial program 42.3%
Taylor expanded in c around inf
lower-/.f6419.5
Applied rewrites19.5%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-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
mul-1-negN/A
sub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6478.5
Applied rewrites78.5%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-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.f6484.2
Applied rewrites84.2%
if -3.7000000000000002e109 < d < -1.9e-104Initial program 85.0%
if -1.9e-104 < d < 1.4000000000000001e-13Initial program 74.4%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6487.2
Applied rewrites87.2%
if 1.4000000000000001e-13 < d Initial program 33.9%
Taylor expanded in c around inf
lower-/.f6415.1
Applied rewrites15.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
sub-negN/A
mul-1-negN/A
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6474.3
Applied rewrites74.3%
Applied rewrites80.2%
Final simplification84.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ b d) c (- a)) d)))
(if (<= d -3.4e+86)
t_0
(if (<= d -4.8e-60)
(/ (- d) (/ (fma d d (* c c)) a))
(if (<= d 1.4e-13) (/ (- 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 <= -3.4e+86) {
tmp = t_0;
} else if (d <= -4.8e-60) {
tmp = -d / (fma(d, d, (c * c)) / a);
} else if (d <= 1.4e-13) {
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 <= -3.4e+86) tmp = t_0; elseif (d <= -4.8e-60) tmp = Float64(Float64(-d) / Float64(fma(d, d, Float64(c * c)) / a)); elseif (d <= 1.4e-13) 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, -3.4e+86], t$95$0, If[LessEqual[d, -4.8e-60], N[((-d) / N[(N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.4e-13], 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 -3.4 \cdot 10^{+86}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -4.8 \cdot 10^{-60}:\\
\;\;\;\;\frac{-d}{\frac{\mathsf{fma}\left(d, d, c \cdot c\right)}{a}}\\
\mathbf{elif}\;d \leq 1.4 \cdot 10^{-13}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -3.3999999999999998e86 or 1.4000000000000001e-13 < d Initial program 39.3%
Taylor expanded in c around inf
lower-/.f6417.6
Applied rewrites17.6%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-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
mul-1-negN/A
sub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6475.3
Applied rewrites75.3%
Applied rewrites80.8%
if -3.3999999999999998e86 < d < -4.80000000000000019e-60Initial program 84.4%
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-*.f6470.9
Applied rewrites70.9%
Applied rewrites71.1%
if -4.80000000000000019e-60 < d < 1.4000000000000001e-13Initial program 75.6%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6484.1
Applied rewrites84.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ b d) c (- a)) d)))
(if (<= d -7.6e+86)
t_0
(if (<= d -4.8e-60)
(* (/ d (fma c c (* d d))) (- a))
(if (<= d 1.4e-13) (/ (- 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 <= -7.6e+86) {
tmp = t_0;
} else if (d <= -4.8e-60) {
tmp = (d / fma(c, c, (d * d))) * -a;
} else if (d <= 1.4e-13) {
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 <= -7.6e+86) tmp = t_0; elseif (d <= -4.8e-60) tmp = Float64(Float64(d / fma(c, c, Float64(d * d))) * Float64(-a)); elseif (d <= 1.4e-13) 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, -7.6e+86], t$95$0, If[LessEqual[d, -4.8e-60], N[(N[(d / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision], If[LessEqual[d, 1.4e-13], 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 -7.6 \cdot 10^{+86}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -4.8 \cdot 10^{-60}:\\
\;\;\;\;\frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \left(-a\right)\\
\mathbf{elif}\;d \leq 1.4 \cdot 10^{-13}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -7.59999999999999956e86 or 1.4000000000000001e-13 < d Initial program 39.3%
Taylor expanded in c around inf
lower-/.f6417.6
Applied rewrites17.6%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-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
mul-1-negN/A
sub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6475.3
Applied rewrites75.3%
Applied rewrites80.8%
if -7.59999999999999956e86 < d < -4.80000000000000019e-60Initial program 84.4%
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-*.f6470.9
Applied rewrites70.9%
if -4.80000000000000019e-60 < d < 1.4000000000000001e-13Initial program 75.6%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6484.1
Applied rewrites84.1%
Final simplification80.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (/ (* c b) d) a) d)))
(if (<= d -7.6e+86)
t_0
(if (<= d -4.8e-60)
(* (/ d (fma c c (* d d))) (- a))
(if (<= d 1.1e-13) (/ (- 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 <= -7.6e+86) {
tmp = t_0;
} else if (d <= -4.8e-60) {
tmp = (d / fma(c, c, (d * d))) * -a;
} else if (d <= 1.1e-13) {
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 <= -7.6e+86) tmp = t_0; elseif (d <= -4.8e-60) tmp = Float64(Float64(d / fma(c, c, Float64(d * d))) * Float64(-a)); elseif (d <= 1.1e-13) 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[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -7.6e+86], t$95$0, If[LessEqual[d, -4.8e-60], N[(N[(d / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision], If[LessEqual[d, 1.1e-13], 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 -7.6 \cdot 10^{+86}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -4.8 \cdot 10^{-60}:\\
\;\;\;\;\frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \left(-a\right)\\
\mathbf{elif}\;d \leq 1.1 \cdot 10^{-13}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -7.59999999999999956e86 or 1.09999999999999998e-13 < d Initial program 39.3%
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-*.f6475.3
Applied rewrites75.3%
if -7.59999999999999956e86 < d < -4.80000000000000019e-60Initial program 84.4%
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-*.f6470.9
Applied rewrites70.9%
if -4.80000000000000019e-60 < d < 1.09999999999999998e-13Initial program 75.6%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6484.1
Applied rewrites84.1%
Final simplification78.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -3.2e+133)
t_0
(if (<= d -4.8e-60)
(* (/ d (fma c c (* d d))) (- a))
(if (<= d 5.2e-11) (/ (- b (/ (* a d) c)) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -3.2e+133) {
tmp = t_0;
} else if (d <= -4.8e-60) {
tmp = (d / fma(c, c, (d * d))) * -a;
} else if (d <= 5.2e-11) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -3.2e+133) tmp = t_0; elseif (d <= -4.8e-60) tmp = Float64(Float64(d / fma(c, c, Float64(d * d))) * Float64(-a)); elseif (d <= 5.2e-11) 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[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -3.2e+133], t$95$0, If[LessEqual[d, -4.8e-60], N[(N[(d / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision], If[LessEqual[d, 5.2e-11], 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{-a}{d}\\
\mathbf{if}\;d \leq -3.2 \cdot 10^{+133}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -4.8 \cdot 10^{-60}:\\
\;\;\;\;\frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \left(-a\right)\\
\mathbf{elif}\;d \leq 5.2 \cdot 10^{-11}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -3.19999999999999997e133 or 5.2000000000000001e-11 < d Initial program 33.6%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6465.9
Applied rewrites65.9%
if -3.19999999999999997e133 < d < -4.80000000000000019e-60Initial program 83.5%
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-*.f6469.3
Applied rewrites69.3%
if -4.80000000000000019e-60 < d < 5.2000000000000001e-11Initial program 75.8%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6483.3
Applied rewrites83.3%
Final simplification74.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma d (/ (- a) c) b) c)))
(if (<= c -2.6e+45)
t_0
(if (<= c 1.75e+68) (/ (- (/ (* c b) d) a) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, (-a / c), b) / c;
double tmp;
if (c <= -2.6e+45) {
tmp = t_0;
} else if (c <= 1.75e+68) {
tmp = (((c * b) / d) - a) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(d, Float64(Float64(-a) / c), b) / c) tmp = 0.0 if (c <= -2.6e+45) tmp = t_0; elseif (c <= 1.75e+68) tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * N[((-a) / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2.6e+45], t$95$0, If[LessEqual[c, 1.75e+68], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(d, \frac{-a}{c}, b\right)}{c}\\
\mathbf{if}\;c \leq -2.6 \cdot 10^{+45}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.75 \cdot 10^{+68}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -2.60000000000000007e45 or 1.74999999999999989e68 < c Initial program 42.0%
Taylor expanded in c around inf
lower-/.f6468.5
Applied rewrites68.5%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-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
mul-1-negN/A
sub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6418.8
Applied rewrites18.8%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
associate-/l*N/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6480.6
Applied rewrites80.6%
if -2.60000000000000007e45 < c < 1.74999999999999989e68Initial program 73.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-*.f6476.4
Applied rewrites76.4%
Final simplification78.1%
(FPCore (a b c d) :precision binary64 (if (<= c -2.55e+45) (/ b c) (if (<= c 1.75e+68) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.55e+45) {
tmp = b / c;
} else if (c <= 1.75e+68) {
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.55d+45)) then
tmp = b / c
else if (c <= 1.75d+68) 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.55e+45) {
tmp = b / c;
} else if (c <= 1.75e+68) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.55e+45: tmp = b / c elif c <= 1.75e+68: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.55e+45) tmp = Float64(b / c); elseif (c <= 1.75e+68) 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.55e+45) tmp = b / c; elseif (c <= 1.75e+68) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.55e+45], N[(b / c), $MachinePrecision], If[LessEqual[c, 1.75e+68], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.55 \cdot 10^{+45}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 1.75 \cdot 10^{+68}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.5499999999999999e45 or 1.74999999999999989e68 < c Initial program 42.0%
Taylor expanded in c around inf
lower-/.f6468.5
Applied rewrites68.5%
if -2.5499999999999999e45 < c < 1.74999999999999989e68Initial program 73.8%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6461.6
Applied rewrites61.6%
(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 61.0%
Taylor expanded in c around inf
lower-/.f6441.1
Applied rewrites41.1%
(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 2024268
(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))))