
(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 8 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))) 4e+284) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (+ a (* d (/ b c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 4e+284) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (a + (d * (b / c))) / c;
}
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))) <= 4e+284) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); 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], 4e+284], 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[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 4 \cdot 10^{+284}:\\
\;\;\;\;\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{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 4.00000000000000032e284Initial program 77.2%
*-un-lft-identity77.2%
add-sqr-sqrt77.2%
times-frac77.2%
hypot-define77.2%
fma-define77.2%
hypot-define94.1%
Applied egg-rr94.1%
if 4.00000000000000032e284 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 8.3%
Taylor expanded in c around inf 54.5%
*-commutative54.5%
associate-/l*64.9%
Applied egg-rr64.9%
Final simplification86.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -6.6e+57)
(/ (+ a (* d (/ b c))) c)
(if (<= c -2.9e-72)
t_0
(if (<= c 2.7e-153)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 8e+50) t_0 (/ (+ a (/ d (/ c b))) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -6.6e+57) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= -2.9e-72) {
tmp = t_0;
} else if (c <= 2.7e-153) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 8e+50) {
tmp = t_0;
} else {
tmp = (a + (d / (c / 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) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (c <= (-6.6d+57)) then
tmp = (a + (d * (b / c))) / c
else if (c <= (-2.9d-72)) then
tmp = t_0
else if (c <= 2.7d-153) then
tmp = (b + ((a * c) / d)) / d
else if (c <= 8d+50) then
tmp = t_0
else
tmp = (a + (d / (c / b))) / c
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 (c <= -6.6e+57) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= -2.9e-72) {
tmp = t_0;
} else if (c <= 2.7e-153) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 8e+50) {
tmp = t_0;
} else {
tmp = (a + (d / (c / b))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -6.6e+57: tmp = (a + (d * (b / c))) / c elif c <= -2.9e-72: tmp = t_0 elif c <= 2.7e-153: tmp = (b + ((a * c) / d)) / d elif c <= 8e+50: tmp = t_0 else: tmp = (a + (d / (c / b))) / c 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 (c <= -6.6e+57) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); elseif (c <= -2.9e-72) tmp = t_0; elseif (c <= 2.7e-153) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 8e+50) tmp = t_0; else tmp = Float64(Float64(a + Float64(d / Float64(c / b))) / c); 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 (c <= -6.6e+57) tmp = (a + (d * (b / c))) / c; elseif (c <= -2.9e-72) tmp = t_0; elseif (c <= 2.7e-153) tmp = (b + ((a * c) / d)) / d; elseif (c <= 8e+50) tmp = t_0; else tmp = (a + (d / (c / b))) / c; 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[c, -6.6e+57], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -2.9e-72], t$95$0, If[LessEqual[c, 2.7e-153], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8e+50], t$95$0, N[(N[(a + N[(d / N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -6.6 \cdot 10^{+57}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq -2.9 \cdot 10^{-72}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.7 \cdot 10^{-153}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 8 \cdot 10^{+50}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{d}{\frac{c}{b}}}{c}\\
\end{array}
\end{array}
if c < -6.6000000000000002e57Initial program 37.7%
Taylor expanded in c around inf 76.9%
*-commutative76.9%
associate-/l*82.8%
Applied egg-rr82.8%
if -6.6000000000000002e57 < c < -2.89999999999999998e-72 or 2.70000000000000009e-153 < c < 8.0000000000000006e50Initial program 86.7%
if -2.89999999999999998e-72 < c < 2.70000000000000009e-153Initial program 67.0%
Taylor expanded in d around inf 91.2%
if 8.0000000000000006e50 < c Initial program 39.5%
Taylor expanded in c around inf 75.5%
*-commutative75.5%
associate-/l*82.2%
Applied egg-rr82.2%
clear-num83.6%
un-div-inv83.7%
Applied egg-rr83.7%
Final simplification86.5%
(FPCore (a b c d)
:precision binary64
(if (<= c -8.6e-26)
(/ (+ a (* d (/ b c))) c)
(if (<= c 5.8e-66)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 2.4e+15)
(/ (+ a (* b (/ d c))) c)
(if (<= c 6.2e+75)
(/ (+ b (* a (/ c d))) d)
(/ (+ a (/ d (/ c b))) c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -8.6e-26) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= 5.8e-66) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 2.4e+15) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 6.2e+75) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (d / (c / 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 (c <= (-8.6d-26)) then
tmp = (a + (d * (b / c))) / c
else if (c <= 5.8d-66) then
tmp = (b + ((a * c) / d)) / d
else if (c <= 2.4d+15) then
tmp = (a + (b * (d / c))) / c
else if (c <= 6.2d+75) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a + (d / (c / b))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -8.6e-26) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= 5.8e-66) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 2.4e+15) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 6.2e+75) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (d / (c / b))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -8.6e-26: tmp = (a + (d * (b / c))) / c elif c <= 5.8e-66: tmp = (b + ((a * c) / d)) / d elif c <= 2.4e+15: tmp = (a + (b * (d / c))) / c elif c <= 6.2e+75: tmp = (b + (a * (c / d))) / d else: tmp = (a + (d / (c / b))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -8.6e-26) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); elseif (c <= 5.8e-66) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 2.4e+15) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= 6.2e+75) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(d / Float64(c / b))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -8.6e-26) tmp = (a + (d * (b / c))) / c; elseif (c <= 5.8e-66) tmp = (b + ((a * c) / d)) / d; elseif (c <= 2.4e+15) tmp = (a + (b * (d / c))) / c; elseif (c <= 6.2e+75) tmp = (b + (a * (c / d))) / d; else tmp = (a + (d / (c / b))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -8.6e-26], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 5.8e-66], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.4e+15], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 6.2e+75], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(d / N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.6 \cdot 10^{-26}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq 5.8 \cdot 10^{-66}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{+15}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 6.2 \cdot 10^{+75}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{d}{\frac{c}{b}}}{c}\\
\end{array}
\end{array}
if c < -8.59999999999999976e-26Initial program 51.2%
Taylor expanded in c around inf 74.6%
*-commutative74.6%
associate-/l*78.9%
Applied egg-rr78.9%
if -8.59999999999999976e-26 < c < 5.80000000000000023e-66Initial program 74.1%
Taylor expanded in d around inf 85.3%
if 5.80000000000000023e-66 < c < 2.4e15Initial program 87.3%
Taylor expanded in c around inf 73.1%
associate-/l*73.1%
Simplified73.1%
if 2.4e15 < c < 6.2000000000000002e75Initial program 46.4%
Taylor expanded in d around inf 74.0%
associate-/l*74.0%
Simplified74.0%
if 6.2000000000000002e75 < c Initial program 39.3%
Taylor expanded in c around inf 78.2%
*-commutative78.2%
associate-/l*85.5%
Applied egg-rr85.5%
clear-num87.0%
un-div-inv87.1%
Applied egg-rr87.1%
Final simplification82.8%
(FPCore (a b c d)
:precision binary64
(if (or (<= d -2.7e-70)
(not (or (<= d 1.35e-99) (and (not (<= d 4.5e-89)) (<= d 4.6e+56)))))
(/ b d)
(/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.7e-70) || !((d <= 1.35e-99) || (!(d <= 4.5e-89) && (d <= 4.6e+56)))) {
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 <= (-2.7d-70)) .or. (.not. (d <= 1.35d-99) .or. (.not. (d <= 4.5d-89)) .and. (d <= 4.6d+56))) 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 <= -2.7e-70) || !((d <= 1.35e-99) || (!(d <= 4.5e-89) && (d <= 4.6e+56)))) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.7e-70) or not ((d <= 1.35e-99) or (not (d <= 4.5e-89) and (d <= 4.6e+56))): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.7e-70) || !((d <= 1.35e-99) || (!(d <= 4.5e-89) && (d <= 4.6e+56)))) 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 <= -2.7e-70) || ~(((d <= 1.35e-99) || (~((d <= 4.5e-89)) && (d <= 4.6e+56))))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.7e-70], N[Not[Or[LessEqual[d, 1.35e-99], And[N[Not[LessEqual[d, 4.5e-89]], $MachinePrecision], LessEqual[d, 4.6e+56]]]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.7 \cdot 10^{-70} \lor \neg \left(d \leq 1.35 \cdot 10^{-99} \lor \neg \left(d \leq 4.5 \cdot 10^{-89}\right) \land d \leq 4.6 \cdot 10^{+56}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -2.7000000000000001e-70 or 1.35e-99 < d < 4.4999999999999999e-89 or 4.60000000000000029e56 < d Initial program 51.4%
Taylor expanded in c around 0 68.1%
if -2.7000000000000001e-70 < d < 1.35e-99 or 4.4999999999999999e-89 < d < 4.60000000000000029e56Initial program 67.3%
Taylor expanded in c around inf 71.8%
Final simplification70.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.1e-46) (not (<= d 3.2e+59))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.1e-46) || !(d <= 3.2e+59)) {
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 <= (-3.1d-46)) .or. (.not. (d <= 3.2d+59))) 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 <= -3.1e-46) || !(d <= 3.2e+59)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.1e-46) or not (d <= 3.2e+59): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.1e-46) || !(d <= 3.2e+59)) 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 <= -3.1e-46) || ~((d <= 3.2e+59))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.1e-46], N[Not[LessEqual[d, 3.2e+59]], $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 -3.1 \cdot 10^{-46} \lor \neg \left(d \leq 3.2 \cdot 10^{+59}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -3.1000000000000001e-46 or 3.19999999999999982e59 < d Initial program 47.3%
Taylor expanded in c around 0 68.7%
if -3.1000000000000001e-46 < d < 3.19999999999999982e59Initial program 69.7%
Taylor expanded in c around inf 80.4%
associate-/l*81.2%
Simplified81.2%
Final simplification75.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.15e-65) (not (<= d 6.6e+63))) (/ (+ b (* a (/ c d))) d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.15e-65) || !(d <= 6.6e+63)) {
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 <= (-1.15d-65)) .or. (.not. (d <= 6.6d+63))) 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 <= -1.15e-65) || !(d <= 6.6e+63)) {
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 <= -1.15e-65) or not (d <= 6.6e+63): 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 <= -1.15e-65) || !(d <= 6.6e+63)) 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 <= -1.15e-65) || ~((d <= 6.6e+63))) 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, -1.15e-65], N[Not[LessEqual[d, 6.6e+63]], $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 -1.15 \cdot 10^{-65} \lor \neg \left(d \leq 6.6 \cdot 10^{+63}\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 < -1.15e-65 or 6.6000000000000003e63 < d Initial program 48.2%
Taylor expanded in d around inf 73.5%
associate-/l*77.0%
Simplified77.0%
if -1.15e-65 < d < 6.6000000000000003e63Initial program 69.2%
Taylor expanded in c around inf 80.8%
associate-/l*81.6%
Simplified81.6%
Final simplification79.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.15e-65) (not (<= d 1.4e+58))) (/ (+ b (* c (/ a d))) d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.15e-65) || !(d <= 1.4e+58)) {
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 <= (-1.15d-65)) .or. (.not. (d <= 1.4d+58))) 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 <= -1.15e-65) || !(d <= 1.4e+58)) {
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 <= -1.15e-65) or not (d <= 1.4e+58): 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 <= -1.15e-65) || !(d <= 1.4e+58)) 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 <= -1.15e-65) || ~((d <= 1.4e+58))) 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, -1.15e-65], N[Not[LessEqual[d, 1.4e+58]], $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 -1.15 \cdot 10^{-65} \lor \neg \left(d \leq 1.4 \cdot 10^{+58}\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 < -1.15e-65 or 1.3999999999999999e58 < d Initial program 48.2%
Taylor expanded in d around inf 73.5%
*-commutative73.5%
*-un-lft-identity73.5%
times-frac77.7%
Applied egg-rr77.7%
if -1.15e-65 < d < 1.3999999999999999e58Initial program 69.2%
Taylor expanded in c around inf 80.8%
associate-/l*81.6%
Simplified81.6%
Final simplification79.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 59.4%
Taylor expanded in c around inf 47.8%
Final simplification47.8%
(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 2024050
(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))))