
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 1e+270) (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d)) (+ (/ a c) (/ (/ d c) (/ c b)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 1e+270) {
tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = (a / c) + ((d / c) / (c / b));
}
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))) <= 1e+270) tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(a / c) + Float64(Float64(d / c) / Float64(c / b))); 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], 1e+270], N[(N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] / N[(c / b), $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 10^{+270}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{d}{c}}{\frac{c}{b}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1e270Initial program 78.8%
*-un-lft-identity78.8%
add-sqr-sqrt78.8%
times-frac78.7%
hypot-def78.7%
fma-def78.7%
hypot-def96.5%
Applied egg-rr96.5%
associate-*l/96.7%
*-un-lft-identity96.7%
Applied egg-rr96.7%
if 1e270 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 9.0%
Taylor expanded in c around inf 48.4%
*-commutative48.4%
unpow248.4%
times-frac59.8%
Simplified59.8%
Taylor expanded in d around 0 48.4%
unpow248.4%
associate-/r*50.9%
*-commutative50.9%
associate-*l/59.7%
associate-/l*59.8%
Simplified59.8%
Final simplification86.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ a c) (/ (* d (/ b c)) c))))
(if (<= c -8.5e+88)
t_0
(if (<= c -2.3e-90)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= c 3.05e+50) (* (/ 1.0 d) (+ b (/ a (/ d c)))) 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 <= -8.5e+88) {
tmp = t_0;
} else if (c <= -2.3e-90) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 3.05e+50) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} 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 <= (-8.5d+88)) then
tmp = t_0
else if (c <= (-2.3d-90)) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else if (c <= 3.05d+50) then
tmp = (1.0d0 / d) * (b + (a / (d / c)))
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 <= -8.5e+88) {
tmp = t_0;
} else if (c <= -2.3e-90) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 3.05e+50) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a / c) + ((d * (b / c)) / c) tmp = 0 if c <= -8.5e+88: tmp = t_0 elif c <= -2.3e-90: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif c <= 3.05e+50: tmp = (1.0 / d) * (b + (a / (d / c))) 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 <= -8.5e+88) tmp = t_0; elseif (c <= -2.3e-90) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 3.05e+50) tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c)))); 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 <= -8.5e+88) tmp = t_0; elseif (c <= -2.3e-90) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (c <= 3.05e+50) tmp = (1.0 / d) * (b + (a / (d / c))); 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, -8.5e+88], t$95$0, If[LessEqual[c, -2.3e-90], 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, 3.05e+50], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $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 -8.5 \cdot 10^{+88}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq -2.3 \cdot 10^{-90}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 3.05 \cdot 10^{+50}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if c < -8.5000000000000005e88 or 3.05000000000000013e50 < c Initial program 43.1%
Taylor expanded in c around inf 77.1%
*-commutative77.1%
unpow277.1%
times-frac84.7%
Simplified84.7%
associate-*l/86.4%
Applied egg-rr86.4%
if -8.5000000000000005e88 < c < -2.2999999999999998e-90Initial program 85.3%
if -2.2999999999999998e-90 < c < 3.05000000000000013e50Initial program 66.1%
*-un-lft-identity66.1%
add-sqr-sqrt66.1%
times-frac66.2%
hypot-def66.2%
fma-def66.2%
hypot-def81.3%
Applied egg-rr81.3%
Taylor expanded in c around 0 48.0%
associate-/l*48.1%
Simplified48.1%
Taylor expanded in c around 0 85.4%
Final simplification85.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -8.4e-48) (not (<= c 3.7e+49))) (+ (/ a c) (* (/ d c) (/ b c))) (* (/ 1.0 d) (+ b (/ a (/ d c))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -8.4e-48) || !(c <= 3.7e+49)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = (1.0 / d) * (b + (a / (d / c)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-8.4d-48)) .or. (.not. (c <= 3.7d+49))) then
tmp = (a / c) + ((d / c) * (b / c))
else
tmp = (1.0d0 / d) * (b + (a / (d / c)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -8.4e-48) || !(c <= 3.7e+49)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = (1.0 / d) * (b + (a / (d / c)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -8.4e-48) or not (c <= 3.7e+49): tmp = (a / c) + ((d / c) * (b / c)) else: tmp = (1.0 / d) * (b + (a / (d / c))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -8.4e-48) || !(c <= 3.7e+49)) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); else tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -8.4e-48) || ~((c <= 3.7e+49))) tmp = (a / c) + ((d / c) * (b / c)); else tmp = (1.0 / d) * (b + (a / (d / c))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -8.4e-48], N[Not[LessEqual[c, 3.7e+49]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.4 \cdot 10^{-48} \lor \neg \left(c \leq 3.7 \cdot 10^{+49}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\end{array}
\end{array}
if c < -8.39999999999999954e-48 or 3.70000000000000018e49 < c Initial program 51.0%
Taylor expanded in c around inf 75.7%
*-commutative75.7%
unpow275.7%
times-frac81.8%
Simplified81.8%
if -8.39999999999999954e-48 < c < 3.70000000000000018e49Initial program 67.6%
*-un-lft-identity67.6%
add-sqr-sqrt67.6%
times-frac67.6%
hypot-def67.6%
fma-def67.6%
hypot-def82.4%
Applied egg-rr82.4%
Taylor expanded in c around 0 46.8%
associate-/l*46.8%
Simplified46.8%
Taylor expanded in c around 0 84.7%
Final simplification83.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.16e-47) (not (<= c 8e+51))) (+ (/ a c) (/ (* d (/ b c)) c)) (* (/ 1.0 d) (+ b (/ a (/ d c))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.16e-47) || !(c <= 8e+51)) {
tmp = (a / c) + ((d * (b / c)) / c);
} else {
tmp = (1.0 / d) * (b + (a / (d / c)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-1.16d-47)) .or. (.not. (c <= 8d+51))) then
tmp = (a / c) + ((d * (b / c)) / c)
else
tmp = (1.0d0 / d) * (b + (a / (d / c)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.16e-47) || !(c <= 8e+51)) {
tmp = (a / c) + ((d * (b / c)) / c);
} else {
tmp = (1.0 / d) * (b + (a / (d / c)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.16e-47) or not (c <= 8e+51): tmp = (a / c) + ((d * (b / c)) / c) else: tmp = (1.0 / d) * (b + (a / (d / c))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.16e-47) || !(c <= 8e+51)) tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); else tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.16e-47) || ~((c <= 8e+51))) tmp = (a / c) + ((d * (b / c)) / c); else tmp = (1.0 / d) * (b + (a / (d / c))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.16e-47], N[Not[LessEqual[c, 8e+51]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.16 \cdot 10^{-47} \lor \neg \left(c \leq 8 \cdot 10^{+51}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\end{array}
\end{array}
if c < -1.1600000000000001e-47 or 8e51 < c Initial program 51.0%
Taylor expanded in c around inf 75.7%
*-commutative75.7%
unpow275.7%
times-frac81.8%
Simplified81.8%
associate-*l/83.1%
Applied egg-rr83.1%
if -1.1600000000000001e-47 < c < 8e51Initial program 67.6%
*-un-lft-identity67.6%
add-sqr-sqrt67.6%
times-frac67.6%
hypot-def67.6%
fma-def67.6%
hypot-def82.4%
Applied egg-rr82.4%
Taylor expanded in c around 0 46.8%
associate-/l*46.8%
Simplified46.8%
Taylor expanded in c around 0 84.7%
Final simplification83.9%
(FPCore (a b c d) :precision binary64 (if (<= c -5.2e-75) (/ a c) (if (<= c 1.25e+54) (* (/ 1.0 d) (+ b (/ a (/ d c)))) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.2e-75) {
tmp = a / c;
} else if (c <= 1.25e+54) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} 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 (c <= (-5.2d-75)) then
tmp = a / c
else if (c <= 1.25d+54) then
tmp = (1.0d0 / d) * (b + (a / (d / c)))
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 (c <= -5.2e-75) {
tmp = a / c;
} else if (c <= 1.25e+54) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -5.2e-75: tmp = a / c elif c <= 1.25e+54: tmp = (1.0 / d) * (b + (a / (d / c))) else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -5.2e-75) tmp = Float64(a / c); elseif (c <= 1.25e+54) tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c)))); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -5.2e-75) tmp = a / c; elseif (c <= 1.25e+54) tmp = (1.0 / d) * (b + (a / (d / c))); else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.2e-75], N[(a / c), $MachinePrecision], If[LessEqual[c, 1.25e+54], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.2 \cdot 10^{-75}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 1.25 \cdot 10^{+54}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -5.2e-75 or 1.25000000000000001e54 < c Initial program 51.8%
Taylor expanded in c around inf 70.6%
if -5.2e-75 < c < 1.25000000000000001e54Initial program 67.2%
*-un-lft-identity67.2%
add-sqr-sqrt67.2%
times-frac67.3%
hypot-def67.3%
fma-def67.3%
hypot-def81.9%
Applied egg-rr81.9%
Taylor expanded in c around 0 47.4%
associate-/l*47.4%
Simplified47.4%
Taylor expanded in c around 0 85.8%
Final simplification77.8%
(FPCore (a b c d) :precision binary64 (if (<= c -6.5e-53) (/ a c) (if (<= c 7.8e+48) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.5e-53) {
tmp = a / c;
} else if (c <= 7.8e+48) {
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 (c <= (-6.5d-53)) then
tmp = a / c
else if (c <= 7.8d+48) 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 (c <= -6.5e-53) {
tmp = a / c;
} else if (c <= 7.8e+48) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -6.5e-53: tmp = a / c elif c <= 7.8e+48: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -6.5e-53) tmp = Float64(a / c); elseif (c <= 7.8e+48) 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 (c <= -6.5e-53) tmp = a / c; elseif (c <= 7.8e+48) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -6.5e-53], N[(a / c), $MachinePrecision], If[LessEqual[c, 7.8e+48], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.5 \cdot 10^{-53}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 7.8 \cdot 10^{+48}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -6.4999999999999997e-53 or 7.8000000000000002e48 < c Initial program 51.0%
Taylor expanded in c around inf 71.2%
if -6.4999999999999997e-53 < c < 7.8000000000000002e48Initial program 67.6%
Taylor expanded in c around 0 72.5%
Final simplification71.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.2%
Taylor expanded in c around inf 42.4%
Final simplification42.4%
(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 2023283
(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))))