
(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
(let* ((t_0 (- x (* z (* x y)))))
(if (<= (* z y) (- INFINITY))
t_0
(if (<= (* z y) 5e+190) (* x (- 1.0 (* z y))) t_0))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = x - (z * (x * y));
double tmp;
if ((z * y) <= -((double) INFINITY)) {
tmp = t_0;
} else if ((z * y) <= 5e+190) {
tmp = x * (1.0 - (z * y));
} else {
tmp = t_0;
}
return tmp;
}
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = x - (z * (x * y));
double tmp;
if ((z * y) <= -Double.POSITIVE_INFINITY) {
tmp = t_0;
} else if ((z * y) <= 5e+190) {
tmp = x * (1.0 - (z * y));
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = x - (z * (x * y)) tmp = 0 if (z * y) <= -math.inf: tmp = t_0 elif (z * y) <= 5e+190: tmp = x * (1.0 - (z * y)) else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(x - Float64(z * Float64(x * y))) tmp = 0.0 if (Float64(z * y) <= Float64(-Inf)) tmp = t_0; elseif (Float64(z * y) <= 5e+190) tmp = Float64(x * Float64(1.0 - Float64(z * y))); else tmp = t_0; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = x - (z * (x * y));
tmp = 0.0;
if ((z * y) <= -Inf)
tmp = t_0;
elseif ((z * y) <= 5e+190)
tmp = x * (1.0 - (z * y));
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(x - N[(z * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * y), $MachinePrecision], (-Infinity)], t$95$0, If[LessEqual[N[(z * y), $MachinePrecision], 5e+190], N[(x * N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := x - z \cdot \left(x \cdot y\right)\\
\mathbf{if}\;z \cdot y \leq -\infty:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \cdot y \leq 5 \cdot 10^{+190}:\\
\;\;\;\;x \cdot \left(1 - z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 5.00000000000000036e190 < (*.f64 y z) Initial program 70.5%
sub-negN/A
distribute-rgt-inN/A
fma-defineN/A
distribute-lft-neg-outN/A
fmm-undefN/A
*-lft-identityN/A
--lowering--.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6470.5%
Applied egg-rr70.5%
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.9%
Applied egg-rr99.9%
if -inf.0 < (*.f64 y z) < 5.00000000000000036e190Initial program 99.9%
Final simplification99.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 0.0 (* (* x z) y))))
(if (<= (* z y) -1e+227)
t_0
(if (<= (* z y) 2e+114) (* x (- 1.0 (* z y))) t_0))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 0.0 - ((x * z) * y);
double tmp;
if ((z * y) <= -1e+227) {
tmp = t_0;
} else if ((z * y) <= 2e+114) {
tmp = x * (1.0 - (z * y));
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = 0.0d0 - ((x * z) * y)
if ((z * y) <= (-1d+227)) then
tmp = t_0
else if ((z * y) <= 2d+114) then
tmp = x * (1.0d0 - (z * y))
else
tmp = t_0
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = 0.0 - ((x * z) * y);
double tmp;
if ((z * y) <= -1e+227) {
tmp = t_0;
} else if ((z * y) <= 2e+114) {
tmp = x * (1.0 - (z * y));
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = 0.0 - ((x * z) * y) tmp = 0 if (z * y) <= -1e+227: tmp = t_0 elif (z * y) <= 2e+114: tmp = x * (1.0 - (z * y)) else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(0.0 - Float64(Float64(x * z) * y)) tmp = 0.0 if (Float64(z * y) <= -1e+227) tmp = t_0; elseif (Float64(z * y) <= 2e+114) tmp = Float64(x * Float64(1.0 - Float64(z * y))); else tmp = t_0; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = 0.0 - ((x * z) * y);
tmp = 0.0;
if ((z * y) <= -1e+227)
tmp = t_0;
elseif ((z * y) <= 2e+114)
tmp = x * (1.0 - (z * y));
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(0.0 - N[(N[(x * z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * y), $MachinePrecision], -1e+227], t$95$0, If[LessEqual[N[(z * y), $MachinePrecision], 2e+114], N[(x * N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 0 - \left(x \cdot z\right) \cdot y\\
\mathbf{if}\;z \cdot y \leq -1 \cdot 10^{+227}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \cdot y \leq 2 \cdot 10^{+114}:\\
\;\;\;\;x \cdot \left(1 - z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -1.0000000000000001e227 or 2e114 < (*.f64 y z) Initial program 80.5%
Taylor expanded in y around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6497.2%
Simplified97.2%
if -1.0000000000000001e227 < (*.f64 y z) < 2e114Initial program 99.9%
Final simplification99.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x 1e+27) (- x (* (* x z) y)) (* x (- 1.0 (* z y)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 1e+27) {
tmp = x - ((x * z) * y);
} else {
tmp = x * (1.0 - (z * y));
}
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 (x <= 1d+27) then
tmp = x - ((x * z) * y)
else
tmp = x * (1.0d0 - (z * y))
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (x <= 1e+27) {
tmp = x - ((x * z) * y);
} else {
tmp = x * (1.0 - (z * y));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= 1e+27: tmp = x - ((x * z) * y) else: tmp = x * (1.0 - (z * y)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= 1e+27) tmp = Float64(x - Float64(Float64(x * z) * y)); else tmp = Float64(x * Float64(1.0 - Float64(z * y))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= 1e+27)
tmp = x - ((x * z) * y);
else
tmp = x * (1.0 - (z * y));
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[x, 1e+27], N[(x - N[(N[(x * z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{+27}:\\
\;\;\;\;x - \left(x \cdot z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z \cdot y\right)\\
\end{array}
\end{array}
if x < 1e27Initial program 92.7%
sub-negN/A
distribute-rgt-inN/A
fma-defineN/A
distribute-lft-neg-outN/A
fmm-undefN/A
*-lft-identityN/A
--lowering--.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6492.7%
Applied egg-rr92.7%
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6495.4%
Applied egg-rr95.4%
if 1e27 < x Initial program 99.9%
Final simplification96.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* x (- 1.0 (* z y))))
assert(x < y && y < z);
double code(double x, double y, double z) {
return x * (1.0 - (z * y));
}
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 * (1.0d0 - (z * y))
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x * (1.0 - (z * y));
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x * (1.0 - (z * y))
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(x * Float64(1.0 - Float64(z * y))) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x * (1.0 - (z * y));
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot \left(1 - z \cdot y\right)
\end{array}
Initial program 94.4%
Final simplification94.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.4%
Taylor expanded in y around 0
Simplified53.7%
herbie shell --seed 2024150
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))