
(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 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 2e+299) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (+ b (* c (/ a d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 2e+299) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (b + (c * (a / d))) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= 2e+299) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e+299], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+299}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 2.0000000000000001e299Initial program 82.0%
*-un-lft-identity82.0%
add-sqr-sqrt82.0%
times-frac82.0%
hypot-define82.0%
fma-define82.0%
hypot-define97.0%
Applied egg-rr97.0%
if 2.0000000000000001e299 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 13.0%
Taylor expanded in d around inf 54.6%
associate-/l*62.1%
Simplified62.1%
clear-num62.1%
un-div-inv62.1%
Applied egg-rr62.1%
associate-/r/62.1%
Simplified62.1%
Final simplification88.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -3e+107)
(/ (+ b (* a (/ c d))) d)
(if (<= d -8.6e-119)
t_0
(if (<= d 6.5e-164)
(/ (+ a (/ b (/ c d))) c)
(if (<= d 1.4e+133) t_0 (/ (+ b (/ a (/ d c))) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -3e+107) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -8.6e-119) {
tmp = t_0;
} else if (d <= 6.5e-164) {
tmp = (a + (b / (c / d))) / c;
} else if (d <= 1.4e+133) {
tmp = t_0;
} else {
tmp = (b + (a / (d / 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) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (d <= (-3d+107)) then
tmp = (b + (a * (c / d))) / d
else if (d <= (-8.6d-119)) then
tmp = t_0
else if (d <= 6.5d-164) then
tmp = (a + (b / (c / d))) / c
else if (d <= 1.4d+133) then
tmp = t_0
else
tmp = (b + (a / (d / c))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -3e+107) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -8.6e-119) {
tmp = t_0;
} else if (d <= 6.5e-164) {
tmp = (a + (b / (c / d))) / c;
} else if (d <= 1.4e+133) {
tmp = t_0;
} else {
tmp = (b + (a / (d / c))) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -3e+107: tmp = (b + (a * (c / d))) / d elif d <= -8.6e-119: tmp = t_0 elif d <= 6.5e-164: tmp = (a + (b / (c / d))) / c elif d <= 1.4e+133: tmp = t_0 else: tmp = (b + (a / (d / c))) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (d <= -3e+107) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= -8.6e-119) tmp = t_0; elseif (d <= 6.5e-164) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); elseif (d <= 1.4e+133) tmp = t_0; else tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -3e+107) tmp = (b + (a * (c / d))) / d; elseif (d <= -8.6e-119) tmp = t_0; elseif (d <= 6.5e-164) tmp = (a + (b / (c / d))) / c; elseif (d <= 1.4e+133) tmp = t_0; else tmp = (b + (a / (d / c))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3e+107], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -8.6e-119], t$95$0, If[LessEqual[d, 6.5e-164], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.4e+133], t$95$0, N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -3 \cdot 10^{+107}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq -8.6 \cdot 10^{-119}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 6.5 \cdot 10^{-164}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\mathbf{elif}\;d \leq 1.4 \cdot 10^{+133}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\end{array}
\end{array}
if d < -3.00000000000000023e107Initial program 33.6%
Taylor expanded in d around inf 81.4%
associate-/l*86.2%
Simplified86.2%
if -3.00000000000000023e107 < d < -8.5999999999999999e-119 or 6.50000000000000004e-164 < d < 1.40000000000000008e133Initial program 81.2%
if -8.5999999999999999e-119 < d < 6.50000000000000004e-164Initial program 76.1%
Taylor expanded in c around inf 93.6%
associate-/l*93.6%
Simplified93.6%
clear-num93.6%
un-div-inv93.6%
Applied egg-rr93.6%
if 1.40000000000000008e133 < d Initial program 27.2%
Taylor expanded in d around inf 87.1%
associate-/l*94.9%
Simplified94.9%
clear-num94.9%
un-div-inv94.9%
Applied egg-rr94.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.25e-43) (not (<= d 3.4e-20))) (/ (+ b (* a (/ c d))) d) (/ (+ a (/ b (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.25e-43) || !(d <= 3.4e-20)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b / (c / d))) / 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-43)) .or. (.not. (d <= 3.4d-20))) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a + (b / (c / d))) / 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-43) || !(d <= 3.4e-20)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.25e-43) or not (d <= 3.4e-20): tmp = (b + (a * (c / d))) / d else: tmp = (a + (b / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.25e-43) || !(d <= 3.4e-20)) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.25e-43) || ~((d <= 3.4e-20))) tmp = (b + (a * (c / d))) / d; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.25e-43], N[Not[LessEqual[d, 3.4e-20]], $MachinePrecision]], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.25 \cdot 10^{-43} \lor \neg \left(d \leq 3.4 \cdot 10^{-20}\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -1.25000000000000005e-43 or 3.3999999999999997e-20 < d Initial program 53.3%
Taylor expanded in d around inf 74.7%
associate-/l*78.3%
Simplified78.3%
if -1.25000000000000005e-43 < d < 3.3999999999999997e-20Initial program 78.9%
Taylor expanded in c around inf 85.9%
associate-/l*86.0%
Simplified86.0%
clear-num86.0%
un-div-inv86.0%
Applied egg-rr86.0%
Final simplification81.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.95e-42) (not (<= d 1.6e-20))) (/ b d) (/ (+ a (/ b (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.95e-42) || !(d <= 1.6e-20)) {
tmp = b / d;
} else {
tmp = (a + (b / (c / d))) / 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.95d-42)) .or. (.not. (d <= 1.6d-20))) then
tmp = b / d
else
tmp = (a + (b / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.95e-42) || !(d <= 1.6e-20)) {
tmp = b / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.95e-42) or not (d <= 1.6e-20): tmp = b / d else: tmp = (a + (b / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.95e-42) || !(d <= 1.6e-20)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.95e-42) || ~((d <= 1.6e-20))) tmp = b / d; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.95e-42], N[Not[LessEqual[d, 1.6e-20]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.95 \cdot 10^{-42} \lor \neg \left(d \leq 1.6 \cdot 10^{-20}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -1.9500000000000001e-42 or 1.59999999999999985e-20 < d Initial program 53.3%
Taylor expanded in c around 0 66.8%
if -1.9500000000000001e-42 < d < 1.59999999999999985e-20Initial program 78.9%
Taylor expanded in c around inf 85.9%
associate-/l*86.0%
Simplified86.0%
clear-num86.0%
un-div-inv86.0%
Applied egg-rr86.0%
Final simplification75.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.9e-42) (not (<= d 2.9e-20))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.9e-42) || !(d <= 2.9e-20)) {
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.9d-42)) .or. (.not. (d <= 2.9d-20))) 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.9e-42) || !(d <= 2.9e-20)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.9e-42) or not (d <= 2.9e-20): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.9e-42) || !(d <= 2.9e-20)) 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.9e-42) || ~((d <= 2.9e-20))) 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.9e-42], N[Not[LessEqual[d, 2.9e-20]], $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.9 \cdot 10^{-42} \lor \neg \left(d \leq 2.9 \cdot 10^{-20}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.90000000000000009e-42 or 2.9e-20 < d Initial program 53.3%
Taylor expanded in c around 0 66.8%
if -1.90000000000000009e-42 < d < 2.9e-20Initial program 78.9%
Taylor expanded in c around inf 85.9%
associate-/l*86.0%
Simplified86.0%
Final simplification75.0%
(FPCore (a b c d) :precision binary64 (if (<= d -1.9e-42) (/ (+ b (/ a (/ d c))) d) (if (<= d 8.2e-21) (/ (+ a (/ b (/ c d))) c) (/ (+ b (* c (/ a d))) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.9e-42) {
tmp = (b + (a / (d / c))) / d;
} else if (d <= 8.2e-21) {
tmp = (a + (b / (c / d))) / c;
} else {
tmp = (b + (c * (a / 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 (d <= (-1.9d-42)) then
tmp = (b + (a / (d / c))) / d
else if (d <= 8.2d-21) then
tmp = (a + (b / (c / d))) / c
else
tmp = (b + (c * (a / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.9e-42) {
tmp = (b + (a / (d / c))) / d;
} else if (d <= 8.2e-21) {
tmp = (a + (b / (c / d))) / c;
} else {
tmp = (b + (c * (a / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.9e-42: tmp = (b + (a / (d / c))) / d elif d <= 8.2e-21: tmp = (a + (b / (c / d))) / c else: tmp = (b + (c * (a / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.9e-42) tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d); elseif (d <= 8.2e-21) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); else tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.9e-42) tmp = (b + (a / (d / c))) / d; elseif (d <= 8.2e-21) tmp = (a + (b / (c / d))) / c; else tmp = (b + (c * (a / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.9e-42], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 8.2e-21], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.9 \cdot 10^{-42}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\mathbf{elif}\;d \leq 8.2 \cdot 10^{-21}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\end{array}
\end{array}
if d < -1.90000000000000009e-42Initial program 54.0%
Taylor expanded in d around inf 74.1%
associate-/l*77.1%
Simplified77.1%
clear-num77.1%
un-div-inv77.2%
Applied egg-rr77.2%
if -1.90000000000000009e-42 < d < 8.19999999999999988e-21Initial program 78.9%
Taylor expanded in c around inf 85.9%
associate-/l*86.0%
Simplified86.0%
clear-num86.0%
un-div-inv86.0%
Applied egg-rr86.0%
if 8.19999999999999988e-21 < d Initial program 52.5%
Taylor expanded in d around inf 75.3%
associate-/l*79.5%
Simplified79.5%
clear-num79.5%
un-div-inv79.6%
Applied egg-rr79.6%
associate-/r/82.2%
Simplified82.2%
Final simplification82.3%
(FPCore (a b c d) :precision binary64 (if (<= d -6.5e-44) (/ (+ b (* a (/ c d))) d) (if (<= d 1.5e-21) (/ (+ a (/ b (/ c d))) c) (/ (+ b (* c (/ a d))) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -6.5e-44) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= 1.5e-21) {
tmp = (a + (b / (c / d))) / c;
} else {
tmp = (b + (c * (a / 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 (d <= (-6.5d-44)) then
tmp = (b + (a * (c / d))) / d
else if (d <= 1.5d-21) then
tmp = (a + (b / (c / d))) / c
else
tmp = (b + (c * (a / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -6.5e-44) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= 1.5e-21) {
tmp = (a + (b / (c / d))) / c;
} else {
tmp = (b + (c * (a / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -6.5e-44: tmp = (b + (a * (c / d))) / d elif d <= 1.5e-21: tmp = (a + (b / (c / d))) / c else: tmp = (b + (c * (a / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -6.5e-44) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= 1.5e-21) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); else tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -6.5e-44) tmp = (b + (a * (c / d))) / d; elseif (d <= 1.5e-21) tmp = (a + (b / (c / d))) / c; else tmp = (b + (c * (a / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -6.5e-44], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.5e-21], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.5 \cdot 10^{-44}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq 1.5 \cdot 10^{-21}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\end{array}
\end{array}
if d < -6.5e-44Initial program 54.0%
Taylor expanded in d around inf 74.1%
associate-/l*77.1%
Simplified77.1%
if -6.5e-44 < d < 1.49999999999999996e-21Initial program 78.9%
Taylor expanded in c around inf 85.9%
associate-/l*86.0%
Simplified86.0%
clear-num86.0%
un-div-inv86.0%
Applied egg-rr86.0%
if 1.49999999999999996e-21 < d Initial program 52.5%
Taylor expanded in d around inf 75.3%
associate-/l*79.5%
Simplified79.5%
clear-num79.5%
un-div-inv79.6%
Applied egg-rr79.6%
associate-/r/82.2%
Simplified82.2%
Final simplification82.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.8e-43) (not (<= d 2.8e-22))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.8e-43) || !(d <= 2.8e-22)) {
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 <= (-3.8d-43)) .or. (.not. (d <= 2.8d-22))) 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 <= -3.8e-43) || !(d <= 2.8e-22)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.8e-43) or not (d <= 2.8e-22): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.8e-43) || !(d <= 2.8e-22)) 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 <= -3.8e-43) || ~((d <= 2.8e-22))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.8e-43], N[Not[LessEqual[d, 2.8e-22]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.8 \cdot 10^{-43} \lor \neg \left(d \leq 2.8 \cdot 10^{-22}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -3.7999999999999997e-43 or 2.79999999999999995e-22 < d Initial program 53.3%
Taylor expanded in c around 0 66.8%
if -3.7999999999999997e-43 < d < 2.79999999999999995e-22Initial program 78.9%
Taylor expanded in c around inf 71.1%
Final simplification68.6%
(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 64.2%
Taylor expanded in c around inf 40.1%
(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 2024117
(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))))