
(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
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -4.6e+107)
(* (+ b (* c (/ a d))) (/ -1.0 (hypot c d)))
(if (<= d -1.28e+84)
(+ (/ a c) (/ (* d (/ b c)) c))
(if (<= d -1.7e-35)
t_0
(if (<= d 9.5e-87)
(+ (/ a c) (* (/ 1.0 c) (/ (* b d) c)))
(if (<= d 6.5e+78) t_0 (+ (/ b d) (/ a (/ (pow d 2.0) 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 (d <= -4.6e+107) {
tmp = (b + (c * (a / d))) * (-1.0 / hypot(c, d));
} else if (d <= -1.28e+84) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (d <= -1.7e-35) {
tmp = t_0;
} else if (d <= 9.5e-87) {
tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
} else if (d <= 6.5e+78) {
tmp = t_0;
} else {
tmp = (b / d) + (a / (pow(d, 2.0) / c));
}
return tmp;
}
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 <= -4.6e+107) {
tmp = (b + (c * (a / d))) * (-1.0 / Math.hypot(c, d));
} else if (d <= -1.28e+84) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (d <= -1.7e-35) {
tmp = t_0;
} else if (d <= 9.5e-87) {
tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
} else if (d <= 6.5e+78) {
tmp = t_0;
} else {
tmp = (b / d) + (a / (Math.pow(d, 2.0) / c));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -4.6e+107: tmp = (b + (c * (a / d))) * (-1.0 / math.hypot(c, d)) elif d <= -1.28e+84: tmp = (a / c) + ((d * (b / c)) / c) elif d <= -1.7e-35: tmp = t_0 elif d <= 9.5e-87: tmp = (a / c) + ((1.0 / c) * ((b * d) / c)) elif d <= 6.5e+78: tmp = t_0 else: tmp = (b / d) + (a / (math.pow(d, 2.0) / 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 (d <= -4.6e+107) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) * Float64(-1.0 / hypot(c, d))); elseif (d <= -1.28e+84) tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); elseif (d <= -1.7e-35) tmp = t_0; elseif (d <= 9.5e-87) tmp = Float64(Float64(a / c) + Float64(Float64(1.0 / c) * Float64(Float64(b * d) / c))); elseif (d <= 6.5e+78) tmp = t_0; else tmp = Float64(Float64(b / d) + Float64(a / Float64((d ^ 2.0) / 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 (d <= -4.6e+107) tmp = (b + (c * (a / d))) * (-1.0 / hypot(c, d)); elseif (d <= -1.28e+84) tmp = (a / c) + ((d * (b / c)) / c); elseif (d <= -1.7e-35) tmp = t_0; elseif (d <= 9.5e-87) tmp = (a / c) + ((1.0 / c) * ((b * d) / c)); elseif (d <= 6.5e+78) tmp = t_0; else tmp = (b / d) + (a / ((d ^ 2.0) / 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[d, -4.6e+107], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.28e+84], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.7e-35], t$95$0, If[LessEqual[d, 9.5e-87], N[(N[(a / c), $MachinePrecision] + N[(N[(1.0 / c), $MachinePrecision] * N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6.5e+78], t$95$0, N[(N[(b / d), $MachinePrecision] + N[(a / N[(N[Power[d, 2.0], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $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 -4.6 \cdot 10^{+107}:\\
\;\;\;\;\left(b + c \cdot \frac{a}{d}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq -1.28 \cdot 10^{+84}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;d \leq -1.7 \cdot 10^{-35}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 9.5 \cdot 10^{-87}:\\
\;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\
\mathbf{elif}\;d \leq 6.5 \cdot 10^{+78}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{\frac{{d}^{2}}{c}}\\
\end{array}
\end{array}
if d < -4.6000000000000001e107Initial program 37.3%
*-un-lft-identity37.3%
add-sqr-sqrt37.3%
times-frac37.3%
hypot-def37.3%
fma-def37.3%
hypot-def68.2%
Applied egg-rr68.2%
Taylor expanded in d around -inf 89.9%
mul-1-neg89.9%
unsub-neg89.9%
neg-mul-189.9%
associate-/l*92.4%
associate-/r/92.5%
Simplified92.5%
if -4.6000000000000001e107 < d < -1.28e84Initial program 23.7%
Taylor expanded in c around inf 67.3%
*-commutative67.3%
pow267.3%
times-frac99.7%
Applied egg-rr99.7%
associate-*l/100.0%
Applied egg-rr100.0%
if -1.28e84 < d < -1.7000000000000001e-35 or 9.5e-87 < d < 6.50000000000000036e78Initial program 87.5%
if -1.7000000000000001e-35 < d < 9.5e-87Initial program 68.5%
Taylor expanded in c around inf 83.0%
*-un-lft-identity83.0%
pow283.0%
times-frac93.2%
Applied egg-rr93.2%
if 6.50000000000000036e78 < d Initial program 42.2%
Taylor expanded in c around 0 71.4%
associate-/l*76.1%
Simplified76.1%
Final simplification89.1%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (+ (/ a c) (* (/ d c) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (a / c) + ((d / c) * (b / 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))) <= Inf) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / 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], Infinity], 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 / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\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}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 74.9%
*-un-lft-identity74.9%
add-sqr-sqrt74.9%
times-frac74.9%
hypot-def74.9%
fma-def74.9%
hypot-def93.9%
Applied egg-rr93.9%
if +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 0.0%
Taylor expanded in c around inf 43.7%
*-commutative43.7%
pow243.7%
times-frac56.2%
Applied egg-rr56.2%
Final simplification87.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* (/ d (hypot c d)) (/ b (hypot c d)))))
(if (<= d -1.2e+84)
t_0
(if (<= d -2.1e-35)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 60000000.0) (+ (/ a c) (* (/ 1.0 c) (/ (* b d) c))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (d / hypot(c, d)) * (b / hypot(c, d));
double tmp;
if (d <= -1.2e+84) {
tmp = t_0;
} else if (d <= -2.1e-35) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 60000000.0) {
tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = (d / Math.hypot(c, d)) * (b / Math.hypot(c, d));
double tmp;
if (d <= -1.2e+84) {
tmp = t_0;
} else if (d <= -2.1e-35) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 60000000.0) {
tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (d / math.hypot(c, d)) * (b / math.hypot(c, d)) tmp = 0 if d <= -1.2e+84: tmp = t_0 elif d <= -2.1e-35: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif d <= 60000000.0: tmp = (a / c) + ((1.0 / c) * ((b * d) / c)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(d / hypot(c, d)) * Float64(b / hypot(c, d))) tmp = 0.0 if (d <= -1.2e+84) tmp = t_0; elseif (d <= -2.1e-35) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 60000000.0) tmp = Float64(Float64(a / c) + Float64(Float64(1.0 / c) * Float64(Float64(b * d) / c))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (d / hypot(c, d)) * (b / hypot(c, d)); tmp = 0.0; if (d <= -1.2e+84) tmp = t_0; elseif (d <= -2.1e-35) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (d <= 60000000.0) tmp = (a / c) + ((1.0 / c) * ((b * d) / c)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.2e+84], t$95$0, If[LessEqual[d, -2.1e-35], 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, 60000000.0], N[(N[(a / c), $MachinePrecision] + N[(N[(1.0 / c), $MachinePrecision] * N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;d \leq -1.2 \cdot 10^{+84}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -2.1 \cdot 10^{-35}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 60000000:\\
\;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.2e84 or 6e7 < d Initial program 46.9%
Taylor expanded in a around 0 40.5%
*-commutative40.5%
fma-def40.5%
add-sqr-sqrt40.5%
fma-def40.5%
hypot-udef40.5%
fma-def40.5%
hypot-udef40.5%
times-frac82.5%
Applied egg-rr82.5%
if -1.2e84 < d < -2.1e-35Initial program 88.4%
if -2.1e-35 < d < 6e7Initial program 69.8%
Taylor expanded in c around inf 81.8%
*-un-lft-identity81.8%
pow281.8%
times-frac90.9%
Applied egg-rr90.9%
Final simplification87.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ a c) (/ (* d (/ b c)) c))))
(if (<= c -3.4e-51)
t_0
(if (<= c 8e-121)
(+ (/ b d) (/ a (/ (pow d 2.0) c)))
(if (<= c 2.75e+43) (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (a / c) + ((d * (b / c)) / c);
double tmp;
if (c <= -3.4e-51) {
tmp = t_0;
} else if (c <= 8e-121) {
tmp = (b / d) + (a / (pow(d, 2.0) / c));
} else if (c <= 2.75e+43) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
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) + ((d * (b / c)) / c)
if (c <= (-3.4d-51)) then
tmp = t_0
else if (c <= 8d-121) then
tmp = (b / d) + (a / ((d ** 2.0d0) / c))
else if (c <= 2.75d+43) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (a / c) + ((d * (b / c)) / c);
double tmp;
if (c <= -3.4e-51) {
tmp = t_0;
} else if (c <= 8e-121) {
tmp = (b / d) + (a / (Math.pow(d, 2.0) / c));
} else if (c <= 2.75e+43) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a / c) + ((d * (b / c)) / c) tmp = 0 if c <= -3.4e-51: tmp = t_0 elif c <= 8e-121: tmp = (b / d) + (a / (math.pow(d, 2.0) / c)) elif c <= 2.75e+43: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)) tmp = 0.0 if (c <= -3.4e-51) tmp = t_0; elseif (c <= 8e-121) tmp = Float64(Float64(b / d) + Float64(a / Float64((d ^ 2.0) / c))); elseif (c <= 2.75e+43) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a / c) + ((d * (b / c)) / c); tmp = 0.0; if (c <= -3.4e-51) tmp = t_0; elseif (c <= 8e-121) tmp = (b / d) + (a / ((d ^ 2.0) / c)); elseif (c <= 2.75e+43) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.4e-51], t$95$0, If[LessEqual[c, 8e-121], N[(N[(b / d), $MachinePrecision] + N[(a / N[(N[Power[d, 2.0], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.75e+43], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{if}\;c \leq -3.4 \cdot 10^{-51}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 8 \cdot 10^{-121}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{\frac{{d}^{2}}{c}}\\
\mathbf{elif}\;c \leq 2.75 \cdot 10^{+43}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.40000000000000003e-51 or 2.74999999999999995e43 < c Initial program 51.8%
Taylor expanded in c around inf 77.7%
*-commutative77.7%
pow277.7%
times-frac83.6%
Applied egg-rr83.6%
associate-*l/84.2%
Applied egg-rr84.2%
if -3.40000000000000003e-51 < c < 7.9999999999999998e-121Initial program 71.9%
Taylor expanded in c around 0 82.1%
associate-/l*81.2%
Simplified81.2%
if 7.9999999999999998e-121 < c < 2.74999999999999995e43Initial program 90.7%
Final simplification83.7%
(FPCore (a b c d)
:precision binary64
(if (<= d -2.4e+108)
(/ b d)
(if (<= d -9.2e+58)
(+ (/ a c) (/ (* d (/ b c)) c))
(if (<= d -7.2e-35)
(/ (* b d) (+ (* c c) (* d d)))
(if (<= d 29000000.0)
(+ (/ a c) (* (/ 1.0 c) (/ (* b d) c)))
(/ b d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.4e+108) {
tmp = b / d;
} else if (d <= -9.2e+58) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (d <= -7.2e-35) {
tmp = (b * d) / ((c * c) + (d * d));
} else if (d <= 29000000.0) {
tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
} else {
tmp = b / 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 <= (-2.4d+108)) then
tmp = b / d
else if (d <= (-9.2d+58)) then
tmp = (a / c) + ((d * (b / c)) / c)
else if (d <= (-7.2d-35)) then
tmp = (b * d) / ((c * c) + (d * d))
else if (d <= 29000000.0d0) then
tmp = (a / c) + ((1.0d0 / c) * ((b * d) / c))
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.4e+108) {
tmp = b / d;
} else if (d <= -9.2e+58) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (d <= -7.2e-35) {
tmp = (b * d) / ((c * c) + (d * d));
} else if (d <= 29000000.0) {
tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -2.4e+108: tmp = b / d elif d <= -9.2e+58: tmp = (a / c) + ((d * (b / c)) / c) elif d <= -7.2e-35: tmp = (b * d) / ((c * c) + (d * d)) elif d <= 29000000.0: tmp = (a / c) + ((1.0 / c) * ((b * d) / c)) else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -2.4e+108) tmp = Float64(b / d); elseif (d <= -9.2e+58) tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); elseif (d <= -7.2e-35) tmp = Float64(Float64(b * d) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 29000000.0) tmp = Float64(Float64(a / c) + Float64(Float64(1.0 / c) * Float64(Float64(b * d) / c))); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -2.4e+108) tmp = b / d; elseif (d <= -9.2e+58) tmp = (a / c) + ((d * (b / c)) / c); elseif (d <= -7.2e-35) tmp = (b * d) / ((c * c) + (d * d)); elseif (d <= 29000000.0) tmp = (a / c) + ((1.0 / c) * ((b * d) / c)); else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.4e+108], N[(b / d), $MachinePrecision], If[LessEqual[d, -9.2e+58], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -7.2e-35], N[(N[(b * d), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 29000000.0], N[(N[(a / c), $MachinePrecision] + N[(N[(1.0 / c), $MachinePrecision] * N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.4 \cdot 10^{+108}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -9.2 \cdot 10^{+58}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;d \leq -7.2 \cdot 10^{-35}:\\
\;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 29000000:\\
\;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -2.40000000000000019e108 or 2.9e7 < d Initial program 48.4%
Taylor expanded in c around 0 73.5%
if -2.40000000000000019e108 < d < -9.2000000000000001e58Initial program 49.1%
Taylor expanded in c around inf 56.0%
*-commutative56.0%
pow256.0%
times-frac73.5%
Applied egg-rr73.5%
associate-*l/73.8%
Applied egg-rr73.8%
if -9.2000000000000001e58 < d < -7.20000000000000038e-35Initial program 90.4%
Taylor expanded in a around 0 61.5%
if -7.20000000000000038e-35 < d < 2.9e7Initial program 69.8%
Taylor expanded in c around inf 81.8%
*-un-lft-identity81.8%
pow281.8%
times-frac90.9%
Applied egg-rr90.9%
Final simplification81.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ a c) (/ (* d (/ b c)) c))))
(if (<= d -1.65e+108)
(/ b d)
(if (<= d -9e+58)
t_0
(if (<= d -2.5e-34)
(/ (* b d) (+ (* c c) (* d d)))
(if (<= d 2600.0) t_0 (/ b d)))))))
double code(double a, double b, double c, double d) {
double t_0 = (a / c) + ((d * (b / c)) / c);
double tmp;
if (d <= -1.65e+108) {
tmp = b / d;
} else if (d <= -9e+58) {
tmp = t_0;
} else if (d <= -2.5e-34) {
tmp = (b * d) / ((c * c) + (d * d));
} else if (d <= 2600.0) {
tmp = t_0;
} else {
tmp = b / 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) + ((d * (b / c)) / c)
if (d <= (-1.65d+108)) then
tmp = b / d
else if (d <= (-9d+58)) then
tmp = t_0
else if (d <= (-2.5d-34)) then
tmp = (b * d) / ((c * c) + (d * d))
else if (d <= 2600.0d0) then
tmp = t_0
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (a / c) + ((d * (b / c)) / c);
double tmp;
if (d <= -1.65e+108) {
tmp = b / d;
} else if (d <= -9e+58) {
tmp = t_0;
} else if (d <= -2.5e-34) {
tmp = (b * d) / ((c * c) + (d * d));
} else if (d <= 2600.0) {
tmp = t_0;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a / c) + ((d * (b / c)) / c) tmp = 0 if d <= -1.65e+108: tmp = b / d elif d <= -9e+58: tmp = t_0 elif d <= -2.5e-34: tmp = (b * d) / ((c * c) + (d * d)) elif d <= 2600.0: tmp = t_0 else: tmp = b / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)) tmp = 0.0 if (d <= -1.65e+108) tmp = Float64(b / d); elseif (d <= -9e+58) tmp = t_0; elseif (d <= -2.5e-34) tmp = Float64(Float64(b * d) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 2600.0) tmp = t_0; else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a / c) + ((d * (b / c)) / c); tmp = 0.0; if (d <= -1.65e+108) tmp = b / d; elseif (d <= -9e+58) tmp = t_0; elseif (d <= -2.5e-34) tmp = (b * d) / ((c * c) + (d * d)); elseif (d <= 2600.0) tmp = t_0; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.65e+108], N[(b / d), $MachinePrecision], If[LessEqual[d, -9e+58], t$95$0, If[LessEqual[d, -2.5e-34], N[(N[(b * d), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2600.0], t$95$0, N[(b / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{if}\;d \leq -1.65 \cdot 10^{+108}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -9 \cdot 10^{+58}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -2.5 \cdot 10^{-34}:\\
\;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 2600:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.6500000000000001e108 or 2600 < d Initial program 48.4%
Taylor expanded in c around 0 73.5%
if -1.6500000000000001e108 < d < -8.9999999999999996e58 or -2.5000000000000001e-34 < d < 2600Initial program 68.2%
Taylor expanded in c around inf 79.8%
*-commutative79.8%
pow279.8%
times-frac88.3%
Applied egg-rr88.3%
associate-*l/89.0%
Applied egg-rr89.0%
if -8.9999999999999996e58 < d < -2.5000000000000001e-34Initial program 90.4%
Taylor expanded in a around 0 61.5%
Final simplification80.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.65e+118) (not (<= c 6.4e+42))) (+ (/ a c) (/ (* d (/ b c)) c)) (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.65e+118) || !(c <= 6.4e+42)) {
tmp = (a / c) + ((d * (b / c)) / c);
} else {
tmp = ((a * c) + (b * d)) / ((c * 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.65d+118)) .or. (.not. (c <= 6.4d+42))) then
tmp = (a / c) + ((d * (b / c)) / c)
else
tmp = ((a * c) + (b * d)) / ((c * 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.65e+118) || !(c <= 6.4e+42)) {
tmp = (a / c) + ((d * (b / c)) / c);
} else {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.65e+118) or not (c <= 6.4e+42): tmp = (a / c) + ((d * (b / c)) / c) else: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.65e+118) || !(c <= 6.4e+42)) tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); else tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.65e+118) || ~((c <= 6.4e+42))) tmp = (a / c) + ((d * (b / c)) / c); else tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.65e+118], N[Not[LessEqual[c, 6.4e+42]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], 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}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.65 \cdot 10^{+118} \lor \neg \left(c \leq 6.4 \cdot 10^{+42}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\end{array}
\end{array}
if c < -1.65e118 or 6.40000000000000004e42 < c Initial program 44.3%
Taylor expanded in c around inf 80.6%
*-commutative80.6%
pow280.6%
times-frac88.3%
Applied egg-rr88.3%
associate-*l/89.2%
Applied egg-rr89.2%
if -1.65e118 < c < 6.40000000000000004e42Initial program 75.3%
Final simplification81.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5.3e+107) (not (<= d 850000000000.0))) (/ b d) (+ (/ a c) (* (/ d c) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5.3e+107) || !(d <= 850000000000.0)) {
tmp = b / d;
} else {
tmp = (a / c) + ((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 ((d <= (-5.3d+107)) .or. (.not. (d <= 850000000000.0d0))) then
tmp = b / d
else
tmp = (a / c) + ((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 ((d <= -5.3e+107) || !(d <= 850000000000.0)) {
tmp = b / d;
} else {
tmp = (a / c) + ((d / c) * (b / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5.3e+107) or not (d <= 850000000000.0): tmp = b / d else: tmp = (a / c) + ((d / c) * (b / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5.3e+107) || !(d <= 850000000000.0)) tmp = Float64(b / d); else tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -5.3e+107) || ~((d <= 850000000000.0))) tmp = b / d; else tmp = (a / c) + ((d / c) * (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5.3e+107], N[Not[LessEqual[d, 850000000000.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.3 \cdot 10^{+107} \lor \neg \left(d \leq 850000000000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\end{array}
\end{array}
if d < -5.3e107 or 8.5e11 < d Initial program 48.4%
Taylor expanded in c around 0 73.5%
if -5.3e107 < d < 8.5e11Initial program 71.1%
Taylor expanded in c around inf 74.6%
*-commutative74.6%
pow274.6%
times-frac81.9%
Applied egg-rr81.9%
Final simplification78.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.35e+109) (not (<= d 12500000.0))) (/ b d) (+ (/ a c) (/ (* d (/ b c)) c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.35e+109) || !(d <= 12500000.0)) {
tmp = b / d;
} else {
tmp = (a / c) + ((d * (b / 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.35d+109)) .or. (.not. (d <= 12500000.0d0))) then
tmp = b / d
else
tmp = (a / c) + ((d * (b / 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.35e+109) || !(d <= 12500000.0)) {
tmp = b / d;
} else {
tmp = (a / c) + ((d * (b / c)) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.35e+109) or not (d <= 12500000.0): tmp = b / d else: tmp = (a / c) + ((d * (b / c)) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.35e+109) || !(d <= 12500000.0)) tmp = Float64(b / d); else tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.35e+109) || ~((d <= 12500000.0))) tmp = b / d; else tmp = (a / c) + ((d * (b / c)) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.35e+109], N[Not[LessEqual[d, 12500000.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.35 \cdot 10^{+109} \lor \neg \left(d \leq 12500000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if d < -1.35000000000000001e109 or 1.25e7 < d Initial program 48.4%
Taylor expanded in c around 0 73.5%
if -1.35000000000000001e109 < d < 1.25e7Initial program 71.1%
Taylor expanded in c around inf 74.6%
*-commutative74.6%
pow274.6%
times-frac81.9%
Applied egg-rr81.9%
associate-*l/82.6%
Applied egg-rr82.6%
Final simplification79.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -9.2e-35) (not (<= d 12000000.0))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9.2e-35) || !(d <= 12000000.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 <= (-9.2d-35)) .or. (.not. (d <= 12000000.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 <= -9.2e-35) || !(d <= 12000000.0)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -9.2e-35) or not (d <= 12000000.0): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -9.2e-35) || !(d <= 12000000.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 <= -9.2e-35) || ~((d <= 12000000.0))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9.2e-35], N[Not[LessEqual[d, 12000000.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.2 \cdot 10^{-35} \lor \neg \left(d \leq 12000000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -9.1999999999999996e-35 or 1.2e7 < d Initial program 55.3%
Taylor expanded in c around 0 64.0%
if -9.1999999999999996e-35 < d < 1.2e7Initial program 69.8%
Taylor expanded in c around inf 79.1%
Final simplification71.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 62.6%
Taylor expanded in c around inf 49.7%
Final simplification49.7%
(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 2024096
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:herbie-target
(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))))