
(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 6 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(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, \left(-t\right) \cdot z\right)
\end{array}
Initial program 98.4%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6499.2
Applied rewrites99.2%
(FPCore (x y z t) :precision binary64 (if (or (<= (* x y) -2e-11) (not (<= (* x y) 5e-63))) (fma y x (* t z)) (* (- z) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (((x * y) <= -2e-11) || !((x * y) <= 5e-63)) {
tmp = fma(y, x, (t * z));
} else {
tmp = -z * t;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((Float64(x * y) <= -2e-11) || !(Float64(x * y) <= 5e-63)) tmp = fma(y, x, Float64(t * z)); else tmp = Float64(Float64(-z) * t); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -2e-11], N[Not[LessEqual[N[(x * y), $MachinePrecision], 5e-63]], $MachinePrecision]], N[(y * x + N[(t * z), $MachinePrecision]), $MachinePrecision], N[((-z) * t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{-11} \lor \neg \left(x \cdot y \leq 5 \cdot 10^{-63}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -1.99999999999999988e-11 or 5.0000000000000002e-63 < (*.f64 x y) Initial program 97.1%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6498.6
Applied rewrites98.6%
lift-neg.f64N/A
neg-sub0N/A
flip3--N/A
metadata-evalN/A
sub0-negN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
lift-neg.f64N/A
lift-neg.f64N/A
pow-prod-downN/A
sqr-powN/A
lift-neg.f64N/A
cube-negN/A
sub0-negN/A
metadata-evalN/A
distribute-neg-fracN/A
flip3--N/A
neg-sub0N/A
remove-double-neg70.9
Applied rewrites70.9%
if -1.99999999999999988e-11 < (*.f64 x y) < 5.0000000000000002e-63Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6486.6
Applied rewrites86.6%
Final simplification78.0%
(FPCore (x y z t) :precision binary64 (if (<= (* x y) -2e-11) (fma y x (* t z)) (if (<= (* x y) 5e-63) (* (- z) t) (fma z t (* y x)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * y) <= -2e-11) {
tmp = fma(y, x, (t * z));
} else if ((x * y) <= 5e-63) {
tmp = -z * t;
} else {
tmp = fma(z, t, (y * x));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(x * y) <= -2e-11) tmp = fma(y, x, Float64(t * z)); elseif (Float64(x * y) <= 5e-63) tmp = Float64(Float64(-z) * t); else tmp = fma(z, t, Float64(y * x)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * y), $MachinePrecision], -2e-11], N[(y * x + N[(t * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e-63], N[((-z) * t), $MachinePrecision], N[(z * t + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{-63}:\\
\;\;\;\;\left(-z\right) \cdot t\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, t, y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -1.99999999999999988e-11Initial program 96.4%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6498.2
Applied rewrites98.2%
lift-neg.f64N/A
neg-sub0N/A
flip3--N/A
metadata-evalN/A
sub0-negN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
lift-neg.f64N/A
lift-neg.f64N/A
pow-prod-downN/A
sqr-powN/A
lift-neg.f64N/A
cube-negN/A
sub0-negN/A
metadata-evalN/A
distribute-neg-fracN/A
flip3--N/A
neg-sub0N/A
remove-double-neg72.5
Applied rewrites72.5%
if -1.99999999999999988e-11 < (*.f64 x y) < 5.0000000000000002e-63Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6486.6
Applied rewrites86.6%
if 5.0000000000000002e-63 < (*.f64 x y) Initial program 97.6%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6498.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.8
Applied rewrites98.8%
lift-neg.f64N/A
neg-sub0N/A
flip3--N/A
metadata-evalN/A
sub0-negN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
lift-neg.f64N/A
lift-neg.f64N/A
pow-prod-downN/A
sqr-powN/A
lift-neg.f64N/A
cube-negN/A
sub0-negN/A
metadata-evalN/A
distribute-neg-fracN/A
flip3--N/A
neg-sub0N/A
remove-double-neg71.0
Applied rewrites71.0%
(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}
Initial program 98.4%
(FPCore (x y z t) :precision binary64 (* (- z) t))
double code(double x, double y, double z, double t) {
return -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 = -z * t
end function
public static double code(double x, double y, double z, double t) {
return -z * t;
}
def code(x, y, z, t): return -z * t
function code(x, y, z, t) return Float64(Float64(-z) * t) end
function tmp = code(x, y, z, t) tmp = -z * t; end
code[x_, y_, z_, t_] := N[((-z) * t), $MachinePrecision]
\begin{array}{l}
\\
\left(-z\right) \cdot t
\end{array}
Initial program 98.4%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6455.5
Applied rewrites55.5%
(FPCore (x y z t) :precision binary64 (* z t))
double code(double x, double y, double z, double t) {
return 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 = z * t
end function
public static double code(double x, double y, double z, double t) {
return z * t;
}
def code(x, y, z, t): return z * t
function code(x, y, z, t) return Float64(z * t) end
function tmp = code(x, y, z, t) tmp = z * t; end
code[x_, y_, z_, t_] := N[(z * t), $MachinePrecision]
\begin{array}{l}
\\
z \cdot t
\end{array}
Initial program 98.4%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6455.5
Applied rewrites55.5%
Applied rewrites4.4%
herbie shell --seed 2024317
(FPCore (x y z t)
:name "Linear.V3:cross from linear-1.19.1.3"
:precision binary64
(- (* x y) (* z t)))