
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * 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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \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 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * 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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0
(fma
b
(/ d (pow (hypot d c) 2.0))
(* c (/ (/ a (hypot d c)) (hypot d c)))))
(t_1 (/ 1.0 (hypot d c))))
(if (<= d -6.9e+149)
(fma b (/ 1.0 d) (* c (* t_1 (* a t_1))))
(if (<= d -5.5e-82)
t_0
(if (<= d 1.2e-87)
(/ (+ a (* b (/ d c))) c)
(if (<= d 2.9e+155) t_0 (/ (+ b (* c (/ a d))) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(b, (d / pow(hypot(d, c), 2.0)), (c * ((a / hypot(d, c)) / hypot(d, c))));
double t_1 = 1.0 / hypot(d, c);
double tmp;
if (d <= -6.9e+149) {
tmp = fma(b, (1.0 / d), (c * (t_1 * (a * t_1))));
} else if (d <= -5.5e-82) {
tmp = t_0;
} else if (d <= 1.2e-87) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 2.9e+155) {
tmp = t_0;
} else {
tmp = (b + (c * (a / d))) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(b, Float64(d / (hypot(d, c) ^ 2.0)), Float64(c * Float64(Float64(a / hypot(d, c)) / hypot(d, c)))) t_1 = Float64(1.0 / hypot(d, c)) tmp = 0.0 if (d <= -6.9e+149) tmp = fma(b, Float64(1.0 / d), Float64(c * Float64(t_1 * Float64(a * t_1)))); elseif (d <= -5.5e-82) tmp = t_0; elseif (d <= 1.2e-87) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (d <= 2.9e+155) tmp = t_0; else tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(b * N[(d / N[Power[N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(c * N[(N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -6.9e+149], N[(b * N[(1.0 / d), $MachinePrecision] + N[(c * N[(t$95$1 * N[(a * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5.5e-82], t$95$0, If[LessEqual[d, 1.2e-87], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.9e+155], t$95$0, N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(b, \frac{d}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}, c \cdot \frac{\frac{a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\right)\\
t_1 := \frac{1}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{if}\;d \leq -6.9 \cdot 10^{+149}:\\
\;\;\;\;\mathsf{fma}\left(b, \frac{1}{d}, c \cdot \left(t\_1 \cdot \left(a \cdot t\_1\right)\right)\right)\\
\mathbf{elif}\;d \leq -5.5 \cdot 10^{-82}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.2 \cdot 10^{-87}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.9 \cdot 10^{+155}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\end{array}
\end{array}
if d < -6.9000000000000004e149Initial program 35.9%
Taylor expanded in a around 0 35.9%
+-commutative35.9%
associate-/l*36.7%
fma-define36.7%
Simplified37.3%
*-un-lft-identity37.3%
unpow237.3%
times-frac44.9%
Applied egg-rr44.9%
associate-*l/44.9%
*-lft-identity44.9%
Simplified44.9%
div-inv44.9%
div-inv44.9%
associate-*l*37.3%
Applied egg-rr37.3%
associate-*r*44.9%
Simplified44.9%
Taylor expanded in d around inf 96.5%
if -6.9000000000000004e149 < d < -5.4999999999999998e-82 or 1.2e-87 < d < 2.8999999999999999e155Initial program 74.7%
Taylor expanded in a around 0 74.8%
+-commutative74.8%
associate-/l*79.1%
fma-define79.1%
Simplified82.9%
*-un-lft-identity82.9%
unpow282.9%
times-frac89.6%
Applied egg-rr89.6%
associate-*l/89.7%
*-lft-identity89.7%
Simplified89.7%
if -5.4999999999999998e-82 < d < 1.2e-87Initial program 66.8%
Taylor expanded in c around inf 94.3%
associate-/l*94.6%
Simplified94.6%
if 2.8999999999999999e155 < d Initial program 22.6%
Taylor expanded in d around inf 85.4%
associate-/l*94.2%
Simplified94.2%
clear-num94.2%
un-div-inv94.2%
Applied egg-rr94.2%
associate-/r/94.2%
Simplified94.2%
Final simplification93.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma b (/ 1.0 d) (* c (/ (/ a (hypot d c)) (hypot d c)))))
(t_1 (pow (hypot d c) 2.0)))
(if (<= d -1.02e-69)
t_0
(if (<= d 5.5e-88)
(/ (+ a (* b (/ d c))) c)
(if (<= d 7e+105) (fma b (/ d t_1) (* c (/ a t_1))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(b, (1.0 / d), (c * ((a / hypot(d, c)) / hypot(d, c))));
double t_1 = pow(hypot(d, c), 2.0);
double tmp;
if (d <= -1.02e-69) {
tmp = t_0;
} else if (d <= 5.5e-88) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 7e+105) {
tmp = fma(b, (d / t_1), (c * (a / t_1)));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(b, Float64(1.0 / d), Float64(c * Float64(Float64(a / hypot(d, c)) / hypot(d, c)))) t_1 = hypot(d, c) ^ 2.0 tmp = 0.0 if (d <= -1.02e-69) tmp = t_0; elseif (d <= 5.5e-88) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (d <= 7e+105) tmp = fma(b, Float64(d / t_1), Float64(c * Float64(a / t_1))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(b * N[(1.0 / d), $MachinePrecision] + N[(c * N[(N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[d, -1.02e-69], t$95$0, If[LessEqual[d, 5.5e-88], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 7e+105], N[(b * N[(d / t$95$1), $MachinePrecision] + N[(c * N[(a / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(b, \frac{1}{d}, c \cdot \frac{\frac{a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\right)\\
t_1 := {\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}\\
\mathbf{if}\;d \leq -1.02 \cdot 10^{-69}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 5.5 \cdot 10^{-88}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 7 \cdot 10^{+105}:\\
\;\;\;\;\mathsf{fma}\left(b, \frac{d}{t\_1}, c \cdot \frac{a}{t\_1}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.02000000000000005e-69 or 6.99999999999999982e105 < d Initial program 49.5%
Taylor expanded in a around 0 49.5%
+-commutative49.5%
associate-/l*51.8%
fma-define51.8%
Simplified52.3%
*-un-lft-identity52.3%
unpow252.3%
times-frac57.1%
Applied egg-rr57.1%
associate-*l/57.1%
*-lft-identity57.1%
Simplified57.1%
Taylor expanded in d around inf 87.0%
if -1.02000000000000005e-69 < d < 5.49999999999999971e-88Initial program 66.8%
Taylor expanded in c around inf 94.3%
associate-/l*94.6%
Simplified94.6%
if 5.49999999999999971e-88 < d < 6.99999999999999982e105Initial program 71.2%
Taylor expanded in a around 0 71.3%
+-commutative71.3%
associate-/l*76.7%
fma-define76.7%
Simplified85.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.8e-82) (not (<= d 1.15e-16))) (fma b (/ 1.0 d) (* c (/ (/ a (hypot d c)) (hypot d c)))) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.8e-82) || !(d <= 1.15e-16)) {
tmp = fma(b, (1.0 / d), (c * ((a / hypot(d, c)) / hypot(d, c))));
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.8e-82) || !(d <= 1.15e-16)) tmp = fma(b, Float64(1.0 / d), Float64(c * Float64(Float64(a / hypot(d, c)) / hypot(d, c)))); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.8e-82], N[Not[LessEqual[d, 1.15e-16]], $MachinePrecision]], N[(b * N[(1.0 / d), $MachinePrecision] + N[(c * N[(N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.8 \cdot 10^{-82} \lor \neg \left(d \leq 1.15 \cdot 10^{-16}\right):\\
\;\;\;\;\mathsf{fma}\left(b, \frac{1}{d}, c \cdot \frac{\frac{a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -4.80000000000000017e-82 or 1.15e-16 < d Initial program 52.8%
Taylor expanded in a around 0 52.8%
+-commutative52.8%
associate-/l*55.9%
fma-define55.9%
Simplified58.3%
*-un-lft-identity58.3%
unpow258.3%
times-frac63.6%
Applied egg-rr63.6%
associate-*l/63.6%
*-lft-identity63.6%
Simplified63.6%
Taylor expanded in d around inf 84.0%
if -4.80000000000000017e-82 < d < 1.15e-16Initial program 67.7%
Taylor expanded in c around inf 92.1%
associate-/l*92.4%
Simplified92.4%
Final simplification87.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* c a) (* d b)) (+ (* c c) (* d d)))))
(if (<= d -8.8e+67)
(/ (+ b (* c (/ a d))) d)
(if (<= d -2.4e-79)
t_0
(if (<= d 7.5e-88)
(/ (+ a (* b (/ d c))) c)
(if (<= d 3.5e+102) t_0 (/ (+ b (* a (/ c d))) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d));
double tmp;
if (d <= -8.8e+67) {
tmp = (b + (c * (a / d))) / d;
} else if (d <= -2.4e-79) {
tmp = t_0;
} else if (d <= 7.5e-88) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 3.5e+102) {
tmp = t_0;
} else {
tmp = (b + (a * (c / d))) / 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) :: t_0
real(8) :: tmp
t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d))
if (d <= (-8.8d+67)) then
tmp = (b + (c * (a / d))) / d
else if (d <= (-2.4d-79)) then
tmp = t_0
else if (d <= 7.5d-88) then
tmp = (a + (b * (d / c))) / c
else if (d <= 3.5d+102) then
tmp = t_0
else
tmp = (b + (a * (c / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d));
double tmp;
if (d <= -8.8e+67) {
tmp = (b + (c * (a / d))) / d;
} else if (d <= -2.4e-79) {
tmp = t_0;
} else if (d <= 7.5e-88) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 3.5e+102) {
tmp = t_0;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d)) tmp = 0 if d <= -8.8e+67: tmp = (b + (c * (a / d))) / d elif d <= -2.4e-79: tmp = t_0 elif d <= 7.5e-88: tmp = (a + (b * (d / c))) / c elif d <= 3.5e+102: tmp = t_0 else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * a) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (d <= -8.8e+67) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); elseif (d <= -2.4e-79) tmp = t_0; elseif (d <= 7.5e-88) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (d <= 3.5e+102) tmp = t_0; else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -8.8e+67) tmp = (b + (c * (a / d))) / d; elseif (d <= -2.4e-79) tmp = t_0; elseif (d <= 7.5e-88) tmp = (a + (b * (d / c))) / c; elseif (d <= 3.5e+102) tmp = t_0; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -8.8e+67], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -2.4e-79], t$95$0, If[LessEqual[d, 7.5e-88], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.5e+102], t$95$0, N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -8.8 \cdot 10^{+67}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{elif}\;d \leq -2.4 \cdot 10^{-79}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 7.5 \cdot 10^{-88}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 3.5 \cdot 10^{+102}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if d < -8.8e67Initial program 49.5%
Taylor expanded in d around inf 82.5%
associate-/l*89.8%
Simplified89.8%
clear-num89.7%
un-div-inv89.8%
Applied egg-rr89.8%
associate-/r/91.7%
Simplified91.7%
if -8.8e67 < d < -2.40000000000000006e-79 or 7.50000000000000041e-88 < d < 3.50000000000000011e102Initial program 76.5%
if -2.40000000000000006e-79 < d < 7.50000000000000041e-88Initial program 66.8%
Taylor expanded in c around inf 94.3%
associate-/l*94.6%
Simplified94.6%
if 3.50000000000000011e102 < d Initial program 29.9%
Taylor expanded in d around inf 77.2%
associate-/l*86.4%
Simplified86.4%
Final simplification88.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2200000.0) (not (<= d 1.8e-15))) (/ (+ b (* c (/ a d))) d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2200000.0) || !(d <= 1.8e-15)) {
tmp = (b + (c * (a / d))) / d;
} else {
tmp = (a + (b * (d / c))) / 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 <= (-2200000.0d0)) .or. (.not. (d <= 1.8d-15))) then
tmp = (b + (c * (a / d))) / d
else
tmp = (a + (b * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2200000.0) || !(d <= 1.8e-15)) {
tmp = (b + (c * (a / d))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2200000.0) or not (d <= 1.8e-15): tmp = (b + (c * (a / d))) / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2200000.0) || !(d <= 1.8e-15)) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2200000.0) || ~((d <= 1.8e-15))) tmp = (b + (c * (a / d))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2200000.0], N[Not[LessEqual[d, 1.8e-15]], $MachinePrecision]], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2200000 \lor \neg \left(d \leq 1.8 \cdot 10^{-15}\right):\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -2.2e6 or 1.8000000000000001e-15 < d Initial program 49.3%
Taylor expanded in d around inf 73.9%
associate-/l*80.6%
Simplified80.6%
clear-num80.6%
un-div-inv80.6%
Applied egg-rr80.6%
associate-/r/81.4%
Simplified81.4%
if -2.2e6 < d < 1.8000000000000001e-15Initial program 69.8%
Taylor expanded in c around inf 88.4%
associate-/l*88.7%
Simplified88.7%
Final simplification84.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -490000.0) (not (<= d 1.76e-15))) (/ (+ b (* a (/ c d))) d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -490000.0) || !(d <= 1.76e-15)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b * (d / c))) / 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 <= (-490000.0d0)) .or. (.not. (d <= 1.76d-15))) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a + (b * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -490000.0) || !(d <= 1.76e-15)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -490000.0) or not (d <= 1.76e-15): tmp = (b + (a * (c / d))) / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -490000.0) || !(d <= 1.76e-15)) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -490000.0) || ~((d <= 1.76e-15))) tmp = (b + (a * (c / d))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -490000.0], N[Not[LessEqual[d, 1.76e-15]], $MachinePrecision]], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -490000 \lor \neg \left(d \leq 1.76 \cdot 10^{-15}\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -4.9e5 or 1.76e-15 < d Initial program 49.3%
Taylor expanded in d around inf 73.9%
associate-/l*80.6%
Simplified80.6%
if -4.9e5 < d < 1.76e-15Initial program 69.8%
Taylor expanded in c around inf 88.4%
associate-/l*88.7%
Simplified88.7%
Final simplification84.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.05e+48) (not (<= d 3.1e+125))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.05e+48) || !(d <= 3.1e+125)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / 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.05d+48)) .or. (.not. (d <= 3.1d+125))) then
tmp = b / d
else
tmp = (a + (b * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.05e+48) || !(d <= 3.1e+125)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.05e+48) or not (d <= 3.1e+125): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.05e+48) || !(d <= 3.1e+125)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.05e+48) || ~((d <= 3.1e+125))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.05e+48], N[Not[LessEqual[d, 3.1e+125]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.05 \cdot 10^{+48} \lor \neg \left(d \leq 3.1 \cdot 10^{+125}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.0499999999999999e48 or 3.1e125 < d Initial program 42.1%
Taylor expanded in c around 0 82.2%
if -1.0499999999999999e48 < d < 3.1e125Initial program 69.7%
Taylor expanded in c around inf 78.2%
associate-/l*79.6%
Simplified79.6%
Final simplification80.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -8000.0) (not (<= d 5e+127))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -8000.0) || !(d <= 5e+127)) {
tmp = b / d;
} else {
tmp = a / 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 <= (-8000.0d0)) .or. (.not. (d <= 5d+127))) then
tmp = b / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -8000.0) || !(d <= 5e+127)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -8000.0) or not (d <= 5e+127): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -8000.0) || !(d <= 5e+127)) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -8000.0) || ~((d <= 5e+127))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -8000.0], N[Not[LessEqual[d, 5e+127]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -8000 \lor \neg \left(d \leq 5 \cdot 10^{+127}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -8e3 or 5.0000000000000004e127 < d Initial program 45.0%
Taylor expanded in c around 0 78.8%
if -8e3 < d < 5.0000000000000004e127Initial program 69.0%
Taylor expanded in c around inf 64.1%
Final simplification70.1%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / 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 = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 59.2%
Taylor expanded in c around inf 43.6%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (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(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * 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 = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (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[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * 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{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024131
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))