
(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 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -6.6e+85)
(/ (+ a (* b (/ d c))) c)
(if (<= c -4.6e-158)
t_0
(if (<= c 1.05e-94)
(/ (+ b (* a (/ c d))) d)
(if (<= c 4.8e+60) t_0 (* (/ 1.0 (hypot c d)) (fma b (/ d c) a))))))))
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 <= -6.6e+85) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -4.6e-158) {
tmp = t_0;
} else if (c <= 1.05e-94) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 4.8e+60) {
tmp = t_0;
} else {
tmp = (1.0 / hypot(c, d)) * fma(b, (d / c), a);
}
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 <= -6.6e+85) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= -4.6e-158) tmp = t_0; elseif (c <= 1.05e-94) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 4.8e+60) tmp = t_0; else tmp = Float64(Float64(1.0 / hypot(c, d)) * fma(b, Float64(d / c), a)); end return 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, -6.6e+85], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -4.6e-158], t$95$0, If[LessEqual[c, 1.05e-94], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.8e+60], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -6.6 \cdot 10^{+85}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -4.6 \cdot 10^{-158}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.05 \cdot 10^{-94}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 4.8 \cdot 10^{+60}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \mathsf{fma}\left(b, \frac{d}{c}, a\right)\\
\end{array}
\end{array}
if c < -6.5999999999999998e85Initial program 27.4%
Taylor expanded in c around inf 69.3%
associate-/l*81.8%
Simplified81.8%
if -6.5999999999999998e85 < c < -4.5999999999999998e-158 or 1.05e-94 < c < 4.8e60Initial program 81.3%
if -4.5999999999999998e-158 < c < 1.05e-94Initial program 73.3%
Taylor expanded in d around inf 94.4%
associate-/l*95.5%
Simplified95.5%
if 4.8e60 < c Initial program 43.6%
*-un-lft-identity43.6%
add-sqr-sqrt43.6%
times-frac43.5%
hypot-define43.5%
fma-define43.5%
hypot-define64.8%
Applied egg-rr64.8%
Taylor expanded in c around inf 84.3%
+-commutative84.3%
associate-/l*90.0%
fma-undefine90.0%
Simplified90.0%
Final simplification87.7%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 2e+304) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (+ a (/ b (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 2e+304) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (a + (b / (c / d))) / c;
}
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))) <= 2e+304) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); 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], 2e+304], 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[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+304}:\\
\;\;\;\;\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{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.9999999999999999e304Initial program 77.1%
*-un-lft-identity77.1%
add-sqr-sqrt77.1%
times-frac77.1%
hypot-define77.1%
fma-define77.1%
hypot-define94.7%
Applied egg-rr94.7%
if 1.9999999999999999e304 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 13.5%
Taylor expanded in c around inf 50.6%
associate-/l*64.4%
Simplified64.4%
clear-num64.4%
un-div-inv64.4%
Applied egg-rr64.4%
Final simplification87.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -5.3e+85)
(/ (+ a (* b (/ d c))) c)
(if (<= c -1.25e-157)
t_0
(if (<= c 3.6e-94)
(/ (+ b (* a (/ c d))) d)
(if (<= c 6.6e+63) 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 <= -5.3e+85) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -1.25e-157) {
tmp = t_0;
} else if (c <= 3.6e-94) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 6.6e+63) {
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 <= (-5.3d+85)) then
tmp = (a + (b * (d / c))) / c
else if (c <= (-1.25d-157)) then
tmp = t_0
else if (c <= 3.6d-94) then
tmp = (b + (a * (c / d))) / d
else if (c <= 6.6d+63) 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 <= -5.3e+85) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -1.25e-157) {
tmp = t_0;
} else if (c <= 3.6e-94) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 6.6e+63) {
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 <= -5.3e+85: tmp = (a + (b * (d / c))) / c elif c <= -1.25e-157: tmp = t_0 elif c <= 3.6e-94: tmp = (b + (a * (c / d))) / d elif c <= 6.6e+63: 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 <= -5.3e+85) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= -1.25e-157) tmp = t_0; elseif (c <= 3.6e-94) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 6.6e+63) 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 <= -5.3e+85) tmp = (a + (b * (d / c))) / c; elseif (c <= -1.25e-157) tmp = t_0; elseif (c <= 3.6e-94) tmp = (b + (a * (c / d))) / d; elseif (c <= 6.6e+63) 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, -5.3e+85], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.25e-157], t$95$0, If[LessEqual[c, 3.6e-94], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 6.6e+63], 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 -5.3 \cdot 10^{+85}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -1.25 \cdot 10^{-157}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 3.6 \cdot 10^{-94}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 6.6 \cdot 10^{+63}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -5.2999999999999999e85Initial program 27.4%
Taylor expanded in c around inf 69.3%
associate-/l*81.8%
Simplified81.8%
if -5.2999999999999999e85 < c < -1.25000000000000005e-157 or 3.6e-94 < c < 6.6000000000000003e63Initial program 81.3%
if -1.25000000000000005e-157 < c < 3.6e-94Initial program 73.3%
Taylor expanded in d around inf 94.4%
associate-/l*95.5%
Simplified95.5%
if 6.6000000000000003e63 < c Initial program 43.6%
Taylor expanded in c around inf 82.7%
associate-/l*88.4%
Simplified88.4%
clear-num88.5%
un-div-inv88.5%
Applied egg-rr88.5%
Final simplification87.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ b (* a (/ c d))) d)))
(if (<= c -1.02e+102)
(/ (+ a (/ b (/ c d))) c)
(if (<= c -4.3e+30)
t_0
(if (<= c -2.25e-40)
(/ (+ a (/ (* b d) c)) c)
(if (<= c 7.6e-17) t_0 (/ (+ a (* b (/ d c))) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = (b + (a * (c / d))) / d;
double tmp;
if (c <= -1.02e+102) {
tmp = (a + (b / (c / d))) / c;
} else if (c <= -4.3e+30) {
tmp = t_0;
} else if (c <= -2.25e-40) {
tmp = (a + ((b * d) / c)) / c;
} else if (c <= 7.6e-17) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = (b + (a * (c / d))) / d
if (c <= (-1.02d+102)) then
tmp = (a + (b / (c / d))) / c
else if (c <= (-4.3d+30)) then
tmp = t_0
else if (c <= (-2.25d-40)) then
tmp = (a + ((b * d) / c)) / c
else if (c <= 7.6d-17) then
tmp = t_0
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 t_0 = (b + (a * (c / d))) / d;
double tmp;
if (c <= -1.02e+102) {
tmp = (a + (b / (c / d))) / c;
} else if (c <= -4.3e+30) {
tmp = t_0;
} else if (c <= -2.25e-40) {
tmp = (a + ((b * d) / c)) / c;
} else if (c <= 7.6e-17) {
tmp = t_0;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b + (a * (c / d))) / d tmp = 0 if c <= -1.02e+102: tmp = (a + (b / (c / d))) / c elif c <= -4.3e+30: tmp = t_0 elif c <= -2.25e-40: tmp = (a + ((b * d) / c)) / c elif c <= 7.6e-17: tmp = t_0 else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b + Float64(a * Float64(c / d))) / d) tmp = 0.0 if (c <= -1.02e+102) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); elseif (c <= -4.3e+30) tmp = t_0; elseif (c <= -2.25e-40) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif (c <= 7.6e-17) tmp = t_0; else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b + (a * (c / d))) / d; tmp = 0.0; if (c <= -1.02e+102) tmp = (a + (b / (c / d))) / c; elseif (c <= -4.3e+30) tmp = t_0; elseif (c <= -2.25e-40) tmp = (a + ((b * d) / c)) / c; elseif (c <= 7.6e-17) tmp = t_0; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[c, -1.02e+102], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -4.3e+30], t$95$0, If[LessEqual[c, -2.25e-40], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 7.6e-17], t$95$0, N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{if}\;c \leq -1.02 \cdot 10^{+102}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\mathbf{elif}\;c \leq -4.3 \cdot 10^{+30}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -2.25 \cdot 10^{-40}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;c \leq 7.6 \cdot 10^{-17}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -1.01999999999999999e102Initial program 29.7%
Taylor expanded in c around inf 75.2%
associate-/l*90.1%
Simplified90.1%
clear-num90.1%
un-div-inv90.2%
Applied egg-rr90.2%
if -1.01999999999999999e102 < c < -4.3e30 or -2.25e-40 < c < 7.6000000000000002e-17Initial program 73.2%
Taylor expanded in d around inf 83.9%
associate-/l*86.0%
Simplified86.0%
if -4.3e30 < c < -2.25e-40Initial program 87.8%
Taylor expanded in c around inf 77.3%
if 7.6000000000000002e-17 < c Initial program 49.1%
Taylor expanded in c around inf 76.5%
associate-/l*80.2%
Simplified80.2%
Final simplification84.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.16) (not (<= d 6.2e+22))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.16) || !(d <= 6.2e+22)) {
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 <= (-0.16d0)) .or. (.not. (d <= 6.2d+22))) 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 <= -0.16) || !(d <= 6.2e+22)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.16) or not (d <= 6.2e+22): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.16) || !(d <= 6.2e+22)) 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 <= -0.16) || ~((d <= 6.2e+22))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.16], N[Not[LessEqual[d, 6.2e+22]], $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 -0.16 \lor \neg \left(d \leq 6.2 \cdot 10^{+22}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -0.160000000000000003 or 6.2000000000000004e22 < d Initial program 51.5%
Taylor expanded in c around 0 69.2%
if -0.160000000000000003 < d < 6.2000000000000004e22Initial program 70.5%
Taylor expanded in c around inf 80.9%
associate-/l*80.4%
Simplified80.4%
Final simplification75.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1250.0) (not (<= d 6.6e+22))) (/ b d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1250.0) || !(d <= 6.6e+22)) {
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 <= (-1250.0d0)) .or. (.not. (d <= 6.6d+22))) 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 <= -1250.0) || !(d <= 6.6e+22)) {
tmp = b / d;
} else {
tmp = (a + ((b * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1250.0) or not (d <= 6.6e+22): tmp = b / d else: tmp = (a + ((b * d) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1250.0) || !(d <= 6.6e+22)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1250.0) || ~((d <= 6.6e+22))) tmp = b / d; else tmp = (a + ((b * d) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1250.0], N[Not[LessEqual[d, 6.6e+22]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1250 \lor \neg \left(d \leq 6.6 \cdot 10^{+22}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -1250 or 6.5999999999999996e22 < d Initial program 51.5%
Taylor expanded in c around 0 69.2%
if -1250 < d < 6.5999999999999996e22Initial program 70.5%
Taylor expanded in c around inf 80.9%
Final simplification75.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.00025) (not (<= d 4.9e+22))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.00025) || !(d <= 4.9e+22)) {
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 <= (-0.00025d0)) .or. (.not. (d <= 4.9d+22))) 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 <= -0.00025) || !(d <= 4.9e+22)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.00025) or not (d <= 4.9e+22): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.00025) || !(d <= 4.9e+22)) 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 <= -0.00025) || ~((d <= 4.9e+22))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.00025], N[Not[LessEqual[d, 4.9e+22]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.00025 \lor \neg \left(d \leq 4.9 \cdot 10^{+22}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -2.5000000000000001e-4 or 4.89999999999999979e22 < d Initial program 51.5%
Taylor expanded in c around 0 69.2%
if -2.5000000000000001e-4 < d < 4.89999999999999979e22Initial program 70.5%
Taylor expanded in c around inf 64.0%
Final simplification66.5%
(FPCore (a b c d) :precision binary64 (if (<= d -1.65e+167) (/ a d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.65e+167) {
tmp = a / d;
} else {
tmp = a / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-1.65d+167)) then
tmp = a / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.65e+167) {
tmp = a / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.65e+167: tmp = a / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.65e+167) tmp = Float64(a / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.65e+167) tmp = a / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.65e+167], N[(a / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.65 \cdot 10^{+167}:\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -1.65000000000000009e167Initial program 41.2%
*-un-lft-identity41.2%
add-sqr-sqrt41.2%
times-frac41.2%
hypot-define41.2%
fma-define41.2%
hypot-define61.0%
Applied egg-rr61.0%
Taylor expanded in c around inf 12.7%
+-commutative12.7%
associate-/l*15.5%
fma-undefine15.5%
Simplified15.5%
Taylor expanded in d around inf 9.9%
Taylor expanded in a around inf 27.0%
if -1.65000000000000009e167 < d Initial program 64.1%
Taylor expanded in c around inf 44.6%
Final simplification42.5%
(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 61.4%
Taylor expanded in c around inf 40.8%
Final simplification40.8%
(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 2024075
(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))))