
(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 (- z) t (* x y)))
double code(double x, double y, double z, double t) {
return fma(-z, t, (x * y));
}
function code(x, y, z, t) return fma(Float64(-z), t, Float64(x * y)) end
code[x_, y_, z_, t_] := N[((-z) * t + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-z, t, x \cdot y\right)
\end{array}
Initial program 99.2%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
Final simplification99.6%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (fma z t (* x y))))
(if (<= (* x y) -50000000000000.0)
t_1
(if (<= (* x y) 5e-95) (* (- t) z) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma(z, t, (x * y));
double tmp;
if ((x * y) <= -50000000000000.0) {
tmp = t_1;
} else if ((x * y) <= 5e-95) {
tmp = -t * z;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(z, t, Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -50000000000000.0) tmp = t_1; elseif (Float64(x * y) <= 5e-95) tmp = Float64(Float64(-t) * z); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z * t + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -50000000000000.0], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 5e-95], N[((-t) * z), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(z, t, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -50000000000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{-95}:\\
\;\;\;\;\left(-t\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -5e13 or 4.9999999999999998e-95 < (*.f64 x y) Initial program 98.5%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.2
Applied rewrites99.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-neg75.0
Applied rewrites75.0%
if -5e13 < (*.f64 x y) < 4.9999999999999998e-95Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6480.9
Applied rewrites80.9%
Final simplification77.8%
(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 99.2%
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 (- (* x y) (* t z)))
double code(double x, double y, double z, double t) {
return (x * y) - (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 = (x * y) - (t * z)
end function
public static double code(double x, double y, double z, double t) {
return (x * y) - (t * z);
}
def code(x, y, z, t): return (x * y) - (t * z)
function code(x, y, z, t) return Float64(Float64(x * y) - Float64(t * z)) end
function tmp = code(x, y, z, t) tmp = (x * y) - (t * z); end
code[x_, y_, z_, t_] := N[(N[(x * y), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y - t \cdot z
\end{array}
Initial program 99.2%
Final simplification99.2%
(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(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}
\\
\left(-t\right) \cdot z
\end{array}
Initial program 99.2%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6453.4
Applied rewrites53.4%
Final simplification53.4%
(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 99.2%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6453.4
Applied rewrites53.4%
Applied rewrites4.2%
Final simplification4.2%
herbie shell --seed 2024327
(FPCore (x y z t)
:name "Linear.V3:cross from linear-1.19.1.3"
:precision binary64
(- (* x y) (* z t)))