
(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 d (* c c)))
(t_1 (fma a (/ c t_0) (* b (/ d t_0))))
(t_2 (/ (fma b (/ d c) a) c)))
(if (<= c -6.2e+147)
t_2
(if (<= c -2.05e-69)
t_1
(if (<= c 1.2e-174)
(/ (fma a (/ c d) b) d)
(if (<= c 1.25e+154) t_1 t_2))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = fma(a, (c / t_0), (b * (d / t_0)));
double t_2 = fma(b, (d / c), a) / c;
double tmp;
if (c <= -6.2e+147) {
tmp = t_2;
} else if (c <= -2.05e-69) {
tmp = t_1;
} else if (c <= 1.2e-174) {
tmp = fma(a, (c / d), b) / d;
} else if (c <= 1.25e+154) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = fma(a, Float64(c / t_0), Float64(b * Float64(d / t_0))) t_2 = Float64(fma(b, Float64(d / c), a) / c) tmp = 0.0 if (c <= -6.2e+147) tmp = t_2; elseif (c <= -2.05e-69) tmp = t_1; elseif (c <= 1.2e-174) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (c <= 1.25e+154) tmp = t_1; else tmp = t_2; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(a * N[(c / t$95$0), $MachinePrecision] + N[(b * N[(d / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -6.2e+147], t$95$2, If[LessEqual[c, -2.05e-69], t$95$1, If[LessEqual[c, 1.2e-174], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.25e+154], t$95$1, t$95$2]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \mathsf{fma}\left(a, \frac{c}{t\_0}, b \cdot \frac{d}{t\_0}\right)\\
t_2 := \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -6.2 \cdot 10^{+147}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;c \leq -2.05 \cdot 10^{-69}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq 1.2 \cdot 10^{-174}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;c \leq 1.25 \cdot 10^{+154}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if c < -6.2000000000000001e147 or 1.25000000000000001e154 < c Initial program 27.5%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6488.7
Simplified88.7%
if -6.2000000000000001e147 < c < -2.04999999999999995e-69 or 1.2e-174 < c < 1.25000000000000001e154Initial program 78.6%
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6478.5
Applied egg-rr78.5%
Taylor expanded in a around 0
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6484.2
Simplified84.2%
if -2.04999999999999995e-69 < c < 1.2e-174Initial program 72.8%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6489.2
Simplified89.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* c a) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -5.5e+139)
(/ (fma a (/ c d) b) d)
(if (<= d -2.35e-11)
t_0
(if (<= d 1.85e-90)
(fma (/ 1.0 c) (/ (* b d) c) (/ a c))
(if (<= d 6.6e+140) t_0 (/ (fma c (/ a d) b) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * a) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -5.5e+139) {
tmp = fma(a, (c / d), b) / d;
} else if (d <= -2.35e-11) {
tmp = t_0;
} else if (d <= 1.85e-90) {
tmp = fma((1.0 / c), ((b * d) / c), (a / c));
} else if (d <= 6.6e+140) {
tmp = t_0;
} else {
tmp = fma(c, (a / d), b) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * a) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (d <= -5.5e+139) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (d <= -2.35e-11) tmp = t_0; elseif (d <= 1.85e-90) tmp = fma(Float64(1.0 / c), Float64(Float64(b * d) / c), Float64(a / c)); elseif (d <= 6.6e+140) tmp = t_0; else tmp = Float64(fma(c, Float64(a / d), b) / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.5e+139], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -2.35e-11], t$95$0, If[LessEqual[d, 1.85e-90], N[(N[(1.0 / c), $MachinePrecision] * N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] + N[(a / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6.6e+140], t$95$0, N[(N[(c * N[(a / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -5.5 \cdot 10^{+139}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;d \leq -2.35 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.85 \cdot 10^{-90}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{c}, \frac{b \cdot d}{c}, \frac{a}{c}\right)\\
\mathbf{elif}\;d \leq 6.6 \cdot 10^{+140}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\
\end{array}
\end{array}
if d < -5.4999999999999996e139Initial program 31.4%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6486.6
Simplified86.6%
if -5.4999999999999996e139 < d < -2.34999999999999996e-11 or 1.85000000000000009e-90 < d < 6.6000000000000003e140Initial program 83.1%
if -2.34999999999999996e-11 < d < 1.85000000000000009e-90Initial program 64.0%
Taylor expanded in d around 0
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64N/A
/-lowering-/.f6479.3
Simplified79.3%
associate-*r/N/A
frac-2negN/A
neg-mul-1N/A
distribute-lft-neg-inN/A
times-fracN/A
metadata-evalN/A
frac-2negN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6487.2
Applied egg-rr87.2%
if 6.6000000000000003e140 < d Initial program 31.8%
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6431.8
Applied egg-rr31.8%
Taylor expanded in a around 0
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6439.2
Simplified39.2%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6487.5
Simplified87.5%
Final simplification85.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* c a) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -1.5e+139)
(/ (fma a (/ c d) b) d)
(if (<= d -3e-11)
t_0
(if (<= d 3e-97)
(/ (fma b (/ d c) a) c)
(if (<= d 2.8e+140) t_0 (/ (fma c (/ a d) b) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * a) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.5e+139) {
tmp = fma(a, (c / d), b) / d;
} else if (d <= -3e-11) {
tmp = t_0;
} else if (d <= 3e-97) {
tmp = fma(b, (d / c), a) / c;
} else if (d <= 2.8e+140) {
tmp = t_0;
} else {
tmp = fma(c, (a / d), b) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * a) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (d <= -1.5e+139) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (d <= -3e-11) tmp = t_0; elseif (d <= 3e-97) tmp = Float64(fma(b, Float64(d / c), a) / c); elseif (d <= 2.8e+140) tmp = t_0; else tmp = Float64(fma(c, Float64(a / d), b) / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.5e+139], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -3e-11], t$95$0, If[LessEqual[d, 3e-97], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.8e+140], t$95$0, N[(N[(c * N[(a / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -1.5 \cdot 10^{+139}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;d \leq -3 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 3 \cdot 10^{-97}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{elif}\;d \leq 2.8 \cdot 10^{+140}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\
\end{array}
\end{array}
if d < -1.5e139Initial program 31.4%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6486.6
Simplified86.6%
if -1.5e139 < d < -3e-11 or 3.00000000000000024e-97 < d < 2.79999999999999983e140Initial program 83.1%
if -3e-11 < d < 3.00000000000000024e-97Initial program 64.0%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6486.9
Simplified86.9%
if 2.79999999999999983e140 < d Initial program 31.8%
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6431.8
Applied egg-rr31.8%
Taylor expanded in a around 0
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6439.2
Simplified39.2%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6487.5
Simplified87.5%
Final simplification85.7%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.7e-10)
(/ b d)
(if (<= d 9.6e-112)
(/ a c)
(if (<= d 1.42e+141) (* b (/ d (fma d d (* c c)))) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.7e-10) {
tmp = b / d;
} else if (d <= 9.6e-112) {
tmp = a / c;
} else if (d <= 1.42e+141) {
tmp = b * (d / fma(d, d, (c * c)));
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -1.7e-10) tmp = Float64(b / d); elseif (d <= 9.6e-112) tmp = Float64(a / c); elseif (d <= 1.42e+141) tmp = Float64(b * Float64(d / fma(d, d, Float64(c * c)))); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.7e-10], N[(b / d), $MachinePrecision], If[LessEqual[d, 9.6e-112], N[(a / c), $MachinePrecision], If[LessEqual[d, 1.42e+141], N[(b * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.7 \cdot 10^{-10}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 9.6 \cdot 10^{-112}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 1.42 \cdot 10^{+141}:\\
\;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.70000000000000007e-10 or 1.42000000000000005e141 < d Initial program 51.6%
Taylor expanded in c around 0
/-lowering-/.f6469.5
Simplified69.5%
if -1.70000000000000007e-10 < d < 9.6000000000000003e-112Initial program 64.1%
Taylor expanded in c around inf
/-lowering-/.f6470.6
Simplified70.6%
if 9.6000000000000003e-112 < d < 1.42000000000000005e141Initial program 76.4%
Taylor expanded in a around 0
/-lowering-/.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6455.7
Simplified55.7%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
+-commutativeN/A
/-lowering-/.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6455.7
Applied egg-rr55.7%
Final simplification67.1%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma c (/ a d) b) d))) (if (<= d -1.95e-10) t_0 (if (<= d 8e+49) (/ (fma b (/ d c) a) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(c, (a / d), b) / d;
double tmp;
if (d <= -1.95e-10) {
tmp = t_0;
} else if (d <= 8e+49) {
tmp = fma(b, (d / c), a) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(c, Float64(a / d), b) / d) tmp = 0.0 if (d <= -1.95e-10) tmp = t_0; elseif (d <= 8e+49) tmp = Float64(fma(b, Float64(d / c), a) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * N[(a / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.95e-10], t$95$0, If[LessEqual[d, 8e+49], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\
\mathbf{if}\;d \leq -1.95 \cdot 10^{-10}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 8 \cdot 10^{+49}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.95e-10 or 7.99999999999999957e49 < d Initial program 55.5%
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6455.3
Applied egg-rr55.3%
Taylor expanded in a around 0
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6458.4
Simplified58.4%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6478.5
Simplified78.5%
if -1.95e-10 < d < 7.99999999999999957e49Initial program 67.3%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6481.7
Simplified81.7%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma a (/ c d) b) d))) (if (<= d -2.2e-9) t_0 (if (<= d 1.02e+52) (/ (fma b (/ d c) a) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(a, (c / d), b) / d;
double tmp;
if (d <= -2.2e-9) {
tmp = t_0;
} else if (d <= 1.02e+52) {
tmp = fma(b, (d / c), a) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(a, Float64(c / d), b) / d) tmp = 0.0 if (d <= -2.2e-9) tmp = t_0; elseif (d <= 1.02e+52) tmp = Float64(fma(b, Float64(d / c), a) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.2e-9], t$95$0, If[LessEqual[d, 1.02e+52], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{if}\;d \leq -2.2 \cdot 10^{-9}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.02 \cdot 10^{+52}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.1999999999999998e-9 or 1.02000000000000002e52 < d Initial program 55.5%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6478.1
Simplified78.1%
if -2.1999999999999998e-9 < d < 1.02000000000000002e52Initial program 67.3%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6481.7
Simplified81.7%
(FPCore (a b c d) :precision binary64 (if (<= c -1.9e+28) (/ a c) (if (<= c 1.3e-37) (/ (fma a (/ c d) b) d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.9e+28) {
tmp = a / c;
} else if (c <= 1.3e-37) {
tmp = fma(a, (c / d), b) / d;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.9e+28) tmp = Float64(a / c); elseif (c <= 1.3e-37) tmp = Float64(fma(a, Float64(c / d), b) / d); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.9e+28], N[(a / c), $MachinePrecision], If[LessEqual[c, 1.3e-37], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.9 \cdot 10^{+28}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 1.3 \cdot 10^{-37}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -1.8999999999999999e28 or 1.2999999999999999e-37 < c Initial program 50.6%
Taylor expanded in c around inf
/-lowering-/.f6464.7
Simplified64.7%
if -1.8999999999999999e28 < c < 1.2999999999999999e-37Initial program 75.9%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6478.8
Simplified78.8%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.54e+150)
(/ a c)
(if (<= c -1.55e-80)
(/ (fma b d (* c a)) (* c c))
(if (<= c 9.2e-38) (/ b d) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.54e+150) {
tmp = a / c;
} else if (c <= -1.55e-80) {
tmp = fma(b, d, (c * a)) / (c * c);
} else if (c <= 9.2e-38) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.54e+150) tmp = Float64(a / c); elseif (c <= -1.55e-80) tmp = Float64(fma(b, d, Float64(c * a)) / Float64(c * c)); elseif (c <= 9.2e-38) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.54e+150], N[(a / c), $MachinePrecision], If[LessEqual[c, -1.55e-80], N[(N[(b * d + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 9.2e-38], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.54 \cdot 10^{+150}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -1.55 \cdot 10^{-80}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{c \cdot c}\\
\mathbf{elif}\;c \leq 9.2 \cdot 10^{-38}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -1.54e150 or 9.20000000000000007e-38 < c Initial program 45.3%
Taylor expanded in c around inf
/-lowering-/.f6469.4
Simplified69.4%
if -1.54e150 < c < -1.55000000000000008e-80Initial program 77.7%
Taylor expanded in d around 0
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64N/A
/-lowering-/.f6458.7
Simplified58.7%
Taylor expanded in c around 0
/-lowering-/.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6456.3
Simplified56.3%
if -1.55000000000000008e-80 < c < 9.20000000000000007e-38Initial program 74.3%
Taylor expanded in c around 0
/-lowering-/.f6470.1
Simplified70.1%
Final simplification67.2%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.25e+59)
(/ a c)
(if (<= c -6.8e-87)
(* c (/ a (fma d d (* c c))))
(if (<= c 2.8e-38) (/ b d) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.25e+59) {
tmp = a / c;
} else if (c <= -6.8e-87) {
tmp = c * (a / fma(d, d, (c * c)));
} else if (c <= 2.8e-38) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.25e+59) tmp = Float64(a / c); elseif (c <= -6.8e-87) tmp = Float64(c * Float64(a / fma(d, d, Float64(c * c)))); elseif (c <= 2.8e-38) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.25e+59], N[(a / c), $MachinePrecision], If[LessEqual[c, -6.8e-87], N[(c * N[(a / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.8e-38], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.25 \cdot 10^{+59}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -6.8 \cdot 10^{-87}:\\
\;\;\;\;c \cdot \frac{a}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;c \leq 2.8 \cdot 10^{-38}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -1.2499999999999999e59 or 2.8e-38 < c Initial program 48.7%
Taylor expanded in c around inf
/-lowering-/.f6465.6
Simplified65.6%
if -1.2499999999999999e59 < c < -6.7999999999999997e-87Initial program 83.4%
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6483.3
Applied egg-rr83.3%
Taylor expanded in a around 0
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6489.9
Simplified89.9%
Taylor expanded in a around inf
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6458.1
Simplified58.1%
if -6.7999999999999997e-87 < c < 2.8e-38Initial program 74.3%
Taylor expanded in c around 0
/-lowering-/.f6470.1
Simplified70.1%
(FPCore (a b c d) :precision binary64 (if (<= d -2.1e-10) (/ b d) (if (<= d 5.5e+53) (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.1e-10) {
tmp = b / d;
} else if (d <= 5.5e+53) {
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 (d <= (-2.1d-10)) then
tmp = b / d
else if (d <= 5.5d+53) 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 (d <= -2.1e-10) {
tmp = b / d;
} else if (d <= 5.5e+53) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -2.1e-10: tmp = b / d elif d <= 5.5e+53: tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -2.1e-10) tmp = Float64(b / d); elseif (d <= 5.5e+53) 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 (d <= -2.1e-10) tmp = b / d; elseif (d <= 5.5e+53) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.1e-10], N[(b / d), $MachinePrecision], If[LessEqual[d, 5.5e+53], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.1 \cdot 10^{-10}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 5.5 \cdot 10^{+53}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -2.1e-10 or 5.49999999999999975e53 < d Initial program 55.9%
Taylor expanded in c around 0
/-lowering-/.f6467.3
Simplified67.3%
if -2.1e-10 < d < 5.49999999999999975e53Initial program 66.8%
Taylor expanded in c around inf
/-lowering-/.f6462.8
Simplified62.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 62.1%
Taylor expanded in c around inf
/-lowering-/.f6444.0
Simplified44.0%
(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 2024204
(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))))