
(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
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -2.1e+139)
(/ (+ a (* b (/ d c))) c)
(if (<= c -7.8e-74)
t_0
(if (<= c 7.2e-88)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 1.9e-35)
t_0
(if (<= c 1.9e+14)
(/ (+ b (* a (/ c d))) d)
(/ (fma b (/ d c) a) 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 <= -2.1e+139) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -7.8e-74) {
tmp = t_0;
} else if (c <= 7.2e-88) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 1.9e-35) {
tmp = t_0;
} else if (c <= 1.9e+14) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = fma(b, (d / c), a) / 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 <= -2.1e+139) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= -7.8e-74) tmp = t_0; elseif (c <= 7.2e-88) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 1.9e-35) tmp = t_0; elseif (c <= 1.9e+14) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(fma(b, Float64(d / c), a) / 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[c, -2.1e+139], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -7.8e-74], t$95$0, If[LessEqual[c, 7.2e-88], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.9e-35], t$95$0, If[LessEqual[c, 1.9e+14], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(b * N[(d / c), $MachinePrecision] + a), $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 -2.1 \cdot 10^{+139}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -7.8 \cdot 10^{-74}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 7.2 \cdot 10^{-88}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{-35}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{+14}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\end{array}
\end{array}
if c < -2.0999999999999999e139Initial program 20.9%
Taylor expanded in c around inf 91.1%
associate-/l*95.7%
Simplified95.7%
if -2.0999999999999999e139 < c < -7.8000000000000003e-74 or 7.1999999999999999e-88 < c < 1.9000000000000001e-35Initial program 84.0%
if -7.8000000000000003e-74 < c < 7.1999999999999999e-88Initial program 68.7%
Taylor expanded in d around inf 92.3%
if 1.9000000000000001e-35 < c < 1.9e14Initial program 77.2%
Taylor expanded in d around inf 85.2%
associate-/l*85.3%
Simplified85.3%
if 1.9e14 < c Initial program 44.8%
Taylor expanded in c around inf 79.2%
+-commutative79.2%
associate-/l*84.5%
fma-define84.6%
Simplified84.6%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 2e+302) (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d)) (/ (fma b (/ d c) a) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 2e+302) {
tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = fma(b, (d / c), a) / 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))) <= 2e+302) tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(fma(b, Float64(d / c), a) / 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], 2e+302], N[(N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(b * N[(d / c), $MachinePrecision] + a), $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 2 \cdot 10^{+302}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 2.0000000000000002e302Initial program 77.3%
*-un-lft-identity77.3%
add-sqr-sqrt77.2%
times-frac77.2%
hypot-define77.2%
fma-define77.2%
hypot-define97.0%
Applied egg-rr97.0%
associate-*l/97.2%
*-un-lft-identity97.2%
Applied egg-rr97.2%
if 2.0000000000000002e302 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 6.5%
Taylor expanded in c around inf 50.7%
+-commutative50.7%
associate-/l*59.8%
fma-define59.8%
Simplified59.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -7.5e+138)
(/ (+ a (* b (/ d c))) c)
(if (<= c -8e-74)
t_0
(if (<= c 8.4e-88)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 8.5e-40)
t_0
(if (<= c 6.2e+17)
(/ (+ b (* a (/ c d))) d)
(/ (+ a (/ 1.0 (/ (/ c d) b))) 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 <= -7.5e+138) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -8e-74) {
tmp = t_0;
} else if (c <= 8.4e-88) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 8.5e-40) {
tmp = t_0;
} else if (c <= 6.2e+17) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (1.0 / ((c / d) / b))) / 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 <= (-7.5d+138)) then
tmp = (a + (b * (d / c))) / c
else if (c <= (-8d-74)) then
tmp = t_0
else if (c <= 8.4d-88) then
tmp = (b + ((a * c) / d)) / d
else if (c <= 8.5d-40) then
tmp = t_0
else if (c <= 6.2d+17) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a + (1.0d0 / ((c / d) / b))) / 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 <= -7.5e+138) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -8e-74) {
tmp = t_0;
} else if (c <= 8.4e-88) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 8.5e-40) {
tmp = t_0;
} else if (c <= 6.2e+17) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (1.0 / ((c / d) / b))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -7.5e+138: tmp = (a + (b * (d / c))) / c elif c <= -8e-74: tmp = t_0 elif c <= 8.4e-88: tmp = (b + ((a * c) / d)) / d elif c <= 8.5e-40: tmp = t_0 elif c <= 6.2e+17: tmp = (b + (a * (c / d))) / d else: tmp = (a + (1.0 / ((c / d) / b))) / 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 <= -7.5e+138) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= -8e-74) tmp = t_0; elseif (c <= 8.4e-88) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 8.5e-40) tmp = t_0; elseif (c <= 6.2e+17) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(1.0 / Float64(Float64(c / d) / b))) / 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 <= -7.5e+138) tmp = (a + (b * (d / c))) / c; elseif (c <= -8e-74) tmp = t_0; elseif (c <= 8.4e-88) tmp = (b + ((a * c) / d)) / d; elseif (c <= 8.5e-40) tmp = t_0; elseif (c <= 6.2e+17) tmp = (b + (a * (c / d))) / d; else tmp = (a + (1.0 / ((c / d) / b))) / 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, -7.5e+138], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -8e-74], t$95$0, If[LessEqual[c, 8.4e-88], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8.5e-40], t$95$0, If[LessEqual[c, 6.2e+17], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(1.0 / N[(N[(c / d), $MachinePrecision] / b), $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 -7.5 \cdot 10^{+138}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -8 \cdot 10^{-74}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 8.4 \cdot 10^{-88}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 8.5 \cdot 10^{-40}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 6.2 \cdot 10^{+17}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{1}{\frac{\frac{c}{d}}{b}}}{c}\\
\end{array}
\end{array}
if c < -7.4999999999999999e138Initial program 20.9%
Taylor expanded in c around inf 91.1%
associate-/l*95.7%
Simplified95.7%
if -7.4999999999999999e138 < c < -7.99999999999999966e-74 or 8.3999999999999998e-88 < c < 8.4999999999999998e-40Initial program 84.0%
if -7.99999999999999966e-74 < c < 8.3999999999999998e-88Initial program 68.7%
Taylor expanded in d around inf 92.3%
if 8.4999999999999998e-40 < c < 6.2e17Initial program 77.2%
Taylor expanded in d around inf 85.2%
associate-/l*85.3%
Simplified85.3%
if 6.2e17 < c Initial program 44.8%
Taylor expanded in c around inf 79.2%
clear-num79.2%
inv-pow79.2%
*-commutative79.2%
associate-/r*84.6%
Applied egg-rr84.6%
unpow-184.6%
Simplified84.6%
(FPCore (a b c d)
:precision binary64
(if (<= c -59000000.0)
(/ (+ a (* b (/ d c))) c)
(if (<= c 2.2e+15)
(/ (+ b (/ (* a c) d)) d)
(/ (+ a (/ 1.0 (/ (/ c d) b))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -59000000.0) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 2.2e+15) {
tmp = (b + ((a * c) / d)) / d;
} else {
tmp = (a + (1.0 / ((c / d) / b))) / 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 <= (-59000000.0d0)) then
tmp = (a + (b * (d / c))) / c
else if (c <= 2.2d+15) then
tmp = (b + ((a * c) / d)) / d
else
tmp = (a + (1.0d0 / ((c / d) / b))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -59000000.0) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 2.2e+15) {
tmp = (b + ((a * c) / d)) / d;
} else {
tmp = (a + (1.0 / ((c / d) / b))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -59000000.0: tmp = (a + (b * (d / c))) / c elif c <= 2.2e+15: tmp = (b + ((a * c) / d)) / d else: tmp = (a + (1.0 / ((c / d) / b))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -59000000.0) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= 2.2e+15) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); else tmp = Float64(Float64(a + Float64(1.0 / Float64(Float64(c / d) / b))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -59000000.0) tmp = (a + (b * (d / c))) / c; elseif (c <= 2.2e+15) tmp = (b + ((a * c) / d)) / d; else tmp = (a + (1.0 / ((c / d) / b))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -59000000.0], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 2.2e+15], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(1.0 / N[(N[(c / d), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -59000000:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 2.2 \cdot 10^{+15}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{1}{\frac{\frac{c}{d}}{b}}}{c}\\
\end{array}
\end{array}
if c < -5.9e7Initial program 47.8%
Taylor expanded in c around inf 78.8%
associate-/l*82.6%
Simplified82.6%
if -5.9e7 < c < 2.2e15Initial program 72.7%
Taylor expanded in d around inf 83.4%
if 2.2e15 < c Initial program 44.8%
Taylor expanded in c around inf 79.2%
clear-num79.2%
inv-pow79.2%
*-commutative79.2%
associate-/r*84.6%
Applied egg-rr84.6%
unpow-184.6%
Simplified84.6%
(FPCore (a b c d) :precision binary64 (if (or (<= c -122000000.0) (not (<= c 6e+16))) (/ (+ a (* b (/ d c))) c) (/ (+ b (/ (* a c) d)) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -122000000.0) || !(c <= 6e+16)) {
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 <= (-122000000.0d0)) .or. (.not. (c <= 6d+16))) 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 <= -122000000.0) || !(c <= 6e+16)) {
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 <= -122000000.0) or not (c <= 6e+16): 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 <= -122000000.0) || !(c <= 6e+16)) 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 <= -122000000.0) || ~((c <= 6e+16))) 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, -122000000.0], N[Not[LessEqual[c, 6e+16]], $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 -122000000 \lor \neg \left(c \leq 6 \cdot 10^{+16}\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.22e8 or 6e16 < c Initial program 46.5%
Taylor expanded in c around inf 79.0%
associate-/l*83.4%
Simplified83.4%
if -1.22e8 < c < 6e16Initial program 72.7%
Taylor expanded in d around inf 83.4%
Final simplification83.4%
(FPCore (a b c d) :precision binary64 (if (or (<= c -290000.0) (not (<= c 6.2e+16))) (/ (+ a (* b (/ d c))) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -290000.0) || !(c <= 6.2e+16)) {
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 <= (-290000.0d0)) .or. (.not. (c <= 6.2d+16))) 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 <= -290000.0) || !(c <= 6.2e+16)) {
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 <= -290000.0) or not (c <= 6.2e+16): 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 <= -290000.0) || !(c <= 6.2e+16)) 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 <= -290000.0) || ~((c <= 6.2e+16))) 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, -290000.0], N[Not[LessEqual[c, 6.2e+16]], $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 -290000 \lor \neg \left(c \leq 6.2 \cdot 10^{+16}\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 < -2.9e5 or 6.2e16 < c Initial program 46.5%
Taylor expanded in c around inf 79.0%
associate-/l*83.4%
Simplified83.4%
if -2.9e5 < c < 6.2e16Initial program 72.7%
Taylor expanded in d around inf 83.4%
associate-/l*83.1%
Simplified83.1%
Final simplification83.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.08e-73) (not (<= c 0.000235))) (/ (+ a (* b (/ d c))) c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.08e-73) || !(c <= 0.000235)) {
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 <= (-1.08d-73)) .or. (.not. (c <= 0.000235d0))) 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 <= -1.08e-73) || !(c <= 0.000235)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.08e-73) or not (c <= 0.000235): tmp = (a + (b * (d / c))) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.08e-73) || !(c <= 0.000235)) 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 <= -1.08e-73) || ~((c <= 0.000235))) tmp = (a + (b * (d / c))) / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.08e-73], N[Not[LessEqual[c, 0.000235]], $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 -1.08 \cdot 10^{-73} \lor \neg \left(c \leq 0.000235\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -1.08000000000000007e-73 or 2.34999999999999993e-4 < c Initial program 51.1%
Taylor expanded in c around inf 75.4%
associate-/l*79.4%
Simplified79.4%
if -1.08000000000000007e-73 < c < 2.34999999999999993e-4Initial program 70.3%
Taylor expanded in c around 0 67.5%
Final simplification74.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3800.0) (not (<= d 2.45e-45))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3800.0) || !(d <= 2.45e-45)) {
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 <= (-3800.0d0)) .or. (.not. (d <= 2.45d-45))) 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 <= -3800.0) || !(d <= 2.45e-45)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3800.0) or not (d <= 2.45e-45): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3800.0) || !(d <= 2.45e-45)) 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 <= -3800.0) || ~((d <= 2.45e-45))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3800.0], N[Not[LessEqual[d, 2.45e-45]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3800 \lor \neg \left(d \leq 2.45 \cdot 10^{-45}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -3800 or 2.4499999999999999e-45 < d Initial program 53.1%
Taylor expanded in c around 0 61.1%
if -3800 < d < 2.4499999999999999e-45Initial program 67.8%
Taylor expanded in c around inf 70.2%
Final simplification64.9%
(FPCore (a b c d) :precision binary64 (if (<= d 1.5e+163) (/ a c) (/ a d)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= 1.5e+163) {
tmp = a / c;
} else {
tmp = a / 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.5d+163) then
tmp = a / c
else
tmp = a / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= 1.5e+163) {
tmp = a / c;
} else {
tmp = a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= 1.5e+163: tmp = a / c else: tmp = a / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= 1.5e+163) tmp = Float64(a / c); else tmp = Float64(a / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= 1.5e+163) tmp = a / c; else tmp = a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, 1.5e+163], N[(a / c), $MachinePrecision], N[(a / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq 1.5 \cdot 10^{+163}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{d}\\
\end{array}
\end{array}
if d < 1.50000000000000007e163Initial program 60.6%
Taylor expanded in c around inf 46.6%
if 1.50000000000000007e163 < d Initial program 50.3%
*-un-lft-identity50.3%
add-sqr-sqrt50.3%
times-frac50.3%
hypot-define50.3%
fma-define50.3%
hypot-define69.5%
Applied egg-rr69.5%
Taylor expanded in c around 0 87.3%
Taylor expanded in c around inf 39.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 59.3%
Taylor expanded in c around inf 43.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 2024110
(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))))