
(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 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.f6499.2
Applied rewrites99.2%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* z t) -2e+75)
(* z t)
(if (<= (* z t) -5e-62)
(* a b)
(if (<= (* z t) -1e-128)
(* x y)
(if (<= (* z t) 2.0)
(* a b)
(if (<= (* z t) 2e+81) (* x y) (* z t)))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -2e+75) {
tmp = z * t;
} else if ((z * t) <= -5e-62) {
tmp = a * b;
} else if ((z * t) <= -1e-128) {
tmp = x * y;
} else if ((z * t) <= 2.0) {
tmp = a * b;
} else if ((z * t) <= 2e+81) {
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) <= (-2d+75)) then
tmp = z * t
else if ((z * t) <= (-5d-62)) then
tmp = a * b
else if ((z * t) <= (-1d-128)) then
tmp = x * y
else if ((z * t) <= 2.0d0) then
tmp = a * b
else if ((z * t) <= 2d+81) 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) <= -2e+75) {
tmp = z * t;
} else if ((z * t) <= -5e-62) {
tmp = a * b;
} else if ((z * t) <= -1e-128) {
tmp = x * y;
} else if ((z * t) <= 2.0) {
tmp = a * b;
} else if ((z * t) <= 2e+81) {
tmp = x * y;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z * t) <= -2e+75: tmp = z * t elif (z * t) <= -5e-62: tmp = a * b elif (z * t) <= -1e-128: tmp = x * y elif (z * t) <= 2.0: tmp = a * b elif (z * t) <= 2e+81: tmp = x * y else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -2e+75) tmp = Float64(z * t); elseif (Float64(z * t) <= -5e-62) tmp = Float64(a * b); elseif (Float64(z * t) <= -1e-128) tmp = Float64(x * y); elseif (Float64(z * t) <= 2.0) tmp = Float64(a * b); elseif (Float64(z * t) <= 2e+81) 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) <= -2e+75) tmp = z * t; elseif ((z * t) <= -5e-62) tmp = a * b; elseif ((z * t) <= -1e-128) tmp = x * y; elseif ((z * t) <= 2.0) tmp = a * b; elseif ((z * t) <= 2e+81) 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], -2e+75], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], -5e-62], N[(a * b), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], -1e-128], N[(x * y), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 2.0], N[(a * b), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 2e+81], N[(x * y), $MachinePrecision], N[(z * t), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+75}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq -5 \cdot 10^{-62}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;z \cdot t \leq -1 \cdot 10^{-128}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;z \cdot t \leq 2:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+81}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -1.99999999999999985e75 or 1.99999999999999984e81 < (*.f64 z t) Initial program 97.8%
Taylor expanded in z around inf
lower-*.f6469.4
Applied rewrites69.4%
if -1.99999999999999985e75 < (*.f64 z t) < -5.0000000000000002e-62 or -1.00000000000000005e-128 < (*.f64 z t) < 2Initial program 99.1%
Taylor expanded in a around inf
lower-*.f6459.8
Applied rewrites59.8%
if -5.0000000000000002e-62 < (*.f64 z t) < -1.00000000000000005e-128 or 2 < (*.f64 z t) < 1.99999999999999984e81Initial program 97.4%
Taylor expanded in x around inf
lower-*.f6462.8
Applied rewrites62.8%
Final simplification63.8%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma t z (* x y))))
(if (<= (* x y) -2500000000.0)
t_1
(if (<= (* x y) 1.85e+22) (fma a b (* z t)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(t, z, (x * y));
double tmp;
if ((x * y) <= -2500000000.0) {
tmp = t_1;
} else if ((x * y) <= 1.85e+22) {
tmp = fma(a, b, (z * t));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(t, z, Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -2500000000.0) tmp = t_1; elseif (Float64(x * y) <= 1.85e+22) tmp = fma(a, b, Float64(z * t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -2500000000.0], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 1.85e+22], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(t, z, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -2500000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 1.85 \cdot 10^{+22}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -2.5e9 or 1.8499999999999999e22 < (*.f64 x y) Initial program 97.6%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-*.f6483.3
Applied rewrites83.3%
if -2.5e9 < (*.f64 x y) < 1.8499999999999999e22Initial program 99.2%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6496.3
Applied rewrites96.3%
Final simplification89.8%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma a b (* x y))))
(if (<= (* x y) -2.3e+171)
t_1
(if (<= (* x y) 1.15e+73) (fma a b (* z t)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(a, b, (x * y));
double tmp;
if ((x * y) <= -2.3e+171) {
tmp = t_1;
} else if ((x * y) <= 1.15e+73) {
tmp = fma(a, b, (z * t));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(a, b, Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -2.3e+171) tmp = t_1; elseif (Float64(x * y) <= 1.15e+73) tmp = fma(a, b, Float64(z * t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -2.3e+171], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 1.15e+73], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -2.3 \cdot 10^{+171}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 1.15 \cdot 10^{+73}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -2.30000000000000017e171 or 1.15e73 < (*.f64 x y) Initial program 96.6%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6486.5
Applied rewrites86.5%
if -2.30000000000000017e171 < (*.f64 x y) < 1.15e73Initial program 99.4%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6489.6
Applied rewrites89.6%
Final simplification88.5%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -1e+184) (* x y) (if (<= (* x y) 1.55e+206) (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) <= -1e+184) {
tmp = x * y;
} else if ((x * y) <= 1.55e+206) {
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) <= -1e+184) tmp = Float64(x * y); elseif (Float64(x * y) <= 1.55e+206) 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], -1e+184], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1.55e+206], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+184}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 1.55 \cdot 10^{+206}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -1.00000000000000002e184 or 1.54999999999999995e206 < (*.f64 x y) Initial program 95.2%
Taylor expanded in x around inf
lower-*.f6488.0
Applied rewrites88.0%
if -1.00000000000000002e184 < (*.f64 x y) < 1.54999999999999995e206Initial program 99.4%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6485.0
Applied rewrites85.0%
Final simplification85.7%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -2e+75) (* z t) (if (<= (* z t) 5e+29) (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -2e+75) {
tmp = z * t;
} else if ((z * t) <= 5e+29) {
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) <= (-2d+75)) then
tmp = z * t
else if ((z * t) <= 5d+29) 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) <= -2e+75) {
tmp = z * t;
} else if ((z * t) <= 5e+29) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z * t) <= -2e+75: tmp = z * t elif (z * t) <= 5e+29: tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -2e+75) tmp = Float64(z * t); elseif (Float64(z * t) <= 5e+29) 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) <= -2e+75) tmp = z * t; elseif ((z * t) <= 5e+29) 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], -2e+75], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 5e+29], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+75}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+29}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -1.99999999999999985e75 or 5.0000000000000001e29 < (*.f64 z t) Initial program 97.2%
Taylor expanded in z around inf
lower-*.f6465.2
Applied rewrites65.2%
if -1.99999999999999985e75 < (*.f64 z t) < 5.0000000000000001e29Initial program 99.3%
Taylor expanded in a around inf
lower-*.f6453.7
Applied rewrites53.7%
Final simplification58.6%
(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-*.f6437.8
Applied rewrites37.8%
herbie shell --seed 2024216
(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)))