
(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 7 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) 1e+49) (- x (* (* y z) x)) (* z (* y (- x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 1e+49) {
tmp = x - ((y * z) * x);
} else {
tmp = z * (y * -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 * z) <= 1d+49) then
tmp = x - ((y * z) * x)
else
tmp = z * (y * -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 * z) <= 1e+49) {
tmp = x - ((y * z) * x);
} else {
tmp = z * (y * -x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 1e+49: tmp = x - ((y * z) * x) else: tmp = z * (y * -x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 1e+49) tmp = Float64(x - Float64(Float64(y * z) * x)); else tmp = Float64(z * Float64(y * Float64(-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) <= 1e+49)
tmp = x - ((y * z) * x);
else
tmp = z * (y * -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[LessEqual[N[(y * z), $MachinePrecision], 1e+49], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 10^{+49}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 9.99999999999999946e48Initial program 98.0%
sub-neg98.0%
distribute-rgt-in98.0%
*-un-lft-identity98.0%
distribute-rgt-neg-in98.0%
Applied egg-rr98.0%
associate-*l*94.8%
add-sqr-sqrt47.6%
sqrt-unprod73.1%
sqr-neg73.1%
sqrt-unprod32.7%
add-sqr-sqrt60.8%
cancel-sign-sub-inv60.8%
associate-*l*63.6%
*-commutative63.6%
*-commutative63.6%
distribute-lft-neg-out63.6%
distribute-rgt-neg-out63.6%
associate-*l*60.8%
add-sqr-sqrt32.7%
sqrt-unprod73.1%
sqr-neg73.1%
sqrt-unprod47.6%
add-sqr-sqrt94.8%
associate-*l*98.0%
*-commutative98.0%
Applied egg-rr98.0%
if 9.99999999999999946e48 < (*.f64 y z) Initial program 82.5%
Taylor expanded in z around inf 97.9%
Taylor expanded in y around inf 99.7%
neg-mul-199.7%
*-commutative99.7%
distribute-rgt-neg-in99.7%
Simplified99.7%
Final simplification98.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -1.9e-99) (not (<= z 1.55e+61))) (* z (* y (- x))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.9e-99) || !(z <= 1.55e+61)) {
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 ((z <= (-1.9d-99)) .or. (.not. (z <= 1.55d+61))) 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 ((z <= -1.9e-99) || !(z <= 1.55e+61)) {
tmp = z * (y * -x);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -1.9e-99) or not (z <= 1.55e+61): 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 ((z <= -1.9e-99) || !(z <= 1.55e+61)) 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 ((z <= -1.9e-99) || ~((z <= 1.55e+61)))
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[z, -1.9e-99], N[Not[LessEqual[z, 1.55e+61]], $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}\;z \leq -1.9 \cdot 10^{-99} \lor \neg \left(z \leq 1.55 \cdot 10^{+61}\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.8999999999999998e-99 or 1.55e61 < z Initial program 91.2%
Taylor expanded in z around inf 94.7%
Taylor expanded in y around inf 67.1%
neg-mul-167.1%
*-commutative67.1%
distribute-rgt-neg-in67.1%
Simplified67.1%
if -1.8999999999999998e-99 < z < 1.55e61Initial program 99.9%
Taylor expanded in y around 0 80.5%
Final simplification72.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -1.35e-100) (not (<= z 1.55e+61))) (* (* y z) (- x)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.35e-100) || !(z <= 1.55e+61)) {
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 <= (-1.35d-100)) .or. (.not. (z <= 1.55d+61))) 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 <= -1.35e-100) || !(z <= 1.55e+61)) {
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 <= -1.35e-100) or not (z <= 1.55e+61): 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 <= -1.35e-100) || !(z <= 1.55e+61)) 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 <= -1.35e-100) || ~((z <= 1.55e+61)))
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, -1.35e-100], N[Not[LessEqual[z, 1.55e+61]], $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 -1.35 \cdot 10^{-100} \lor \neg \left(z \leq 1.55 \cdot 10^{+61}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.35000000000000008e-100 or 1.55e61 < z Initial program 91.2%
Taylor expanded in y around inf 61.1%
mul-1-neg61.1%
distribute-rgt-neg-out61.1%
Simplified61.1%
if -1.35000000000000008e-100 < z < 1.55e61Initial program 99.9%
Taylor expanded in y around 0 80.6%
Final simplification69.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z -1.9e-99) (* y (- (* z x))) (if (<= z 1.6e+61) x (* z (* y (- x))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= -1.9e-99) {
tmp = y * -(z * x);
} else if (z <= 1.6e+61) {
tmp = x;
} else {
tmp = z * (y * -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 <= (-1.9d-99)) then
tmp = y * -(z * x)
else if (z <= 1.6d+61) then
tmp = x
else
tmp = z * (y * -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 <= -1.9e-99) {
tmp = y * -(z * x);
} else if (z <= 1.6e+61) {
tmp = x;
} else {
tmp = z * (y * -x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if z <= -1.9e-99: tmp = y * -(z * x) elif z <= 1.6e+61: tmp = x else: tmp = z * (y * -x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (z <= -1.9e-99) tmp = Float64(y * Float64(-Float64(z * x))); elseif (z <= 1.6e+61) tmp = x; else tmp = Float64(z * Float64(y * Float64(-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 <= -1.9e-99)
tmp = y * -(z * x);
elseif (z <= 1.6e+61)
tmp = x;
else
tmp = z * (y * -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[LessEqual[z, -1.9e-99], N[(y * (-N[(z * x), $MachinePrecision])), $MachinePrecision], If[LessEqual[z, 1.6e+61], x, N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.9 \cdot 10^{-99}:\\
\;\;\;\;y \cdot \left(-z \cdot x\right)\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{+61}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if z < -1.8999999999999998e-99Initial program 93.5%
Taylor expanded in y around inf 58.5%
mul-1-neg58.5%
*-commutative58.5%
associate-*r*62.2%
distribute-rgt-neg-in62.2%
Simplified62.2%
if -1.8999999999999998e-99 < z < 1.5999999999999999e61Initial program 99.9%
Taylor expanded in y around 0 80.5%
if 1.5999999999999999e61 < z Initial program 86.2%
Taylor expanded in z around inf 93.9%
Taylor expanded in y around inf 77.2%
neg-mul-177.2%
*-commutative77.2%
distribute-rgt-neg-in77.2%
Simplified77.2%
Final simplification72.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) 1e+49) (* x (- 1.0 (* y z))) (* z (* y (- x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 1e+49) {
tmp = x * (1.0 - (y * z));
} else {
tmp = z * (y * -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 * z) <= 1d+49) then
tmp = x * (1.0d0 - (y * z))
else
tmp = z * (y * -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 * z) <= 1e+49) {
tmp = x * (1.0 - (y * z));
} else {
tmp = z * (y * -x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 1e+49: tmp = x * (1.0 - (y * z)) else: tmp = z * (y * -x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 1e+49) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(z * Float64(y * Float64(-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) <= 1e+49)
tmp = x * (1.0 - (y * z));
else
tmp = z * (y * -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[LessEqual[N[(y * z), $MachinePrecision], 1e+49], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 10^{+49}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 9.99999999999999946e48Initial program 98.0%
if 9.99999999999999946e48 < (*.f64 y z) Initial program 82.5%
Taylor expanded in z around inf 97.9%
Taylor expanded in y around inf 99.7%
neg-mul-199.7%
*-commutative99.7%
distribute-rgt-neg-in99.7%
Simplified99.7%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z 1.82e+186) x (/ (* z x) z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= 1.82e+186) {
tmp = x;
} else {
tmp = (z * x) / 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 (z <= 1.82d+186) then
tmp = x
else
tmp = (z * x) / 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 (z <= 1.82e+186) {
tmp = x;
} else {
tmp = (z * x) / z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if z <= 1.82e+186: tmp = x else: tmp = (z * x) / z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (z <= 1.82e+186) tmp = x; else tmp = Float64(Float64(z * x) / z); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= 1.82e+186)
tmp = x;
else
tmp = (z * x) / 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[z, 1.82e+186], x, N[(N[(z * x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.82 \cdot 10^{+186}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{z \cdot x}{z}\\
\end{array}
\end{array}
if z < 1.8200000000000001e186Initial program 95.4%
Taylor expanded in y around 0 56.7%
if 1.8200000000000001e186 < z Initial program 88.0%
Taylor expanded in z around inf 91.8%
Taylor expanded in y around 0 2.8%
associate-*r/14.4%
Applied egg-rr14.4%
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.7%
Taylor expanded in y around 0 51.6%
herbie shell --seed 2024133
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))