
(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 (if (<= (* y z) -2e+129) (* y (* x (- z))) (* x (- 1.0 (* y z)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2e+129) {
tmp = y * (x * -z);
} else {
tmp = x * (1.0 - (y * z));
}
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 ((y * z) <= (-2d+129)) then
tmp = y * (x * -z)
else
tmp = x * (1.0d0 - (y * z))
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2e+129) {
tmp = y * (x * -z);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -2e+129: tmp = y * (x * -z) else: tmp = x * (1.0 - (y * z)) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -2e+129) tmp = Float64(y * Float64(x * Float64(-z))); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= -2e+129)
tmp = y * (x * -z);
else
tmp = x * (1.0 - (y * z));
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -2e+129], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -2 \cdot 10^{+129}:\\
\;\;\;\;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) < -2e129Initial program 78.1%
Taylor expanded in y around inf 97.0%
mul-1-neg97.0%
distribute-rgt-neg-in97.0%
distribute-lft-neg-out97.0%
*-commutative97.0%
Simplified97.0%
if -2e129 < (*.f64 y z) Initial program 98.2%
Final simplification98.0%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -1.42e+107) (not (<= y 4.8e-149))) (* x (* z (- y))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.42e+107) || !(y <= 4.8e-149)) {
tmp = x * (z * -y);
} 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 ((y <= (-1.42d+107)) .or. (.not. (y <= 4.8d-149))) then
tmp = x * (z * -y)
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 ((y <= -1.42e+107) || !(y <= 4.8e-149)) {
tmp = x * (z * -y);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y <= -1.42e+107) or not (y <= 4.8e-149): tmp = x * (z * -y) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -1.42e+107) || !(y <= 4.8e-149)) tmp = Float64(x * Float64(z * Float64(-y))); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= -1.42e+107) || ~((y <= 4.8e-149)))
tmp = x * (z * -y);
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[y, -1.42e+107], N[Not[LessEqual[y, 4.8e-149]], $MachinePrecision]], N[(x * N[(z * (-y)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.42 \cdot 10^{+107} \lor \neg \left(y \leq 4.8 \cdot 10^{-149}\right):\\
\;\;\;\;x \cdot \left(z \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.42000000000000006e107 or 4.8000000000000002e-149 < y Initial program 92.6%
Taylor expanded in y around inf 69.7%
mul-1-neg69.7%
associate-*r*67.8%
distribute-lft-neg-in67.8%
distribute-rgt-neg-out67.8%
*-commutative67.8%
Simplified67.8%
if -1.42000000000000006e107 < y < 4.8000000000000002e-149Initial program 99.1%
Taylor expanded in y around 0 76.4%
Final simplification71.7%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -1.1e+98) (not (<= y 5.5e-175))) (* y (* x (- z))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.1e+98) || !(y <= 5.5e-175)) {
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 ((y <= (-1.1d+98)) .or. (.not. (y <= 5.5d-175))) 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 ((y <= -1.1e+98) || !(y <= 5.5e-175)) {
tmp = y * (x * -z);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y <= -1.1e+98) or not (y <= 5.5e-175): tmp = y * (x * -z) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -1.1e+98) || !(y <= 5.5e-175)) 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 ((y <= -1.1e+98) || ~((y <= 5.5e-175)))
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[y, -1.1e+98], N[Not[LessEqual[y, 5.5e-175]], $MachinePrecision]], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+98} \lor \neg \left(y \leq 5.5 \cdot 10^{-175}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.10000000000000004e98 or 5.50000000000000054e-175 < y Initial program 92.5%
Taylor expanded in y around inf 68.1%
mul-1-neg68.1%
distribute-rgt-neg-in68.1%
distribute-lft-neg-out68.1%
*-commutative68.1%
Simplified68.1%
if -1.10000000000000004e98 < y < 5.50000000000000054e-175Initial program 100.0%
Taylor expanded in y around 0 80.1%
Final simplification73.0%
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.5%
Taylor expanded in y around 0 49.0%
Final simplification49.0%
herbie shell --seed 2023230
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))