
(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 y x (fma b a (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(y, x, fma(b, a, (z * t)));
}
function code(x, y, z, t, a, b) return fma(y, x, fma(b, a, Float64(z * t))) end
code[x_, y_, z_, t_, a_, b_] := N[(y * x + N[(b * a + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(b, a, z \cdot t\right)\right)
\end{array}
Initial program 97.6%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6498.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.8
Applied rewrites98.8%
Final simplification98.8%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -5e+25) (* a b) (if (<= (* a b) -5e-315) (* z t) (if (<= (* a b) 1e-7) (* x y) (* a b)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -5e+25) {
tmp = a * b;
} else if ((a * b) <= -5e-315) {
tmp = z * t;
} else if ((a * b) <= 1e-7) {
tmp = x * y;
} else {
tmp = a * b;
}
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 ((a * b) <= (-5d+25)) then
tmp = a * b
else if ((a * b) <= (-5d-315)) then
tmp = z * t
else if ((a * b) <= 1d-7) then
tmp = x * y
else
tmp = a * b
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 ((a * b) <= -5e+25) {
tmp = a * b;
} else if ((a * b) <= -5e-315) {
tmp = z * t;
} else if ((a * b) <= 1e-7) {
tmp = x * y;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -5e+25: tmp = a * b elif (a * b) <= -5e-315: tmp = z * t elif (a * b) <= 1e-7: tmp = x * y else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -5e+25) tmp = Float64(a * b); elseif (Float64(a * b) <= -5e-315) tmp = Float64(z * t); elseif (Float64(a * b) <= 1e-7) tmp = Float64(x * y); else tmp = Float64(a * b); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((a * b) <= -5e+25) tmp = a * b; elseif ((a * b) <= -5e-315) tmp = z * t; elseif ((a * b) <= 1e-7) tmp = x * y; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -5e+25], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -5e-315], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1e-7], N[(x * y), $MachinePrecision], N[(a * b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -5 \cdot 10^{+25}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq -5 \cdot 10^{-315}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 10^{-7}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -5.00000000000000024e25 or 9.9999999999999995e-8 < (*.f64 a b) Initial program 95.4%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6488.0
Applied rewrites88.0%
Taylor expanded in x around 0
Applied rewrites69.3%
if -5.00000000000000024e25 < (*.f64 a b) < -5.0000000023e-315Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6462.9
Applied rewrites62.9%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6489.2
Applied rewrites89.2%
Taylor expanded in x around 0
Applied rewrites52.3%
if -5.0000000023e-315 < (*.f64 a b) < 9.9999999999999995e-8Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6450.9
Applied rewrites50.9%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6494.2
Applied rewrites94.2%
Taylor expanded in x around 0
Applied rewrites45.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6455.1
Applied rewrites55.1%
Final simplification61.8%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma y x (* a b)))) (if (<= (* a b) -5e+25) t_1 (if (<= (* a b) 4e-30) (fma t z (* x y)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(y, x, (a * b));
double tmp;
if ((a * b) <= -5e+25) {
tmp = t_1;
} else if ((a * b) <= 4e-30) {
tmp = fma(t, z, (x * y));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(y, x, Float64(a * b)) tmp = 0.0 if (Float64(a * b) <= -5e+25) tmp = t_1; elseif (Float64(a * b) <= 4e-30) tmp = fma(t, z, Float64(x * y)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a * b), $MachinePrecision], -5e+25], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 4e-30], N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{if}\;a \cdot b \leq -5 \cdot 10^{+25}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \cdot b \leq 4 \cdot 10^{-30}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 a b) < -5.00000000000000024e25 or 4e-30 < (*.f64 a b) Initial program 95.4%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6488.1
Applied rewrites88.1%
Applied rewrites89.6%
if -5.00000000000000024e25 < (*.f64 a b) < 4e-30Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6455.7
Applied rewrites55.7%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6492.3
Applied rewrites92.3%
Final simplification90.9%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma b a (* x y)))) (if (<= (* a b) -5e+25) t_1 (if (<= (* a b) 4e-30) (fma t z (* x y)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(b, a, (x * y));
double tmp;
if ((a * b) <= -5e+25) {
tmp = t_1;
} else if ((a * b) <= 4e-30) {
tmp = fma(t, z, (x * y));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(b, a, Float64(x * y)) tmp = 0.0 if (Float64(a * b) <= -5e+25) tmp = t_1; elseif (Float64(a * b) <= 4e-30) tmp = fma(t, z, Float64(x * y)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a * b), $MachinePrecision], -5e+25], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 4e-30], N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{if}\;a \cdot b \leq -5 \cdot 10^{+25}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \cdot b \leq 4 \cdot 10^{-30}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 a b) < -5.00000000000000024e25 or 4e-30 < (*.f64 a b) Initial program 95.4%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6488.1
Applied rewrites88.1%
if -5.00000000000000024e25 < (*.f64 a b) < 4e-30Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6455.7
Applied rewrites55.7%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6492.3
Applied rewrites92.3%
Final simplification90.1%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma b a (* x y))))
(if (<= (* x y) -1e+161)
t_1
(if (<= (* x y) 2e+68) (fma b a (* z t)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(b, a, (x * y));
double tmp;
if ((x * y) <= -1e+161) {
tmp = t_1;
} else if ((x * y) <= 2e+68) {
tmp = fma(b, a, (z * t));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(b, a, Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -1e+161) tmp = t_1; elseif (Float64(x * y) <= 2e+68) tmp = fma(b, a, Float64(z * t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -1e+161], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 2e+68], N[(b * a + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+161}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+68}:\\
\;\;\;\;\mathsf{fma}\left(b, a, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -1e161 or 1.99999999999999991e68 < (*.f64 x y) Initial program 94.2%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6493.3
Applied rewrites93.3%
if -1e161 < (*.f64 x y) < 1.99999999999999991e68Initial program 99.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6488.2
Applied rewrites88.2%
Final simplification89.9%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -1e+161) (* x y) (if (<= (* x y) 1e+109) (fma b a (* z t)) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -1e+161) {
tmp = x * y;
} else if ((x * y) <= 1e+109) {
tmp = fma(b, a, (z * t));
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -1e+161) tmp = Float64(x * y); elseif (Float64(x * y) <= 1e+109) tmp = fma(b, a, 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], -1e+161], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1e+109], N[(b * a + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+161}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 10^{+109}:\\
\;\;\;\;\mathsf{fma}\left(b, a, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -1e161 or 9.99999999999999982e108 < (*.f64 x y) Initial program 93.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6422.7
Applied rewrites22.7%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6483.2
Applied rewrites83.2%
Taylor expanded in x around 0
Applied rewrites9.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6479.6
Applied rewrites79.6%
if -1e161 < (*.f64 x y) < 9.99999999999999982e108Initial program 99.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6486.6
Applied rewrites86.6%
Final simplification84.4%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -5e+25) (* a b) (if (<= (* a b) 1e-7) (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -5e+25) {
tmp = a * b;
} else if ((a * b) <= 1e-7) {
tmp = z * t;
} else {
tmp = a * b;
}
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 ((a * b) <= (-5d+25)) then
tmp = a * b
else if ((a * b) <= 1d-7) then
tmp = z * t
else
tmp = a * b
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 ((a * b) <= -5e+25) {
tmp = a * b;
} else if ((a * b) <= 1e-7) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -5e+25: tmp = a * b elif (a * b) <= 1e-7: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -5e+25) tmp = Float64(a * b); elseif (Float64(a * b) <= 1e-7) tmp = Float64(z * t); else tmp = Float64(a * b); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((a * b) <= -5e+25) tmp = a * b; elseif ((a * b) <= 1e-7) tmp = z * t; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -5e+25], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1e-7], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -5 \cdot 10^{+25}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 10^{-7}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -5.00000000000000024e25 or 9.9999999999999995e-8 < (*.f64 a b) Initial program 95.4%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6488.0
Applied rewrites88.0%
Taylor expanded in x around 0
Applied rewrites69.3%
if -5.00000000000000024e25 < (*.f64 a b) < 9.9999999999999995e-8Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6455.3
Applied rewrites55.3%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6492.4
Applied rewrites92.4%
Taylor expanded in x around 0
Applied rewrites47.8%
Final simplification58.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 97.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6472.5
Applied rewrites72.5%
Taylor expanded in x around 0
Applied rewrites40.6%
Final simplification40.6%
herbie shell --seed 2024325
(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)))