
(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 -4.2e+126)
t_1
(if (<= d -2.32e-73)
(/ (- (* c b) (* d a)) (fma c c (* d d)))
(if (<= d 2e-121)
(/ (fma (* d a) (/ -1.0 c) b) c)
(if (<= d 5e+146) (fma (- a) (/ d t_0) (/ (* c b) 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 <= -4.2e+126) {
tmp = t_1;
} else if (d <= -2.32e-73) {
tmp = ((c * b) - (d * a)) / fma(c, c, (d * d));
} else if (d <= 2e-121) {
tmp = fma((d * a), (-1.0 / c), b) / c;
} else if (d <= 5e+146) {
tmp = fma(-a, (d / t_0), ((c * b) / 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 <= -4.2e+126) tmp = t_1; elseif (d <= -2.32e-73) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / fma(c, c, Float64(d * d))); elseif (d <= 2e-121) tmp = Float64(fma(Float64(d * a), Float64(-1.0 / c), b) / c); elseif (d <= 5e+146) tmp = fma(Float64(-a), Float64(d / t_0), Float64(Float64(c * b) / 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, -4.2e+126], t$95$1, If[LessEqual[d, -2.32e-73], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2e-121], N[(N[(N[(d * a), $MachinePrecision] * N[(-1.0 / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5e+146], N[((-a) * N[(d / t$95$0), $MachinePrecision] + N[(N[(c * b), $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 -4.2 \cdot 10^{+126}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -2.32 \cdot 10^{-73}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;d \leq 2 \cdot 10^{-121}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d \cdot a, \frac{-1}{c}, b\right)}{c}\\
\mathbf{elif}\;d \leq 5 \cdot 10^{+146}:\\
\;\;\;\;\mathsf{fma}\left(-a, \frac{d}{t\_0}, \frac{c \cdot b}{t\_0}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -4.1999999999999998e126 or 4.9999999999999999e146 < d Initial program 32.3%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
lower-/.f64N/A
sub-negN/A
*-commutativeN/A
associate-/l*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6492.2
Applied rewrites92.2%
if -4.1999999999999998e126 < d < -2.32e-73Initial program 90.4%
lift-*.f64N/A
lower-fma.f6490.4
Applied rewrites90.4%
if -2.32e-73 < d < 2e-121Initial program 69.7%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6495.2
Applied rewrites95.2%
lift-*.f64N/A
lift-/.f64N/A
sub-negN/A
+-commutativeN/A
lift-/.f64N/A
distribute-neg-frac2N/A
div-invN/A
lower-fma.f64N/A
frac-2negN/A
metadata-evalN/A
remove-double-negN/A
lower-/.f6495.2
Applied rewrites95.2%
if 2e-121 < d < 4.9999999999999999e146Initial program 74.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
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
Applied rewrites82.3%
Final simplification91.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (fma c c (* d d))))
(t_1 (/ (fma c (/ b d) (- a)) d)))
(if (<= d -4.2e+126)
t_1
(if (<= d -2.32e-73)
t_0
(if (<= d 2e-121)
(/ (fma (* d a) (/ -1.0 c) b) c)
(if (<= d 3.8e+38) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / fma(c, c, (d * d));
double t_1 = fma(c, (b / d), -a) / d;
double tmp;
if (d <= -4.2e+126) {
tmp = t_1;
} else if (d <= -2.32e-73) {
tmp = t_0;
} else if (d <= 2e-121) {
tmp = fma((d * a), (-1.0 / c), b) / c;
} else if (d <= 3.8e+38) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - 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 <= -4.2e+126) tmp = t_1; elseif (d <= -2.32e-73) tmp = t_0; elseif (d <= 2e-121) tmp = Float64(fma(Float64(d * a), Float64(-1.0 / c), b) / c); elseif (d <= 3.8e+38) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $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, -4.2e+126], t$95$1, If[LessEqual[d, -2.32e-73], t$95$0, If[LessEqual[d, 2e-121], N[(N[(N[(d * a), $MachinePrecision] * N[(-1.0 / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.8e+38], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - 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 -4.2 \cdot 10^{+126}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -2.32 \cdot 10^{-73}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2 \cdot 10^{-121}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d \cdot a, \frac{-1}{c}, b\right)}{c}\\
\mathbf{elif}\;d \leq 3.8 \cdot 10^{+38}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -4.1999999999999998e126 or 3.7999999999999998e38 < d Initial program 41.2%
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.f6488.8
Applied rewrites88.8%
if -4.1999999999999998e126 < d < -2.32e-73 or 2e-121 < d < 3.7999999999999998e38Initial program 85.8%
lift-*.f64N/A
lower-fma.f6485.9
Applied rewrites85.9%
if -2.32e-73 < d < 2e-121Initial program 69.7%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6495.2
Applied rewrites95.2%
lift-*.f64N/A
lift-/.f64N/A
sub-negN/A
+-commutativeN/A
lift-/.f64N/A
distribute-neg-frac2N/A
div-invN/A
lower-fma.f64N/A
frac-2negN/A
metadata-evalN/A
remove-double-negN/A
lower-/.f6495.2
Applied rewrites95.2%
Final simplification90.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma c (/ b d) (- a)) d)))
(if (<= d -65000000000.0)
t_0
(if (<= d 2.1e-81) (/ (fma (* d a) (/ -1.0 c) b) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(c, (b / d), -a) / d;
double tmp;
if (d <= -65000000000.0) {
tmp = t_0;
} else if (d <= 2.1e-81) {
tmp = fma((d * a), (-1.0 / c), b) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(c, Float64(b / d), Float64(-a)) / d) tmp = 0.0 if (d <= -65000000000.0) tmp = t_0; elseif (d <= 2.1e-81) tmp = Float64(fma(Float64(d * a), Float64(-1.0 / c), b) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -65000000000.0], t$95$0, If[LessEqual[d, 2.1e-81], N[(N[(N[(d * a), $MachinePrecision] * N[(-1.0 / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -65000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{-81}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d \cdot a, \frac{-1}{c}, b\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -6.5e10 or 2.0999999999999999e-81 < d Initial program 56.3%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
lower-/.f64N/A
sub-negN/A
*-commutativeN/A
associate-/l*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6482.0
Applied rewrites82.0%
if -6.5e10 < d < 2.0999999999999999e-81Initial program 72.7%
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-*.f6488.3
Applied rewrites88.3%
lift-*.f64N/A
lift-/.f64N/A
sub-negN/A
+-commutativeN/A
lift-/.f64N/A
distribute-neg-frac2N/A
div-invN/A
lower-fma.f64N/A
frac-2negN/A
metadata-evalN/A
remove-double-negN/A
lower-/.f6488.3
Applied rewrites88.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma c (/ b d) (- a)) d)))
(if (<= d -65000000000.0)
t_0
(if (<= d 2.1e-81) (/ (- b (/ (* d a) c)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(c, (b / d), -a) / d;
double tmp;
if (d <= -65000000000.0) {
tmp = t_0;
} else if (d <= 2.1e-81) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(c, Float64(b / d), Float64(-a)) / d) tmp = 0.0 if (d <= -65000000000.0) tmp = t_0; elseif (d <= 2.1e-81) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -65000000000.0], t$95$0, If[LessEqual[d, 2.1e-81], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -65000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{-81}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -6.5e10 or 2.0999999999999999e-81 < d Initial program 56.3%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
lower-/.f64N/A
sub-negN/A
*-commutativeN/A
associate-/l*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6482.0
Applied rewrites82.0%
if -6.5e10 < d < 2.0999999999999999e-81Initial program 72.7%
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-*.f6488.3
Applied rewrites88.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (/ a d))))
(if (<= d -65000000000.0)
t_0
(if (<= d 1.9e+35) (/ (- b (/ (* d a) c)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = -(a / d);
double tmp;
if (d <= -65000000000.0) {
tmp = t_0;
} else if (d <= 1.9e+35) {
tmp = (b - ((d * a) / 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 <= (-65000000000.0d0)) then
tmp = t_0
else if (d <= 1.9d+35) then
tmp = (b - ((d * a) / 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 <= -65000000000.0) {
tmp = t_0;
} else if (d <= 1.9e+35) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = -(a / d) tmp = 0 if d <= -65000000000.0: tmp = t_0 elif d <= 1.9e+35: tmp = (b - ((d * a) / c)) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(-Float64(a / d)) tmp = 0.0 if (d <= -65000000000.0) tmp = t_0; elseif (d <= 1.9e+35) tmp = Float64(Float64(b - Float64(Float64(d * a) / 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 <= -65000000000.0) tmp = t_0; elseif (d <= 1.9e+35) tmp = (b - ((d * a) / 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, -65000000000.0], t$95$0, If[LessEqual[d, 1.9e+35], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\frac{a}{d}\\
\mathbf{if}\;d \leq -65000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.9 \cdot 10^{+35}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -6.5e10 or 1.9e35 < d Initial program 51.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.f6480.7
Applied rewrites80.7%
if -6.5e10 < d < 1.9e35Initial program 74.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-*.f6482.6
Applied rewrites82.6%
Final simplification81.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (/ a d))))
(if (<= d -65000000000.0)
t_0
(if (<= d 1.9e+35) (/ (- 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 <= -65000000000.0) {
tmp = t_0;
} else if (d <= 1.9e+35) {
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 <= (-65000000000.0d0)) then
tmp = t_0
else if (d <= 1.9d+35) 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 <= -65000000000.0) {
tmp = t_0;
} else if (d <= 1.9e+35) {
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 <= -65000000000.0: tmp = t_0 elif d <= 1.9e+35: tmp = (b - (a * (d / c))) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(-Float64(a / d)) tmp = 0.0 if (d <= -65000000000.0) tmp = t_0; elseif (d <= 1.9e+35) 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 <= -65000000000.0) tmp = t_0; elseif (d <= 1.9e+35) 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, -65000000000.0], t$95$0, If[LessEqual[d, 1.9e+35], 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 -65000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.9 \cdot 10^{+35}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -6.5e10 or 1.9e35 < d Initial program 51.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.f6480.7
Applied rewrites80.7%
if -6.5e10 < d < 1.9e35Initial program 74.0%
lift-*.f64N/A
lower-fma.f6474.0
Applied rewrites74.0%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6481.3
Applied rewrites81.3%
Final simplification81.0%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (- (/ a d)))) (if (<= d -57000000000.0) t_0 (if (<= d 2.2e-104) (/ b c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = -(a / d);
double tmp;
if (d <= -57000000000.0) {
tmp = t_0;
} else if (d <= 2.2e-104) {
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 <= (-57000000000.0d0)) then
tmp = t_0
else if (d <= 2.2d-104) 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 <= -57000000000.0) {
tmp = t_0;
} else if (d <= 2.2e-104) {
tmp = b / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = -(a / d) tmp = 0 if d <= -57000000000.0: tmp = t_0 elif d <= 2.2e-104: tmp = b / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(-Float64(a / d)) tmp = 0.0 if (d <= -57000000000.0) tmp = t_0; elseif (d <= 2.2e-104) 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 <= -57000000000.0) tmp = t_0; elseif (d <= 2.2e-104) 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, -57000000000.0], t$95$0, If[LessEqual[d, 2.2e-104], N[(b / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\frac{a}{d}\\
\mathbf{if}\;d \leq -57000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.2 \cdot 10^{-104}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -5.7e10 or 2.20000000000000012e-104 < d Initial program 56.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.f6474.6
Applied rewrites74.6%
if -5.7e10 < d < 2.20000000000000012e-104Initial program 73.0%
Taylor expanded in c around inf
lower-/.f6469.5
Applied rewrites69.5%
Final simplification72.3%
(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 64.0%
Taylor expanded in c around inf
lower-/.f6441.3
Applied rewrites41.3%
(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 2024219
(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))))