
(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 5 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}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= (* y z) -1e+122) (not (<= (* y z) 2e+303))) (* z (* y (- x))) (* x (- 1.0 (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -1e+122) || !((y * z) <= 2e+303)) {
tmp = z * (y * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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) <= (-1d+122)) .or. (.not. ((y * z) <= 2d+303))) then
tmp = z * (y * -x)
else
tmp = x * (1.0d0 - (y * z))
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -1e+122) || !((y * z) <= 2e+303)) {
tmp = z * (y * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -1e+122) or not ((y * z) <= 2e+303): tmp = z * (y * -x) else: tmp = x * (1.0 - (y * z)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -1e+122) || !(Float64(y * z) <= 2e+303)) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (((y * z) <= -1e+122) || ~(((y * z) <= 2e+303)))
tmp = z * (y * -x);
else
tmp = x * (1.0 - (y * z));
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -1e+122], N[Not[LessEqual[N[(y * z), $MachinePrecision], 2e+303]], $MachinePrecision]], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+122} \lor \neg \left(y \cdot z \leq 2 \cdot 10^{+303}\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) < -1.00000000000000001e122 or 2e303 < (*.f64 y z) Initial program 77.2%
Taylor expanded in y around inf 77.2%
mul-1-neg77.2%
associate-*r*99.9%
Simplified99.9%
if -1.00000000000000001e122 < (*.f64 y z) < 2e303Initial program 99.8%
Final simplification99.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (or (<= y -5e+128)
(not (or (<= y -9e+120) (and (not (<= y -3.5e+43)) (<= y 8e-64)))))
(* z (* y (- x)))
x))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -5e+128) || !((y <= -9e+120) || (!(y <= -3.5e+43) && (y <= 8e-64)))) {
tmp = z * (y * -x);
} else {
tmp = x;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 <= (-5d+128)) .or. (.not. (y <= (-9d+120)) .or. (.not. (y <= (-3.5d+43))) .and. (y <= 8d-64))) then
tmp = z * (y * -x)
else
tmp = x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5e+128) || !((y <= -9e+120) || (!(y <= -3.5e+43) && (y <= 8e-64)))) {
tmp = z * (y * -x);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y <= -5e+128) or not ((y <= -9e+120) or (not (y <= -3.5e+43) and (y <= 8e-64))): tmp = z * (y * -x) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -5e+128) || !((y <= -9e+120) || (!(y <= -3.5e+43) && (y <= 8e-64)))) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = x; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= -5e+128) || ~(((y <= -9e+120) || (~((y <= -3.5e+43)) && (y <= 8e-64)))))
tmp = z * (y * -x);
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[y, -5e+128], N[Not[Or[LessEqual[y, -9e+120], And[N[Not[LessEqual[y, -3.5e+43]], $MachinePrecision], LessEqual[y, 8e-64]]]], $MachinePrecision]], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+128} \lor \neg \left(y \leq -9 \cdot 10^{+120} \lor \neg \left(y \leq -3.5 \cdot 10^{+43}\right) \land y \leq 8 \cdot 10^{-64}\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5e128 or -8.99999999999999953e120 < y < -3.5000000000000001e43 or 7.99999999999999972e-64 < y Initial program 91.0%
Taylor expanded in y around inf 65.0%
mul-1-neg65.0%
associate-*r*70.7%
Simplified70.7%
if -5e128 < y < -8.99999999999999953e120 or -3.5000000000000001e43 < y < 7.99999999999999972e-64Initial program 99.9%
Taylor expanded in y around 0 77.8%
Final simplification74.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (or (<= y -9.2e+126)
(not (or (<= y -9e+120) (and (not (<= y -1.1e+41)) (<= y 5.1e-163)))))
(* y (* x (- z)))
x))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.2e+126) || !((y <= -9e+120) || (!(y <= -1.1e+41) && (y <= 5.1e-163)))) {
tmp = y * (x * -z);
} else {
tmp = x;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 <= (-9.2d+126)) .or. (.not. (y <= (-9d+120)) .or. (.not. (y <= (-1.1d+41))) .and. (y <= 5.1d-163))) then
tmp = y * (x * -z)
else
tmp = x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -9.2e+126) || !((y <= -9e+120) || (!(y <= -1.1e+41) && (y <= 5.1e-163)))) {
tmp = y * (x * -z);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y <= -9.2e+126) or not ((y <= -9e+120) or (not (y <= -1.1e+41) and (y <= 5.1e-163))): tmp = y * (x * -z) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -9.2e+126) || !((y <= -9e+120) || (!(y <= -1.1e+41) && (y <= 5.1e-163)))) tmp = Float64(y * Float64(x * Float64(-z))); else tmp = x; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= -9.2e+126) || ~(((y <= -9e+120) || (~((y <= -1.1e+41)) && (y <= 5.1e-163)))))
tmp = y * (x * -z);
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[y, -9.2e+126], N[Not[Or[LessEqual[y, -9e+120], And[N[Not[LessEqual[y, -1.1e+41]], $MachinePrecision], LessEqual[y, 5.1e-163]]]], $MachinePrecision]], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.2 \cdot 10^{+126} \lor \neg \left(y \leq -9 \cdot 10^{+120} \lor \neg \left(y \leq -1.1 \cdot 10^{+41}\right) \land y \leq 5.1 \cdot 10^{-163}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -9.2000000000000002e126 or -8.99999999999999953e120 < y < -1.09999999999999995e41 or 5.0999999999999999e-163 < y Initial program 91.8%
Taylor expanded in y around inf 62.1%
mul-1-neg62.1%
associate-*r*66.7%
distribute-rgt-neg-in66.7%
*-commutative66.7%
associate-*l*66.6%
Simplified66.6%
if -9.2000000000000002e126 < y < -8.99999999999999953e120 or -1.09999999999999995e41 < y < 5.0999999999999999e-163Initial program 99.9%
Taylor expanded in y around 0 79.6%
Final simplification71.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x 3.65e-81) (- x (* (* x y) z)) (* x (- 1.0 (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 3.65e-81) {
tmp = x - ((x * y) * z);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 (x <= 3.65d-81) then
tmp = x - ((x * y) * z)
else
tmp = x * (1.0d0 - (y * z))
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (x <= 3.65e-81) {
tmp = x - ((x * y) * z);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= 3.65e-81: tmp = x - ((x * y) * z) else: tmp = x * (1.0 - (y * z)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= 3.65e-81) tmp = Float64(x - Float64(Float64(x * y) * z)); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= 3.65e-81)
tmp = x - ((x * y) * z);
else
tmp = x * (1.0 - (y * z));
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[x, 3.65e-81], N[(x - N[(N[(x * y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.65 \cdot 10^{-81}:\\
\;\;\;\;x - \left(x \cdot y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if x < 3.6500000000000001e-81Initial program 92.6%
Taylor expanded in y around 0 92.6%
mul-1-neg92.6%
associate-*r*96.5%
Simplified96.5%
if 3.6500000000000001e-81 < x Initial program 99.8%
Final simplification97.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(x < y && y < z);
double code(double x, double y, double z) {
return x;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x
x, y, z = sort([x, y, z]) function code(x, y, z) return x end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x
\end{array}
Initial program 95.1%
Taylor expanded in y around 0 50.6%
Final simplification50.6%
herbie shell --seed 2024089
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))