
(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) -1e+218) (* z (* y (- x))) (* x (fma z (- y) 1.0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -1e+218) {
tmp = z * (y * -x);
} else {
tmp = x * fma(z, -y, 1.0);
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -1e+218) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = Float64(x * fma(z, Float64(-y), 1.0)); end return 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+218], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], N[(x * N[(z * (-y) + 1.0), $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^{+218}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(z, -y, 1\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -1.00000000000000008e218Initial program 75.1%
Taylor expanded in z around inf 75.1%
add-sqr-sqrt30.7%
add-sqr-sqrt0.0%
difference-of-squares0.0%
inv-pow0.0%
sqrt-pow10.0%
metadata-eval0.0%
inv-pow0.0%
sqrt-pow10.0%
metadata-eval0.0%
Applied egg-rr0.0%
Taylor expanded in y around inf 75.1%
associate-*r*99.6%
associate-*r*99.6%
*-commutative99.6%
mul-1-neg99.6%
distribute-rgt-neg-out99.6%
Simplified99.6%
if -1.00000000000000008e218 < (*.f64 y z) Initial program 99.4%
cancel-sign-sub-inv99.4%
+-commutative99.4%
*-commutative99.4%
fma-define99.4%
Simplified99.4%
Final simplification99.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 -4.1e-132) (not (<= z 2.8e+54))) (* (* y z) (- x)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.1e-132) || !(z <= 2.8e+54)) {
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 <= (-4.1d-132)) .or. (.not. (z <= 2.8d+54))) 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 <= -4.1e-132) || !(z <= 2.8e+54)) {
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 <= -4.1e-132) or not (z <= 2.8e+54): 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 <= -4.1e-132) || !(z <= 2.8e+54)) 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 <= -4.1e-132) || ~((z <= 2.8e+54)))
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, -4.1e-132], N[Not[LessEqual[z, 2.8e+54]], $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 -4.1 \cdot 10^{-132} \lor \neg \left(z \leq 2.8 \cdot 10^{+54}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.10000000000000007e-132 or 2.80000000000000015e54 < z Initial program 94.8%
Taylor expanded in y around inf 69.4%
associate-*r*69.4%
mul-1-neg69.4%
Simplified69.4%
if -4.10000000000000007e-132 < z < 2.80000000000000015e54Initial program 99.9%
Taylor expanded in y around 0 77.2%
Final simplification73.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -4.1e-132) (not (<= z 4.9e+54))) (* y (* z (- x))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.1e-132) || !(z <= 4.9e+54)) {
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 <= (-4.1d-132)) .or. (.not. (z <= 4.9d+54))) 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 <= -4.1e-132) || !(z <= 4.9e+54)) {
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 <= -4.1e-132) or not (z <= 4.9e+54): 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 <= -4.1e-132) || !(z <= 4.9e+54)) tmp = Float64(y * Float64(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 <= -4.1e-132) || ~((z <= 4.9e+54)))
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, -4.1e-132], N[Not[LessEqual[z, 4.9e+54]], $MachinePrecision]], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.1 \cdot 10^{-132} \lor \neg \left(z \leq 4.9 \cdot 10^{+54}\right):\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.10000000000000007e-132 or 4.90000000000000001e54 < z Initial program 94.8%
Taylor expanded in y around inf 69.4%
mul-1-neg69.4%
*-commutative69.4%
associate-*l*66.9%
*-commutative66.9%
distribute-rgt-neg-in66.9%
distribute-rgt-neg-in66.9%
Simplified66.9%
if -4.10000000000000007e-132 < z < 4.90000000000000001e54Initial program 99.9%
Taylor expanded in y around 0 77.2%
Final simplification71.8%
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+218) (* 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+218) {
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+218)) 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+218) {
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+218: 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+218) 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+218)
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], -1e+218], 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^{+218}:\\
\;\;\;\;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.00000000000000008e218Initial program 75.1%
Taylor expanded in z around inf 75.1%
add-sqr-sqrt30.7%
add-sqr-sqrt0.0%
difference-of-squares0.0%
inv-pow0.0%
sqrt-pow10.0%
metadata-eval0.0%
inv-pow0.0%
sqrt-pow10.0%
metadata-eval0.0%
Applied egg-rr0.0%
Taylor expanded in y around inf 75.1%
associate-*r*99.6%
associate-*r*99.6%
*-commutative99.6%
mul-1-neg99.6%
distribute-rgt-neg-out99.6%
Simplified99.6%
if -1.00000000000000008e218 < (*.f64 y z) Initial program 99.4%
Final simplification99.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 97.2%
Taylor expanded in y around 0 50.7%
Final simplification50.7%
herbie shell --seed 2024059
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))