
(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 96.9%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f6497.6
Applied rewrites97.6%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* a b) -3.2e+76)
(* a b)
(if (<= (* a b) -1600.0)
(* x y)
(if (<= (* a b) -1e-313)
(* z t)
(if (<= (* a b) 4.8e-107)
(* x y)
(if (<= (* a b) 1.3e-60) (* z t) (* a b)))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -3.2e+76) {
tmp = a * b;
} else if ((a * b) <= -1600.0) {
tmp = x * y;
} else if ((a * b) <= -1e-313) {
tmp = z * t;
} else if ((a * b) <= 4.8e-107) {
tmp = x * y;
} else if ((a * b) <= 1.3e-60) {
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) <= (-3.2d+76)) then
tmp = a * b
else if ((a * b) <= (-1600.0d0)) then
tmp = x * y
else if ((a * b) <= (-1d-313)) then
tmp = z * t
else if ((a * b) <= 4.8d-107) then
tmp = x * y
else if ((a * b) <= 1.3d-60) 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) <= -3.2e+76) {
tmp = a * b;
} else if ((a * b) <= -1600.0) {
tmp = x * y;
} else if ((a * b) <= -1e-313) {
tmp = z * t;
} else if ((a * b) <= 4.8e-107) {
tmp = x * y;
} else if ((a * b) <= 1.3e-60) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -3.2e+76: tmp = a * b elif (a * b) <= -1600.0: tmp = x * y elif (a * b) <= -1e-313: tmp = z * t elif (a * b) <= 4.8e-107: tmp = x * y elif (a * b) <= 1.3e-60: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -3.2e+76) tmp = Float64(a * b); elseif (Float64(a * b) <= -1600.0) tmp = Float64(x * y); elseif (Float64(a * b) <= -1e-313) tmp = Float64(z * t); elseif (Float64(a * b) <= 4.8e-107) tmp = Float64(x * y); elseif (Float64(a * b) <= 1.3e-60) 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) <= -3.2e+76) tmp = a * b; elseif ((a * b) <= -1600.0) tmp = x * y; elseif ((a * b) <= -1e-313) tmp = z * t; elseif ((a * b) <= 4.8e-107) tmp = x * y; elseif ((a * b) <= 1.3e-60) 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], -3.2e+76], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -1600.0], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -1e-313], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 4.8e-107], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.3e-60], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -3.2 \cdot 10^{+76}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq -1600:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq -1 \cdot 10^{-313}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 4.8 \cdot 10^{-107}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq 1.3 \cdot 10^{-60}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -3.19999999999999976e76 or 1.2999999999999999e-60 < (*.f64 a b) Initial program 95.5%
Taylor expanded in a around inf
lower-*.f6461.1
Applied rewrites61.1%
if -3.19999999999999976e76 < (*.f64 a b) < -1600 or -1.00000000001e-313 < (*.f64 a b) < 4.79999999999999989e-107Initial program 98.5%
Taylor expanded in x around inf
lower-*.f6475.1
Applied rewrites75.1%
if -1600 < (*.f64 a b) < -1.00000000001e-313 or 4.79999999999999989e-107 < (*.f64 a b) < 1.2999999999999999e-60Initial program 98.2%
Taylor expanded in z around inf
lower-*.f6460.5
Applied rewrites60.5%
Final simplification64.6%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -4e-84) (fma a b (* z t)) (if (<= (* z t) 0.1) (fma a b (* x y)) (fma t z (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -4e-84) {
tmp = fma(a, b, (z * t));
} else if ((z * t) <= 0.1) {
tmp = fma(a, b, (x * y));
} else {
tmp = fma(t, z, (x * y));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -4e-84) tmp = fma(a, b, Float64(z * t)); elseif (Float64(z * t) <= 0.1) tmp = fma(a, b, Float64(x * y)); else tmp = fma(t, z, Float64(x * y)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -4e-84], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 0.1], N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -4 \cdot 10^{-84}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{elif}\;z \cdot t \leq 0.1:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 z t) < -4.0000000000000001e-84Initial program 95.0%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6482.5
Applied rewrites82.5%
if -4.0000000000000001e-84 < (*.f64 z t) < 0.10000000000000001Initial program 98.4%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6497.0
Applied rewrites97.0%
if 0.10000000000000001 < (*.f64 z t) Initial program 96.0%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-*.f6482.5
Applied rewrites82.5%
Final simplification89.6%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma a b (* z t)))) (if (<= (* z t) -4e-84) t_1 (if (<= (* z t) 500.0) (fma a b (* x y)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(a, b, (z * t));
double tmp;
if ((z * t) <= -4e-84) {
tmp = t_1;
} else if ((z * t) <= 500.0) {
tmp = fma(a, b, (x * y));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(a, b, Float64(z * t)) tmp = 0.0 if (Float64(z * t) <= -4e-84) tmp = t_1; elseif (Float64(z * t) <= 500.0) tmp = fma(a, b, Float64(x * y)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -4e-84], t$95$1, If[LessEqual[N[(z * t), $MachinePrecision], 500.0], N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{if}\;z \cdot t \leq -4 \cdot 10^{-84}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \cdot t \leq 500:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 z t) < -4.0000000000000001e-84 or 500 < (*.f64 z t) Initial program 95.3%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6480.6
Applied rewrites80.6%
if -4.0000000000000001e-84 < (*.f64 z t) < 500Initial program 98.4%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6496.3
Applied rewrites96.3%
Final simplification88.4%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -9.5e+117) (* x y) (if (<= (* x y) 2.15e+98) (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) <= -9.5e+117) {
tmp = x * y;
} else if ((x * y) <= 2.15e+98) {
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) <= -9.5e+117) tmp = Float64(x * y); elseif (Float64(x * y) <= 2.15e+98) 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], -9.5e+117], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2.15e+98], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -9.5 \cdot 10^{+117}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 2.15 \cdot 10^{+98}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -9.50000000000000041e117 or 2.1500000000000001e98 < (*.f64 x y) Initial program 91.1%
Taylor expanded in x around inf
lower-*.f6477.3
Applied rewrites77.3%
if -9.50000000000000041e117 < (*.f64 x y) < 2.1500000000000001e98Initial program 100.0%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6486.1
Applied rewrites86.1%
Final simplification83.0%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -2e+113) (* z t) (if (<= (* z t) 0.1) (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -2e+113) {
tmp = z * t;
} else if ((z * t) <= 0.1) {
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+113)) then
tmp = z * t
else if ((z * t) <= 0.1d0) 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+113) {
tmp = z * t;
} else if ((z * t) <= 0.1) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z * t) <= -2e+113: tmp = z * t elif (z * t) <= 0.1: 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+113) tmp = Float64(z * t); elseif (Float64(z * t) <= 0.1) 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+113) tmp = z * t; elseif ((z * t) <= 0.1) 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+113], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 0.1], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+113}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq 0.1:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -2e113 or 0.10000000000000001 < (*.f64 z t) Initial program 93.6%
Taylor expanded in z around inf
lower-*.f6467.4
Applied rewrites67.4%
if -2e113 < (*.f64 z t) < 0.10000000000000001Initial program 98.7%
Taylor expanded in a around inf
lower-*.f6446.2
Applied rewrites46.2%
Final simplification54.0%
(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.9%
Taylor expanded in a around inf
lower-*.f6437.2
Applied rewrites37.2%
herbie shell --seed 2024221
(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)))