
(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))))
(t_1 (/ (+ b (* a (/ c d))) d)))
(if (<= d -1.02e+89)
t_1
(if (<= d -6.5e-152)
t_0
(if (<= d 2.8e-70)
(/ (+ a (/ (* b d) c)) c)
(if (<= d 5.8e+120) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -1.02e+89) {
tmp = t_1;
} else if (d <= -6.5e-152) {
tmp = t_0;
} else if (d <= 2.8e-70) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 5.8e+120) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
t_1 = (b + (a * (c / d))) / d
if (d <= (-1.02d+89)) then
tmp = t_1
else if (d <= (-6.5d-152)) then
tmp = t_0
else if (d <= 2.8d-70) then
tmp = (a + ((b * d) / c)) / c
else if (d <= 5.8d+120) then
tmp = t_0
else
tmp = t_1
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 t_1 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -1.02e+89) {
tmp = t_1;
} else if (d <= -6.5e-152) {
tmp = t_0;
} else if (d <= 2.8e-70) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 5.8e+120) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = (b + (a * (c / d))) / d tmp = 0 if d <= -1.02e+89: tmp = t_1 elif d <= -6.5e-152: tmp = t_0 elif d <= 2.8e-70: tmp = (a + ((b * d) / c)) / c elif d <= 5.8e+120: tmp = t_0 else: tmp = t_1 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))) t_1 = Float64(Float64(b + Float64(a * Float64(c / d))) / d) tmp = 0.0 if (d <= -1.02e+89) tmp = t_1; elseif (d <= -6.5e-152) tmp = t_0; elseif (d <= 2.8e-70) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif (d <= 5.8e+120) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); t_1 = (b + (a * (c / d))) / d; tmp = 0.0; if (d <= -1.02e+89) tmp = t_1; elseif (d <= -6.5e-152) tmp = t_0; elseif (d <= 2.8e-70) tmp = (a + ((b * d) / c)) / c; elseif (d <= 5.8e+120) tmp = t_0; else tmp = t_1; 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]}, Block[{t$95$1 = N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.02e+89], t$95$1, If[LessEqual[d, -6.5e-152], t$95$0, If[LessEqual[d, 2.8e-70], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.8e+120], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{if}\;d \leq -1.02 \cdot 10^{+89}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -6.5 \cdot 10^{-152}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.8 \cdot 10^{-70}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 5.8 \cdot 10^{+120}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.0199999999999999e89 or 5.8000000000000003e120 < d Initial program 28.0%
Taylor expanded in d around inf 79.7%
associate-/l*90.6%
Simplified90.6%
if -1.0199999999999999e89 < d < -6.5000000000000001e-152 or 2.7999999999999999e-70 < d < 5.8000000000000003e120Initial program 85.3%
if -6.5000000000000001e-152 < d < 2.7999999999999999e-70Initial program 71.6%
Taylor expanded in c around inf 90.7%
*-commutative90.7%
Simplified90.7%
Final simplification88.7%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 5e+268) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 5e+268) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (b + (a * (c / 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+268) 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 / 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+268], 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 / d), $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^{+268}:\\
\;\;\;\;\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 \frac{c}{d}}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 5.0000000000000002e268Initial program 79.9%
*-un-lft-identity79.9%
add-sqr-sqrt79.9%
times-frac79.8%
hypot-define79.8%
fma-define79.8%
hypot-define95.0%
Applied egg-rr95.0%
if 5.0000000000000002e268 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 20.3%
Taylor expanded in d around inf 58.0%
associate-/l*69.8%
Simplified69.8%
(FPCore (a b c d) :precision binary64 (if (<= d -1.06e-11) (/ b d) (if (<= d 8e+49) (/ a c) (if (<= d 4.7e+88) (/ (* a (/ c d)) d) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.06e-11) {
tmp = b / d;
} else if (d <= 8e+49) {
tmp = a / c;
} else if (d <= 4.7e+88) {
tmp = (a * (c / d)) / d;
} 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 (d <= (-1.06d-11)) then
tmp = b / d
else if (d <= 8d+49) then
tmp = a / c
else if (d <= 4.7d+88) then
tmp = (a * (c / d)) / d
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 (d <= -1.06e-11) {
tmp = b / d;
} else if (d <= 8e+49) {
tmp = a / c;
} else if (d <= 4.7e+88) {
tmp = (a * (c / d)) / d;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.06e-11: tmp = b / d elif d <= 8e+49: tmp = a / c elif d <= 4.7e+88: tmp = (a * (c / d)) / d else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.06e-11) tmp = Float64(b / d); elseif (d <= 8e+49) tmp = Float64(a / c); elseif (d <= 4.7e+88) tmp = Float64(Float64(a * Float64(c / d)) / d); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.06e-11) tmp = b / d; elseif (d <= 8e+49) tmp = a / c; elseif (d <= 4.7e+88) tmp = (a * (c / d)) / d; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.06e-11], N[(b / d), $MachinePrecision], If[LessEqual[d, 8e+49], N[(a / c), $MachinePrecision], If[LessEqual[d, 4.7e+88], N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.06 \cdot 10^{-11}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 8 \cdot 10^{+49}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 4.7 \cdot 10^{+88}:\\
\;\;\;\;\frac{a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.05999999999999993e-11 or 4.70000000000000007e88 < d Initial program 39.0%
Taylor expanded in c around 0 71.3%
if -1.05999999999999993e-11 < d < 7.99999999999999957e49Initial program 77.8%
Taylor expanded in c around inf 63.2%
if 7.99999999999999957e49 < d < 4.70000000000000007e88Initial program 91.0%
Taylor expanded in d around inf 76.1%
Taylor expanded in b around 0 59.7%
associate-*r/60.0%
Simplified60.0%
(FPCore (a b c d)
:precision binary64
(if (<= d -0.0032)
(/ b d)
(if (<= d 2.8e+47)
(/ a c)
(if (<= d 4.5e+90) (* (/ c d) (/ a d)) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -0.0032) {
tmp = b / d;
} else if (d <= 2.8e+47) {
tmp = a / c;
} else if (d <= 4.5e+90) {
tmp = (c / d) * (a / d);
} 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 (d <= (-0.0032d0)) then
tmp = b / d
else if (d <= 2.8d+47) then
tmp = a / c
else if (d <= 4.5d+90) then
tmp = (c / d) * (a / d)
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 (d <= -0.0032) {
tmp = b / d;
} else if (d <= 2.8e+47) {
tmp = a / c;
} else if (d <= 4.5e+90) {
tmp = (c / d) * (a / d);
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -0.0032: tmp = b / d elif d <= 2.8e+47: tmp = a / c elif d <= 4.5e+90: tmp = (c / d) * (a / d) else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -0.0032) tmp = Float64(b / d); elseif (d <= 2.8e+47) tmp = Float64(a / c); elseif (d <= 4.5e+90) tmp = Float64(Float64(c / d) * Float64(a / d)); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -0.0032) tmp = b / d; elseif (d <= 2.8e+47) tmp = a / c; elseif (d <= 4.5e+90) tmp = (c / d) * (a / d); else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -0.0032], N[(b / d), $MachinePrecision], If[LessEqual[d, 2.8e+47], N[(a / c), $MachinePrecision], If[LessEqual[d, 4.5e+90], N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.0032:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 2.8 \cdot 10^{+47}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 4.5 \cdot 10^{+90}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -0.00320000000000000015 or 4.5e90 < d Initial program 39.0%
Taylor expanded in c around 0 71.3%
if -0.00320000000000000015 < d < 2.79999999999999988e47Initial program 77.8%
Taylor expanded in c around inf 63.2%
if 2.79999999999999988e47 < d < 4.5e90Initial program 91.0%
Taylor expanded in d around inf 76.1%
Taylor expanded in b around 0 59.7%
associate-/l/59.9%
*-commutative59.9%
times-frac59.9%
Applied egg-rr59.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.75e-41) (not (<= d 6.2e-12))) (/ (+ b (* a (/ c d))) d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.75e-41) || !(d <= 6.2e-12)) {
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 <= (-2.75d-41)) .or. (.not. (d <= 6.2d-12))) 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 <= -2.75e-41) || !(d <= 6.2e-12)) {
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 <= -2.75e-41) or not (d <= 6.2e-12): 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 <= -2.75e-41) || !(d <= 6.2e-12)) 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 <= -2.75e-41) || ~((d <= 6.2e-12))) 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, -2.75e-41], N[Not[LessEqual[d, 6.2e-12]], $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 -2.75 \cdot 10^{-41} \lor \neg \left(d \leq 6.2 \cdot 10^{-12}\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 < -2.75000000000000011e-41 or 6.2000000000000002e-12 < d Initial program 50.8%
Taylor expanded in d around inf 72.4%
associate-/l*78.6%
Simplified78.6%
if -2.75000000000000011e-41 < d < 6.2000000000000002e-12Initial program 77.6%
Taylor expanded in c around inf 84.8%
*-commutative84.8%
Simplified84.8%
Final simplification81.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -8e-10) (not (<= d 4.9e+120))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -8e-10) || !(d <= 4.9e+120)) {
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 <= (-8d-10)) .or. (.not. (d <= 4.9d+120))) 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 <= -8e-10) || !(d <= 4.9e+120)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -8e-10) or not (d <= 4.9e+120): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -8e-10) || !(d <= 4.9e+120)) 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 <= -8e-10) || ~((d <= 4.9e+120))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -8e-10], N[Not[LessEqual[d, 4.9e+120]], $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 -8 \cdot 10^{-10} \lor \neg \left(d \leq 4.9 \cdot 10^{+120}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -8.00000000000000029e-10 or 4.9000000000000001e120 < d Initial program 38.4%
Taylor expanded in c around 0 71.9%
if -8.00000000000000029e-10 < d < 4.9000000000000001e120Initial program 78.9%
Taylor expanded in c around inf 74.1%
*-commutative74.1%
Simplified74.1%
Taylor expanded in d around 0 74.1%
associate-*r/74.8%
Simplified74.8%
Final simplification73.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -13.5) (not (<= d 2.4e+39))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -13.5) || !(d <= 2.4e+39)) {
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 <= (-13.5d0)) .or. (.not. (d <= 2.4d+39))) 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 <= -13.5) || !(d <= 2.4e+39)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -13.5) or not (d <= 2.4e+39): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -13.5) || !(d <= 2.4e+39)) 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 <= -13.5) || ~((d <= 2.4e+39))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -13.5], N[Not[LessEqual[d, 2.4e+39]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -13.5 \lor \neg \left(d \leq 2.4 \cdot 10^{+39}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -13.5 or 2.4000000000000001e39 < d Initial program 46.1%
Taylor expanded in c around 0 64.6%
if -13.5 < d < 2.4000000000000001e39Initial program 77.8%
Taylor expanded in c around inf 64.1%
Final simplification64.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 64.3%
Taylor expanded in c around inf 43.3%
(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 2024137
(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))))