
(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 97.3%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f6499.2
Applied egg-rr99.2%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -15200.0) (* a b) (if (<= (* a b) 4e-289) (* y x) (if (<= (* a b) 1e+69) (* z t) (* a b)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -15200.0) {
tmp = a * b;
} else if ((a * b) <= 4e-289) {
tmp = y * x;
} else if ((a * b) <= 1e+69) {
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) <= (-15200.0d0)) then
tmp = a * b
else if ((a * b) <= 4d-289) then
tmp = y * x
else if ((a * b) <= 1d+69) 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) <= -15200.0) {
tmp = a * b;
} else if ((a * b) <= 4e-289) {
tmp = y * x;
} else if ((a * b) <= 1e+69) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -15200.0: tmp = a * b elif (a * b) <= 4e-289: tmp = y * x elif (a * b) <= 1e+69: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -15200.0) tmp = Float64(a * b); elseif (Float64(a * b) <= 4e-289) tmp = Float64(y * x); elseif (Float64(a * b) <= 1e+69) 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) <= -15200.0) tmp = a * b; elseif ((a * b) <= 4e-289) tmp = y * x; elseif ((a * b) <= 1e+69) 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], -15200.0], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 4e-289], N[(y * x), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1e+69], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -15200:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 4 \cdot 10^{-289}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;a \cdot b \leq 10^{+69}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -15200 or 1.0000000000000001e69 < (*.f64 a b) Initial program 95.4%
Taylor expanded in a around inf
lower-*.f6470.6
Simplified70.6%
if -15200 < (*.f64 a b) < 4e-289Initial program 97.6%
Taylor expanded in x around inf
lower-*.f6459.5
Simplified59.5%
if 4e-289 < (*.f64 a b) < 1.0000000000000001e69Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6450.0
Simplified50.0%
Final simplification61.8%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma a b (* z t))))
(if (<= (* z t) -4e+111)
t_1
(if (<= (* z t) 2e+29) (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(a, b, (z * t));
double tmp;
if ((z * t) <= -4e+111) {
tmp = t_1;
} else if ((z * t) <= 2e+29) {
tmp = fma(y, x, (a * b));
} 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+111) tmp = t_1; elseif (Float64(z * t) <= 2e+29) 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[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -4e+111], t$95$1, If[LessEqual[N[(z * t), $MachinePrecision], 2e+29], N[(y * x + N[(a * b), $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^{+111}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+29}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 z t) < -3.99999999999999983e111 or 1.99999999999999983e29 < (*.f64 z t) Initial program 95.9%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6490.2
Simplified90.2%
if -3.99999999999999983e111 < (*.f64 z t) < 1.99999999999999983e29Initial program 98.1%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f6499.4
Applied egg-rr99.4%
Taylor expanded in z around 0
lower-*.f6491.0
Simplified91.0%
Final simplification90.7%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma a b (* z t))))
(if (<= (* z t) -4e+111)
t_1
(if (<= (* z t) 2e+29) (fma a b (* y x)) 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+111) {
tmp = t_1;
} else if ((z * t) <= 2e+29) {
tmp = fma(a, b, (y * x));
} 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+111) tmp = t_1; elseif (Float64(z * t) <= 2e+29) tmp = fma(a, b, Float64(y * x)); 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+111], t$95$1, If[LessEqual[N[(z * t), $MachinePrecision], 2e+29], N[(a * b + N[(y * x), $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^{+111}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+29}:\\
\;\;\;\;\mathsf{fma}\left(a, b, y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 z t) < -3.99999999999999983e111 or 1.99999999999999983e29 < (*.f64 z t) Initial program 95.9%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6490.2
Simplified90.2%
if -3.99999999999999983e111 < (*.f64 z t) < 1.99999999999999983e29Initial program 98.1%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6490.4
Simplified90.4%
Final simplification90.3%
(FPCore (x y z t a b) :precision binary64 (if (<= (* y x) -7.4e+110) (* y x) (if (<= (* y x) 2.9e+115) (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) <= -7.4e+110) {
tmp = y * x;
} else if ((y * x) <= 2.9e+115) {
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) <= -7.4e+110) tmp = Float64(y * x); elseif (Float64(y * x) <= 2.9e+115) 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], -7.4e+110], N[(y * x), $MachinePrecision], If[LessEqual[N[(y * x), $MachinePrecision], 2.9e+115], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot x \leq -7.4 \cdot 10^{+110}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \cdot x \leq 2.9 \cdot 10^{+115}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (*.f64 x y) < -7.40000000000000024e110 or 2.90000000000000005e115 < (*.f64 x y) Initial program 93.0%
Taylor expanded in x around inf
lower-*.f6477.3
Simplified77.3%
if -7.40000000000000024e110 < (*.f64 x y) < 2.90000000000000005e115Initial program 99.4%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6485.9
Simplified85.9%
Final simplification83.0%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -7e+39) (* a b) (if (<= (* a b) 1e+69) (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -7e+39) {
tmp = a * b;
} else if ((a * b) <= 1e+69) {
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) <= (-7d+39)) then
tmp = a * b
else if ((a * b) <= 1d+69) 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) <= -7e+39) {
tmp = a * b;
} else if ((a * b) <= 1e+69) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -7e+39: tmp = a * b elif (a * b) <= 1e+69: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -7e+39) tmp = Float64(a * b); elseif (Float64(a * b) <= 1e+69) 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) <= -7e+39) tmp = a * b; elseif ((a * b) <= 1e+69) 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], -7e+39], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1e+69], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -7 \cdot 10^{+39}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 10^{+69}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -7.0000000000000003e39 or 1.0000000000000001e69 < (*.f64 a b) Initial program 95.0%
Taylor expanded in a around inf
lower-*.f6474.3
Simplified74.3%
if -7.0000000000000003e39 < (*.f64 a b) < 1.0000000000000001e69Initial program 98.7%
Taylor expanded in z around inf
lower-*.f6445.6
Simplified45.6%
Final simplification56.9%
(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 97.3%
Taylor expanded in a around inf
lower-*.f6437.1
Simplified37.1%
herbie shell --seed 2024207
(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)))