
(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))) INFINITY) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (* (/ d (hypot c d)) (/ b (hypot c d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (d / hypot(c, d)) * (b / hypot(c, 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))) <= Inf) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(d / hypot(c, d)) * Float64(b / hypot(c, 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], Infinity], 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[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\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{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 77.4%
*-un-lft-identity77.4%
associate-*r/77.4%
fma-define77.4%
add-sqr-sqrt77.4%
times-frac77.4%
fma-define77.4%
hypot-define77.4%
fma-define77.4%
fma-define77.4%
hypot-define93.7%
Applied egg-rr93.7%
if +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 0.0%
Taylor expanded in a around 0 1.4%
*-commutative1.4%
add-sqr-sqrt1.4%
hypot-undefine1.4%
hypot-undefine1.4%
times-frac61.6%
Applied egg-rr61.6%
Final simplification88.1%
(FPCore (a b c d)
:precision binary64
(if (<= d -3e+45)
(* (+ b (* a (/ c d))) (/ -1.0 (hypot c d)))
(if (<= d -2.2e-131)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 2.2e-65)
(/ (+ a (/ (* b d) c)) c)
(/ 1.0 (/ (hypot c d) (fma a (/ c d) b)))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3e+45) {
tmp = (b + (a * (c / d))) * (-1.0 / hypot(c, d));
} else if (d <= -2.2e-131) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 2.2e-65) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = 1.0 / (hypot(c, d) / fma(a, (c / d), b));
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -3e+45) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) * Float64(-1.0 / hypot(c, d))); elseif (d <= -2.2e-131) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 2.2e-65) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); else tmp = Float64(1.0 / Float64(hypot(c, d) / fma(a, Float64(c / d), b))); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -3e+45], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.2e-131], 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, 2.2e-65], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(1.0 / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3 \cdot 10^{+45}:\\
\;\;\;\;\left(b + a \cdot \frac{c}{d}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq -2.2 \cdot 10^{-131}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 2.2 \cdot 10^{-65}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}}\\
\end{array}
\end{array}
if d < -3.00000000000000011e45Initial program 47.1%
*-un-lft-identity47.1%
associate-*r/47.1%
fma-define47.1%
add-sqr-sqrt47.1%
times-frac47.0%
fma-define47.0%
hypot-define47.0%
fma-define47.0%
fma-define47.0%
hypot-define64.5%
Applied egg-rr64.5%
Taylor expanded in d around -inf 82.3%
distribute-lft-out82.3%
associate-/l*87.7%
Simplified87.7%
if -3.00000000000000011e45 < d < -2.2e-131Initial program 80.0%
if -2.2e-131 < d < 2.20000000000000021e-65Initial program 76.0%
Taylor expanded in c around inf 95.0%
if 2.20000000000000021e-65 < d Initial program 54.3%
*-un-lft-identity54.3%
associate-*r/54.3%
fma-define54.3%
add-sqr-sqrt54.3%
times-frac54.4%
fma-define54.4%
hypot-define54.4%
fma-define54.4%
fma-define54.4%
hypot-define68.9%
Applied egg-rr68.9%
Taylor expanded in d around -inf 18.0%
distribute-lft-out18.0%
associate-/l*18.0%
Simplified18.0%
associate-*l/18.0%
*-un-lft-identity18.0%
clear-num18.1%
add-sqr-sqrt5.7%
sqrt-unprod30.0%
mul-1-neg30.0%
mul-1-neg30.0%
sqr-neg30.0%
sqrt-unprod40.0%
add-sqr-sqrt80.1%
+-commutative80.1%
fma-define80.1%
Applied egg-rr80.1%
Final simplification86.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ b (* a (/ c d)))))
(if (<= d -1.4e+50)
(* t_0 (/ -1.0 (hypot c d)))
(if (<= d -2e-131)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 1.72e-65) (/ (+ a (/ (* b d) c)) c) (/ t_0 d))))))
double code(double a, double b, double c, double d) {
double t_0 = b + (a * (c / d));
double tmp;
if (d <= -1.4e+50) {
tmp = t_0 * (-1.0 / hypot(c, d));
} else if (d <= -2e-131) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 1.72e-65) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = t_0 / d;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = b + (a * (c / d));
double tmp;
if (d <= -1.4e+50) {
tmp = t_0 * (-1.0 / Math.hypot(c, d));
} else if (d <= -2e-131) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 1.72e-65) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = t_0 / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = b + (a * (c / d)) tmp = 0 if d <= -1.4e+50: tmp = t_0 * (-1.0 / math.hypot(c, d)) elif d <= -2e-131: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif d <= 1.72e-65: tmp = (a + ((b * d) / c)) / c else: tmp = t_0 / d return tmp
function code(a, b, c, d) t_0 = Float64(b + Float64(a * Float64(c / d))) tmp = 0.0 if (d <= -1.4e+50) tmp = Float64(t_0 * Float64(-1.0 / hypot(c, d))); elseif (d <= -2e-131) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 1.72e-65) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); else tmp = Float64(t_0 / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = b + (a * (c / d)); tmp = 0.0; if (d <= -1.4e+50) tmp = t_0 * (-1.0 / hypot(c, d)); elseif (d <= -2e-131) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (d <= 1.72e-65) tmp = (a + ((b * d) / c)) / c; else tmp = t_0 / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.4e+50], N[(t$95$0 * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2e-131], 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.72e-65], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(t$95$0 / d), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b + a \cdot \frac{c}{d}\\
\mathbf{if}\;d \leq -1.4 \cdot 10^{+50}:\\
\;\;\;\;t\_0 \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq -2 \cdot 10^{-131}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 1.72 \cdot 10^{-65}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{d}\\
\end{array}
\end{array}
if d < -1.3999999999999999e50Initial program 47.1%
*-un-lft-identity47.1%
associate-*r/47.1%
fma-define47.1%
add-sqr-sqrt47.1%
times-frac47.0%
fma-define47.0%
hypot-define47.0%
fma-define47.0%
fma-define47.0%
hypot-define64.5%
Applied egg-rr64.5%
Taylor expanded in d around -inf 82.3%
distribute-lft-out82.3%
associate-/l*87.7%
Simplified87.7%
if -1.3999999999999999e50 < d < -2e-131Initial program 80.0%
if -2e-131 < d < 1.72000000000000005e-65Initial program 76.0%
Taylor expanded in c around inf 95.0%
if 1.72000000000000005e-65 < d Initial program 54.3%
Taylor expanded in d around inf 79.0%
associate-/l*79.2%
Simplified79.2%
Final simplification86.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ b (* a (/ c d))) d)))
(if (<= d -1.45e+85)
t_0
(if (<= d -1.95e-131)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 2.3e-65) (/ (+ a (/ (* b d) c)) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -1.45e+85) {
tmp = t_0;
} else if (d <= -1.95e-131) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 2.3e-65) {
tmp = (a + ((b * d) / c)) / c;
} 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 + (a * (c / d))) / d
if (d <= (-1.45d+85)) then
tmp = t_0
else if (d <= (-1.95d-131)) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else if (d <= 2.3d-65) then
tmp = (a + ((b * d) / c)) / c
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 + (a * (c / d))) / d;
double tmp;
if (d <= -1.45e+85) {
tmp = t_0;
} else if (d <= -1.95e-131) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 2.3e-65) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b + (a * (c / d))) / d tmp = 0 if d <= -1.45e+85: tmp = t_0 elif d <= -1.95e-131: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif d <= 2.3e-65: tmp = (a + ((b * d) / c)) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b + Float64(a * Float64(c / d))) / d) tmp = 0.0 if (d <= -1.45e+85) tmp = t_0; elseif (d <= -1.95e-131) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 2.3e-65) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b + (a * (c / d))) / d; tmp = 0.0; if (d <= -1.45e+85) tmp = t_0; elseif (d <= -1.95e-131) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (d <= 2.3e-65) tmp = (a + ((b * d) / c)) / c; else tmp = t_0; 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[d, -1.45e+85], t$95$0, If[LessEqual[d, -1.95e-131], 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, 2.3e-65], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{if}\;d \leq -1.45 \cdot 10^{+85}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.95 \cdot 10^{-131}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 2.3 \cdot 10^{-65}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.44999999999999999e85 or 2.3e-65 < d Initial program 49.3%
Taylor expanded in d around inf 79.4%
associate-/l*81.8%
Simplified81.8%
if -1.44999999999999999e85 < d < -1.9500000000000001e-131Initial program 81.0%
if -1.9500000000000001e-131 < d < 2.3e-65Initial program 76.0%
Taylor expanded in c around inf 95.0%
Final simplification86.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5.8e+44) (not (<= d 1e-11))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5.8e+44) || !(d <= 1e-11)) {
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 <= (-5.8d+44)) .or. (.not. (d <= 1d-11))) 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 <= -5.8e+44) || !(d <= 1e-11)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5.8e+44) or not (d <= 1e-11): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5.8e+44) || !(d <= 1e-11)) 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 <= -5.8e+44) || ~((d <= 1e-11))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5.8e+44], N[Not[LessEqual[d, 1e-11]], $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 -5.8 \cdot 10^{+44} \lor \neg \left(d \leq 10^{-11}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -5.8000000000000004e44 or 9.99999999999999939e-12 < d Initial program 47.4%
Taylor expanded in c around 0 73.0%
if -5.8000000000000004e44 < d < 9.99999999999999939e-12Initial program 79.0%
Taylor expanded in c around inf 79.1%
associate-/l*78.4%
Simplified78.4%
Final simplification75.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.3e+41) (not (<= d 2e-18))) (/ b d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.3e+41) || !(d <= 2e-18)) {
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 <= (-2.3d+41)) .or. (.not. (d <= 2d-18))) 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 <= -2.3e+41) || !(d <= 2e-18)) {
tmp = b / d;
} else {
tmp = (a + ((b * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.3e+41) or not (d <= 2e-18): tmp = b / d else: tmp = (a + ((b * d) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.3e+41) || !(d <= 2e-18)) 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 <= -2.3e+41) || ~((d <= 2e-18))) tmp = b / d; else tmp = (a + ((b * d) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.3e+41], N[Not[LessEqual[d, 2e-18]], $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 -2.3 \cdot 10^{+41} \lor \neg \left(d \leq 2 \cdot 10^{-18}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -2.2999999999999998e41 or 2.0000000000000001e-18 < d Initial program 47.4%
Taylor expanded in c around 0 73.0%
if -2.2999999999999998e41 < d < 2.0000000000000001e-18Initial program 79.0%
Taylor expanded in c around inf 79.1%
Final simplification76.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -9.5e-92) (not (<= d 2.3e-65))) (/ (+ b (* a (/ c d))) d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9.5e-92) || !(d <= 2.3e-65)) {
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 <= (-9.5d-92)) .or. (.not. (d <= 2.3d-65))) 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 <= -9.5e-92) || !(d <= 2.3e-65)) {
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 <= -9.5e-92) or not (d <= 2.3e-65): 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 <= -9.5e-92) || !(d <= 2.3e-65)) 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 <= -9.5e-92) || ~((d <= 2.3e-65))) 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, -9.5e-92], N[Not[LessEqual[d, 2.3e-65]], $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 -9.5 \cdot 10^{-92} \lor \neg \left(d \leq 2.3 \cdot 10^{-65}\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 < -9.49999999999999946e-92 or 2.3e-65 < d Initial program 56.4%
Taylor expanded in d around inf 75.7%
associate-/l*77.6%
Simplified77.6%
if -9.49999999999999946e-92 < d < 2.3e-65Initial program 76.5%
Taylor expanded in c around inf 91.5%
Final simplification82.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -6.4e-93) (not (<= d 1.15e-65))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.4e-93) || !(d <= 1.15e-65)) {
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 <= (-6.4d-93)) .or. (.not. (d <= 1.15d-65))) 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 <= -6.4e-93) || !(d <= 1.15e-65)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -6.4e-93) or not (d <= 1.15e-65): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -6.4e-93) || !(d <= 1.15e-65)) 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 <= -6.4e-93) || ~((d <= 1.15e-65))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6.4e-93], N[Not[LessEqual[d, 1.15e-65]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.4 \cdot 10^{-93} \lor \neg \left(d \leq 1.15 \cdot 10^{-65}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -6.3999999999999997e-93 or 1.15e-65 < d Initial program 56.4%
Taylor expanded in c around 0 64.0%
if -6.3999999999999997e-93 < d < 1.15e-65Initial program 76.5%
Taylor expanded in c around inf 77.4%
Final simplification68.9%
(FPCore (a b c d) :precision binary64 (if (<= d -2.1e+123) (/ a d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.1e+123) {
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 <= (-2.1d+123)) 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 <= -2.1e+123) {
tmp = a / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -2.1e+123: tmp = a / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -2.1e+123) 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 <= -2.1e+123) tmp = a / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.1e+123], N[(a / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.1 \cdot 10^{+123}:\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -2.09999999999999994e123Initial program 41.1%
*-un-lft-identity41.1%
associate-*r/41.1%
fma-define41.1%
add-sqr-sqrt41.1%
times-frac41.1%
fma-define41.1%
hypot-define41.1%
fma-define41.1%
fma-define41.1%
hypot-define64.3%
Applied egg-rr64.3%
Taylor expanded in d around -inf 88.0%
distribute-lft-out88.0%
associate-/l*95.2%
Simplified95.2%
Taylor expanded in c around -inf 23.3%
if -2.09999999999999994e123 < d Initial program 68.1%
Taylor expanded in c around inf 48.8%
Final simplification44.7%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 63.8%
Taylor expanded in c around inf 42.7%
Final simplification42.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 2024072
(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))))