
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d)))))
(if (<= c -5e+206)
(+ (/ a c) (/ 1.0 (* (/ c b) (/ c d))))
(if (<= c -2.55e-64)
t_0
(if (<= c 4.5e-95)
(/ (+ b (* a (/ c d))) d)
(if (<= c 5.5e+119) t_0 (/ (+ a (* d (/ b c))) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
double tmp;
if (c <= -5e+206) {
tmp = (a / c) + (1.0 / ((c / b) * (c / d)));
} else if (c <= -2.55e-64) {
tmp = t_0;
} else if (c <= 4.5e-95) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 5.5e+119) {
tmp = t_0;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))) tmp = 0.0 if (c <= -5e+206) tmp = Float64(Float64(a / c) + Float64(1.0 / Float64(Float64(c / b) * Float64(c / d)))); elseif (c <= -2.55e-64) tmp = t_0; elseif (c <= 4.5e-95) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 5.5e+119) tmp = t_0; else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = 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]}, If[LessEqual[c, -5e+206], N[(N[(a / c), $MachinePrecision] + N[(1.0 / N[(N[(c / b), $MachinePrecision] * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -2.55e-64], t$95$0, If[LessEqual[c, 4.5e-95], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 5.5e+119], t$95$0, N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \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{if}\;c \leq -5 \cdot 10^{+206}:\\
\;\;\;\;\frac{a}{c} + \frac{1}{\frac{c}{b} \cdot \frac{c}{d}}\\
\mathbf{elif}\;c \leq -2.55 \cdot 10^{-64}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4.5 \cdot 10^{-95}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 5.5 \cdot 10^{+119}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -5.0000000000000002e206Initial program 43.8%
Taylor expanded in d around 0 88.3%
associate-/l*88.7%
Simplified88.7%
*-un-lft-identity88.7%
pow288.7%
times-frac91.7%
Applied egg-rr91.7%
associate-*r*92.3%
div-inv92.3%
clear-num92.4%
clear-num92.4%
frac-times92.4%
metadata-eval92.4%
Applied egg-rr92.4%
if -5.0000000000000002e206 < c < -2.54999999999999992e-64 or 4.5e-95 < c < 5.5000000000000003e119Initial program 68.4%
*-un-lft-identity68.4%
add-sqr-sqrt68.4%
times-frac68.5%
hypot-define68.5%
fma-define68.5%
hypot-define86.5%
Applied egg-rr86.5%
if -2.54999999999999992e-64 < c < 4.5e-95Initial program 66.4%
Taylor expanded in d around inf 93.7%
associate-/l*93.7%
Simplified93.7%
if 5.5000000000000003e119 < c Initial program 34.0%
Taylor expanded in c around inf 88.4%
*-commutative88.4%
associate-/l*94.5%
Applied egg-rr94.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ b (* a (/ c d))) d))
(t_1 (/ (+ (* b d) (* c a)) (+ (* c c) (* d d)))))
(if (<= c -7e+59)
(/ (+ a (* d (* b (/ 1.0 c)))) c)
(if (<= c -1.7e+27)
t_0
(if (<= c -3.5e-64)
t_1
(if (<= c 6.5e-79)
t_0
(if (<= c 1.45e+119) t_1 (/ (+ a (* d (/ b c))) c))))))))
double code(double a, double b, double c, double d) {
double t_0 = (b + (a * (c / d))) / d;
double t_1 = ((b * d) + (c * a)) / ((c * c) + (d * d));
double tmp;
if (c <= -7e+59) {
tmp = (a + (d * (b * (1.0 / c)))) / c;
} else if (c <= -1.7e+27) {
tmp = t_0;
} else if (c <= -3.5e-64) {
tmp = t_1;
} else if (c <= 6.5e-79) {
tmp = t_0;
} else if (c <= 1.45e+119) {
tmp = t_1;
} else {
tmp = (a + (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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (b + (a * (c / d))) / d
t_1 = ((b * d) + (c * a)) / ((c * c) + (d * d))
if (c <= (-7d+59)) then
tmp = (a + (d * (b * (1.0d0 / c)))) / c
else if (c <= (-1.7d+27)) then
tmp = t_0
else if (c <= (-3.5d-64)) then
tmp = t_1
else if (c <= 6.5d-79) then
tmp = t_0
else if (c <= 1.45d+119) then
tmp = t_1
else
tmp = (a + (d * (b / 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 t_1 = ((b * d) + (c * a)) / ((c * c) + (d * d));
double tmp;
if (c <= -7e+59) {
tmp = (a + (d * (b * (1.0 / c)))) / c;
} else if (c <= -1.7e+27) {
tmp = t_0;
} else if (c <= -3.5e-64) {
tmp = t_1;
} else if (c <= 6.5e-79) {
tmp = t_0;
} else if (c <= 1.45e+119) {
tmp = t_1;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b + (a * (c / d))) / d t_1 = ((b * d) + (c * a)) / ((c * c) + (d * d)) tmp = 0 if c <= -7e+59: tmp = (a + (d * (b * (1.0 / c)))) / c elif c <= -1.7e+27: tmp = t_0 elif c <= -3.5e-64: tmp = t_1 elif c <= 6.5e-79: tmp = t_0 elif c <= 1.45e+119: tmp = t_1 else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b + Float64(a * Float64(c / d))) / d) t_1 = Float64(Float64(Float64(b * d) + Float64(c * a)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (c <= -7e+59) tmp = Float64(Float64(a + Float64(d * Float64(b * Float64(1.0 / c)))) / c); elseif (c <= -1.7e+27) tmp = t_0; elseif (c <= -3.5e-64) tmp = t_1; elseif (c <= 6.5e-79) tmp = t_0; elseif (c <= 1.45e+119) tmp = t_1; else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b + (a * (c / d))) / d; t_1 = ((b * d) + (c * a)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -7e+59) tmp = (a + (d * (b * (1.0 / c)))) / c; elseif (c <= -1.7e+27) tmp = t_0; elseif (c <= -3.5e-64) tmp = t_1; elseif (c <= 6.5e-79) tmp = t_0; elseif (c <= 1.45e+119) tmp = t_1; else tmp = (a + (d * (b / 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]}, Block[{t$95$1 = N[(N[(N[(b * d), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -7e+59], N[(N[(a + N[(d * N[(b * N[(1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.7e+27], t$95$0, If[LessEqual[c, -3.5e-64], t$95$1, If[LessEqual[c, 6.5e-79], t$95$0, If[LessEqual[c, 1.45e+119], t$95$1, N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b + a \cdot \frac{c}{d}}{d}\\
t_1 := \frac{b \cdot d + c \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -7 \cdot 10^{+59}:\\
\;\;\;\;\frac{a + d \cdot \left(b \cdot \frac{1}{c}\right)}{c}\\
\mathbf{elif}\;c \leq -1.7 \cdot 10^{+27}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -3.5 \cdot 10^{-64}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq 6.5 \cdot 10^{-79}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.45 \cdot 10^{+119}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -7e59Initial program 56.4%
Taylor expanded in c around inf 82.0%
div-inv82.0%
*-commutative82.0%
associate-*l*85.7%
Applied egg-rr85.7%
if -7e59 < c < -1.7e27 or -3.5000000000000003e-64 < c < 6.5000000000000003e-79Initial program 63.6%
Taylor expanded in d around inf 93.3%
associate-/l*93.3%
Simplified93.3%
if -1.7e27 < c < -3.5000000000000003e-64 or 6.5000000000000003e-79 < c < 1.45000000000000004e119Initial program 73.8%
if 1.45000000000000004e119 < c Initial program 34.0%
Taylor expanded in c around inf 88.4%
*-commutative88.4%
associate-/l*94.5%
Applied egg-rr94.5%
Final simplification87.5%
(FPCore (a b c d)
:precision binary64
(if (or (<= d -53000000.0)
(and (not (<= d -1.65e-9))
(or (<= d -1.3e-41) (not (<= d 1.15e+149)))))
(/ b d)
(/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -53000000.0) || (!(d <= -1.65e-9) && ((d <= -1.3e-41) || !(d <= 1.15e+149)))) {
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 <= (-53000000.0d0)) .or. (.not. (d <= (-1.65d-9))) .and. (d <= (-1.3d-41)) .or. (.not. (d <= 1.15d+149))) 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 <= -53000000.0) || (!(d <= -1.65e-9) && ((d <= -1.3e-41) || !(d <= 1.15e+149)))) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -53000000.0) or (not (d <= -1.65e-9) and ((d <= -1.3e-41) or not (d <= 1.15e+149))): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -53000000.0) || (!(d <= -1.65e-9) && ((d <= -1.3e-41) || !(d <= 1.15e+149)))) 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 <= -53000000.0) || (~((d <= -1.65e-9)) && ((d <= -1.3e-41) || ~((d <= 1.15e+149))))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -53000000.0], And[N[Not[LessEqual[d, -1.65e-9]], $MachinePrecision], Or[LessEqual[d, -1.3e-41], N[Not[LessEqual[d, 1.15e+149]], $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 -53000000 \lor \neg \left(d \leq -1.65 \cdot 10^{-9}\right) \land \left(d \leq -1.3 \cdot 10^{-41} \lor \neg \left(d \leq 1.15 \cdot 10^{+149}\right)\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -5.3e7 or -1.65000000000000009e-9 < d < -1.3e-41 or 1.1499999999999999e149 < d Initial program 48.1%
Taylor expanded in c around 0 76.3%
if -5.3e7 < d < -1.65000000000000009e-9 or -1.3e-41 < d < 1.1499999999999999e149Initial program 67.4%
Taylor expanded in c around inf 78.2%
associate-/l*79.7%
Simplified79.7%
Final simplification78.2%
(FPCore (a b c d)
:precision binary64
(if (or (<= c -2.45e+61)
(and (not (<= c -1.4e-45))
(or (<= c -1.65e-64) (not (<= c 1.45e+66)))))
(/ a c)
(/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.45e+61) || (!(c <= -1.4e-45) && ((c <= -1.65e-64) || !(c <= 1.45e+66)))) {
tmp = a / 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 ((c <= (-2.45d+61)) .or. (.not. (c <= (-1.4d-45))) .and. (c <= (-1.65d-64)) .or. (.not. (c <= 1.45d+66))) then
tmp = a / 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 ((c <= -2.45e+61) || (!(c <= -1.4e-45) && ((c <= -1.65e-64) || !(c <= 1.45e+66)))) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.45e+61) or (not (c <= -1.4e-45) and ((c <= -1.65e-64) or not (c <= 1.45e+66))): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.45e+61) || (!(c <= -1.4e-45) && ((c <= -1.65e-64) || !(c <= 1.45e+66)))) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.45e+61) || (~((c <= -1.4e-45)) && ((c <= -1.65e-64) || ~((c <= 1.45e+66))))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.45e+61], And[N[Not[LessEqual[c, -1.4e-45]], $MachinePrecision], Or[LessEqual[c, -1.65e-64], N[Not[LessEqual[c, 1.45e+66]], $MachinePrecision]]]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.45 \cdot 10^{+61} \lor \neg \left(c \leq -1.4 \cdot 10^{-45}\right) \land \left(c \leq -1.65 \cdot 10^{-64} \lor \neg \left(c \leq 1.45 \cdot 10^{+66}\right)\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -2.45000000000000013e61 or -1.4000000000000001e-45 < c < -1.65e-64 or 1.44999999999999993e66 < c Initial program 52.2%
Taylor expanded in c around inf 80.2%
if -2.45000000000000013e61 < c < -1.4000000000000001e-45 or -1.65e-64 < c < 1.44999999999999993e66Initial program 64.7%
Taylor expanded in c around 0 67.0%
Final simplification73.1%
(FPCore (a b c d) :precision binary64 (if (<= c -1.65e+69) (/ (+ a (* d (* b (/ 1.0 c)))) c) (if (<= c 1050000.0) (/ (+ b (* a (/ c d))) d) (/ (+ a (* d (/ b c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.65e+69) {
tmp = (a + (d * (b * (1.0 / c)))) / c;
} else if (c <= 1050000.0) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (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 (c <= (-1.65d+69)) then
tmp = (a + (d * (b * (1.0d0 / c)))) / c
else if (c <= 1050000.0d0) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a + (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 (c <= -1.65e+69) {
tmp = (a + (d * (b * (1.0 / c)))) / c;
} else if (c <= 1050000.0) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.65e+69: tmp = (a + (d * (b * (1.0 / c)))) / c elif c <= 1050000.0: tmp = (b + (a * (c / d))) / d else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.65e+69) tmp = Float64(Float64(a + Float64(d * Float64(b * Float64(1.0 / c)))) / c); elseif (c <= 1050000.0) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.65e+69) tmp = (a + (d * (b * (1.0 / c)))) / c; elseif (c <= 1050000.0) tmp = (b + (a * (c / d))) / d; else tmp = (a + (d * (b / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.65e+69], N[(N[(a + N[(d * N[(b * N[(1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1050000.0], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.65 \cdot 10^{+69}:\\
\;\;\;\;\frac{a + d \cdot \left(b \cdot \frac{1}{c}\right)}{c}\\
\mathbf{elif}\;c \leq 1050000:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -1.6499999999999999e69Initial program 56.4%
Taylor expanded in c around inf 82.0%
div-inv82.0%
*-commutative82.0%
associate-*l*85.7%
Applied egg-rr85.7%
if -1.6499999999999999e69 < c < 1.05e6Initial program 66.6%
Taylor expanded in d around inf 84.9%
associate-/l*84.9%
Simplified84.9%
if 1.05e6 < c Initial program 47.5%
Taylor expanded in c around inf 77.5%
*-commutative77.5%
associate-/l*81.5%
Applied egg-rr81.5%
(FPCore (a b c d) :precision binary64 (if (<= c -1.12e+66) (/ (+ a (/ d (/ c b))) c) (if (<= c 5000.0) (/ (+ b (* a (/ c d))) d) (/ (+ a (* d (/ b c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.12e+66) {
tmp = (a + (d / (c / b))) / c;
} else if (c <= 5000.0) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (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 (c <= (-1.12d+66)) then
tmp = (a + (d / (c / b))) / c
else if (c <= 5000.0d0) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a + (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 (c <= -1.12e+66) {
tmp = (a + (d / (c / b))) / c;
} else if (c <= 5000.0) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.12e+66: tmp = (a + (d / (c / b))) / c elif c <= 5000.0: tmp = (b + (a * (c / d))) / d else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.12e+66) tmp = Float64(Float64(a + Float64(d / Float64(c / b))) / c); elseif (c <= 5000.0) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.12e+66) tmp = (a + (d / (c / b))) / c; elseif (c <= 5000.0) tmp = (b + (a * (c / d))) / d; else tmp = (a + (d * (b / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.12e+66], N[(N[(a + N[(d / N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 5000.0], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.12 \cdot 10^{+66}:\\
\;\;\;\;\frac{a + \frac{d}{\frac{c}{b}}}{c}\\
\mathbf{elif}\;c \leq 5000:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -1.12e66Initial program 56.4%
Taylor expanded in c around inf 82.0%
*-commutative82.0%
associate-/l*85.7%
Applied egg-rr85.7%
clear-num85.7%
un-div-inv85.7%
Applied egg-rr85.7%
if -1.12e66 < c < 5e3Initial program 66.6%
Taylor expanded in d around inf 84.9%
associate-/l*84.9%
Simplified84.9%
if 5e3 < c Initial program 47.5%
Taylor expanded in c around inf 77.5%
*-commutative77.5%
associate-/l*81.5%
Applied egg-rr81.5%
(FPCore (a b c d) :precision binary64 (if (<= d -2.5e+194) (/ a d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.5e+194) {
tmp = a / d;
} else {
tmp = a / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-2.5d+194)) then
tmp = a / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.5e+194) {
tmp = a / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -2.5e+194: tmp = a / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -2.5e+194) tmp = Float64(a / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -2.5e+194) tmp = a / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.5e+194], N[(a / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.5 \cdot 10^{+194}:\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -2.49999999999999994e194Initial program 38.6%
*-un-lft-identity38.6%
add-sqr-sqrt38.6%
times-frac38.6%
hypot-define38.6%
fma-define38.6%
hypot-define64.2%
Applied egg-rr64.2%
Taylor expanded in c around inf 30.7%
Taylor expanded in c around 0 30.6%
if -2.49999999999999994e194 < d Initial program 61.7%
Taylor expanded in c around inf 50.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 59.0%
Taylor expanded in c around inf 46.3%
(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 2024085
(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))))