
(FPCore (x y z t) :precision binary64 (+ (* x y) (* z t)))
double code(double x, double y, double z, double t) {
return (x * y) + (z * t);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x * y) + (z * t)
end function
public static double code(double x, double y, double z, double t) {
return (x * y) + (z * t);
}
def code(x, y, z, t): return (x * y) + (z * t)
function code(x, y, z, t) return Float64(Float64(x * y) + Float64(z * t)) end
function tmp = code(x, y, z, t) tmp = (x * y) + (z * t); end
code[x_, y_, z_, t_] := N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot t
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ (* x y) (* z t)))
double code(double x, double y, double z, double t) {
return (x * y) + (z * t);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x * y) + (z * t)
end function
public static double code(double x, double y, double z, double t) {
return (x * y) + (z * t);
}
def code(x, y, z, t): return (x * y) + (z * t)
function code(x, y, z, t) return Float64(Float64(x * y) + Float64(z * t)) end
function tmp = code(x, y, z, t) tmp = (x * y) + (z * t); end
code[x_, y_, z_, t_] := N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot t
\end{array}
(FPCore (x y z t) :precision binary64 (fma y x (* t z)))
double code(double x, double y, double z, double t) {
return fma(y, x, (t * z));
}
function code(x, y, z, t) return fma(y, x, Float64(t * z)) end
code[x_, y_, z_, t_] := N[(y * x + N[(t * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, t \cdot z\right)
\end{array}
Initial program 98.4%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
(FPCore (x y z t) :precision binary64 (if (<= (* z t) -0.002) (* t z) (if (<= (* z t) 2e+59) (* y x) (fabs (* t z)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * t) <= -0.002) {
tmp = t * z;
} else if ((z * t) <= 2e+59) {
tmp = y * x;
} else {
tmp = fabs((t * z));
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((z * t) <= (-0.002d0)) then
tmp = t * z
else if ((z * t) <= 2d+59) then
tmp = y * x
else
tmp = abs((t * z))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * t) <= -0.002) {
tmp = t * z;
} else if ((z * t) <= 2e+59) {
tmp = y * x;
} else {
tmp = Math.abs((t * z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * t) <= -0.002: tmp = t * z elif (z * t) <= 2e+59: tmp = y * x else: tmp = math.fabs((t * z)) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * t) <= -0.002) tmp = Float64(t * z); elseif (Float64(z * t) <= 2e+59) tmp = Float64(y * x); else tmp = abs(Float64(t * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * t) <= -0.002) tmp = t * z; elseif ((z * t) <= 2e+59) tmp = y * x; else tmp = abs((t * z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * t), $MachinePrecision], -0.002], N[(t * z), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 2e+59], N[(y * x), $MachinePrecision], N[Abs[N[(t * z), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -0.002:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+59}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left|t \cdot z\right|\\
\end{array}
\end{array}
if (*.f64 z t) < -2e-3Initial program 95.7%
Taylor expanded in x around 0
lower-*.f6483.9
Applied rewrites83.9%
if -2e-3 < (*.f64 z t) < 1.99999999999999994e59Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6427.7
Applied rewrites27.7%
Applied rewrites20.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6478.8
Applied rewrites78.8%
if 1.99999999999999994e59 < (*.f64 z t) Initial program 98.1%
Taylor expanded in x around 0
lower-*.f6486.2
Applied rewrites86.2%
Applied rewrites86.2%
(FPCore (x y z t) :precision binary64 (if (or (<= (* z t) -0.002) (not (<= (* z t) 2e+59))) (* t z) (* y x)))
double code(double x, double y, double z, double t) {
double tmp;
if (((z * t) <= -0.002) || !((z * t) <= 2e+59)) {
tmp = t * z;
} else {
tmp = y * x;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (((z * t) <= (-0.002d0)) .or. (.not. ((z * t) <= 2d+59))) then
tmp = t * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (((z * t) <= -0.002) || !((z * t) <= 2e+59)) {
tmp = t * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((z * t) <= -0.002) or not ((z * t) <= 2e+59): tmp = t * z else: tmp = y * x return tmp
function code(x, y, z, t) tmp = 0.0 if ((Float64(z * t) <= -0.002) || !(Float64(z * t) <= 2e+59)) tmp = Float64(t * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((z * t) <= -0.002) || ~(((z * t) <= 2e+59))) tmp = t * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], -0.002], N[Not[LessEqual[N[(z * t), $MachinePrecision], 2e+59]], $MachinePrecision]], N[(t * z), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -0.002 \lor \neg \left(z \cdot t \leq 2 \cdot 10^{+59}\right):\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (*.f64 z t) < -2e-3 or 1.99999999999999994e59 < (*.f64 z t) Initial program 96.7%
Taylor expanded in x around 0
lower-*.f6484.9
Applied rewrites84.9%
if -2e-3 < (*.f64 z t) < 1.99999999999999994e59Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6427.7
Applied rewrites27.7%
Applied rewrites20.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6478.8
Applied rewrites78.8%
Final simplification81.7%
(FPCore (x y z t) :precision binary64 (* t z))
double code(double x, double y, double z, double t) {
return t * z;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = t * z
end function
public static double code(double x, double y, double z, double t) {
return t * z;
}
def code(x, y, z, t): return t * z
function code(x, y, z, t) return Float64(t * z) end
function tmp = code(x, y, z, t) tmp = t * z; end
code[x_, y_, z_, t_] := N[(t * z), $MachinePrecision]
\begin{array}{l}
\\
t \cdot z
\end{array}
Initial program 98.4%
Taylor expanded in x around 0
lower-*.f6455.0
Applied rewrites55.0%
herbie shell --seed 2024337
(FPCore (x y z t)
:name "Linear.V2:$cdot from linear-1.19.1.3, A"
:precision binary64
(+ (* x y) (* z t)))