
(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 (- 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 100.0%
sub-neg100.0%
distribute-rgt-neg-out100.0%
+-commutative100.0%
distribute-rgt-neg-out100.0%
distribute-lft-neg-in100.0%
fma-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(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 100.0%
fma-neg100.0%
distribute-rgt-neg-in100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z t)
:precision binary64
(if (or (<= x -4.5e+168)
(and (not (<= x -1.9e+109)) (or (<= x -0.495) (not (<= x 1.9e-64)))))
(* x y)
(* z (- t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -4.5e+168) || (!(x <= -1.9e+109) && ((x <= -0.495) || !(x <= 1.9e-64)))) {
tmp = x * y;
} else {
tmp = z * -t;
}
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 ((x <= (-4.5d+168)) .or. (.not. (x <= (-1.9d+109))) .and. (x <= (-0.495d0)) .or. (.not. (x <= 1.9d-64))) then
tmp = x * y
else
tmp = z * -t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -4.5e+168) || (!(x <= -1.9e+109) && ((x <= -0.495) || !(x <= 1.9e-64)))) {
tmp = x * y;
} else {
tmp = z * -t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -4.5e+168) or (not (x <= -1.9e+109) and ((x <= -0.495) or not (x <= 1.9e-64))): tmp = x * y else: tmp = z * -t return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -4.5e+168) || (!(x <= -1.9e+109) && ((x <= -0.495) || !(x <= 1.9e-64)))) tmp = Float64(x * y); else tmp = Float64(z * Float64(-t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -4.5e+168) || (~((x <= -1.9e+109)) && ((x <= -0.495) || ~((x <= 1.9e-64))))) tmp = x * y; else tmp = z * -t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -4.5e+168], And[N[Not[LessEqual[x, -1.9e+109]], $MachinePrecision], Or[LessEqual[x, -0.495], N[Not[LessEqual[x, 1.9e-64]], $MachinePrecision]]]], N[(x * y), $MachinePrecision], N[(z * (-t)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{+168} \lor \neg \left(x \leq -1.9 \cdot 10^{+109}\right) \land \left(x \leq -0.495 \lor \neg \left(x \leq 1.9 \cdot 10^{-64}\right)\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-t\right)\\
\end{array}
\end{array}
if x < -4.50000000000000012e168 or -1.90000000000000019e109 < x < -0.495 or 1.9000000000000001e-64 < x Initial program 100.0%
Taylor expanded in x around inf 65.0%
if -4.50000000000000012e168 < x < -1.90000000000000019e109 or -0.495 < x < 1.9000000000000001e-64Initial program 100.0%
Taylor expanded in x around 0 77.9%
mul-1-neg77.9%
distribute-rgt-neg-in77.9%
Simplified77.9%
Final simplification71.9%
(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 100.0%
Final simplification100.0%
(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 100.0%
Taylor expanded in x around inf 45.2%
Final simplification45.2%
herbie shell --seed 2023200
(FPCore (x y z t)
:name "Linear.V3:cross from linear-1.19.1.3"
:precision binary64
(- (* x y) (* z t)))