
(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 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 1e+231) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 1e+231) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (a + (b * (d / c))) / c;
}
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))) <= 1e+231) 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(d / c))) / c); 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], 1e+231], 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[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 10^{+231}:\\
\;\;\;\;\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 + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.0000000000000001e231Initial program 76.1%
*-un-lft-identity76.1%
add-sqr-sqrt76.1%
times-frac76.1%
hypot-define76.1%
fma-define76.1%
hypot-define97.1%
Applied egg-rr97.1%
if 1.0000000000000001e231 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 20.3%
Taylor expanded in c around inf 53.6%
associate-/l*65.7%
Simplified65.7%
Final simplification89.1%
(FPCore (a b c d)
:precision binary64
(if (<= c -4.6e-44)
(* (/ c (hypot c d)) (/ a (hypot c d)))
(if (<= c 4.4e-104)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 4.5e+81)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(/ (+ a (/ b (/ c d))) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.6e-44) {
tmp = (c / hypot(c, d)) * (a / hypot(c, d));
} else if (c <= 4.4e-104) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 4.5e+81) {
tmp = ((a * c) + (b * d)) / ((c * c) + (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.6e-44) {
tmp = (c / Math.hypot(c, d)) * (a / Math.hypot(c, d));
} else if (c <= 4.4e-104) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 4.5e+81) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -4.6e-44: tmp = (c / math.hypot(c, d)) * (a / math.hypot(c, d)) elif c <= 4.4e-104: tmp = (b + ((a * c) / d)) / d elif c <= 4.5e+81: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) else: tmp = (a + (b / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -4.6e-44) tmp = Float64(Float64(c / hypot(c, d)) * Float64(a / hypot(c, d))); elseif (c <= 4.4e-104) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 4.5e+81) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(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.6e-44) tmp = (c / hypot(c, d)) * (a / hypot(c, d)); elseif (c <= 4.4e-104) tmp = (b + ((a * c) / d)) / d; elseif (c <= 4.5e+81) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -4.6e-44], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.4e-104], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.5e+81], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $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.6 \cdot 10^{-44}:\\
\;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq 4.4 \cdot 10^{-104}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 4.5 \cdot 10^{+81}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -4.59999999999999996e-44Initial program 50.0%
Taylor expanded in a around inf 43.1%
*-commutative43.1%
Simplified43.1%
add-sqr-sqrt43.1%
hypot-undefine43.1%
hypot-undefine43.1%
times-frac82.4%
Applied egg-rr82.4%
if -4.59999999999999996e-44 < c < 4.40000000000000023e-104Initial program 71.4%
Taylor expanded in d around inf 89.9%
if 4.40000000000000023e-104 < c < 4.50000000000000017e81Initial program 85.7%
if 4.50000000000000017e81 < c Initial program 40.7%
Taylor expanded in c around inf 78.0%
associate-/l*88.9%
Simplified88.9%
clear-num88.9%
un-div-inv88.9%
Applied egg-rr88.9%
Final simplification87.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -1.02e+103)
(/ (+ a (* b (/ d c))) c)
(if (<= c -1.05e-46)
t_0
(if (<= c 2.5e-106)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 8.5e+81) t_0 (/ (+ 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 (c <= -1.02e+103) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -1.05e-46) {
tmp = t_0;
} else if (c <= 2.5e-106) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 8.5e+81) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (c <= (-1.02d+103)) then
tmp = (a + (b * (d / c))) / c
else if (c <= (-1.05d-46)) then
tmp = t_0
else if (c <= 2.5d-106) then
tmp = (b + ((a * c) / d)) / d
else if (c <= 8.5d+81) then
tmp = t_0
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 t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -1.02e+103) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -1.05e-46) {
tmp = t_0;
} else if (c <= 2.5e-106) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 8.5e+81) {
tmp = t_0;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -1.02e+103: tmp = (a + (b * (d / c))) / c elif c <= -1.05e-46: tmp = t_0 elif c <= 2.5e-106: tmp = (b + ((a * c) / d)) / d elif c <= 8.5e+81: tmp = t_0 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 (c <= -1.02e+103) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= -1.05e-46) tmp = t_0; elseif (c <= 2.5e-106) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 8.5e+81) tmp = t_0; else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -1.02e+103) tmp = (a + (b * (d / c))) / c; elseif (c <= -1.05e-46) tmp = t_0; elseif (c <= 2.5e-106) tmp = (b + ((a * c) / d)) / d; elseif (c <= 8.5e+81) tmp = t_0; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.02e+103], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.05e-46], t$95$0, If[LessEqual[c, 2.5e-106], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8.5e+81], t$95$0, 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}\;c \leq -1.02 \cdot 10^{+103}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -1.05 \cdot 10^{-46}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.5 \cdot 10^{-106}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 8.5 \cdot 10^{+81}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -1.01999999999999991e103Initial program 20.0%
Taylor expanded in c around inf 78.7%
associate-/l*86.2%
Simplified86.2%
if -1.01999999999999991e103 < c < -1.04999999999999994e-46 or 2.49999999999999991e-106 < c < 8.49999999999999986e81Initial program 85.5%
if -1.04999999999999994e-46 < c < 2.49999999999999991e-106Initial program 71.4%
Taylor expanded in d around inf 89.9%
if 8.49999999999999986e81 < c Initial program 40.7%
Taylor expanded in c around inf 78.0%
associate-/l*88.9%
Simplified88.9%
clear-num88.9%
un-div-inv88.9%
Applied egg-rr88.9%
Final simplification88.0%
(FPCore (a b c d)
:precision binary64
(if (<= c -6.2e-26)
(/ (+ a (* b (/ d c))) c)
(if (or (<= c 6.5e-66) (and (not (<= c 2.35e+72)) (<= c 1.15e+118)))
(/ (+ b (* a (/ c d))) d)
(/ (+ a (/ b (/ c d))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.2e-26) {
tmp = (a + (b * (d / c))) / c;
} else if ((c <= 6.5e-66) || (!(c <= 2.35e+72) && (c <= 1.15e+118))) {
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 <= (-6.2d-26)) then
tmp = (a + (b * (d / c))) / c
else if ((c <= 6.5d-66) .or. (.not. (c <= 2.35d+72)) .and. (c <= 1.15d+118)) 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 <= -6.2e-26) {
tmp = (a + (b * (d / c))) / c;
} else if ((c <= 6.5e-66) || (!(c <= 2.35e+72) && (c <= 1.15e+118))) {
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 <= -6.2e-26: tmp = (a + (b * (d / c))) / c elif (c <= 6.5e-66) or (not (c <= 2.35e+72) and (c <= 1.15e+118)): 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 <= -6.2e-26) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif ((c <= 6.5e-66) || (!(c <= 2.35e+72) && (c <= 1.15e+118))) 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 <= -6.2e-26) tmp = (a + (b * (d / c))) / c; elseif ((c <= 6.5e-66) || (~((c <= 2.35e+72)) && (c <= 1.15e+118))) 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, -6.2e-26], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[c, 6.5e-66], And[N[Not[LessEqual[c, 2.35e+72]], $MachinePrecision], LessEqual[c, 1.15e+118]]], 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 -6.2 \cdot 10^{-26}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 6.5 \cdot 10^{-66} \lor \neg \left(c \leq 2.35 \cdot 10^{+72}\right) \land c \leq 1.15 \cdot 10^{+118}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -6.19999999999999966e-26Initial program 45.8%
Taylor expanded in c around inf 74.9%
associate-/l*79.3%
Simplified79.3%
if -6.19999999999999966e-26 < c < 6.50000000000000024e-66 or 2.35000000000000017e72 < c < 1.15000000000000008e118Initial program 72.6%
Taylor expanded in d around inf 86.9%
associate-/l*86.1%
Simplified86.1%
if 6.50000000000000024e-66 < c < 2.35000000000000017e72 or 1.15000000000000008e118 < c Initial program 57.9%
Taylor expanded in c around inf 78.1%
associate-/l*85.9%
Simplified85.9%
clear-num85.9%
un-div-inv85.9%
Applied egg-rr85.9%
Final simplification84.3%
(FPCore (a b c d)
:precision binary64
(if (or (<= c -1e-44)
(not (or (<= c 1.6e-68) (and (not (<= c 1.62e+69)) (<= c 9e+117)))))
(/ a c)
(/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1e-44) || !((c <= 1.6e-68) || (!(c <= 1.62e+69) && (c <= 9e+117)))) {
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 <= (-1d-44)) .or. (.not. (c <= 1.6d-68) .or. (.not. (c <= 1.62d+69)) .and. (c <= 9d+117))) 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 <= -1e-44) || !((c <= 1.6e-68) || (!(c <= 1.62e+69) && (c <= 9e+117)))) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1e-44) or not ((c <= 1.6e-68) or (not (c <= 1.62e+69) and (c <= 9e+117))): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1e-44) || !((c <= 1.6e-68) || (!(c <= 1.62e+69) && (c <= 9e+117)))) 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 <= -1e-44) || ~(((c <= 1.6e-68) || (~((c <= 1.62e+69)) && (c <= 9e+117))))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1e-44], N[Not[Or[LessEqual[c, 1.6e-68], And[N[Not[LessEqual[c, 1.62e+69]], $MachinePrecision], LessEqual[c, 9e+117]]]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1 \cdot 10^{-44} \lor \neg \left(c \leq 1.6 \cdot 10^{-68} \lor \neg \left(c \leq 1.62 \cdot 10^{+69}\right) \land c \leq 9 \cdot 10^{+117}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -9.99999999999999953e-45 or 1.5999999999999999e-68 < c < 1.62e69 or 9e117 < c Initial program 53.6%
Taylor expanded in c around inf 68.2%
if -9.99999999999999953e-45 < c < 1.5999999999999999e-68 or 1.62e69 < c < 9e117Initial program 71.3%
Taylor expanded in c around 0 72.9%
Final simplification70.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5.2e+80) (not (<= d 5.8e+140))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5.2e+80) || !(d <= 5.8e+140)) {
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.2d+80)) .or. (.not. (d <= 5.8d+140))) 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.2e+80) || !(d <= 5.8e+140)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5.2e+80) or not (d <= 5.8e+140): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5.2e+80) || !(d <= 5.8e+140)) 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.2e+80) || ~((d <= 5.8e+140))) 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.2e+80], N[Not[LessEqual[d, 5.8e+140]], $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.2 \cdot 10^{+80} \lor \neg \left(d \leq 5.8 \cdot 10^{+140}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -5.19999999999999963e80 or 5.7999999999999998e140 < d Initial program 34.7%
Taylor expanded in c around 0 75.5%
if -5.19999999999999963e80 < d < 5.7999999999999998e140Initial program 74.5%
Taylor expanded in c around inf 72.8%
associate-/l*75.0%
Simplified75.0%
Final simplification75.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -6.2e+80) (not (<= d 6e+140))) (/ b d) (/ (+ a (/ b (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.2e+80) || !(d <= 6e+140)) {
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 <= (-6.2d+80)) .or. (.not. (d <= 6d+140))) 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 <= -6.2e+80) || !(d <= 6e+140)) {
tmp = b / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -6.2e+80) or not (d <= 6e+140): tmp = b / d else: tmp = (a + (b / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -6.2e+80) || !(d <= 6e+140)) 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 <= -6.2e+80) || ~((d <= 6e+140))) tmp = b / d; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6.2e+80], N[Not[LessEqual[d, 6e+140]], $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 -6.2 \cdot 10^{+80} \lor \neg \left(d \leq 6 \cdot 10^{+140}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -6.19999999999999976e80 or 5.99999999999999993e140 < d Initial program 34.7%
Taylor expanded in c around 0 75.5%
if -6.19999999999999976e80 < d < 5.99999999999999993e140Initial program 74.5%
Taylor expanded in c around inf 72.8%
associate-/l*75.0%
Simplified75.0%
clear-num75.0%
un-div-inv75.0%
Applied egg-rr75.0%
Final simplification75.1%
(FPCore (a b c d) :precision binary64 (if (<= c -3.4e-23) (/ (+ a (* b (/ d c))) c) (if (<= c 8e-45) (/ (+ b (/ (* a c) d)) d) (/ (+ a (/ b (/ c d))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.4e-23) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 8e-45) {
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 <= (-3.4d-23)) then
tmp = (a + (b * (d / c))) / c
else if (c <= 8d-45) 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 <= -3.4e-23) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 8e-45) {
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 <= -3.4e-23: tmp = (a + (b * (d / c))) / c elif c <= 8e-45: 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 <= -3.4e-23) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= 8e-45) tmp = Float64(Float64(b + Float64(Float64(a * 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 <= -3.4e-23) tmp = (a + (b * (d / c))) / c; elseif (c <= 8e-45) 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, -3.4e-23], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 8e-45], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $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 -3.4 \cdot 10^{-23}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 8 \cdot 10^{-45}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -3.4000000000000001e-23Initial program 45.8%
Taylor expanded in c around inf 74.9%
associate-/l*79.3%
Simplified79.3%
if -3.4000000000000001e-23 < c < 7.99999999999999987e-45Initial program 73.7%
Taylor expanded in d around inf 86.6%
if 7.99999999999999987e-45 < c Initial program 57.2%
Taylor expanded in c around inf 71.7%
associate-/l*78.8%
Simplified78.8%
clear-num78.8%
un-div-inv78.8%
Applied egg-rr78.8%
Final simplification82.6%
(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 61.9%
Taylor expanded in c around inf 44.2%
Final simplification44.2%
(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 2024079
(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))))