
(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
(if (<= d -9.2e+198)
(/ (- (* (/ c d) b) a) d)
(if (<= d 3.2e+146)
(fma
(/ c (hypot c d))
(/ b (hypot c d))
(/ (- a) (/ (pow (hypot c d) 2.0) d)))
(/ (- (* c (/ b d)) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -9.2e+198) {
tmp = (((c / d) * b) - a) / d;
} else if (d <= 3.2e+146) {
tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (-a / (pow(hypot(c, d), 2.0) / d)));
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -9.2e+198) tmp = Float64(Float64(Float64(Float64(c / d) * b) - a) / d); elseif (d <= 3.2e+146) tmp = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(Float64(-a) / Float64((hypot(c, d) ^ 2.0) / d))); else tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -9.2e+198], N[(N[(N[(N[(c / d), $MachinePrecision] * b), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 3.2e+146], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[((-a) / N[(N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.2 \cdot 10^{+198}:\\
\;\;\;\;\frac{\frac{c}{d} \cdot b - a}{d}\\
\mathbf{elif}\;d \leq 3.2 \cdot 10^{+146}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if d < -9.2000000000000002e198Initial program 32.5%
div-sub32.5%
*-commutative32.5%
add-sqr-sqrt32.5%
times-frac32.7%
fma-neg32.7%
hypot-def32.7%
hypot-def42.8%
associate-/l*44.6%
add-sqr-sqrt44.6%
pow244.6%
hypot-def44.6%
Applied egg-rr44.6%
Taylor expanded in c around 0 84.5%
+-commutative84.5%
mul-1-neg84.5%
unsub-neg84.5%
unpow284.5%
times-frac95.1%
Simplified95.1%
associate-*r/95.1%
sub-div95.1%
Applied egg-rr95.1%
if -9.2000000000000002e198 < d < 3.2e146Initial program 70.7%
div-sub69.0%
*-commutative69.0%
add-sqr-sqrt69.0%
times-frac72.0%
fma-neg72.0%
hypot-def72.0%
hypot-def88.6%
associate-/l*91.6%
add-sqr-sqrt91.6%
pow291.6%
hypot-def91.6%
Applied egg-rr91.6%
if 3.2e146 < d Initial program 19.3%
div-sub19.3%
*-commutative19.3%
add-sqr-sqrt19.3%
times-frac20.0%
fma-neg20.0%
hypot-def20.0%
hypot-def38.8%
associate-/l*49.8%
add-sqr-sqrt49.8%
pow249.8%
hypot-def49.8%
Applied egg-rr49.8%
Taylor expanded in c around 0 70.6%
+-commutative70.6%
mul-1-neg70.6%
unsub-neg70.6%
unpow270.6%
times-frac88.3%
Simplified88.3%
associate-*l/88.3%
sub-div88.3%
Applied egg-rr88.3%
Final simplification91.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0
(-
(* (/ 1.0 (hypot c d)) (/ c (/ (hypot c d) b)))
(* d (/ a (fma c c (* d d)))))))
(if (<= d -7.4e+140)
(- (/ c (* d (/ d b))) (/ a d))
(if (<= d -2.9e-135)
t_0
(if (<= d 1.7e-169)
(- (/ b c) (* (/ a c) (/ d c)))
(if (<= d 2.95e+146) t_0 (/ (- (* c (/ b d)) a) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((1.0 / hypot(c, d)) * (c / (hypot(c, d) / b))) - (d * (a / fma(c, c, (d * d))));
double tmp;
if (d <= -7.4e+140) {
tmp = (c / (d * (d / b))) - (a / d);
} else if (d <= -2.9e-135) {
tmp = t_0;
} else if (d <= 1.7e-169) {
tmp = (b / c) - ((a / c) * (d / c));
} else if (d <= 2.95e+146) {
tmp = t_0;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(1.0 / hypot(c, d)) * Float64(c / Float64(hypot(c, d) / b))) - Float64(d * Float64(a / fma(c, c, Float64(d * d))))) tmp = 0.0 if (d <= -7.4e+140) tmp = Float64(Float64(c / Float64(d * Float64(d / b))) - Float64(a / d)); elseif (d <= -2.9e-135) tmp = t_0; elseif (d <= 1.7e-169) tmp = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))); elseif (d <= 2.95e+146) tmp = t_0; else tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(c / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(d * N[(a / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -7.4e+140], N[(N[(c / N[(d * N[(d / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.9e-135], t$95$0, If[LessEqual[d, 1.7e-169], N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.95e+146], t$95$0, N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c}{\frac{\mathsf{hypot}\left(c, d\right)}{b}} - d \cdot \frac{a}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{if}\;d \leq -7.4 \cdot 10^{+140}:\\
\;\;\;\;\frac{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\
\mathbf{elif}\;d \leq -2.9 \cdot 10^{-135}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 1.7 \cdot 10^{-169}:\\
\;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{elif}\;d \leq 2.95 \cdot 10^{+146}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if d < -7.40000000000000006e140Initial program 34.8%
div-sub34.8%
*-commutative34.8%
add-sqr-sqrt34.8%
times-frac35.0%
fma-neg35.0%
hypot-def35.0%
hypot-def52.5%
associate-/l*53.9%
add-sqr-sqrt53.9%
pow253.9%
hypot-def53.9%
Applied egg-rr53.9%
Taylor expanded in c around 0 71.6%
+-commutative71.6%
mul-1-neg71.6%
unsub-neg71.6%
unpow271.6%
times-frac86.1%
Simplified86.1%
*-commutative86.1%
clear-num86.1%
frac-times86.2%
*-un-lft-identity86.2%
Applied egg-rr86.2%
if -7.40000000000000006e140 < d < -2.9000000000000002e-135 or 1.7e-169 < d < 2.95000000000000015e146Initial program 74.1%
Taylor expanded in b around 0 74.1%
mul-1-neg74.1%
unsub-neg74.1%
unpow274.1%
unpow274.1%
+-commutative74.1%
fma-udef74.1%
associate-/l*78.2%
associate-/r/76.7%
unpow276.7%
unpow276.7%
+-commutative76.7%
fma-udef76.7%
Simplified76.7%
*-commutative76.7%
*-un-lft-identity76.7%
add-sqr-sqrt76.7%
fma-udef76.7%
hypot-udef76.7%
fma-udef76.7%
hypot-udef76.7%
times-frac81.4%
*-commutative81.4%
Applied egg-rr81.4%
associate-/l*91.8%
Simplified91.8%
if -2.9000000000000002e-135 < d < 1.7e-169Initial program 68.2%
Taylor expanded in c around inf 90.1%
+-commutative90.1%
mul-1-neg90.1%
unsub-neg90.1%
unpow290.1%
times-frac92.9%
Simplified92.9%
if 2.95000000000000015e146 < d Initial program 19.3%
div-sub19.3%
*-commutative19.3%
add-sqr-sqrt19.3%
times-frac20.0%
fma-neg20.0%
hypot-def20.0%
hypot-def38.8%
associate-/l*49.8%
add-sqr-sqrt49.8%
pow249.8%
hypot-def49.8%
Applied egg-rr49.8%
Taylor expanded in c around 0 70.6%
+-commutative70.6%
mul-1-neg70.6%
unsub-neg70.6%
unpow270.6%
times-frac88.3%
Simplified88.3%
associate-*l/88.3%
sub-div88.3%
Applied egg-rr88.3%
Final simplification91.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* c b) (* d a))))
(if (<= (/ t_0 (+ (* d d) (* c c))) 5e+302)
(* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
(/ (- (/ c (/ d b)) a) d))))
double code(double a, double b, double c, double d) {
double t_0 = (c * b) - (d * a);
double tmp;
if ((t_0 / ((d * d) + (c * c))) <= 5e+302) {
tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
} else {
tmp = ((c / (d / b)) - a) / d;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = (c * b) - (d * a);
double tmp;
if ((t_0 / ((d * d) + (c * c))) <= 5e+302) {
tmp = (1.0 / Math.hypot(c, d)) * (t_0 / Math.hypot(c, d));
} else {
tmp = ((c / (d / b)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = (c * b) - (d * a) tmp = 0 if (t_0 / ((d * d) + (c * c))) <= 5e+302: tmp = (1.0 / math.hypot(c, d)) * (t_0 / math.hypot(c, d)) else: tmp = ((c / (d / b)) - a) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(c * b) - Float64(d * a)) tmp = 0.0 if (Float64(t_0 / Float64(Float64(d * d) + Float64(c * c))) <= 5e+302) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d))); else tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (c * b) - (d * a); tmp = 0.0; if ((t_0 / ((d * d) + (c * c))) <= 5e+302) tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d)); else tmp = ((c / (d / b)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+302], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot b - d \cdot a\\
\mathbf{if}\;\frac{t_0}{d \cdot d + c \cdot c} \leq 5 \cdot 10^{+302}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 5e302Initial program 78.8%
*-un-lft-identity78.8%
add-sqr-sqrt78.7%
times-frac78.7%
hypot-def78.7%
hypot-def95.9%
Applied egg-rr95.9%
if 5e302 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 10.4%
div-sub9.0%
*-commutative9.0%
add-sqr-sqrt9.0%
times-frac13.3%
fma-neg13.3%
hypot-def13.3%
hypot-def48.2%
associate-/l*59.2%
add-sqr-sqrt59.2%
pow259.2%
hypot-def59.2%
Applied egg-rr59.2%
Taylor expanded in c around 0 46.3%
+-commutative46.3%
mul-1-neg46.3%
unsub-neg46.3%
unpow246.3%
times-frac58.1%
Simplified58.1%
*-commutative58.1%
clear-num58.0%
frac-times52.7%
*-un-lft-identity52.7%
Applied egg-rr52.7%
*-un-lft-identity52.7%
associate-/r*58.1%
sub-div58.1%
Applied egg-rr58.1%
*-lft-identity58.1%
Simplified58.1%
Final simplification85.4%
(FPCore (a b c d)
:precision binary64
(if (<= d -5e+18)
(/ (- (/ c (/ d b)) a) d)
(if (<= d 8.5e+26)
(- (/ b c) (* (/ a c) (/ d c)))
(/ (- (* (/ c d) b) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -5e+18) {
tmp = ((c / (d / b)) - a) / d;
} else if (d <= 8.5e+26) {
tmp = (b / c) - ((a / c) * (d / c));
} else {
tmp = (((c / d) * b) - a) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-5d+18)) then
tmp = ((c / (d / b)) - a) / d
else if (d <= 8.5d+26) then
tmp = (b / c) - ((a / c) * (d / c))
else
tmp = (((c / d) * b) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -5e+18) {
tmp = ((c / (d / b)) - a) / d;
} else if (d <= 8.5e+26) {
tmp = (b / c) - ((a / c) * (d / c));
} else {
tmp = (((c / d) * b) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -5e+18: tmp = ((c / (d / b)) - a) / d elif d <= 8.5e+26: tmp = (b / c) - ((a / c) * (d / c)) else: tmp = (((c / d) * b) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -5e+18) tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / d); elseif (d <= 8.5e+26) tmp = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))); else tmp = Float64(Float64(Float64(Float64(c / d) * b) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -5e+18) tmp = ((c / (d / b)) - a) / d; elseif (d <= 8.5e+26) tmp = (b / c) - ((a / c) * (d / c)); else tmp = (((c / d) * b) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -5e+18], N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 8.5e+26], N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(c / d), $MachinePrecision] * b), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5 \cdot 10^{+18}:\\
\;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\
\mathbf{elif}\;d \leq 8.5 \cdot 10^{+26}:\\
\;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{d} \cdot b - a}{d}\\
\end{array}
\end{array}
if d < -5e18Initial program 55.9%
div-sub55.9%
*-commutative55.9%
add-sqr-sqrt55.9%
times-frac56.1%
fma-neg56.1%
hypot-def56.1%
hypot-def67.7%
associate-/l*72.5%
add-sqr-sqrt72.5%
pow272.5%
hypot-def72.5%
Applied egg-rr72.5%
Taylor expanded in c around 0 78.3%
+-commutative78.3%
mul-1-neg78.3%
unsub-neg78.3%
unpow278.3%
times-frac86.4%
Simplified86.4%
*-commutative86.4%
clear-num86.3%
frac-times86.5%
*-un-lft-identity86.5%
Applied egg-rr86.5%
*-un-lft-identity86.5%
associate-/r*86.4%
sub-div86.4%
Applied egg-rr86.4%
*-lft-identity86.4%
Simplified86.4%
if -5e18 < d < 8.5e26Initial program 70.3%
Taylor expanded in c around inf 82.9%
+-commutative82.9%
mul-1-neg82.9%
unsub-neg82.9%
unpow282.9%
times-frac87.2%
Simplified87.2%
if 8.5e26 < d Initial program 42.8%
div-sub42.8%
*-commutative42.8%
add-sqr-sqrt42.8%
times-frac44.7%
fma-neg44.7%
hypot-def44.7%
hypot-def57.8%
associate-/l*69.3%
add-sqr-sqrt69.3%
pow269.3%
hypot-def69.3%
Applied egg-rr69.3%
Taylor expanded in c around 0 67.4%
+-commutative67.4%
mul-1-neg67.4%
unsub-neg67.4%
unpow267.4%
times-frac77.2%
Simplified77.2%
associate-*r/77.3%
sub-div77.3%
Applied egg-rr77.3%
Final simplification84.3%
(FPCore (a b c d)
:precision binary64
(if (<= d -3.3e+18)
(- (/ c (* d (/ d b))) (/ a d))
(if (<= d 8.5e+26)
(- (/ b c) (* (/ a c) (/ d c)))
(/ (- (* (/ c d) b) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3.3e+18) {
tmp = (c / (d * (d / b))) - (a / d);
} else if (d <= 8.5e+26) {
tmp = (b / c) - ((a / c) * (d / c));
} else {
tmp = (((c / d) * b) - a) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-3.3d+18)) then
tmp = (c / (d * (d / b))) - (a / d)
else if (d <= 8.5d+26) then
tmp = (b / c) - ((a / c) * (d / c))
else
tmp = (((c / d) * b) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3.3e+18) {
tmp = (c / (d * (d / b))) - (a / d);
} else if (d <= 8.5e+26) {
tmp = (b / c) - ((a / c) * (d / c));
} else {
tmp = (((c / d) * b) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -3.3e+18: tmp = (c / (d * (d / b))) - (a / d) elif d <= 8.5e+26: tmp = (b / c) - ((a / c) * (d / c)) else: tmp = (((c / d) * b) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -3.3e+18) tmp = Float64(Float64(c / Float64(d * Float64(d / b))) - Float64(a / d)); elseif (d <= 8.5e+26) tmp = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))); else tmp = Float64(Float64(Float64(Float64(c / d) * b) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -3.3e+18) tmp = (c / (d * (d / b))) - (a / d); elseif (d <= 8.5e+26) tmp = (b / c) - ((a / c) * (d / c)); else tmp = (((c / d) * b) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -3.3e+18], N[(N[(c / N[(d * N[(d / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 8.5e+26], N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(c / d), $MachinePrecision] * b), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.3 \cdot 10^{+18}:\\
\;\;\;\;\frac{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\
\mathbf{elif}\;d \leq 8.5 \cdot 10^{+26}:\\
\;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{d} \cdot b - a}{d}\\
\end{array}
\end{array}
if d < -3.3e18Initial program 55.9%
div-sub55.9%
*-commutative55.9%
add-sqr-sqrt55.9%
times-frac56.1%
fma-neg56.1%
hypot-def56.1%
hypot-def67.7%
associate-/l*72.5%
add-sqr-sqrt72.5%
pow272.5%
hypot-def72.5%
Applied egg-rr72.5%
Taylor expanded in c around 0 78.3%
+-commutative78.3%
mul-1-neg78.3%
unsub-neg78.3%
unpow278.3%
times-frac86.4%
Simplified86.4%
*-commutative86.4%
clear-num86.3%
frac-times86.5%
*-un-lft-identity86.5%
Applied egg-rr86.5%
if -3.3e18 < d < 8.5e26Initial program 70.3%
Taylor expanded in c around inf 82.9%
+-commutative82.9%
mul-1-neg82.9%
unsub-neg82.9%
unpow282.9%
times-frac87.2%
Simplified87.2%
if 8.5e26 < d Initial program 42.8%
div-sub42.8%
*-commutative42.8%
add-sqr-sqrt42.8%
times-frac44.7%
fma-neg44.7%
hypot-def44.7%
hypot-def57.8%
associate-/l*69.3%
add-sqr-sqrt69.3%
pow269.3%
hypot-def69.3%
Applied egg-rr69.3%
Taylor expanded in c around 0 67.4%
+-commutative67.4%
mul-1-neg67.4%
unsub-neg67.4%
unpow267.4%
times-frac77.2%
Simplified77.2%
associate-*r/77.3%
sub-div77.3%
Applied egg-rr77.3%
Final simplification84.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.1e+18) (not (<= d 2.3e+15))) (/ (- (* c (/ b d)) a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.1e+18) || !(d <= 2.3e+15)) {
tmp = ((c * (b / d)) - 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 ((d <= (-3.1d+18)) .or. (.not. (d <= 2.3d+15))) then
tmp = ((c * (b / d)) - 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 ((d <= -3.1e+18) || !(d <= 2.3e+15)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.1e+18) or not (d <= 2.3e+15): tmp = ((c * (b / d)) - a) / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.1e+18) || !(d <= 2.3e+15)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -3.1e+18) || ~((d <= 2.3e+15))) tmp = ((c * (b / d)) - a) / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.1e+18], N[Not[LessEqual[d, 2.3e+15]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.1 \cdot 10^{+18} \lor \neg \left(d \leq 2.3 \cdot 10^{+15}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -3.1e18 or 2.3e15 < d Initial program 48.6%
div-sub48.6%
*-commutative48.6%
add-sqr-sqrt48.6%
times-frac49.7%
fma-neg49.7%
hypot-def49.7%
hypot-def62.1%
associate-/l*70.8%
add-sqr-sqrt70.8%
pow270.8%
hypot-def70.8%
Applied egg-rr70.8%
Taylor expanded in c around 0 71.3%
+-commutative71.3%
mul-1-neg71.3%
unsub-neg71.3%
unpow271.3%
times-frac80.3%
Simplified80.3%
associate-*l/80.3%
sub-div80.3%
Applied egg-rr80.3%
if -3.1e18 < d < 2.3e15Initial program 70.1%
Taylor expanded in c around inf 72.0%
Final simplification76.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.7e+18) (not (<= d 1.4e+21))) (/ (- (* (/ c d) b) a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.7e+18) || !(d <= 1.4e+21)) {
tmp = (((c / d) * b) - 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 ((d <= (-1.7d+18)) .or. (.not. (d <= 1.4d+21))) then
tmp = (((c / d) * b) - 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 ((d <= -1.7e+18) || !(d <= 1.4e+21)) {
tmp = (((c / d) * b) - a) / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.7e+18) or not (d <= 1.4e+21): tmp = (((c / d) * b) - a) / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.7e+18) || !(d <= 1.4e+21)) tmp = Float64(Float64(Float64(Float64(c / d) * b) - a) / d); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.7e+18) || ~((d <= 1.4e+21))) tmp = (((c / d) * b) - a) / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.7e+18], N[Not[LessEqual[d, 1.4e+21]], $MachinePrecision]], N[(N[(N[(N[(c / d), $MachinePrecision] * b), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.7 \cdot 10^{+18} \lor \neg \left(d \leq 1.4 \cdot 10^{+21}\right):\\
\;\;\;\;\frac{\frac{c}{d} \cdot b - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -1.7e18 or 1.4e21 < d Initial program 48.6%
div-sub48.6%
*-commutative48.6%
add-sqr-sqrt48.6%
times-frac49.7%
fma-neg49.7%
hypot-def49.7%
hypot-def62.1%
associate-/l*70.8%
add-sqr-sqrt70.8%
pow270.8%
hypot-def70.8%
Applied egg-rr70.8%
Taylor expanded in c around 0 71.3%
+-commutative71.3%
mul-1-neg71.3%
unsub-neg71.3%
unpow271.3%
times-frac80.3%
Simplified80.3%
associate-*r/80.3%
sub-div80.3%
Applied egg-rr80.3%
if -1.7e18 < d < 1.4e21Initial program 70.1%
Taylor expanded in c around inf 72.0%
Final simplification76.0%
(FPCore (a b c d) :precision binary64 (if (<= d -4e+18) (/ (- (/ c (/ d b)) a) d) (if (<= d 5.3e+15) (/ b c) (/ (- (* (/ c d) b) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4e+18) {
tmp = ((c / (d / b)) - a) / d;
} else if (d <= 5.3e+15) {
tmp = b / c;
} else {
tmp = (((c / d) * b) - a) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-4d+18)) then
tmp = ((c / (d / b)) - a) / d
else if (d <= 5.3d+15) then
tmp = b / c
else
tmp = (((c / d) * b) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4e+18) {
tmp = ((c / (d / b)) - a) / d;
} else if (d <= 5.3e+15) {
tmp = b / c;
} else {
tmp = (((c / d) * b) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -4e+18: tmp = ((c / (d / b)) - a) / d elif d <= 5.3e+15: tmp = b / c else: tmp = (((c / d) * b) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -4e+18) tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / d); elseif (d <= 5.3e+15) tmp = Float64(b / c); else tmp = Float64(Float64(Float64(Float64(c / d) * b) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -4e+18) tmp = ((c / (d / b)) - a) / d; elseif (d <= 5.3e+15) tmp = b / c; else tmp = (((c / d) * b) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -4e+18], N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 5.3e+15], N[(b / c), $MachinePrecision], N[(N[(N[(N[(c / d), $MachinePrecision] * b), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4 \cdot 10^{+18}:\\
\;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\
\mathbf{elif}\;d \leq 5.3 \cdot 10^{+15}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{d} \cdot b - a}{d}\\
\end{array}
\end{array}
if d < -4e18Initial program 55.9%
div-sub55.9%
*-commutative55.9%
add-sqr-sqrt55.9%
times-frac56.1%
fma-neg56.1%
hypot-def56.1%
hypot-def67.7%
associate-/l*72.5%
add-sqr-sqrt72.5%
pow272.5%
hypot-def72.5%
Applied egg-rr72.5%
Taylor expanded in c around 0 78.3%
+-commutative78.3%
mul-1-neg78.3%
unsub-neg78.3%
unpow278.3%
times-frac86.4%
Simplified86.4%
*-commutative86.4%
clear-num86.3%
frac-times86.5%
*-un-lft-identity86.5%
Applied egg-rr86.5%
*-un-lft-identity86.5%
associate-/r*86.4%
sub-div86.4%
Applied egg-rr86.4%
*-lft-identity86.4%
Simplified86.4%
if -4e18 < d < 5.3e15Initial program 70.1%
Taylor expanded in c around inf 72.0%
if 5.3e15 < d Initial program 43.6%
div-sub43.6%
*-commutative43.6%
add-sqr-sqrt43.6%
times-frac45.4%
fma-neg45.4%
hypot-def45.4%
hypot-def58.4%
associate-/l*69.7%
add-sqr-sqrt69.7%
pow269.7%
hypot-def69.7%
Applied egg-rr69.7%
Taylor expanded in c around 0 66.5%
+-commutative66.5%
mul-1-neg66.5%
unsub-neg66.5%
unpow266.5%
times-frac76.3%
Simplified76.3%
associate-*r/76.3%
sub-div76.3%
Applied egg-rr76.3%
Final simplification76.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.65e+24) (not (<= d 1.4e+17))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.65e+24) || !(d <= 1.4e+17)) {
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 ((d <= (-1.65d+24)) .or. (.not. (d <= 1.4d+17))) 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 ((d <= -1.65e+24) || !(d <= 1.4e+17)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.65e+24) or not (d <= 1.4e+17): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.65e+24) || !(d <= 1.4e+17)) 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 ((d <= -1.65e+24) || ~((d <= 1.4e+17))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.65e+24], N[Not[LessEqual[d, 1.4e+17]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.65 \cdot 10^{+24} \lor \neg \left(d \leq 1.4 \cdot 10^{+17}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -1.6499999999999999e24 or 1.4e17 < d Initial program 48.1%
Taylor expanded in c around 0 62.8%
associate-*r/62.8%
neg-mul-162.8%
Simplified62.8%
if -1.6499999999999999e24 < d < 1.4e17Initial program 70.3%
Taylor expanded in c around inf 71.5%
Final simplification67.4%
(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 59.8%
Taylor expanded in c around inf 44.6%
Final simplification44.6%
(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 2023230
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:herbie-target
(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))))