
(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}
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) (- INFINITY)) (not (<= (* y z) 5e+160))) (* y (* x (- z))) (- x (* (* y z) x))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -((double) INFINITY)) || !((y * z) <= 5e+160)) {
tmp = y * (x * -z);
} else {
tmp = x - ((y * z) * x);
}
return tmp;
}
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -Double.POSITIVE_INFINITY) || !((y * z) <= 5e+160)) {
tmp = y * (x * -z);
} else {
tmp = x - ((y * z) * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -math.inf) or not ((y * z) <= 5e+160): tmp = y * (x * -z) else: tmp = x - ((y * z) * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= Float64(-Inf)) || !(Float64(y * z) <= 5e+160)) tmp = Float64(y * Float64(x * Float64(-z))); else tmp = Float64(x - Float64(Float64(y * z) * 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 * z) <= -Inf) || ~(((y * z) <= 5e+160)))
tmp = y * (x * -z);
else
tmp = x - ((y * z) * 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[N[(y * z), $MachinePrecision], (-Infinity)], N[Not[LessEqual[N[(y * z), $MachinePrecision], 5e+160]], $MachinePrecision]], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -\infty \lor \neg \left(y \cdot z \leq 5 \cdot 10^{+160}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 5.0000000000000002e160 < (*.f64 y z) Initial program 70.2%
Taylor expanded in y around inf 70.2%
mul-1-neg70.2%
associate-*r*99.9%
distribute-rgt-neg-in99.9%
*-commutative99.9%
associate-*l*99.5%
Simplified99.5%
if -inf.0 < (*.f64 y z) < 5.0000000000000002e160Initial program 99.9%
sub-neg99.9%
distribute-rgt-in99.9%
*-un-lft-identity99.9%
distribute-rgt-neg-in99.9%
Applied egg-rr99.9%
*-commutative99.9%
*-commutative99.9%
associate-*r*94.3%
distribute-rgt-neg-out94.3%
add-sqr-sqrt38.6%
sqrt-unprod66.6%
sqr-neg66.6%
sqrt-unprod35.8%
add-sqr-sqrt61.3%
cancel-sign-sub-inv61.3%
*-commutative61.3%
associate-*r*63.2%
*-commutative63.2%
add-sqr-sqrt35.5%
sqrt-unprod67.8%
sqr-neg67.8%
sqrt-unprod39.6%
add-sqr-sqrt93.6%
Applied egg-rr93.6%
Taylor expanded in z around 0 99.9%
Final simplification99.8%
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) (- INFINITY)) (not (<= (* y z) 5e+160))) (* y (* x (- z))) (* x (- 1.0 (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -((double) INFINITY)) || !((y * z) <= 5e+160)) {
tmp = y * (x * -z);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -Double.POSITIVE_INFINITY) || !((y * z) <= 5e+160)) {
tmp = y * (x * -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 ((y * z) <= -math.inf) or not ((y * z) <= 5e+160): tmp = y * (x * -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 ((Float64(y * z) <= Float64(-Inf)) || !(Float64(y * z) <= 5e+160)) tmp = Float64(y * Float64(x * Float64(-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 (((y * z) <= -Inf) || ~(((y * z) <= 5e+160)))
tmp = y * (x * -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[Or[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], N[Not[LessEqual[N[(y * z), $MachinePrecision], 5e+160]], $MachinePrecision]], N[(y * N[(x * (-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}\;y \cdot z \leq -\infty \lor \neg \left(y \cdot z \leq 5 \cdot 10^{+160}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 5.0000000000000002e160 < (*.f64 y z) Initial program 70.2%
Taylor expanded in y around inf 70.2%
mul-1-neg70.2%
associate-*r*99.9%
distribute-rgt-neg-in99.9%
*-commutative99.9%
associate-*l*99.5%
Simplified99.5%
if -inf.0 < (*.f64 y z) < 5.0000000000000002e160Initial program 99.9%
Final simplification99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -9500.0) (not (<= y 1.46e-89))) (* z (* y (- x))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -9500.0) || !(y <= 1.46e-89)) {
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 <= (-9500.0d0)) .or. (.not. (y <= 1.46d-89))) 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 <= -9500.0) || !(y <= 1.46e-89)) {
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 <= -9500.0) or not (y <= 1.46e-89): 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 <= -9500.0) || !(y <= 1.46e-89)) 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 <= -9500.0) || ~((y <= 1.46e-89)))
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, -9500.0], N[Not[LessEqual[y, 1.46e-89]], $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 -9500 \lor \neg \left(y \leq 1.46 \cdot 10^{-89}\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -9500 or 1.46e-89 < y Initial program 89.9%
sub-neg89.9%
distribute-rgt-in89.9%
*-un-lft-identity89.9%
distribute-rgt-neg-in89.9%
Applied egg-rr89.9%
*-commutative89.9%
*-commutative89.9%
associate-*r*97.2%
distribute-rgt-neg-out97.2%
add-sqr-sqrt38.9%
sqrt-unprod50.4%
sqr-neg50.4%
sqrt-unprod17.8%
add-sqr-sqrt29.7%
cancel-sign-sub-inv29.7%
*-commutative29.7%
associate-*r*28.3%
*-commutative28.3%
add-sqr-sqrt16.5%
sqrt-unprod49.1%
sqr-neg49.1%
sqrt-unprod40.3%
add-sqr-sqrt96.7%
Applied egg-rr96.7%
Taylor expanded in z around inf 60.9%
mul-1-neg60.9%
*-commutative60.9%
*-commutative60.9%
distribute-rgt-neg-in60.9%
associate-*r*69.0%
Simplified69.0%
if -9500 < y < 1.46e-89Initial program 99.9%
Taylor expanded in y around 0 83.3%
Final simplification74.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -6.5e-119) (not (<= z 1.65e+93))) (* y (* x (- z))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-119) || !(z <= 1.65e+93)) {
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 ((z <= (-6.5d-119)) .or. (.not. (z <= 1.65d+93))) 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 ((z <= -6.5e-119) || !(z <= 1.65e+93)) {
tmp = y * (x * -z);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -6.5e-119) or not (z <= 1.65e+93): 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 ((z <= -6.5e-119) || !(z <= 1.65e+93)) 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 ((z <= -6.5e-119) || ~((z <= 1.65e+93)))
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[z, -6.5e-119], N[Not[LessEqual[z, 1.65e+93]], $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}\;z \leq -6.5 \cdot 10^{-119} \lor \neg \left(z \leq 1.65 \cdot 10^{+93}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.5e-119 or 1.65000000000000004e93 < z Initial program 89.2%
Taylor expanded in y around inf 61.6%
mul-1-neg61.6%
associate-*r*67.0%
distribute-rgt-neg-in67.0%
*-commutative67.0%
associate-*l*70.8%
Simplified70.8%
if -6.5e-119 < z < 1.65000000000000004e93Initial program 99.9%
Taylor expanded in y around 0 81.2%
Final simplification75.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -6.5e-119) (not (<= z 2.3e+119))) (* (* y z) (- x)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-119) || !(z <= 2.3e+119)) {
tmp = (y * z) * -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 ((z <= (-6.5d-119)) .or. (.not. (z <= 2.3d+119))) then
tmp = (y * z) * -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 ((z <= -6.5e-119) || !(z <= 2.3e+119)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -6.5e-119) or not (z <= 2.3e+119): tmp = (y * z) * -x else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -6.5e-119) || !(z <= 2.3e+119)) tmp = Float64(Float64(y * z) * 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 ((z <= -6.5e-119) || ~((z <= 2.3e+119)))
tmp = (y * z) * -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[z, -6.5e-119], N[Not[LessEqual[z, 2.3e+119]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{-119} \lor \neg \left(z \leq 2.3 \cdot 10^{+119}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.5e-119 or 2.3000000000000001e119 < z Initial program 90.1%
Taylor expanded in y around inf 61.7%
mul-1-neg61.7%
distribute-rgt-neg-in61.7%
distribute-rgt-neg-out61.7%
Simplified61.7%
if -6.5e-119 < z < 2.3000000000000001e119Initial program 98.3%
Taylor expanded in y around 0 77.4%
Final simplification69.1%
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 94.0%
Taylor expanded in y around 0 52.6%
herbie shell --seed 2024116
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))