
(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 (* t (- z))))
double code(double x, double y, double z, double t) {
return fma(x, y, (t * -z));
}
function code(x, y, z, t) return fma(x, y, Float64(t * Float64(-z))) end
code[x_, y_, z_, t_] := N[(x * y + N[(t * (-z)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, t \cdot \left(-z\right)\right)
\end{array}
Initial program 99.2%
fma-neg99.2%
distribute-rgt-neg-in99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (x y z t)
:precision binary64
(if (or (<= y -3.2e-118)
(and (not (<= y 6e-38)) (or (<= y 2.8e-21) (not (<= y 8e+14)))))
(* x y)
(* t (- z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.2e-118) || (!(y <= 6e-38) && ((y <= 2.8e-21) || !(y <= 8e+14)))) {
tmp = x * y;
} else {
tmp = t * -z;
}
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 ((y <= (-3.2d-118)) .or. (.not. (y <= 6d-38)) .and. (y <= 2.8d-21) .or. (.not. (y <= 8d+14))) then
tmp = x * y
else
tmp = t * -z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.2e-118) || (!(y <= 6e-38) && ((y <= 2.8e-21) || !(y <= 8e+14)))) {
tmp = x * y;
} else {
tmp = t * -z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3.2e-118) or (not (y <= 6e-38) and ((y <= 2.8e-21) or not (y <= 8e+14))): tmp = x * y else: tmp = t * -z return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3.2e-118) || (!(y <= 6e-38) && ((y <= 2.8e-21) || !(y <= 8e+14)))) tmp = Float64(x * y); else tmp = Float64(t * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -3.2e-118) || (~((y <= 6e-38)) && ((y <= 2.8e-21) || ~((y <= 8e+14))))) tmp = x * y; else tmp = t * -z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.2e-118], And[N[Not[LessEqual[y, 6e-38]], $MachinePrecision], Or[LessEqual[y, 2.8e-21], N[Not[LessEqual[y, 8e+14]], $MachinePrecision]]]], N[(x * y), $MachinePrecision], N[(t * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{-118} \lor \neg \left(y \leq 6 \cdot 10^{-38}\right) \land \left(y \leq 2.8 \cdot 10^{-21} \lor \neg \left(y \leq 8 \cdot 10^{+14}\right)\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(-z\right)\\
\end{array}
\end{array}
if y < -3.20000000000000004e-118 or 5.99999999999999977e-38 < y < 2.80000000000000004e-21 or 8e14 < y Initial program 98.8%
Taylor expanded in x around inf 68.1%
if -3.20000000000000004e-118 < y < 5.99999999999999977e-38 or 2.80000000000000004e-21 < y < 8e14Initial program 100.0%
Taylor expanded in x around 0 72.9%
mul-1-neg72.9%
distribute-rgt-neg-in72.9%
Simplified72.9%
Final simplification69.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 99.2%
Final simplification99.2%
(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.2%
Taylor expanded in x around inf 56.2%
Final simplification56.2%
herbie shell --seed 2023224
(FPCore (x y z t)
:name "Linear.V3:cross from linear-1.19.1.3"
:precision binary64
(- (* x y) (* z t)))