
(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 10 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 (or (<= d -1.1e-114) (not (<= d 1.75e-63))) (* (/ (fma a (/ c d) b) (hypot d c)) (/ d (hypot d c))) (/ (+ a (/ (* d b) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.1e-114) || !(d <= 1.75e-63)) {
tmp = (fma(a, (c / d), b) / hypot(d, c)) * (d / hypot(d, c));
} else {
tmp = (a + ((d * b) / c)) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.1e-114) || !(d <= 1.75e-63)) tmp = Float64(Float64(fma(a, Float64(c / d), b) / hypot(d, c)) * Float64(d / hypot(d, c))); else tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.1e-114], N[Not[LessEqual[d, 1.75e-63]], $MachinePrecision]], N[(N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.1 \cdot 10^{-114} \lor \neg \left(d \leq 1.75 \cdot 10^{-63}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{d}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\end{array}
\end{array}
if d < -1.10000000000000006e-114 or 1.75000000000000002e-63 < d Initial program 55.5%
Taylor expanded in d around inf 54.9%
associate-/l*53.8%
Simplified53.8%
*-commutative53.8%
add-sqr-sqrt53.8%
hypot-undefine53.8%
hypot-undefine53.8%
times-frac95.8%
+-commutative95.8%
fma-define95.8%
hypot-undefine58.7%
+-commutative58.7%
hypot-undefine95.8%
hypot-undefine58.7%
+-commutative58.7%
hypot-undefine95.8%
Applied egg-rr95.8%
if -1.10000000000000006e-114 < d < 1.75000000000000002e-63Initial program 78.2%
Taylor expanded in c around inf 94.4%
Final simplification95.4%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* d b) (* a c)) (+ (* c c) (* d d))) 1e+305) (* (/ 1.0 (hypot c d)) (/ (fma a c (* d b)) (hypot c d))) (/ (+ b (* c (/ a d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((d * b) + (a * c)) / ((c * c) + (d * d))) <= 1e+305) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (d * b)) / hypot(c, d));
} else {
tmp = (b + (c * (a / d))) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (Float64(Float64(Float64(d * b) + Float64(a * c)) / Float64(Float64(c * c) + Float64(d * d))) <= 1e+305) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(d * b)) / hypot(c, d))); else tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(d * b), $MachinePrecision] + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+305], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d} \leq 10^{+305}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 9.9999999999999994e304Initial program 81.4%
*-un-lft-identity81.4%
associate-*r/81.4%
fma-define81.4%
add-sqr-sqrt81.4%
times-frac81.4%
fma-define81.4%
hypot-define81.4%
fma-define81.4%
fma-define81.4%
hypot-define97.5%
Applied egg-rr97.5%
if 9.9999999999999994e304 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 11.0%
Taylor expanded in d around inf 34.7%
+-commutative34.7%
mul-1-neg34.7%
unsub-neg34.7%
*-commutative34.7%
associate-/l*36.3%
Simplified36.3%
Taylor expanded in c around 0 58.8%
*-commutative58.8%
associate-*r/63.6%
Simplified63.6%
Final simplification88.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma c c (* d d))) (t_1 (/ (+ a (* b (/ d c))) c)))
(if (<= c -1.05e+55)
t_1
(if (<= c -1.4e-137)
(/ (+ (* d b) (* a c)) t_0)
(if (<= c 2.8e-66)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 2.2e+131) (/ (fma a c (* d b)) t_0) t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(c, c, (d * d));
double t_1 = (a + (b * (d / c))) / c;
double tmp;
if (c <= -1.05e+55) {
tmp = t_1;
} else if (c <= -1.4e-137) {
tmp = ((d * b) + (a * c)) / t_0;
} else if (c <= 2.8e-66) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 2.2e+131) {
tmp = fma(a, c, (d * b)) / t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(c, c, Float64(d * d)) t_1 = Float64(Float64(a + Float64(b * Float64(d / c))) / c) tmp = 0.0 if (c <= -1.05e+55) tmp = t_1; elseif (c <= -1.4e-137) tmp = Float64(Float64(Float64(d * b) + Float64(a * c)) / t_0); elseif (c <= 2.8e-66) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 2.2e+131) tmp = Float64(fma(a, c, Float64(d * b)) / t_0); else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.05e+55], t$95$1, If[LessEqual[c, -1.4e-137], N[(N[(N[(d * b), $MachinePrecision] + N[(a * c), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], If[LessEqual[c, 2.8e-66], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.2e+131], N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, c, d \cdot d\right)\\
t_1 := \frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{if}\;c \leq -1.05 \cdot 10^{+55}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -1.4 \cdot 10^{-137}:\\
\;\;\;\;\frac{d \cdot b + a \cdot c}{t\_0}\\
\mathbf{elif}\;c \leq 2.8 \cdot 10^{-66}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 2.2 \cdot 10^{+131}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -1.05e55 or 2.1999999999999999e131 < c Initial program 36.0%
Taylor expanded in c around inf 75.5%
associate-/l*84.1%
Simplified84.1%
if -1.05e55 < c < -1.3999999999999999e-137Initial program 84.2%
fma-define84.2%
fma-define84.2%
Simplified84.2%
fma-define84.2%
+-commutative84.2%
Applied egg-rr84.2%
if -1.3999999999999999e-137 < c < 2.8e-66Initial program 67.4%
Taylor expanded in d around inf 97.0%
if 2.8e-66 < c < 2.1999999999999999e131Initial program 81.7%
fma-define81.7%
fma-define81.7%
Simplified81.7%
Final simplification87.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (* d b) (* a c))) (t_1 (/ (+ a (* b (/ d c))) c)))
(if (<= c -1.9e+53)
t_1
(if (<= c -3.2e-130)
(/ t_0 (fma c c (* d d)))
(if (<= c 2.9e-66)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 2.2e+131) (/ t_0 (+ (* c c) (* d d))) t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = (d * b) + (a * c);
double t_1 = (a + (b * (d / c))) / c;
double tmp;
if (c <= -1.9e+53) {
tmp = t_1;
} else if (c <= -3.2e-130) {
tmp = t_0 / fma(c, c, (d * d));
} else if (c <= 2.9e-66) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 2.2e+131) {
tmp = t_0 / ((c * c) + (d * d));
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(d * b) + Float64(a * c)) t_1 = Float64(Float64(a + Float64(b * Float64(d / c))) / c) tmp = 0.0 if (c <= -1.9e+53) tmp = t_1; elseif (c <= -3.2e-130) tmp = Float64(t_0 / fma(c, c, Float64(d * d))); elseif (c <= 2.9e-66) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 2.2e+131) tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * b), $MachinePrecision] + N[(a * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.9e+53], t$95$1, If[LessEqual[c, -3.2e-130], N[(t$95$0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.9e-66], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.2e+131], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := d \cdot b + a \cdot c\\
t_1 := \frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{if}\;c \leq -1.9 \cdot 10^{+53}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -3.2 \cdot 10^{-130}:\\
\;\;\;\;\frac{t\_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;c \leq 2.9 \cdot 10^{-66}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 2.2 \cdot 10^{+131}:\\
\;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -1.89999999999999999e53 or 2.1999999999999999e131 < c Initial program 36.0%
Taylor expanded in c around inf 75.5%
associate-/l*84.1%
Simplified84.1%
if -1.89999999999999999e53 < c < -3.2e-130Initial program 84.2%
fma-define84.2%
fma-define84.2%
Simplified84.2%
fma-define84.2%
+-commutative84.2%
Applied egg-rr84.2%
if -3.2e-130 < c < 2.90000000000000011e-66Initial program 67.4%
Taylor expanded in d around inf 97.0%
if 2.90000000000000011e-66 < c < 2.1999999999999999e131Initial program 81.7%
Final simplification87.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* d b) (* a c)) (+ (* c c) (* d d))))
(t_1 (/ (+ a (* b (/ d c))) c)))
(if (<= c -3e+58)
t_1
(if (<= c -5.8e-131)
t_0
(if (<= c 1.7e-65)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 2.2e+131) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((d * b) + (a * c)) / ((c * c) + (d * d));
double t_1 = (a + (b * (d / c))) / c;
double tmp;
if (c <= -3e+58) {
tmp = t_1;
} else if (c <= -5.8e-131) {
tmp = t_0;
} else if (c <= 1.7e-65) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 2.2e+131) {
tmp = t_0;
} 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 = ((d * b) + (a * c)) / ((c * c) + (d * d))
t_1 = (a + (b * (d / c))) / c
if (c <= (-3d+58)) then
tmp = t_1
else if (c <= (-5.8d-131)) then
tmp = t_0
else if (c <= 1.7d-65) then
tmp = (b + ((a * c) / d)) / d
else if (c <= 2.2d+131) then
tmp = t_0
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 = ((d * b) + (a * c)) / ((c * c) + (d * d));
double t_1 = (a + (b * (d / c))) / c;
double tmp;
if (c <= -3e+58) {
tmp = t_1;
} else if (c <= -5.8e-131) {
tmp = t_0;
} else if (c <= 1.7e-65) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 2.2e+131) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((d * b) + (a * c)) / ((c * c) + (d * d)) t_1 = (a + (b * (d / c))) / c tmp = 0 if c <= -3e+58: tmp = t_1 elif c <= -5.8e-131: tmp = t_0 elif c <= 1.7e-65: tmp = (b + ((a * c) / d)) / d elif c <= 2.2e+131: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(d * b) + Float64(a * c)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(a + Float64(b * Float64(d / c))) / c) tmp = 0.0 if (c <= -3e+58) tmp = t_1; elseif (c <= -5.8e-131) tmp = t_0; elseif (c <= 1.7e-65) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 2.2e+131) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((d * b) + (a * c)) / ((c * c) + (d * d)); t_1 = (a + (b * (d / c))) / c; tmp = 0.0; if (c <= -3e+58) tmp = t_1; elseif (c <= -5.8e-131) tmp = t_0; elseif (c <= 1.7e-65) tmp = (b + ((a * c) / d)) / d; elseif (c <= 2.2e+131) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(d * b), $MachinePrecision] + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3e+58], t$95$1, If[LessEqual[c, -5.8e-131], t$95$0, If[LessEqual[c, 1.7e-65], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.2e+131], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\
t_1 := \frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{if}\;c \leq -3 \cdot 10^{+58}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -5.8 \cdot 10^{-131}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.7 \cdot 10^{-65}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 2.2 \cdot 10^{+131}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -3.0000000000000002e58 or 2.1999999999999999e131 < c Initial program 36.0%
Taylor expanded in c around inf 75.5%
associate-/l*84.1%
Simplified84.1%
if -3.0000000000000002e58 < c < -5.8000000000000004e-131 or 1.69999999999999993e-65 < c < 2.1999999999999999e131Initial program 83.0%
if -5.8000000000000004e-131 < c < 1.69999999999999993e-65Initial program 67.4%
Taylor expanded in d around inf 97.0%
Final simplification87.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.55e+49) (not (<= c 7e-52))) (/ (+ a (* b (/ d c))) c) (/ (+ b (/ (* a c) d)) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.55e+49) || !(c <= 7e-52)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + ((a * c) / d)) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-1.55d+49)) .or. (.not. (c <= 7d-52))) then
tmp = (a + (b * (d / c))) / c
else
tmp = (b + ((a * c) / d)) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.55e+49) || !(c <= 7e-52)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + ((a * c) / d)) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.55e+49) or not (c <= 7e-52): tmp = (a + (b * (d / c))) / c else: tmp = (b + ((a * c) / d)) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.55e+49) || !(c <= 7e-52)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.55e+49) || ~((c <= 7e-52))) tmp = (a + (b * (d / c))) / c; else tmp = (b + ((a * c) / d)) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.55e+49], N[Not[LessEqual[c, 7e-52]], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.55 \cdot 10^{+49} \lor \neg \left(c \leq 7 \cdot 10^{-52}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\end{array}
\end{array}
if c < -1.54999999999999996e49 or 7.0000000000000001e-52 < c Initial program 50.9%
Taylor expanded in c around inf 72.8%
associate-/l*77.8%
Simplified77.8%
if -1.54999999999999996e49 < c < 7.0000000000000001e-52Initial program 74.2%
Taylor expanded in d around inf 84.8%
Final simplification81.4%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5.1e+47) (not (<= c 8.6e-52))) (/ (+ a (* b (/ d c))) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.1e+47) || !(c <= 8.6e-52)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-5.1d+47)) .or. (.not. (c <= 8.6d-52))) then
tmp = (a + (b * (d / c))) / c
else
tmp = (b + (a * (c / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.1e+47) || !(c <= 8.6e-52)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5.1e+47) or not (c <= 8.6e-52): tmp = (a + (b * (d / c))) / c else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5.1e+47) || !(c <= 8.6e-52)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -5.1e+47) || ~((c <= 8.6e-52))) tmp = (a + (b * (d / c))) / c; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5.1e+47], N[Not[LessEqual[c, 8.6e-52]], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.1 \cdot 10^{+47} \lor \neg \left(c \leq 8.6 \cdot 10^{-52}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if c < -5.1000000000000001e47 or 8.6000000000000007e-52 < c Initial program 50.9%
Taylor expanded in c around inf 72.8%
associate-/l*77.8%
Simplified77.8%
if -5.1000000000000001e47 < c < 8.6000000000000007e-52Initial program 74.2%
Taylor expanded in d around inf 84.8%
associate-/l*84.2%
Simplified84.2%
Final simplification81.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -7.8e+121) (not (<= d 4.2e+105))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.8e+121) || !(d <= 4.2e+105)) {
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 <= (-7.8d+121)) .or. (.not. (d <= 4.2d+105))) 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 <= -7.8e+121) || !(d <= 4.2e+105)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -7.8e+121) or not (d <= 4.2e+105): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -7.8e+121) || !(d <= 4.2e+105)) 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 <= -7.8e+121) || ~((d <= 4.2e+105))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7.8e+121], N[Not[LessEqual[d, 4.2e+105]], $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 -7.8 \cdot 10^{+121} \lor \neg \left(d \leq 4.2 \cdot 10^{+105}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -7.79999999999999967e121 or 4.2000000000000002e105 < d Initial program 38.9%
Taylor expanded in c around 0 79.8%
if -7.79999999999999967e121 < d < 4.2000000000000002e105Initial program 75.6%
Taylor expanded in c around inf 70.5%
associate-/l*72.3%
Simplified72.3%
Final simplification74.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.14e-14) (not (<= d 1.36e+60))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.14e-14) || !(d <= 1.36e+60)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-1.14d-14)) .or. (.not. (d <= 1.36d+60))) then
tmp = b / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.14e-14) || !(d <= 1.36e+60)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.14e-14) or not (d <= 1.36e+60): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.14e-14) || !(d <= 1.36e+60)) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.14e-14) || ~((d <= 1.36e+60))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.14e-14], N[Not[LessEqual[d, 1.36e+60]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.14 \cdot 10^{-14} \lor \neg \left(d \leq 1.36 \cdot 10^{+60}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -1.1400000000000001e-14 or 1.36000000000000002e60 < d Initial program 47.1%
Taylor expanded in c around 0 66.5%
if -1.1400000000000001e-14 < d < 1.36000000000000002e60Initial program 80.2%
Taylor expanded in c around inf 67.2%
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 63.0%
Taylor expanded in c around inf 41.1%
(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 2024111
(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))))