
(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 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.8%
+-commutativeN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6499.6
Applied egg-rr99.6%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* a b) -2e+127)
(* a b)
(if (<= (* a b) -4e+45)
(* z t)
(if (<= (* a b) 1e-181)
(* x y)
(if (<= (* a b) 5e+122) (* z t) (* a b))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -2e+127) {
tmp = a * b;
} else if ((a * b) <= -4e+45) {
tmp = z * t;
} else if ((a * b) <= 1e-181) {
tmp = x * y;
} else if ((a * b) <= 5e+122) {
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) <= (-2d+127)) then
tmp = a * b
else if ((a * b) <= (-4d+45)) then
tmp = z * t
else if ((a * b) <= 1d-181) then
tmp = x * y
else if ((a * b) <= 5d+122) 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) <= -2e+127) {
tmp = a * b;
} else if ((a * b) <= -4e+45) {
tmp = z * t;
} else if ((a * b) <= 1e-181) {
tmp = x * y;
} else if ((a * b) <= 5e+122) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -2e+127: tmp = a * b elif (a * b) <= -4e+45: tmp = z * t elif (a * b) <= 1e-181: tmp = x * y elif (a * b) <= 5e+122: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -2e+127) tmp = Float64(a * b); elseif (Float64(a * b) <= -4e+45) tmp = Float64(z * t); elseif (Float64(a * b) <= 1e-181) tmp = Float64(x * y); elseif (Float64(a * b) <= 5e+122) 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) <= -2e+127) tmp = a * b; elseif ((a * b) <= -4e+45) tmp = z * t; elseif ((a * b) <= 1e-181) tmp = x * y; elseif ((a * b) <= 5e+122) 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], -2e+127], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -4e+45], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1e-181], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 5e+122], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+127}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq -4 \cdot 10^{+45}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 10^{-181}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq 5 \cdot 10^{+122}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -1.99999999999999991e127 or 4.99999999999999989e122 < (*.f64 a b) Initial program 96.8%
Taylor expanded in a around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6478.0
Simplified78.0%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6478.0
Applied egg-rr78.0%
if -1.99999999999999991e127 < (*.f64 a b) < -3.9999999999999997e45 or 1.00000000000000005e-181 < (*.f64 a b) < 4.99999999999999989e122Initial program 100.0%
Taylor expanded in z around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6452.6
Simplified52.6%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6452.6
Applied egg-rr52.6%
if -3.9999999999999997e45 < (*.f64 a b) < 1.00000000000000005e-181Initial program 100.0%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6457.6
Simplified57.6%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6457.6
Applied egg-rr57.6%
Final simplification63.8%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -0.005) (fma z t (* a b)) (if (<= (* z t) 1e+107) (fma y x (* a b)) (fma z t (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -0.005) {
tmp = fma(z, t, (a * b));
} else if ((z * t) <= 1e+107) {
tmp = fma(y, x, (a * b));
} else {
tmp = fma(z, t, (x * y));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -0.005) tmp = fma(z, t, Float64(a * b)); elseif (Float64(z * t) <= 1e+107) tmp = fma(y, x, Float64(a * b)); else tmp = fma(z, t, Float64(x * y)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -0.005], N[(z * t + N[(a * b), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 1e+107], N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision], N[(z * t + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -0.005:\\
\;\;\;\;\mathsf{fma}\left(z, t, a \cdot b\right)\\
\mathbf{elif}\;z \cdot t \leq 10^{+107}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, t, x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 z t) < -0.0050000000000000001Initial program 100.0%
+-commutativeN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
*-lowering-*.f6488.6
Simplified88.6%
if -0.0050000000000000001 < (*.f64 z t) < 9.9999999999999997e106Initial program 98.7%
+-commutativeN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6499.4
Applied egg-rr99.4%
Taylor expanded in z around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6490.2
Simplified90.2%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6490.2
Applied egg-rr90.2%
if 9.9999999999999997e106 < (*.f64 z t) Initial program 97.5%
+-commutativeN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
Taylor expanded in x around inf
*-lowering-*.f6497.5
Simplified97.5%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma z t (* a b)))) (if (<= (* z t) -0.005) t_1 (if (<= (* z t) 1e-28) (fma y x (* a b)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(z, t, (a * b));
double tmp;
if ((z * t) <= -0.005) {
tmp = t_1;
} else if ((z * t) <= 1e-28) {
tmp = fma(y, x, (a * b));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(z, t, Float64(a * b)) tmp = 0.0 if (Float64(z * t) <= -0.005) tmp = t_1; elseif (Float64(z * t) <= 1e-28) tmp = fma(y, x, Float64(a * b)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(z * t + N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -0.005], t$95$1, If[LessEqual[N[(z * t), $MachinePrecision], 1e-28], N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(z, t, a \cdot b\right)\\
\mathbf{if}\;z \cdot t \leq -0.005:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \cdot t \leq 10^{-28}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 z t) < -0.0050000000000000001 or 9.99999999999999971e-29 < (*.f64 z t) Initial program 99.2%
+-commutativeN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
*-lowering-*.f6485.6
Simplified85.6%
if -0.0050000000000000001 < (*.f64 z t) < 9.99999999999999971e-29Initial program 98.5%
+-commutativeN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6499.2
Applied egg-rr99.2%
Taylor expanded in z around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6493.5
Simplified93.5%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6493.5
Applied egg-rr93.5%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -6.5e+78) (* z t) (if (<= (* z t) 5e+142) (fma y x (* a b)) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -6.5e+78) {
tmp = z * t;
} else if ((z * t) <= 5e+142) {
tmp = fma(y, x, (a * b));
} else {
tmp = z * t;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -6.5e+78) tmp = Float64(z * t); elseif (Float64(z * t) <= 5e+142) tmp = fma(y, x, Float64(a * b)); else tmp = Float64(z * t); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -6.5e+78], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 5e+142], N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision], N[(z * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -6.5 \cdot 10^{+78}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+142}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -6.50000000000000036e78 or 5.0000000000000001e142 < (*.f64 z t) Initial program 98.7%
Taylor expanded in z around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6477.5
Simplified77.5%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6477.5
Applied egg-rr77.5%
if -6.50000000000000036e78 < (*.f64 z t) < 5.0000000000000001e142Initial program 98.9%
+-commutativeN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6499.4
Applied egg-rr99.4%
Taylor expanded in z around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6486.6
Simplified86.6%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6486.6
Applied egg-rr86.6%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -6.5e+78) (* z t) (if (<= (* z t) 5e+142) (fma a b (* x y)) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -6.5e+78) {
tmp = z * t;
} else if ((z * t) <= 5e+142) {
tmp = fma(a, b, (x * y));
} else {
tmp = z * t;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -6.5e+78) tmp = Float64(z * t); elseif (Float64(z * t) <= 5e+142) tmp = fma(a, b, Float64(x * y)); else tmp = Float64(z * t); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -6.5e+78], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 5e+142], N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -6.5 \cdot 10^{+78}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+142}:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -6.50000000000000036e78 or 5.0000000000000001e142 < (*.f64 z t) Initial program 98.7%
Taylor expanded in z around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6477.5
Simplified77.5%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6477.5
Applied egg-rr77.5%
if -6.50000000000000036e78 < (*.f64 z t) < 5.0000000000000001e142Initial program 98.9%
+-commutativeN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6499.4
Applied egg-rr99.4%
Taylor expanded in z around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6486.6
Simplified86.6%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -1e+144) (* a b) (if (<= (* a b) 1e+117) (* x y) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -1e+144) {
tmp = a * b;
} else if ((a * b) <= 1e+117) {
tmp = x * y;
} 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+144)) then
tmp = a * b
else if ((a * b) <= 1d+117) then
tmp = x * y
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+144) {
tmp = a * b;
} else if ((a * b) <= 1e+117) {
tmp = x * y;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -1e+144: tmp = a * b elif (a * b) <= 1e+117: tmp = x * y else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -1e+144) tmp = Float64(a * b); elseif (Float64(a * b) <= 1e+117) tmp = Float64(x * y); 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+144) tmp = a * b; elseif ((a * b) <= 1e+117) tmp = x * y; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -1e+144], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1e+117], N[(x * y), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+144}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 10^{+117}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -1.00000000000000002e144 or 1.00000000000000005e117 < (*.f64 a b) Initial program 96.7%
Taylor expanded in a around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6477.8
Simplified77.8%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6477.8
Applied egg-rr77.8%
if -1.00000000000000002e144 < (*.f64 a b) < 1.00000000000000005e117Initial program 100.0%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6449.5
Simplified49.5%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6449.5
Applied egg-rr49.5%
Final simplification59.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 98.8%
Taylor expanded in a around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6436.8
Simplified36.8%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6436.8
Applied egg-rr36.8%
Final simplification36.8%
herbie shell --seed 2024196
(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)))