
(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 11 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 (/ (fma d (/ b c) a) c)))
(if (<= c -3.7e+59)
t_0
(if (<= c 1.85e-125)
(/ (+ b (/ (fma a c (/ (* c (* c b)) (- d))) d)) d)
(if (<= c 6.2e+48)
(* (fma a c (* b d)) (/ 1.0 (fma c c (* d d))))
t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, (b / c), a) / c;
double tmp;
if (c <= -3.7e+59) {
tmp = t_0;
} else if (c <= 1.85e-125) {
tmp = (b + (fma(a, c, ((c * (c * b)) / -d)) / d)) / d;
} else if (c <= 6.2e+48) {
tmp = fma(a, c, (b * d)) * (1.0 / fma(c, c, (d * d)));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(d, Float64(b / c), a) / c) tmp = 0.0 if (c <= -3.7e+59) tmp = t_0; elseif (c <= 1.85e-125) tmp = Float64(Float64(b + Float64(fma(a, c, Float64(Float64(c * Float64(c * b)) / Float64(-d))) / d)) / d); elseif (c <= 6.2e+48) tmp = Float64(fma(a, c, Float64(b * d)) * Float64(1.0 / fma(c, c, Float64(d * d)))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3.7e+59], t$95$0, If[LessEqual[c, 1.85e-125], N[(N[(b + N[(N[(a * c + N[(N[(c * N[(c * b), $MachinePrecision]), $MachinePrecision] / (-d)), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 6.2e+48], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -3.7 \cdot 10^{+59}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.85 \cdot 10^{-125}:\\
\;\;\;\;\frac{b + \frac{\mathsf{fma}\left(a, c, \frac{c \cdot \left(c \cdot b\right)}{-d}\right)}{d}}{d}\\
\mathbf{elif}\;c \leq 6.2 \cdot 10^{+48}:\\
\;\;\;\;\mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.69999999999999997e59 or 6.20000000000000011e48 < c Initial program 44.6%
Taylor expanded in c around inf
lower-/.f6475.4
Applied rewrites75.4%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6483.3
Applied rewrites83.3%
if -3.69999999999999997e59 < c < 1.85e-125Initial program 65.0%
Taylor expanded in c around inf
lower-/.f6418.9
Applied rewrites18.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6424.6
Applied rewrites24.6%
Applied rewrites25.4%
Taylor expanded in d around inf
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
unsub-negN/A
mul-1-negN/A
+-commutativeN/A
lower-/.f64N/A
Applied rewrites85.0%
if 1.85e-125 < c < 6.20000000000000011e48Initial program 84.3%
lift-/.f64N/A
div-invN/A
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
lower-/.f6484.3
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6484.4
Applied rewrites84.4%
Final simplification84.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma d (/ b c) a) c)))
(if (<= c -1.25e+60)
t_0
(if (<= c 1.85e-125)
(/ (fma a (/ c d) b) d)
(if (<= c 6.2e+48)
(* (fma a c (* b d)) (/ 1.0 (fma c c (* d d))))
t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, (b / c), a) / c;
double tmp;
if (c <= -1.25e+60) {
tmp = t_0;
} else if (c <= 1.85e-125) {
tmp = fma(a, (c / d), b) / d;
} else if (c <= 6.2e+48) {
tmp = fma(a, c, (b * d)) * (1.0 / fma(c, c, (d * d)));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(d, Float64(b / c), a) / c) tmp = 0.0 if (c <= -1.25e+60) tmp = t_0; elseif (c <= 1.85e-125) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (c <= 6.2e+48) tmp = Float64(fma(a, c, Float64(b * d)) * Float64(1.0 / fma(c, c, Float64(d * d)))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.25e+60], t$95$0, If[LessEqual[c, 1.85e-125], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 6.2e+48], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -1.25 \cdot 10^{+60}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.85 \cdot 10^{-125}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;c \leq 6.2 \cdot 10^{+48}:\\
\;\;\;\;\mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.24999999999999994e60 or 6.20000000000000011e48 < c Initial program 44.6%
Taylor expanded in c around inf
lower-/.f6475.4
Applied rewrites75.4%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6483.3
Applied rewrites83.3%
if -1.24999999999999994e60 < c < 1.85e-125Initial program 65.0%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6484.4
Applied rewrites84.4%
if 1.85e-125 < c < 6.20000000000000011e48Initial program 84.3%
lift-/.f64N/A
div-invN/A
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
lower-/.f6484.3
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6484.4
Applied rewrites84.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma d (/ b c) a) c)))
(if (<= c -1.25e+60)
t_0
(if (<= c 1.85e-125)
(/ (fma a (/ c d) b) d)
(if (<= c 6.2e+48) (/ (+ (* b d) (* c a)) (+ (* d d) (* c c))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, (b / c), a) / c;
double tmp;
if (c <= -1.25e+60) {
tmp = t_0;
} else if (c <= 1.85e-125) {
tmp = fma(a, (c / d), b) / d;
} else if (c <= 6.2e+48) {
tmp = ((b * d) + (c * a)) / ((d * d) + (c * c));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(d, Float64(b / c), a) / c) tmp = 0.0 if (c <= -1.25e+60) tmp = t_0; elseif (c <= 1.85e-125) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (c <= 6.2e+48) tmp = Float64(Float64(Float64(b * d) + Float64(c * a)) / Float64(Float64(d * d) + Float64(c * c))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.25e+60], t$95$0, If[LessEqual[c, 1.85e-125], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 6.2e+48], N[(N[(N[(b * d), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -1.25 \cdot 10^{+60}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.85 \cdot 10^{-125}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;c \leq 6.2 \cdot 10^{+48}:\\
\;\;\;\;\frac{b \cdot d + c \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.24999999999999994e60 or 6.20000000000000011e48 < c Initial program 44.6%
Taylor expanded in c around inf
lower-/.f6475.4
Applied rewrites75.4%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6483.3
Applied rewrites83.3%
if -1.24999999999999994e60 < c < 1.85e-125Initial program 65.0%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6484.4
Applied rewrites84.4%
if 1.85e-125 < c < 6.20000000000000011e48Initial program 84.3%
Final simplification83.9%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.25e+60)
(/ (fma d (/ b c) a) c)
(if (<= c 3.1e-52)
(/ (fma a (/ c d) b) d)
(if (<= c 4.5e+118)
(/ a (/ (fma c c (* d d)) c))
(/ (fma b (/ d c) a) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.25e+60) {
tmp = fma(d, (b / c), a) / c;
} else if (c <= 3.1e-52) {
tmp = fma(a, (c / d), b) / d;
} else if (c <= 4.5e+118) {
tmp = a / (fma(c, c, (d * d)) / c);
} else {
tmp = fma(b, (d / c), a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.25e+60) tmp = Float64(fma(d, Float64(b / c), a) / c); elseif (c <= 3.1e-52) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (c <= 4.5e+118) tmp = Float64(a / Float64(fma(c, c, Float64(d * d)) / c)); else tmp = Float64(fma(b, Float64(d / c), a) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.25e+60], N[(N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 3.1e-52], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.5e+118], N[(a / N[(N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.25 \cdot 10^{+60}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{c}\\
\mathbf{elif}\;c \leq 3.1 \cdot 10^{-52}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;c \leq 4.5 \cdot 10^{+118}:\\
\;\;\;\;\frac{a}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\end{array}
\end{array}
if c < -1.24999999999999994e60Initial program 45.0%
Taylor expanded in c around inf
lower-/.f6476.0
Applied rewrites76.0%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6486.3
Applied rewrites86.3%
if -1.24999999999999994e60 < c < 3.0999999999999999e-52Initial program 65.2%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6482.1
Applied rewrites82.1%
if 3.0999999999999999e-52 < c < 4.50000000000000002e118Initial program 79.5%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6460.2
Applied rewrites60.2%
Applied rewrites79.9%
if 4.50000000000000002e118 < c Initial program 39.4%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6481.4
Applied rewrites81.4%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.25e+60)
(/ (fma d (/ b c) a) c)
(if (<= c 3.1e-52)
(/ (fma a (/ c d) b) d)
(if (<= c 4.5e+118)
(* a (/ c (fma c c (* d d))))
(/ (fma b (/ d c) a) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.25e+60) {
tmp = fma(d, (b / c), a) / c;
} else if (c <= 3.1e-52) {
tmp = fma(a, (c / d), b) / d;
} else if (c <= 4.5e+118) {
tmp = a * (c / fma(c, c, (d * d)));
} else {
tmp = fma(b, (d / c), a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.25e+60) tmp = Float64(fma(d, Float64(b / c), a) / c); elseif (c <= 3.1e-52) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (c <= 4.5e+118) tmp = Float64(a * Float64(c / fma(c, c, Float64(d * d)))); else tmp = Float64(fma(b, Float64(d / c), a) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.25e+60], N[(N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 3.1e-52], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.5e+118], N[(a * N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.25 \cdot 10^{+60}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{c}\\
\mathbf{elif}\;c \leq 3.1 \cdot 10^{-52}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;c \leq 4.5 \cdot 10^{+118}:\\
\;\;\;\;a \cdot \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\end{array}
\end{array}
if c < -1.24999999999999994e60Initial program 45.0%
Taylor expanded in c around inf
lower-/.f6476.0
Applied rewrites76.0%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6486.3
Applied rewrites86.3%
if -1.24999999999999994e60 < c < 3.0999999999999999e-52Initial program 65.2%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6482.1
Applied rewrites82.1%
if 3.0999999999999999e-52 < c < 4.50000000000000002e118Initial program 79.5%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6460.2
Applied rewrites60.2%
Applied rewrites79.7%
if 4.50000000000000002e118 < c Initial program 39.4%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6481.4
Applied rewrites81.4%
Final simplification82.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma b (/ d c) a) c)))
(if (<= c -1.25e+60)
t_0
(if (<= c 3.1e-52)
(/ (fma a (/ c d) b) d)
(if (<= c 4.5e+118) (* a (/ c (fma c c (* d d)))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(b, (d / c), a) / c;
double tmp;
if (c <= -1.25e+60) {
tmp = t_0;
} else if (c <= 3.1e-52) {
tmp = fma(a, (c / d), b) / d;
} else if (c <= 4.5e+118) {
tmp = a * (c / fma(c, c, (d * d)));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(b, Float64(d / c), a) / c) tmp = 0.0 if (c <= -1.25e+60) tmp = t_0; elseif (c <= 3.1e-52) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (c <= 4.5e+118) tmp = Float64(a * Float64(c / fma(c, c, Float64(d * d)))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.25e+60], t$95$0, If[LessEqual[c, 3.1e-52], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.5e+118], N[(a * N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -1.25 \cdot 10^{+60}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 3.1 \cdot 10^{-52}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;c \leq 4.5 \cdot 10^{+118}:\\
\;\;\;\;a \cdot \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.24999999999999994e60 or 4.50000000000000002e118 < c Initial program 42.6%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6482.3
Applied rewrites82.3%
if -1.24999999999999994e60 < c < 3.0999999999999999e-52Initial program 65.2%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6482.1
Applied rewrites82.1%
if 3.0999999999999999e-52 < c < 4.50000000000000002e118Initial program 79.5%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6460.2
Applied rewrites60.2%
Applied rewrites79.7%
Final simplification81.8%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.25e+60)
(/ a c)
(if (<= c 3.1e-52)
(/ (fma a (/ c d) b) d)
(if (<= c 1.3e+164) (* a (/ c (fma c c (* d d)))) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.25e+60) {
tmp = a / c;
} else if (c <= 3.1e-52) {
tmp = fma(a, (c / d), b) / d;
} else if (c <= 1.3e+164) {
tmp = a * (c / fma(c, c, (d * d)));
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.25e+60) tmp = Float64(a / c); elseif (c <= 3.1e-52) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (c <= 1.3e+164) tmp = Float64(a * Float64(c / fma(c, c, Float64(d * d)))); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.25e+60], N[(a / c), $MachinePrecision], If[LessEqual[c, 3.1e-52], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.3e+164], N[(a * N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.25 \cdot 10^{+60}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 3.1 \cdot 10^{-52}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;c \leq 1.3 \cdot 10^{+164}:\\
\;\;\;\;a \cdot \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -1.24999999999999994e60 or 1.3e164 < c Initial program 40.7%
Taylor expanded in c around inf
lower-/.f6476.9
Applied rewrites76.9%
if -1.24999999999999994e60 < c < 3.0999999999999999e-52Initial program 65.2%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6482.1
Applied rewrites82.1%
if 3.0999999999999999e-52 < c < 1.3e164Initial program 72.8%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6455.0
Applied rewrites55.0%
Applied rewrites75.2%
Final simplification79.1%
(FPCore (a b c d)
:precision binary64
(if (<= c -3.8e+57)
(/ a c)
(if (<= c 7.8e-53)
(/ b d)
(if (<= c 1.3e+164) (* a (/ c (fma c c (* d d)))) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.8e+57) {
tmp = a / c;
} else if (c <= 7.8e-53) {
tmp = b / d;
} else if (c <= 1.3e+164) {
tmp = a * (c / fma(c, c, (d * d)));
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -3.8e+57) tmp = Float64(a / c); elseif (c <= 7.8e-53) tmp = Float64(b / d); elseif (c <= 1.3e+164) tmp = Float64(a * Float64(c / fma(c, c, Float64(d * d)))); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.8e+57], N[(a / c), $MachinePrecision], If[LessEqual[c, 7.8e-53], N[(b / d), $MachinePrecision], If[LessEqual[c, 1.3e+164], N[(a * N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.8 \cdot 10^{+57}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 7.8 \cdot 10^{-53}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 1.3 \cdot 10^{+164}:\\
\;\;\;\;a \cdot \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -3.7999999999999999e57 or 1.3e164 < c Initial program 41.0%
Taylor expanded in c around inf
lower-/.f6475.3
Applied rewrites75.3%
if -3.7999999999999999e57 < c < 7.8000000000000004e-53Initial program 65.4%
Taylor expanded in c around 0
lower-/.f6467.8
Applied rewrites67.8%
if 7.8000000000000004e-53 < c < 1.3e164Initial program 72.8%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6455.0
Applied rewrites55.0%
Applied rewrites75.2%
Final simplification71.6%
(FPCore (a b c d) :precision binary64 (if (<= c -3.8e+57) (/ a c) (if (<= c 3.1e-25) (/ b d) (/ 1.0 (/ c a)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.8e+57) {
tmp = a / c;
} else if (c <= 3.1e-25) {
tmp = b / d;
} else {
tmp = 1.0 / (c / a);
}
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.8d+57)) then
tmp = a / c
else if (c <= 3.1d-25) then
tmp = b / d
else
tmp = 1.0d0 / (c / a)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.8e+57) {
tmp = a / c;
} else if (c <= 3.1e-25) {
tmp = b / d;
} else {
tmp = 1.0 / (c / a);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3.8e+57: tmp = a / c elif c <= 3.1e-25: tmp = b / d else: tmp = 1.0 / (c / a) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3.8e+57) tmp = Float64(a / c); elseif (c <= 3.1e-25) tmp = Float64(b / d); else tmp = Float64(1.0 / Float64(c / a)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -3.8e+57) tmp = a / c; elseif (c <= 3.1e-25) tmp = b / d; else tmp = 1.0 / (c / a); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.8e+57], N[(a / c), $MachinePrecision], If[LessEqual[c, 3.1e-25], N[(b / d), $MachinePrecision], N[(1.0 / N[(c / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.8 \cdot 10^{+57}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 3.1 \cdot 10^{-25}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{c}{a}}\\
\end{array}
\end{array}
if c < -3.7999999999999999e57Initial program 45.3%
Taylor expanded in c around inf
lower-/.f6473.6
Applied rewrites73.6%
if -3.7999999999999999e57 < c < 3.09999999999999995e-25Initial program 66.0%
Taylor expanded in c around 0
lower-/.f6466.1
Applied rewrites66.1%
if 3.09999999999999995e-25 < c Initial program 56.1%
Taylor expanded in c around inf
lower-/.f6470.4
Applied rewrites70.4%
Applied rewrites70.7%
(FPCore (a b c d) :precision binary64 (if (<= c -3.8e+57) (/ a c) (if (<= c 3.1e-25) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.8e+57) {
tmp = a / c;
} else if (c <= 3.1e-25) {
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 (c <= (-3.8d+57)) then
tmp = a / c
else if (c <= 3.1d-25) 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 (c <= -3.8e+57) {
tmp = a / c;
} else if (c <= 3.1e-25) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3.8e+57: tmp = a / c elif c <= 3.1e-25: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3.8e+57) tmp = Float64(a / c); elseif (c <= 3.1e-25) 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 (c <= -3.8e+57) tmp = a / c; elseif (c <= 3.1e-25) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.8e+57], N[(a / c), $MachinePrecision], If[LessEqual[c, 3.1e-25], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.8 \cdot 10^{+57}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 3.1 \cdot 10^{-25}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -3.7999999999999999e57 or 3.09999999999999995e-25 < c Initial program 51.2%
Taylor expanded in c around inf
lower-/.f6471.9
Applied rewrites71.9%
if -3.7999999999999999e57 < c < 3.09999999999999995e-25Initial program 66.0%
Taylor expanded in c around 0
lower-/.f6466.1
Applied rewrites66.1%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 58.7%
Taylor expanded in c around inf
lower-/.f6445.9
Applied rewrites45.9%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024226
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(! :herbie-platform default (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))))