
(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 (<= (* y z) (- INFINITY)) (* 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) <= -((double) INFINITY)) {
tmp = z * (-y * x);
} 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) {
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) <= -math.inf: 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) <= Float64(-Inf)) tmp = Float64(z * Float64(Float64(-y) * 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) <= -Inf)
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[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], 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 -\infty:\\
\;\;\;\;z \cdot \left(\left(-y\right) \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0Initial program 63.3%
sub-neg63.3%
distribute-rgt-in63.3%
*-un-lft-identity63.3%
distribute-rgt-neg-in63.3%
Applied egg-rr63.3%
Taylor expanded in y around 0 63.3%
mul-1-neg63.3%
associate-*r*99.8%
*-commutative99.8%
distribute-lft-neg-out99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
distribute-rgt-neg-in99.8%
*-commutative99.8%
distribute-lft-neg-out99.8%
unsub-neg99.8%
*-commutative99.8%
Applied egg-rr99.8%
Taylor expanded in z around inf 63.3%
mul-1-neg63.3%
*-commutative63.3%
*-commutative63.3%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
distribute-lft-neg-in99.8%
Simplified99.8%
if -inf.0 < (*.f64 y z) Initial program 98.7%
Final simplification98.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 -5.5e+40) (not (<= y 1.35e-108))) (* x (* y (- z))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.5e+40) || !(y <= 1.35e-108)) {
tmp = x * (y * -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 <= (-5.5d+40)) .or. (.not. (y <= 1.35d-108))) then
tmp = x * (y * -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 <= -5.5e+40) || !(y <= 1.35e-108)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y <= -5.5e+40) or not (y <= 1.35e-108): tmp = x * (y * -z) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -5.5e+40) || !(y <= 1.35e-108)) tmp = Float64(x * Float64(y * 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 <= -5.5e+40) || ~((y <= 1.35e-108)))
tmp = x * (y * -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, -5.5e+40], N[Not[LessEqual[y, 1.35e-108]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{+40} \lor \neg \left(y \leq 1.35 \cdot 10^{-108}\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.49999999999999974e40 or 1.35000000000000002e-108 < y Initial program 93.0%
Taylor expanded in y around inf 71.1%
mul-1-neg71.1%
distribute-rgt-neg-out71.1%
Simplified71.1%
if -5.49999999999999974e40 < y < 1.35000000000000002e-108Initial program 99.9%
Taylor expanded in y around 0 71.4%
Final simplification71.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -5.2e+37) (not (<= y 7e-106))) (* y (* x (- z))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e+37) || !(y <= 7e-106)) {
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 <= (-5.2d+37)) .or. (.not. (y <= 7d-106))) 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 <= -5.2e+37) || !(y <= 7e-106)) {
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 <= -5.2e+37) or not (y <= 7e-106): 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 <= -5.2e+37) || !(y <= 7e-106)) 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 <= -5.2e+37) || ~((y <= 7e-106)))
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, -5.2e+37], N[Not[LessEqual[y, 7e-106]], $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 -5.2 \cdot 10^{+37} \lor \neg \left(y \leq 7 \cdot 10^{-106}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.1999999999999998e37 or 7e-106 < y Initial program 93.0%
Taylor expanded in y around inf 70.6%
mul-1-neg70.6%
*-commutative70.6%
distribute-lft-neg-in70.6%
distribute-rgt-neg-out70.6%
associate-*l*73.2%
*-commutative73.2%
Simplified73.2%
if -5.1999999999999998e37 < y < 7e-106Initial program 99.9%
Taylor expanded in y around 0 71.2%
Final simplification72.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -5.2e+37) (not (<= y 7.4e-106))) (* z (* (- y) x)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e+37) || !(y <= 7.4e-106)) {
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 <= (-5.2d+37)) .or. (.not. (y <= 7.4d-106))) 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 <= -5.2e+37) || !(y <= 7.4e-106)) {
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 <= -5.2e+37) or not (y <= 7.4e-106): 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 <= -5.2e+37) || !(y <= 7.4e-106)) tmp = Float64(z * Float64(Float64(-y) * 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 <= -5.2e+37) || ~((y <= 7.4e-106)))
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, -5.2e+37], N[Not[LessEqual[y, 7.4e-106]], $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.2 \cdot 10^{+37} \lor \neg \left(y \leq 7.4 \cdot 10^{-106}\right):\\
\;\;\;\;z \cdot \left(\left(-y\right) \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.1999999999999998e37 or 7.39999999999999959e-106 < y Initial program 93.0%
sub-neg93.0%
distribute-rgt-in93.0%
*-un-lft-identity93.0%
distribute-rgt-neg-in93.0%
Applied egg-rr93.0%
Taylor expanded in y around 0 93.0%
mul-1-neg93.0%
associate-*r*94.1%
*-commutative94.1%
distribute-lft-neg-out94.1%
*-commutative94.1%
distribute-rgt-neg-in94.1%
Simplified94.1%
distribute-rgt-neg-in94.1%
*-commutative94.1%
distribute-lft-neg-out94.1%
unsub-neg94.1%
*-commutative94.1%
Applied egg-rr94.1%
Taylor expanded in z around inf 70.6%
mul-1-neg70.6%
*-commutative70.6%
*-commutative70.6%
associate-*r*73.8%
distribute-rgt-neg-in73.8%
distribute-lft-neg-in73.8%
Simplified73.8%
if -5.1999999999999998e37 < y < 7.39999999999999959e-106Initial program 99.9%
Taylor expanded in y around 0 71.2%
Final simplification72.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 96.2%
Taylor expanded in y around 0 46.4%
Final simplification46.4%
herbie shell --seed 2023330
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))