
(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 b a (* y x))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(z, t, fma(b, a, (y * x)));
}
function code(x, y, z, t, a, b) return fma(z, t, fma(b, a, Float64(y * x))) end
code[x_, y_, z_, t_, a_, b_] := N[(z * t + N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, \mathsf{fma}\left(b, a, y \cdot x\right)\right)
\end{array}
Initial program 98.0%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.2
Applied rewrites99.2%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -5e+103) (* y x) (if (<= (* x y) 1e-319) (* b a) (if (<= (* x y) 5e+91) (* t z) (* y x)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -5e+103) {
tmp = y * x;
} else if ((x * y) <= 1e-319) {
tmp = b * a;
} else if ((x * y) <= 5e+91) {
tmp = t * z;
} else {
tmp = y * x;
}
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 ((x * y) <= (-5d+103)) then
tmp = y * x
else if ((x * y) <= 1d-319) then
tmp = b * a
else if ((x * y) <= 5d+91) then
tmp = t * z
else
tmp = y * x
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 ((x * y) <= -5e+103) {
tmp = y * x;
} else if ((x * y) <= 1e-319) {
tmp = b * a;
} else if ((x * y) <= 5e+91) {
tmp = t * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -5e+103: tmp = y * x elif (x * y) <= 1e-319: tmp = b * a elif (x * y) <= 5e+91: tmp = t * z else: tmp = y * x return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -5e+103) tmp = Float64(y * x); elseif (Float64(x * y) <= 1e-319) tmp = Float64(b * a); elseif (Float64(x * y) <= 5e+91) tmp = Float64(t * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((x * y) <= -5e+103) tmp = y * x; elseif ((x * y) <= 1e-319) tmp = b * a; elseif ((x * y) <= 5e+91) tmp = t * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -5e+103], N[(y * x), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1e-319], N[(b * a), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e+91], N[(t * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+103}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \cdot y \leq 10^{-319}:\\
\;\;\;\;b \cdot a\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+91}:\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (*.f64 x y) < -5e103 or 5.0000000000000002e91 < (*.f64 x y) Initial program 95.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6435.0
Applied rewrites35.0%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6482.6
Applied rewrites82.6%
Taylor expanded in x around 0
Applied rewrites16.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6472.5
Applied rewrites72.5%
if -5e103 < (*.f64 x y) < 9.99989e-320Initial program 98.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6470.2
Applied rewrites70.2%
Taylor expanded in x around 0
Applied rewrites59.3%
if 9.99989e-320 < (*.f64 x y) < 5.0000000000000002e91Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6490.5
Applied rewrites90.5%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6462.6
Applied rewrites62.6%
Taylor expanded in x around 0
Applied rewrites53.2%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -1e+24) (not (<= (* x y) 2e+86))) (fma b a (* y x)) (fma b a (* t z))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -1e+24) || !((x * y) <= 2e+86)) {
tmp = fma(b, a, (y * x));
} else {
tmp = fma(b, a, (t * z));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(x * y) <= -1e+24) || !(Float64(x * y) <= 2e+86)) tmp = fma(b, a, Float64(y * x)); else tmp = fma(b, a, Float64(t * z)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -1e+24], N[Not[LessEqual[N[(x * y), $MachinePrecision], 2e+86]], $MachinePrecision]], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+24} \lor \neg \left(x \cdot y \leq 2 \cdot 10^{+86}\right):\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -9.9999999999999998e23 or 2e86 < (*.f64 x y) Initial program 96.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6488.6
Applied rewrites88.6%
if -9.9999999999999998e23 < (*.f64 x y) < 2e86Initial program 99.2%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6493.7
Applied rewrites93.7%
Final simplification91.4%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -4e+171) (not (<= (* x y) 2e+217))) (* y x) (fma b a (* t z))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -4e+171) || !((x * y) <= 2e+217)) {
tmp = y * x;
} else {
tmp = fma(b, a, (t * z));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(x * y) <= -4e+171) || !(Float64(x * y) <= 2e+217)) tmp = Float64(y * x); else tmp = fma(b, a, Float64(t * z)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -4e+171], N[Not[LessEqual[N[(x * y), $MachinePrecision], 2e+217]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -4 \cdot 10^{+171} \lor \neg \left(x \cdot y \leq 2 \cdot 10^{+217}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -3.99999999999999982e171 or 1.99999999999999992e217 < (*.f64 x y) Initial program 94.3%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6423.4
Applied rewrites23.4%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6490.5
Applied rewrites90.5%
Taylor expanded in x around 0
Applied rewrites12.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6486.0
Applied rewrites86.0%
if -3.99999999999999982e171 < (*.f64 x y) < 1.99999999999999992e217Initial program 99.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6485.5
Applied rewrites85.5%
Final simplification85.7%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -1e+117) (fma t z (* y x)) (if (<= (* z t) 5e+98) (fma b a (* y x)) (fma b a (* t z)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -1e+117) {
tmp = fma(t, z, (y * x));
} else if ((z * t) <= 5e+98) {
tmp = fma(b, a, (y * x));
} else {
tmp = fma(b, a, (t * z));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -1e+117) tmp = fma(t, z, Float64(y * x)); elseif (Float64(z * t) <= 5e+98) tmp = fma(b, a, Float64(y * x)); else tmp = fma(b, a, Float64(t * z)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -1e+117], N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 5e+98], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+117}:\\
\;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\
\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+98}:\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 z t) < -1.00000000000000005e117Initial program 93.3%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6478.8
Applied rewrites78.8%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6491.4
Applied rewrites91.4%
if -1.00000000000000005e117 < (*.f64 z t) < 4.9999999999999998e98Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6491.6
Applied rewrites91.6%
if 4.9999999999999998e98 < (*.f64 z t) Initial program 95.1%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6493.0
Applied rewrites93.0%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* z t) -1e+117) (not (<= (* z t) 2e+110))) (* t z) (* b a)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((z * t) <= -1e+117) || !((z * t) <= 2e+110)) {
tmp = t * z;
} else {
tmp = b * a;
}
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+117)) .or. (.not. ((z * t) <= 2d+110))) then
tmp = t * z
else
tmp = b * a
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+117) || !((z * t) <= 2e+110)) {
tmp = t * z;
} else {
tmp = b * a;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((z * t) <= -1e+117) or not ((z * t) <= 2e+110): tmp = t * z else: tmp = b * a return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(z * t) <= -1e+117) || !(Float64(z * t) <= 2e+110)) tmp = Float64(t * z); else tmp = Float64(b * a); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (((z * t) <= -1e+117) || ~(((z * t) <= 2e+110))) tmp = t * z; else tmp = b * a; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], -1e+117], N[Not[LessEqual[N[(z * t), $MachinePrecision], 2e+110]], $MachinePrecision]], N[(t * z), $MachinePrecision], N[(b * a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+117} \lor \neg \left(z \cdot t \leq 2 \cdot 10^{+110}\right):\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;b \cdot a\\
\end{array}
\end{array}
if (*.f64 z t) < -1.00000000000000005e117 or 2e110 < (*.f64 z t) Initial program 94.1%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6485.4
Applied rewrites85.4%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6487.6
Applied rewrites87.6%
Taylor expanded in x around 0
Applied rewrites72.9%
if -1.00000000000000005e117 < (*.f64 z t) < 2e110Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6491.6
Applied rewrites91.6%
Taylor expanded in x around 0
Applied rewrites51.7%
Final simplification58.7%
(FPCore (x y z t a b) :precision binary64 (* b a))
double code(double x, double y, double z, double t, double a, double b) {
return b * a;
}
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 = b * a
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return b * a;
}
def code(x, y, z, t, a, b): return b * a
function code(x, y, z, t, a, b) return Float64(b * a) end
function tmp = code(x, y, z, t, a, b) tmp = b * a; end
code[x_, y_, z_, t_, a_, b_] := N[(b * a), $MachinePrecision]
\begin{array}{l}
\\
b \cdot a
\end{array}
Initial program 98.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6472.7
Applied rewrites72.7%
Taylor expanded in x around 0
Applied rewrites40.0%
herbie shell --seed 2024317
(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)))