
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma d d (* c c))) (t_1 (/ (fma c (/ b d) (- a)) d)))
(if (<= d -1.15e+87)
t_1
(if (<= d -7.5e-153)
(/ (- (* b c) (* d a)) (fma c c (* d d)))
(if (<= d 8e-161)
(/ (- b (* a (/ d c))) c)
(if (<= d 5.5e+128) (fma (- a) (/ d t_0) (/ (* b c) t_0)) t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = fma(c, (b / d), -a) / d;
double tmp;
if (d <= -1.15e+87) {
tmp = t_1;
} else if (d <= -7.5e-153) {
tmp = ((b * c) - (d * a)) / fma(c, c, (d * d));
} else if (d <= 8e-161) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 5.5e+128) {
tmp = fma(-a, (d / t_0), ((b * c) / t_0));
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = Float64(fma(c, Float64(b / d), Float64(-a)) / d) tmp = 0.0 if (d <= -1.15e+87) tmp = t_1; elseif (d <= -7.5e-153) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / fma(c, c, Float64(d * d))); elseif (d <= 8e-161) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 5.5e+128) tmp = fma(Float64(-a), Float64(d / t_0), Float64(Float64(b * c) / t_0)); else tmp = t_1; 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 * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.15e+87], t$95$1, If[LessEqual[d, -7.5e-153], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 8e-161], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.5e+128], N[((-a) * N[(d / t$95$0), $MachinePrecision] + N[(N[(b * c), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -1.15 \cdot 10^{+87}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -7.5 \cdot 10^{-153}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;d \leq 8 \cdot 10^{-161}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 5.5 \cdot 10^{+128}:\\
\;\;\;\;\mathsf{fma}\left(-a, \frac{d}{t\_0}, \frac{b \cdot c}{t\_0}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.1500000000000001e87 or 5.4999999999999998e128 < d Initial program 33.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
sub-negN/A
*-commutativeN/A
associate-/l*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6485.1
Applied rewrites85.1%
if -1.1500000000000001e87 < d < -7.5e-153Initial program 85.9%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6486.0
Applied rewrites86.0%
if -7.5e-153 < d < 8.00000000000000022e-161Initial program 75.2%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6495.7
Applied rewrites95.7%
Applied rewrites98.5%
if 8.00000000000000022e-161 < d < 5.4999999999999998e128Initial program 78.7%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-/.f6481.4
Applied rewrites81.4%
Final simplification87.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* d a)) (fma c c (* d d))))
(t_1 (/ (fma c (/ b d) (- a)) d)))
(if (<= d -1.15e+87)
t_1
(if (<= d -7.5e-153)
t_0
(if (<= d 1.18e-148)
(/ (- b (* a (/ d c))) c)
(if (<= d 1.6e+96) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (d * a)) / fma(c, c, (d * d));
double t_1 = fma(c, (b / d), -a) / d;
double tmp;
if (d <= -1.15e+87) {
tmp = t_1;
} else if (d <= -7.5e-153) {
tmp = t_0;
} else if (d <= 1.18e-148) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 1.6e+96) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(d * a)) / fma(c, c, Float64(d * d))) t_1 = Float64(fma(c, Float64(b / d), Float64(-a)) / d) tmp = 0.0 if (d <= -1.15e+87) tmp = t_1; elseif (d <= -7.5e-153) tmp = t_0; elseif (d <= 1.18e-148) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 1.6e+96) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.15e+87], t$95$1, If[LessEqual[d, -7.5e-153], t$95$0, If[LessEqual[d, 1.18e-148], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.6e+96], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - d \cdot a}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
t_1 := \frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -1.15 \cdot 10^{+87}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -7.5 \cdot 10^{-153}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.18 \cdot 10^{-148}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.6 \cdot 10^{+96}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.1500000000000001e87 or 1.60000000000000003e96 < d Initial program 39.1%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
lower-/.f64N/A
sub-negN/A
*-commutativeN/A
associate-/l*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6482.9
Applied rewrites82.9%
if -1.1500000000000001e87 < d < -7.5e-153 or 1.18e-148 < d < 1.60000000000000003e96Initial program 83.4%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6483.4
Applied rewrites83.4%
if -7.5e-153 < d < 1.18e-148Initial program 76.3%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6495.9
Applied rewrites95.9%
Applied rewrites98.5%
Final simplification87.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* b c) (* d a))))
(if (<= c -1.12e+74)
(/ b c)
(if (<= c -5e-102)
(/ (* b c) (fma d d (* c c)))
(if (<= c 6e-118)
(/ t_0 (* d d))
(if (<= c 4.8e+142) (/ t_0 (* c c)) (/ b c)))))))
double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (d * a);
double tmp;
if (c <= -1.12e+74) {
tmp = b / c;
} else if (c <= -5e-102) {
tmp = (b * c) / fma(d, d, (c * c));
} else if (c <= 6e-118) {
tmp = t_0 / (d * d);
} else if (c <= 4.8e+142) {
tmp = t_0 / (c * c);
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b * c) - Float64(d * a)) tmp = 0.0 if (c <= -1.12e+74) tmp = Float64(b / c); elseif (c <= -5e-102) tmp = Float64(Float64(b * c) / fma(d, d, Float64(c * c))); elseif (c <= 6e-118) tmp = Float64(t_0 / Float64(d * d)); elseif (c <= 4.8e+142) tmp = Float64(t_0 / Float64(c * c)); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.12e+74], N[(b / c), $MachinePrecision], If[LessEqual[c, -5e-102], N[(N[(b * c), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 6e-118], N[(t$95$0 / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.8e+142], N[(t$95$0 / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot c - d \cdot a\\
\mathbf{if}\;c \leq -1.12 \cdot 10^{+74}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -5 \cdot 10^{-102}:\\
\;\;\;\;\frac{b \cdot c}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;c \leq 6 \cdot 10^{-118}:\\
\;\;\;\;\frac{t\_0}{d \cdot d}\\
\mathbf{elif}\;c \leq 4.8 \cdot 10^{+142}:\\
\;\;\;\;\frac{t\_0}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.12000000000000003e74 or 4.7999999999999998e142 < c Initial program 40.9%
Taylor expanded in c around inf
lower-/.f6475.3
Applied rewrites75.3%
if -1.12000000000000003e74 < c < -5.00000000000000026e-102Initial program 74.2%
Taylor expanded in b around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6461.8
Applied rewrites61.8%
if -5.00000000000000026e-102 < c < 6.00000000000000035e-118Initial program 82.3%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6479.0
Applied rewrites79.0%
if 6.00000000000000035e-118 < c < 4.7999999999999998e142Initial program 78.2%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6454.5
Applied rewrites54.5%
Final simplification69.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma d d (* c c))) (t_1 (/ (- a) d)))
(if (<= d -1.35e+23)
t_1
(if (<= d -1.35e-90)
(/ (* b c) t_0)
(if (<= d 6.8e-88)
(/ (- (* b c) (* d a)) (* c c))
(if (<= d 3.6e+137) (* (- a) (/ d t_0)) t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = -a / d;
double tmp;
if (d <= -1.35e+23) {
tmp = t_1;
} else if (d <= -1.35e-90) {
tmp = (b * c) / t_0;
} else if (d <= 6.8e-88) {
tmp = ((b * c) - (d * a)) / (c * c);
} else if (d <= 3.6e+137) {
tmp = -a * (d / t_0);
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -1.35e+23) tmp = t_1; elseif (d <= -1.35e-90) tmp = Float64(Float64(b * c) / t_0); elseif (d <= 6.8e-88) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(c * c)); elseif (d <= 3.6e+137) tmp = Float64(Float64(-a) * Float64(d / t_0)); else tmp = t_1; 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[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -1.35e+23], t$95$1, If[LessEqual[d, -1.35e-90], N[(N[(b * c), $MachinePrecision] / t$95$0), $MachinePrecision], If[LessEqual[d, 6.8e-88], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.6e+137], N[((-a) * N[(d / t$95$0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -1.35 \cdot 10^{+23}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -1.35 \cdot 10^{-90}:\\
\;\;\;\;\frac{b \cdot c}{t\_0}\\
\mathbf{elif}\;d \leq 6.8 \cdot 10^{-88}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{c \cdot c}\\
\mathbf{elif}\;d \leq 3.6 \cdot 10^{+137}:\\
\;\;\;\;\left(-a\right) \cdot \frac{d}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.3499999999999999e23 or 3.6e137 < d Initial program 37.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.2
Applied rewrites71.2%
if -1.3499999999999999e23 < d < -1.34999999999999998e-90Initial program 89.0%
Taylor expanded in b around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6464.0
Applied rewrites64.0%
if -1.34999999999999998e-90 < d < 6.79999999999999949e-88Initial program 80.1%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6473.5
Applied rewrites73.5%
if 6.79999999999999949e-88 < d < 3.6e137Initial program 73.1%
Taylor expanded in b around 0
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6455.8
Applied rewrites55.8%
Applied rewrites59.3%
Final simplification68.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma d d (* c c))) (t_1 (/ (- a) d)))
(if (<= d -1.35e+23)
t_1
(if (<= d -5.5e-106)
(/ (* b c) t_0)
(if (<= d 1.45e-157)
(/ b c)
(if (<= d 3.6e+137) (* (- a) (/ d t_0)) t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = -a / d;
double tmp;
if (d <= -1.35e+23) {
tmp = t_1;
} else if (d <= -5.5e-106) {
tmp = (b * c) / t_0;
} else if (d <= 1.45e-157) {
tmp = b / c;
} else if (d <= 3.6e+137) {
tmp = -a * (d / t_0);
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -1.35e+23) tmp = t_1; elseif (d <= -5.5e-106) tmp = Float64(Float64(b * c) / t_0); elseif (d <= 1.45e-157) tmp = Float64(b / c); elseif (d <= 3.6e+137) tmp = Float64(Float64(-a) * Float64(d / t_0)); else tmp = t_1; 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[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -1.35e+23], t$95$1, If[LessEqual[d, -5.5e-106], N[(N[(b * c), $MachinePrecision] / t$95$0), $MachinePrecision], If[LessEqual[d, 1.45e-157], N[(b / c), $MachinePrecision], If[LessEqual[d, 3.6e+137], N[((-a) * N[(d / t$95$0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -1.35 \cdot 10^{+23}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -5.5 \cdot 10^{-106}:\\
\;\;\;\;\frac{b \cdot c}{t\_0}\\
\mathbf{elif}\;d \leq 1.45 \cdot 10^{-157}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;d \leq 3.6 \cdot 10^{+137}:\\
\;\;\;\;\left(-a\right) \cdot \frac{d}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.3499999999999999e23 or 3.6e137 < d Initial program 37.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.2
Applied rewrites71.2%
if -1.3499999999999999e23 < d < -5.5000000000000001e-106Initial program 90.1%
Taylor expanded in b around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6464.4
Applied rewrites64.4%
if -5.5000000000000001e-106 < d < 1.44999999999999994e-157Initial program 77.7%
Taylor expanded in c around inf
lower-/.f6472.2
Applied rewrites72.2%
if 1.44999999999999994e-157 < d < 3.6e137Initial program 76.6%
Taylor expanded in b around 0
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6456.8
Applied rewrites56.8%
Applied rewrites59.4%
Final simplification67.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (* b c) (fma d d (* c c)))))
(if (<= c -1.12e+74)
(/ b c)
(if (<= c -6.5e-153)
t_0
(if (<= c 1.65e-131) (/ (- a) d) (if (<= c 5e+38) t_0 (/ b c)))))))
double code(double a, double b, double c, double d) {
double t_0 = (b * c) / fma(d, d, (c * c));
double tmp;
if (c <= -1.12e+74) {
tmp = b / c;
} else if (c <= -6.5e-153) {
tmp = t_0;
} else if (c <= 1.65e-131) {
tmp = -a / d;
} else if (c <= 5e+38) {
tmp = t_0;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b * c) / fma(d, d, Float64(c * c))) tmp = 0.0 if (c <= -1.12e+74) tmp = Float64(b / c); elseif (c <= -6.5e-153) tmp = t_0; elseif (c <= 1.65e-131) tmp = Float64(Float64(-a) / d); elseif (c <= 5e+38) tmp = t_0; else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.12e+74], N[(b / c), $MachinePrecision], If[LessEqual[c, -6.5e-153], t$95$0, If[LessEqual[c, 1.65e-131], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 5e+38], t$95$0, N[(b / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{if}\;c \leq -1.12 \cdot 10^{+74}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -6.5 \cdot 10^{-153}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.65 \cdot 10^{-131}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 5 \cdot 10^{+38}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.12000000000000003e74 or 4.9999999999999997e38 < c Initial program 47.2%
Taylor expanded in c around inf
lower-/.f6470.1
Applied rewrites70.1%
if -1.12000000000000003e74 < c < -6.50000000000000032e-153 or 1.6500000000000001e-131 < c < 4.9999999999999997e38Initial program 80.9%
Taylor expanded in b around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6460.9
Applied rewrites60.9%
if -6.50000000000000032e-153 < c < 1.6500000000000001e-131Initial program 79.7%
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.f6470.8
Applied rewrites70.8%
Final simplification67.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -1.18e+86)
t_0
(if (<= d -1.42e-90)
(/ (- (* b c) (* d a)) (* d d))
(if (<= d 2.8e+32) (/ (- 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 <= -1.18e+86) {
tmp = t_0;
} else if (d <= -1.42e-90) {
tmp = ((b * c) - (d * a)) / (d * d);
} else if (d <= 2.8e+32) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = -a / d
if (d <= (-1.18d+86)) then
tmp = t_0
else if (d <= (-1.42d-90)) then
tmp = ((b * c) - (d * a)) / (d * d)
else if (d <= 2.8d+32) then
tmp = (b - (a * (d / c))) / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -1.18e+86) {
tmp = t_0;
} else if (d <= -1.42e-90) {
tmp = ((b * c) - (d * a)) / (d * d);
} else if (d <= 2.8e+32) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = -a / d tmp = 0 if d <= -1.18e+86: tmp = t_0 elif d <= -1.42e-90: tmp = ((b * c) - (d * a)) / (d * d) elif d <= 2.8e+32: 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 <= -1.18e+86) tmp = t_0; elseif (d <= -1.42e-90) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(d * d)); elseif (d <= 2.8e+32) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = -a / d; tmp = 0.0; if (d <= -1.18e+86) tmp = t_0; elseif (d <= -1.42e-90) tmp = ((b * c) - (d * a)) / (d * d); elseif (d <= 2.8e+32) tmp = (b - (a * (d / c))) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -1.18e+86], t$95$0, If[LessEqual[d, -1.42e-90], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.8e+32], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -1.18 \cdot 10^{+86}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.42 \cdot 10^{-90}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d}\\
\mathbf{elif}\;d \leq 2.8 \cdot 10^{+32}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.18e86 or 2.8e32 < d Initial program 46.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.f6469.6
Applied rewrites69.6%
if -1.18e86 < d < -1.41999999999999998e-90Initial program 83.1%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6461.7
Applied rewrites61.7%
if -1.41999999999999998e-90 < d < 2.8e32Initial program 78.5%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6484.0
Applied rewrites84.0%
Applied rewrites85.4%
Final simplification76.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma c (/ b d) (- a)) d)))
(if (<= d -7.8e-88)
t_0
(if (<= d 1.35e+53) (/ (- b (* a (/ d c))) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(c, (b / d), -a) / d;
double tmp;
if (d <= -7.8e-88) {
tmp = t_0;
} else if (d <= 1.35e+53) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(c, Float64(b / d), Float64(-a)) / d) tmp = 0.0 if (d <= -7.8e-88) tmp = t_0; elseif (d <= 1.35e+53) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -7.8e-88], t$95$0, If[LessEqual[d, 1.35e+53], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -7.8 \cdot 10^{-88}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.35 \cdot 10^{+53}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -7.79999999999999985e-88 or 1.3500000000000001e53 < d Initial program 54.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
sub-negN/A
*-commutativeN/A
associate-/l*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6477.1
Applied rewrites77.1%
if -7.79999999999999985e-88 < d < 1.3500000000000001e53Initial program 78.9%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6481.9
Applied rewrites81.9%
Applied rewrites83.3%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (- b (* a (/ d c))) c))) (if (<= c -2.2e+39) t_0 (if (<= c 2.1e+36) (/ (- (/ (* b c) d) a) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (b - (a * (d / c))) / c;
double tmp;
if (c <= -2.2e+39) {
tmp = t_0;
} else if (c <= 2.1e+36) {
tmp = (((b * c) / d) - a) / d;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = (b - (a * (d / c))) / c
if (c <= (-2.2d+39)) then
tmp = t_0
else if (c <= 2.1d+36) then
tmp = (((b * c) / d) - a) / d
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b - (a * (d / c))) / c;
double tmp;
if (c <= -2.2e+39) {
tmp = t_0;
} else if (c <= 2.1e+36) {
tmp = (((b * c) / d) - a) / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b - (a * (d / c))) / c tmp = 0 if c <= -2.2e+39: tmp = t_0 elif c <= 2.1e+36: tmp = (((b * c) / d) - a) / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(a * Float64(d / c))) / c) tmp = 0.0 if (c <= -2.2e+39) tmp = t_0; elseif (c <= 2.1e+36) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b - (a * (d / c))) / c; tmp = 0.0; if (c <= -2.2e+39) tmp = t_0; elseif (c <= 2.1e+36) tmp = (((b * c) / d) - a) / d; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2.2e+39], t$95$0, If[LessEqual[c, 2.1e+36], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{if}\;c \leq -2.2 \cdot 10^{+39}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.1 \cdot 10^{+36}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -2.2000000000000001e39 or 2.10000000000000004e36 < c Initial program 49.1%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6478.7
Applied rewrites78.7%
Applied rewrites83.2%
if -2.2000000000000001e39 < c < 2.10000000000000004e36Initial program 79.9%
Taylor expanded in c around 0
Applied rewrites75.6%
Taylor expanded in c around 0
Applied rewrites76.5%
Final simplification79.4%
(FPCore (a b c d) :precision binary64 (if (<= c -1850000000000.0) (/ b c) (if (<= c 3.9e+29) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1850000000000.0) {
tmp = b / c;
} else if (c <= 3.9e+29) {
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 <= (-1850000000000.0d0)) then
tmp = b / c
else if (c <= 3.9d+29) 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 <= -1850000000000.0) {
tmp = b / c;
} else if (c <= 3.9e+29) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1850000000000.0: tmp = b / c elif c <= 3.9e+29: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1850000000000.0) tmp = Float64(b / c); elseif (c <= 3.9e+29) 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 <= -1850000000000.0) tmp = b / c; elseif (c <= 3.9e+29) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1850000000000.0], N[(b / c), $MachinePrecision], If[LessEqual[c, 3.9e+29], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1850000000000:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 3.9 \cdot 10^{+29}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.85e12 or 3.89999999999999968e29 < c Initial program 51.0%
Taylor expanded in c around inf
lower-/.f6468.2
Applied rewrites68.2%
if -1.85e12 < c < 3.89999999999999968e29Initial program 80.1%
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.f6458.4
Applied rewrites58.4%
Final simplification62.8%
(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 66.9%
Taylor expanded in c around inf
lower-/.f6443.1
Applied rewrites43.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 2024238
(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))))