
(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 (/ (fma d b (* a c)) (fma d d (* c c))))
(t_1 (/ (fma (/ b c) d a) c)))
(if (<= c -6.2e+120)
t_1
(if (<= c -5.8e-116)
t_0
(if (<= c 1.3e-129)
(/ (fma (/ c d) a b) d)
(if (<= c 1.46e+85) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, b, (a * c)) / fma(d, d, (c * c));
double t_1 = fma((b / c), d, a) / c;
double tmp;
if (c <= -6.2e+120) {
tmp = t_1;
} else if (c <= -5.8e-116) {
tmp = t_0;
} else if (c <= 1.3e-129) {
tmp = fma((c / d), a, b) / d;
} else if (c <= 1.46e+85) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(d, b, Float64(a * c)) / fma(d, d, Float64(c * c))) t_1 = Float64(fma(Float64(b / c), d, a) / c) tmp = 0.0 if (c <= -6.2e+120) tmp = t_1; elseif (c <= -5.8e-116) tmp = t_0; elseif (c <= 1.3e-129) tmp = Float64(fma(Float64(c / d), a, b) / d); elseif (c <= 1.46e+85) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * b + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -6.2e+120], t$95$1, If[LessEqual[c, -5.8e-116], t$95$0, If[LessEqual[c, 1.3e-129], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.46e+85], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(d, b, a \cdot c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
t_1 := \frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{if}\;c \leq -6.2 \cdot 10^{+120}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -5.8 \cdot 10^{-116}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.3 \cdot 10^{-129}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
\mathbf{elif}\;c \leq 1.46 \cdot 10^{+85}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -6.19999999999999947e120 or 1.46e85 < c Initial program 39.5%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6491.0
Applied rewrites91.0%
if -6.19999999999999947e120 < c < -5.7999999999999996e-116 or 1.3e-129 < c < 1.46e85Initial program 84.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6484.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6484.1
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6484.1
Applied rewrites84.1%
if -5.7999999999999996e-116 < c < 1.3e-129Initial program 72.2%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6472.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6472.2
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6472.2
Applied rewrites72.2%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6491.1
Applied rewrites91.1%
Final simplification88.4%
(FPCore (a b c d)
:precision binary64
(if (<= c -6.8e+120)
(/ a c)
(if (<= c -5.5e-39)
(* (/ a (fma d d (* c c))) c)
(if (<= c 1.25e-193)
(/ (fma d b (* a c)) (* d d))
(if (<= c 1700.0)
(/ b d)
(if (<= c 3.85e+142) (/ (fma a c (* d b)) (* c c)) (/ a c)))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.8e+120) {
tmp = a / c;
} else if (c <= -5.5e-39) {
tmp = (a / fma(d, d, (c * c))) * c;
} else if (c <= 1.25e-193) {
tmp = fma(d, b, (a * c)) / (d * d);
} else if (c <= 1700.0) {
tmp = b / d;
} else if (c <= 3.85e+142) {
tmp = fma(a, c, (d * b)) / (c * c);
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -6.8e+120) tmp = Float64(a / c); elseif (c <= -5.5e-39) tmp = Float64(Float64(a / fma(d, d, Float64(c * c))) * c); elseif (c <= 1.25e-193) tmp = Float64(fma(d, b, Float64(a * c)) / Float64(d * d)); elseif (c <= 1700.0) tmp = Float64(b / d); elseif (c <= 3.85e+142) tmp = Float64(fma(a, c, Float64(d * b)) / Float64(c * c)); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -6.8e+120], N[(a / c), $MachinePrecision], If[LessEqual[c, -5.5e-39], N[(N[(a / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision], If[LessEqual[c, 1.25e-193], N[(N[(d * b + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1700.0], N[(b / d), $MachinePrecision], If[LessEqual[c, 3.85e+142], N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(a / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.8 \cdot 10^{+120}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -5.5 \cdot 10^{-39}:\\
\;\;\;\;\frac{a}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot c\\
\mathbf{elif}\;c \leq 1.25 \cdot 10^{-193}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, a \cdot c\right)}{d \cdot d}\\
\mathbf{elif}\;c \leq 1700:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 3.85 \cdot 10^{+142}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -6.79999999999999998e120 or 3.85000000000000024e142 < c Initial program 35.4%
Taylor expanded in c around inf
lower-/.f6485.5
Applied rewrites85.5%
if -6.79999999999999998e120 < c < -5.50000000000000018e-39Initial program 77.6%
Taylor expanded in a around inf
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6462.1
Applied rewrites62.1%
if -5.50000000000000018e-39 < c < 1.2500000000000001e-193Initial program 78.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6478.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6478.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6478.4
Applied rewrites78.4%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6473.5
Applied rewrites73.5%
if 1.2500000000000001e-193 < c < 1700Initial program 76.2%
Taylor expanded in c around 0
lower-/.f6472.0
Applied rewrites72.0%
if 1700 < c < 3.85000000000000024e142Initial program 78.4%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6470.3
Applied rewrites70.3%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6470.3
Applied rewrites70.3%
Final simplification74.6%
(FPCore (a b c d)
:precision binary64
(if (<= c -6.8e+120)
(/ a c)
(if (<= c -2.6e-50)
(* (/ a (fma d d (* c c))) c)
(if (<= c 1700.0)
(/ b d)
(if (<= c 3.85e+142) (/ (fma a c (* d b)) (* c c)) (/ a c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.8e+120) {
tmp = a / c;
} else if (c <= -2.6e-50) {
tmp = (a / fma(d, d, (c * c))) * c;
} else if (c <= 1700.0) {
tmp = b / d;
} else if (c <= 3.85e+142) {
tmp = fma(a, c, (d * b)) / (c * c);
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -6.8e+120) tmp = Float64(a / c); elseif (c <= -2.6e-50) tmp = Float64(Float64(a / fma(d, d, Float64(c * c))) * c); elseif (c <= 1700.0) tmp = Float64(b / d); elseif (c <= 3.85e+142) tmp = Float64(fma(a, c, Float64(d * b)) / Float64(c * c)); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -6.8e+120], N[(a / c), $MachinePrecision], If[LessEqual[c, -2.6e-50], N[(N[(a / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision], If[LessEqual[c, 1700.0], N[(b / d), $MachinePrecision], If[LessEqual[c, 3.85e+142], N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(a / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.8 \cdot 10^{+120}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -2.6 \cdot 10^{-50}:\\
\;\;\;\;\frac{a}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot c\\
\mathbf{elif}\;c \leq 1700:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 3.85 \cdot 10^{+142}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -6.79999999999999998e120 or 3.85000000000000024e142 < c Initial program 35.4%
Taylor expanded in c around inf
lower-/.f6485.5
Applied rewrites85.5%
if -6.79999999999999998e120 < c < -2.6000000000000001e-50Initial program 79.4%
Taylor expanded in a around inf
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6460.1
Applied rewrites60.1%
if -2.6000000000000001e-50 < c < 1700Initial program 77.1%
Taylor expanded in c around 0
lower-/.f6468.7
Applied rewrites68.7%
if 1700 < c < 3.85000000000000024e142Initial program 78.4%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6470.3
Applied rewrites70.3%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6470.3
Applied rewrites70.3%
Final simplification72.3%
(FPCore (a b c d)
:precision binary64
(if (<= c -5.2e+120)
(/ a c)
(if (<= c 18000000000000.0)
(/ (fma (/ a d) c b) d)
(if (<= c 3.85e+142) (/ (fma a c (* d b)) (* c c)) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.2e+120) {
tmp = a / c;
} else if (c <= 18000000000000.0) {
tmp = fma((a / d), c, b) / d;
} else if (c <= 3.85e+142) {
tmp = fma(a, c, (d * b)) / (c * c);
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -5.2e+120) tmp = Float64(a / c); elseif (c <= 18000000000000.0) tmp = Float64(fma(Float64(a / d), c, b) / d); elseif (c <= 3.85e+142) tmp = Float64(fma(a, c, Float64(d * b)) / Float64(c * c)); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.2e+120], N[(a / c), $MachinePrecision], If[LessEqual[c, 18000000000000.0], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 3.85e+142], N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.2 \cdot 10^{+120}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 18000000000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{elif}\;c \leq 3.85 \cdot 10^{+142}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -5.1999999999999998e120 or 3.85000000000000024e142 < c Initial program 35.4%
Taylor expanded in c around inf
lower-/.f6485.5
Applied rewrites85.5%
if -5.1999999999999998e120 < c < 1.8e13Initial program 77.8%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6474.9
Applied rewrites74.9%
if 1.8e13 < c < 3.85000000000000024e142Initial program 77.8%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6472.1
Applied rewrites72.1%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6472.1
Applied rewrites72.1%
Final simplification77.5%
(FPCore (a b c d)
:precision binary64
(if (<= c -5.8)
(/ (fma (/ d c) b a) c)
(if (<= c 18000000000000.0)
(/ (fma (/ c d) a b) d)
(/ (fma (/ b c) d a) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.8) {
tmp = fma((d / c), b, a) / c;
} else if (c <= 18000000000000.0) {
tmp = fma((c / d), a, b) / d;
} else {
tmp = fma((b / c), d, a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -5.8) tmp = Float64(fma(Float64(d / c), b, a) / c); elseif (c <= 18000000000000.0) tmp = Float64(fma(Float64(c / d), a, b) / d); else tmp = Float64(fma(Float64(b / c), d, a) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.8], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 18000000000000.0], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.8:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{elif}\;c \leq 18000000000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\end{array}
\end{array}
if c < -5.79999999999999982Initial program 51.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6451.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6451.0
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6451.0
Applied rewrites51.0%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6478.0
Applied rewrites78.0%
if -5.79999999999999982 < c < 1.8e13Initial program 78.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6478.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6478.1
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6478.1
Applied rewrites78.1%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6482.0
Applied rewrites82.0%
if 1.8e13 < c Initial program 57.6%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6486.5
Applied rewrites86.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ b c) d a) c)))
(if (<= c -5.8)
t_0
(if (<= c 18000000000000.0) (/ (fma (/ c d) a b) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma((b / c), d, a) / c;
double tmp;
if (c <= -5.8) {
tmp = t_0;
} else if (c <= 18000000000000.0) {
tmp = fma((c / d), a, b) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(b / c), d, a) / c) tmp = 0.0 if (c <= -5.8) tmp = t_0; elseif (c <= 18000000000000.0) tmp = Float64(fma(Float64(c / d), a, b) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -5.8], t$95$0, If[LessEqual[c, 18000000000000.0], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{if}\;c \leq -5.8:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 18000000000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -5.79999999999999982 or 1.8e13 < c Initial program 54.6%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6482.6
Applied rewrites82.6%
if -5.79999999999999982 < c < 1.8e13Initial program 78.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6478.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6478.1
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6478.1
Applied rewrites78.1%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6482.0
Applied rewrites82.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ b c) d a) c)))
(if (<= c -5.8)
t_0
(if (<= c 18000000000000.0) (/ (fma (/ a d) c b) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma((b / c), d, a) / c;
double tmp;
if (c <= -5.8) {
tmp = t_0;
} else if (c <= 18000000000000.0) {
tmp = fma((a / d), c, b) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(b / c), d, a) / c) tmp = 0.0 if (c <= -5.8) tmp = t_0; elseif (c <= 18000000000000.0) tmp = Float64(fma(Float64(a / d), c, b) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -5.8], t$95$0, If[LessEqual[c, 18000000000000.0], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{if}\;c \leq -5.8:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 18000000000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -5.79999999999999982 or 1.8e13 < c Initial program 54.6%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6482.6
Applied rewrites82.6%
if -5.79999999999999982 < c < 1.8e13Initial program 78.1%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6480.5
Applied rewrites80.5%
(FPCore (a b c d)
:precision binary64
(if (<= c -6.8e+120)
(/ a c)
(if (<= c -2.6e-50)
(* (/ a (fma d d (* c c))) c)
(if (<= c 48000.0) (/ b d) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.8e+120) {
tmp = a / c;
} else if (c <= -2.6e-50) {
tmp = (a / fma(d, d, (c * c))) * c;
} else if (c <= 48000.0) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -6.8e+120) tmp = Float64(a / c); elseif (c <= -2.6e-50) tmp = Float64(Float64(a / fma(d, d, Float64(c * c))) * c); elseif (c <= 48000.0) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -6.8e+120], N[(a / c), $MachinePrecision], If[LessEqual[c, -2.6e-50], N[(N[(a / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision], If[LessEqual[c, 48000.0], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.8 \cdot 10^{+120}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -2.6 \cdot 10^{-50}:\\
\;\;\;\;\frac{a}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot c\\
\mathbf{elif}\;c \leq 48000:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -6.79999999999999998e120 or 48000 < c Initial program 49.8%
Taylor expanded in c around inf
lower-/.f6473.0
Applied rewrites73.0%
if -6.79999999999999998e120 < c < -2.6000000000000001e-50Initial program 79.4%
Taylor expanded in a around inf
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6460.1
Applied rewrites60.1%
if -2.6000000000000001e-50 < c < 48000Initial program 77.1%
Taylor expanded in c around 0
lower-/.f6468.7
Applied rewrites68.7%
(FPCore (a b c d) :precision binary64 (if (<= c -1.4e-34) (/ a c) (if (<= c 48000.0) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.4e-34) {
tmp = a / c;
} else if (c <= 48000.0) {
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 <= (-1.4d-34)) then
tmp = a / c
else if (c <= 48000.0d0) 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 <= -1.4e-34) {
tmp = a / c;
} else if (c <= 48000.0) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.4e-34: tmp = a / c elif c <= 48000.0: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.4e-34) tmp = Float64(a / c); elseif (c <= 48000.0) 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 <= -1.4e-34) tmp = a / c; elseif (c <= 48000.0) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.4e-34], N[(a / c), $MachinePrecision], If[LessEqual[c, 48000.0], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.4 \cdot 10^{-34}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 48000:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -1.39999999999999998e-34 or 48000 < c Initial program 56.5%
Taylor expanded in c around inf
lower-/.f6465.8
Applied rewrites65.8%
if -1.39999999999999998e-34 < c < 48000Initial program 77.4%
Taylor expanded in c around 0
lower-/.f6467.8
Applied rewrites67.8%
(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.0%
Taylor expanded in c around inf
lower-/.f6444.3
Applied rewrites44.3%
(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 2024296
(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))))