
(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 y x (fma z t (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(y, x, fma(z, t, (a * b)));
}
function code(x, y, z, t, a, b) return fma(y, x, fma(z, t, Float64(a * b))) end
code[x_, y_, z_, t_, a_, b_] := N[(y * x + N[(z * t + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(z, t, a \cdot b\right)\right)
\end{array}
Initial program 98.0%
associate-+l+N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* a b) -1e+31)
(* a b)
(if (<= (* a b) -2e-175)
(* y x)
(if (<= (* a b) 50000000.0)
(* z t)
(if (<= (* a b) 2e+71) (* y x) (* a b))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -1e+31) {
tmp = a * b;
} else if ((a * b) <= -2e-175) {
tmp = y * x;
} else if ((a * b) <= 50000000.0) {
tmp = z * t;
} else if ((a * b) <= 2e+71) {
tmp = y * x;
} 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) <= (-1d+31)) then
tmp = a * b
else if ((a * b) <= (-2d-175)) then
tmp = y * x
else if ((a * b) <= 50000000.0d0) then
tmp = z * t
else if ((a * b) <= 2d+71) then
tmp = y * x
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) <= -1e+31) {
tmp = a * b;
} else if ((a * b) <= -2e-175) {
tmp = y * x;
} else if ((a * b) <= 50000000.0) {
tmp = z * t;
} else if ((a * b) <= 2e+71) {
tmp = y * x;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -1e+31: tmp = a * b elif (a * b) <= -2e-175: tmp = y * x elif (a * b) <= 50000000.0: tmp = z * t elif (a * b) <= 2e+71: tmp = y * x else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -1e+31) tmp = Float64(a * b); elseif (Float64(a * b) <= -2e-175) tmp = Float64(y * x); elseif (Float64(a * b) <= 50000000.0) tmp = Float64(z * t); elseif (Float64(a * b) <= 2e+71) tmp = Float64(y * x); 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) <= -1e+31) tmp = a * b; elseif ((a * b) <= -2e-175) tmp = y * x; elseif ((a * b) <= 50000000.0) tmp = z * t; elseif ((a * b) <= 2e+71) tmp = y * x; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -1e+31], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -2e-175], N[(y * x), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 50000000.0], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2e+71], N[(y * x), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+31}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq -2 \cdot 10^{-175}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;a \cdot b \leq 50000000:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{+71}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -9.9999999999999996e30 or 2.0000000000000001e71 < (*.f64 a b) Initial program 95.7%
Taylor expanded in a around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6470.5
Simplified70.5%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6470.5
Applied egg-rr70.5%
if -9.9999999999999996e30 < (*.f64 a b) < -2e-175 or 5e7 < (*.f64 a b) < 2.0000000000000001e71Initial program 100.0%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6458.0
Simplified58.0%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6458.0
Applied egg-rr58.0%
if -2e-175 < (*.f64 a b) < 5e7Initial program 99.0%
Taylor expanded in z around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6456.0
Simplified56.0%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6456.0
Applied egg-rr56.0%
Final simplification61.7%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -1e+31) (fma a b (* z t)) (if (<= (* a b) 50000000.0) (fma y x (* z t)) (fma y x (* a b)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -1e+31) {
tmp = fma(a, b, (z * t));
} else if ((a * b) <= 50000000.0) {
tmp = fma(y, x, (z * t));
} else {
tmp = fma(y, x, (a * b));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -1e+31) tmp = fma(a, b, Float64(z * t)); elseif (Float64(a * b) <= 50000000.0) tmp = fma(y, x, Float64(z * t)); else tmp = fma(y, x, Float64(a * b)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -1e+31], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 50000000.0], N[(y * x + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+31}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{elif}\;a \cdot b \leq 50000000:\\
\;\;\;\;\mathsf{fma}\left(y, x, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\end{array}
\end{array}
if (*.f64 a b) < -9.9999999999999996e30Initial program 92.7%
Taylor expanded in x around 0
accelerator-lowering-fma.f64N/A
+-rgt-identityN/A
accelerator-lowering-fma.f6485.6
Simplified85.6%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6485.6
Applied egg-rr85.6%
if -9.9999999999999996e30 < (*.f64 a b) < 5e7Initial program 99.3%
associate-+l+N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
Taylor expanded in z around inf
*-lowering-*.f6491.3
Simplified91.3%
if 5e7 < (*.f64 a b) Initial program 98.4%
associate-+l+N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
Taylor expanded in z around 0
*-lowering-*.f6490.6
Simplified90.6%
Final simplification90.2%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma y x (* a b)))) (if (<= (* y x) -4e+51) t_1 (if (<= (* y x) 1e+51) (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(y, x, (a * b));
double tmp;
if ((y * x) <= -4e+51) {
tmp = t_1;
} else if ((y * x) <= 1e+51) {
tmp = fma(a, b, (z * t));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(y, x, Float64(a * b)) tmp = 0.0 if (Float64(y * x) <= -4e+51) tmp = t_1; elseif (Float64(y * x) <= 1e+51) 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[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * x), $MachinePrecision], -4e+51], t$95$1, If[LessEqual[N[(y * x), $MachinePrecision], 1e+51], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{if}\;y \cdot x \leq -4 \cdot 10^{+51}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \cdot x \leq 10^{+51}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -4e51 or 1e51 < (*.f64 x y) Initial program 95.4%
associate-+l+N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
Taylor expanded in z around 0
*-lowering-*.f6485.7
Simplified85.7%
if -4e51 < (*.f64 x y) < 1e51Initial program 100.0%
Taylor expanded in x around 0
accelerator-lowering-fma.f64N/A
+-rgt-identityN/A
accelerator-lowering-fma.f6489.0
Simplified89.0%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6489.0
Applied egg-rr89.0%
Final simplification87.6%
(FPCore (x y z t a b) :precision binary64 (if (<= (* y x) -2e+227) (* y x) (if (<= (* y x) 1e+51) (fma a b (* z t)) (* y x))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((y * x) <= -2e+227) {
tmp = y * x;
} else if ((y * x) <= 1e+51) {
tmp = fma(a, b, (z * t));
} else {
tmp = y * x;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(y * x) <= -2e+227) tmp = Float64(y * x); elseif (Float64(y * x) <= 1e+51) tmp = fma(a, b, Float64(z * t)); else tmp = Float64(y * x); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(y * x), $MachinePrecision], -2e+227], N[(y * x), $MachinePrecision], If[LessEqual[N[(y * x), $MachinePrecision], 1e+51], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot x \leq -2 \cdot 10^{+227}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \cdot x \leq 10^{+51}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (*.f64 x y) < -2.0000000000000002e227 or 1e51 < (*.f64 x y) Initial program 94.0%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6474.8
Simplified74.8%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6474.8
Applied egg-rr74.8%
if -2.0000000000000002e227 < (*.f64 x y) < 1e51Initial program 100.0%
Taylor expanded in x around 0
accelerator-lowering-fma.f64N/A
+-rgt-identityN/A
accelerator-lowering-fma.f6483.0
Simplified83.0%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6483.0
Applied egg-rr83.0%
Final simplification80.3%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -1e+31) (* a b) (if (<= (* a b) 2e+71) (* y x) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -1e+31) {
tmp = a * b;
} else if ((a * b) <= 2e+71) {
tmp = y * x;
} 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) <= (-1d+31)) then
tmp = a * b
else if ((a * b) <= 2d+71) then
tmp = y * x
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) <= -1e+31) {
tmp = a * b;
} else if ((a * b) <= 2e+71) {
tmp = y * x;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -1e+31: tmp = a * b elif (a * b) <= 2e+71: tmp = y * x else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -1e+31) tmp = Float64(a * b); elseif (Float64(a * b) <= 2e+71) tmp = Float64(y * x); 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) <= -1e+31) tmp = a * b; elseif ((a * b) <= 2e+71) tmp = y * x; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -1e+31], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2e+71], N[(y * x), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+31}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{+71}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -9.9999999999999996e30 or 2.0000000000000001e71 < (*.f64 a b) Initial program 95.7%
Taylor expanded in a around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6470.5
Simplified70.5%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6470.5
Applied egg-rr70.5%
if -9.9999999999999996e30 < (*.f64 a b) < 2.0000000000000001e71Initial program 99.3%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6448.1
Simplified48.1%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6448.1
Applied egg-rr48.1%
Final simplification56.3%
(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.0%
Taylor expanded in a around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6433.3
Simplified33.3%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6433.3
Applied egg-rr33.3%
Final simplification33.3%
herbie shell --seed 2024195
(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)))