
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= t_0 -2e+256)
(/ (+ b (* a (/ c d))) d)
(if (<= t_0 4e+222)
(* (/ 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 <= -2e+256) {
tmp = (b + (a * (c / d))) / d;
} else if (t_0 <= 4e+222) {
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 <= -2e+256) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (t_0 <= 4e+222) 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, -2e+256], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[t$95$0, 4e+222], 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 -2 \cdot 10^{+256}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+222}:\\
\;\;\;\;\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))) < -2.0000000000000001e256Initial program 64.7%
Taylor expanded in d around inf 100.0%
associate-/l*100.0%
Simplified100.0%
if -2.0000000000000001e256 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 4.0000000000000002e222Initial program 79.4%
*-un-lft-identity79.4%
add-sqr-sqrt79.4%
times-frac79.5%
hypot-define79.5%
fma-define79.5%
hypot-define98.3%
Applied egg-rr98.3%
if 4.0000000000000002e222 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 16.5%
Taylor expanded in c around inf 58.8%
associate-/l*63.8%
Simplified63.8%
clear-num63.8%
un-div-inv63.8%
Applied egg-rr63.8%
Final simplification87.3%
(FPCore (a b c d)
:precision binary64
(if (<= c -4.1e+110)
(* (+ a (* b (/ d c))) (/ -1.0 (hypot c d)))
(if (<= c -5e-126)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= c 2.6e+45) (/ (+ b (* c (/ a d))) d) (/ (+ a (/ b (/ c d))) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.1e+110) {
tmp = (a + (b * (d / c))) * (-1.0 / hypot(c, d));
} else if (c <= -5e-126) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 2.6e+45) {
tmp = (b + (c * (a / d))) / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.1e+110) {
tmp = (a + (b * (d / c))) * (-1.0 / Math.hypot(c, d));
} else if (c <= -5e-126) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 2.6e+45) {
tmp = (b + (c * (a / d))) / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -4.1e+110: tmp = (a + (b * (d / c))) * (-1.0 / math.hypot(c, d)) elif c <= -5e-126: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif c <= 2.6e+45: tmp = (b + (c * (a / d))) / d else: tmp = (a + (b / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -4.1e+110) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) * Float64(-1.0 / hypot(c, d))); elseif (c <= -5e-126) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 2.6e+45) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -4.1e+110) tmp = (a + (b * (d / c))) * (-1.0 / hypot(c, d)); elseif (c <= -5e-126) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (c <= 2.6e+45) tmp = (b + (c * (a / d))) / d; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -4.1e+110], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -5e-126], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.6e+45], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.1 \cdot 10^{+110}:\\
\;\;\;\;\left(a + b \cdot \frac{d}{c}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -5 \cdot 10^{-126}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 2.6 \cdot 10^{+45}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -4.0999999999999999e110Initial program 33.1%
*-un-lft-identity33.1%
add-sqr-sqrt33.1%
times-frac33.2%
hypot-define33.2%
fma-define33.2%
hypot-define49.5%
Applied egg-rr49.5%
Taylor expanded in c around -inf 81.7%
distribute-lft-out81.7%
associate-/l*88.7%
Simplified88.7%
if -4.0999999999999999e110 < c < -5.00000000000000006e-126Initial program 77.8%
if -5.00000000000000006e-126 < c < 2.60000000000000007e45Initial program 69.4%
Taylor expanded in d around inf 91.4%
associate-/l*90.6%
Simplified90.6%
clear-num90.7%
un-div-inv90.6%
Applied egg-rr90.6%
associate-/r/91.5%
Simplified91.5%
if 2.60000000000000007e45 < c Initial program 46.6%
Taylor expanded in c around inf 78.0%
associate-/l*78.3%
Simplified78.3%
clear-num78.3%
un-div-inv78.4%
Applied egg-rr78.4%
Final simplification85.7%
(FPCore (a b c d)
:precision binary64
(if (or (<= d -4.2e+63)
(not (or (<= d 1.35e-43) (and (not (<= d 8.5e-19)) (<= d 1.1e+109)))))
(/ b d)
(/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.2e+63) || !((d <= 1.35e-43) || (!(d <= 8.5e-19) && (d <= 1.1e+109)))) {
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 <= (-4.2d+63)) .or. (.not. (d <= 1.35d-43) .or. (.not. (d <= 8.5d-19)) .and. (d <= 1.1d+109))) 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 <= -4.2e+63) || !((d <= 1.35e-43) || (!(d <= 8.5e-19) && (d <= 1.1e+109)))) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.2e+63) or not ((d <= 1.35e-43) or (not (d <= 8.5e-19) and (d <= 1.1e+109))): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.2e+63) || !((d <= 1.35e-43) || (!(d <= 8.5e-19) && (d <= 1.1e+109)))) 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 <= -4.2e+63) || ~(((d <= 1.35e-43) || (~((d <= 8.5e-19)) && (d <= 1.1e+109))))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.2e+63], N[Not[Or[LessEqual[d, 1.35e-43], And[N[Not[LessEqual[d, 8.5e-19]], $MachinePrecision], LessEqual[d, 1.1e+109]]]], $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 -4.2 \cdot 10^{+63} \lor \neg \left(d \leq 1.35 \cdot 10^{-43} \lor \neg \left(d \leq 8.5 \cdot 10^{-19}\right) \land d \leq 1.1 \cdot 10^{+109}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -4.2000000000000004e63 or 1.34999999999999996e-43 < d < 8.50000000000000003e-19 or 1.1e109 < d Initial program 37.1%
Taylor expanded in c around 0 77.7%
if -4.2000000000000004e63 < d < 1.34999999999999996e-43 or 8.50000000000000003e-19 < d < 1.1e109Initial program 70.3%
Taylor expanded in c around inf 76.4%
associate-/l*77.6%
Simplified77.6%
Final simplification77.6%
(FPCore (a b c d)
:precision binary64
(if (or (<= d -4.2e+63)
(not
(or (<= d 1.35e-43) (and (not (<= d 9.2e-18)) (<= d 1.38e+107)))))
(/ b d)
(/ (+ a (/ b (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.2e+63) || !((d <= 1.35e-43) || (!(d <= 9.2e-18) && (d <= 1.38e+107)))) {
tmp = b / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-4.2d+63)) .or. (.not. (d <= 1.35d-43) .or. (.not. (d <= 9.2d-18)) .and. (d <= 1.38d+107))) then
tmp = b / d
else
tmp = (a + (b / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.2e+63) || !((d <= 1.35e-43) || (!(d <= 9.2e-18) && (d <= 1.38e+107)))) {
tmp = b / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.2e+63) or not ((d <= 1.35e-43) or (not (d <= 9.2e-18) and (d <= 1.38e+107))): tmp = b / d else: tmp = (a + (b / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.2e+63) || !((d <= 1.35e-43) || (!(d <= 9.2e-18) && (d <= 1.38e+107)))) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4.2e+63) || ~(((d <= 1.35e-43) || (~((d <= 9.2e-18)) && (d <= 1.38e+107))))) tmp = b / d; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.2e+63], N[Not[Or[LessEqual[d, 1.35e-43], And[N[Not[LessEqual[d, 9.2e-18]], $MachinePrecision], LessEqual[d, 1.38e+107]]]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.2 \cdot 10^{+63} \lor \neg \left(d \leq 1.35 \cdot 10^{-43} \lor \neg \left(d \leq 9.2 \cdot 10^{-18}\right) \land d \leq 1.38 \cdot 10^{+107}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -4.2000000000000004e63 or 1.34999999999999996e-43 < d < 9.2000000000000004e-18 or 1.38e107 < d Initial program 37.1%
Taylor expanded in c around 0 77.7%
if -4.2000000000000004e63 < d < 1.34999999999999996e-43 or 9.2000000000000004e-18 < d < 1.38e107Initial program 70.3%
Taylor expanded in c around inf 76.4%
associate-/l*77.6%
Simplified77.6%
clear-num77.6%
un-div-inv77.6%
Applied egg-rr77.6%
Final simplification77.6%
(FPCore (a b c d)
:precision binary64
(if (<= c -2.3e+65)
(/ (+ a (* b (/ d c))) c)
(if (or (<= c -2800000000000.0) (and (not (<= c -9e-99)) (<= c 6.3e+47)))
(/ (+ b (* a (/ c d))) d)
(/ (+ a (/ b (/ c d))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.3e+65) {
tmp = (a + (b * (d / c))) / c;
} else if ((c <= -2800000000000.0) || (!(c <= -9e-99) && (c <= 6.3e+47))) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-2.3d+65)) then
tmp = (a + (b * (d / c))) / c
else if ((c <= (-2800000000000.0d0)) .or. (.not. (c <= (-9d-99))) .and. (c <= 6.3d+47)) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a + (b / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.3e+65) {
tmp = (a + (b * (d / c))) / c;
} else if ((c <= -2800000000000.0) || (!(c <= -9e-99) && (c <= 6.3e+47))) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.3e+65: tmp = (a + (b * (d / c))) / c elif (c <= -2800000000000.0) or (not (c <= -9e-99) and (c <= 6.3e+47)): tmp = (b + (a * (c / d))) / d else: tmp = (a + (b / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.3e+65) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif ((c <= -2800000000000.0) || (!(c <= -9e-99) && (c <= 6.3e+47))) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -2.3e+65) tmp = (a + (b * (d / c))) / c; elseif ((c <= -2800000000000.0) || (~((c <= -9e-99)) && (c <= 6.3e+47))) tmp = (b + (a * (c / d))) / d; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.3e+65], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[c, -2800000000000.0], And[N[Not[LessEqual[c, -9e-99]], $MachinePrecision], LessEqual[c, 6.3e+47]]], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.3 \cdot 10^{+65}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -2800000000000 \lor \neg \left(c \leq -9 \cdot 10^{-99}\right) \land c \leq 6.3 \cdot 10^{+47}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -2.3e65Initial program 40.9%
Taylor expanded in c around inf 81.2%
associate-/l*87.2%
Simplified87.2%
if -2.3e65 < c < -2.8e12 or -9.0000000000000006e-99 < c < 6.30000000000000003e47Initial program 68.5%
Taylor expanded in d around inf 87.9%
associate-/l*87.3%
Simplified87.3%
if -2.8e12 < c < -9.0000000000000006e-99 or 6.30000000000000003e47 < c Initial program 57.3%
Taylor expanded in c around inf 77.4%
associate-/l*77.7%
Simplified77.7%
clear-num77.7%
un-div-inv77.7%
Applied egg-rr77.7%
Final simplification84.7%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.24e+67)
(/ (+ a (* b (/ d c))) c)
(if (<= c -32500000000000.0)
(/ (+ b (* a (/ c d))) d)
(if (or (<= c -1.2e-98) (not (<= c 4e+46)))
(/ (+ a (/ b (/ c d))) c)
(/ (+ b (* c (/ a d))) d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.24e+67) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -32500000000000.0) {
tmp = (b + (a * (c / d))) / d;
} else if ((c <= -1.2e-98) || !(c <= 4e+46)) {
tmp = (a + (b / (c / d))) / c;
} else {
tmp = (b + (c * (a / 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 (c <= (-1.24d+67)) then
tmp = (a + (b * (d / c))) / c
else if (c <= (-32500000000000.0d0)) then
tmp = (b + (a * (c / d))) / d
else if ((c <= (-1.2d-98)) .or. (.not. (c <= 4d+46))) then
tmp = (a + (b / (c / d))) / c
else
tmp = (b + (c * (a / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.24e+67) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -32500000000000.0) {
tmp = (b + (a * (c / d))) / d;
} else if ((c <= -1.2e-98) || !(c <= 4e+46)) {
tmp = (a + (b / (c / d))) / c;
} else {
tmp = (b + (c * (a / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.24e+67: tmp = (a + (b * (d / c))) / c elif c <= -32500000000000.0: tmp = (b + (a * (c / d))) / d elif (c <= -1.2e-98) or not (c <= 4e+46): tmp = (a + (b / (c / d))) / c else: tmp = (b + (c * (a / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.24e+67) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= -32500000000000.0) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif ((c <= -1.2e-98) || !(c <= 4e+46)) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); else tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.24e+67) tmp = (a + (b * (d / c))) / c; elseif (c <= -32500000000000.0) tmp = (b + (a * (c / d))) / d; elseif ((c <= -1.2e-98) || ~((c <= 4e+46))) tmp = (a + (b / (c / d))) / c; else tmp = (b + (c * (a / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.24e+67], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -32500000000000.0], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[Or[LessEqual[c, -1.2e-98], N[Not[LessEqual[c, 4e+46]], $MachinePrecision]], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.24 \cdot 10^{+67}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -32500000000000:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq -1.2 \cdot 10^{-98} \lor \neg \left(c \leq 4 \cdot 10^{+46}\right):\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\end{array}
\end{array}
if c < -1.24000000000000007e67Initial program 40.9%
Taylor expanded in c around inf 81.2%
associate-/l*87.2%
Simplified87.2%
if -1.24000000000000007e67 < c < -3.25e13Initial program 58.0%
Taylor expanded in d around inf 72.4%
associate-/l*72.4%
Simplified72.4%
if -3.25e13 < c < -1.20000000000000002e-98 or 4e46 < c Initial program 57.3%
Taylor expanded in c around inf 77.4%
associate-/l*77.7%
Simplified77.7%
clear-num77.7%
un-div-inv77.7%
Applied egg-rr77.7%
if -1.20000000000000002e-98 < c < 4e46Initial program 69.9%
Taylor expanded in d around inf 90.0%
associate-/l*89.3%
Simplified89.3%
clear-num89.3%
un-div-inv89.3%
Applied egg-rr89.3%
associate-/r/90.2%
Simplified90.2%
Final simplification85.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ a (/ b (/ c d))) c)))
(if (<= c -5.7e+135)
t_0
(if (<= c -2.15e-126)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= c 2.55e+44) (/ (+ b (* c (/ a d))) d) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (a + (b / (c / d))) / c;
double tmp;
if (c <= -5.7e+135) {
tmp = t_0;
} else if (c <= -2.15e-126) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 2.55e+44) {
tmp = (b + (c * (a / 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 = (a + (b / (c / d))) / c
if (c <= (-5.7d+135)) then
tmp = t_0
else if (c <= (-2.15d-126)) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else if (c <= 2.55d+44) then
tmp = (b + (c * (a / 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 = (a + (b / (c / d))) / c;
double tmp;
if (c <= -5.7e+135) {
tmp = t_0;
} else if (c <= -2.15e-126) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 2.55e+44) {
tmp = (b + (c * (a / d))) / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a + (b / (c / d))) / c tmp = 0 if c <= -5.7e+135: tmp = t_0 elif c <= -2.15e-126: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif c <= 2.55e+44: tmp = (b + (c * (a / d))) / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a + Float64(b / Float64(c / d))) / c) tmp = 0.0 if (c <= -5.7e+135) tmp = t_0; elseif (c <= -2.15e-126) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 2.55e+44) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a + (b / (c / d))) / c; tmp = 0.0; if (c <= -5.7e+135) tmp = t_0; elseif (c <= -2.15e-126) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (c <= 2.55e+44) tmp = (b + (c * (a / d))) / d; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -5.7e+135], t$95$0, If[LessEqual[c, -2.15e-126], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.55e+44], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\mathbf{if}\;c \leq -5.7 \cdot 10^{+135}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -2.15 \cdot 10^{-126}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 2.55 \cdot 10^{+44}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -5.7000000000000002e135 or 2.55e44 < c Initial program 37.9%
Taylor expanded in c around inf 79.3%
associate-/l*83.2%
Simplified83.2%
clear-num83.2%
un-div-inv83.3%
Applied egg-rr83.3%
if -5.7000000000000002e135 < c < -2.15000000000000016e-126Initial program 79.0%
if -2.15000000000000016e-126 < c < 2.55e44Initial program 69.4%
Taylor expanded in d around inf 91.4%
associate-/l*90.6%
Simplified90.6%
clear-num90.7%
un-div-inv90.6%
Applied egg-rr90.6%
associate-/r/91.5%
Simplified91.5%
Final simplification85.7%
(FPCore (a b c d)
:precision binary64
(if (or (<= c -3.2e+64)
(not
(or (<= c -110000000000.0)
(and (not (<= c -9.5e-126)) (<= c 5.2e+44)))))
(/ a c)
(/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.2e+64) || !((c <= -110000000000.0) || (!(c <= -9.5e-126) && (c <= 5.2e+44)))) {
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.2d+64)) .or. (.not. (c <= (-110000000000.0d0)) .or. (.not. (c <= (-9.5d-126))) .and. (c <= 5.2d+44))) 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.2e+64) || !((c <= -110000000000.0) || (!(c <= -9.5e-126) && (c <= 5.2e+44)))) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3.2e+64) or not ((c <= -110000000000.0) or (not (c <= -9.5e-126) and (c <= 5.2e+44))): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.2e+64) || !((c <= -110000000000.0) || (!(c <= -9.5e-126) && (c <= 5.2e+44)))) 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.2e+64) || ~(((c <= -110000000000.0) || (~((c <= -9.5e-126)) && (c <= 5.2e+44))))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.2e+64], N[Not[Or[LessEqual[c, -110000000000.0], And[N[Not[LessEqual[c, -9.5e-126]], $MachinePrecision], LessEqual[c, 5.2e+44]]]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.2 \cdot 10^{+64} \lor \neg \left(c \leq -110000000000 \lor \neg \left(c \leq -9.5 \cdot 10^{-126}\right) \land c \leq 5.2 \cdot 10^{+44}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -3.20000000000000019e64 or -1.1e11 < c < -9.5000000000000003e-126 or 5.1999999999999998e44 < c Initial program 50.8%
Taylor expanded in c around inf 68.5%
if -3.20000000000000019e64 < c < -1.1e11 or -9.5000000000000003e-126 < c < 5.1999999999999998e44Initial program 67.7%
Taylor expanded in c around 0 71.9%
Final simplification70.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 58.4%
Taylor expanded in c around inf 45.9%
Final simplification45.9%
(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 2024053
(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))))