
(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 (* 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 96.1%
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%
Final simplification99.2%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* a b) -2e+73)
(* a b)
(if (<= (* a b) 2e-165)
(* t z)
(if (<= (* a b) 5e-47)
(* x y)
(if (<= (* a b) 1e+103) (* t z) (* a b))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -2e+73) {
tmp = a * b;
} else if ((a * b) <= 2e-165) {
tmp = t * z;
} else if ((a * b) <= 5e-47) {
tmp = x * y;
} else if ((a * b) <= 1e+103) {
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) <= (-2d+73)) then
tmp = a * b
else if ((a * b) <= 2d-165) then
tmp = t * z
else if ((a * b) <= 5d-47) then
tmp = x * y
else if ((a * b) <= 1d+103) 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) <= -2e+73) {
tmp = a * b;
} else if ((a * b) <= 2e-165) {
tmp = t * z;
} else if ((a * b) <= 5e-47) {
tmp = x * y;
} else if ((a * b) <= 1e+103) {
tmp = t * z;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -2e+73: tmp = a * b elif (a * b) <= 2e-165: tmp = t * z elif (a * b) <= 5e-47: tmp = x * y elif (a * b) <= 1e+103: tmp = t * z else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -2e+73) tmp = Float64(a * b); elseif (Float64(a * b) <= 2e-165) tmp = Float64(t * z); elseif (Float64(a * b) <= 5e-47) tmp = Float64(x * y); elseif (Float64(a * b) <= 1e+103) 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) <= -2e+73) tmp = a * b; elseif ((a * b) <= 2e-165) tmp = t * z; elseif ((a * b) <= 5e-47) tmp = x * y; elseif ((a * b) <= 1e+103) 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], -2e+73], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2e-165], N[(t * z), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 5e-47], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1e+103], N[(t * z), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+73}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{-165}:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;a \cdot b \leq 5 \cdot 10^{-47}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq 10^{+103}:\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -1.99999999999999997e73 or 1e103 < (*.f64 a b) Initial program 93.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6490.0
Applied rewrites90.0%
Taylor expanded in x around 0
Applied rewrites73.8%
if -1.99999999999999997e73 < (*.f64 a b) < 2e-165 or 5.00000000000000011e-47 < (*.f64 a b) < 1e103Initial program 97.5%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6461.3
Applied rewrites61.3%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6490.0
Applied rewrites90.0%
Taylor expanded in x around 0
Applied rewrites53.4%
if 2e-165 < (*.f64 a b) < 5.00000000000000011e-47Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6443.6
Applied rewrites43.6%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6477.3
Applied rewrites77.3%
Taylor expanded in x around 0
Applied rewrites22.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6457.3
Applied rewrites57.3%
Final simplification62.1%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma b a (* x y))))
(if (<= (* a b) -2e+73)
t_1
(if (<= (* a b) 1e+103) (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) <= -2e+73) {
tmp = t_1;
} else if ((a * b) <= 1e+103) {
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) <= -2e+73) tmp = t_1; elseif (Float64(a * b) <= 1e+103) 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], -2e+73], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 1e+103], 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 -2 \cdot 10^{+73}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \cdot b \leq 10^{+103}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 a b) < -1.99999999999999997e73 or 1e103 < (*.f64 a b) Initial program 93.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6490.0
Applied rewrites90.0%
if -1.99999999999999997e73 < (*.f64 a b) < 1e103Initial program 98.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6458.0
Applied rewrites58.0%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6487.6
Applied rewrites87.6%
Final simplification88.5%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma b a (* x y))))
(if (<= (* x y) -2e+34)
t_1
(if (<= (* x y) 1e+119) (fma b a (* 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 ((x * y) <= -2e+34) {
tmp = t_1;
} else if ((x * y) <= 1e+119) {
tmp = fma(b, a, (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(x * y) <= -2e+34) tmp = t_1; elseif (Float64(x * y) <= 1e+119) tmp = fma(b, a, 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[(x * y), $MachinePrecision], -2e+34], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 1e+119], N[(b * a + 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}\;x \cdot y \leq -2 \cdot 10^{+34}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 10^{+119}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -1.99999999999999989e34 or 9.99999999999999944e118 < (*.f64 x y) Initial program 94.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6486.2
Applied rewrites86.2%
if -1.99999999999999989e34 < (*.f64 x y) < 9.99999999999999944e118Initial program 97.3%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6488.2
Applied rewrites88.2%
Final simplification87.4%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -5e+86) (* x y) (if (<= (* x y) 1e+158) (fma b a (* t z)) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -5e+86) {
tmp = x * y;
} else if ((x * y) <= 1e+158) {
tmp = fma(b, a, (t * z));
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -5e+86) tmp = Float64(x * y); elseif (Float64(x * y) <= 1e+158) tmp = fma(b, a, Float64(t * z)); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -5e+86], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1e+158], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+86}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 10^{+158}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -4.9999999999999998e86 or 9.99999999999999953e157 < (*.f64 x y) Initial program 93.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6431.0
Applied rewrites31.0%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6484.2
Applied rewrites84.2%
Taylor expanded in x around 0
Applied rewrites15.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6475.2
Applied rewrites75.2%
if -4.9999999999999998e86 < (*.f64 x y) < 9.99999999999999953e157Initial program 97.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6485.0
Applied rewrites85.0%
Final simplification81.7%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -2e+73) (* a b) (if (<= (* a b) 1e+103) (* t z) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -2e+73) {
tmp = a * b;
} else if ((a * b) <= 1e+103) {
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) <= (-2d+73)) then
tmp = a * b
else if ((a * b) <= 1d+103) 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) <= -2e+73) {
tmp = a * b;
} else if ((a * b) <= 1e+103) {
tmp = t * z;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -2e+73: tmp = a * b elif (a * b) <= 1e+103: tmp = t * z else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -2e+73) tmp = Float64(a * b); elseif (Float64(a * b) <= 1e+103) 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) <= -2e+73) tmp = a * b; elseif ((a * b) <= 1e+103) 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], -2e+73], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1e+103], N[(t * z), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+73}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 10^{+103}:\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -1.99999999999999997e73 or 1e103 < (*.f64 a b) Initial program 93.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6490.0
Applied rewrites90.0%
Taylor expanded in x around 0
Applied rewrites73.8%
if -1.99999999999999997e73 < (*.f64 a b) < 1e103Initial program 98.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6458.0
Applied rewrites58.0%
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 rewrites47.6%
Final simplification58.2%
(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 96.1%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6468.5
Applied rewrites68.5%
Taylor expanded in x around 0
Applied rewrites37.3%
Final simplification37.3%
herbie shell --seed 2024295
(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)))