
(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 8 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%
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f6498.8
Applied rewrites98.8%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -1e+134) (* z t) (if (<= (* z t) -1e-154) (* a b) (if (<= (* z t) 5e+86) (* x y) (* z t)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -1e+134) {
tmp = z * t;
} else if ((z * t) <= -1e-154) {
tmp = a * b;
} else if ((z * t) <= 5e+86) {
tmp = x * y;
} 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) <= (-1d+134)) then
tmp = z * t
else if ((z * t) <= (-1d-154)) then
tmp = a * b
else if ((z * t) <= 5d+86) then
tmp = x * y
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) <= -1e+134) {
tmp = z * t;
} else if ((z * t) <= -1e-154) {
tmp = a * b;
} else if ((z * t) <= 5e+86) {
tmp = x * y;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z * t) <= -1e+134: tmp = z * t elif (z * t) <= -1e-154: tmp = a * b elif (z * t) <= 5e+86: tmp = x * y else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -1e+134) tmp = Float64(z * t); elseif (Float64(z * t) <= -1e-154) tmp = Float64(a * b); elseif (Float64(z * t) <= 5e+86) tmp = Float64(x * y); 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) <= -1e+134) tmp = z * t; elseif ((z * t) <= -1e-154) tmp = a * b; elseif ((z * t) <= 5e+86) tmp = x * y; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -1e+134], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], -1e-154], N[(a * b), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 5e+86], N[(x * y), $MachinePrecision], N[(z * t), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+134}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq -1 \cdot 10^{-154}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+86}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -9.99999999999999921e133 or 4.9999999999999998e86 < (*.f64 z t) Initial program 95.6%
Taylor expanded in z around inf
lower-*.f6482.1
Applied rewrites82.1%
if -9.99999999999999921e133 < (*.f64 z t) < -9.9999999999999997e-155Initial program 100.0%
Taylor expanded in a around inf
lower-*.f6456.6
Applied rewrites56.6%
if -9.9999999999999997e-155 < (*.f64 z t) < 4.9999999999999998e86Initial program 100.0%
Taylor expanded in x around inf
lower-*.f6452.4
Applied rewrites52.4%
Final simplification63.6%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -1e+134) (fma t z (* x y)) (if (<= (* z t) 5e+86) (fma y x (* a b)) (fma a b (* z t)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -1e+134) {
tmp = fma(t, z, (x * y));
} else if ((z * t) <= 5e+86) {
tmp = fma(y, x, (a * b));
} else {
tmp = fma(a, b, (z * t));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -1e+134) tmp = fma(t, z, Float64(x * y)); elseif (Float64(z * t) <= 5e+86) tmp = fma(y, x, Float64(a * b)); else tmp = fma(a, b, Float64(z * t)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -1e+134], N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 5e+86], N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+134}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\right)\\
\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+86}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\end{array}
\end{array}
if (*.f64 z t) < -9.99999999999999921e133Initial program 95.7%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-*.f6497.6
Applied rewrites97.6%
if -9.99999999999999921e133 < (*.f64 z t) < 4.9999999999999998e86Initial program 100.0%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6490.6
Applied rewrites90.6%
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6490.6
Applied rewrites90.6%
if 4.9999999999999998e86 < (*.f64 z t) Initial program 95.5%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6490.4
Applied rewrites90.4%
Final simplification91.8%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -1e+134) (fma t z (* x y)) (if (<= (* z t) 5e+86) (fma a b (* x y)) (fma a b (* z t)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -1e+134) {
tmp = fma(t, z, (x * y));
} else if ((z * t) <= 5e+86) {
tmp = fma(a, b, (x * y));
} else {
tmp = fma(a, b, (z * t));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -1e+134) tmp = fma(t, z, Float64(x * y)); elseif (Float64(z * t) <= 5e+86) tmp = fma(a, b, Float64(x * y)); else tmp = fma(a, b, Float64(z * t)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -1e+134], N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 5e+86], N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+134}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\right)\\
\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+86}:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\end{array}
\end{array}
if (*.f64 z t) < -9.99999999999999921e133Initial program 95.7%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-*.f6497.6
Applied rewrites97.6%
if -9.99999999999999921e133 < (*.f64 z t) < 4.9999999999999998e86Initial program 100.0%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6490.6
Applied rewrites90.6%
if 4.9999999999999998e86 < (*.f64 z t) Initial program 95.5%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6490.4
Applied rewrites90.4%
Final simplification91.8%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma a b (* z t)))) (if (<= (* z t) -5e+62) t_1 (if (<= (* z t) 5e+86) (fma a b (* x y)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(a, b, (z * t));
double tmp;
if ((z * t) <= -5e+62) {
tmp = t_1;
} else if ((z * t) <= 5e+86) {
tmp = fma(a, b, (x * y));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(a, b, Float64(z * t)) tmp = 0.0 if (Float64(z * t) <= -5e+62) tmp = t_1; elseif (Float64(z * t) <= 5e+86) tmp = fma(a, b, Float64(x * y)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -5e+62], t$95$1, If[LessEqual[N[(z * t), $MachinePrecision], 5e+86], N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+62}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+86}:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 z t) < -5.00000000000000029e62 or 4.9999999999999998e86 < (*.f64 z t) Initial program 95.9%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6489.8
Applied rewrites89.8%
if -5.00000000000000029e62 < (*.f64 z t) < 4.9999999999999998e86Initial program 100.0%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6492.0
Applied rewrites92.0%
Final simplification91.1%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -7.8e+204) (* x y) (if (<= (* x y) 7.2e+186) (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) <= -7.8e+204) {
tmp = x * y;
} else if ((x * y) <= 7.2e+186) {
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) <= -7.8e+204) tmp = Float64(x * y); elseif (Float64(x * y) <= 7.2e+186) 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], -7.8e+204], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 7.2e+186], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -7.8 \cdot 10^{+204}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 7.2 \cdot 10^{+186}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -7.80000000000000033e204 or 7.2000000000000003e186 < (*.f64 x y) Initial program 98.2%
Taylor expanded in x around inf
lower-*.f6482.1
Applied rewrites82.1%
if -7.80000000000000033e204 < (*.f64 x y) < 7.2000000000000003e186Initial program 98.5%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6481.2
Applied rewrites81.2%
Final simplification81.4%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -1e+134) (* z t) (if (<= (* z t) 2e+83) (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -1e+134) {
tmp = z * t;
} else if ((z * t) <= 2e+83) {
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) <= (-1d+134)) then
tmp = z * t
else if ((z * t) <= 2d+83) 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) <= -1e+134) {
tmp = z * t;
} else if ((z * t) <= 2e+83) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z * t) <= -1e+134: tmp = z * t elif (z * t) <= 2e+83: tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -1e+134) tmp = Float64(z * t); elseif (Float64(z * t) <= 2e+83) 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) <= -1e+134) tmp = z * t; elseif ((z * t) <= 2e+83) 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], -1e+134], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 2e+83], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+134}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+83}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -9.99999999999999921e133 or 2.00000000000000006e83 < (*.f64 z t) Initial program 95.7%
Taylor expanded in z around inf
lower-*.f6479.6
Applied rewrites79.6%
if -9.99999999999999921e133 < (*.f64 z t) < 2.00000000000000006e83Initial program 100.0%
Taylor expanded in a around inf
lower-*.f6448.1
Applied rewrites48.1%
Final simplification59.7%
(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
lower-*.f6436.5
Applied rewrites36.5%
herbie shell --seed 2024214
(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)))