
(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 7 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 (* (/ 1.0 (hypot c d)) (/ (fma a c (* d b)) (hypot c d)))))
(if (<= c -1.35e+68)
(/ (+ a (* d (/ b c))) (- (hypot c d)))
(if (<= c -3e-118)
t_0
(if (<= c 3.1e-32)
(/ (+ b (* a (/ c d))) d)
(if (<= c 4.3e+107) t_0 (/ (+ a (* b (/ d c))) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = (1.0 / hypot(c, d)) * (fma(a, c, (d * b)) / hypot(c, d));
double tmp;
if (c <= -1.35e+68) {
tmp = (a + (d * (b / c))) / -hypot(c, d);
} else if (c <= -3e-118) {
tmp = t_0;
} else if (c <= 3.1e-32) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 4.3e+107) {
tmp = t_0;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(d * b)) / hypot(c, d))) tmp = 0.0 if (c <= -1.35e+68) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / Float64(-hypot(c, d))); elseif (c <= -3e-118) tmp = t_0; elseif (c <= 3.1e-32) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 4.3e+107) tmp = t_0; else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.35e+68], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision])), $MachinePrecision], If[LessEqual[c, -3e-118], t$95$0, If[LessEqual[c, 3.1e-32], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.3e+107], t$95$0, N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;c \leq -1.35 \cdot 10^{+68}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{-\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -3 \cdot 10^{-118}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 3.1 \cdot 10^{-32}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 4.3 \cdot 10^{+107}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -1.34999999999999995e68Initial program 52.2%
*-un-lft-identity52.2%
associate-*r/52.2%
fma-define52.2%
add-sqr-sqrt52.2%
times-frac52.2%
fma-define52.2%
hypot-define52.2%
fma-define52.3%
fma-define52.3%
hypot-define69.4%
Applied egg-rr69.4%
Taylor expanded in c around -inf 82.6%
frac-2neg82.6%
metadata-eval82.6%
associate-*l/82.8%
Applied egg-rr87.9%
if -1.34999999999999995e68 < c < -3.00000000000000018e-118 or 3.10000000000000011e-32 < c < 4.3e107Initial program 84.1%
*-un-lft-identity84.1%
associate-*r/84.1%
fma-define84.1%
add-sqr-sqrt84.1%
times-frac84.1%
fma-define84.1%
hypot-define84.1%
fma-define84.1%
fma-define84.1%
hypot-define91.1%
Applied egg-rr91.1%
if -3.00000000000000018e-118 < c < 3.10000000000000011e-32Initial program 64.1%
Taylor expanded in d around inf 89.7%
associate-/l*91.5%
Simplified91.5%
if 4.3e107 < c Initial program 27.3%
Taylor expanded in c around inf 79.2%
associate-/l*90.9%
Simplified90.9%
Final simplification90.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* d b) (* c a)) (+ (* c c) (* d d)))))
(if (<= c -5.3e+70)
(/ (+ a (* d (/ b c))) (- (hypot c d)))
(if (<= c -8.5e-139)
t_0
(if (<= c 0.00046)
(/ (+ b (* a (/ c d))) d)
(if (<= c 4.3e+107) t_0 (/ (+ a (* b (/ d c))) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
double tmp;
if (c <= -5.3e+70) {
tmp = (a + (d * (b / c))) / -hypot(c, d);
} else if (c <= -8.5e-139) {
tmp = t_0;
} else if (c <= 0.00046) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 4.3e+107) {
tmp = t_0;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
double tmp;
if (c <= -5.3e+70) {
tmp = (a + (d * (b / c))) / -Math.hypot(c, d);
} else if (c <= -8.5e-139) {
tmp = t_0;
} else if (c <= 0.00046) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 4.3e+107) {
tmp = t_0;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d)) tmp = 0 if c <= -5.3e+70: tmp = (a + (d * (b / c))) / -math.hypot(c, d) elif c <= -8.5e-139: tmp = t_0 elif c <= 0.00046: tmp = (b + (a * (c / d))) / d elif c <= 4.3e+107: tmp = t_0 else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(d * b) + Float64(c * a)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (c <= -5.3e+70) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / Float64(-hypot(c, d))); elseif (c <= -8.5e-139) tmp = t_0; elseif (c <= 0.00046) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 4.3e+107) tmp = t_0; else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -5.3e+70) tmp = (a + (d * (b / c))) / -hypot(c, d); elseif (c <= -8.5e-139) tmp = t_0; elseif (c <= 0.00046) tmp = (b + (a * (c / d))) / d; elseif (c <= 4.3e+107) tmp = t_0; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(d * b), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -5.3e+70], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision])), $MachinePrecision], If[LessEqual[c, -8.5e-139], t$95$0, If[LessEqual[c, 0.00046], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.3e+107], t$95$0, N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -5.3 \cdot 10^{+70}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{-\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -8.5 \cdot 10^{-139}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 0.00046:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 4.3 \cdot 10^{+107}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -5.3e70Initial program 50.3%
*-un-lft-identity50.3%
associate-*r/50.3%
fma-define50.3%
add-sqr-sqrt50.3%
times-frac50.3%
fma-define50.3%
hypot-define50.3%
fma-define50.4%
fma-define50.4%
hypot-define68.2%
Applied egg-rr68.2%
Taylor expanded in c around -inf 81.9%
frac-2neg81.9%
metadata-eval81.9%
associate-*l/82.1%
Applied egg-rr87.5%
if -5.3e70 < c < -8.5000000000000003e-139 or 4.6000000000000001e-4 < c < 4.3e107Initial program 86.3%
if -8.5000000000000003e-139 < c < 4.6000000000000001e-4Initial program 65.4%
Taylor expanded in d around inf 88.2%
associate-/l*89.8%
Simplified89.8%
if 4.3e107 < c Initial program 27.3%
Taylor expanded in c around inf 79.2%
associate-/l*90.9%
Simplified90.9%
Final simplification88.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* d b) (* c a)) (+ (* c c) (* d d))))
(t_1 (/ (+ a (* b (/ d c))) c)))
(if (<= c -1.16e+128)
t_1
(if (<= c -3.2e-123)
t_0
(if (<= c 0.00045)
(/ (+ b (* a (/ c d))) d)
(if (<= c 5.2e+107) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
double t_1 = (a + (b * (d / c))) / c;
double tmp;
if (c <= -1.16e+128) {
tmp = t_1;
} else if (c <= -3.2e-123) {
tmp = t_0;
} else if (c <= 0.00045) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 5.2e+107) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d))
t_1 = (a + (b * (d / c))) / c
if (c <= (-1.16d+128)) then
tmp = t_1
else if (c <= (-3.2d-123)) then
tmp = t_0
else if (c <= 0.00045d0) then
tmp = (b + (a * (c / d))) / d
else if (c <= 5.2d+107) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
double t_1 = (a + (b * (d / c))) / c;
double tmp;
if (c <= -1.16e+128) {
tmp = t_1;
} else if (c <= -3.2e-123) {
tmp = t_0;
} else if (c <= 0.00045) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 5.2e+107) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d)) t_1 = (a + (b * (d / c))) / c tmp = 0 if c <= -1.16e+128: tmp = t_1 elif c <= -3.2e-123: tmp = t_0 elif c <= 0.00045: tmp = (b + (a * (c / d))) / d elif c <= 5.2e+107: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(d * b) + Float64(c * a)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(a + Float64(b * Float64(d / c))) / c) tmp = 0.0 if (c <= -1.16e+128) tmp = t_1; elseif (c <= -3.2e-123) tmp = t_0; elseif (c <= 0.00045) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 5.2e+107) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d)); t_1 = (a + (b * (d / c))) / c; tmp = 0.0; if (c <= -1.16e+128) tmp = t_1; elseif (c <= -3.2e-123) tmp = t_0; elseif (c <= 0.00045) tmp = (b + (a * (c / d))) / d; elseif (c <= 5.2e+107) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(d * b), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.16e+128], t$95$1, If[LessEqual[c, -3.2e-123], t$95$0, If[LessEqual[c, 0.00045], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 5.2e+107], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\
t_1 := \frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{if}\;c \leq -1.16 \cdot 10^{+128}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -3.2 \cdot 10^{-123}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 0.00045:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 5.2 \cdot 10^{+107}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -1.1600000000000001e128 or 5.2000000000000002e107 < c Initial program 28.0%
Taylor expanded in c around inf 80.9%
associate-/l*90.0%
Simplified90.0%
if -1.1600000000000001e128 < c < -3.19999999999999979e-123 or 4.4999999999999999e-4 < c < 5.2000000000000002e107Initial program 85.8%
if -3.19999999999999979e-123 < c < 4.4999999999999999e-4Initial program 65.4%
Taylor expanded in d around inf 88.2%
associate-/l*89.8%
Simplified89.8%
Final simplification88.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.2e+90) (not (<= d 6.8e+27))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.2e+90) || !(d <= 6.8e+27)) {
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.2d+90)) .or. (.not. (d <= 6.8d+27))) 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.2e+90) || !(d <= 6.8e+27)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.2e+90) or not (d <= 6.8e+27): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.2e+90) || !(d <= 6.8e+27)) 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.2e+90) || ~((d <= 6.8e+27))) 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.2e+90], N[Not[LessEqual[d, 6.8e+27]], $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.2 \cdot 10^{+90} \lor \neg \left(d \leq 6.8 \cdot 10^{+27}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.20000000000000005e90 or 6.8e27 < d Initial program 44.7%
Taylor expanded in c around 0 72.1%
if -1.20000000000000005e90 < d < 6.8e27Initial program 72.5%
Taylor expanded in c around inf 80.2%
associate-/l*81.0%
Simplified81.0%
Final simplification77.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.72e-20) (not (<= c 800.0))) (/ (+ a (* b (/ d c))) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.72e-20) || !(c <= 800.0)) {
tmp = (a + (b * (d / c))) / c;
} 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) :: tmp
if ((c <= (-1.72d-20)) .or. (.not. (c <= 800.0d0))) then
tmp = (a + (b * (d / c))) / c
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 tmp;
if ((c <= -1.72e-20) || !(c <= 800.0)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.72e-20) or not (c <= 800.0): tmp = (a + (b * (d / c))) / c else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.72e-20) || !(c <= 800.0)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.72e-20) || ~((c <= 800.0))) tmp = (a + (b * (d / c))) / c; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.72e-20], N[Not[LessEqual[c, 800.0]], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.72 \cdot 10^{-20} \lor \neg \left(c \leq 800\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if c < -1.7199999999999999e-20 or 800 < c Initial program 54.4%
Taylor expanded in c around inf 77.9%
associate-/l*83.8%
Simplified83.8%
if -1.7199999999999999e-20 < c < 800Initial program 67.7%
Taylor expanded in d around inf 84.9%
associate-/l*86.3%
Simplified86.3%
Final simplification85.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.25e+20) (not (<= d 2.45e+19))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.25e+20) || !(d <= 2.45e+19)) {
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 <= (-1.25d+20)) .or. (.not. (d <= 2.45d+19))) 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 <= -1.25e+20) || !(d <= 2.45e+19)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.25e+20) or not (d <= 2.45e+19): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.25e+20) || !(d <= 2.45e+19)) 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 <= -1.25e+20) || ~((d <= 2.45e+19))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.25e+20], N[Not[LessEqual[d, 2.45e+19]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.25 \cdot 10^{+20} \lor \neg \left(d \leq 2.45 \cdot 10^{+19}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -1.25e20 or 2.45e19 < d Initial program 45.2%
Taylor expanded in c around 0 68.3%
if -1.25e20 < d < 2.45e19Initial program 75.7%
Taylor expanded in c around inf 71.1%
Final simplification69.8%
(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 61.0%
Taylor expanded in c around inf 46.6%
Final simplification46.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 2024076
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(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))))