
(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 13 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 (/ (fma d (/ b c) a) (hypot c d))))
(if (<= c -1.42e-62)
(* t_0 (/ c (hypot c d)))
(if (<= c 7.2e-58) (/ (+ b (* a (/ c d))) d) (/ t_0 (/ (hypot c d) c))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, (b / c), a) / hypot(c, d);
double tmp;
if (c <= -1.42e-62) {
tmp = t_0 * (c / hypot(c, d));
} else if (c <= 7.2e-58) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = t_0 / (hypot(c, d) / c);
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(d, Float64(b / c), a) / hypot(c, d)) tmp = 0.0 if (c <= -1.42e-62) tmp = Float64(t_0 * Float64(c / hypot(c, d))); elseif (c <= 7.2e-58) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(t_0 / Float64(hypot(c, d) / c)); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.42e-62], N[(t$95$0 * N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.2e-58], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(t$95$0 / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;c \leq -1.42 \cdot 10^{-62}:\\
\;\;\;\;t\_0 \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq 7.2 \cdot 10^{-58}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}\\
\end{array}
\end{array}
if c < -1.42e-62Initial program 64.1%
fma-define64.1%
fma-define64.1%
Simplified64.1%
Taylor expanded in c around inf 63.0%
*-commutative63.0%
Simplified63.0%
*-commutative63.0%
add-sqr-sqrt62.9%
times-frac63.5%
+-commutative63.5%
associate-/l*63.8%
fma-define63.8%
fma-undefine63.8%
hypot-define63.8%
fma-undefine63.8%
hypot-define95.1%
Applied egg-rr95.1%
if -1.42e-62 < c < 7.20000000000000019e-58Initial program 72.7%
fma-define72.7%
fma-define72.7%
Simplified72.7%
Taylor expanded in d around inf 87.3%
associate-/l*87.9%
Simplified87.9%
if 7.20000000000000019e-58 < c Initial program 57.6%
fma-define57.6%
fma-define57.6%
Simplified57.6%
Taylor expanded in c around inf 57.5%
*-commutative57.5%
Simplified57.5%
*-commutative57.5%
add-sqr-sqrt57.5%
times-frac60.5%
+-commutative60.5%
associate-/l*62.2%
fma-define62.2%
fma-undefine62.2%
hypot-define62.2%
fma-undefine62.2%
hypot-define95.8%
Applied egg-rr95.8%
clear-num95.8%
un-div-inv95.8%
Applied egg-rr95.8%
(FPCore (a b c d)
:precision binary64
(if (<= c -8.2e+142)
(/
(+ a (- (- (* b (/ d c)) (* b (pow (/ d c) 3.0))) (* a (pow (/ d c) 2.0))))
c)
(if (<= c -1.7e-97)
(/ (fma a c (* d b)) (fma c c (* d d)))
(if (<= c 7.2e-58)
(/ (+ b (* a (/ c d))) d)
(if (<= c 1.55e+121)
(* c (/ (/ (fma d (/ b c) a) (hypot c d)) (hypot c d)))
(/ (+ a (* d (/ b c))) c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -8.2e+142) {
tmp = (a + (((b * (d / c)) - (b * pow((d / c), 3.0))) - (a * pow((d / c), 2.0)))) / c;
} else if (c <= -1.7e-97) {
tmp = fma(a, c, (d * b)) / fma(c, c, (d * d));
} else if (c <= 7.2e-58) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.55e+121) {
tmp = c * ((fma(d, (b / c), a) / hypot(c, d)) / hypot(c, d));
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -8.2e+142) tmp = Float64(Float64(a + Float64(Float64(Float64(b * Float64(d / c)) - Float64(b * (Float64(d / c) ^ 3.0))) - Float64(a * (Float64(d / c) ^ 2.0)))) / c); elseif (c <= -1.7e-97) tmp = Float64(fma(a, c, Float64(d * b)) / fma(c, c, Float64(d * d))); elseif (c <= 7.2e-58) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 1.55e+121) tmp = Float64(c * Float64(Float64(fma(d, Float64(b / c), a) / hypot(c, d)) / hypot(c, d))); else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -8.2e+142], N[(N[(a + N[(N[(N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision] - N[(b * N[Power[N[(d / c), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a * N[Power[N[(d / c), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.7e-97], N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.2e-58], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.55e+121], N[(c * N[(N[(N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.2 \cdot 10^{+142}:\\
\;\;\;\;\frac{a + \left(\left(b \cdot \frac{d}{c} - b \cdot {\left(\frac{d}{c}\right)}^{3}\right) - a \cdot {\left(\frac{d}{c}\right)}^{2}\right)}{c}\\
\mathbf{elif}\;c \leq -1.7 \cdot 10^{-97}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;c \leq 7.2 \cdot 10^{-58}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.55 \cdot 10^{+121}:\\
\;\;\;\;c \cdot \frac{\frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -8.19999999999999963e142Initial program 37.4%
fma-define37.4%
fma-define37.4%
Simplified37.4%
Taylor expanded in c around inf 37.4%
*-commutative37.4%
Simplified37.4%
Taylor expanded in c around inf 55.6%
Simplified88.6%
if -8.19999999999999963e142 < c < -1.6999999999999999e-97Initial program 85.9%
fma-define85.9%
fma-define85.9%
Simplified85.9%
if -1.6999999999999999e-97 < c < 7.20000000000000019e-58Initial program 71.8%
fma-define71.8%
fma-define71.8%
Simplified71.8%
Taylor expanded in d around inf 86.9%
associate-/l*87.5%
Simplified87.5%
if 7.20000000000000019e-58 < c < 1.55000000000000004e121Initial program 83.1%
fma-define83.1%
fma-define83.1%
Simplified83.1%
Taylor expanded in c around inf 82.8%
*-commutative82.8%
Simplified82.8%
*-commutative82.8%
add-sqr-sqrt82.8%
times-frac85.4%
+-commutative85.4%
associate-/l*88.4%
fma-define88.4%
fma-undefine88.4%
hypot-define88.4%
fma-undefine88.4%
hypot-define94.0%
Applied egg-rr94.0%
clear-num93.9%
un-div-inv94.0%
Applied egg-rr94.0%
associate-/r/91.4%
Applied egg-rr91.4%
if 1.55000000000000004e121 < c Initial program 35.5%
fma-define35.5%
fma-define35.5%
Simplified35.5%
Taylor expanded in c around inf 73.1%
+-commutative73.1%
associate-/l*80.7%
fma-define80.7%
Simplified80.7%
fma-undefine80.7%
associate-*r/73.1%
*-commutative73.1%
associate-/l*83.1%
Applied egg-rr83.1%
Final simplification87.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.85e-63) (not (<= c 1.9e-56))) (* (/ (fma d (/ b c) a) (hypot c d)) (/ c (hypot c d))) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.85e-63) || !(c <= 1.9e-56)) {
tmp = (fma(d, (b / c), a) / hypot(c, d)) * (c / hypot(c, d));
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.85e-63) || !(c <= 1.9e-56)) tmp = Float64(Float64(fma(d, Float64(b / c), a) / hypot(c, d)) * Float64(c / hypot(c, d))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.85e-63], N[Not[LessEqual[c, 1.9e-56]], $MachinePrecision]], N[(N[(N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(c / 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}\;c \leq -2.85 \cdot 10^{-63} \lor \neg \left(c \leq 1.9 \cdot 10^{-56}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if c < -2.85000000000000026e-63 or 1.9000000000000001e-56 < c Initial program 61.1%
fma-define61.1%
fma-define61.1%
Simplified61.1%
Taylor expanded in c around inf 60.4%
*-commutative60.4%
Simplified60.4%
*-commutative60.4%
add-sqr-sqrt60.4%
times-frac62.1%
+-commutative62.1%
associate-/l*63.1%
fma-define63.1%
fma-undefine63.1%
hypot-define63.1%
fma-undefine63.1%
hypot-define95.4%
Applied egg-rr95.4%
if -2.85000000000000026e-63 < c < 1.9000000000000001e-56Initial program 72.7%
fma-define72.7%
fma-define72.7%
Simplified72.7%
Taylor expanded in d around inf 87.3%
associate-/l*87.9%
Simplified87.9%
Final simplification92.5%
(FPCore (a b c d)
:precision binary64
(if (<= c -9e+142)
(/
(+ a (- (- (* b (/ d c)) (* b (pow (/ d c) 3.0))) (* a (pow (/ d c) 2.0))))
c)
(if (<= c -1.6e-97)
(/ (fma a c (* d b)) (fma c c (* d d)))
(if (<= c 6.3e-142)
(/ (+ b (* a (/ c d))) d)
(if (<= c 5e+100)
(/ (+ (* d b) (* c a)) (+ (* d d) (* c c)))
(/ (+ a (* d (/ b c))) c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -9e+142) {
tmp = (a + (((b * (d / c)) - (b * pow((d / c), 3.0))) - (a * pow((d / c), 2.0)))) / c;
} else if (c <= -1.6e-97) {
tmp = fma(a, c, (d * b)) / fma(c, c, (d * d));
} else if (c <= 6.3e-142) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 5e+100) {
tmp = ((d * b) + (c * a)) / ((d * d) + (c * c));
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -9e+142) tmp = Float64(Float64(a + Float64(Float64(Float64(b * Float64(d / c)) - Float64(b * (Float64(d / c) ^ 3.0))) - Float64(a * (Float64(d / c) ^ 2.0)))) / c); elseif (c <= -1.6e-97) tmp = Float64(fma(a, c, Float64(d * b)) / fma(c, c, Float64(d * d))); elseif (c <= 6.3e-142) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 5e+100) tmp = Float64(Float64(Float64(d * b) + Float64(c * a)) / Float64(Float64(d * d) + Float64(c * c))); else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -9e+142], N[(N[(a + N[(N[(N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision] - N[(b * N[Power[N[(d / c), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a * N[Power[N[(d / c), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.6e-97], N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 6.3e-142], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 5e+100], N[(N[(N[(d * b), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{+142}:\\
\;\;\;\;\frac{a + \left(\left(b \cdot \frac{d}{c} - b \cdot {\left(\frac{d}{c}\right)}^{3}\right) - a \cdot {\left(\frac{d}{c}\right)}^{2}\right)}{c}\\
\mathbf{elif}\;c \leq -1.6 \cdot 10^{-97}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;c \leq 6.3 \cdot 10^{-142}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 5 \cdot 10^{+100}:\\
\;\;\;\;\frac{d \cdot b + c \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -8.9999999999999998e142Initial program 37.4%
fma-define37.4%
fma-define37.4%
Simplified37.4%
Taylor expanded in c around inf 37.4%
*-commutative37.4%
Simplified37.4%
Taylor expanded in c around inf 55.6%
Simplified88.6%
if -8.9999999999999998e142 < c < -1.5999999999999999e-97Initial program 85.9%
fma-define85.9%
fma-define85.9%
Simplified85.9%
if -1.5999999999999999e-97 < c < 6.2999999999999998e-142Initial program 69.3%
fma-define69.3%
fma-define69.3%
Simplified69.3%
Taylor expanded in d around inf 87.8%
associate-/l*88.6%
Simplified88.6%
if 6.2999999999999998e-142 < c < 4.9999999999999999e100Initial program 85.5%
if 4.9999999999999999e100 < c Initial program 38.4%
fma-define38.4%
fma-define38.4%
Simplified38.4%
Taylor expanded in c around inf 71.7%
+-commutative71.7%
associate-/l*78.6%
fma-define78.6%
Simplified78.6%
fma-undefine78.6%
associate-*r/71.7%
*-commutative71.7%
associate-/l*80.8%
Applied egg-rr80.8%
Final simplification86.2%
(FPCore (a b c d)
:precision binary64
(if (<= c -8.2e+142)
(/ (fma d (/ b c) a) (- (hypot c d)))
(if (<= c -1.9e-97)
(/ (fma a c (* d b)) (fma c c (* d d)))
(if (<= c 1.35e-140)
(/ (+ b (* a (/ c d))) d)
(if (<= c 4.4e+99)
(/ (+ (* d b) (* c a)) (+ (* d d) (* c c)))
(/ (+ a (* d (/ b c))) c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -8.2e+142) {
tmp = fma(d, (b / c), a) / -hypot(c, d);
} else if (c <= -1.9e-97) {
tmp = fma(a, c, (d * b)) / fma(c, c, (d * d));
} else if (c <= 1.35e-140) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 4.4e+99) {
tmp = ((d * b) + (c * a)) / ((d * d) + (c * c));
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -8.2e+142) tmp = Float64(fma(d, Float64(b / c), a) / Float64(-hypot(c, d))); elseif (c <= -1.9e-97) tmp = Float64(fma(a, c, Float64(d * b)) / fma(c, c, Float64(d * d))); elseif (c <= 1.35e-140) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 4.4e+99) tmp = Float64(Float64(Float64(d * b) + Float64(c * a)) / Float64(Float64(d * d) + Float64(c * c))); else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -8.2e+142], N[(N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision] / (-N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision])), $MachinePrecision], If[LessEqual[c, -1.9e-97], N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.35e-140], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.4e+99], N[(N[(N[(d * b), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.2 \cdot 10^{+142}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{-\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -1.9 \cdot 10^{-97}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;c \leq 1.35 \cdot 10^{-140}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 4.4 \cdot 10^{+99}:\\
\;\;\;\;\frac{d \cdot b + c \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -8.19999999999999963e142Initial program 37.4%
fma-define37.4%
fma-define37.4%
Simplified37.4%
Taylor expanded in c around inf 37.4%
*-commutative37.4%
Simplified37.4%
*-commutative37.4%
add-sqr-sqrt37.4%
times-frac38.6%
+-commutative38.6%
associate-/l*39.2%
fma-define39.2%
fma-undefine39.2%
hypot-define39.2%
fma-undefine39.2%
hypot-define99.7%
Applied egg-rr99.7%
Taylor expanded in c around -inf 88.2%
if -8.19999999999999963e142 < c < -1.9e-97Initial program 85.9%
fma-define85.9%
fma-define85.9%
Simplified85.9%
if -1.9e-97 < c < 1.35e-140Initial program 69.3%
fma-define69.3%
fma-define69.3%
Simplified69.3%
Taylor expanded in d around inf 87.8%
associate-/l*88.6%
Simplified88.6%
if 1.35e-140 < c < 4.39999999999999956e99Initial program 85.5%
if 4.39999999999999956e99 < c Initial program 38.4%
fma-define38.4%
fma-define38.4%
Simplified38.4%
Taylor expanded in c around inf 71.7%
+-commutative71.7%
associate-/l*78.6%
fma-define78.6%
Simplified78.6%
fma-undefine78.6%
associate-*r/71.7%
*-commutative71.7%
associate-/l*80.8%
Applied egg-rr80.8%
Final simplification86.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* d b) (* c a)) (+ (* d d) (* c c)))))
(if (<= c -8.6e+142)
(/ (fma d (/ b c) a) (- (hypot c d)))
(if (<= c -1.6e-97)
t_0
(if (<= c 5.9e-142)
(/ (+ b (* a (/ c d))) d)
(if (<= c 2.4e+99) t_0 (/ (+ a (* d (/ b c))) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((d * b) + (c * a)) / ((d * d) + (c * c));
double tmp;
if (c <= -8.6e+142) {
tmp = fma(d, (b / c), a) / -hypot(c, d);
} else if (c <= -1.6e-97) {
tmp = t_0;
} else if (c <= 5.9e-142) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 2.4e+99) {
tmp = t_0;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(d * b) + Float64(c * a)) / Float64(Float64(d * d) + Float64(c * c))) tmp = 0.0 if (c <= -8.6e+142) tmp = Float64(fma(d, Float64(b / c), a) / Float64(-hypot(c, d))); elseif (c <= -1.6e-97) tmp = t_0; elseif (c <= 5.9e-142) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 2.4e+99) 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[(N[(d * b), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -8.6e+142], N[(N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision] / (-N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision])), $MachinePrecision], If[LessEqual[c, -1.6e-97], t$95$0, If[LessEqual[c, 5.9e-142], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.4e+99], 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{d \cdot b + c \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{if}\;c \leq -8.6 \cdot 10^{+142}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{-\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -1.6 \cdot 10^{-97}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 5.9 \cdot 10^{-142}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{+99}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -8.60000000000000025e142Initial program 37.4%
fma-define37.4%
fma-define37.4%
Simplified37.4%
Taylor expanded in c around inf 37.4%
*-commutative37.4%
Simplified37.4%
*-commutative37.4%
add-sqr-sqrt37.4%
times-frac38.6%
+-commutative38.6%
associate-/l*39.2%
fma-define39.2%
fma-undefine39.2%
hypot-define39.2%
fma-undefine39.2%
hypot-define99.7%
Applied egg-rr99.7%
Taylor expanded in c around -inf 88.2%
if -8.60000000000000025e142 < c < -1.5999999999999999e-97 or 5.89999999999999966e-142 < c < 2.4000000000000001e99Initial program 85.7%
if -1.5999999999999999e-97 < c < 5.89999999999999966e-142Initial program 69.3%
fma-define69.3%
fma-define69.3%
Simplified69.3%
Taylor expanded in d around inf 87.8%
associate-/l*88.6%
Simplified88.6%
if 2.4000000000000001e99 < c Initial program 38.4%
fma-define38.4%
fma-define38.4%
Simplified38.4%
Taylor expanded in c around inf 71.7%
+-commutative71.7%
associate-/l*78.6%
fma-define78.6%
Simplified78.6%
fma-undefine78.6%
associate-*r/71.7%
*-commutative71.7%
associate-/l*80.8%
Applied egg-rr80.8%
Final simplification86.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* d b) (* c a)) (+ (* d d) (* c c)))))
(if (<= c -1.95e+143)
(/ (+ a (/ b (* c (/ 1.0 d)))) c)
(if (<= c -1.6e-97)
t_0
(if (<= c 3.2e-141)
(/ (+ b (* a (/ c d))) d)
(if (<= c 8e+99) t_0 (/ (+ a (* d (/ b c))) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((d * b) + (c * a)) / ((d * d) + (c * c));
double tmp;
if (c <= -1.95e+143) {
tmp = (a + (b / (c * (1.0 / d)))) / c;
} else if (c <= -1.6e-97) {
tmp = t_0;
} else if (c <= 3.2e-141) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 8e+99) {
tmp = t_0;
} 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) :: tmp
t_0 = ((d * b) + (c * a)) / ((d * d) + (c * c))
if (c <= (-1.95d+143)) then
tmp = (a + (b / (c * (1.0d0 / d)))) / c
else if (c <= (-1.6d-97)) then
tmp = t_0
else if (c <= 3.2d-141) then
tmp = (b + (a * (c / d))) / d
else if (c <= 8d+99) then
tmp = t_0
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 = ((d * b) + (c * a)) / ((d * d) + (c * c));
double tmp;
if (c <= -1.95e+143) {
tmp = (a + (b / (c * (1.0 / d)))) / c;
} else if (c <= -1.6e-97) {
tmp = t_0;
} else if (c <= 3.2e-141) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 8e+99) {
tmp = t_0;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((d * b) + (c * a)) / ((d * d) + (c * c)) tmp = 0 if c <= -1.95e+143: tmp = (a + (b / (c * (1.0 / d)))) / c elif c <= -1.6e-97: tmp = t_0 elif c <= 3.2e-141: tmp = (b + (a * (c / d))) / d elif c <= 8e+99: tmp = t_0 else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(d * b) + Float64(c * a)) / Float64(Float64(d * d) + Float64(c * c))) tmp = 0.0 if (c <= -1.95e+143) tmp = Float64(Float64(a + Float64(b / Float64(c * Float64(1.0 / d)))) / c); elseif (c <= -1.6e-97) tmp = t_0; elseif (c <= 3.2e-141) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 8e+99) tmp = t_0; 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 = ((d * b) + (c * a)) / ((d * d) + (c * c)); tmp = 0.0; if (c <= -1.95e+143) tmp = (a + (b / (c * (1.0 / d)))) / c; elseif (c <= -1.6e-97) tmp = t_0; elseif (c <= 3.2e-141) tmp = (b + (a * (c / d))) / d; elseif (c <= 8e+99) tmp = t_0; else tmp = (a + (d * (b / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(d * b), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.95e+143], N[(N[(a + N[(b / N[(c * N[(1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.6e-97], t$95$0, If[LessEqual[c, 3.2e-141], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8e+99], 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{d \cdot b + c \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{if}\;c \leq -1.95 \cdot 10^{+143}:\\
\;\;\;\;\frac{a + \frac{b}{c \cdot \frac{1}{d}}}{c}\\
\mathbf{elif}\;c \leq -1.6 \cdot 10^{-97}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 3.2 \cdot 10^{-141}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 8 \cdot 10^{+99}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -1.9499999999999999e143Initial program 37.4%
fma-define37.4%
fma-define37.4%
Simplified37.4%
Taylor expanded in c around inf 81.1%
*-commutative81.1%
Simplified81.1%
*-commutative81.1%
associate-*r/88.1%
*-commutative88.1%
Applied egg-rr88.1%
*-commutative88.1%
clear-num88.0%
un-div-inv88.1%
Applied egg-rr88.1%
div-inv88.1%
Applied egg-rr88.1%
if -1.9499999999999999e143 < c < -1.5999999999999999e-97 or 3.2000000000000001e-141 < c < 7.9999999999999997e99Initial program 85.7%
if -1.5999999999999999e-97 < c < 3.2000000000000001e-141Initial program 69.3%
fma-define69.3%
fma-define69.3%
Simplified69.3%
Taylor expanded in d around inf 87.8%
associate-/l*88.6%
Simplified88.6%
if 7.9999999999999997e99 < c Initial program 38.4%
fma-define38.4%
fma-define38.4%
Simplified38.4%
Taylor expanded in c around inf 71.7%
+-commutative71.7%
associate-/l*78.6%
fma-define78.6%
Simplified78.6%
fma-undefine78.6%
associate-*r/71.7%
*-commutative71.7%
associate-/l*80.8%
Applied egg-rr80.8%
Final simplification86.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.22e+23) (not (<= d 1.95e-50))) (/ (+ b (* a (/ c d))) d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.22e+23) || !(d <= 1.95e-50)) {
tmp = (b + (a * (c / d))) / 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 <= (-1.22d+23)) .or. (.not. (d <= 1.95d-50))) then
tmp = (b + (a * (c / d))) / 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 <= -1.22e+23) || !(d <= 1.95e-50)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.22e+23) or not (d <= 1.95e-50): tmp = (b + (a * (c / d))) / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.22e+23) || !(d <= 1.95e-50)) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / 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 <= -1.22e+23) || ~((d <= 1.95e-50))) tmp = (b + (a * (c / d))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.22e+23], N[Not[LessEqual[d, 1.95e-50]], $MachinePrecision]], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 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 -1.22 \cdot 10^{+23} \lor \neg \left(d \leq 1.95 \cdot 10^{-50}\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.22e23 or 1.9500000000000001e-50 < d Initial program 57.5%
fma-define57.6%
fma-define57.6%
Simplified57.6%
Taylor expanded in d around inf 76.0%
associate-/l*78.3%
Simplified78.3%
if -1.22e23 < d < 1.9500000000000001e-50Initial program 75.4%
fma-define75.4%
fma-define75.4%
Simplified75.4%
Taylor expanded in c around inf 83.6%
*-commutative83.6%
Simplified83.6%
*-commutative83.6%
associate-*r/83.9%
*-commutative83.9%
Applied egg-rr83.9%
Final simplification80.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.2e+24) (not (<= d 13500000.0))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.2e+24) || !(d <= 13500000.0)) {
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 <= (-4.2d+24)) .or. (.not. (d <= 13500000.0d0))) 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 <= -4.2e+24) || !(d <= 13500000.0)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.2e+24) or not (d <= 13500000.0): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.2e+24) || !(d <= 13500000.0)) 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 <= -4.2e+24) || ~((d <= 13500000.0))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.2e+24], N[Not[LessEqual[d, 13500000.0]], $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 -4.2 \cdot 10^{+24} \lor \neg \left(d \leq 13500000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -4.2000000000000003e24 or 1.35e7 < d Initial program 53.2%
fma-define53.3%
fma-define53.3%
Simplified53.3%
Taylor expanded in c around 0 67.8%
if -4.2000000000000003e24 < d < 1.35e7Initial program 77.8%
fma-define77.8%
fma-define77.8%
Simplified77.8%
Taylor expanded in c around inf 80.8%
*-commutative80.8%
Simplified80.8%
*-commutative80.8%
associate-*r/81.0%
*-commutative81.0%
Applied egg-rr81.0%
Final simplification74.4%
(FPCore (a b c d) :precision binary64 (if (<= d -1.45e+23) (/ (+ b (* a (/ c d))) d) (if (<= d 2.9e-50) (/ (+ a (* d (/ b c))) c) (/ (+ b (/ c (/ d a))) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.45e+23) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= 2.9e-50) {
tmp = (a + (d * (b / c))) / c;
} else {
tmp = (b + (c / (d / a))) / 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 (d <= (-1.45d+23)) then
tmp = (b + (a * (c / d))) / d
else if (d <= 2.9d-50) then
tmp = (a + (d * (b / c))) / c
else
tmp = (b + (c / (d / a))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.45e+23) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= 2.9e-50) {
tmp = (a + (d * (b / c))) / c;
} else {
tmp = (b + (c / (d / a))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.45e+23: tmp = (b + (a * (c / d))) / d elif d <= 2.9e-50: tmp = (a + (d * (b / c))) / c else: tmp = (b + (c / (d / a))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.45e+23) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= 2.9e-50) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); else tmp = Float64(Float64(b + Float64(c / Float64(d / a))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.45e+23) tmp = (b + (a * (c / d))) / d; elseif (d <= 2.9e-50) tmp = (a + (d * (b / c))) / c; else tmp = (b + (c / (d / a))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.45e+23], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 2.9e-50], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.45 \cdot 10^{+23}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq 2.9 \cdot 10^{-50}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\
\end{array}
\end{array}
if d < -1.45000000000000006e23Initial program 49.5%
fma-define49.5%
fma-define49.5%
Simplified49.5%
Taylor expanded in d around inf 76.4%
associate-/l*78.2%
Simplified78.2%
if -1.45000000000000006e23 < d < 2.90000000000000008e-50Initial program 75.4%
fma-define75.4%
fma-define75.4%
Simplified75.4%
Taylor expanded in c around inf 83.6%
+-commutative83.6%
associate-/l*83.9%
fma-define83.9%
Simplified83.9%
fma-undefine83.9%
associate-*r/83.6%
*-commutative83.6%
associate-/l*84.8%
Applied egg-rr84.8%
if 2.90000000000000008e-50 < d Initial program 63.7%
fma-define63.8%
fma-define63.8%
Simplified63.8%
Taylor expanded in d around inf 75.7%
add-sqr-sqrt39.8%
pow239.8%
*-commutative39.8%
associate-/l*46.2%
Applied egg-rr46.2%
unpow246.2%
add-sqr-sqrt79.7%
clear-num79.5%
un-div-inv79.6%
Applied egg-rr79.6%
Final simplification81.6%
(FPCore (a b c d) :precision binary64 (if (<= d -2.3e+26) (/ (+ b (* a (/ c d))) d) (if (<= d 1.75e-48) (/ (+ a (* b (/ d c))) c) (/ (+ b (/ c (/ d a))) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.3e+26) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= 1.75e-48) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + (c / (d / a))) / 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 (d <= (-2.3d+26)) then
tmp = (b + (a * (c / d))) / d
else if (d <= 1.75d-48) then
tmp = (a + (b * (d / c))) / c
else
tmp = (b + (c / (d / a))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.3e+26) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= 1.75e-48) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + (c / (d / a))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -2.3e+26: tmp = (b + (a * (c / d))) / d elif d <= 1.75e-48: tmp = (a + (b * (d / c))) / c else: tmp = (b + (c / (d / a))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -2.3e+26) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= 1.75e-48) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(Float64(b + Float64(c / Float64(d / a))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -2.3e+26) tmp = (b + (a * (c / d))) / d; elseif (d <= 1.75e-48) tmp = (a + (b * (d / c))) / c; else tmp = (b + (c / (d / a))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.3e+26], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.75e-48], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.3 \cdot 10^{+26}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq 1.75 \cdot 10^{-48}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\
\end{array}
\end{array}
if d < -2.3000000000000001e26Initial program 49.5%
fma-define49.5%
fma-define49.5%
Simplified49.5%
Taylor expanded in d around inf 76.4%
associate-/l*78.2%
Simplified78.2%
if -2.3000000000000001e26 < d < 1.74999999999999996e-48Initial program 75.4%
fma-define75.4%
fma-define75.4%
Simplified75.4%
Taylor expanded in c around inf 83.6%
*-commutative83.6%
Simplified83.6%
*-commutative83.6%
associate-*r/83.9%
*-commutative83.9%
Applied egg-rr83.9%
if 1.74999999999999996e-48 < d Initial program 63.7%
fma-define63.8%
fma-define63.8%
Simplified63.8%
Taylor expanded in d around inf 75.7%
add-sqr-sqrt39.8%
pow239.8%
*-commutative39.8%
associate-/l*46.2%
Applied egg-rr46.2%
unpow246.2%
add-sqr-sqrt79.7%
clear-num79.5%
un-div-inv79.6%
Applied egg-rr79.6%
Final simplification81.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5.4e-27) (not (<= d 1850.0))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5.4e-27) || !(d <= 1850.0)) {
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 <= (-5.4d-27)) .or. (.not. (d <= 1850.0d0))) 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 <= -5.4e-27) || !(d <= 1850.0)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5.4e-27) or not (d <= 1850.0): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5.4e-27) || !(d <= 1850.0)) 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 <= -5.4e-27) || ~((d <= 1850.0))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5.4e-27], N[Not[LessEqual[d, 1850.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.4 \cdot 10^{-27} \lor \neg \left(d \leq 1850\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -5.39999999999999978e-27 or 1850 < d Initial program 55.5%
fma-define55.5%
fma-define55.5%
Simplified55.5%
Taylor expanded in c around 0 65.0%
if -5.39999999999999978e-27 < d < 1850Initial program 77.9%
fma-define77.9%
fma-define77.9%
Simplified77.9%
Taylor expanded in c around inf 65.3%
Final simplification65.1%
(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 65.6%
fma-define65.6%
fma-define65.6%
Simplified65.6%
Taylor expanded in c around inf 38.0%
(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 2024133
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(! :herbie-platform default (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))))