
(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 (* (- d) (/ a t_0))))
(t_2 (/ (- b (* a (/ d c))) c)))
(if (<= c -1.26e+154)
t_2
(if (<= c -7.6e-24)
t_1
(if (<= c 1.6e-152)
(/ (- (/ (* b c) d) a) d)
(if (<= c 1.95e+146) 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, (-d * (a / t_0)));
double t_2 = (b - (a * (d / c))) / c;
double tmp;
if (c <= -1.26e+154) {
tmp = t_2;
} else if (c <= -7.6e-24) {
tmp = t_1;
} else if (c <= 1.6e-152) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 1.95e+146) {
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(-d) * Float64(a / t_0))) t_2 = Float64(Float64(b - Float64(a * Float64(d / c))) / c) tmp = 0.0 if (c <= -1.26e+154) tmp = t_2; elseif (c <= -7.6e-24) tmp = t_1; elseif (c <= 1.6e-152) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 1.95e+146) 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[((-d) * N[(a / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.26e+154], t$95$2, If[LessEqual[c, -7.6e-24], t$95$1, If[LessEqual[c, 1.6e-152], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.95e+146], 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, \left(-d\right) \cdot \frac{a}{t\_0}\right)\\
t_2 := \frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{if}\;c \leq -1.26 \cdot 10^{+154}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;c \leq -7.6 \cdot 10^{-24}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq 1.6 \cdot 10^{-152}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.95 \cdot 10^{+146}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if c < -1.26e154 or 1.95e146 < c Initial program 32.4%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6432.4
Applied rewrites32.4%
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-*.f6491.2
Applied rewrites91.2%
Applied rewrites98.4%
if -1.26e154 < c < -7.60000000000000052e-24 or 1.60000000000000006e-152 < c < 1.95e146Initial program 77.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 rewrites83.0%
if -7.60000000000000052e-24 < c < 1.60000000000000006e-152Initial program 69.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
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6493.6
Applied rewrites93.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (* a (/ d c))) c)))
(if (<= c -4.6e+80)
t_0
(if (<= c -6e-24)
(* (fma (- b) c (* a d)) (/ -1.0 (fma d d (* c c))))
(if (<= c 1.1e-133)
(/ (- (/ (* b c) d) a) d)
(if (<= c 7e+139) (/ (- (* b c) (* a d)) (fma c c (* d 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 <= -4.6e+80) {
tmp = t_0;
} else if (c <= -6e-24) {
tmp = fma(-b, c, (a * d)) * (-1.0 / fma(d, d, (c * c)));
} else if (c <= 1.1e-133) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 7e+139) {
tmp = ((b * c) - (a * d)) / fma(c, c, (d * 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 <= -4.6e+80) tmp = t_0; elseif (c <= -6e-24) tmp = Float64(fma(Float64(-b), c, Float64(a * d)) * Float64(-1.0 / fma(d, d, Float64(c * c)))); elseif (c <= 1.1e-133) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 7e+139) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / fma(c, c, Float64(d * d))); else tmp = t_0; end return 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, -4.6e+80], t$95$0, If[LessEqual[c, -6e-24], N[(N[((-b) * c + N[(a * d), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.1e-133], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 7e+139], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{if}\;c \leq -4.6 \cdot 10^{+80}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -6 \cdot 10^{-24}:\\
\;\;\;\;\mathsf{fma}\left(-b, c, a \cdot d\right) \cdot \frac{-1}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;c \leq 1.1 \cdot 10^{-133}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 7 \cdot 10^{+139}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -4.60000000000000008e80 or 6.99999999999999957e139 < c Initial program 41.6%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6441.6
Applied rewrites41.6%
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-*.f6490.0
Applied rewrites90.0%
Applied rewrites93.8%
if -4.60000000000000008e80 < c < -5.99999999999999991e-24Initial program 92.1%
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-/.f6492.1
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6492.1
Applied rewrites92.1%
if -5.99999999999999991e-24 < c < 1.1e-133Initial program 69.4%
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-*.f6492.7
Applied rewrites92.7%
if 1.1e-133 < c < 6.99999999999999957e139Initial program 77.4%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6477.5
Applied rewrites77.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* a d)) (fma c c (* d d))))
(t_1 (/ (- b (* a (/ d c))) c)))
(if (<= c -3.5e+85)
t_1
(if (<= c -6e-24)
t_0
(if (<= c 1.1e-133)
(/ (- (/ (* b c) d) a) d)
(if (<= c 7e+139) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / fma(c, c, (d * d));
double t_1 = (b - (a * (d / c))) / c;
double tmp;
if (c <= -3.5e+85) {
tmp = t_1;
} else if (c <= -6e-24) {
tmp = t_0;
} else if (c <= 1.1e-133) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 7e+139) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) / fma(c, c, Float64(d * d))) t_1 = Float64(Float64(b - Float64(a * Float64(d / c))) / c) tmp = 0.0 if (c <= -3.5e+85) tmp = t_1; elseif (c <= -6e-24) tmp = t_0; elseif (c <= 1.1e-133) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 7e+139) 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[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3.5e+85], t$95$1, If[LessEqual[c, -6e-24], t$95$0, If[LessEqual[c, 1.1e-133], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 7e+139], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
t_1 := \frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{if}\;c \leq -3.5 \cdot 10^{+85}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -6 \cdot 10^{-24}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.1 \cdot 10^{-133}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 7 \cdot 10^{+139}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -3.50000000000000005e85 or 6.99999999999999957e139 < c Initial program 40.8%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6440.8
Applied rewrites40.8%
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-*.f6489.8
Applied rewrites89.8%
Applied rewrites93.8%
if -3.50000000000000005e85 < c < -5.99999999999999991e-24 or 1.1e-133 < c < 6.99999999999999957e139Initial program 81.8%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6481.9
Applied rewrites81.9%
if -5.99999999999999991e-24 < c < 1.1e-133Initial program 69.4%
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-*.f6492.7
Applied rewrites92.7%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.65e+69)
(/ b c)
(if (<= c -1.25e-23)
(/ (- (* b c) (* a d)) (* c c))
(if (<= c 3.5e-49)
(/ a (- d))
(if (<= c 4.3e+144) (* (/ c (fma c c (* d d))) b) (/ b c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.65e+69) {
tmp = b / c;
} else if (c <= -1.25e-23) {
tmp = ((b * c) - (a * d)) / (c * c);
} else if (c <= 3.5e-49) {
tmp = a / -d;
} else if (c <= 4.3e+144) {
tmp = (c / fma(c, c, (d * d))) * b;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.65e+69) tmp = Float64(b / c); elseif (c <= -1.25e-23) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(c * c)); elseif (c <= 3.5e-49) tmp = Float64(a / Float64(-d)); elseif (c <= 4.3e+144) tmp = Float64(Float64(c / fma(c, c, Float64(d * d))) * b); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.65e+69], N[(b / c), $MachinePrecision], If[LessEqual[c, -1.25e-23], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.5e-49], N[(a / (-d)), $MachinePrecision], If[LessEqual[c, 4.3e+144], N[(N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], N[(b / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.65 \cdot 10^{+69}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -1.25 \cdot 10^{-23}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c}\\
\mathbf{elif}\;c \leq 3.5 \cdot 10^{-49}:\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{elif}\;c \leq 4.3 \cdot 10^{+144}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot b\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.6499999999999999e69 or 4.29999999999999984e144 < c Initial program 42.6%
Taylor expanded in c around inf
lower-/.f6479.3
Applied rewrites79.3%
if -1.6499999999999999e69 < c < -1.2500000000000001e-23Initial program 95.1%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6478.4
Applied rewrites78.4%
if -1.2500000000000001e-23 < c < 3.50000000000000006e-49Initial program 70.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.f6469.6
Applied rewrites69.6%
if 3.50000000000000006e-49 < c < 4.29999999999999984e144Initial program 77.1%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6477.2
Applied rewrites77.2%
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-*.f6467.3
Applied rewrites67.3%
Applied rewrites67.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (* a (/ d c))) c)))
(if (<= c -1.25e-23)
t_0
(if (<= c 1.6e-48)
(/ a (- d))
(if (<= c 1.45e+34) (* (/ b (fma d d (* c c))) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b - (a * (d / c))) / c;
double tmp;
if (c <= -1.25e-23) {
tmp = t_0;
} else if (c <= 1.6e-48) {
tmp = a / -d;
} else if (c <= 1.45e+34) {
tmp = (b / fma(d, d, (c * c))) * c;
} 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 <= -1.25e-23) tmp = t_0; elseif (c <= 1.6e-48) tmp = Float64(a / Float64(-d)); elseif (c <= 1.45e+34) tmp = Float64(Float64(b / fma(d, d, Float64(c * c))) * c); else tmp = t_0; end return 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, -1.25e-23], t$95$0, If[LessEqual[c, 1.6e-48], N[(a / (-d)), $MachinePrecision], If[LessEqual[c, 1.45e+34], N[(N[(b / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{if}\;c \leq -1.25 \cdot 10^{-23}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.6 \cdot 10^{-48}:\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{elif}\;c \leq 1.45 \cdot 10^{+34}:\\
\;\;\;\;\frac{b}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot c\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.2500000000000001e-23 or 1.4500000000000001e34 < c Initial program 57.4%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6457.4
Applied rewrites57.4%
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.2
Applied rewrites81.2%
Applied rewrites83.5%
if -1.2500000000000001e-23 < c < 1.5999999999999999e-48Initial program 70.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.f6469.6
Applied rewrites69.6%
if 1.5999999999999999e-48 < c < 1.4500000000000001e34Initial program 93.0%
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-*.f6493.0
Applied rewrites93.0%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.3e-23)
(/ b c)
(if (<= c 3.5e-49)
(/ a (- d))
(if (<= c 4.3e+144) (* (/ c (fma c c (* d d))) b) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.3e-23) {
tmp = b / c;
} else if (c <= 3.5e-49) {
tmp = a / -d;
} else if (c <= 4.3e+144) {
tmp = (c / fma(c, c, (d * d))) * b;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.3e-23) tmp = Float64(b / c); elseif (c <= 3.5e-49) tmp = Float64(a / Float64(-d)); elseif (c <= 4.3e+144) tmp = Float64(Float64(c / fma(c, c, Float64(d * d))) * b); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.3e-23], N[(b / c), $MachinePrecision], If[LessEqual[c, 3.5e-49], N[(a / (-d)), $MachinePrecision], If[LessEqual[c, 4.3e+144], N[(N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.3 \cdot 10^{-23}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 3.5 \cdot 10^{-49}:\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{elif}\;c \leq 4.3 \cdot 10^{+144}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot b\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.3e-23 or 4.29999999999999984e144 < c Initial program 54.0%
Taylor expanded in c around inf
lower-/.f6474.7
Applied rewrites74.7%
if -1.3e-23 < c < 3.50000000000000006e-49Initial program 70.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.f6469.6
Applied rewrites69.6%
if 3.50000000000000006e-49 < c < 4.29999999999999984e144Initial program 77.1%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6477.2
Applied rewrites77.2%
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-*.f6467.3
Applied rewrites67.3%
Applied rewrites67.4%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.3e-23)
(/ b c)
(if (<= c 1.6e-48)
(/ a (- d))
(if (<= c 8e+112) (* (/ b (fma d d (* c c))) c) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.3e-23) {
tmp = b / c;
} else if (c <= 1.6e-48) {
tmp = a / -d;
} else if (c <= 8e+112) {
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.3e-23) tmp = Float64(b / c); elseif (c <= 1.6e-48) tmp = Float64(a / Float64(-d)); elseif (c <= 8e+112) 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.3e-23], N[(b / c), $MachinePrecision], If[LessEqual[c, 1.6e-48], N[(a / (-d)), $MachinePrecision], If[LessEqual[c, 8e+112], 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.3 \cdot 10^{-23}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 1.6 \cdot 10^{-48}:\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{elif}\;c \leq 8 \cdot 10^{+112}:\\
\;\;\;\;\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.3e-23 or 7.9999999999999994e112 < c Initial program 54.6%
Taylor expanded in c around inf
lower-/.f6472.2
Applied rewrites72.2%
if -1.3e-23 < c < 1.5999999999999999e-48Initial program 70.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.f6469.6
Applied rewrites69.6%
if 1.5999999999999999e-48 < c < 7.9999999999999994e112Initial program 82.1%
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-*.f6472.0
Applied rewrites72.0%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5.8e-21) (not (<= c 4.8e+31))) (/ (- b (* a (/ d c))) c) (/ (- (/ (* b c) d) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.8e-21) || !(c <= 4.8e+31)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = (((b * c) / d) - a) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-5.8d-21)) .or. (.not. (c <= 4.8d+31))) then
tmp = (b - (a * (d / c))) / c
else
tmp = (((b * c) / d) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.8e-21) || !(c <= 4.8e+31)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = (((b * c) / d) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5.8e-21) or not (c <= 4.8e+31): tmp = (b - (a * (d / c))) / c else: tmp = (((b * c) / d) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5.8e-21) || !(c <= 4.8e+31)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -5.8e-21) || ~((c <= 4.8e+31))) tmp = (b - (a * (d / c))) / c; else tmp = (((b * c) / d) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5.8e-21], N[Not[LessEqual[c, 4.8e+31]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.8 \cdot 10^{-21} \lor \neg \left(c \leq 4.8 \cdot 10^{+31}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -5.8e-21 or 4.79999999999999965e31 < c Initial program 58.0%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6458.0
Applied rewrites58.0%
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-*.f6480.8
Applied rewrites80.8%
Applied rewrites83.0%
if -5.8e-21 < c < 4.79999999999999965e31Initial program 73.0%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6485.4
Applied rewrites85.4%
Final simplification84.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.3e-23) (not (<= c 1.35e-27))) (/ b c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.3e-23) || !(c <= 1.35e-27)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-1.3d-23)) .or. (.not. (c <= 1.35d-27))) then
tmp = b / c
else
tmp = a / -d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.3e-23) || !(c <= 1.35e-27)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.3e-23) or not (c <= 1.35e-27): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.3e-23) || !(c <= 1.35e-27)) tmp = Float64(b / c); else tmp = Float64(a / Float64(-d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.3e-23) || ~((c <= 1.35e-27))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.3e-23], N[Not[LessEqual[c, 1.35e-27]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.3 \cdot 10^{-23} \lor \neg \left(c \leq 1.35 \cdot 10^{-27}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -1.3e-23 or 1.34999999999999994e-27 < c Initial program 60.6%
Taylor expanded in c around inf
lower-/.f6467.4
Applied rewrites67.4%
if -1.3e-23 < c < 1.34999999999999994e-27Initial program 71.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.8
Applied rewrites69.8%
Final simplification68.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 65.2%
Taylor expanded in c around inf
lower-/.f6445.0
Applied rewrites45.0%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024318
(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))))