
(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 8 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 -1e+110)
t_1
(if (<= d -6.6e-104)
(/ (- (* b c) (* d a)) (fma c c (* d d)))
(if (<= d 6.5e-134)
(/ (- b (* a (/ d c))) c)
(if (<= d 7.5e+114) (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 <= -1e+110) {
tmp = t_1;
} else if (d <= -6.6e-104) {
tmp = ((b * c) - (d * a)) / fma(c, c, (d * d));
} else if (d <= 6.5e-134) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 7.5e+114) {
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 <= -1e+110) tmp = t_1; elseif (d <= -6.6e-104) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / fma(c, c, Float64(d * d))); elseif (d <= 6.5e-134) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 7.5e+114) 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, -1e+110], t$95$1, If[LessEqual[d, -6.6e-104], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6.5e-134], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 7.5e+114], 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 \cdot 10^{+110}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -6.6 \cdot 10^{-104}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;d \leq 6.5 \cdot 10^{-134}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 7.5 \cdot 10^{+114}:\\
\;\;\;\;\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 < -1e110 or 7.5000000000000001e114 < d Initial program 28.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.5
Applied rewrites85.5%
if -1e110 < d < -6.60000000000000004e-104Initial program 83.4%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6483.5
Applied rewrites83.5%
if -6.60000000000000004e-104 < d < 6.4999999999999998e-134Initial program 71.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-*.f6489.5
Applied rewrites89.5%
Applied rewrites90.2%
if 6.4999999999999998e-134 < d < 7.5000000000000001e114Initial program 74.2%
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.1
Applied rewrites81.1%
Final simplification86.2%
(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 -1e+110)
t_1
(if (<= d -6.6e-104)
t_0
(if (<= d 6.5e-134)
(/ (- b (* a (/ d c))) c)
(if (<= d 2.12e+105) 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 <= -1e+110) {
tmp = t_1;
} else if (d <= -6.6e-104) {
tmp = t_0;
} else if (d <= 6.5e-134) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 2.12e+105) {
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 <= -1e+110) tmp = t_1; elseif (d <= -6.6e-104) tmp = t_0; elseif (d <= 6.5e-134) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 2.12e+105) 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, -1e+110], t$95$1, If[LessEqual[d, -6.6e-104], t$95$0, If[LessEqual[d, 6.5e-134], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.12e+105], 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 \cdot 10^{+110}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -6.6 \cdot 10^{-104}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 6.5 \cdot 10^{-134}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.12 \cdot 10^{+105}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1e110 or 2.1199999999999999e105 < d Initial program 28.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.f6485.0
Applied rewrites85.0%
if -1e110 < d < -6.60000000000000004e-104 or 6.4999999999999998e-134 < d < 2.1199999999999999e105Initial program 81.3%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6481.3
Applied rewrites81.3%
if -6.60000000000000004e-104 < d < 6.4999999999999998e-134Initial program 71.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-*.f6489.5
Applied rewrites89.5%
Applied rewrites90.2%
Final simplification85.8%
(FPCore (a b c d) :precision binary64 (if (<= c -5.6e-8) (/ (fma (- d) (/ a c) b) c) (if (<= c 2.8e+16) (/ (fma c (/ b d) (- a)) d) (/ (- b (* a (/ d c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.6e-8) {
tmp = fma(-d, (a / c), b) / c;
} else if (c <= 2.8e+16) {
tmp = fma(c, (b / d), -a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -5.6e-8) tmp = Float64(fma(Float64(-d), Float64(a / c), b) / c); elseif (c <= 2.8e+16) tmp = Float64(fma(c, Float64(b / d), Float64(-a)) / d); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.6e-8], N[(N[((-d) * N[(a / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 2.8e+16], N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.6 \cdot 10^{-8}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-d, \frac{a}{c}, b\right)}{c}\\
\mathbf{elif}\;c \leq 2.8 \cdot 10^{+16}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -5.5999999999999999e-8Initial program 59.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-*.f6474.2
Applied rewrites74.2%
Applied rewrites81.0%
if -5.5999999999999999e-8 < c < 2.8e16Initial program 59.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.f6483.5
Applied rewrites83.5%
if 2.8e16 < c Initial program 51.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-*.f6474.1
Applied rewrites74.1%
Applied rewrites81.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (* a (/ d c))) c)))
(if (<= c -5.6e-8)
t_0
(if (<= c 2.8e+16) (/ (fma c (/ b 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 <= -5.6e-8) {
tmp = t_0;
} else if (c <= 2.8e+16) {
tmp = fma(c, (b / 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 <= -5.6e-8) tmp = t_0; elseif (c <= 2.8e+16) tmp = Float64(fma(c, Float64(b / d), Float64(-a)) / 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, -5.6e-8], t$95$0, If[LessEqual[c, 2.8e+16], N[(N[(c * N[(b / 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 -5.6 \cdot 10^{-8}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.8 \cdot 10^{+16}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -5.5999999999999999e-8 or 2.8e16 < c Initial program 55.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-*.f6474.2
Applied rewrites74.2%
Applied rewrites81.1%
if -5.5999999999999999e-8 < c < 2.8e16Initial program 59.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.f6483.5
Applied rewrites83.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (* a (/ d c))) c)))
(if (<= c -5.6e-8)
t_0
(if (<= c 2.8e+16) (/ (fma 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 <= -5.6e-8) {
tmp = t_0;
} else if (c <= 2.8e+16) {
tmp = fma(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 <= -5.6e-8) tmp = t_0; elseif (c <= 2.8e+16) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / 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, -5.6e-8], t$95$0, If[LessEqual[c, 2.8e+16], N[(N[(b * N[(c / 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 -5.6 \cdot 10^{-8}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.8 \cdot 10^{+16}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -5.5999999999999999e-8 or 2.8e16 < c Initial program 55.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-*.f6474.2
Applied rewrites74.2%
Applied rewrites81.1%
if -5.5999999999999999e-8 < c < 2.8e16Initial program 59.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.f6483.5
Applied rewrites83.5%
Applied rewrites82.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ a (- d))))
(if (<= d -2.15e+30)
t_0
(if (<= d 8.8e+157) (/ (- 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 <= -2.15e+30) {
tmp = t_0;
} else if (d <= 8.8e+157) {
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 <= (-2.15d+30)) then
tmp = t_0
else if (d <= 8.8d+157) 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 <= -2.15e+30) {
tmp = t_0;
} else if (d <= 8.8e+157) {
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 <= -2.15e+30: tmp = t_0 elif d <= 8.8e+157: tmp = (b - (a * (d / c))) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(a / Float64(-d)) tmp = 0.0 if (d <= -2.15e+30) tmp = t_0; elseif (d <= 8.8e+157) 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 <= -2.15e+30) tmp = t_0; elseif (d <= 8.8e+157) 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, -2.15e+30], t$95$0, If[LessEqual[d, 8.8e+157], 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 -2.15 \cdot 10^{+30}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 8.8 \cdot 10^{+157}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.15e30 or 8.8000000000000005e157 < d Initial program 34.5%
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.f6476.8
Applied rewrites76.8%
if -2.15e30 < d < 8.8000000000000005e157Initial program 71.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-*.f6472.8
Applied rewrites72.8%
Applied rewrites76.8%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ a (- d)))) (if (<= d -21000000000000.0) t_0 (if (<= d 4.8e+46) (/ b c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = a / -d;
double tmp;
if (d <= -21000000000000.0) {
tmp = t_0;
} else if (d <= 4.8e+46) {
tmp = b / 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 <= (-21000000000000.0d0)) then
tmp = t_0
else if (d <= 4.8d+46) then
tmp = b / 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 <= -21000000000000.0) {
tmp = t_0;
} else if (d <= 4.8e+46) {
tmp = b / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = a / -d tmp = 0 if d <= -21000000000000.0: tmp = t_0 elif d <= 4.8e+46: tmp = b / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(a / Float64(-d)) tmp = 0.0 if (d <= -21000000000000.0) tmp = t_0; elseif (d <= 4.8e+46) tmp = Float64(b / 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 <= -21000000000000.0) tmp = t_0; elseif (d <= 4.8e+46) tmp = b / 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, -21000000000000.0], t$95$0, If[LessEqual[d, 4.8e+46], N[(b / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{-d}\\
\mathbf{if}\;d \leq -21000000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 4.8 \cdot 10^{+46}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.1e13 or 4.80000000000000017e46 < d Initial program 39.4%
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.4
Applied rewrites71.4%
if -2.1e13 < d < 4.80000000000000017e46Initial program 73.3%
Taylor expanded in c around inf
lower-/.f6464.8
Applied rewrites64.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 57.9%
Taylor expanded in c around inf
lower-/.f6441.8
Applied rewrites41.8%
(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 2024234
(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))))