
(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 9 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)))
(t_2 (/ (fma c (* a (/ 1.0 d)) b) d)))
(if (<= d -2e+102)
t_2
(if (<= d -9.6e-141)
t_1
(if (<= d 6e-139)
(/ (fma b (/ d c) a) c)
(if (<= d 4.5e+104) 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(b, (d / t_0), ((a * c) / t_0));
double t_2 = fma(c, (a * (1.0 / d)), b) / d;
double tmp;
if (d <= -2e+102) {
tmp = t_2;
} else if (d <= -9.6e-141) {
tmp = t_1;
} else if (d <= 6e-139) {
tmp = fma(b, (d / c), a) / c;
} else if (d <= 4.5e+104) {
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(b, Float64(d / t_0), Float64(Float64(a * c) / t_0)) t_2 = Float64(fma(c, Float64(a * Float64(1.0 / d)), b) / d) tmp = 0.0 if (d <= -2e+102) tmp = t_2; elseif (d <= -9.6e-141) tmp = t_1; elseif (d <= 6e-139) tmp = Float64(fma(b, Float64(d / c), a) / c); elseif (d <= 4.5e+104) 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[(b * N[(d / t$95$0), $MachinePrecision] + N[(N[(a * c), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(c * N[(a * N[(1.0 / d), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2e+102], t$95$2, If[LessEqual[d, -9.6e-141], t$95$1, If[LessEqual[d, 6e-139], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 4.5e+104], 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(b, \frac{d}{t\_0}, \frac{a \cdot c}{t\_0}\right)\\
t_2 := \frac{\mathsf{fma}\left(c, a \cdot \frac{1}{d}, b\right)}{d}\\
\mathbf{if}\;d \leq -2 \cdot 10^{+102}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;d \leq -9.6 \cdot 10^{-141}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 6 \cdot 10^{-139}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{elif}\;d \leq 4.5 \cdot 10^{+104}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if d < -1.99999999999999995e102 or 4.4999999999999998e104 < d Initial program 35.6%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6481.1
Applied rewrites81.1%
Applied rewrites82.6%
if -1.99999999999999995e102 < d < -9.6000000000000004e-141 or 5.9999999999999998e-139 < d < 4.4999999999999998e104Initial program 84.7%
Taylor expanded in a around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6486.4
Applied rewrites86.4%
if -9.6000000000000004e-141 < d < 5.9999999999999998e-139Initial program 75.0%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6496.3
Applied rewrites96.3%
Final simplification88.3%
(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 (/ 1.0 d)) b) d)))
(if (<= d -1.5e+102)
t_1
(if (<= d -2.6e-141)
t_0
(if (<= d 7.6e-139)
(/ (fma b (/ d c) a) c)
(if (<= d 2.1e+79) 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 * (1.0 / d)), b) / d;
double tmp;
if (d <= -1.5e+102) {
tmp = t_1;
} else if (d <= -2.6e-141) {
tmp = t_0;
} else if (d <= 7.6e-139) {
tmp = fma(b, (d / c), a) / c;
} else if (d <= 2.1e+79) {
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 * Float64(1.0 / d)), b) / d) tmp = 0.0 if (d <= -1.5e+102) tmp = t_1; elseif (d <= -2.6e-141) tmp = t_0; elseif (d <= 7.6e-139) tmp = Float64(fma(b, Float64(d / c), a) / c); elseif (d <= 2.1e+79) 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 * N[(1.0 / d), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.5e+102], t$95$1, If[LessEqual[d, -2.6e-141], t$95$0, If[LessEqual[d, 7.6e-139], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.1e+79], 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, a \cdot \frac{1}{d}, b\right)}{d}\\
\mathbf{if}\;d \leq -1.5 \cdot 10^{+102}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -2.6 \cdot 10^{-141}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 7.6 \cdot 10^{-139}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{+79}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.4999999999999999e102 or 2.10000000000000008e79 < d Initial program 37.2%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6479.9
Applied rewrites79.9%
Applied rewrites81.4%
if -1.4999999999999999e102 < d < -2.60000000000000011e-141 or 7.60000000000000015e-139 < d < 2.10000000000000008e79Initial program 85.9%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6485.9
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6485.9
Applied rewrites85.9%
if -2.60000000000000011e-141 < d < 7.60000000000000015e-139Initial program 75.0%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6496.3
Applied rewrites96.3%
Final simplification87.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma c (* a (/ 1.0 d)) b) d)))
(if (<= d -3000000.0)
t_0
(if (<= d 2.1e-106)
(/ (fma b (/ d c) a) c)
(if (<= d 1.4e+103) (* b (/ d (fma c c (* d d)))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(c, (a * (1.0 / d)), b) / d;
double tmp;
if (d <= -3000000.0) {
tmp = t_0;
} else if (d <= 2.1e-106) {
tmp = fma(b, (d / c), a) / c;
} else if (d <= 1.4e+103) {
tmp = b * (d / fma(c, c, (d * d)));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(c, Float64(a * Float64(1.0 / d)), b) / d) tmp = 0.0 if (d <= -3000000.0) tmp = t_0; elseif (d <= 2.1e-106) tmp = Float64(fma(b, Float64(d / c), a) / c); elseif (d <= 1.4e+103) tmp = Float64(b * Float64(d / 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[(c * N[(a * N[(1.0 / d), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -3000000.0], t$95$0, If[LessEqual[d, 2.1e-106], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.4e+103], N[(b * N[(d / 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(c, a \cdot \frac{1}{d}, b\right)}{d}\\
\mathbf{if}\;d \leq -3000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{-106}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{elif}\;d \leq 1.4 \cdot 10^{+103}:\\
\;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -3e6 or 1.40000000000000004e103 < d Initial program 46.8%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6476.2
Applied rewrites76.2%
Applied rewrites77.4%
if -3e6 < d < 2.10000000000000003e-106Initial program 77.1%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6486.3
Applied rewrites86.3%
if 2.10000000000000003e-106 < d < 1.40000000000000004e103Initial program 87.6%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6487.6
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6487.6
Applied rewrites87.6%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6468.8
Applied rewrites68.8%
Applied rewrites73.7%
Final simplification80.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma a (/ c d) b) d)))
(if (<= d -3000000.0)
t_0
(if (<= d 2.1e-106)
(/ (fma b (/ d c) a) c)
(if (<= d 1.46e+103) (* b (/ d (fma c c (* d d)))) 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 <= -3000000.0) {
tmp = t_0;
} else if (d <= 2.1e-106) {
tmp = fma(b, (d / c), a) / c;
} else if (d <= 1.46e+103) {
tmp = b * (d / fma(c, c, (d * d)));
} 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 <= -3000000.0) tmp = t_0; elseif (d <= 2.1e-106) tmp = Float64(fma(b, Float64(d / c), a) / c); elseif (d <= 1.46e+103) tmp = Float64(b * Float64(d / 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[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -3000000.0], t$95$0, If[LessEqual[d, 2.1e-106], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.46e+103], N[(b * N[(d / 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(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{if}\;d \leq -3000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{-106}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{elif}\;d \leq 1.46 \cdot 10^{+103}:\\
\;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -3e6 or 1.45999999999999998e103 < d Initial program 46.8%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6476.2
Applied rewrites76.2%
if -3e6 < d < 2.10000000000000003e-106Initial program 77.1%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6486.3
Applied rewrites86.3%
if 2.10000000000000003e-106 < d < 1.45999999999999998e103Initial program 87.6%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6487.6
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6487.6
Applied rewrites87.6%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6468.8
Applied rewrites68.8%
Applied rewrites73.7%
Final simplification80.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma a (/ c d) b) d)))
(if (<= d -2050000.0)
t_0
(if (<= d 1.45e-134)
(/ a c)
(if (<= d 1.46e+103) (* b (/ d (fma c c (* d d)))) 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 <= -2050000.0) {
tmp = t_0;
} else if (d <= 1.45e-134) {
tmp = a / c;
} else if (d <= 1.46e+103) {
tmp = b * (d / fma(c, c, (d * d)));
} 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 <= -2050000.0) tmp = t_0; elseif (d <= 1.45e-134) tmp = Float64(a / c); elseif (d <= 1.46e+103) tmp = Float64(b * Float64(d / 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[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2050000.0], t$95$0, If[LessEqual[d, 1.45e-134], N[(a / c), $MachinePrecision], If[LessEqual[d, 1.46e+103], N[(b * N[(d / 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(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{if}\;d \leq -2050000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.45 \cdot 10^{-134}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 1.46 \cdot 10^{+103}:\\
\;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.05e6 or 1.45999999999999998e103 < d Initial program 46.8%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6476.2
Applied rewrites76.2%
if -2.05e6 < d < 1.44999999999999997e-134Initial program 75.8%
Taylor expanded in c around inf
lower-/.f6468.9
Applied rewrites68.9%
if 1.44999999999999997e-134 < d < 1.45999999999999998e103Initial program 89.1%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6489.1
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6489.1
Applied rewrites89.1%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6467.9
Applied rewrites67.9%
Applied rewrites72.3%
Final simplification72.5%
(FPCore (a b c d)
:precision binary64
(if (<= d -2750000.0)
(/ b d)
(if (<= d 1.45e-134)
(/ a c)
(if (<= d 7.5e+103) (* b (/ d (fma c c (* d d)))) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2750000.0) {
tmp = b / d;
} else if (d <= 1.45e-134) {
tmp = a / c;
} else if (d <= 7.5e+103) {
tmp = b * (d / fma(c, c, (d * d)));
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -2750000.0) tmp = Float64(b / d); elseif (d <= 1.45e-134) tmp = Float64(a / c); elseif (d <= 7.5e+103) tmp = Float64(b * Float64(d / fma(c, c, Float64(d * d)))); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -2750000.0], N[(b / d), $MachinePrecision], If[LessEqual[d, 1.45e-134], N[(a / c), $MachinePrecision], If[LessEqual[d, 7.5e+103], N[(b * N[(d / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2750000:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 1.45 \cdot 10^{-134}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 7.5 \cdot 10^{+103}:\\
\;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -2.75e6 or 7.49999999999999922e103 < d Initial program 46.8%
Taylor expanded in c around 0
lower-/.f6466.2
Applied rewrites66.2%
if -2.75e6 < d < 1.44999999999999997e-134Initial program 75.8%
Taylor expanded in c around inf
lower-/.f6468.9
Applied rewrites68.9%
if 1.44999999999999997e-134 < d < 7.49999999999999922e103Initial program 89.1%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6489.1
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6489.1
Applied rewrites89.1%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6467.9
Applied rewrites67.9%
Applied rewrites72.3%
Final simplification68.4%
(FPCore (a b c d)
:precision binary64
(if (<= d -2750000.0)
(/ b d)
(if (<= d 1.5e-134)
(/ a c)
(if (<= d 2.4e+103) (* d (/ b (fma d d (* c c)))) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2750000.0) {
tmp = b / d;
} else if (d <= 1.5e-134) {
tmp = a / c;
} else if (d <= 2.4e+103) {
tmp = d * (b / fma(d, d, (c * c)));
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -2750000.0) tmp = Float64(b / d); elseif (d <= 1.5e-134) tmp = Float64(a / c); elseif (d <= 2.4e+103) tmp = Float64(d * Float64(b / fma(d, d, Float64(c * c)))); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -2750000.0], N[(b / d), $MachinePrecision], If[LessEqual[d, 1.5e-134], N[(a / c), $MachinePrecision], If[LessEqual[d, 2.4e+103], N[(d * N[(b / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2750000:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 1.5 \cdot 10^{-134}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 2.4 \cdot 10^{+103}:\\
\;\;\;\;d \cdot \frac{b}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -2.75e6 or 2.3999999999999998e103 < d Initial program 46.8%
Taylor expanded in c around 0
lower-/.f6466.2
Applied rewrites66.2%
if -2.75e6 < d < 1.5e-134Initial program 75.8%
Taylor expanded in c around inf
lower-/.f6468.9
Applied rewrites68.9%
if 1.5e-134 < d < 2.3999999999999998e103Initial program 89.1%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6489.1
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6489.1
Applied rewrites89.1%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6467.9
Applied rewrites67.9%
(FPCore (a b c d) :precision binary64 (if (<= d -2750000.0) (/ b d) (if (<= d 6.2e-107) (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2750000.0) {
tmp = b / d;
} else if (d <= 6.2e-107) {
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 <= (-2750000.0d0)) then
tmp = b / d
else if (d <= 6.2d-107) 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 <= -2750000.0) {
tmp = b / d;
} else if (d <= 6.2e-107) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -2750000.0: tmp = b / d elif d <= 6.2e-107: tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -2750000.0) tmp = Float64(b / d); elseif (d <= 6.2e-107) 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 <= -2750000.0) tmp = b / d; elseif (d <= 6.2e-107) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -2750000.0], N[(b / d), $MachinePrecision], If[LessEqual[d, 6.2e-107], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2750000:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 6.2 \cdot 10^{-107}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -2.75e6 or 6.20000000000000043e-107 < d Initial program 58.6%
Taylor expanded in c around 0
lower-/.f6462.2
Applied rewrites62.2%
if -2.75e6 < d < 6.20000000000000043e-107Initial program 77.1%
Taylor expanded in c around inf
lower-/.f6467.1
Applied rewrites67.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 66.6%
Taylor expanded in c around inf
lower-/.f6442.2
Applied rewrites42.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 2024221
(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))))