
(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 11 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 (or (<= c -2.25e-162) (not (<= c 1.22e-54))) (* (/ (fma b (/ d c) a) (hypot c d)) (/ c (hypot c d))) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.25e-162) || !(c <= 1.22e-54)) {
tmp = (fma(b, (d / c), a) / hypot(c, d)) * (c / hypot(c, d));
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.25e-162) || !(c <= 1.22e-54)) tmp = Float64(Float64(fma(b, Float64(d / c), a) / hypot(c, d)) * Float64(c / hypot(c, d))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.25e-162], N[Not[LessEqual[c, 1.22e-54]], $MachinePrecision]], N[(N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.25 \cdot 10^{-162} \lor \neg \left(c \leq 1.22 \cdot 10^{-54}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if c < -2.25000000000000011e-162 or 1.22e-54 < c Initial program 57.9%
Taylor expanded in c around inf 57.4%
*-commutative57.4%
add-sqr-sqrt57.3%
hypot-undefine57.3%
hypot-undefine57.3%
times-frac87.7%
+-commutative87.7%
associate-/l*93.7%
fma-define93.7%
Applied egg-rr93.7%
if -2.25000000000000011e-162 < c < 1.22e-54Initial program 66.9%
Taylor expanded in d around inf 90.5%
associate-/l*90.7%
Simplified90.7%
Final simplification92.8%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* c a) (* b d)) (+ (* c c) (* d d))) 1e+286) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (+ b (/ a (/ d c))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((c * a) + (b * d)) / ((c * c) + (d * d))) <= 1e+286) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (b + (a / (d / c))) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (Float64(Float64(Float64(c * a) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= 1e+286) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+286], 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[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d} \leq 10^{+286}:\\
\;\;\;\;\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 + \frac{a}{\frac{d}{c}}}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.00000000000000003e286Initial program 75.5%
*-un-lft-identity75.5%
associate-*r/75.5%
fma-define75.5%
add-sqr-sqrt75.5%
times-frac75.5%
fma-define75.5%
hypot-define75.5%
fma-define75.5%
fma-define75.5%
hypot-define94.6%
Applied egg-rr94.6%
if 1.00000000000000003e286 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 15.2%
Taylor expanded in d around inf 59.8%
associate-/l*63.0%
Simplified63.0%
clear-num63.0%
un-div-inv63.0%
Applied egg-rr63.0%
Final simplification86.8%
(FPCore (a b c d)
:precision binary64
(if (<= d -7.0)
(/ (+ b (/ (* c a) d)) d)
(if (<= d 1.35e-83)
(/ (+ a (/ (* b d) c)) c)
(if (<= d 3e+96)
(/ (+ (* c a) (* b d)) (+ (* c c) (* d d)))
(/ (+ b (/ a (/ d c))) d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -7.0) {
tmp = (b + ((c * a) / d)) / d;
} else if (d <= 1.35e-83) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 3e+96) {
tmp = ((c * a) + (b * d)) / ((c * c) + (d * d));
} 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) :: tmp
if (d <= (-7.0d0)) then
tmp = (b + ((c * a) / d)) / d
else if (d <= 1.35d-83) then
tmp = (a + ((b * d) / c)) / c
else if (d <= 3d+96) then
tmp = ((c * a) + (b * d)) / ((c * c) + (d * d))
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 tmp;
if (d <= -7.0) {
tmp = (b + ((c * a) / d)) / d;
} else if (d <= 1.35e-83) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 3e+96) {
tmp = ((c * a) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (b + (a / (d / c))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -7.0: tmp = (b + ((c * a) / d)) / d elif d <= 1.35e-83: tmp = (a + ((b * d) / c)) / c elif d <= 3e+96: tmp = ((c * a) + (b * d)) / ((c * c) + (d * d)) else: tmp = (b + (a / (d / c))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -7.0) tmp = Float64(Float64(b + Float64(Float64(c * a) / d)) / d); elseif (d <= 1.35e-83) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif (d <= 3e+96) tmp = Float64(Float64(Float64(c * a) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -7.0) tmp = (b + ((c * a) / d)) / d; elseif (d <= 1.35e-83) tmp = (a + ((b * d) / c)) / c; elseif (d <= 3e+96) tmp = ((c * a) + (b * d)) / ((c * c) + (d * d)); else tmp = (b + (a / (d / c))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -7.0], N[(N[(b + N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.35e-83], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3e+96], N[(N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -7:\\
\;\;\;\;\frac{b + \frac{c \cdot a}{d}}{d}\\
\mathbf{elif}\;d \leq 1.35 \cdot 10^{-83}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 3 \cdot 10^{+96}:\\
\;\;\;\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\end{array}
\end{array}
if d < -7Initial program 47.7%
Taylor expanded in d around inf 85.6%
if -7 < d < 1.34999999999999996e-83Initial program 73.8%
Taylor expanded in c around inf 88.0%
if 1.34999999999999996e-83 < d < 3e96Initial program 76.7%
if 3e96 < d Initial program 36.8%
Taylor expanded in d around inf 85.4%
associate-/l*89.6%
Simplified89.6%
clear-num89.6%
un-div-inv89.7%
Applied egg-rr89.7%
Final simplification86.2%
(FPCore (a b c d)
:precision binary64
(if (or (<= d -8.5e+33)
(and (not (<= d 6600000000000.0))
(or (<= d 1.15e+55) (not (<= d 7.2e+108)))))
(/ b d)
(/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -8.5e+33) || (!(d <= 6600000000000.0) && ((d <= 1.15e+55) || !(d <= 7.2e+108)))) {
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 <= (-8.5d+33)) .or. (.not. (d <= 6600000000000.0d0)) .and. (d <= 1.15d+55) .or. (.not. (d <= 7.2d+108))) 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 <= -8.5e+33) || (!(d <= 6600000000000.0) && ((d <= 1.15e+55) || !(d <= 7.2e+108)))) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -8.5e+33) or (not (d <= 6600000000000.0) and ((d <= 1.15e+55) or not (d <= 7.2e+108))): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -8.5e+33) || (!(d <= 6600000000000.0) && ((d <= 1.15e+55) || !(d <= 7.2e+108)))) 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 <= -8.5e+33) || (~((d <= 6600000000000.0)) && ((d <= 1.15e+55) || ~((d <= 7.2e+108))))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -8.5e+33], And[N[Not[LessEqual[d, 6600000000000.0]], $MachinePrecision], Or[LessEqual[d, 1.15e+55], N[Not[LessEqual[d, 7.2e+108]], $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 -8.5 \cdot 10^{+33} \lor \neg \left(d \leq 6600000000000\right) \land \left(d \leq 1.15 \cdot 10^{+55} \lor \neg \left(d \leq 7.2 \cdot 10^{+108}\right)\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -8.4999999999999998e33 or 6.6e12 < d < 1.14999999999999994e55 or 7.2e108 < d Initial program 46.9%
Taylor expanded in c around 0 74.3%
if -8.4999999999999998e33 < d < 6.6e12 or 1.14999999999999994e55 < d < 7.2e108Initial program 72.3%
Taylor expanded in c around inf 82.5%
associate-/l*81.9%
Simplified81.9%
Final simplification78.4%
(FPCore (a b c d)
:precision binary64
(if (<= d -0.025)
(/ (+ b (/ (* c a) d)) d)
(if (<= d 18000000000.0)
(/ (+ a (/ (* b d) c)) c)
(if (or (<= d 6.5e+56) (not (<= d 2.45e+100)))
(/ (+ b (/ a (/ d c))) d)
(/ (+ a (* b (/ d c))) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -0.025) {
tmp = (b + ((c * a) / d)) / d;
} else if (d <= 18000000000.0) {
tmp = (a + ((b * d) / c)) / c;
} else if ((d <= 6.5e+56) || !(d <= 2.45e+100)) {
tmp = (b + (a / (d / c))) / 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 <= (-0.025d0)) then
tmp = (b + ((c * a) / d)) / d
else if (d <= 18000000000.0d0) then
tmp = (a + ((b * d) / c)) / c
else if ((d <= 6.5d+56) .or. (.not. (d <= 2.45d+100))) then
tmp = (b + (a / (d / c))) / 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 <= -0.025) {
tmp = (b + ((c * a) / d)) / d;
} else if (d <= 18000000000.0) {
tmp = (a + ((b * d) / c)) / c;
} else if ((d <= 6.5e+56) || !(d <= 2.45e+100)) {
tmp = (b + (a / (d / c))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -0.025: tmp = (b + ((c * a) / d)) / d elif d <= 18000000000.0: tmp = (a + ((b * d) / c)) / c elif (d <= 6.5e+56) or not (d <= 2.45e+100): tmp = (b + (a / (d / c))) / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -0.025) tmp = Float64(Float64(b + Float64(Float64(c * a) / d)) / d); elseif (d <= 18000000000.0) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif ((d <= 6.5e+56) || !(d <= 2.45e+100)) tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / 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 <= -0.025) tmp = (b + ((c * a) / d)) / d; elseif (d <= 18000000000.0) tmp = (a + ((b * d) / c)) / c; elseif ((d <= 6.5e+56) || ~((d <= 2.45e+100))) tmp = (b + (a / (d / c))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -0.025], N[(N[(b + N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 18000000000.0], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[d, 6.5e+56], N[Not[LessEqual[d, 2.45e+100]], $MachinePrecision]], N[(N[(b + N[(a / N[(d / c), $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 -0.025:\\
\;\;\;\;\frac{b + \frac{c \cdot a}{d}}{d}\\
\mathbf{elif}\;d \leq 18000000000:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 6.5 \cdot 10^{+56} \lor \neg \left(d \leq 2.45 \cdot 10^{+100}\right):\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -0.025000000000000001Initial program 47.7%
Taylor expanded in d around inf 85.6%
if -0.025000000000000001 < d < 1.8e10Initial program 73.5%
Taylor expanded in c around inf 84.4%
if 1.8e10 < d < 6.5000000000000001e56 or 2.44999999999999983e100 < d Initial program 48.0%
Taylor expanded in d around inf 85.9%
associate-/l*89.5%
Simplified89.5%
clear-num89.5%
un-div-inv89.5%
Applied egg-rr89.5%
if 6.5000000000000001e56 < d < 2.44999999999999983e100Initial program 51.1%
Taylor expanded in c around inf 75.6%
associate-/l*87.7%
Simplified87.7%
Final simplification85.9%
(FPCore (a b c d)
:precision binary64
(if (<= d -3.8e-5)
(/ (+ b (* a (/ c d))) d)
(if (<= d 2.1e+14)
(/ (+ a (/ (* b d) c)) c)
(if (or (<= d 1.22e+56) (not (<= d 3e+100)))
(/ (+ b (/ a (/ d c))) d)
(/ (+ a (* b (/ d c))) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3.8e-5) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= 2.1e+14) {
tmp = (a + ((b * d) / c)) / c;
} else if ((d <= 1.22e+56) || !(d <= 3e+100)) {
tmp = (b + (a / (d / c))) / 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.8d-5)) then
tmp = (b + (a * (c / d))) / d
else if (d <= 2.1d+14) then
tmp = (a + ((b * d) / c)) / c
else if ((d <= 1.22d+56) .or. (.not. (d <= 3d+100))) then
tmp = (b + (a / (d / c))) / 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.8e-5) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= 2.1e+14) {
tmp = (a + ((b * d) / c)) / c;
} else if ((d <= 1.22e+56) || !(d <= 3e+100)) {
tmp = (b + (a / (d / c))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -3.8e-5: tmp = (b + (a * (c / d))) / d elif d <= 2.1e+14: tmp = (a + ((b * d) / c)) / c elif (d <= 1.22e+56) or not (d <= 3e+100): tmp = (b + (a / (d / c))) / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -3.8e-5) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= 2.1e+14) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif ((d <= 1.22e+56) || !(d <= 3e+100)) tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / 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.8e-5) tmp = (b + (a * (c / d))) / d; elseif (d <= 2.1e+14) tmp = (a + ((b * d) / c)) / c; elseif ((d <= 1.22e+56) || ~((d <= 3e+100))) tmp = (b + (a / (d / c))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -3.8e-5], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 2.1e+14], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[d, 1.22e+56], N[Not[LessEqual[d, 3e+100]], $MachinePrecision]], N[(N[(b + N[(a / N[(d / c), $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 -3.8 \cdot 10^{-5}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{+14}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.22 \cdot 10^{+56} \lor \neg \left(d \leq 3 \cdot 10^{+100}\right):\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -3.8000000000000002e-5Initial program 47.7%
Taylor expanded in d around inf 85.6%
associate-/l*84.5%
Simplified84.5%
if -3.8000000000000002e-5 < d < 2.1e14Initial program 73.5%
Taylor expanded in c around inf 84.4%
if 2.1e14 < d < 1.22e56 or 2.99999999999999985e100 < d Initial program 48.0%
Taylor expanded in d around inf 85.9%
associate-/l*89.5%
Simplified89.5%
clear-num89.5%
un-div-inv89.5%
Applied egg-rr89.5%
if 1.22e56 < d < 2.99999999999999985e100Initial program 51.1%
Taylor expanded in c around inf 75.6%
associate-/l*87.7%
Simplified87.7%
Final simplification85.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ b (* a (/ c d))) d)))
(if (<= d -0.043)
t_0
(if (<= d 2.2e+15)
(/ (+ a (/ (* b d) c)) c)
(if (or (<= d 6.8e+56) (not (<= d 1.22e+101)))
t_0
(/ (+ a (* b (/ d c))) c))))))
double code(double a, double b, double c, double d) {
double t_0 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -0.043) {
tmp = t_0;
} else if (d <= 2.2e+15) {
tmp = (a + ((b * d) / c)) / c;
} else if ((d <= 6.8e+56) || !(d <= 1.22e+101)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = (b + (a * (c / d))) / d
if (d <= (-0.043d0)) then
tmp = t_0
else if (d <= 2.2d+15) then
tmp = (a + ((b * d) / c)) / c
else if ((d <= 6.8d+56) .or. (.not. (d <= 1.22d+101))) then
tmp = t_0
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 t_0 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -0.043) {
tmp = t_0;
} else if (d <= 2.2e+15) {
tmp = (a + ((b * d) / c)) / c;
} else if ((d <= 6.8e+56) || !(d <= 1.22e+101)) {
tmp = t_0;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b + (a * (c / d))) / d tmp = 0 if d <= -0.043: tmp = t_0 elif d <= 2.2e+15: tmp = (a + ((b * d) / c)) / c elif (d <= 6.8e+56) or not (d <= 1.22e+101): tmp = t_0 else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b + Float64(a * Float64(c / d))) / d) tmp = 0.0 if (d <= -0.043) tmp = t_0; elseif (d <= 2.2e+15) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif ((d <= 6.8e+56) || !(d <= 1.22e+101)) 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 = (b + (a * (c / d))) / d; tmp = 0.0; if (d <= -0.043) tmp = t_0; elseif (d <= 2.2e+15) tmp = (a + ((b * d) / c)) / c; elseif ((d <= 6.8e+56) || ~((d <= 1.22e+101))) 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[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -0.043], t$95$0, If[LessEqual[d, 2.2e+15], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[d, 6.8e+56], N[Not[LessEqual[d, 1.22e+101]], $MachinePrecision]], 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{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{if}\;d \leq -0.043:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.2 \cdot 10^{+15}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 6.8 \cdot 10^{+56} \lor \neg \left(d \leq 1.22 \cdot 10^{+101}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -0.042999999999999997 or 2.2e15 < d < 6.80000000000000002e56 or 1.22e101 < d Initial program 47.8%
Taylor expanded in d around inf 85.7%
associate-/l*86.7%
Simplified86.7%
if -0.042999999999999997 < d < 2.2e15Initial program 73.5%
Taylor expanded in c around inf 84.4%
if 6.80000000000000002e56 < d < 1.22e101Initial program 51.1%
Taylor expanded in c around inf 75.6%
associate-/l*87.7%
Simplified87.7%
Final simplification85.6%
(FPCore (a b c d)
:precision binary64
(if (<= d -2.6e+29)
(/ b d)
(if (<= d 3300000000000.0)
(/ (+ a (/ (* b d) c)) c)
(if (or (<= d 2.12e+55) (not (<= d 4.5e+100)))
(/ b d)
(/ (+ a (* b (/ d c))) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.6e+29) {
tmp = b / d;
} else if (d <= 3300000000000.0) {
tmp = (a + ((b * d) / c)) / c;
} else if ((d <= 2.12e+55) || !(d <= 4.5e+100)) {
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 <= (-2.6d+29)) then
tmp = b / d
else if (d <= 3300000000000.0d0) then
tmp = (a + ((b * d) / c)) / c
else if ((d <= 2.12d+55) .or. (.not. (d <= 4.5d+100))) 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 <= -2.6e+29) {
tmp = b / d;
} else if (d <= 3300000000000.0) {
tmp = (a + ((b * d) / c)) / c;
} else if ((d <= 2.12e+55) || !(d <= 4.5e+100)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -2.6e+29: tmp = b / d elif d <= 3300000000000.0: tmp = (a + ((b * d) / c)) / c elif (d <= 2.12e+55) or not (d <= 4.5e+100): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -2.6e+29) tmp = Float64(b / d); elseif (d <= 3300000000000.0) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif ((d <= 2.12e+55) || !(d <= 4.5e+100)) 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 <= -2.6e+29) tmp = b / d; elseif (d <= 3300000000000.0) tmp = (a + ((b * d) / c)) / c; elseif ((d <= 2.12e+55) || ~((d <= 4.5e+100))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.6e+29], N[(b / d), $MachinePrecision], If[LessEqual[d, 3300000000000.0], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[d, 2.12e+55], N[Not[LessEqual[d, 4.5e+100]], $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 -2.6 \cdot 10^{+29}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 3300000000000:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.12 \cdot 10^{+55} \lor \neg \left(d \leq 4.5 \cdot 10^{+100}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -2.6e29 or 3.3e12 < d < 2.12000000000000007e55 or 4.50000000000000036e100 < d Initial program 46.9%
Taylor expanded in c around 0 74.3%
if -2.6e29 < d < 3.3e12Initial program 73.6%
Taylor expanded in c around inf 82.9%
if 2.12000000000000007e55 < d < 4.50000000000000036e100Initial program 51.1%
Taylor expanded in c around inf 75.6%
associate-/l*87.7%
Simplified87.7%
Final simplification79.1%
(FPCore (a b c d)
:precision binary64
(if (<= d -0.00012)
(/ (+ b (/ (* c a) d)) d)
(if (<= d 0.4)
(/ (+ a (/ (* b d) c)) c)
(if (<= d 2.6e+55)
(/ (* b d) (+ (* c c) (* d d)))
(if (<= d 2.5e+100)
(/ (+ a (* b (/ d c))) c)
(/ (+ b (/ a (/ d c))) d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -0.00012) {
tmp = (b + ((c * a) / d)) / d;
} else if (d <= 0.4) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 2.6e+55) {
tmp = (b * d) / ((c * c) + (d * d));
} else if (d <= 2.5e+100) {
tmp = (a + (b * (d / c))) / c;
} 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) :: tmp
if (d <= (-0.00012d0)) then
tmp = (b + ((c * a) / d)) / d
else if (d <= 0.4d0) then
tmp = (a + ((b * d) / c)) / c
else if (d <= 2.6d+55) then
tmp = (b * d) / ((c * c) + (d * d))
else if (d <= 2.5d+100) then
tmp = (a + (b * (d / c))) / c
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 tmp;
if (d <= -0.00012) {
tmp = (b + ((c * a) / d)) / d;
} else if (d <= 0.4) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 2.6e+55) {
tmp = (b * d) / ((c * c) + (d * d));
} else if (d <= 2.5e+100) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + (a / (d / c))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -0.00012: tmp = (b + ((c * a) / d)) / d elif d <= 0.4: tmp = (a + ((b * d) / c)) / c elif d <= 2.6e+55: tmp = (b * d) / ((c * c) + (d * d)) elif d <= 2.5e+100: tmp = (a + (b * (d / c))) / c else: tmp = (b + (a / (d / c))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -0.00012) tmp = Float64(Float64(b + Float64(Float64(c * a) / d)) / d); elseif (d <= 0.4) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif (d <= 2.6e+55) tmp = Float64(Float64(b * d) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 2.5e+100) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -0.00012) tmp = (b + ((c * a) / d)) / d; elseif (d <= 0.4) tmp = (a + ((b * d) / c)) / c; elseif (d <= 2.6e+55) tmp = (b * d) / ((c * c) + (d * d)); elseif (d <= 2.5e+100) tmp = (a + (b * (d / c))) / c; else tmp = (b + (a / (d / c))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -0.00012], N[(N[(b + N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 0.4], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.6e+55], N[(N[(b * d), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.5e+100], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.00012:\\
\;\;\;\;\frac{b + \frac{c \cdot a}{d}}{d}\\
\mathbf{elif}\;d \leq 0.4:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.6 \cdot 10^{+55}:\\
\;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 2.5 \cdot 10^{+100}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\end{array}
\end{array}
if d < -1.20000000000000003e-4Initial program 47.7%
Taylor expanded in d around inf 85.6%
if -1.20000000000000003e-4 < d < 0.40000000000000002Initial program 73.1%
Taylor expanded in c around inf 84.9%
if 0.40000000000000002 < d < 2.6e55Initial program 99.7%
Taylor expanded in a around 0 91.1%
if 2.6e55 < d < 2.4999999999999999e100Initial program 51.1%
Taylor expanded in c around inf 75.6%
associate-/l*87.7%
Simplified87.7%
if 2.4999999999999999e100 < d Initial program 37.6%
Taylor expanded in d around inf 87.2%
associate-/l*91.5%
Simplified91.5%
clear-num91.5%
un-div-inv91.6%
Applied egg-rr91.6%
Final simplification86.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.5e-6) (not (<= d 4200000000.0))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.5e-6) || !(d <= 4200000000.0)) {
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 <= (-4.5d-6)) .or. (.not. (d <= 4200000000.0d0))) 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 <= -4.5e-6) || !(d <= 4200000000.0)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.5e-6) or not (d <= 4200000000.0): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.5e-6) || !(d <= 4200000000.0)) 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 <= -4.5e-6) || ~((d <= 4200000000.0))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.5e-6], N[Not[LessEqual[d, 4200000000.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.5 \cdot 10^{-6} \lor \neg \left(d \leq 4200000000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -4.50000000000000011e-6 or 4.2e9 < d Initial program 48.0%
Taylor expanded in c around 0 69.4%
if -4.50000000000000011e-6 < d < 4.2e9Initial program 73.5%
Taylor expanded in c around inf 67.1%
Final simplification68.3%
(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 60.7%
Taylor expanded in c around inf 39.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 2024092
(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))))