
(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 5 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.6
Applied rewrites99.6%
(FPCore (x y z t) :precision binary64 (if (or (<= (* x y) -5e+85) (not (<= (* x y) 2e+58))) (fma z t (* y x)) (* (- z) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (((x * y) <= -5e+85) || !((x * y) <= 2e+58)) {
tmp = fma(z, t, (y * x));
} else {
tmp = -z * t;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((Float64(x * y) <= -5e+85) || !(Float64(x * y) <= 2e+58)) tmp = fma(z, t, Float64(y * x)); else tmp = Float64(Float64(-z) * t); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -5e+85], N[Not[LessEqual[N[(x * y), $MachinePrecision], 2e+58]], $MachinePrecision]], N[(z * t + N[(y * x), $MachinePrecision]), $MachinePrecision], N[((-z) * t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+85} \lor \neg \left(x \cdot y \leq 2 \cdot 10^{+58}\right):\\
\;\;\;\;\mathsf{fma}\left(z, t, y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -5.0000000000000001e85 or 1.99999999999999989e58 < (*.f64 x y) Initial program 95.7%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6496.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6496.7
Applied rewrites96.7%
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-neg81.0
Applied rewrites81.0%
if -5.0000000000000001e85 < (*.f64 x y) < 1.99999999999999989e58Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6475.4
Applied rewrites75.4%
Final simplification77.4%
(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.f6456.2
Applied rewrites56.2%
(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.f6456.2
Applied rewrites56.2%
Applied rewrites5.1%
herbie shell --seed 2024314
(FPCore (x y z t)
:name "Linear.V3:cross from linear-1.19.1.3"
:precision binary64
(- (* x y) (* z t)))