
(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 x y (* z (- t))))
double code(double x, double y, double z, double t) {
return fma(x, y, (z * -t));
}
function code(x, y, z, t) return fma(x, y, Float64(z * Float64(-t))) end
code[x_, y_, z_, t_] := N[(x * y + N[(z * (-t)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, z \cdot \left(-t\right)\right)
\end{array}
Initial program 99.6%
fma-neg100.0%
distribute-rgt-neg-in100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z t)
:precision binary64
(if (or (<= t -4.4e-100)
(not (or (<= t 1.15e-17) (and (not (<= t 3.3e+18)) (<= t 2.9e+53)))))
(* z (- t))
(* x y)))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -4.4e-100) || !((t <= 1.15e-17) || (!(t <= 3.3e+18) && (t <= 2.9e+53)))) {
tmp = z * -t;
} else {
tmp = x * y;
}
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 ((t <= (-4.4d-100)) .or. (.not. (t <= 1.15d-17) .or. (.not. (t <= 3.3d+18)) .and. (t <= 2.9d+53))) then
tmp = z * -t
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -4.4e-100) || !((t <= 1.15e-17) || (!(t <= 3.3e+18) && (t <= 2.9e+53)))) {
tmp = z * -t;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -4.4e-100) or not ((t <= 1.15e-17) or (not (t <= 3.3e+18) and (t <= 2.9e+53))): tmp = z * -t else: tmp = x * y return tmp
function code(x, y, z, t) tmp = 0.0 if ((t <= -4.4e-100) || !((t <= 1.15e-17) || (!(t <= 3.3e+18) && (t <= 2.9e+53)))) tmp = Float64(z * Float64(-t)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t <= -4.4e-100) || ~(((t <= 1.15e-17) || (~((t <= 3.3e+18)) && (t <= 2.9e+53))))) tmp = z * -t; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -4.4e-100], N[Not[Or[LessEqual[t, 1.15e-17], And[N[Not[LessEqual[t, 3.3e+18]], $MachinePrecision], LessEqual[t, 2.9e+53]]]], $MachinePrecision]], N[(z * (-t)), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -4.4 \cdot 10^{-100} \lor \neg \left(t \leq 1.15 \cdot 10^{-17} \lor \neg \left(t \leq 3.3 \cdot 10^{+18}\right) \land t \leq 2.9 \cdot 10^{+53}\right):\\
\;\;\;\;z \cdot \left(-t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if t < -4.39999999999999978e-100 or 1.15000000000000004e-17 < t < 3.3e18 or 2.9000000000000002e53 < t Initial program 99.3%
Taylor expanded in x around 0 73.8%
associate-*r*73.8%
neg-mul-173.8%
*-commutative73.8%
Simplified73.8%
if -4.39999999999999978e-100 < t < 1.15000000000000004e-17 or 3.3e18 < t < 2.9000000000000002e53Initial program 100.0%
Taylor expanded in x around inf 81.6%
Final simplification77.1%
(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 99.6%
Final simplification99.6%
(FPCore (x y z t) :precision binary64 (* x y))
double code(double x, double y, double z, double t) {
return x * y;
}
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
end function
public static double code(double x, double y, double z, double t) {
return x * y;
}
def code(x, y, z, t): return x * y
function code(x, y, z, t) return Float64(x * y) end
function tmp = code(x, y, z, t) tmp = x * y; end
code[x_, y_, z_, t_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.6%
Taylor expanded in x around inf 51.5%
Final simplification51.5%
herbie shell --seed 2023230
(FPCore (x y z t)
:name "Linear.V3:cross from linear-1.19.1.3"
:precision binary64
(- (* x y) (* z t)))