
(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 a c (* d b)))
(t_1 (/ -1.0 (fma (/ (- d) t_0) d (- (/ c a))))))
(if (<= a -4.3e-23)
t_1
(if (<= a 52000000000.0)
(/ -1.0 (fma (* c (/ -1.0 t_0)) c (- (/ d b))))
t_1))))
double code(double a, double b, double c, double d) {
double t_0 = fma(a, c, (d * b));
double t_1 = -1.0 / fma((-d / t_0), d, -(c / a));
double tmp;
if (a <= -4.3e-23) {
tmp = t_1;
} else if (a <= 52000000000.0) {
tmp = -1.0 / fma((c * (-1.0 / t_0)), c, -(d / b));
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(a, c, Float64(d * b)) t_1 = Float64(-1.0 / fma(Float64(Float64(-d) / t_0), d, Float64(-Float64(c / a)))) tmp = 0.0 if (a <= -4.3e-23) tmp = t_1; elseif (a <= 52000000000.0) tmp = Float64(-1.0 / fma(Float64(c * Float64(-1.0 / t_0)), c, Float64(-Float64(d / b)))); else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-1.0 / N[(N[((-d) / t$95$0), $MachinePrecision] * d + (-N[(c / a), $MachinePrecision])), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -4.3e-23], t$95$1, If[LessEqual[a, 52000000000.0], N[(-1.0 / N[(N[(c * N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision] * c + (-N[(d / b), $MachinePrecision])), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(a, c, d \cdot b\right)\\
t_1 := \frac{-1}{\mathsf{fma}\left(\frac{-d}{t\_0}, d, -\frac{c}{a}\right)}\\
\mathbf{if}\;a \leq -4.3 \cdot 10^{-23}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \leq 52000000000:\\
\;\;\;\;\frac{-1}{\mathsf{fma}\left(c \cdot \frac{-1}{t\_0}, c, -\frac{d}{b}\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if a < -4.30000000000000002e-23 or 5.2e10 < a Initial program 56.3%
lift-/.f64N/A
div-invN/A
frac-2negN/A
metadata-evalN/A
lift-+.f64N/A
flip-+N/A
clear-numN/A
frac-timesN/A
metadata-evalN/A
lower-/.f64N/A
lower-*.f64N/A
Applied rewrites55.8%
lift-*.f64N/A
lift-neg.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
distribute-neg-inN/A
distribute-lft-inN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lift-/.f64N/A
associate-*l/N/A
Applied rewrites59.1%
lift-fma.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-/.f64N/A
associate-*l/N/A
*-lft-identityN/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
Applied rewrites63.0%
Taylor expanded in c around inf
lower-/.f6487.5
Applied rewrites87.5%
if -4.30000000000000002e-23 < a < 5.2e10Initial program 68.7%
lift-/.f64N/A
div-invN/A
frac-2negN/A
metadata-evalN/A
lift-+.f64N/A
flip-+N/A
clear-numN/A
frac-timesN/A
metadata-evalN/A
lower-/.f64N/A
lower-*.f64N/A
Applied rewrites68.6%
lift-*.f64N/A
lift-neg.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
distribute-neg-inN/A
distribute-lft-inN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lift-/.f64N/A
associate-*l/N/A
Applied rewrites77.2%
Taylor expanded in d around inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6491.7
Applied rewrites91.7%
Final simplification89.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma a c (* d b)) (fma c c (* d d))))
(t_1 (/ (fma b (/ d c) a) c)))
(if (<= c -1.1e+151)
t_1
(if (<= c -5.5e-62)
t_0
(if (<= c 9.4e-94)
(/ (+ b (/ (fma b (- (/ (* c c) d)) (* a c)) d)) d)
(if (<= c 5.9e+119) 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(b, (d / c), a) / c;
double tmp;
if (c <= -1.1e+151) {
tmp = t_1;
} else if (c <= -5.5e-62) {
tmp = t_0;
} else if (c <= 9.4e-94) {
tmp = (b + (fma(b, -((c * c) / d), (a * c)) / d)) / d;
} else if (c <= 5.9e+119) {
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(b, Float64(d / c), a) / c) tmp = 0.0 if (c <= -1.1e+151) tmp = t_1; elseif (c <= -5.5e-62) tmp = t_0; elseif (c <= 9.4e-94) tmp = Float64(Float64(b + Float64(fma(b, Float64(-Float64(Float64(c * c) / d)), Float64(a * c)) / d)) / d); elseif (c <= 5.9e+119) 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[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.1e+151], t$95$1, If[LessEqual[c, -5.5e-62], t$95$0, If[LessEqual[c, 9.4e-94], N[(N[(b + N[(N[(b * (-N[(N[(c * c), $MachinePrecision] / d), $MachinePrecision]) + N[(a * c), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 5.9e+119], 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(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -1.1 \cdot 10^{+151}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -5.5 \cdot 10^{-62}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 9.4 \cdot 10^{-94}:\\
\;\;\;\;\frac{b + \frac{\mathsf{fma}\left(b, -\frac{c \cdot c}{d}, a \cdot c\right)}{d}}{d}\\
\mathbf{elif}\;c \leq 5.9 \cdot 10^{+119}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -1.10000000000000003e151 or 5.9000000000000001e119 < c Initial program 30.6%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6494.5
Applied rewrites94.5%
if -1.10000000000000003e151 < c < -5.50000000000000022e-62 or 9.40000000000000007e-94 < c < 5.9000000000000001e119Initial program 79.4%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6479.4
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6479.4
Applied rewrites79.4%
if -5.50000000000000022e-62 < c < 9.40000000000000007e-94Initial program 69.5%
Taylor expanded in d around inf
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
unsub-negN/A
mul-1-negN/A
+-commutativeN/A
lower-/.f64N/A
Applied rewrites92.2%
Final simplification88.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma a c (* d b)) (fma c c (* d d))))
(t_1 (/ (fma b (/ d c) a) c)))
(if (<= c -1.1e+151)
t_1
(if (<= c -2.35e-66)
t_0
(if (<= c 9.4e-94)
(/ (fma a (/ c d) b) d)
(if (<= c 5.9e+119) 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(b, (d / c), a) / c;
double tmp;
if (c <= -1.1e+151) {
tmp = t_1;
} else if (c <= -2.35e-66) {
tmp = t_0;
} else if (c <= 9.4e-94) {
tmp = fma(a, (c / d), b) / d;
} else if (c <= 5.9e+119) {
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(b, Float64(d / c), a) / c) tmp = 0.0 if (c <= -1.1e+151) tmp = t_1; elseif (c <= -2.35e-66) tmp = t_0; elseif (c <= 9.4e-94) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (c <= 5.9e+119) 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[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.1e+151], t$95$1, If[LessEqual[c, -2.35e-66], t$95$0, If[LessEqual[c, 9.4e-94], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 5.9e+119], 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(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -1.1 \cdot 10^{+151}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -2.35 \cdot 10^{-66}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 9.4 \cdot 10^{-94}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;c \leq 5.9 \cdot 10^{+119}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -1.10000000000000003e151 or 5.9000000000000001e119 < c Initial program 30.6%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6494.5
Applied rewrites94.5%
if -1.10000000000000003e151 < c < -2.35e-66 or 9.40000000000000007e-94 < c < 5.9000000000000001e119Initial program 79.6%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6479.6
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6479.6
Applied rewrites79.6%
if -2.35e-66 < c < 9.40000000000000007e-94Initial program 69.1%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6490.0
Applied rewrites90.0%
Final simplification87.6%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma a (/ c d) b) d))) (if (<= d -1.15e+99) t_0 (if (<= d 2.25e+15) (/ (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.15e+99) {
tmp = t_0;
} else if (d <= 2.25e+15) {
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.15e+99) tmp = t_0; elseif (d <= 2.25e+15) 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.15e+99], t$95$0, If[LessEqual[d, 2.25e+15], 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.15 \cdot 10^{+99}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.25 \cdot 10^{+15}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.1500000000000001e99 or 2.25e15 < d Initial program 51.0%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6484.9
Applied rewrites84.9%
if -1.1500000000000001e99 < d < 2.25e15Initial program 70.1%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6479.5
Applied rewrites79.5%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ a (fma (/ d c) d c)))) (if (<= c -4.2e-60) t_0 (if (<= c 2.5e-25) (/ (fma a (/ c d) b) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = a / fma((d / c), d, c);
double tmp;
if (c <= -4.2e-60) {
tmp = t_0;
} else if (c <= 2.5e-25) {
tmp = fma(a, (c / d), b) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(a / fma(Float64(d / c), d, c)) tmp = 0.0 if (c <= -4.2e-60) tmp = t_0; elseif (c <= 2.5e-25) tmp = Float64(fma(a, Float64(c / d), b) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / N[(N[(d / c), $MachinePrecision] * d + c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -4.2e-60], t$95$0, If[LessEqual[c, 2.5e-25], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{\mathsf{fma}\left(\frac{d}{c}, d, c\right)}\\
\mathbf{if}\;c \leq -4.2 \cdot 10^{-60}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.5 \cdot 10^{-25}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -4.19999999999999982e-60 or 2.49999999999999981e-25 < c Initial program 56.6%
lift-/.f64N/A
div-invN/A
frac-2negN/A
metadata-evalN/A
lift-+.f64N/A
flip-+N/A
clear-numN/A
frac-timesN/A
metadata-evalN/A
lower-/.f64N/A
lower-*.f64N/A
Applied rewrites56.5%
lift-*.f64N/A
lift-neg.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
distribute-neg-inN/A
distribute-lft-inN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lift-/.f64N/A
associate-*l/N/A
Applied rewrites65.8%
Taylor expanded in a around -inf
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6471.7
Applied rewrites71.7%
Applied rewrites73.6%
if -4.19999999999999982e-60 < c < 2.49999999999999981e-25Initial program 70.2%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6486.8
Applied rewrites86.8%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ a (fma (/ d c) d c)))) (if (<= c -2.1e-65) t_0 (if (<= c 1.25e-109) (/ b d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = a / fma((d / c), d, c);
double tmp;
if (c <= -2.1e-65) {
tmp = t_0;
} else if (c <= 1.25e-109) {
tmp = b / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(a / fma(Float64(d / c), d, c)) tmp = 0.0 if (c <= -2.1e-65) tmp = t_0; elseif (c <= 1.25e-109) tmp = Float64(b / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / N[(N[(d / c), $MachinePrecision] * d + c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.1e-65], t$95$0, If[LessEqual[c, 1.25e-109], N[(b / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{\mathsf{fma}\left(\frac{d}{c}, d, c\right)}\\
\mathbf{if}\;c \leq -2.1 \cdot 10^{-65}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.25 \cdot 10^{-109}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -2.10000000000000003e-65 or 1.25000000000000005e-109 < c Initial program 59.0%
lift-/.f64N/A
div-invN/A
frac-2negN/A
metadata-evalN/A
lift-+.f64N/A
flip-+N/A
clear-numN/A
frac-timesN/A
metadata-evalN/A
lower-/.f64N/A
lower-*.f64N/A
Applied rewrites58.9%
lift-*.f64N/A
lift-neg.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
distribute-neg-inN/A
distribute-lft-inN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lift-/.f64N/A
associate-*l/N/A
Applied rewrites67.2%
Taylor expanded in a around -inf
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6470.5
Applied rewrites70.5%
Applied rewrites72.2%
if -2.10000000000000003e-65 < c < 1.25000000000000005e-109Initial program 68.6%
Taylor expanded in c around 0
lower-/.f6474.0
Applied rewrites74.0%
(FPCore (a b c d)
:precision binary64
(if (<= c -2.6e+100)
(/ a c)
(if (<= c -7.2e-65)
(/ (fma d b (* a c)) (* c c))
(if (<= c 4.8e-42) (/ b d) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.6e+100) {
tmp = a / c;
} else if (c <= -7.2e-65) {
tmp = fma(d, b, (a * c)) / (c * c);
} else if (c <= 4.8e-42) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -2.6e+100) tmp = Float64(a / c); elseif (c <= -7.2e-65) tmp = Float64(fma(d, b, Float64(a * c)) / Float64(c * c)); elseif (c <= 4.8e-42) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.6e+100], N[(a / c), $MachinePrecision], If[LessEqual[c, -7.2e-65], N[(N[(d * b + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.8e-42], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.6 \cdot 10^{+100}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -7.2 \cdot 10^{-65}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, a \cdot c\right)}{c \cdot c}\\
\mathbf{elif}\;c \leq 4.8 \cdot 10^{-42}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -2.6000000000000002e100 or 4.80000000000000005e-42 < c Initial program 51.2%
Taylor expanded in c around inf
lower-/.f6472.3
Applied rewrites72.3%
if -2.6000000000000002e100 < c < -7.1999999999999996e-65Initial program 75.9%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6454.5
Applied rewrites54.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6454.5
Applied rewrites54.5%
if -7.1999999999999996e-65 < c < 4.80000000000000005e-42Initial program 70.9%
Taylor expanded in c around 0
lower-/.f6471.1
Applied rewrites71.1%
(FPCore (a b c d)
:precision binary64
(if (<= c -8e+150)
(/ a c)
(if (<= c -2.1e-65)
(/ (* a c) (fma d d (* c c)))
(if (<= c 4.8e-42) (/ b d) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -8e+150) {
tmp = a / c;
} else if (c <= -2.1e-65) {
tmp = (a * c) / fma(d, d, (c * c));
} else if (c <= 4.8e-42) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -8e+150) tmp = Float64(a / c); elseif (c <= -2.1e-65) tmp = Float64(Float64(a * c) / fma(d, d, Float64(c * c))); elseif (c <= 4.8e-42) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -8e+150], N[(a / c), $MachinePrecision], If[LessEqual[c, -2.1e-65], N[(N[(a * c), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.8e-42], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8 \cdot 10^{+150}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -2.1 \cdot 10^{-65}:\\
\;\;\;\;\frac{a \cdot c}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;c \leq 4.8 \cdot 10^{-42}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -7.99999999999999985e150 or 4.80000000000000005e-42 < c Initial program 46.6%
Taylor expanded in c around inf
lower-/.f6472.3
Applied rewrites72.3%
if -7.99999999999999985e150 < c < -2.10000000000000003e-65Initial program 78.8%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6459.6
Applied rewrites59.6%
if -2.10000000000000003e-65 < c < 4.80000000000000005e-42Initial program 70.9%
Taylor expanded in c around 0
lower-/.f6471.1
Applied rewrites71.1%
(FPCore (a b c d) :precision binary64 (if (<= c -3.7e+14) (/ a c) (if (<= c 4.8e-42) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.7e+14) {
tmp = a / c;
} else if (c <= 4.8e-42) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-3.7d+14)) then
tmp = a / c
else if (c <= 4.8d-42) then
tmp = b / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.7e+14) {
tmp = a / c;
} else if (c <= 4.8e-42) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3.7e+14: tmp = a / c elif c <= 4.8e-42: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3.7e+14) tmp = Float64(a / c); elseif (c <= 4.8e-42) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -3.7e+14) tmp = a / c; elseif (c <= 4.8e-42) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.7e+14], N[(a / c), $MachinePrecision], If[LessEqual[c, 4.8e-42], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.7 \cdot 10^{+14}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 4.8 \cdot 10^{-42}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -3.7e14 or 4.80000000000000005e-42 < c Initial program 53.4%
Taylor expanded in c around inf
lower-/.f6467.1
Applied rewrites67.1%
if -3.7e14 < c < 4.80000000000000005e-42Initial program 73.0%
Taylor expanded in c around 0
lower-/.f6468.2
Applied rewrites68.2%
(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.4%
Taylor expanded in c around inf
lower-/.f6443.7
Applied rewrites43.7%
(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 2024233
(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))))