
(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 (<= c -1.3e+66)
(/ (+ a (/ 1.0 (/ (/ c b) d))) c)
(if (<= c -4.8e-41)
(* (fma d b (* c a)) (pow (hypot d c) -2.0))
(if (<= c 4.9e+41)
(/ (+ b (* a (/ c d))) d)
(if (<= c 7.6e+92)
(/ (+ (* c a) (* b d)) (+ (* c c) (* d d)))
(if (<= c 1.5e+196)
(/ (/ a (hypot d c)) (/ (hypot d c) c))
(/ (+ a (* b (/ d c))) c)))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.3e+66) {
tmp = (a + (1.0 / ((c / b) / d))) / c;
} else if (c <= -4.8e-41) {
tmp = fma(d, b, (c * a)) * pow(hypot(d, c), -2.0);
} else if (c <= 4.9e+41) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 7.6e+92) {
tmp = ((c * a) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 1.5e+196) {
tmp = (a / hypot(d, c)) / (hypot(d, c) / c);
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.3e+66) tmp = Float64(Float64(a + Float64(1.0 / Float64(Float64(c / b) / d))) / c); elseif (c <= -4.8e-41) tmp = Float64(fma(d, b, Float64(c * a)) * (hypot(d, c) ^ -2.0)); elseif (c <= 4.9e+41) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 7.6e+92) tmp = Float64(Float64(Float64(c * a) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 1.5e+196) tmp = Float64(Float64(a / hypot(d, c)) / Float64(hypot(d, c) / c)); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.3e+66], N[(N[(a + N[(1.0 / N[(N[(c / b), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -4.8e-41], N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] * N[Power[N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.9e+41], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 7.6e+92], N[(N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.5e+196], N[(N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.3 \cdot 10^{+66}:\\
\;\;\;\;\frac{a + \frac{1}{\frac{\frac{c}{b}}{d}}}{c}\\
\mathbf{elif}\;c \leq -4.8 \cdot 10^{-41}:\\
\;\;\;\;\mathsf{fma}\left(d, b, c \cdot a\right) \cdot {\left(\mathsf{hypot}\left(d, c\right)\right)}^{-2}\\
\mathbf{elif}\;c \leq 4.9 \cdot 10^{+41}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 7.6 \cdot 10^{+92}:\\
\;\;\;\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 1.5 \cdot 10^{+196}:\\
\;\;\;\;\frac{\frac{a}{\mathsf{hypot}\left(d, c\right)}}{\frac{\mathsf{hypot}\left(d, c\right)}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -1.30000000000000006e66Initial program 41.5%
Taylor expanded in c around inf 92.2%
clear-num92.2%
inv-pow92.2%
Applied egg-rr92.2%
unpow-192.2%
associate-/r*92.6%
Simplified92.6%
if -1.30000000000000006e66 < c < -4.80000000000000044e-41Initial program 95.2%
fma-define95.2%
fma-define95.3%
Simplified95.3%
fma-define95.3%
+-commutative95.3%
Applied egg-rr95.3%
fma-define95.2%
div-inv95.1%
fma-define95.1%
+-commutative95.1%
add-sqr-sqrt95.2%
hypot-undefine95.2%
hypot-undefine95.2%
unpow295.2%
pow-flip95.3%
metadata-eval95.3%
Applied egg-rr95.3%
fma-undefine95.3%
*-commutative95.3%
fma-undefine95.3%
Simplified95.3%
if -4.80000000000000044e-41 < c < 4.8999999999999999e41Initial program 68.0%
Taylor expanded in d around inf 86.5%
associate-/l*87.1%
Simplified87.1%
if 4.8999999999999999e41 < c < 7.6000000000000001e92Initial program 84.3%
if 7.6000000000000001e92 < c < 1.4999999999999999e196Initial program 40.9%
Taylor expanded in a around inf 41.0%
*-commutative41.0%
Simplified41.0%
+-commutative41.0%
add-sqr-sqrt41.0%
hypot-undefine41.0%
hypot-undefine41.0%
times-frac91.0%
Applied egg-rr91.0%
*-commutative91.0%
clear-num91.0%
un-div-inv91.1%
Applied egg-rr91.1%
if 1.4999999999999999e196 < c Initial program 33.5%
Taylor expanded in c around inf 94.9%
associate-/l*100.0%
Simplified100.0%
Final simplification90.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (* c a) (* b d))))
(if (<= c -8e+65)
(/ (+ a (/ 1.0 (/ (/ c b) d))) c)
(if (<= c -1.5e-40)
(/ t_0 (fma c c (* d d)))
(if (<= c 3.1e+41)
(/ (+ b (* a (/ c d))) d)
(if (<= c 1.56e+92)
(/ t_0 (+ (* c c) (* d d)))
(if (<= c 1.26e+196)
(* (/ a (hypot d c)) (/ c (hypot d c)))
(/ (+ a (* b (/ d c))) c))))))))
double code(double a, double b, double c, double d) {
double t_0 = (c * a) + (b * d);
double tmp;
if (c <= -8e+65) {
tmp = (a + (1.0 / ((c / b) / d))) / c;
} else if (c <= -1.5e-40) {
tmp = t_0 / fma(c, c, (d * d));
} else if (c <= 3.1e+41) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.56e+92) {
tmp = t_0 / ((c * c) + (d * d));
} else if (c <= 1.26e+196) {
tmp = (a / hypot(d, c)) * (c / hypot(d, c));
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(c * a) + Float64(b * d)) tmp = 0.0 if (c <= -8e+65) tmp = Float64(Float64(a + Float64(1.0 / Float64(Float64(c / b) / d))) / c); elseif (c <= -1.5e-40) tmp = Float64(t_0 / fma(c, c, Float64(d * d))); elseif (c <= 3.1e+41) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 1.56e+92) tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 1.26e+196) tmp = Float64(Float64(a / hypot(d, c)) * Float64(c / hypot(d, c))); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -8e+65], N[(N[(a + N[(1.0 / N[(N[(c / b), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.5e-40], N[(t$95$0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.1e+41], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.56e+92], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.26e+196], N[(N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(c / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot a + b \cdot d\\
\mathbf{if}\;c \leq -8 \cdot 10^{+65}:\\
\;\;\;\;\frac{a + \frac{1}{\frac{\frac{c}{b}}{d}}}{c}\\
\mathbf{elif}\;c \leq -1.5 \cdot 10^{-40}:\\
\;\;\;\;\frac{t\_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;c \leq 3.1 \cdot 10^{+41}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.56 \cdot 10^{+92}:\\
\;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 1.26 \cdot 10^{+196}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{c}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -7.9999999999999999e65Initial program 41.5%
Taylor expanded in c around inf 92.2%
clear-num92.2%
inv-pow92.2%
Applied egg-rr92.2%
unpow-192.2%
associate-/r*92.6%
Simplified92.6%
if -7.9999999999999999e65 < c < -1.5000000000000001e-40Initial program 95.2%
fma-define95.2%
fma-define95.3%
Simplified95.3%
fma-define95.3%
+-commutative95.3%
Applied egg-rr95.3%
if -1.5000000000000001e-40 < c < 3.1e41Initial program 68.0%
Taylor expanded in d around inf 86.5%
associate-/l*87.1%
Simplified87.1%
if 3.1e41 < c < 1.55999999999999987e92Initial program 84.3%
if 1.55999999999999987e92 < c < 1.26e196Initial program 40.9%
Taylor expanded in a around inf 41.0%
*-commutative41.0%
Simplified41.0%
+-commutative41.0%
add-sqr-sqrt41.0%
hypot-undefine41.0%
hypot-undefine41.0%
times-frac91.0%
Applied egg-rr91.0%
if 1.26e196 < c Initial program 33.5%
Taylor expanded in c around inf 94.9%
associate-/l*100.0%
Simplified100.0%
Final simplification90.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (* c a) (* b d))))
(if (<= c -4.6e+66)
(/ (+ a (/ 1.0 (/ (/ c b) d))) c)
(if (<= c -9e-43)
(/ t_0 (fma c c (* d d)))
(if (<= c 3.1e+41)
(/ (+ b (* a (/ c d))) d)
(if (<= c 7.2e+92)
(/ t_0 (+ (* c c) (* d d)))
(if (<= c 9.5e+195)
(/ (/ a (hypot d c)) (/ (hypot d c) c))
(/ (+ a (* b (/ d c))) c))))))))
double code(double a, double b, double c, double d) {
double t_0 = (c * a) + (b * d);
double tmp;
if (c <= -4.6e+66) {
tmp = (a + (1.0 / ((c / b) / d))) / c;
} else if (c <= -9e-43) {
tmp = t_0 / fma(c, c, (d * d));
} else if (c <= 3.1e+41) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 7.2e+92) {
tmp = t_0 / ((c * c) + (d * d));
} else if (c <= 9.5e+195) {
tmp = (a / hypot(d, c)) / (hypot(d, c) / c);
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(c * a) + Float64(b * d)) tmp = 0.0 if (c <= -4.6e+66) tmp = Float64(Float64(a + Float64(1.0 / Float64(Float64(c / b) / d))) / c); elseif (c <= -9e-43) tmp = Float64(t_0 / fma(c, c, Float64(d * d))); elseif (c <= 3.1e+41) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 7.2e+92) tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 9.5e+195) tmp = Float64(Float64(a / hypot(d, c)) / Float64(hypot(d, c) / c)); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -4.6e+66], N[(N[(a + N[(1.0 / N[(N[(c / b), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -9e-43], N[(t$95$0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.1e+41], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 7.2e+92], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 9.5e+195], N[(N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot a + b \cdot d\\
\mathbf{if}\;c \leq -4.6 \cdot 10^{+66}:\\
\;\;\;\;\frac{a + \frac{1}{\frac{\frac{c}{b}}{d}}}{c}\\
\mathbf{elif}\;c \leq -9 \cdot 10^{-43}:\\
\;\;\;\;\frac{t\_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;c \leq 3.1 \cdot 10^{+41}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 7.2 \cdot 10^{+92}:\\
\;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 9.5 \cdot 10^{+195}:\\
\;\;\;\;\frac{\frac{a}{\mathsf{hypot}\left(d, c\right)}}{\frac{\mathsf{hypot}\left(d, c\right)}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -4.6e66Initial program 41.5%
Taylor expanded in c around inf 92.2%
clear-num92.2%
inv-pow92.2%
Applied egg-rr92.2%
unpow-192.2%
associate-/r*92.6%
Simplified92.6%
if -4.6e66 < c < -9.0000000000000005e-43Initial program 95.2%
fma-define95.2%
fma-define95.3%
Simplified95.3%
fma-define95.3%
+-commutative95.3%
Applied egg-rr95.3%
if -9.0000000000000005e-43 < c < 3.1e41Initial program 68.0%
Taylor expanded in d around inf 86.5%
associate-/l*87.1%
Simplified87.1%
if 3.1e41 < c < 7.2e92Initial program 84.3%
if 7.2e92 < c < 9.5000000000000004e195Initial program 40.9%
Taylor expanded in a around inf 41.0%
*-commutative41.0%
Simplified41.0%
+-commutative41.0%
add-sqr-sqrt41.0%
hypot-undefine41.0%
hypot-undefine41.0%
times-frac91.0%
Applied egg-rr91.0%
*-commutative91.0%
clear-num91.0%
un-div-inv91.1%
Applied egg-rr91.1%
if 9.5000000000000004e195 < c Initial program 33.5%
Taylor expanded in c around inf 94.9%
associate-/l*100.0%
Simplified100.0%
Final simplification90.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ a (/ 1.0 (/ (/ c b) d))) c)))
(if (<= c -1.3e+65)
t_0
(if (<= c -5.2e-41)
(/ (+ (* c a) (* b d)) (fma c c (* d d)))
(if (<= c 8e+69) (/ (+ b (* a (/ c d))) d) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (a + (1.0 / ((c / b) / d))) / c;
double tmp;
if (c <= -1.3e+65) {
tmp = t_0;
} else if (c <= -5.2e-41) {
tmp = ((c * a) + (b * d)) / fma(c, c, (d * d));
} else if (c <= 8e+69) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(a + Float64(1.0 / Float64(Float64(c / b) / d))) / c) tmp = 0.0 if (c <= -1.3e+65) tmp = t_0; elseif (c <= -5.2e-41) tmp = Float64(Float64(Float64(c * a) + Float64(b * d)) / fma(c, c, Float64(d * d))); elseif (c <= 8e+69) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(1.0 / N[(N[(c / b), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.3e+65], t$95$0, If[LessEqual[c, -5.2e-41], N[(N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 8e+69], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + \frac{1}{\frac{\frac{c}{b}}{d}}}{c}\\
\mathbf{if}\;c \leq -1.3 \cdot 10^{+65}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -5.2 \cdot 10^{-41}:\\
\;\;\;\;\frac{c \cdot a + b \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;c \leq 8 \cdot 10^{+69}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.30000000000000001e65 or 8.0000000000000006e69 < c Initial program 42.9%
Taylor expanded in c around inf 85.9%
clear-num85.9%
inv-pow85.9%
Applied egg-rr85.9%
unpow-185.9%
associate-/r*87.8%
Simplified87.8%
if -1.30000000000000001e65 < c < -5.1999999999999999e-41Initial program 95.2%
fma-define95.2%
fma-define95.3%
Simplified95.3%
fma-define95.3%
+-commutative95.3%
Applied egg-rr95.3%
if -5.1999999999999999e-41 < c < 8.0000000000000006e69Initial program 69.0%
Taylor expanded in d around inf 85.9%
associate-/l*86.4%
Simplified86.4%
Final simplification87.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ a (/ 1.0 (/ (/ c b) d))) c)))
(if (<= c -3.1e+65)
t_0
(if (<= c -6.6e-43)
(/ (+ (* c a) (* b d)) (+ (* c c) (* d d)))
(if (<= c 1.7e+71) (/ (+ b (* a (/ c d))) d) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (a + (1.0 / ((c / b) / d))) / c;
double tmp;
if (c <= -3.1e+65) {
tmp = t_0;
} else if (c <= -6.6e-43) {
tmp = ((c * a) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 1.7e+71) {
tmp = (b + (a * (c / 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 + (1.0d0 / ((c / b) / d))) / c
if (c <= (-3.1d+65)) then
tmp = t_0
else if (c <= (-6.6d-43)) then
tmp = ((c * a) + (b * d)) / ((c * c) + (d * d))
else if (c <= 1.7d+71) then
tmp = (b + (a * (c / 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 + (1.0 / ((c / b) / d))) / c;
double tmp;
if (c <= -3.1e+65) {
tmp = t_0;
} else if (c <= -6.6e-43) {
tmp = ((c * a) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 1.7e+71) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a + (1.0 / ((c / b) / d))) / c tmp = 0 if c <= -3.1e+65: tmp = t_0 elif c <= -6.6e-43: tmp = ((c * a) + (b * d)) / ((c * c) + (d * d)) elif c <= 1.7e+71: tmp = (b + (a * (c / d))) / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a + Float64(1.0 / Float64(Float64(c / b) / d))) / c) tmp = 0.0 if (c <= -3.1e+65) tmp = t_0; elseif (c <= -6.6e-43) tmp = Float64(Float64(Float64(c * a) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 1.7e+71) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a + (1.0 / ((c / b) / d))) / c; tmp = 0.0; if (c <= -3.1e+65) tmp = t_0; elseif (c <= -6.6e-43) tmp = ((c * a) + (b * d)) / ((c * c) + (d * d)); elseif (c <= 1.7e+71) tmp = (b + (a * (c / d))) / d; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(1.0 / N[(N[(c / b), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3.1e+65], t$95$0, If[LessEqual[c, -6.6e-43], N[(N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.7e+71], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + \frac{1}{\frac{\frac{c}{b}}{d}}}{c}\\
\mathbf{if}\;c \leq -3.1 \cdot 10^{+65}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -6.6 \cdot 10^{-43}:\\
\;\;\;\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 1.7 \cdot 10^{+71}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.09999999999999991e65 or 1.6999999999999999e71 < c Initial program 42.9%
Taylor expanded in c around inf 85.9%
clear-num85.9%
inv-pow85.9%
Applied egg-rr85.9%
unpow-185.9%
associate-/r*87.8%
Simplified87.8%
if -3.09999999999999991e65 < c < -6.60000000000000031e-43Initial program 95.2%
if -6.60000000000000031e-43 < c < 1.6999999999999999e71Initial program 69.0%
Taylor expanded in d around inf 85.9%
associate-/l*86.4%
Simplified86.4%
Final simplification87.7%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.2e-39) (not (<= c 9e+69))) (/ (+ a (/ 1.0 (/ (/ c b) d))) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.2e-39) || !(c <= 9e+69)) {
tmp = (a + (1.0 / ((c / b) / d))) / 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.2d-39)) .or. (.not. (c <= 9d+69))) then
tmp = (a + (1.0d0 / ((c / b) / d))) / 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.2e-39) || !(c <= 9e+69)) {
tmp = (a + (1.0 / ((c / b) / d))) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.2e-39) or not (c <= 9e+69): tmp = (a + (1.0 / ((c / b) / d))) / c else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.2e-39) || !(c <= 9e+69)) tmp = Float64(Float64(a + Float64(1.0 / Float64(Float64(c / b) / d))) / 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 <= -1.2e-39) || ~((c <= 9e+69))) tmp = (a + (1.0 / ((c / b) / d))) / c; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.2e-39], N[Not[LessEqual[c, 9e+69]], $MachinePrecision]], N[(N[(a + N[(1.0 / N[(N[(c / b), $MachinePrecision] / d), $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 -1.2 \cdot 10^{-39} \lor \neg \left(c \leq 9 \cdot 10^{+69}\right):\\
\;\;\;\;\frac{a + \frac{1}{\frac{\frac{c}{b}}{d}}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if c < -1.20000000000000008e-39 or 8.9999999999999999e69 < c Initial program 51.5%
Taylor expanded in c around inf 83.3%
clear-num83.3%
inv-pow83.3%
Applied egg-rr83.3%
unpow-183.3%
associate-/r*84.9%
Simplified84.9%
if -1.20000000000000008e-39 < c < 8.9999999999999999e69Initial program 69.0%
Taylor expanded in d around inf 85.9%
associate-/l*86.4%
Simplified86.4%
Final simplification85.7%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.8e-36) (not (<= c 1.72e+69))) (/ (+ a (* b (/ d c))) c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.8e-36) || !(c <= 1.72e+69)) {
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.8d-36)) .or. (.not. (c <= 1.72d+69))) 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.8e-36) || !(c <= 1.72e+69)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.8e-36) or not (c <= 1.72e+69): tmp = (a + (b * (d / c))) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.8e-36) || !(c <= 1.72e+69)) 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.8e-36) || ~((c <= 1.72e+69))) 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.8e-36], N[Not[LessEqual[c, 1.72e+69]], $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.8 \cdot 10^{-36} \lor \neg \left(c \leq 1.72 \cdot 10^{+69}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -1.80000000000000016e-36 or 1.72e69 < c Initial program 51.5%
Taylor expanded in c around inf 83.3%
associate-/l*84.2%
Simplified84.2%
if -1.80000000000000016e-36 < c < 1.72e69Initial program 69.0%
Taylor expanded in c around 0 69.2%
Final simplification76.7%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4e-40) (not (<= c 3.9e+68))) (/ (+ a (* b (/ d c))) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4e-40) || !(c <= 3.9e+68)) {
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 <= (-4d-40)) .or. (.not. (c <= 3.9d+68))) 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 <= -4e-40) || !(c <= 3.9e+68)) {
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 <= -4e-40) or not (c <= 3.9e+68): 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 <= -4e-40) || !(c <= 3.9e+68)) 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 <= -4e-40) || ~((c <= 3.9e+68))) 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, -4e-40], N[Not[LessEqual[c, 3.9e+68]], $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 -4 \cdot 10^{-40} \lor \neg \left(c \leq 3.9 \cdot 10^{+68}\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.9999999999999997e-40 or 3.90000000000000019e68 < c Initial program 51.5%
Taylor expanded in c around inf 83.3%
associate-/l*84.2%
Simplified84.2%
if -3.9999999999999997e-40 < c < 3.90000000000000019e68Initial program 69.0%
Taylor expanded in d around inf 85.9%
associate-/l*86.4%
Simplified86.4%
Final simplification85.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.5e-37) (not (<= c 2.85e+76))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.5e-37) || !(c <= 2.85e+76)) {
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.5d-37)) .or. (.not. (c <= 2.85d+76))) 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.5e-37) || !(c <= 2.85e+76)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.5e-37) or not (c <= 2.85e+76): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.5e-37) || !(c <= 2.85e+76)) 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.5e-37) || ~((c <= 2.85e+76))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.5e-37], N[Not[LessEqual[c, 2.85e+76]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.5 \cdot 10^{-37} \lor \neg \left(c \leq 2.85 \cdot 10^{+76}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -2.4999999999999999e-37 or 2.85000000000000002e76 < c Initial program 51.1%
Taylor expanded in c around inf 76.8%
if -2.4999999999999999e-37 < c < 2.85000000000000002e76Initial program 68.9%
Taylor expanded in c around 0 68.5%
Final simplification72.5%
(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 60.2%
Taylor expanded in c around inf 45.1%
Final simplification45.1%
(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 2024060
(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))))