
(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 z t (* y x)))
double code(double x, double y, double z, double t) {
return fma(z, t, (y * x));
}
function code(x, y, z, t) return fma(z, t, Float64(y * x)) end
code[x_, y_, z_, t_] := N[(z * t + N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, y \cdot x\right)
\end{array}
Initial program 98.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6498.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.8
Applied rewrites98.8%
(FPCore (x y z t) :precision binary64 (if (<= (* z t) -5e-19) (* t z) (if (<= (* z t) 4e+86) (* y x) (fabs (* t z)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * t) <= -5e-19) {
tmp = t * z;
} else if ((z * t) <= 4e+86) {
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) <= (-5d-19)) then
tmp = t * z
else if ((z * t) <= 4d+86) 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) <= -5e-19) {
tmp = t * z;
} else if ((z * t) <= 4e+86) {
tmp = y * x;
} else {
tmp = Math.abs((t * z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * t) <= -5e-19: tmp = t * z elif (z * t) <= 4e+86: tmp = y * x else: tmp = math.fabs((t * z)) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * t) <= -5e-19) tmp = Float64(t * z); elseif (Float64(z * t) <= 4e+86) 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) <= -5e-19) tmp = t * z; elseif ((z * t) <= 4e+86) tmp = y * x; else tmp = abs((t * z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * t), $MachinePrecision], -5e-19], N[(t * z), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 4e+86], N[(y * x), $MachinePrecision], N[Abs[N[(t * z), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{-19}:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;z \cdot t \leq 4 \cdot 10^{+86}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left|t \cdot z\right|\\
\end{array}
\end{array}
if (*.f64 z t) < -5.0000000000000004e-19Initial program 98.4%
Taylor expanded in x around 0
lower-*.f6475.1
Applied rewrites75.1%
if -5.0000000000000004e-19 < (*.f64 z t) < 4.0000000000000001e86Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6428.1
Applied rewrites28.1%
Applied rewrites22.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6476.4
Applied rewrites76.4%
if 4.0000000000000001e86 < (*.f64 z t) Initial program 96.9%
Taylor expanded in x around 0
lower-*.f6486.4
Applied rewrites86.4%
Applied rewrites86.4%
(FPCore (x y z t) :precision binary64 (if (or (<= (* z t) -5e-19) (not (<= (* z t) 4e+86))) (* t z) (* y x)))
double code(double x, double y, double z, double t) {
double tmp;
if (((z * t) <= -5e-19) || !((z * t) <= 4e+86)) {
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) <= (-5d-19)) .or. (.not. ((z * t) <= 4d+86))) 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) <= -5e-19) || !((z * t) <= 4e+86)) {
tmp = t * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((z * t) <= -5e-19) or not ((z * t) <= 4e+86): tmp = t * z else: tmp = y * x return tmp
function code(x, y, z, t) tmp = 0.0 if ((Float64(z * t) <= -5e-19) || !(Float64(z * t) <= 4e+86)) 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) <= -5e-19) || ~(((z * t) <= 4e+86))) tmp = t * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], -5e-19], N[Not[LessEqual[N[(z * t), $MachinePrecision], 4e+86]], $MachinePrecision]], N[(t * z), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{-19} \lor \neg \left(z \cdot t \leq 4 \cdot 10^{+86}\right):\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (*.f64 z t) < -5.0000000000000004e-19 or 4.0000000000000001e86 < (*.f64 z t) Initial program 97.6%
Taylor expanded in x around 0
lower-*.f6480.8
Applied rewrites80.8%
if -5.0000000000000004e-19 < (*.f64 z t) < 4.0000000000000001e86Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6428.1
Applied rewrites28.1%
Applied rewrites22.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6476.4
Applied rewrites76.4%
Final simplification78.6%
(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.8%
Taylor expanded in x around 0
lower-*.f6454.3
Applied rewrites54.3%
herbie shell --seed 2024339
(FPCore (x y z t)
:name "Linear.V2:$cdot from linear-1.19.1.3, A"
:precision binary64
(+ (* x y) (* z t)))