
(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((x * y) + (z * t)) + (a * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
def code(x, y, z, t, a, b): return ((x * y) + (z * t)) + (a * b)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) end
function tmp = code(x, y, z, t, a, b) tmp = ((x * y) + (z * t)) + (a * b); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z \cdot t\right) + a \cdot b
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((x * y) + (z * t)) + (a * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
def code(x, y, z, t, a, b): return ((x * y) + (z * t)) + (a * b)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) end
function tmp = code(x, y, z, t, a, b) tmp = ((x * y) + (z * t)) + (a * b); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z \cdot t\right) + a \cdot b
\end{array}
(FPCore (x y z t a b) :precision binary64 (fma z t (fma x y (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(z, t, fma(x, y, (a * b)));
}
function code(x, y, z, t, a, b) return fma(z, t, fma(x, y, Float64(a * b))) end
code[x_, y_, z_, t_, a_, b_] := N[(z * t + N[(x * y + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, \mathsf{fma}\left(x, y, a \cdot b\right)\right)
\end{array}
Initial program 98.4%
+-commutativeN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6499.2
Applied egg-rr99.2%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (+ (* x y) (* z t)))) (if (<= t_1 -1e+141) (* z t) (if (<= t_1 4e+141) (* a b) (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (x * y) + (z * t);
double tmp;
if (t_1 <= -1e+141) {
tmp = z * t;
} else if (t_1 <= 4e+141) {
tmp = a * b;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_1
real(8) :: tmp
t_1 = (x * y) + (z * t)
if (t_1 <= (-1d+141)) then
tmp = z * t
else if (t_1 <= 4d+141) then
tmp = a * b
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (x * y) + (z * t);
double tmp;
if (t_1 <= -1e+141) {
tmp = z * t;
} else if (t_1 <= 4e+141) {
tmp = a * b;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): t_1 = (x * y) + (z * t) tmp = 0 if t_1 <= -1e+141: tmp = z * t elif t_1 <= 4e+141: tmp = a * b else: tmp = x * y return tmp
function code(x, y, z, t, a, b) t_1 = Float64(Float64(x * y) + Float64(z * t)) tmp = 0.0 if (t_1 <= -1e+141) tmp = Float64(z * t); elseif (t_1 <= 4e+141) tmp = Float64(a * b); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) t_1 = (x * y) + (z * t); tmp = 0.0; if (t_1 <= -1e+141) tmp = z * t; elseif (t_1 <= 4e+141) tmp = a * b; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+141], N[(z * t), $MachinePrecision], If[LessEqual[t$95$1, 4e+141], N[(a * b), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot y + z \cdot t\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+141}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{+141}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (+.f64 (*.f64 x y) (*.f64 z t)) < -1.00000000000000002e141Initial program 98.3%
Taylor expanded in z around inf
*-lowering-*.f6456.9
Simplified56.9%
if -1.00000000000000002e141 < (+.f64 (*.f64 x y) (*.f64 z t)) < 4.00000000000000007e141Initial program 100.0%
Taylor expanded in a around inf
*-lowering-*.f6463.9
Simplified63.9%
if 4.00000000000000007e141 < (+.f64 (*.f64 x y) (*.f64 z t)) Initial program 95.6%
Taylor expanded in x around inf
*-lowering-*.f6456.2
Simplified56.2%
Final simplification60.2%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -4e+41) (fma y x (* a b)) (if (<= (* x y) 4e+76) (fma a b (* z t)) (fma a b (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -4e+41) {
tmp = fma(y, x, (a * b));
} else if ((x * y) <= 4e+76) {
tmp = fma(a, b, (z * t));
} else {
tmp = fma(a, b, (x * y));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -4e+41) tmp = fma(y, x, Float64(a * b)); elseif (Float64(x * y) <= 4e+76) tmp = fma(a, b, Float64(z * t)); else tmp = fma(a, b, Float64(x * y)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -4e+41], N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 4e+76], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -4 \cdot 10^{+41}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{elif}\;x \cdot y \leq 4 \cdot 10^{+76}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -4.00000000000000002e41Initial program 97.4%
Taylor expanded in z around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6483.3
Simplified83.3%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6485.9
Applied egg-rr85.9%
if -4.00000000000000002e41 < (*.f64 x y) < 4.0000000000000002e76Initial program 100.0%
Taylor expanded in x around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6492.4
Simplified92.4%
if 4.0000000000000002e76 < (*.f64 x y) Initial program 94.7%
Taylor expanded in z around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6489.8
Simplified89.8%
Final simplification90.8%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma a b (* x y))))
(if (<= (* x y) -3e+31)
t_1
(if (<= (* x y) 3.6e+76) (fma a b (* z t)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(a, b, (x * y));
double tmp;
if ((x * y) <= -3e+31) {
tmp = t_1;
} else if ((x * y) <= 3.6e+76) {
tmp = fma(a, b, (z * t));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(a, b, Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -3e+31) tmp = t_1; elseif (Float64(x * y) <= 3.6e+76) tmp = fma(a, b, Float64(z * t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -3e+31], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 3.6e+76], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -3 \cdot 10^{+31}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 3.6 \cdot 10^{+76}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -2.99999999999999989e31 or 3.6000000000000003e76 < (*.f64 x y) Initial program 95.8%
Taylor expanded in z around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6487.1
Simplified87.1%
if -2.99999999999999989e31 < (*.f64 x y) < 3.6000000000000003e76Initial program 100.0%
Taylor expanded in x around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6492.4
Simplified92.4%
Final simplification90.4%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -6.6e+88) (* x y) (if (<= (* x y) 1.1e+163) (fma a b (* z t)) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -6.6e+88) {
tmp = x * y;
} else if ((x * y) <= 1.1e+163) {
tmp = fma(a, b, (z * t));
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -6.6e+88) tmp = Float64(x * y); elseif (Float64(x * y) <= 1.1e+163) tmp = fma(a, b, Float64(z * t)); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -6.6e+88], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1.1e+163], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -6.6 \cdot 10^{+88}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 1.1 \cdot 10^{+163}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -6.6000000000000006e88 or 1.09999999999999993e163 < (*.f64 x y) Initial program 94.9%
Taylor expanded in x around inf
*-lowering-*.f6477.4
Simplified77.4%
if -6.6000000000000006e88 < (*.f64 x y) < 1.09999999999999993e163Initial program 100.0%
Taylor expanded in x around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6489.0
Simplified89.0%
Final simplification85.5%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -5e+135) (* z t) (if (<= (* z t) 2e+43) (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -5e+135) {
tmp = z * t;
} else if ((z * t) <= 2e+43) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((z * t) <= (-5d+135)) then
tmp = z * t
else if ((z * t) <= 2d+43) then
tmp = a * b
else
tmp = z * t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -5e+135) {
tmp = z * t;
} else if ((z * t) <= 2e+43) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z * t) <= -5e+135: tmp = z * t elif (z * t) <= 2e+43: tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -5e+135) tmp = Float64(z * t); elseif (Float64(z * t) <= 2e+43) tmp = Float64(a * b); else tmp = Float64(z * t); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((z * t) <= -5e+135) tmp = z * t; elseif ((z * t) <= 2e+43) tmp = a * b; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -5e+135], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 2e+43], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+135}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+43}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -5.00000000000000029e135 or 2.00000000000000003e43 < (*.f64 z t) Initial program 96.9%
Taylor expanded in z around inf
*-lowering-*.f6469.2
Simplified69.2%
if -5.00000000000000029e135 < (*.f64 z t) < 2.00000000000000003e43Initial program 99.4%
Taylor expanded in a around inf
*-lowering-*.f6453.3
Simplified53.3%
Final simplification59.4%
(FPCore (x y z t a b) :precision binary64 (* a b))
double code(double x, double y, double z, double t, double a, double b) {
return a * b;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = a * b
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return a * b;
}
def code(x, y, z, t, a, b): return a * b
function code(x, y, z, t, a, b) return Float64(a * b) end
function tmp = code(x, y, z, t, a, b) tmp = a * b; end
code[x_, y_, z_, t_, a_, b_] := N[(a * b), $MachinePrecision]
\begin{array}{l}
\\
a \cdot b
\end{array}
Initial program 98.4%
Taylor expanded in a around inf
*-lowering-*.f6439.7
Simplified39.7%
herbie shell --seed 2024204
(FPCore (x y z t a b)
:name "Linear.V3:$cdot from linear-1.19.1.3, B"
:precision binary64
(+ (+ (* x y) (* z t)) (* a b)))