
(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 (/ (- b (* (/ a c) d)) c)))
(if (<= c -4.8e+126)
t_1
(if (<= c -1.05e-160)
(/ (- (* b c) (* d a)) (+ (* d d) (* c c)))
(if (<= c 2.1e-6)
(/ (- (/ (* b c) d) a) d)
(if (<= c 1.32e+113) (fma (/ c t_0) b (* (/ a t_0) (- d))) t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = (b - ((a / c) * d)) / c;
double tmp;
if (c <= -4.8e+126) {
tmp = t_1;
} else if (c <= -1.05e-160) {
tmp = ((b * c) - (d * a)) / ((d * d) + (c * c));
} else if (c <= 2.1e-6) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 1.32e+113) {
tmp = fma((c / t_0), b, ((a / t_0) * -d));
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = Float64(Float64(b - Float64(Float64(a / c) * d)) / c) tmp = 0.0 if (c <= -4.8e+126) tmp = t_1; elseif (c <= -1.05e-160) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(Float64(d * d) + Float64(c * c))); elseif (c <= 2.1e-6) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 1.32e+113) tmp = fma(Float64(c / t_0), b, Float64(Float64(a / t_0) * Float64(-d))); 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[(b - N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -4.8e+126], t$95$1, If[LessEqual[c, -1.05e-160], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.1e-6], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.32e+113], N[(N[(c / t$95$0), $MachinePrecision] * b + N[(N[(a / t$95$0), $MachinePrecision] * (-d)), $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{b - \frac{a}{c} \cdot d}{c}\\
\mathbf{if}\;c \leq -4.8 \cdot 10^{+126}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -1.05 \cdot 10^{-160}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;c \leq 2.1 \cdot 10^{-6}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.32 \cdot 10^{+113}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{t\_0}, b, \frac{a}{t\_0} \cdot \left(-d\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -4.80000000000000024e126 or 1.31999999999999996e113 < c Initial program 42.8%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6481.6
Applied rewrites81.6%
Applied rewrites92.7%
if -4.80000000000000024e126 < c < -1.05e-160Initial program 84.1%
if -1.05e-160 < c < 2.0999999999999998e-6Initial program 69.7%
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-*.f6486.8
Applied rewrites86.8%
if 2.0999999999999998e-6 < c < 1.31999999999999996e113Initial program 84.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 rewrites91.0%
Final simplification88.5%
(FPCore (a b c d)
:precision binary64
(if (<= c -2.2e+144)
(/ b c)
(if (<= c -3.3e-78)
(* (/ c (fma d d (* c c))) b)
(if (<= c 2.1e-6)
(/ (- a) d)
(if (<= c 1.9e+100) (/ (- (* b c) (* d a)) (* c c)) (/ b c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.2e+144) {
tmp = b / c;
} else if (c <= -3.3e-78) {
tmp = (c / fma(d, d, (c * c))) * b;
} else if (c <= 2.1e-6) {
tmp = -a / d;
} else if (c <= 1.9e+100) {
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.2e+144) tmp = Float64(b / c); elseif (c <= -3.3e-78) tmp = Float64(Float64(c / fma(d, d, Float64(c * c))) * b); elseif (c <= 2.1e-6) tmp = Float64(Float64(-a) / d); elseif (c <= 1.9e+100) 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.2e+144], N[(b / c), $MachinePrecision], If[LessEqual[c, -3.3e-78], N[(N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], If[LessEqual[c, 2.1e-6], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 1.9e+100], 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.2 \cdot 10^{+144}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -3.3 \cdot 10^{-78}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b\\
\mathbf{elif}\;c \leq 2.1 \cdot 10^{-6}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{+100}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.19999999999999988e144 or 1.89999999999999982e100 < c Initial program 42.8%
Taylor expanded in c around inf
lower-/.f6479.9
Applied rewrites79.9%
if -2.19999999999999988e144 < c < -3.29999999999999982e-78Initial program 78.0%
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 rewrites78.4%
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-*.f6456.6
Applied rewrites56.6%
if -3.29999999999999982e-78 < c < 2.0999999999999998e-6Initial program 73.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.f6468.3
Applied rewrites68.3%
if 2.0999999999999998e-6 < c < 1.89999999999999982e100Initial program 90.0%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6474.2
Applied rewrites74.2%
Final simplification70.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (* (/ a c) d)) c)))
(if (<= c -4.8e+126)
t_0
(if (<= c -1.05e-160)
(/ (- (* b c) (* d a)) (+ (* d d) (* c c)))
(if (<= c 2.4e+15) (/ (- (/ (* b c) d) a) d) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b - ((a / c) * d)) / c;
double tmp;
if (c <= -4.8e+126) {
tmp = t_0;
} else if (c <= -1.05e-160) {
tmp = ((b * c) - (d * a)) / ((d * d) + (c * c));
} else if (c <= 2.4e+15) {
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 / c) * d)) / c
if (c <= (-4.8d+126)) then
tmp = t_0
else if (c <= (-1.05d-160)) then
tmp = ((b * c) - (d * a)) / ((d * d) + (c * c))
else if (c <= 2.4d+15) 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 / c) * d)) / c;
double tmp;
if (c <= -4.8e+126) {
tmp = t_0;
} else if (c <= -1.05e-160) {
tmp = ((b * c) - (d * a)) / ((d * d) + (c * c));
} else if (c <= 2.4e+15) {
tmp = (((b * c) / d) - a) / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b - ((a / c) * d)) / c tmp = 0 if c <= -4.8e+126: tmp = t_0 elif c <= -1.05e-160: tmp = ((b * c) - (d * a)) / ((d * d) + (c * c)) elif c <= 2.4e+15: tmp = (((b * c) / d) - a) / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(Float64(a / c) * d)) / c) tmp = 0.0 if (c <= -4.8e+126) tmp = t_0; elseif (c <= -1.05e-160) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(Float64(d * d) + Float64(c * c))); elseif (c <= 2.4e+15) 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 / c) * d)) / c; tmp = 0.0; if (c <= -4.8e+126) tmp = t_0; elseif (c <= -1.05e-160) tmp = ((b * c) - (d * a)) / ((d * d) + (c * c)); elseif (c <= 2.4e+15) 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[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -4.8e+126], t$95$0, If[LessEqual[c, -1.05e-160], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.4e+15], 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 - \frac{a}{c} \cdot d}{c}\\
\mathbf{if}\;c \leq -4.8 \cdot 10^{+126}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -1.05 \cdot 10^{-160}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{+15}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -4.80000000000000024e126 or 2.4e15 < c Initial program 53.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.9
Applied rewrites79.9%
Applied rewrites89.0%
if -4.80000000000000024e126 < c < -1.05e-160Initial program 84.1%
if -1.05e-160 < c < 2.4e15Initial program 70.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
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6485.6
Applied rewrites85.6%
Final simplification86.7%
(FPCore (a b c d)
:precision binary64
(if (<= c -3.65)
(/ b c)
(if (<= c 2.4e+15)
(/ (fma (/ c d) b (- a)) d)
(if (<= c 1.9e+100) (/ (- (* b c) (* d a)) (* c c)) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.65) {
tmp = b / c;
} else if (c <= 2.4e+15) {
tmp = fma((c / d), b, -a) / d;
} else if (c <= 1.9e+100) {
tmp = ((b * c) - (d * a)) / (c * c);
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -3.65) tmp = Float64(b / c); elseif (c <= 2.4e+15) tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d); elseif (c <= 1.9e+100) 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, -3.65], N[(b / c), $MachinePrecision], If[LessEqual[c, 2.4e+15], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.9e+100], 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 -3.65:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{+15}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{+100}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -3.64999999999999991 or 1.89999999999999982e100 < c Initial program 51.0%
Taylor expanded in c around inf
lower-/.f6471.5
Applied rewrites71.5%
if -3.64999999999999991 < c < 2.4e15Initial program 75.4%
Taylor expanded in d around inf
Applied rewrites77.7%
Taylor expanded in c around 0
Applied rewrites81.0%
if 2.4e15 < c < 1.89999999999999982e100Initial program 91.5%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6483.4
Applied rewrites83.4%
Final simplification77.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* b c) (* d a))))
(if (<= c -3.65)
(/ b c)
(if (<= c 3.5e-95)
(/ t_0 (* d d))
(if (<= c 1.9e+100) (/ 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 <= -3.65) {
tmp = b / c;
} else if (c <= 3.5e-95) {
tmp = t_0 / (d * d);
} else if (c <= 1.9e+100) {
tmp = t_0 / (c * c);
} 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) :: t_0
real(8) :: tmp
t_0 = (b * c) - (d * a)
if (c <= (-3.65d0)) then
tmp = b / c
else if (c <= 3.5d-95) then
tmp = t_0 / (d * d)
else if (c <= 1.9d+100) then
tmp = t_0 / (c * c)
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (d * a);
double tmp;
if (c <= -3.65) {
tmp = b / c;
} else if (c <= 3.5e-95) {
tmp = t_0 / (d * d);
} else if (c <= 1.9e+100) {
tmp = t_0 / (c * c);
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b * c) - (d * a) tmp = 0 if c <= -3.65: tmp = b / c elif c <= 3.5e-95: tmp = t_0 / (d * d) elif c <= 1.9e+100: 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 <= -3.65) tmp = Float64(b / c); elseif (c <= 3.5e-95) tmp = Float64(t_0 / Float64(d * d)); elseif (c <= 1.9e+100) tmp = Float64(t_0 / Float64(c * c)); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b * c) - (d * a); tmp = 0.0; if (c <= -3.65) tmp = b / c; elseif (c <= 3.5e-95) tmp = t_0 / (d * d); elseif (c <= 1.9e+100) tmp = t_0 / (c * c); else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.65], N[(b / c), $MachinePrecision], If[LessEqual[c, 3.5e-95], N[(t$95$0 / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.9e+100], 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 -3.65:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 3.5 \cdot 10^{-95}:\\
\;\;\;\;\frac{t\_0}{d \cdot d}\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{+100}:\\
\;\;\;\;\frac{t\_0}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -3.64999999999999991 or 1.89999999999999982e100 < c Initial program 51.0%
Taylor expanded in c around inf
lower-/.f6471.5
Applied rewrites71.5%
if -3.64999999999999991 < c < 3.4999999999999997e-95Initial program 77.6%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6467.6
Applied rewrites67.6%
if 3.4999999999999997e-95 < c < 1.89999999999999982e100Initial program 79.1%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6465.9
Applied rewrites65.9%
Final simplification69.0%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (- b (* (/ a c) d)) c))) (if (<= c -3.65) t_0 (if (<= c 2.4e+15) (/ (- (/ (* b c) d) a) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (b - ((a / c) * d)) / c;
double tmp;
if (c <= -3.65) {
tmp = t_0;
} else if (c <= 2.4e+15) {
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 / c) * d)) / c
if (c <= (-3.65d0)) then
tmp = t_0
else if (c <= 2.4d+15) 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 / c) * d)) / c;
double tmp;
if (c <= -3.65) {
tmp = t_0;
} else if (c <= 2.4e+15) {
tmp = (((b * c) / d) - a) / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b - ((a / c) * d)) / c tmp = 0 if c <= -3.65: tmp = t_0 elif c <= 2.4e+15: tmp = (((b * c) / d) - a) / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(Float64(a / c) * d)) / c) tmp = 0.0 if (c <= -3.65) tmp = t_0; elseif (c <= 2.4e+15) 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 / c) * d)) / c; tmp = 0.0; if (c <= -3.65) tmp = t_0; elseif (c <= 2.4e+15) 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[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3.65], t$95$0, If[LessEqual[c, 2.4e+15], 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 - \frac{a}{c} \cdot d}{c}\\
\mathbf{if}\;c \leq -3.65:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{+15}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.64999999999999991 or 2.4e15 < c Initial program 58.4%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6475.1
Applied rewrites75.1%
Applied rewrites82.5%
if -3.64999999999999991 < c < 2.4e15Initial program 75.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-*.f6481.8
Applied rewrites81.8%
Final simplification82.1%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (- b (* (/ a c) d)) c))) (if (<= c -3.65) t_0 (if (<= c 2.4e+15) (/ (fma (/ c d) b (- a)) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (b - ((a / c) * d)) / c;
double tmp;
if (c <= -3.65) {
tmp = t_0;
} else if (c <= 2.4e+15) {
tmp = fma((c / d), b, -a) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(Float64(a / c) * d)) / c) tmp = 0.0 if (c <= -3.65) tmp = t_0; elseif (c <= 2.4e+15) tmp = Float64(fma(Float64(c / d), b, 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[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3.65], t$95$0, If[LessEqual[c, 2.4e+15], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b - \frac{a}{c} \cdot d}{c}\\
\mathbf{if}\;c \leq -3.65:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{+15}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.64999999999999991 or 2.4e15 < c Initial program 58.4%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6475.1
Applied rewrites75.1%
Applied rewrites82.5%
if -3.64999999999999991 < c < 2.4e15Initial program 75.4%
Taylor expanded in d around inf
Applied rewrites77.7%
Taylor expanded in c around 0
Applied rewrites81.0%
Final simplification81.8%
(FPCore (a b c d)
:precision binary64
(if (<= c -2.2e+144)
(/ b c)
(if (<= c -3.3e-78)
(* (/ c (fma d d (* c c))) b)
(if (<= c 2.4e+15) (/ (- a) d) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.2e+144) {
tmp = b / c;
} else if (c <= -3.3e-78) {
tmp = (c / fma(d, d, (c * c))) * b;
} else if (c <= 2.4e+15) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -2.2e+144) tmp = Float64(b / c); elseif (c <= -3.3e-78) tmp = Float64(Float64(c / fma(d, d, Float64(c * c))) * b); elseif (c <= 2.4e+15) tmp = Float64(Float64(-a) / d); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.2e+144], N[(b / c), $MachinePrecision], If[LessEqual[c, -3.3e-78], N[(N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], If[LessEqual[c, 2.4e+15], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.2 \cdot 10^{+144}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -3.3 \cdot 10^{-78}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{+15}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.19999999999999988e144 or 2.4e15 < c Initial program 54.3%
Taylor expanded in c around inf
lower-/.f6476.2
Applied rewrites76.2%
if -2.19999999999999988e144 < c < -3.29999999999999982e-78Initial program 78.0%
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 rewrites78.4%
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-*.f6456.6
Applied rewrites56.6%
if -3.29999999999999982e-78 < c < 2.4e15Initial program 73.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.f6466.5
Applied rewrites66.5%
Final simplification68.6%
(FPCore (a b c d) :precision binary64 (if (<= c -7.8e-77) (/ b c) (if (<= c 2.4e+15) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -7.8e-77) {
tmp = b / c;
} else if (c <= 2.4e+15) {
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 <= (-7.8d-77)) then
tmp = b / c
else if (c <= 2.4d+15) 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 <= -7.8e-77) {
tmp = b / c;
} else if (c <= 2.4e+15) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -7.8e-77: tmp = b / c elif c <= 2.4e+15: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -7.8e-77) tmp = Float64(b / c); elseif (c <= 2.4e+15) 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 <= -7.8e-77) tmp = b / c; elseif (c <= 2.4e+15) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -7.8e-77], N[(b / c), $MachinePrecision], If[LessEqual[c, 2.4e+15], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.8 \cdot 10^{-77}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{+15}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -7.79999999999999958e-77 or 2.4e15 < c Initial program 61.5%
Taylor expanded in c around inf
lower-/.f6466.9
Applied rewrites66.9%
if -7.79999999999999958e-77 < c < 2.4e15Initial program 73.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.f6466.5
Applied rewrites66.5%
Final simplification66.7%
(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.7%
Taylor expanded in c around inf
lower-/.f6444.4
Applied rewrites44.4%
(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 2024296
(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))))