
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 5e+257) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (+ b (* a (* c (/ 1.0 d)))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 5e+257) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (b + (a * (c * (1.0 / d)))) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= 5e+257) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(b + Float64(a * Float64(c * Float64(1.0 / d)))) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+257], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c * N[(1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 5 \cdot 10^{+257}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \left(c \cdot \frac{1}{d}\right)}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 5.00000000000000028e257Initial program 73.8%
fma-define73.8%
fma-define73.8%
Simplified73.8%
*-un-lft-identity73.8%
fma-define73.8%
add-sqr-sqrt73.8%
times-frac73.8%
fma-define73.8%
hypot-define73.8%
fma-define73.9%
fma-define73.9%
hypot-define96.8%
Applied egg-rr96.8%
if 5.00000000000000028e257 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 8.7%
fma-define8.7%
fma-define8.7%
Simplified8.7%
Taylor expanded in d around inf 56.1%
associate-/l*62.8%
Simplified62.8%
div-inv62.8%
Applied egg-rr62.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ a (/ (* b d) c))))
(if (<= d -5.5e+30)
(/ (+ b (/ c (/ d a))) d)
(if (<= d 2.4e-228)
(/ t_0 c)
(if (<= d 1.2e+114)
(* (/ 1.0 (hypot c d)) (/ (* c t_0) (hypot c d)))
(/ (+ b (* a (/ c d))) d))))))
double code(double a, double b, double c, double d) {
double t_0 = a + ((b * d) / c);
double tmp;
if (d <= -5.5e+30) {
tmp = (b + (c / (d / a))) / d;
} else if (d <= 2.4e-228) {
tmp = t_0 / c;
} else if (d <= 1.2e+114) {
tmp = (1.0 / hypot(c, d)) * ((c * t_0) / hypot(c, d));
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = a + ((b * d) / c);
double tmp;
if (d <= -5.5e+30) {
tmp = (b + (c / (d / a))) / d;
} else if (d <= 2.4e-228) {
tmp = t_0 / c;
} else if (d <= 1.2e+114) {
tmp = (1.0 / Math.hypot(c, d)) * ((c * t_0) / Math.hypot(c, d));
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = a + ((b * d) / c) tmp = 0 if d <= -5.5e+30: tmp = (b + (c / (d / a))) / d elif d <= 2.4e-228: tmp = t_0 / c elif d <= 1.2e+114: tmp = (1.0 / math.hypot(c, d)) * ((c * t_0) / math.hypot(c, d)) else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) t_0 = Float64(a + Float64(Float64(b * d) / c)) tmp = 0.0 if (d <= -5.5e+30) tmp = Float64(Float64(b + Float64(c / Float64(d / a))) / d); elseif (d <= 2.4e-228) tmp = Float64(t_0 / c); elseif (d <= 1.2e+114) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(Float64(c * t_0) / hypot(c, d))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = a + ((b * d) / c); tmp = 0.0; if (d <= -5.5e+30) tmp = (b + (c / (d / a))) / d; elseif (d <= 2.4e-228) tmp = t_0 / c; elseif (d <= 1.2e+114) tmp = (1.0 / hypot(c, d)) * ((c * t_0) / hypot(c, d)); else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.5e+30], N[(N[(b + N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 2.4e-228], N[(t$95$0 / c), $MachinePrecision], If[LessEqual[d, 1.2e+114], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(c * t$95$0), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a + \frac{b \cdot d}{c}\\
\mathbf{if}\;d \leq -5.5 \cdot 10^{+30}:\\
\;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\
\mathbf{elif}\;d \leq 2.4 \cdot 10^{-228}:\\
\;\;\;\;\frac{t\_0}{c}\\
\mathbf{elif}\;d \leq 1.2 \cdot 10^{+114}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot t\_0}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if d < -5.50000000000000025e30Initial program 33.3%
fma-define33.3%
fma-define33.3%
Simplified33.3%
Taylor expanded in d around inf 79.2%
associate-/l*81.5%
Simplified81.5%
clear-num80.8%
un-div-inv80.7%
Applied egg-rr80.7%
associate-/r/82.1%
Simplified82.1%
*-commutative82.1%
clear-num82.1%
un-div-inv82.1%
Applied egg-rr82.1%
if -5.50000000000000025e30 < d < 2.40000000000000002e-228Initial program 69.1%
fma-define69.1%
fma-define69.1%
Simplified69.1%
Taylor expanded in c around inf 88.4%
*-commutative88.4%
Simplified88.4%
if 2.40000000000000002e-228 < d < 1.2e114Initial program 79.1%
fma-define79.1%
fma-define79.1%
Simplified79.1%
*-un-lft-identity79.1%
fma-define79.1%
add-sqr-sqrt79.1%
times-frac79.3%
fma-define79.3%
hypot-define79.3%
fma-define79.3%
fma-define79.3%
hypot-define88.7%
Applied egg-rr88.7%
Taylor expanded in c around inf 81.0%
*-commutative81.0%
Simplified81.0%
if 1.2e114 < d Initial program 23.8%
fma-define23.8%
fma-define23.8%
Simplified23.8%
Taylor expanded in d around inf 85.3%
associate-/l*92.9%
Simplified92.9%
Final simplification85.6%
(FPCore (a b c d)
:precision binary64
(if (<= d -4.6e+30)
(/ (+ b (/ c (/ d a))) d)
(if (<= d 5.8e-153)
(/ (+ a (/ (* b d) c)) c)
(if (<= d 5.6e+69)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(/ (+ b (* a (/ c d))) d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4.6e+30) {
tmp = (b + (c / (d / a))) / d;
} else if (d <= 5.8e-153) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 5.6e+69) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-4.6d+30)) then
tmp = (b + (c / (d / a))) / d
else if (d <= 5.8d-153) then
tmp = (a + ((b * d) / c)) / c
else if (d <= 5.6d+69) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else
tmp = (b + (a * (c / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4.6e+30) {
tmp = (b + (c / (d / a))) / d;
} else if (d <= 5.8e-153) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 5.6e+69) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -4.6e+30: tmp = (b + (c / (d / a))) / d elif d <= 5.8e-153: tmp = (a + ((b * d) / c)) / c elif d <= 5.6e+69: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -4.6e+30) tmp = Float64(Float64(b + Float64(c / Float64(d / a))) / d); elseif (d <= 5.8e-153) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif (d <= 5.6e+69) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -4.6e+30) tmp = (b + (c / (d / a))) / d; elseif (d <= 5.8e-153) tmp = (a + ((b * d) / c)) / c; elseif (d <= 5.6e+69) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -4.6e+30], N[(N[(b + N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 5.8e-153], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.6e+69], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.6 \cdot 10^{+30}:\\
\;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\
\mathbf{elif}\;d \leq 5.8 \cdot 10^{-153}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 5.6 \cdot 10^{+69}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if d < -4.6e30Initial program 33.3%
fma-define33.3%
fma-define33.3%
Simplified33.3%
Taylor expanded in d around inf 79.2%
associate-/l*81.5%
Simplified81.5%
clear-num80.8%
un-div-inv80.7%
Applied egg-rr80.7%
associate-/r/82.1%
Simplified82.1%
*-commutative82.1%
clear-num82.1%
un-div-inv82.1%
Applied egg-rr82.1%
if -4.6e30 < d < 5.80000000000000004e-153Initial program 68.7%
fma-define68.7%
fma-define68.7%
Simplified68.7%
Taylor expanded in c around inf 87.4%
*-commutative87.4%
Simplified87.4%
if 5.80000000000000004e-153 < d < 5.59999999999999964e69Initial program 85.6%
if 5.59999999999999964e69 < d Initial program 32.6%
fma-define32.6%
fma-define32.6%
Simplified32.6%
Taylor expanded in d around inf 80.9%
associate-/l*86.9%
Simplified86.9%
Final simplification85.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -7.6e+30) (not (<= d 1.9e-39))) (/ (+ b (* a (/ c d))) d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.6e+30) || !(d <= 1.9e-39)) {
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 <= (-7.6d+30)) .or. (.not. (d <= 1.9d-39))) 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 <= -7.6e+30) || !(d <= 1.9e-39)) {
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 <= -7.6e+30) or not (d <= 1.9e-39): 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 <= -7.6e+30) || !(d <= 1.9e-39)) 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 <= -7.6e+30) || ~((d <= 1.9e-39))) 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, -7.6e+30], N[Not[LessEqual[d, 1.9e-39]], $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 -7.6 \cdot 10^{+30} \lor \neg \left(d \leq 1.9 \cdot 10^{-39}\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 < -7.6000000000000003e30 or 1.9000000000000001e-39 < d Initial program 39.5%
fma-define39.5%
fma-define39.5%
Simplified39.5%
Taylor expanded in d around inf 78.8%
associate-/l*82.2%
Simplified82.2%
if -7.6000000000000003e30 < d < 1.9000000000000001e-39Initial program 72.5%
fma-define72.5%
fma-define72.5%
Simplified72.5%
Taylor expanded in c around inf 85.1%
*-commutative85.1%
Simplified85.1%
Final simplification83.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.05e+31) (not (<= d 9.6e-35))) (/ b d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.05e+31) || !(d <= 9.6e-35)) {
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 <= (-1.05d+31)) .or. (.not. (d <= 9.6d-35))) 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 <= -1.05e+31) || !(d <= 9.6e-35)) {
tmp = b / d;
} else {
tmp = (a + ((b * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.05e+31) or not (d <= 9.6e-35): tmp = b / d else: tmp = (a + ((b * d) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.05e+31) || !(d <= 9.6e-35)) 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 <= -1.05e+31) || ~((d <= 9.6e-35))) tmp = b / d; else tmp = (a + ((b * d) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.05e+31], N[Not[LessEqual[d, 9.6e-35]], $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 -1.05 \cdot 10^{+31} \lor \neg \left(d \leq 9.6 \cdot 10^{-35}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.04999999999999989e31 or 9.6000000000000005e-35 < d Initial program 39.5%
fma-define39.5%
fma-define39.5%
Simplified39.5%
Taylor expanded in c around 0 72.7%
if -1.04999999999999989e31 < d < 9.6000000000000005e-35Initial program 72.5%
fma-define72.5%
fma-define72.5%
Simplified72.5%
Taylor expanded in c around inf 85.1%
*-commutative85.1%
Simplified85.1%
Final simplification78.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1e+31) (not (<= d 9.6e-35))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1e+31) || !(d <= 9.6e-35)) {
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 <= (-1d+31)) .or. (.not. (d <= 9.6d-35))) 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 <= -1e+31) || !(d <= 9.6e-35)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1e+31) or not (d <= 9.6e-35): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1e+31) || !(d <= 9.6e-35)) 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 <= -1e+31) || ~((d <= 9.6e-35))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1e+31], N[Not[LessEqual[d, 9.6e-35]], $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 -1 \cdot 10^{+31} \lor \neg \left(d \leq 9.6 \cdot 10^{-35}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -9.9999999999999996e30 or 9.6000000000000005e-35 < d Initial program 39.5%
fma-define39.5%
fma-define39.5%
Simplified39.5%
Taylor expanded in c around 0 72.7%
if -9.9999999999999996e30 < d < 9.6000000000000005e-35Initial program 72.5%
fma-define72.5%
fma-define72.5%
Simplified72.5%
*-un-lft-identity72.5%
fma-define72.5%
add-sqr-sqrt72.5%
times-frac72.5%
fma-define72.5%
hypot-define72.5%
fma-define72.5%
fma-define72.5%
hypot-define83.0%
Applied egg-rr83.0%
Taylor expanded in c around inf 85.1%
associate-/l*84.6%
Simplified84.6%
Final simplification78.2%
(FPCore (a b c d) :precision binary64 (if (<= d -5.8e+30) (/ (+ b (/ c (/ d a))) d) (if (<= d 1.9e-35) (/ (+ a (/ (* b d) c)) c) (/ (+ b (* a (/ c d))) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -5.8e+30) {
tmp = (b + (c / (d / a))) / d;
} else if (d <= 1.9e-35) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-5.8d+30)) then
tmp = (b + (c / (d / a))) / d
else if (d <= 1.9d-35) then
tmp = (a + ((b * d) / c)) / c
else
tmp = (b + (a * (c / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -5.8e+30) {
tmp = (b + (c / (d / a))) / d;
} else if (d <= 1.9e-35) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -5.8e+30: tmp = (b + (c / (d / a))) / d elif d <= 1.9e-35: tmp = (a + ((b * d) / c)) / c else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -5.8e+30) tmp = Float64(Float64(b + Float64(c / Float64(d / a))) / d); elseif (d <= 1.9e-35) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -5.8e+30) tmp = (b + (c / (d / a))) / d; elseif (d <= 1.9e-35) tmp = (a + ((b * d) / c)) / c; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -5.8e+30], N[(N[(b + N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.9e-35], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.8 \cdot 10^{+30}:\\
\;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\
\mathbf{elif}\;d \leq 1.9 \cdot 10^{-35}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if d < -5.7999999999999996e30Initial program 33.3%
fma-define33.3%
fma-define33.3%
Simplified33.3%
Taylor expanded in d around inf 79.2%
associate-/l*81.5%
Simplified81.5%
clear-num80.8%
un-div-inv80.7%
Applied egg-rr80.7%
associate-/r/82.1%
Simplified82.1%
*-commutative82.1%
clear-num82.1%
un-div-inv82.1%
Applied egg-rr82.1%
if -5.7999999999999996e30 < d < 1.9000000000000001e-35Initial program 72.5%
fma-define72.5%
fma-define72.5%
Simplified72.5%
Taylor expanded in c around inf 85.1%
*-commutative85.1%
Simplified85.1%
if 1.9000000000000001e-35 < d Initial program 45.8%
fma-define45.8%
fma-define45.8%
Simplified45.8%
Taylor expanded in d around inf 78.5%
associate-/l*82.9%
Simplified82.9%
Final simplification83.7%
(FPCore (a b c d) :precision binary64 (if (<= d -4.4e+30) (/ (+ b (* c (/ a d))) d) (if (<= d 1.3e-35) (/ (+ a (/ (* b d) c)) c) (/ (+ b (* a (/ c d))) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4.4e+30) {
tmp = (b + (c * (a / d))) / d;
} else if (d <= 1.3e-35) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-4.4d+30)) then
tmp = (b + (c * (a / d))) / d
else if (d <= 1.3d-35) then
tmp = (a + ((b * d) / c)) / c
else
tmp = (b + (a * (c / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4.4e+30) {
tmp = (b + (c * (a / d))) / d;
} else if (d <= 1.3e-35) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -4.4e+30: tmp = (b + (c * (a / d))) / d elif d <= 1.3e-35: tmp = (a + ((b * d) / c)) / c else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -4.4e+30) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); elseif (d <= 1.3e-35) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -4.4e+30) tmp = (b + (c * (a / d))) / d; elseif (d <= 1.3e-35) tmp = (a + ((b * d) / c)) / c; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -4.4e+30], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.3e-35], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.4 \cdot 10^{+30}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{elif}\;d \leq 1.3 \cdot 10^{-35}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if d < -4.4e30Initial program 33.3%
fma-define33.3%
fma-define33.3%
Simplified33.3%
Taylor expanded in d around inf 79.2%
associate-/l*81.5%
Simplified81.5%
clear-num80.8%
un-div-inv80.7%
Applied egg-rr80.7%
associate-/r/82.1%
Simplified82.1%
if -4.4e30 < d < 1.30000000000000002e-35Initial program 72.5%
fma-define72.5%
fma-define72.5%
Simplified72.5%
Taylor expanded in c around inf 85.1%
*-commutative85.1%
Simplified85.1%
if 1.30000000000000002e-35 < d Initial program 45.8%
fma-define45.8%
fma-define45.8%
Simplified45.8%
Taylor expanded in d around inf 78.5%
associate-/l*82.9%
Simplified82.9%
Final simplification83.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5e+30) (not (<= d 3.8e-37))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5e+30) || !(d <= 3.8e-37)) {
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 <= (-5d+30)) .or. (.not. (d <= 3.8d-37))) 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 <= -5e+30) || !(d <= 3.8e-37)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5e+30) or not (d <= 3.8e-37): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5e+30) || !(d <= 3.8e-37)) 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 <= -5e+30) || ~((d <= 3.8e-37))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5e+30], N[Not[LessEqual[d, 3.8e-37]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5 \cdot 10^{+30} \lor \neg \left(d \leq 3.8 \cdot 10^{-37}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -4.9999999999999998e30 or 3.8000000000000004e-37 < d Initial program 39.5%
fma-define39.5%
fma-define39.5%
Simplified39.5%
Taylor expanded in c around 0 72.7%
if -4.9999999999999998e30 < d < 3.8000000000000004e-37Initial program 72.5%
fma-define72.5%
fma-define72.5%
Simplified72.5%
Taylor expanded in c around inf 67.6%
Final simplification70.3%
(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 54.7%
fma-define54.7%
fma-define54.7%
Simplified54.7%
Taylor expanded in c around inf 39.6%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024181
(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))))