
(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 (/ 1.0 (hypot c d))))
(if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 1e+295)
(* t_0 (/ (fma a c (* b d)) (hypot c d)))
(* t_0 (* b (/ (fma c (/ a b) d) (hypot c d)))))))
double code(double a, double b, double c, double d) {
double t_0 = 1.0 / hypot(c, d);
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 1e+295) {
tmp = t_0 * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = t_0 * (b * (fma(c, (a / b), d) / hypot(c, d)));
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(1.0 / hypot(c, d)) tmp = 0.0 if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= 1e+295) tmp = Float64(t_0 * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(t_0 * Float64(b * Float64(fma(c, Float64(a / b), d) / hypot(c, d)))); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, 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+295], N[(t$95$0 * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(b * N[(N[(c * N[(a / b), $MachinePrecision] + d), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 10^{+295}:\\
\;\;\;\;t\_0 \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(b \cdot \frac{\mathsf{fma}\left(c, \frac{a}{b}, d\right)}{\mathsf{hypot}\left(c, d\right)}\right)\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 9.9999999999999998e294Initial program 83.1%
*-un-lft-identity83.1%
add-sqr-sqrt83.1%
times-frac83.1%
hypot-define83.1%
fma-define83.1%
hypot-define96.4%
Applied egg-rr96.4%
if 9.9999999999999998e294 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 7.4%
Taylor expanded in b around inf 7.4%
*-commutative7.4%
Simplified7.4%
*-un-lft-identity7.4%
add-sqr-sqrt7.4%
hypot-undefine7.4%
hypot-undefine7.4%
times-frac16.2%
+-commutative16.2%
associate-/l*13.4%
fma-define13.4%
Applied egg-rr13.4%
associate-/l*68.6%
Simplified68.6%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 1e+295) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (* (/ (fma c (/ a b) d) (hypot c d)) (/ b (hypot c d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 1e+295) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (fma(c, (a / b), d) / hypot(c, d)) * (b / hypot(c, 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))) <= 1e+295) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(fma(c, Float64(a / b), d) / hypot(c, d)) * Float64(b / hypot(c, 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], 1e+295], 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[(N[(c * N[(a / b), $MachinePrecision] + d), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $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^{+295}:\\
\;\;\;\;\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{\mathsf{fma}\left(c, \frac{a}{b}, d\right)}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 9.9999999999999998e294Initial program 83.1%
*-un-lft-identity83.1%
add-sqr-sqrt83.1%
times-frac83.1%
hypot-define83.1%
fma-define83.1%
hypot-define96.4%
Applied egg-rr96.4%
if 9.9999999999999998e294 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 7.4%
Taylor expanded in b around inf 7.4%
*-commutative7.4%
Simplified7.4%
*-commutative7.4%
add-sqr-sqrt7.4%
hypot-undefine7.4%
hypot-undefine7.4%
times-frac55.1%
+-commutative55.1%
associate-/l*68.4%
fma-define68.4%
Applied egg-rr68.4%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 1e+307) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 1e+307) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (b + (a * (c / d))) / 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))) <= 1e+307) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / 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], 1e+307], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 10^{+307}:\\
\;\;\;\;\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 + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 9.99999999999999986e306Initial program 83.2%
*-un-lft-identity83.2%
add-sqr-sqrt83.2%
times-frac83.1%
hypot-define83.2%
fma-define83.2%
hypot-define96.4%
Applied egg-rr96.4%
if 9.99999999999999986e306 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 5.9%
Taylor expanded in d around inf 48.9%
associate-/l*58.4%
Simplified58.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -1.5e+101)
(* (+ a (* b (/ d c))) (/ -1.0 (hypot c d)))
(if (<= c -3e-73)
t_0
(if (<= c 1.7e-78)
(/ (+ b (* c (/ a d))) d)
(if (<= c 4.7e+45) t_0 (/ (+ a (/ b (/ c d))) 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 (c <= -1.5e+101) {
tmp = (a + (b * (d / c))) * (-1.0 / hypot(c, d));
} else if (c <= -3e-73) {
tmp = t_0;
} else if (c <= 1.7e-78) {
tmp = (b + (c * (a / d))) / d;
} else if (c <= 4.7e+45) {
tmp = t_0;
} else {
tmp = (a + (b / (c / d))) / 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 (c <= -1.5e+101) {
tmp = (a + (b * (d / c))) * (-1.0 / Math.hypot(c, d));
} else if (c <= -3e-73) {
tmp = t_0;
} else if (c <= 1.7e-78) {
tmp = (b + (c * (a / d))) / d;
} else if (c <= 4.7e+45) {
tmp = t_0;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -1.5e+101: tmp = (a + (b * (d / c))) * (-1.0 / math.hypot(c, d)) elif c <= -3e-73: tmp = t_0 elif c <= 1.7e-78: tmp = (b + (c * (a / d))) / d elif c <= 4.7e+45: tmp = t_0 else: tmp = (a + (b / (c / d))) / 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 (c <= -1.5e+101) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) * Float64(-1.0 / hypot(c, d))); elseif (c <= -3e-73) tmp = t_0; elseif (c <= 1.7e-78) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); elseif (c <= 4.7e+45) tmp = t_0; else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / 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 (c <= -1.5e+101) tmp = (a + (b * (d / c))) * (-1.0 / hypot(c, d)); elseif (c <= -3e-73) tmp = t_0; elseif (c <= 1.7e-78) tmp = (b + (c * (a / d))) / d; elseif (c <= 4.7e+45) tmp = t_0; else tmp = (a + (b / (c / d))) / 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[c, -1.5e+101], 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, -3e-73], t$95$0, If[LessEqual[c, 1.7e-78], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.7e+45], t$95$0, N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $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 -1.5 \cdot 10^{+101}:\\
\;\;\;\;\left(a + b \cdot \frac{d}{c}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -3 \cdot 10^{-73}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.7 \cdot 10^{-78}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{elif}\;c \leq 4.7 \cdot 10^{+45}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -1.49999999999999997e101Initial program 30.7%
*-un-lft-identity30.7%
add-sqr-sqrt30.7%
times-frac30.7%
hypot-define30.7%
fma-define30.7%
hypot-define57.5%
Applied egg-rr57.5%
Taylor expanded in c around -inf 77.8%
distribute-lft-out77.8%
associate-/l*85.2%
Simplified85.2%
if -1.49999999999999997e101 < c < -3e-73 or 1.70000000000000006e-78 < c < 4.70000000000000002e45Initial program 90.1%
if -3e-73 < c < 1.70000000000000006e-78Initial program 71.1%
Taylor expanded in d around inf 91.6%
associate-/l*92.3%
Simplified92.3%
clear-num92.3%
un-div-inv92.3%
Applied egg-rr92.3%
associate-/r/93.1%
Simplified93.1%
if 4.70000000000000002e45 < c Initial program 48.4%
Taylor expanded in c around inf 81.9%
associate-/l*85.4%
Simplified85.4%
clear-num85.4%
un-div-inv85.5%
Applied egg-rr85.5%
Final simplification89.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -1.6e+100)
(/ (+ a (* b (/ d c))) c)
(if (<= c -4.8e-73)
t_0
(if (<= c 3.2e-81)
(/ (+ b (* c (/ a d))) d)
(if (<= c 4.7e+45) t_0 (/ (+ a (/ b (/ c d))) 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 (c <= -1.6e+100) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -4.8e-73) {
tmp = t_0;
} else if (c <= 3.2e-81) {
tmp = (b + (c * (a / d))) / d;
} else if (c <= 4.7e+45) {
tmp = t_0;
} else {
tmp = (a + (b / (c / 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) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (c <= (-1.6d+100)) then
tmp = (a + (b * (d / c))) / c
else if (c <= (-4.8d-73)) then
tmp = t_0
else if (c <= 3.2d-81) then
tmp = (b + (c * (a / d))) / d
else if (c <= 4.7d+45) then
tmp = t_0
else
tmp = (a + (b / (c / d))) / c
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 tmp;
if (c <= -1.6e+100) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -4.8e-73) {
tmp = t_0;
} else if (c <= 3.2e-81) {
tmp = (b + (c * (a / d))) / d;
} else if (c <= 4.7e+45) {
tmp = t_0;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -1.6e+100: tmp = (a + (b * (d / c))) / c elif c <= -4.8e-73: tmp = t_0 elif c <= 3.2e-81: tmp = (b + (c * (a / d))) / d elif c <= 4.7e+45: tmp = t_0 else: tmp = (a + (b / (c / d))) / 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 (c <= -1.6e+100) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= -4.8e-73) tmp = t_0; elseif (c <= 3.2e-81) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); elseif (c <= 4.7e+45) tmp = t_0; else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / 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 (c <= -1.6e+100) tmp = (a + (b * (d / c))) / c; elseif (c <= -4.8e-73) tmp = t_0; elseif (c <= 3.2e-81) tmp = (b + (c * (a / d))) / d; elseif (c <= 4.7e+45) tmp = t_0; else tmp = (a + (b / (c / d))) / 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[c, -1.6e+100], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -4.8e-73], t$95$0, If[LessEqual[c, 3.2e-81], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.7e+45], t$95$0, N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $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 -1.6 \cdot 10^{+100}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -4.8 \cdot 10^{-73}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 3.2 \cdot 10^{-81}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{elif}\;c \leq 4.7 \cdot 10^{+45}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -1.5999999999999999e100Initial program 32.4%
Taylor expanded in c around inf 76.1%
associate-/l*83.3%
Simplified83.3%
if -1.5999999999999999e100 < c < -4.80000000000000011e-73 or 3.2e-81 < c < 4.70000000000000002e45Initial program 89.9%
if -4.80000000000000011e-73 < c < 3.2e-81Initial program 71.1%
Taylor expanded in d around inf 91.6%
associate-/l*92.3%
Simplified92.3%
clear-num92.3%
un-div-inv92.3%
Applied egg-rr92.3%
associate-/r/93.1%
Simplified93.1%
if 4.70000000000000002e45 < c Initial program 48.4%
Taylor expanded in c around inf 81.9%
associate-/l*85.4%
Simplified85.4%
clear-num85.4%
un-div-inv85.5%
Applied egg-rr85.5%
Final simplification89.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3e-54) (not (<= c 3.8e-57))) (/ (+ a (* b (/ d c))) c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3e-54) || !(c <= 3.8e-57)) {
tmp = (a + (b * (d / c))) / 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 <= (-3d-54)) .or. (.not. (c <= 3.8d-57))) then
tmp = (a + (b * (d / c))) / 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 <= -3e-54) || !(c <= 3.8e-57)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3e-54) or not (c <= 3.8e-57): tmp = (a + (b * (d / c))) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3e-54) || !(c <= 3.8e-57)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -3e-54) || ~((c <= 3.8e-57))) tmp = (a + (b * (d / c))) / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3e-54], N[Not[LessEqual[c, 3.8e-57]], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3 \cdot 10^{-54} \lor \neg \left(c \leq 3.8 \cdot 10^{-57}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -3.00000000000000009e-54 or 3.7999999999999997e-57 < c Initial program 57.8%
Taylor expanded in c around inf 72.5%
associate-/l*75.1%
Simplified75.1%
if -3.00000000000000009e-54 < c < 3.7999999999999997e-57Initial program 73.6%
Taylor expanded in c around 0 73.2%
Final simplification74.3%
(FPCore (a b c d) :precision binary64 (if (<= c -1.25e-48) (/ (+ a (* b (/ d c))) c) (if (<= c 1.75e+42) (/ (+ b (/ a (/ d c))) d) (/ (+ a (/ b (/ c d))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.25e-48) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 1.75e+42) {
tmp = (b + (a / (d / c))) / d;
} else {
tmp = (a + (b / (c / 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.25d-48)) then
tmp = (a + (b * (d / c))) / c
else if (c <= 1.75d+42) then
tmp = (b + (a / (d / c))) / d
else
tmp = (a + (b / (c / 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.25e-48) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 1.75e+42) {
tmp = (b + (a / (d / c))) / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.25e-48: tmp = (a + (b * (d / c))) / c elif c <= 1.75e+42: tmp = (b + (a / (d / c))) / d else: tmp = (a + (b / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.25e-48) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= 1.75e+42) tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d); else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.25e-48) tmp = (a + (b * (d / c))) / c; elseif (c <= 1.75e+42) tmp = (b + (a / (d / c))) / d; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.25e-48], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.75e+42], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.25 \cdot 10^{-48}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 1.75 \cdot 10^{+42}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -1.25e-48Initial program 54.4%
Taylor expanded in c around inf 73.9%
associate-/l*76.8%
Simplified76.8%
if -1.25e-48 < c < 1.75000000000000012e42Initial program 76.1%
Taylor expanded in d around inf 85.3%
associate-/l*85.8%
Simplified85.8%
clear-num85.8%
un-div-inv85.8%
Applied egg-rr85.8%
if 1.75000000000000012e42 < c Initial program 48.4%
Taylor expanded in c around inf 81.9%
associate-/l*85.4%
Simplified85.4%
clear-num85.4%
un-div-inv85.5%
Applied egg-rr85.5%
(FPCore (a b c d) :precision binary64 (if (<= c -3.5e-49) (/ (+ a (* b (/ d c))) c) (if (<= c 1.9e+35) (/ (+ b (* a (/ c d))) d) (/ (+ a (/ b (/ c d))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.5e-49) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 1.9e+35) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b / (c / 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.5d-49)) then
tmp = (a + (b * (d / c))) / c
else if (c <= 1.9d+35) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a + (b / (c / 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.5e-49) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 1.9e+35) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3.5e-49: tmp = (a + (b * (d / c))) / c elif c <= 1.9e+35: tmp = (b + (a * (c / d))) / d else: tmp = (a + (b / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3.5e-49) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= 1.9e+35) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -3.5e-49) tmp = (a + (b * (d / c))) / c; elseif (c <= 1.9e+35) tmp = (b + (a * (c / d))) / d; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.5e-49], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.9e+35], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.5 \cdot 10^{-49}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{+35}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -3.50000000000000006e-49Initial program 54.4%
Taylor expanded in c around inf 73.9%
associate-/l*76.8%
Simplified76.8%
if -3.50000000000000006e-49 < c < 1.9e35Initial program 76.1%
Taylor expanded in d around inf 85.3%
associate-/l*85.8%
Simplified85.8%
if 1.9e35 < c Initial program 48.4%
Taylor expanded in c around inf 81.9%
associate-/l*85.4%
Simplified85.4%
clear-num85.4%
un-div-inv85.5%
Applied egg-rr85.5%
(FPCore (a b c d) :precision binary64 (if (<= c -6.4e-54) (/ (+ a (* b (/ d c))) c) (if (<= c 2.85e-59) (/ b d) (/ (+ a (/ b (/ c d))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.4e-54) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 2.85e-59) {
tmp = b / d;
} else {
tmp = (a + (b / (c / 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 <= (-6.4d-54)) then
tmp = (a + (b * (d / c))) / c
else if (c <= 2.85d-59) then
tmp = b / d
else
tmp = (a + (b / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.4e-54) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 2.85e-59) {
tmp = b / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -6.4e-54: tmp = (a + (b * (d / c))) / c elif c <= 2.85e-59: tmp = b / d else: tmp = (a + (b / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -6.4e-54) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= 2.85e-59) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -6.4e-54) tmp = (a + (b * (d / c))) / c; elseif (c <= 2.85e-59) tmp = b / d; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -6.4e-54], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 2.85e-59], N[(b / d), $MachinePrecision], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.4 \cdot 10^{-54}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 2.85 \cdot 10^{-59}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -6.39999999999999997e-54Initial program 55.0%
Taylor expanded in c around inf 71.6%
associate-/l*74.4%
Simplified74.4%
if -6.39999999999999997e-54 < c < 2.85e-59Initial program 73.6%
Taylor expanded in c around 0 73.2%
if 2.85e-59 < c Initial program 60.5%
Taylor expanded in c around inf 73.2%
associate-/l*75.9%
Simplified75.9%
clear-num75.9%
un-div-inv75.9%
Applied egg-rr75.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.4e-54) (not (<= c 1e+105))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.4e-54) || !(c <= 1e+105)) {
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 <= (-1.4d-54)) .or. (.not. (c <= 1d+105))) 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 <= -1.4e-54) || !(c <= 1e+105)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.4e-54) or not (c <= 1e+105): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.4e-54) || !(c <= 1e+105)) 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 <= -1.4e-54) || ~((c <= 1e+105))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.4e-54], N[Not[LessEqual[c, 1e+105]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.4 \cdot 10^{-54} \lor \neg \left(c \leq 10^{+105}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -1.4000000000000001e-54 or 9.9999999999999994e104 < c Initial program 52.3%
Taylor expanded in c around inf 71.8%
if -1.4000000000000001e-54 < c < 9.9999999999999994e104Initial program 74.8%
Taylor expanded in c around 0 66.3%
Final simplification68.7%
(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 64.8%
Taylor expanded in c around inf 40.6%
(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 2024106
(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))))