
(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 4 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: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- 1.0 (* y z))))) (if (<= t_0 (- INFINITY)) (* z (* y (- x))) t_0)))
assert(y < z);
double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = z * (y * -x);
} else {
tmp = t_0;
}
return tmp;
}
assert y < z;
public static double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = z * (y * -x);
} else {
tmp = t_0;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): t_0 = x * (1.0 - (y * z)) tmp = 0 if t_0 <= -math.inf: tmp = z * (y * -x) else: tmp = t_0 return tmp
y, z = sort([y, z]) function code(x, y, z) t_0 = Float64(x * Float64(1.0 - Float64(y * z))) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = t_0; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = x * (1.0 - (y * z));
tmp = 0.0;
if (t_0 <= -Inf)
tmp = z * (y * -x);
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - y \cdot z\right)\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < -inf.0Initial program 71.0%
*-commutative71.0%
flip--42.3%
associate-*l/42.3%
metadata-eval42.3%
pow242.3%
Applied egg-rr42.3%
unpow242.3%
*-commutative42.3%
*-commutative42.3%
swap-sqr42.3%
Applied egg-rr42.3%
Taylor expanded in z around inf 42.3%
mul-1-neg42.3%
unpow242.3%
*-commutative42.3%
unpow242.3%
Simplified42.3%
Taylor expanded in y around inf 99.9%
mul-1-neg99.9%
*-commutative99.9%
associate-*r*99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
if -inf.0 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 98.6%
Final simplification98.7%
NOTE: y and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (or (<= z -7.8e-110)
(not (or (<= z 1.8e-6) (and (not (<= z 3.2e+15)) (<= z 3.7e+34)))))
(* x (* y (- z)))
x))assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.8e-110) || !((z <= 1.8e-6) || (!(z <= 3.2e+15) && (z <= 3.7e+34)))) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
NOTE: 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 <= (-7.8d-110)) .or. (.not. (z <= 1.8d-6) .or. (.not. (z <= 3.2d+15)) .and. (z <= 3.7d+34))) then
tmp = x * (y * -z)
else
tmp = x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -7.8e-110) || !((z <= 1.8e-6) || (!(z <= 3.2e+15) && (z <= 3.7e+34)))) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (z <= -7.8e-110) or not ((z <= 1.8e-6) or (not (z <= 3.2e+15) and (z <= 3.7e+34))): tmp = x * (y * -z) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -7.8e-110) || !((z <= 1.8e-6) || (!(z <= 3.2e+15) && (z <= 3.7e+34)))) tmp = Float64(x * Float64(y * Float64(-z))); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -7.8e-110) || ~(((z <= 1.8e-6) || (~((z <= 3.2e+15)) && (z <= 3.7e+34)))))
tmp = x * (y * -z);
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[z, -7.8e-110], N[Not[Or[LessEqual[z, 1.8e-6], And[N[Not[LessEqual[z, 3.2e+15]], $MachinePrecision], LessEqual[z, 3.7e+34]]]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.8 \cdot 10^{-110} \lor \neg \left(z \leq 1.8 \cdot 10^{-6} \lor \neg \left(z \leq 3.2 \cdot 10^{+15}\right) \land z \leq 3.7 \cdot 10^{+34}\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.8e-110 or 1.79999999999999992e-6 < z < 3.2e15 or 3.70000000000000009e34 < z Initial program 92.9%
Taylor expanded in y around inf 72.6%
mul-1-neg72.6%
associate-*r*68.8%
distribute-lft-neg-in68.8%
distribute-rgt-neg-out68.8%
*-commutative68.8%
Simplified68.8%
if -7.8e-110 < z < 1.79999999999999992e-6 or 3.2e15 < z < 3.70000000000000009e34Initial program 100.0%
Taylor expanded in y around 0 77.9%
Final simplification72.5%
NOTE: y and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (or (<= z -2.1e-109)
(not (or (<= z 1.82e-6) (and (not (<= z 5.5e+15)) (<= z 7e+34)))))
(* y (* x (- z)))
x))assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.1e-109) || !((z <= 1.82e-6) || (!(z <= 5.5e+15) && (z <= 7e+34)))) {
tmp = y * (x * -z);
} else {
tmp = x;
}
return tmp;
}
NOTE: 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 <= (-2.1d-109)) .or. (.not. (z <= 1.82d-6) .or. (.not. (z <= 5.5d+15)) .and. (z <= 7d+34))) then
tmp = y * (x * -z)
else
tmp = x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.1e-109) || !((z <= 1.82e-6) || (!(z <= 5.5e+15) && (z <= 7e+34)))) {
tmp = y * (x * -z);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (z <= -2.1e-109) or not ((z <= 1.82e-6) or (not (z <= 5.5e+15) and (z <= 7e+34))): tmp = y * (x * -z) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -2.1e-109) || !((z <= 1.82e-6) || (!(z <= 5.5e+15) && (z <= 7e+34)))) tmp = Float64(y * Float64(x * Float64(-z))); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -2.1e-109) || ~(((z <= 1.82e-6) || (~((z <= 5.5e+15)) && (z <= 7e+34)))))
tmp = y * (x * -z);
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[z, -2.1e-109], N[Not[Or[LessEqual[z, 1.82e-6], And[N[Not[LessEqual[z, 5.5e+15]], $MachinePrecision], LessEqual[z, 7e+34]]]], $MachinePrecision]], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.1 \cdot 10^{-109} \lor \neg \left(z \leq 1.82 \cdot 10^{-6} \lor \neg \left(z \leq 5.5 \cdot 10^{+15}\right) \land z \leq 7 \cdot 10^{+34}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.09999999999999996e-109 or 1.8199999999999999e-6 < z < 5.5e15 or 6.99999999999999996e34 < z Initial program 92.9%
Taylor expanded in y around inf 72.6%
mul-1-neg72.6%
distribute-rgt-neg-in72.6%
distribute-lft-neg-out72.6%
*-commutative72.6%
Simplified72.6%
if -2.09999999999999996e-109 < z < 1.8199999999999999e-6 or 5.5e15 < z < 6.99999999999999996e34Initial program 100.0%
Taylor expanded in y around 0 77.9%
Final simplification74.8%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(y < z);
double code(double x, double y, double z) {
return x;
}
NOTE: 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 y < z;
public static double code(double x, double y, double z) {
return x;
}
[y, z] = sort([y, z]) def code(x, y, z): return x
y, z = sort([y, z]) function code(x, y, z) return x end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x
\end{array}
Initial program 95.8%
Taylor expanded in y around 0 47.4%
Final simplification47.4%
herbie shell --seed 2023195
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))