
(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))) 1e+287) (* (/ 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))) <= 1e+287) {
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))) <= 1e+287) 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], 1e+287], 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 10^{+287}:\\
\;\;\;\;\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))) < 1.0000000000000001e287Initial program 80.8%
*-un-lft-identity80.8%
add-sqr-sqrt80.8%
times-frac80.6%
hypot-define80.6%
fma-define80.6%
hypot-define97.0%
Applied egg-rr97.0%
if 1.0000000000000001e287 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 13.6%
Taylor expanded in d around inf 42.7%
associate-/l*60.0%
Simplified60.0%
Final simplification89.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -2.9e+79)
(/ (+ a (* b (/ d c))) c)
(if (<= c -1.05e-157)
t_0
(if (<= c 2.4e-142)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 4.8e+85) t_0 (* (/ c (hypot c d)) (/ a (hypot c d)))))))))
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 <= -2.9e+79) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -1.05e-157) {
tmp = t_0;
} else if (c <= 2.4e-142) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 4.8e+85) {
tmp = t_0;
} else {
tmp = (c / hypot(c, d)) * (a / hypot(c, d));
}
return tmp;
}
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 <= -2.9e+79) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -1.05e-157) {
tmp = t_0;
} else if (c <= 2.4e-142) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 4.8e+85) {
tmp = t_0;
} else {
tmp = (c / Math.hypot(c, d)) * (a / Math.hypot(c, d));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -2.9e+79: tmp = (a + (b * (d / c))) / c elif c <= -1.05e-157: tmp = t_0 elif c <= 2.4e-142: tmp = (b + ((a * c) / d)) / d elif c <= 4.8e+85: tmp = t_0 else: tmp = (c / math.hypot(c, d)) * (a / math.hypot(c, d)) 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 <= -2.9e+79) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= -1.05e-157) tmp = t_0; elseif (c <= 2.4e-142) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 4.8e+85) tmp = t_0; else tmp = Float64(Float64(c / hypot(c, d)) * Float64(a / hypot(c, d))); 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 <= -2.9e+79) tmp = (a + (b * (d / c))) / c; elseif (c <= -1.05e-157) tmp = t_0; elseif (c <= 2.4e-142) tmp = (b + ((a * c) / d)) / d; elseif (c <= 4.8e+85) tmp = t_0; else tmp = (c / hypot(c, d)) * (a / hypot(c, d)); 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, -2.9e+79], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.05e-157], t$95$0, If[LessEqual[c, 2.4e-142], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.8e+85], t$95$0, N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $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 -2.9 \cdot 10^{+79}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -1.05 \cdot 10^{-157}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{-142}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 4.8 \cdot 10^{+85}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if c < -2.89999999999999992e79Initial program 47.1%
Taylor expanded in c around inf 81.2%
associate-/l*85.0%
Simplified85.0%
if -2.89999999999999992e79 < c < -1.05e-157 or 2.39999999999999988e-142 < c < 4.79999999999999993e85Initial program 86.8%
if -1.05e-157 < c < 2.39999999999999988e-142Initial program 75.9%
Taylor expanded in d around inf 98.6%
if 4.79999999999999993e85 < c Initial program 40.2%
Taylor expanded in a around inf 38.8%
*-commutative38.8%
Simplified38.8%
add-sqr-sqrt38.8%
hypot-undefine38.8%
hypot-undefine38.8%
times-frac85.0%
Applied egg-rr85.0%
Final simplification89.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -1.62e+131)
(/ (+ b (* a (/ c d))) d)
(if (<= d -2.1e-114)
t_0
(if (<= d 2e-122)
(/ (+ a (/ b (/ c d))) c)
(if (<= d 2e+74) t_0 (/ (+ b (* c (/ a d))) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.62e+131) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -2.1e-114) {
tmp = t_0;
} else if (d <= 2e-122) {
tmp = (a + (b / (c / d))) / c;
} else if (d <= 2e+74) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (d <= (-1.62d+131)) then
tmp = (b + (a * (c / d))) / d
else if (d <= (-2.1d-114)) then
tmp = t_0
else if (d <= 2d-122) then
tmp = (a + (b / (c / d))) / c
else if (d <= 2d+74) then
tmp = t_0
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 t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.62e+131) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -2.1e-114) {
tmp = t_0;
} else if (d <= 2e-122) {
tmp = (a + (b / (c / d))) / c;
} else if (d <= 2e+74) {
tmp = t_0;
} else {
tmp = (b + (c * (a / d))) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -1.62e+131: tmp = (b + (a * (c / d))) / d elif d <= -2.1e-114: tmp = t_0 elif d <= 2e-122: tmp = (a + (b / (c / d))) / c elif d <= 2e+74: tmp = t_0 else: tmp = (b + (c * (a / d))) / d 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 (d <= -1.62e+131) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= -2.1e-114) tmp = t_0; elseif (d <= 2e-122) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); elseif (d <= 2e+74) tmp = t_0; else tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); 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 (d <= -1.62e+131) tmp = (b + (a * (c / d))) / d; elseif (d <= -2.1e-114) tmp = t_0; elseif (d <= 2e-122) tmp = (a + (b / (c / d))) / c; elseif (d <= 2e+74) tmp = t_0; else tmp = (b + (c * (a / d))) / d; 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[d, -1.62e+131], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -2.1e-114], t$95$0, If[LessEqual[d, 2e-122], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2e+74], t$95$0, N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -1.62 \cdot 10^{+131}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq -2.1 \cdot 10^{-114}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2 \cdot 10^{-122}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\mathbf{elif}\;d \leq 2 \cdot 10^{+74}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\end{array}
\end{array}
if d < -1.6199999999999999e131Initial program 25.0%
Taylor expanded in d around inf 58.7%
associate-/l*79.0%
Simplified79.0%
if -1.6199999999999999e131 < d < -2.09999999999999993e-114 or 2.00000000000000012e-122 < d < 1.9999999999999999e74Initial program 83.8%
if -2.09999999999999993e-114 < d < 2.00000000000000012e-122Initial program 73.6%
Taylor expanded in c around inf 93.8%
associate-/l*95.7%
Simplified95.7%
clear-num95.7%
un-div-inv95.7%
Applied egg-rr95.7%
if 1.9999999999999999e74 < d Initial program 47.0%
Taylor expanded in d around inf 79.7%
associate-/l*85.1%
Simplified85.1%
clear-num85.0%
un-div-inv85.1%
Applied egg-rr85.1%
associate-/r/87.0%
Applied egg-rr87.0%
Final simplification87.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3.4e-124) (not (<= c 3.7e-90))) (/ (+ a (* b (/ d c))) c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.4e-124) || !(c <= 3.7e-90)) {
tmp = (a + (b * (d / c))) / 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.4d-124)) .or. (.not. (c <= 3.7d-90))) then
tmp = (a + (b * (d / c))) / 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.4e-124) || !(c <= 3.7e-90)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3.4e-124) or not (c <= 3.7e-90): tmp = (a + (b * (d / c))) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.4e-124) || !(c <= 3.7e-90)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -3.4e-124) || ~((c <= 3.7e-90))) tmp = (a + (b * (d / c))) / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.4e-124], N[Not[LessEqual[c, 3.7e-90]], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.4 \cdot 10^{-124} \lor \neg \left(c \leq 3.7 \cdot 10^{-90}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -3.4000000000000001e-124 or 3.70000000000000018e-90 < c Initial program 61.0%
Taylor expanded in c around inf 68.7%
associate-/l*71.7%
Simplified71.7%
if -3.4000000000000001e-124 < c < 3.70000000000000018e-90Initial program 80.0%
Taylor expanded in c around 0 80.3%
Final simplification74.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3.4e-106) (not (<= c 8.5e-113))) (/ (+ a (* b (/ d c))) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.4e-106) || !(c <= 8.5e-113)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-3.4d-106)) .or. (.not. (c <= 8.5d-113))) then
tmp = (a + (b * (d / c))) / c
else
tmp = (b + (a * (c / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.4e-106) || !(c <= 8.5e-113)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3.4e-106) or not (c <= 8.5e-113): tmp = (a + (b * (d / c))) / c else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.4e-106) || !(c <= 8.5e-113)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -3.4e-106) || ~((c <= 8.5e-113))) tmp = (a + (b * (d / c))) / c; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.4e-106], N[Not[LessEqual[c, 8.5e-113]], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.4 \cdot 10^{-106} \lor \neg \left(c \leq 8.5 \cdot 10^{-113}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if c < -3.39999999999999982e-106 or 8.4999999999999995e-113 < c Initial program 61.3%
Taylor expanded in c around inf 69.6%
associate-/l*72.1%
Simplified72.1%
if -3.39999999999999982e-106 < c < 8.4999999999999995e-113Initial program 79.0%
Taylor expanded in d around inf 95.8%
associate-/l*95.2%
Simplified95.2%
Final simplification79.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.2e+85) (not (<= d 1.3e-121))) (/ (+ b (* c (/ a d))) d) (/ (+ a (/ b (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.2e+85) || !(d <= 1.3e-121)) {
tmp = (b + (c * (a / 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 ((d <= (-2.2d+85)) .or. (.not. (d <= 1.3d-121))) then
tmp = (b + (c * (a / 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 ((d <= -2.2e+85) || !(d <= 1.3e-121)) {
tmp = (b + (c * (a / d))) / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.2e+85) or not (d <= 1.3e-121): 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 ((d <= -2.2e+85) || !(d <= 1.3e-121)) 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 ((d <= -2.2e+85) || ~((d <= 1.3e-121))) tmp = (b + (c * (a / d))) / d; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.2e+85], N[Not[LessEqual[d, 1.3e-121]], $MachinePrecision]], 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}\;d \leq -2.2 \cdot 10^{+85} \lor \neg \left(d \leq 1.3 \cdot 10^{-121}\right):\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -2.2000000000000002e85 or 1.29999999999999993e-121 < d Initial program 57.3%
Taylor expanded in d around inf 66.1%
associate-/l*73.4%
Simplified73.4%
clear-num73.3%
un-div-inv73.3%
Applied egg-rr73.3%
associate-/r/74.4%
Applied egg-rr74.4%
if -2.2000000000000002e85 < d < 1.29999999999999993e-121Initial program 75.0%
Taylor expanded in c around inf 81.9%
associate-/l*83.3%
Simplified83.3%
clear-num83.3%
un-div-inv83.3%
Applied egg-rr83.3%
Final simplification79.0%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.45e-108) (not (<= c 4.9e-114))) (/ (+ a (* b (/ d c))) c) (/ (+ b (/ (* a c) d)) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.45e-108) || !(c <= 4.9e-114)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + ((a * c) / d)) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-1.45d-108)) .or. (.not. (c <= 4.9d-114))) then
tmp = (a + (b * (d / c))) / c
else
tmp = (b + ((a * c) / d)) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.45e-108) || !(c <= 4.9e-114)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + ((a * c) / d)) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.45e-108) or not (c <= 4.9e-114): tmp = (a + (b * (d / c))) / c else: tmp = (b + ((a * c) / d)) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.45e-108) || !(c <= 4.9e-114)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.45e-108) || ~((c <= 4.9e-114))) tmp = (a + (b * (d / c))) / c; else tmp = (b + ((a * c) / d)) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.45e-108], N[Not[LessEqual[c, 4.9e-114]], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.45 \cdot 10^{-108} \lor \neg \left(c \leq 4.9 \cdot 10^{-114}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\end{array}
\end{array}
if c < -1.45e-108 or 4.8999999999999997e-114 < c Initial program 61.3%
Taylor expanded in c around inf 69.6%
associate-/l*72.1%
Simplified72.1%
if -1.45e-108 < c < 4.8999999999999997e-114Initial program 79.0%
Taylor expanded in d around inf 95.8%
Final simplification79.2%
(FPCore (a b c d) :precision binary64 (if (<= c -3.7e-125) (/ (+ a (/ b (/ c d))) c) (if (<= c 4.8e-91) (/ b d) (/ (+ a (* b (/ d c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.7e-125) {
tmp = (a + (b / (c / d))) / c;
} else if (c <= 4.8e-91) {
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 (c <= (-3.7d-125)) then
tmp = (a + (b / (c / d))) / c
else if (c <= 4.8d-91) 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 (c <= -3.7e-125) {
tmp = (a + (b / (c / d))) / c;
} else if (c <= 4.8e-91) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3.7e-125: tmp = (a + (b / (c / d))) / c elif c <= 4.8e-91: tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3.7e-125) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); elseif (c <= 4.8e-91) 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 (c <= -3.7e-125) tmp = (a + (b / (c / d))) / c; elseif (c <= 4.8e-91) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.7e-125], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 4.8e-91], 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}\;c \leq -3.7 \cdot 10^{-125}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\mathbf{elif}\;c \leq 4.8 \cdot 10^{-91}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -3.6999999999999999e-125Initial program 65.5%
Taylor expanded in c around inf 70.7%
associate-/l*73.7%
Simplified73.7%
clear-num73.7%
un-div-inv73.8%
Applied egg-rr73.8%
if -3.6999999999999999e-125 < c < 4.80000000000000022e-91Initial program 80.0%
Taylor expanded in c around 0 80.3%
if 4.80000000000000022e-91 < c Initial program 56.6%
Taylor expanded in c around inf 66.8%
associate-/l*69.8%
Simplified69.8%
Final simplification74.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.7e-77) (not (<= c 1.8e-70))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.7e-77) || !(c <= 1.8e-70)) {
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 <= (-2.7d-77)) .or. (.not. (c <= 1.8d-70))) 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 <= -2.7e-77) || !(c <= 1.8e-70)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.7e-77) or not (c <= 1.8e-70): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.7e-77) || !(c <= 1.8e-70)) 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 <= -2.7e-77) || ~((c <= 1.8e-70))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.7e-77], N[Not[LessEqual[c, 1.8e-70]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.7 \cdot 10^{-77} \lor \neg \left(c \leq 1.8 \cdot 10^{-70}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -2.7e-77 or 1.8000000000000001e-70 < c Initial program 59.7%
Taylor expanded in c around inf 62.8%
if -2.7e-77 < c < 1.8000000000000001e-70Initial program 80.7%
Taylor expanded in c around 0 75.4%
Final simplification66.9%
(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 66.6%
Taylor expanded in c around inf 46.7%
Final simplification46.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 2024095
(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))))