
(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 9 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))))
(t_2 (* (/ a c) d)))
(if (<= c -2.6e+153)
(/ (- b t_2) c)
(if (<= c -2.8e-21)
t_1
(if (<= c 9.6e-45)
(/ (- (/ (* b c) d) a) d)
(if (<= c 1.9e+137) t_1 (fma (/ -1.0 c) t_2 (/ b c))))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = fma((c / t_0), b, ((a / t_0) * -d));
double t_2 = (a / c) * d;
double tmp;
if (c <= -2.6e+153) {
tmp = (b - t_2) / c;
} else if (c <= -2.8e-21) {
tmp = t_1;
} else if (c <= 9.6e-45) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 1.9e+137) {
tmp = t_1;
} else {
tmp = fma((-1.0 / c), t_2, (b / c));
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = fma(Float64(c / t_0), b, Float64(Float64(a / t_0) * Float64(-d))) t_2 = Float64(Float64(a / c) * d) tmp = 0.0 if (c <= -2.6e+153) tmp = Float64(Float64(b - t_2) / c); elseif (c <= -2.8e-21) tmp = t_1; elseif (c <= 9.6e-45) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 1.9e+137) tmp = t_1; else tmp = fma(Float64(-1.0 / c), t_2, Float64(b / c)); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c / t$95$0), $MachinePrecision] * b + N[(N[(a / t$95$0), $MachinePrecision] * (-d)), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]}, If[LessEqual[c, -2.6e+153], N[(N[(b - t$95$2), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -2.8e-21], t$95$1, If[LessEqual[c, 9.6e-45], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.9e+137], t$95$1, N[(N[(-1.0 / c), $MachinePrecision] * t$95$2 + N[(b / c), $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)\\
t_2 := \frac{a}{c} \cdot d\\
\mathbf{if}\;c \leq -2.6 \cdot 10^{+153}:\\
\;\;\;\;\frac{b - t\_2}{c}\\
\mathbf{elif}\;c \leq -2.8 \cdot 10^{-21}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq 9.6 \cdot 10^{-45}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{+137}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{c}, t\_2, \frac{b}{c}\right)\\
\end{array}
\end{array}
if c < -2.5999999999999999e153Initial program 28.5%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6489.5
Applied rewrites89.5%
Applied rewrites94.7%
if -2.5999999999999999e153 < c < -2.80000000000000004e-21 or 9.5999999999999996e-45 < c < 1.89999999999999981e137Initial program 71.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 rewrites84.2%
if -2.80000000000000004e-21 < c < 9.5999999999999996e-45Initial program 62.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.5
Applied rewrites86.5%
if 1.89999999999999981e137 < c Initial program 25.0%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6485.6
Applied rewrites85.6%
Applied rewrites88.6%
Applied rewrites88.6%
Final simplification87.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* (/ a c) d)))
(if (<= c -5.6e+114)
(/ (- b t_0) c)
(if (<= c -1.15e-23)
(/ (- (* b c) (* d a)) (+ (* d d) (* c c)))
(if (<= c 14.5)
(/ (- (/ (* b c) d) a) d)
(fma (/ -1.0 c) t_0 (/ b c)))))))
double code(double a, double b, double c, double d) {
double t_0 = (a / c) * d;
double tmp;
if (c <= -5.6e+114) {
tmp = (b - t_0) / c;
} else if (c <= -1.15e-23) {
tmp = ((b * c) - (d * a)) / ((d * d) + (c * c));
} else if (c <= 14.5) {
tmp = (((b * c) / d) - a) / d;
} else {
tmp = fma((-1.0 / c), t_0, (b / c));
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(a / c) * d) tmp = 0.0 if (c <= -5.6e+114) tmp = Float64(Float64(b - t_0) / c); elseif (c <= -1.15e-23) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(Float64(d * d) + Float64(c * c))); elseif (c <= 14.5) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); else tmp = fma(Float64(-1.0 / c), t_0, Float64(b / c)); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]}, If[LessEqual[c, -5.6e+114], N[(N[(b - t$95$0), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.15e-23], 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, 14.5], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(-1.0 / c), $MachinePrecision] * t$95$0 + N[(b / c), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{c} \cdot d\\
\mathbf{if}\;c \leq -5.6 \cdot 10^{+114}:\\
\;\;\;\;\frac{b - t\_0}{c}\\
\mathbf{elif}\;c \leq -1.15 \cdot 10^{-23}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;c \leq 14.5:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{c}, t\_0, \frac{b}{c}\right)\\
\end{array}
\end{array}
if c < -5.6000000000000001e114Initial program 30.7%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6485.9
Applied rewrites85.9%
Applied rewrites92.9%
if -5.6000000000000001e114 < c < -1.15000000000000005e-23Initial program 75.3%
if -1.15000000000000005e-23 < c < 14.5Initial program 62.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.4
Applied rewrites85.4%
if 14.5 < c Initial program 50.1%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6479.2
Applied rewrites79.2%
Applied rewrites80.6%
Applied rewrites80.6%
Final simplification84.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (* (/ a c) d)) c)))
(if (<= c -5.6e+114)
t_0
(if (<= c -1.15e-23)
(/ (- (* b c) (* d a)) (+ (* d d) (* c c)))
(if (<= c 14.5) (/ (- (/ (* 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 <= -5.6e+114) {
tmp = t_0;
} else if (c <= -1.15e-23) {
tmp = ((b * c) - (d * a)) / ((d * d) + (c * c));
} else if (c <= 14.5) {
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 <= (-5.6d+114)) then
tmp = t_0
else if (c <= (-1.15d-23)) then
tmp = ((b * c) - (d * a)) / ((d * d) + (c * c))
else if (c <= 14.5d0) 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 <= -5.6e+114) {
tmp = t_0;
} else if (c <= -1.15e-23) {
tmp = ((b * c) - (d * a)) / ((d * d) + (c * c));
} else if (c <= 14.5) {
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 <= -5.6e+114: tmp = t_0 elif c <= -1.15e-23: tmp = ((b * c) - (d * a)) / ((d * d) + (c * c)) elif c <= 14.5: 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 <= -5.6e+114) tmp = t_0; elseif (c <= -1.15e-23) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(Float64(d * d) + Float64(c * c))); elseif (c <= 14.5) 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 <= -5.6e+114) tmp = t_0; elseif (c <= -1.15e-23) tmp = ((b * c) - (d * a)) / ((d * d) + (c * c)); elseif (c <= 14.5) 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, -5.6e+114], t$95$0, If[LessEqual[c, -1.15e-23], 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, 14.5], 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 -5.6 \cdot 10^{+114}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -1.15 \cdot 10^{-23}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;c \leq 14.5:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -5.6000000000000001e114 or 14.5 < c Initial program 43.1%
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 rewrites85.0%
if -5.6000000000000001e114 < c < -1.15000000000000005e-23Initial program 75.3%
if -1.15000000000000005e-23 < c < 14.5Initial program 62.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.4
Applied rewrites85.4%
Final simplification84.0%
(FPCore (a b c d)
:precision binary64
(if (<= c -3e-14)
(/ b c)
(if (<= c 1.7e-44)
(/ (- a) d)
(if (<= c 1.9e+137) (* (/ c (fma d d (* c c))) b) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3e-14) {
tmp = b / c;
} else if (c <= 1.7e-44) {
tmp = -a / d;
} else if (c <= 1.9e+137) {
tmp = (c / fma(d, d, (c * c))) * b;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -3e-14) tmp = Float64(b / c); elseif (c <= 1.7e-44) tmp = Float64(Float64(-a) / d); elseif (c <= 1.9e+137) tmp = Float64(Float64(c / fma(d, d, Float64(c * c))) * b); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -3e-14], N[(b / c), $MachinePrecision], If[LessEqual[c, 1.7e-44], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 1.9e+137], N[(N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3 \cdot 10^{-14}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 1.7 \cdot 10^{-44}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{+137}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.9999999999999998e-14 or 1.89999999999999981e137 < c Initial program 40.7%
Taylor expanded in c around inf
lower-/.f6473.0
Applied rewrites73.0%
if -2.9999999999999998e-14 < c < 1.70000000000000008e-44Initial program 63.4%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6471.2
Applied rewrites71.2%
if 1.70000000000000008e-44 < c < 1.89999999999999981e137Initial program 70.4%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
frac-subN/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites46.9%
Taylor expanded in b around inf
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6467.9
Applied rewrites67.9%
(FPCore (a b c d)
:precision binary64
(if (<= c -3e-14)
(/ b c)
(if (<= c 1.7e-44)
(/ (- a) d)
(if (<= c 5.6e+109) (* (/ b (fma d d (* c c))) c) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3e-14) {
tmp = b / c;
} else if (c <= 1.7e-44) {
tmp = -a / d;
} else if (c <= 5.6e+109) {
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 <= -3e-14) tmp = Float64(b / c); elseif (c <= 1.7e-44) tmp = Float64(Float64(-a) / d); elseif (c <= 5.6e+109) 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, -3e-14], N[(b / c), $MachinePrecision], If[LessEqual[c, 1.7e-44], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 5.6e+109], 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 -3 \cdot 10^{-14}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 1.7 \cdot 10^{-44}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 5.6 \cdot 10^{+109}:\\
\;\;\;\;\frac{b}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot c\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.9999999999999998e-14 or 5.6000000000000004e109 < c Initial program 41.8%
Taylor expanded in c around inf
lower-/.f6470.4
Applied rewrites70.4%
if -2.9999999999999998e-14 < c < 1.70000000000000008e-44Initial program 63.4%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6471.2
Applied rewrites71.2%
if 1.70000000000000008e-44 < c < 5.6000000000000004e109Initial program 72.5%
Taylor expanded in b around inf
*-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-*.f6469.7
Applied rewrites69.7%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (- b (* (/ a c) d)) c))) (if (<= c -3.1e-14) t_0 (if (<= c 14.5) (/ (- (/ (* 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.1e-14) {
tmp = t_0;
} else if (c <= 14.5) {
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.1d-14)) then
tmp = t_0
else if (c <= 14.5d0) 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.1e-14) {
tmp = t_0;
} else if (c <= 14.5) {
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.1e-14: tmp = t_0 elif c <= 14.5: 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.1e-14) tmp = t_0; elseif (c <= 14.5) 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.1e-14) tmp = t_0; elseif (c <= 14.5) 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.1e-14], t$95$0, If[LessEqual[c, 14.5], 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.1 \cdot 10^{-14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 14.5:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.10000000000000004e-14 or 14.5 < 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
lower-*.f6476.9
Applied rewrites76.9%
Applied rewrites80.3%
if -3.10000000000000004e-14 < c < 14.5Initial program 63.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.0
Applied rewrites85.0%
Final simplification82.3%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (- b (* (/ a c) d)) c))) (if (<= c -1.55e-19) t_0 (if (<= c 1.7e-44) (/ (- 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 <= -1.55e-19) {
tmp = t_0;
} else if (c <= 1.7e-44) {
tmp = -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 <= (-1.55d-19)) then
tmp = t_0
else if (c <= 1.7d-44) then
tmp = -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 <= -1.55e-19) {
tmp = t_0;
} else if (c <= 1.7e-44) {
tmp = -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 <= -1.55e-19: tmp = t_0 elif c <= 1.7e-44: tmp = -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 <= -1.55e-19) tmp = t_0; elseif (c <= 1.7e-44) tmp = Float64(Float64(-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 <= -1.55e-19) tmp = t_0; elseif (c <= 1.7e-44) tmp = -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, -1.55e-19], t$95$0, If[LessEqual[c, 1.7e-44], N[((-a) / 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 -1.55 \cdot 10^{-19}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.7 \cdot 10^{-44}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.5499999999999999e-19 or 1.70000000000000008e-44 < c Initial program 49.9%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6475.9
Applied rewrites75.9%
Applied rewrites79.1%
if -1.5499999999999999e-19 < c < 1.70000000000000008e-44Initial program 63.4%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6471.2
Applied rewrites71.2%
Final simplification75.8%
(FPCore (a b c d) :precision binary64 (if (<= c -3e-14) (/ b c) (if (<= c 1.7e-44) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3e-14) {
tmp = b / c;
} else if (c <= 1.7e-44) {
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 <= (-3d-14)) then
tmp = b / c
else if (c <= 1.7d-44) 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 <= -3e-14) {
tmp = b / c;
} else if (c <= 1.7e-44) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3e-14: tmp = b / c elif c <= 1.7e-44: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3e-14) tmp = Float64(b / c); elseif (c <= 1.7e-44) 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 <= -3e-14) tmp = b / c; elseif (c <= 1.7e-44) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3e-14], N[(b / c), $MachinePrecision], If[LessEqual[c, 1.7e-44], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3 \cdot 10^{-14}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 1.7 \cdot 10^{-44}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.9999999999999998e-14 or 1.70000000000000008e-44 < c Initial program 49.9%
Taylor expanded in c around inf
lower-/.f6466.6
Applied rewrites66.6%
if -2.9999999999999998e-14 < c < 1.70000000000000008e-44Initial program 63.4%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6471.2
Applied rewrites71.2%
(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 55.5%
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 2024276
(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))))