
(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 8 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 (<= d -1.2e+23)
(* (/ d (hypot d c)) (/ b (hypot d c)))
(if (<= d -8e-44)
t_0
(if (<= d 6.8e-139)
(/ (+ a (/ (* b d) c)) c)
(if (<= d 2.06e+77) t_0 (/ (+ b (* c (/ a d))) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.2e+23) {
tmp = (d / hypot(d, c)) * (b / hypot(d, c));
} else if (d <= -8e-44) {
tmp = t_0;
} else if (d <= 6.8e-139) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 2.06e+77) {
tmp = t_0;
} else {
tmp = (b + (c * (a / d))) / d;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.2e+23) {
tmp = (d / Math.hypot(d, c)) * (b / Math.hypot(d, c));
} else if (d <= -8e-44) {
tmp = t_0;
} else if (d <= 6.8e-139) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 2.06e+77) {
tmp = t_0;
} else {
tmp = (b + (c * (a / d))) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -1.2e+23: tmp = (d / math.hypot(d, c)) * (b / math.hypot(d, c)) elif d <= -8e-44: tmp = t_0 elif d <= 6.8e-139: tmp = (a + ((b * d) / c)) / c elif d <= 2.06e+77: tmp = t_0 else: tmp = (b + (c * (a / d))) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (d <= -1.2e+23) tmp = Float64(Float64(d / hypot(d, c)) * Float64(b / hypot(d, c))); elseif (d <= -8e-44) tmp = t_0; elseif (d <= 6.8e-139) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif (d <= 2.06e+77) tmp = t_0; else tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -1.2e+23) tmp = (d / hypot(d, c)) * (b / hypot(d, c)); elseif (d <= -8e-44) tmp = t_0; elseif (d <= 6.8e-139) tmp = (a + ((b * d) / c)) / c; elseif (d <= 2.06e+77) tmp = t_0; else tmp = (b + (c * (a / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.2e+23], N[(N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -8e-44], t$95$0, If[LessEqual[d, 6.8e-139], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.06e+77], t$95$0, N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -1.2 \cdot 10^{+23}:\\
\;\;\;\;\frac{d}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;d \leq -8 \cdot 10^{-44}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 6.8 \cdot 10^{-139}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.06 \cdot 10^{+77}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\end{array}
\end{array}
if d < -1.2e23Initial program 38.8%
Taylor expanded in a around 0 34.6%
*-commutative34.6%
Simplified34.6%
*-un-lft-identity34.6%
add-sqr-sqrt34.6%
hypot-undefine34.6%
hypot-undefine34.6%
times-frac46.2%
Applied egg-rr46.2%
associate-*l/46.3%
*-lft-identity46.3%
associate-/l*81.3%
associate-*l/81.3%
hypot-undefine42.1%
unpow242.1%
unpow242.1%
+-commutative42.1%
unpow242.1%
unpow242.1%
hypot-define81.3%
hypot-undefine42.1%
unpow242.1%
unpow242.1%
+-commutative42.1%
unpow242.1%
unpow242.1%
hypot-define81.3%
Simplified81.3%
if -1.2e23 < d < -7.99999999999999962e-44 or 6.79999999999999998e-139 < d < 2.06e77Initial program 80.3%
if -7.99999999999999962e-44 < d < 6.79999999999999998e-139Initial program 64.5%
Taylor expanded in c around inf 90.4%
*-commutative90.4%
Simplified90.4%
if 2.06e77 < d Initial program 40.8%
Taylor expanded in d around inf 73.4%
associate-/l*82.5%
Simplified82.5%
clear-num82.5%
un-div-inv82.5%
Applied egg-rr82.5%
associate-/r/84.9%
Simplified84.9%
Final simplification85.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= t_0 (- INFINITY))
(/ (+ b (/ a (/ d c))) d)
(if (<= t_0 4e+238)
(* (/ 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 t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = (b + (a / (d / c))) / d;
} else if (t_0 <= 4e+238) {
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) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d); elseif (t_0 <= 4e+238) 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_] := 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[t$95$0, (-Infinity)], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[t$95$0, 4e+238], 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}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+238}:\\
\;\;\;\;\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))) < -inf.0Initial program 54.4%
Taylor expanded in d around inf 83.4%
associate-/l*87.5%
Simplified87.5%
clear-num87.5%
un-div-inv87.6%
Applied egg-rr87.6%
if -inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 4.0000000000000002e238Initial program 78.7%
*-un-lft-identity78.7%
add-sqr-sqrt78.7%
times-frac78.7%
hypot-define78.7%
fma-define78.7%
hypot-define97.3%
Applied egg-rr97.3%
if 4.0000000000000002e238 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 14.4%
*-un-lft-identity14.4%
add-sqr-sqrt14.4%
times-frac14.4%
hypot-define14.4%
fma-define14.4%
hypot-define22.1%
Applied egg-rr22.1%
Taylor expanded in c around inf 52.4%
associate-/l*60.9%
Simplified60.9%
clear-num61.0%
un-div-inv61.0%
Applied egg-rr61.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ b (* c (/ a d))) d)))
(if (<= d -1.3e-43)
t_0
(if (<= d 2.05e-140)
(/ (+ a (/ (* b d) c)) c)
(if (<= d 1.85e+77) (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b + (c * (a / d))) / d;
double tmp;
if (d <= -1.3e-43) {
tmp = t_0;
} else if (d <= 2.05e-140) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 1.85e+77) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
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 + (c * (a / d))) / d
if (d <= (-1.3d-43)) then
tmp = t_0
else if (d <= 2.05d-140) then
tmp = (a + ((b * d) / c)) / c
else if (d <= 1.85d+77) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b + (c * (a / d))) / d;
double tmp;
if (d <= -1.3e-43) {
tmp = t_0;
} else if (d <= 2.05e-140) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 1.85e+77) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b + (c * (a / d))) / d tmp = 0 if d <= -1.3e-43: tmp = t_0 elif d <= 2.05e-140: tmp = (a + ((b * d) / c)) / c elif d <= 1.85e+77: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b + Float64(c * Float64(a / d))) / d) tmp = 0.0 if (d <= -1.3e-43) tmp = t_0; elseif (d <= 2.05e-140) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif (d <= 1.85e+77) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b + (c * (a / d))) / d; tmp = 0.0; if (d <= -1.3e-43) tmp = t_0; elseif (d <= 2.05e-140) tmp = (a + ((b * d) / c)) / c; elseif (d <= 1.85e+77) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.3e-43], t$95$0, If[LessEqual[d, 2.05e-140], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.85e+77], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{if}\;d \leq -1.3 \cdot 10^{-43}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.05 \cdot 10^{-140}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.85 \cdot 10^{+77}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.3e-43 or 1.84999999999999997e77 < d Initial program 45.2%
Taylor expanded in d around inf 74.3%
associate-/l*78.3%
Simplified78.3%
clear-num78.1%
un-div-inv78.1%
Applied egg-rr78.1%
associate-/r/79.9%
Simplified79.9%
if -1.3e-43 < d < 2.0500000000000001e-140Initial program 64.5%
Taylor expanded in c around inf 90.4%
*-commutative90.4%
Simplified90.4%
if 2.0500000000000001e-140 < d < 1.84999999999999997e77Initial program 75.3%
Final simplification83.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.15e-43) (not (<= d 5.5e+56))) (/ (+ b (* c (/ a d))) d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.15e-43) || !(d <= 5.5e+56)) {
tmp = (b + (c * (a / 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.15d-43)) .or. (.not. (d <= 5.5d+56))) then
tmp = (b + (c * (a / 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.15e-43) || !(d <= 5.5e+56)) {
tmp = (b + (c * (a / d))) / d;
} else {
tmp = (a + ((b * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.15e-43) or not (d <= 5.5e+56): tmp = (b + (c * (a / d))) / d else: tmp = (a + ((b * d) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.15e-43) || !(d <= 5.5e+56)) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / 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 <= -1.15e-43) || ~((d <= 5.5e+56))) tmp = (b + (c * (a / d))) / d; else tmp = (a + ((b * d) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.15e-43], N[Not[LessEqual[d, 5.5e+56]], $MachinePrecision]], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 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 -1.15 \cdot 10^{-43} \lor \neg \left(d \leq 5.5 \cdot 10^{+56}\right):\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.1499999999999999e-43 or 5.5000000000000002e56 < d Initial program 46.5%
Taylor expanded in d around inf 73.7%
associate-/l*77.6%
Simplified77.6%
clear-num77.4%
un-div-inv77.4%
Applied egg-rr77.4%
associate-/r/79.1%
Simplified79.1%
if -1.1499999999999999e-43 < d < 5.5000000000000002e56Initial program 66.6%
Taylor expanded in c around inf 83.4%
*-commutative83.4%
Simplified83.4%
Final simplification81.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -8.2e-44) (not (<= d 2.05e-14))) (/ (+ b (* a (/ c d))) d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -8.2e-44) || !(d <= 2.05e-14)) {
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 <= (-8.2d-44)) .or. (.not. (d <= 2.05d-14))) 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 <= -8.2e-44) || !(d <= 2.05e-14)) {
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 <= -8.2e-44) or not (d <= 2.05e-14): 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 <= -8.2e-44) || !(d <= 2.05e-14)) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / 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 <= -8.2e-44) || ~((d <= 2.05e-14))) 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, -8.2e-44], N[Not[LessEqual[d, 2.05e-14]], $MachinePrecision]], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 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 -8.2 \cdot 10^{-44} \lor \neg \left(d \leq 2.05 \cdot 10^{-14}\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -8.19999999999999984e-44 or 2.0500000000000001e-14 < d Initial program 48.9%
Taylor expanded in d around inf 72.4%
associate-/l*76.1%
Simplified76.1%
if -8.19999999999999984e-44 < d < 2.0500000000000001e-14Initial program 65.2%
Taylor expanded in c around inf 85.5%
*-commutative85.5%
Simplified85.5%
Final simplification80.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -7.2e+50) (not (<= d 5.4e+57))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.2e+50) || !(d <= 5.4e+57)) {
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.2d+50)) .or. (.not. (d <= 5.4d+57))) 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.2e+50) || !(d <= 5.4e+57)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -7.2e+50) or not (d <= 5.4e+57): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -7.2e+50) || !(d <= 5.4e+57)) 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.2e+50) || ~((d <= 5.4e+57))) 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.2e+50], N[Not[LessEqual[d, 5.4e+57]], $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.2 \cdot 10^{+50} \lor \neg \left(d \leq 5.4 \cdot 10^{+57}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -7.19999999999999972e50 or 5.3999999999999997e57 < d Initial program 42.5%
Taylor expanded in c around 0 70.3%
if -7.19999999999999972e50 < d < 5.3999999999999997e57Initial program 67.6%
*-un-lft-identity67.6%
add-sqr-sqrt67.6%
times-frac67.6%
hypot-define67.7%
fma-define67.7%
hypot-define80.9%
Applied egg-rr80.9%
Taylor expanded in c around inf 78.5%
associate-/l*78.5%
Simplified78.5%
Final simplification74.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3.85e+102) (not (<= c 2.4e+43))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.85e+102) || !(c <= 2.4e+43)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-3.85d+102)) .or. (.not. (c <= 2.4d+43))) then
tmp = a / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.85e+102) || !(c <= 2.4e+43)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3.85e+102) or not (c <= 2.4e+43): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.85e+102) || !(c <= 2.4e+43)) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -3.85e+102) || ~((c <= 2.4e+43))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.85e+102], N[Not[LessEqual[c, 2.4e+43]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.85 \cdot 10^{+102} \lor \neg \left(c \leq 2.4 \cdot 10^{+43}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -3.85000000000000007e102 or 2.40000000000000023e43 < c Initial program 38.5%
Taylor expanded in c around inf 74.1%
if -3.85000000000000007e102 < c < 2.40000000000000023e43Initial program 67.4%
Taylor expanded in c around 0 61.0%
Final simplification66.0%
(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 56.4%
Taylor expanded in c around inf 40.7%
(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 2024165
(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))))