
(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 8 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 b (/ d t_0) (/ (* a c) t_0))))
(if (<= d -7e+112)
(/ (fma a (/ c d) b) d)
(if (<= d -5.5e-77)
t_1
(if (<= d 3.8e-145)
(/ (fma b (/ d c) a) c)
(if (<= d 6.1e+144) t_1 (/ (fma c (/ a d) b) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = fma(b, (d / t_0), ((a * c) / t_0));
double tmp;
if (d <= -7e+112) {
tmp = fma(a, (c / d), b) / d;
} else if (d <= -5.5e-77) {
tmp = t_1;
} else if (d <= 3.8e-145) {
tmp = fma(b, (d / c), a) / c;
} else if (d <= 6.1e+144) {
tmp = t_1;
} else {
tmp = fma(c, (a / d), b) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = fma(b, Float64(d / t_0), Float64(Float64(a * c) / t_0)) tmp = 0.0 if (d <= -7e+112) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (d <= -5.5e-77) tmp = t_1; elseif (d <= 3.8e-145) tmp = Float64(fma(b, Float64(d / c), a) / c); elseif (d <= 6.1e+144) tmp = t_1; else tmp = Float64(fma(c, Float64(a / d), b) / d); 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[(b * N[(d / t$95$0), $MachinePrecision] + N[(N[(a * c), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -7e+112], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -5.5e-77], t$95$1, If[LessEqual[d, 3.8e-145], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 6.1e+144], t$95$1, N[(N[(c * N[(a / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \mathsf{fma}\left(b, \frac{d}{t\_0}, \frac{a \cdot c}{t\_0}\right)\\
\mathbf{if}\;d \leq -7 \cdot 10^{+112}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;d \leq -5.5 \cdot 10^{-77}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 3.8 \cdot 10^{-145}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{elif}\;d \leq 6.1 \cdot 10^{+144}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\
\end{array}
\end{array}
if d < -6.99999999999999994e112Initial program 33.7%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6484.9
Simplified84.9%
if -6.99999999999999994e112 < d < -5.49999999999999998e-77 or 3.8000000000000002e-145 < d < 6.09999999999999971e144Initial program 78.9%
Taylor expanded in a around 0
+-commutativeN/A
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
/-lowering-/.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6481.8
Simplified81.8%
if -5.49999999999999998e-77 < d < 3.8000000000000002e-145Initial program 67.8%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6493.4
Simplified93.4%
if 6.09999999999999971e144 < d Initial program 25.0%
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6425.0
Applied egg-rr25.0%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6492.2
Simplified92.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma c (/ a d) b) d)))
(if (<= d -3e+99)
t_0
(if (<= d -4.4e-79)
(/ (fma a c (* d b)) (fma c c (* d d)))
(if (<= d 6.5e-146)
(/ (fma b (/ d c) a) c)
(if (<= d 1.6e+104) (/ (fma d b (* a c)) (fma d d (* c 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 <= -3e+99) {
tmp = t_0;
} else if (d <= -4.4e-79) {
tmp = fma(a, c, (d * b)) / fma(c, c, (d * d));
} else if (d <= 6.5e-146) {
tmp = fma(b, (d / c), a) / c;
} else if (d <= 1.6e+104) {
tmp = fma(d, b, (a * c)) / fma(d, d, (c * 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 <= -3e+99) tmp = t_0; elseif (d <= -4.4e-79) tmp = Float64(fma(a, c, Float64(d * b)) / fma(c, c, Float64(d * d))); elseif (d <= 6.5e-146) tmp = Float64(fma(b, Float64(d / c), a) / c); elseif (d <= 1.6e+104) tmp = Float64(fma(d, b, Float64(a * c)) / fma(d, d, Float64(c * 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, -3e+99], t$95$0, If[LessEqual[d, -4.4e-79], N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6.5e-146], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.6e+104], N[(N[(d * b + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $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 -3 \cdot 10^{+99}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -4.4 \cdot 10^{-79}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;d \leq 6.5 \cdot 10^{-146}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{elif}\;d \leq 1.6 \cdot 10^{+104}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, a \cdot c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -3.00000000000000014e99 or 1.6e104 < d Initial program 34.2%
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6434.2
Applied egg-rr34.2%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6485.6
Simplified85.6%
if -3.00000000000000014e99 < d < -4.3999999999999998e-79Initial program 81.6%
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6481.6
Applied egg-rr81.6%
if -4.3999999999999998e-79 < d < 6.4999999999999999e-146Initial program 67.8%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6493.4
Simplified93.4%
if 6.4999999999999999e-146 < d < 1.6e104Initial program 80.7%
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6480.7
Applied egg-rr80.7%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6480.7
Applied egg-rr80.7%
Final simplification86.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma a c (* d b)) (fma c c (* d d))))
(t_1 (/ (fma c (/ a d) b) d)))
(if (<= d -8.2e+99)
t_1
(if (<= d -5e-78)
t_0
(if (<= d 1.3e-152)
(/ (fma b (/ d c) a) c)
(if (<= d 1.8e+100) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(a, c, (d * b)) / fma(c, c, (d * d));
double t_1 = fma(c, (a / d), b) / d;
double tmp;
if (d <= -8.2e+99) {
tmp = t_1;
} else if (d <= -5e-78) {
tmp = t_0;
} else if (d <= 1.3e-152) {
tmp = fma(b, (d / c), a) / c;
} else if (d <= 1.8e+100) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(a, c, Float64(d * b)) / fma(c, c, Float64(d * d))) t_1 = Float64(fma(c, Float64(a / d), b) / d) tmp = 0.0 if (d <= -8.2e+99) tmp = t_1; elseif (d <= -5e-78) tmp = t_0; elseif (d <= 1.3e-152) tmp = Float64(fma(b, Float64(d / c), a) / c); elseif (d <= 1.8e+100) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c * N[(a / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -8.2e+99], t$95$1, If[LessEqual[d, -5e-78], t$95$0, If[LessEqual[d, 1.3e-152], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.8e+100], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
t_1 := \frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\
\mathbf{if}\;d \leq -8.2 \cdot 10^{+99}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -5 \cdot 10^{-78}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.3 \cdot 10^{-152}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{elif}\;d \leq 1.8 \cdot 10^{+100}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -8.19999999999999959e99 or 1.8e100 < d Initial program 34.2%
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6434.2
Applied egg-rr34.2%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6485.6
Simplified85.6%
if -8.19999999999999959e99 < d < -4.9999999999999996e-78 or 1.30000000000000006e-152 < d < 1.8e100Initial program 81.0%
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6481.0
Applied egg-rr81.0%
if -4.9999999999999996e-78 < d < 1.30000000000000006e-152Initial program 67.8%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6493.4
Simplified93.4%
Final simplification86.7%
(FPCore (a b c d) :precision binary64 (if (<= d -4.8e-24) (/ (fma c (/ a d) b) d) (if (<= d 1.7e-95) (/ (fma b (/ d c) a) c) (/ (fma a (/ c d) b) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4.8e-24) {
tmp = fma(c, (a / d), b) / d;
} else if (d <= 1.7e-95) {
tmp = fma(b, (d / c), a) / c;
} else {
tmp = fma(a, (c / d), b) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -4.8e-24) tmp = Float64(fma(c, Float64(a / d), b) / d); elseif (d <= 1.7e-95) tmp = Float64(fma(b, Float64(d / c), a) / c); else tmp = Float64(fma(a, Float64(c / d), b) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -4.8e-24], N[(N[(c * N[(a / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.7e-95], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.8 \cdot 10^{-24}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\
\mathbf{elif}\;d \leq 1.7 \cdot 10^{-95}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\end{array}
\end{array}
if d < -4.7999999999999996e-24Initial program 55.3%
/-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 d around inf
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6479.2
Simplified79.2%
if -4.7999999999999996e-24 < d < 1.69999999999999997e-95Initial program 71.3%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6488.4
Simplified88.4%
if 1.69999999999999997e-95 < d Initial program 51.9%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6475.8
Simplified75.8%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma a (/ c d) b) d))) (if (<= d -1.08e-26) t_0 (if (<= d 1.7e-95) (/ (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 <= -1.08e-26) {
tmp = t_0;
} else if (d <= 1.7e-95) {
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 <= -1.08e-26) tmp = t_0; elseif (d <= 1.7e-95) 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, -1.08e-26], t$95$0, If[LessEqual[d, 1.7e-95], 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 -1.08 \cdot 10^{-26}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.7 \cdot 10^{-95}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.07999999999999996e-26 or 1.69999999999999997e-95 < d Initial program 53.4%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6477.3
Simplified77.3%
if -1.07999999999999996e-26 < d < 1.69999999999999997e-95Initial program 71.3%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6488.4
Simplified88.4%
(FPCore (a b c d) :precision binary64 (if (<= c -2.45e+29) (/ a c) (if (<= c 5.2e+68) (/ (fma a (/ c d) b) d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.45e+29) {
tmp = a / c;
} else if (c <= 5.2e+68) {
tmp = fma(a, (c / d), b) / d;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -2.45e+29) tmp = Float64(a / c); elseif (c <= 5.2e+68) 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, -2.45e+29], N[(a / c), $MachinePrecision], If[LessEqual[c, 5.2e+68], 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 -2.45 \cdot 10^{+29}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 5.2 \cdot 10^{+68}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -2.4500000000000001e29 or 5.1999999999999996e68 < c Initial program 42.5%
Taylor expanded in c around inf
/-lowering-/.f6477.0
Simplified77.0%
if -2.4500000000000001e29 < c < 5.1999999999999996e68Initial program 73.6%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6479.2
Simplified79.2%
(FPCore (a b c d) :precision binary64 (if (<= c -2.9e+24) (/ a c) (if (<= c 3.2e+63) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.9e+24) {
tmp = a / c;
} else if (c <= 3.2e+63) {
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 <= (-2.9d+24)) then
tmp = a / c
else if (c <= 3.2d+63) 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 <= -2.9e+24) {
tmp = a / c;
} else if (c <= 3.2e+63) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.9e+24: tmp = a / c elif c <= 3.2e+63: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.9e+24) tmp = Float64(a / c); elseif (c <= 3.2e+63) 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 <= -2.9e+24) tmp = a / c; elseif (c <= 3.2e+63) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.9e+24], N[(a / c), $MachinePrecision], If[LessEqual[c, 3.2e+63], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.9 \cdot 10^{+24}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 3.2 \cdot 10^{+63}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -2.89999999999999979e24 or 3.20000000000000011e63 < c Initial program 43.0%
Taylor expanded in c around inf
/-lowering-/.f6476.3
Simplified76.3%
if -2.89999999999999979e24 < c < 3.20000000000000011e63Initial program 73.4%
Taylor expanded in c around 0
/-lowering-/.f6466.7
Simplified66.7%
(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 61.1%
Taylor expanded in c around inf
/-lowering-/.f6441.2
Simplified41.2%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024198
(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))))