
(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 d) c b) d)))
(if (<= d -3e+85)
t_0
(if (<= d -3.9e-6)
(/ (fma d b (* c a)) (fma d d (* c c)))
(if (<= d 3.4e-121)
(/ (fma (/ d c) b a) c)
(if (<= d 6e+35) (/ (+ (* a c) (* b d)) (fma c c (* d d))) t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = fma((a / d), c, b) / d;
double tmp;
if (d <= -3e+85) {
tmp = t_0;
} else if (d <= -3.9e-6) {
tmp = fma(d, b, (c * a)) / fma(d, d, (c * c));
} else if (d <= 3.4e-121) {
tmp = fma((d / c), b, a) / c;
} else if (d <= 6e+35) {
tmp = ((a * c) + (b * d)) / fma(c, c, (d * d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(a / d), c, b) / d) tmp = 0.0 if (d <= -3e+85) tmp = t_0; elseif (d <= -3.9e-6) tmp = Float64(fma(d, b, Float64(c * a)) / fma(d, d, Float64(c * c))); elseif (d <= 3.4e-121) tmp = Float64(fma(Float64(d / c), b, a) / c); elseif (d <= 6e+35) tmp = Float64(Float64(Float64(a * c) + Float64(b * 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[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -3e+85], t$95$0, If[LessEqual[d, -3.9e-6], N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.4e-121], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 6e+35], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{if}\;d \leq -3 \cdot 10^{+85}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -3.9 \cdot 10^{-6}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;d \leq 3.4 \cdot 10^{-121}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{elif}\;d \leq 6 \cdot 10^{+35}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -3e85 or 5.99999999999999981e35 < d Initial program 40.6%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6481.6
Applied rewrites81.6%
if -3e85 < d < -3.8999999999999999e-6Initial program 87.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6488.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6488.0
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6488.0
Applied rewrites88.0%
if -3.8999999999999999e-6 < d < 3.40000000000000001e-121Initial program 70.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6470.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6470.0
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6470.0
Applied rewrites70.0%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6490.3
Applied rewrites90.3%
if 3.40000000000000001e-121 < d < 5.99999999999999981e35Initial program 87.0%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6487.1
Applied rewrites87.1%
Final simplification85.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma d b (* c a)) (fma d d (* c c))))
(t_1 (/ (fma (/ a d) c b) d)))
(if (<= d -3e+85)
t_1
(if (<= d -3.9e-6)
t_0
(if (<= d 3.4e-121)
(/ (fma (/ d c) b a) c)
(if (<= d 6e+35) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, b, (c * a)) / fma(d, d, (c * c));
double t_1 = fma((a / d), c, b) / d;
double tmp;
if (d <= -3e+85) {
tmp = t_1;
} else if (d <= -3.9e-6) {
tmp = t_0;
} else if (d <= 3.4e-121) {
tmp = fma((d / c), b, a) / c;
} else if (d <= 6e+35) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(d, b, Float64(c * a)) / fma(d, d, Float64(c * c))) t_1 = Float64(fma(Float64(a / d), c, b) / d) tmp = 0.0 if (d <= -3e+85) tmp = t_1; elseif (d <= -3.9e-6) tmp = t_0; elseif (d <= 3.4e-121) tmp = Float64(fma(Float64(d / c), b, a) / c); elseif (d <= 6e+35) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -3e+85], t$95$1, If[LessEqual[d, -3.9e-6], t$95$0, If[LessEqual[d, 3.4e-121], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 6e+35], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
t_1 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{if}\;d \leq -3 \cdot 10^{+85}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -3.9 \cdot 10^{-6}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 3.4 \cdot 10^{-121}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{elif}\;d \leq 6 \cdot 10^{+35}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -3e85 or 5.99999999999999981e35 < d Initial program 40.6%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6481.6
Applied rewrites81.6%
if -3e85 < d < -3.8999999999999999e-6 or 3.40000000000000001e-121 < d < 5.99999999999999981e35Initial program 87.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6487.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6487.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6487.5
Applied rewrites87.5%
if -3.8999999999999999e-6 < d < 3.40000000000000001e-121Initial program 70.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6470.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6470.0
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6470.0
Applied rewrites70.0%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6490.3
Applied rewrites90.3%
Final simplification85.8%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.9e+150)
(/ b d)
(if (<= d -0.0011)
(* (/ d (fma c c (* d d))) b)
(if (<= d 1.4e-42)
(/ a c)
(if (<= d 6e+116) (* (/ b (fma d d (* c c))) d) (/ b d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.9e+150) {
tmp = b / d;
} else if (d <= -0.0011) {
tmp = (d / fma(c, c, (d * d))) * b;
} else if (d <= 1.4e-42) {
tmp = a / c;
} else if (d <= 6e+116) {
tmp = (b / fma(d, d, (c * c))) * d;
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -1.9e+150) tmp = Float64(b / d); elseif (d <= -0.0011) tmp = Float64(Float64(d / fma(c, c, Float64(d * d))) * b); elseif (d <= 1.4e-42) tmp = Float64(a / c); elseif (d <= 6e+116) tmp = Float64(Float64(b / fma(d, d, Float64(c * c))) * d); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.9e+150], N[(b / d), $MachinePrecision], If[LessEqual[d, -0.0011], N[(N[(d / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], If[LessEqual[d, 1.4e-42], N[(a / c), $MachinePrecision], If[LessEqual[d, 6e+116], N[(N[(b / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision], N[(b / d), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.9 \cdot 10^{+150}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -0.0011:\\
\;\;\;\;\frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot b\\
\mathbf{elif}\;d \leq 1.4 \cdot 10^{-42}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 6 \cdot 10^{+116}:\\
\;\;\;\;\frac{b}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot d\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.89999999999999995e150 or 5.9999999999999997e116 < d Initial program 32.1%
Taylor expanded in c around 0
lower-/.f6473.2
Applied rewrites73.2%
if -1.89999999999999995e150 < d < -0.00110000000000000007Initial program 73.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6473.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6473.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6473.5
Applied rewrites73.5%
Taylor expanded in a around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6461.8
Applied rewrites61.8%
if -0.00110000000000000007 < d < 1.39999999999999999e-42Initial program 73.0%
Taylor expanded in c around inf
lower-/.f6471.5
Applied rewrites71.5%
if 1.39999999999999999e-42 < d < 5.9999999999999997e116Initial program 72.0%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6471.4
Applied rewrites71.4%
Final simplification70.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* (/ b (fma d d (* c c))) d)))
(if (<= d -2.9e+122)
(/ b d)
(if (<= d -0.0011)
t_0
(if (<= d 1.4e-42) (/ a c) (if (<= d 4.1e+121) t_0 (/ b d)))))))
double code(double a, double b, double c, double d) {
double t_0 = (b / fma(d, d, (c * c))) * d;
double tmp;
if (d <= -2.9e+122) {
tmp = b / d;
} else if (d <= -0.0011) {
tmp = t_0;
} else if (d <= 1.4e-42) {
tmp = a / c;
} else if (d <= 4.1e+121) {
tmp = t_0;
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b / fma(d, d, Float64(c * c))) * d) tmp = 0.0 if (d <= -2.9e+122) tmp = Float64(b / d); elseif (d <= -0.0011) tmp = t_0; elseif (d <= 1.4e-42) tmp = Float64(a / c); elseif (d <= 4.1e+121) tmp = t_0; else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision]}, If[LessEqual[d, -2.9e+122], N[(b / d), $MachinePrecision], If[LessEqual[d, -0.0011], t$95$0, If[LessEqual[d, 1.4e-42], N[(a / c), $MachinePrecision], If[LessEqual[d, 4.1e+121], t$95$0, N[(b / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot d\\
\mathbf{if}\;d \leq -2.9 \cdot 10^{+122}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -0.0011:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.4 \cdot 10^{-42}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 4.1 \cdot 10^{+121}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -2.9000000000000001e122 or 4.1e121 < d Initial program 33.9%
Taylor expanded in c around 0
lower-/.f6474.8
Applied rewrites74.8%
if -2.9000000000000001e122 < d < -0.00110000000000000007 or 1.39999999999999999e-42 < d < 4.1e121Initial program 73.6%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6462.9
Applied rewrites62.9%
if -0.00110000000000000007 < d < 1.39999999999999999e-42Initial program 73.0%
Taylor expanded in c around inf
lower-/.f6471.5
Applied rewrites71.5%
Final simplification70.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.1e+94) (not (<= d 8.2e+35))) (/ (fma (/ a d) c b) d) (/ (fma (/ b c) d a) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.1e+94) || !(d <= 8.2e+35)) {
tmp = fma((a / d), c, b) / d;
} else {
tmp = fma((b / c), d, a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.1e+94) || !(d <= 8.2e+35)) tmp = Float64(fma(Float64(a / d), c, b) / d); else tmp = Float64(fma(Float64(b / c), d, a) / c); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.1e+94], N[Not[LessEqual[d, 8.2e+35]], $MachinePrecision]], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.1 \cdot 10^{+94} \lor \neg \left(d \leq 8.2 \cdot 10^{+35}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\end{array}
\end{array}
if d < -3.09999999999999991e94 or 8.1999999999999997e35 < d Initial program 41.7%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6483.7
Applied rewrites83.7%
if -3.09999999999999991e94 < d < 8.1999999999999997e35Initial program 74.8%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6473.2
Applied rewrites73.2%
Final simplification77.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.0145) (not (<= d 1.35e-44))) (/ (fma (/ a d) c b) d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.0145) || !(d <= 1.35e-44)) {
tmp = fma((a / d), c, b) / d;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.0145) || !(d <= 1.35e-44)) tmp = Float64(fma(Float64(a / d), c, b) / d); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.0145], N[Not[LessEqual[d, 1.35e-44]], $MachinePrecision]], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.0145 \lor \neg \left(d \leq 1.35 \cdot 10^{-44}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -0.0145000000000000007 or 1.35e-44 < d Initial program 51.8%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6473.8
Applied rewrites73.8%
if -0.0145000000000000007 < d < 1.35e-44Initial program 73.1%
Taylor expanded in c around inf
lower-/.f6471.6
Applied rewrites71.6%
Final simplification72.9%
(FPCore (a b c d) :precision binary64 (if (<= d -3.1e+94) (/ (fma (/ a d) c b) d) (if (<= d 5.4e-83) (/ (fma (/ d c) b a) c) (/ (fma (/ c d) a b) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3.1e+94) {
tmp = fma((a / d), c, b) / d;
} else if (d <= 5.4e-83) {
tmp = fma((d / c), b, a) / c;
} else {
tmp = fma((c / d), a, b) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -3.1e+94) tmp = Float64(fma(Float64(a / d), c, b) / d); elseif (d <= 5.4e-83) tmp = Float64(fma(Float64(d / c), b, a) / c); else tmp = Float64(fma(Float64(c / d), a, b) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -3.1e+94], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 5.4e-83], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.1 \cdot 10^{+94}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{elif}\;d \leq 5.4 \cdot 10^{-83}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
\end{array}
\end{array}
if d < -3.09999999999999991e94Initial program 36.1%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6482.4
Applied rewrites82.4%
if -3.09999999999999991e94 < d < 5.39999999999999982e-83Initial program 73.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6473.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6473.6
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6473.6
Applied rewrites73.6%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6482.2
Applied rewrites82.2%
if 5.39999999999999982e-83 < d Initial program 54.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6454.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6454.7
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6454.7
Applied rewrites54.7%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6476.2
Applied rewrites76.2%
Final simplification80.1%
(FPCore (a b c d) :precision binary64 (if (<= d -3.1e+94) (/ (fma (/ a d) c b) d) (if (<= d 5.4e-83) (/ (fma (/ b c) d a) c) (/ (fma (/ c d) a b) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3.1e+94) {
tmp = fma((a / d), c, b) / d;
} else if (d <= 5.4e-83) {
tmp = fma((b / c), d, a) / c;
} else {
tmp = fma((c / d), a, b) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -3.1e+94) tmp = Float64(fma(Float64(a / d), c, b) / d); elseif (d <= 5.4e-83) tmp = Float64(fma(Float64(b / c), d, a) / c); else tmp = Float64(fma(Float64(c / d), a, b) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -3.1e+94], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 5.4e-83], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.1 \cdot 10^{+94}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{elif}\;d \leq 5.4 \cdot 10^{-83}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
\end{array}
\end{array}
if d < -3.09999999999999991e94Initial program 36.1%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6482.4
Applied rewrites82.4%
if -3.09999999999999991e94 < d < 5.39999999999999982e-83Initial program 73.5%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6478.3
Applied rewrites78.3%
if 5.39999999999999982e-83 < d Initial program 54.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6454.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6454.7
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6454.7
Applied rewrites54.7%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6476.2
Applied rewrites76.2%
Final simplification78.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.5e+93) (not (<= d 3.9e-35))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.5e+93) || !(d <= 3.9e-35)) {
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 ((d <= (-2.5d+93)) .or. (.not. (d <= 3.9d-35))) 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 ((d <= -2.5e+93) || !(d <= 3.9e-35)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.5e+93) or not (d <= 3.9e-35): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.5e+93) || !(d <= 3.9e-35)) 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 ((d <= -2.5e+93) || ~((d <= 3.9e-35))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.5e+93], N[Not[LessEqual[d, 3.9e-35]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.5 \cdot 10^{+93} \lor \neg \left(d \leq 3.9 \cdot 10^{-35}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -2.5000000000000001e93 or 3.8999999999999998e-35 < d Initial program 45.5%
Taylor expanded in c around 0
lower-/.f6465.8
Applied rewrites65.8%
if -2.5000000000000001e93 < d < 3.8999999999999998e-35Initial program 74.8%
Taylor expanded in c around inf
lower-/.f6464.9
Applied rewrites64.9%
Final simplification65.3%
(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 60.3%
Taylor expanded in c around inf
lower-/.f6441.2
Applied rewrites41.2%
Final simplification41.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 2024314
(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))))