
(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
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (+ (/ b d) (* (/ c d) (/ a d)))))
(if (<= d -1.5e+115)
t_1
(if (<= d -6.2e-123)
t_0
(if (<= d 3.7e-10)
(* (+ a (/ b (/ c d))) (/ (- -1.0) c))
(if (<= d 2.5e+117) t_0 (if (<= d 2.7e+124) (/ a c) t_1)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (b / d) + ((c / d) * (a / d));
double tmp;
if (d <= -1.5e+115) {
tmp = t_1;
} else if (d <= -6.2e-123) {
tmp = t_0;
} else if (d <= 3.7e-10) {
tmp = (a + (b / (c / d))) * (-(-1.0) / c);
} else if (d <= 2.5e+117) {
tmp = t_0;
} else if (d <= 2.7e+124) {
tmp = a / c;
} else {
tmp = t_1;
}
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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
t_1 = (b / d) + ((c / d) * (a / d))
if (d <= (-1.5d+115)) then
tmp = t_1
else if (d <= (-6.2d-123)) then
tmp = t_0
else if (d <= 3.7d-10) then
tmp = (a + (b / (c / d))) * (-(-1.0d0) / c)
else if (d <= 2.5d+117) then
tmp = t_0
else if (d <= 2.7d+124) then
tmp = a / c
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (b / d) + ((c / d) * (a / d));
double tmp;
if (d <= -1.5e+115) {
tmp = t_1;
} else if (d <= -6.2e-123) {
tmp = t_0;
} else if (d <= 3.7e-10) {
tmp = (a + (b / (c / d))) * (-(-1.0) / c);
} else if (d <= 2.5e+117) {
tmp = t_0;
} else if (d <= 2.7e+124) {
tmp = a / c;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = (b / d) + ((c / d) * (a / d)) tmp = 0 if d <= -1.5e+115: tmp = t_1 elif d <= -6.2e-123: tmp = t_0 elif d <= 3.7e-10: tmp = (a + (b / (c / d))) * (-(-1.0) / c) elif d <= 2.5e+117: tmp = t_0 elif d <= 2.7e+124: tmp = a / c else: tmp = t_1 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))) t_1 = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))) tmp = 0.0 if (d <= -1.5e+115) tmp = t_1; elseif (d <= -6.2e-123) tmp = t_0; elseif (d <= 3.7e-10) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) * Float64(Float64(-(-1.0)) / c)); elseif (d <= 2.5e+117) tmp = t_0; elseif (d <= 2.7e+124) tmp = Float64(a / c); else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); t_1 = (b / d) + ((c / d) * (a / d)); tmp = 0.0; if (d <= -1.5e+115) tmp = t_1; elseif (d <= -6.2e-123) tmp = t_0; elseif (d <= 3.7e-10) tmp = (a + (b / (c / d))) * (-(-1.0) / c); elseif (d <= 2.5e+117) tmp = t_0; elseif (d <= 2.7e+124) tmp = a / c; else tmp = t_1; 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]}, Block[{t$95$1 = N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.5e+115], t$95$1, If[LessEqual[d, -6.2e-123], t$95$0, If[LessEqual[d, 3.7e-10], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[((--1.0) / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.5e+117], t$95$0, If[LessEqual[d, 2.7e+124], N[(a / c), $MachinePrecision], t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{if}\;d \leq -1.5 \cdot 10^{+115}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d \leq -6.2 \cdot 10^{-123}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 3.7 \cdot 10^{-10}:\\
\;\;\;\;\left(a + \frac{b}{\frac{c}{d}}\right) \cdot \frac{--1}{c}\\
\mathbf{elif}\;d \leq 2.5 \cdot 10^{+117}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 2.7 \cdot 10^{+124}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if d < -1.5e115 or 2.69999999999999978e124 < d Initial program 32.3%
*-un-lft-identity32.3%
add-sqr-sqrt32.3%
times-frac32.4%
hypot-def32.4%
fma-def32.4%
hypot-def50.6%
Applied egg-rr50.6%
Taylor expanded in c around 0 80.6%
*-commutative80.6%
unpow280.6%
times-frac90.1%
Applied egg-rr90.1%
if -1.5e115 < d < -6.19999999999999996e-123 or 3.70000000000000015e-10 < d < 2.49999999999999992e117Initial program 82.9%
if -6.19999999999999996e-123 < d < 3.70000000000000015e-10Initial program 70.8%
*-un-lft-identity70.8%
add-sqr-sqrt70.8%
times-frac70.8%
hypot-def70.8%
fma-def70.8%
hypot-def84.3%
Applied egg-rr84.3%
Taylor expanded in c around -inf 42.6%
neg-mul-142.6%
+-commutative42.6%
unsub-neg42.6%
mul-1-neg42.6%
associate-/l*42.6%
distribute-neg-frac42.6%
Simplified42.6%
Taylor expanded in c around -inf 89.9%
if 2.49999999999999992e117 < d < 2.69999999999999978e124Initial program 21.9%
Taylor expanded in c around inf 80.6%
Final simplification87.7%
(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))) (+ (/ b d) (* (/ c d) (/ a d)))))
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 = (b / d) + ((c / d) * (a / d));
}
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(b / d) + Float64(Float64(c / d) * Float64(a / d))); 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[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $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{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 78.8%
*-un-lft-identity78.8%
add-sqr-sqrt78.8%
times-frac78.8%
hypot-def78.8%
fma-def78.8%
hypot-def95.3%
Applied egg-rr95.3%
if +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 0.0%
*-un-lft-identity0.0%
add-sqr-sqrt0.0%
times-frac0.0%
hypot-def0.0%
fma-def0.0%
hypot-def2.6%
Applied egg-rr2.6%
Taylor expanded in c around 0 43.7%
*-commutative43.7%
unpow243.7%
times-frac55.6%
Applied egg-rr55.6%
Final simplification87.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -2.6e+80)
(* (+ a (* b (/ d c))) (/ -1.0 (hypot c d)))
(if (<= c -8.2e-80)
t_0
(if (<= c 4.2e-109)
(* (/ 1.0 d) (+ b (/ a (/ d c))))
(if (<= c 5.1e+91)
t_0
(* (/ 1.0 (hypot c d)) (+ a (/ b (/ c d))))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -2.6e+80) {
tmp = (a + (b * (d / c))) * (-1.0 / hypot(c, d));
} else if (c <= -8.2e-80) {
tmp = t_0;
} else if (c <= 4.2e-109) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (c <= 5.1e+91) {
tmp = t_0;
} else {
tmp = (1.0 / hypot(c, d)) * (a + (b / (c / d)));
}
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 (c <= -2.6e+80) {
tmp = (a + (b * (d / c))) * (-1.0 / Math.hypot(c, d));
} else if (c <= -8.2e-80) {
tmp = t_0;
} else if (c <= 4.2e-109) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (c <= 5.1e+91) {
tmp = t_0;
} else {
tmp = (1.0 / Math.hypot(c, d)) * (a + (b / (c / d)));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -2.6e+80: tmp = (a + (b * (d / c))) * (-1.0 / math.hypot(c, d)) elif c <= -8.2e-80: tmp = t_0 elif c <= 4.2e-109: tmp = (1.0 / d) * (b + (a / (d / c))) elif c <= 5.1e+91: tmp = t_0 else: tmp = (1.0 / math.hypot(c, d)) * (a + (b / (c / d))) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (c <= -2.6e+80) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) * Float64(-1.0 / hypot(c, d))); elseif (c <= -8.2e-80) tmp = t_0; elseif (c <= 4.2e-109) tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c)))); elseif (c <= 5.1e+91) tmp = t_0; else tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(a + Float64(b / Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -2.6e+80) tmp = (a + (b * (d / c))) * (-1.0 / hypot(c, d)); elseif (c <= -8.2e-80) tmp = t_0; elseif (c <= 4.2e-109) tmp = (1.0 / d) * (b + (a / (d / c))); elseif (c <= 5.1e+91) tmp = t_0; else tmp = (1.0 / hypot(c, d)) * (a + (b / (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.6e+80], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -8.2e-80], t$95$0, If[LessEqual[c, 4.2e-109], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 5.1e+91], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $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}\;c \leq -2.6 \cdot 10^{+80}:\\
\;\;\;\;\left(a + b \cdot \frac{d}{c}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -8.2 \cdot 10^{-80}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 4.2 \cdot 10^{-109}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\mathbf{elif}\;c \leq 5.1 \cdot 10^{+91}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\
\end{array}
\end{array}
if c < -2.59999999999999982e80Initial program 45.1%
*-un-lft-identity45.1%
add-sqr-sqrt45.1%
times-frac45.0%
hypot-def45.0%
fma-def45.0%
hypot-def68.0%
Applied egg-rr68.0%
Taylor expanded in c around -inf 82.8%
neg-mul-182.8%
+-commutative82.8%
unsub-neg82.8%
mul-1-neg82.8%
associate-/l*89.3%
distribute-neg-frac89.3%
Simplified89.3%
Taylor expanded in b around 0 82.8%
associate-*r/89.3%
neg-mul-189.3%
distribute-rgt-neg-in89.3%
Simplified89.3%
if -2.59999999999999982e80 < c < -8.1999999999999999e-80 or 4.19999999999999992e-109 < c < 5.10000000000000013e91Initial program 76.9%
if -8.1999999999999999e-80 < c < 4.19999999999999992e-109Initial program 69.1%
*-un-lft-identity69.1%
add-sqr-sqrt69.1%
times-frac69.1%
hypot-def69.1%
fma-def69.1%
hypot-def82.1%
Applied egg-rr82.1%
Taylor expanded in c around 0 83.3%
*-commutative83.3%
unpow283.3%
times-frac85.8%
Applied egg-rr85.8%
+-commutative85.8%
frac-times83.3%
*-un-lft-identity83.3%
frac-times87.7%
*-commutative87.7%
div-inv87.6%
distribute-rgt-out87.7%
*-commutative87.7%
associate-/l*89.8%
Applied egg-rr89.8%
if 5.10000000000000013e91 < c Initial program 38.4%
*-un-lft-identity38.4%
add-sqr-sqrt38.4%
times-frac38.4%
hypot-def38.4%
fma-def38.4%
hypot-def54.6%
Applied egg-rr54.6%
Taylor expanded in c around inf 73.9%
associate-/l*88.4%
Simplified88.4%
Final simplification85.7%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.9e+30) (not (<= c 68000.0))) (* (+ a (/ b (/ c d))) (/ (- -1.0) c)) (* (/ 1.0 d) (+ b (/ a (/ d c))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.9e+30) || !(c <= 68000.0)) {
tmp = (a + (b / (c / d))) * (-(-1.0) / 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 <= (-2.9d+30)) .or. (.not. (c <= 68000.0d0))) then
tmp = (a + (b / (c / d))) * (-(-1.0d0) / 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 <= -2.9e+30) || !(c <= 68000.0)) {
tmp = (a + (b / (c / d))) * (-(-1.0) / c);
} else {
tmp = (1.0 / d) * (b + (a / (d / c)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.9e+30) or not (c <= 68000.0): tmp = (a + (b / (c / d))) * (-(-1.0) / c) else: tmp = (1.0 / d) * (b + (a / (d / c))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.9e+30) || !(c <= 68000.0)) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) * Float64(Float64(-(-1.0)) / 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 <= -2.9e+30) || ~((c <= 68000.0))) tmp = (a + (b / (c / d))) * (-(-1.0) / c); else tmp = (1.0 / d) * (b + (a / (d / c))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.9e+30], N[Not[LessEqual[c, 68000.0]], $MachinePrecision]], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[((--1.0) / 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 -2.9 \cdot 10^{+30} \lor \neg \left(c \leq 68000\right):\\
\;\;\;\;\left(a + \frac{b}{\frac{c}{d}}\right) \cdot \frac{--1}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\end{array}
\end{array}
if c < -2.8999999999999998e30 or 68000 < c Initial program 50.9%
*-un-lft-identity50.9%
add-sqr-sqrt50.9%
times-frac50.9%
hypot-def50.9%
fma-def50.9%
hypot-def67.0%
Applied egg-rr67.0%
Taylor expanded in c around -inf 48.2%
neg-mul-148.2%
+-commutative48.2%
unsub-neg48.2%
mul-1-neg48.2%
associate-/l*50.9%
distribute-neg-frac50.9%
Simplified50.9%
Taylor expanded in c around -inf 84.6%
if -2.8999999999999998e30 < c < 68000Initial program 70.3%
*-un-lft-identity70.3%
add-sqr-sqrt70.3%
times-frac70.3%
hypot-def70.3%
fma-def70.3%
hypot-def82.1%
Applied egg-rr82.1%
Taylor expanded in c around 0 72.4%
*-commutative72.4%
unpow272.4%
times-frac74.6%
Applied egg-rr74.6%
+-commutative74.6%
frac-times72.4%
*-un-lft-identity72.4%
frac-times75.8%
*-commutative75.8%
div-inv75.6%
distribute-rgt-out75.7%
*-commutative75.7%
associate-/l*77.0%
Applied egg-rr77.0%
Final simplification80.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3.8e+44) (not (<= c 72.0))) (/ a c) (* (/ 1.0 d) (+ b (/ a (/ d c))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.8e+44) || !(c <= 72.0)) {
tmp = a / 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 <= (-3.8d+44)) .or. (.not. (c <= 72.0d0))) then
tmp = a / 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 <= -3.8e+44) || !(c <= 72.0)) {
tmp = a / c;
} else {
tmp = (1.0 / d) * (b + (a / (d / c)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3.8e+44) or not (c <= 72.0): tmp = a / c else: tmp = (1.0 / d) * (b + (a / (d / c))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.8e+44) || !(c <= 72.0)) tmp = Float64(a / 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 <= -3.8e+44) || ~((c <= 72.0))) tmp = a / c; else tmp = (1.0 / d) * (b + (a / (d / c))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.8e+44], N[Not[LessEqual[c, 72.0]], $MachinePrecision]], N[(a / c), $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 -3.8 \cdot 10^{+44} \lor \neg \left(c \leq 72\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\end{array}
\end{array}
if c < -3.8000000000000002e44 or 72 < c Initial program 51.4%
Taylor expanded in c around inf 70.5%
if -3.8000000000000002e44 < c < 72Initial program 70.1%
*-un-lft-identity70.1%
add-sqr-sqrt70.1%
times-frac70.1%
hypot-def70.1%
fma-def70.1%
hypot-def82.0%
Applied egg-rr82.0%
Taylor expanded in c around 0 72.3%
*-commutative72.3%
unpow272.3%
times-frac74.5%
Applied egg-rr74.5%
+-commutative74.5%
frac-times72.3%
*-un-lft-identity72.3%
frac-times75.6%
*-commutative75.6%
div-inv75.5%
distribute-rgt-out75.6%
*-commutative75.6%
associate-/l*76.9%
Applied egg-rr76.9%
Final simplification74.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4e+45) (not (<= c 2.2e-73))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4e+45) || !(c <= 2.2e-73)) {
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 <= (-4d+45)) .or. (.not. (c <= 2.2d-73))) 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 <= -4e+45) || !(c <= 2.2e-73)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4e+45) or not (c <= 2.2e-73): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -4e+45) || !(c <= 2.2e-73)) 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 <= -4e+45) || ~((c <= 2.2e-73))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4e+45], N[Not[LessEqual[c, 2.2e-73]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4 \cdot 10^{+45} \lor \neg \left(c \leq 2.2 \cdot 10^{-73}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -3.9999999999999997e45 or 2.2e-73 < c Initial program 54.4%
Taylor expanded in c around inf 67.0%
if -3.9999999999999997e45 < c < 2.2e-73Initial program 70.2%
Taylor expanded in c around 0 66.6%
Final simplification66.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 62.2%
Taylor expanded in c around inf 42.3%
Final simplification42.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 2023331
(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))))