
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
def code(x, y, z): return x * (1.0 - (y * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
def code(x, y, z): return x * (1.0 - (y * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
def code(x, y, z): return x * (1.0 - (y * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
Initial program 97.6%
Final simplification97.6%
(FPCore (x y z) :precision binary64 (if (or (<= (* y z) -4e+15) (not (<= (* y z) 1e-12))) (* x (* y (- z))) x))
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -4e+15) || !((y * z) <= 1e-12)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (((y * z) <= (-4d+15)) .or. (.not. ((y * z) <= 1d-12))) then
tmp = x * (y * -z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -4e+15) || !((y * z) <= 1e-12)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((y * z) <= -4e+15) or not ((y * z) <= 1e-12): tmp = x * (y * -z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -4e+15) || !(Float64(y * z) <= 1e-12)) tmp = Float64(x * Float64(y * Float64(-z))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((y * z) <= -4e+15) || ~(((y * z) <= 1e-12))) tmp = x * (y * -z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -4e+15], N[Not[LessEqual[N[(y * z), $MachinePrecision], 1e-12]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -4 \cdot 10^{+15} \lor \neg \left(y \cdot z \leq 10^{-12}\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -4e15 or 9.9999999999999998e-13 < (*.f64 y z) Initial program 95.2%
Taylor expanded in y around inf 88.3%
mul-1-neg88.3%
associate-*r*94.1%
distribute-lft-neg-in94.1%
distribute-rgt-neg-out94.1%
*-commutative94.1%
Simplified94.1%
if -4e15 < (*.f64 y z) < 9.9999999999999998e-13Initial program 100.0%
Taylor expanded in y around 0 99.1%
Final simplification96.6%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 97.6%
Taylor expanded in y around 0 52.4%
Final simplification52.4%
herbie shell --seed 2023252
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))