
(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 6 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 (if (or (<= (* y z) (- INFINITY)) (not (<= (* y z) 2e+70))) (* z (* y (- x))) (- x (* (* y z) x))))
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -((double) INFINITY)) || !((y * z) <= 2e+70)) {
tmp = z * (y * -x);
} else {
tmp = x - ((y * z) * x);
}
return tmp;
}
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -Double.POSITIVE_INFINITY) || !((y * z) <= 2e+70)) {
tmp = z * (y * -x);
} else {
tmp = x - ((y * z) * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((y * z) <= -math.inf) or not ((y * z) <= 2e+70): tmp = z * (y * -x) else: tmp = x - ((y * z) * x) return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= Float64(-Inf)) || !(Float64(y * z) <= 2e+70)) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = Float64(x - Float64(Float64(y * z) * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((y * z) <= -Inf) || ~(((y * z) <= 2e+70))) tmp = z * (y * -x); else tmp = x - ((y * z) * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], N[Not[LessEqual[N[(y * z), $MachinePrecision], 2e+70]], $MachinePrecision]], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -\infty \lor \neg \left(y \cdot z \leq 2 \cdot 10^{+70}\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 2.00000000000000015e70 < (*.f64 y z) Initial program 78.2%
Taylor expanded in x around 0 78.2%
*-commutative78.2%
distribute-rgt-out--78.2%
associate-*r*98.4%
*-lft-identity98.4%
Simplified98.4%
Taylor expanded in y around inf 98.4%
mul-1-neg98.4%
associate-*r*78.2%
distribute-rgt-neg-in78.2%
*-commutative78.2%
associate-*r*99.8%
Simplified99.8%
if -inf.0 < (*.f64 y z) < 2.00000000000000015e70Initial program 99.9%
sub-neg99.9%
distribute-rgt-in99.9%
*-un-lft-identity99.9%
distribute-rgt-neg-in99.9%
Applied egg-rr99.9%
distribute-rgt-neg-out99.9%
cancel-sign-sub-inv99.9%
*-commutative99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= (* y z) (- INFINITY)) (not (<= (* y z) 2e+70))) (* z (* y (- x))) (* x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -((double) INFINITY)) || !((y * z) <= 2e+70)) {
tmp = z * (y * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -Double.POSITIVE_INFINITY) || !((y * z) <= 2e+70)) {
tmp = z * (y * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((y * z) <= -math.inf) or not ((y * z) <= 2e+70): tmp = z * (y * -x) else: tmp = x * (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= Float64(-Inf)) || !(Float64(y * z) <= 2e+70)) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((y * z) <= -Inf) || ~(((y * z) <= 2e+70))) tmp = z * (y * -x); else tmp = x * (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], N[Not[LessEqual[N[(y * z), $MachinePrecision], 2e+70]], $MachinePrecision]], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -\infty \lor \neg \left(y \cdot z \leq 2 \cdot 10^{+70}\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 2.00000000000000015e70 < (*.f64 y z) Initial program 78.2%
Taylor expanded in x around 0 78.2%
*-commutative78.2%
distribute-rgt-out--78.2%
associate-*r*98.4%
*-lft-identity98.4%
Simplified98.4%
Taylor expanded in y around inf 98.4%
mul-1-neg98.4%
associate-*r*78.2%
distribute-rgt-neg-in78.2%
*-commutative78.2%
associate-*r*99.8%
Simplified99.8%
if -inf.0 < (*.f64 y z) < 2.00000000000000015e70Initial program 99.9%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.000112) (not (<= y 1.5e-146))) (* (* y z) (- x)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.000112) || !(y <= 1.5e-146)) {
tmp = (y * z) * -x;
} 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 <= (-0.000112d0)) .or. (.not. (y <= 1.5d-146))) then
tmp = (y * z) * -x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.000112) || !(y <= 1.5e-146)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.000112) or not (y <= 1.5e-146): tmp = (y * z) * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.000112) || !(y <= 1.5e-146)) tmp = Float64(Float64(y * z) * Float64(-x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.000112) || ~((y <= 1.5e-146))) tmp = (y * z) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.000112], N[Not[LessEqual[y, 1.5e-146]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.000112 \lor \neg \left(y \leq 1.5 \cdot 10^{-146}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.11999999999999998e-4 or 1.50000000000000009e-146 < y Initial program 90.3%
Taylor expanded in y around inf 64.6%
mul-1-neg64.6%
associate-*r*60.0%
distribute-lft-neg-in60.0%
distribute-rgt-neg-out60.0%
*-commutative60.0%
Simplified60.0%
if -1.11999999999999998e-4 < y < 1.50000000000000009e-146Initial program 99.9%
Taylor expanded in y around 0 73.2%
Final simplification65.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.000105) (not (<= y 1.95e-185))) (* y (* z (- x))) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.000105) || !(y <= 1.95e-185)) {
tmp = y * (z * -x);
} 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 <= (-0.000105d0)) .or. (.not. (y <= 1.95d-185))) then
tmp = y * (z * -x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.000105) || !(y <= 1.95e-185)) {
tmp = y * (z * -x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.000105) or not (y <= 1.95e-185): tmp = y * (z * -x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.000105) || !(y <= 1.95e-185)) tmp = Float64(y * Float64(z * Float64(-x))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.000105) || ~((y <= 1.95e-185))) tmp = y * (z * -x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.000105], N[Not[LessEqual[y, 1.95e-185]], $MachinePrecision]], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.000105 \lor \neg \left(y \leq 1.95 \cdot 10^{-185}\right):\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.05e-4 or 1.95e-185 < y Initial program 90.7%
Taylor expanded in y around inf 62.1%
mul-1-neg62.1%
distribute-rgt-neg-in62.1%
distribute-lft-neg-out62.1%
*-commutative62.1%
Simplified62.1%
if -1.05e-4 < y < 1.95e-185Initial program 99.8%
Taylor expanded in y around 0 73.2%
Final simplification66.1%
(FPCore (x y z) :precision binary64 (if (<= y -0.000112) (* z (* y (- x))) (if (<= y 1.95e-185) x (* y (* z (- x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.000112) {
tmp = z * (y * -x);
} else if (y <= 1.95e-185) {
tmp = x;
} else {
tmp = y * (z * -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 <= (-0.000112d0)) then
tmp = z * (y * -x)
else if (y <= 1.95d-185) then
tmp = x
else
tmp = y * (z * -x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -0.000112) {
tmp = z * (y * -x);
} else if (y <= 1.95e-185) {
tmp = x;
} else {
tmp = y * (z * -x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.000112: tmp = z * (y * -x) elif y <= 1.95e-185: tmp = x else: tmp = y * (z * -x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.000112) tmp = Float64(z * Float64(y * Float64(-x))); elseif (y <= 1.95e-185) tmp = x; else tmp = Float64(y * Float64(z * Float64(-x))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.000112) tmp = z * (y * -x); elseif (y <= 1.95e-185) tmp = x; else tmp = y * (z * -x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.000112], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.95e-185], x, N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.000112:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{-185}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if y < -1.11999999999999998e-4Initial program 88.6%
Taylor expanded in x around 0 88.6%
*-commutative88.6%
distribute-rgt-out--88.6%
associate-*r*96.5%
*-lft-identity96.5%
Simplified96.5%
Taylor expanded in y around inf 77.9%
mul-1-neg77.9%
associate-*r*70.1%
distribute-rgt-neg-in70.1%
*-commutative70.1%
associate-*r*81.4%
Simplified81.4%
if -1.11999999999999998e-4 < y < 1.95e-185Initial program 99.8%
Taylor expanded in y around 0 73.2%
if 1.95e-185 < y Initial program 92.2%
Taylor expanded in y around inf 51.3%
mul-1-neg51.3%
distribute-rgt-neg-in51.3%
distribute-lft-neg-out51.3%
*-commutative51.3%
Simplified51.3%
Final simplification67.0%
(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 94.0%
Taylor expanded in y around 0 48.0%
Final simplification48.0%
herbie shell --seed 2023196
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))