
(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 b a (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(z, t, fma(b, a, (x * y)));
}
function code(x, y, z, t, a, b) return fma(z, t, fma(b, a, Float64(x * y))) end
code[x_, y_, z_, t_, a_, b_] := N[(z * t + N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, \mathsf{fma}\left(b, a, x \cdot y\right)\right)
\end{array}
Initial program 97.2%
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.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 (let* ((t_1 (fma b a (* x y)))) (if (<= (* a b) -1e+52) t_1 (if (<= (* a b) 4e+83) (fma z t (* 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) <= -1e+52) {
tmp = t_1;
} else if ((a * b) <= 4e+83) {
tmp = fma(z, t, (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) <= -1e+52) tmp = t_1; elseif (Float64(a * b) <= 4e+83) tmp = fma(z, t, 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], -1e+52], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 4e+83], N[(z * t + 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 -1 \cdot 10^{+52}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \cdot b \leq 4 \cdot 10^{+83}:\\
\;\;\;\;\mathsf{fma}\left(z, t, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 a b) < -9.9999999999999999e51 or 4.00000000000000012e83 < (*.f64 a b) Initial program 94.9%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6486.8
Applied rewrites86.8%
if -9.9999999999999999e51 < (*.f64 a b) < 4.00000000000000012e83Initial program 99.2%
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.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
*-commutativeN/A
lower-*.f6495.0
Applied rewrites95.0%
Final simplification91.3%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma b a (* x y)))) (if (<= (* a b) -1e+52) t_1 (if (<= (* a b) 4e+83) (fma y x (* t z)) 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) <= -1e+52) {
tmp = t_1;
} else if ((a * b) <= 4e+83) {
tmp = fma(y, x, (t * z));
} 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) <= -1e+52) tmp = t_1; elseif (Float64(a * b) <= 4e+83) tmp = fma(y, x, Float64(t * z)); 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], -1e+52], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 4e+83], N[(y * x + N[(t * z), $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 -1 \cdot 10^{+52}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \cdot b \leq 4 \cdot 10^{+83}:\\
\;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 a b) < -9.9999999999999999e51 or 4.00000000000000012e83 < (*.f64 a b) Initial program 94.9%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6486.8
Applied rewrites86.8%
if -9.9999999999999999e51 < (*.f64 a b) < 4.00000000000000012e83Initial program 99.2%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6494.3
Applied rewrites94.3%
Final simplification90.9%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma b a (* t z))))
(if (<= (* t z) -2.5e-16)
t_1
(if (<= (* t z) 2.05e-49) (fma b a (* x y)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(b, a, (t * z));
double tmp;
if ((t * z) <= -2.5e-16) {
tmp = t_1;
} else if ((t * z) <= 2.05e-49) {
tmp = fma(b, a, (x * y));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(b, a, Float64(t * z)) tmp = 0.0 if (Float64(t * z) <= -2.5e-16) tmp = t_1; elseif (Float64(t * z) <= 2.05e-49) tmp = fma(b, a, 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[(t * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t * z), $MachinePrecision], -2.5e-16], t$95$1, If[LessEqual[N[(t * z), $MachinePrecision], 2.05e-49], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{if}\;t \cdot z \leq -2.5 \cdot 10^{-16}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \cdot z \leq 2.05 \cdot 10^{-49}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 z t) < -2.5000000000000002e-16 or 2.0500000000000001e-49 < (*.f64 z t) Initial program 95.1%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6484.0
Applied rewrites84.0%
if -2.5000000000000002e-16 < (*.f64 z t) < 2.0500000000000001e-49Initial program 100.0%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6492.3
Applied rewrites92.3%
Final simplification87.6%
(FPCore (x y z t a b) :precision binary64 (if (<= (* t z) -5.4e+130) (* t z) (if (<= (* t z) 6.5e+86) (fma b a (* x y)) (* t z))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((t * z) <= -5.4e+130) {
tmp = t * z;
} else if ((t * z) <= 6.5e+86) {
tmp = fma(b, a, (x * y));
} else {
tmp = t * z;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(t * z) <= -5.4e+130) tmp = Float64(t * z); elseif (Float64(t * z) <= 6.5e+86) tmp = fma(b, a, Float64(x * y)); else tmp = Float64(t * z); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(t * z), $MachinePrecision], -5.4e+130], N[(t * z), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 6.5e+86], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(t * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \cdot z \leq -5.4 \cdot 10^{+130}:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;t \cdot z \leq 6.5 \cdot 10^{+86}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot z\\
\end{array}
\end{array}
if (*.f64 z t) < -5.3999999999999997e130 or 6.49999999999999996e86 < (*.f64 z t) Initial program 94.2%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f6473.1
Applied rewrites73.1%
if -5.3999999999999997e130 < (*.f64 z t) < 6.49999999999999996e86Initial program 98.8%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6481.9
Applied rewrites81.9%
Final simplification78.9%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -4e+37) (* a b) (if (<= (* a b) 4e+83) (* t z) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -4e+37) {
tmp = a * b;
} else if ((a * b) <= 4e+83) {
tmp = t * z;
} 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) <= (-4d+37)) then
tmp = a * b
else if ((a * b) <= 4d+83) then
tmp = t * z
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) <= -4e+37) {
tmp = a * b;
} else if ((a * b) <= 4e+83) {
tmp = t * z;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -4e+37: tmp = a * b elif (a * b) <= 4e+83: tmp = t * z else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -4e+37) tmp = Float64(a * b); elseif (Float64(a * b) <= 4e+83) tmp = Float64(t * z); 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) <= -4e+37) tmp = a * b; elseif ((a * b) <= 4e+83) tmp = t * z; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -4e+37], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 4e+83], N[(t * z), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -4 \cdot 10^{+37}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 4 \cdot 10^{+83}:\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -3.99999999999999982e37 or 4.00000000000000012e83 < (*.f64 a b) Initial program 95.1%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6469.8
Applied rewrites69.8%
if -3.99999999999999982e37 < (*.f64 a b) < 4.00000000000000012e83Initial program 99.2%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f6458.0
Applied rewrites58.0%
Final simplification63.7%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -2e+46) (* x y) (if (<= (* x y) 2e+93) (* a b) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -2e+46) {
tmp = x * y;
} else if ((x * y) <= 2e+93) {
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) :: tmp
if ((x * y) <= (-2d+46)) then
tmp = x * y
else if ((x * y) <= 2d+93) 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 tmp;
if ((x * y) <= -2e+46) {
tmp = x * y;
} else if ((x * y) <= 2e+93) {
tmp = a * b;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -2e+46: tmp = x * y elif (x * y) <= 2e+93: tmp = a * b else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -2e+46) tmp = Float64(x * y); elseif (Float64(x * y) <= 2e+93) tmp = Float64(a * b); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((x * y) <= -2e+46) tmp = x * y; elseif ((x * y) <= 2e+93) tmp = a * b; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -2e+46], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2e+93], N[(a * b), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{+46}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+93}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -2e46 or 2.00000000000000009e93 < (*.f64 x y) Initial program 93.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6469.2
Applied rewrites69.2%
if -2e46 < (*.f64 x y) < 2.00000000000000009e93Initial program 99.3%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6449.2
Applied rewrites49.2%
Final simplification56.8%
(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.2%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6436.7
Applied rewrites36.7%
Final simplification36.7%
herbie shell --seed 2024255
(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)))