
(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 (<= (* z y) (- INFINITY)) (* z (* x (- y))) (if (<= (* z y) 5e+119) (* x (- 1.0 (* z y))) (* y (* x (- z))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z * y) <= -((double) INFINITY)) {
tmp = z * (x * -y);
} else if ((z * y) <= 5e+119) {
tmp = x * (1.0 - (z * y));
} else {
tmp = y * (x * -z);
}
return tmp;
}
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z * y) <= -Double.POSITIVE_INFINITY) {
tmp = z * (x * -y);
} else if ((z * y) <= 5e+119) {
tmp = x * (1.0 - (z * y));
} else {
tmp = y * (x * -z);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z * y) <= -math.inf: tmp = z * (x * -y) elif (z * y) <= 5e+119: tmp = x * (1.0 - (z * y)) else: tmp = y * (x * -z) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(z * y) <= Float64(-Inf)) tmp = Float64(z * Float64(x * Float64(-y))); elseif (Float64(z * y) <= 5e+119) tmp = Float64(x * Float64(1.0 - Float64(z * y))); else tmp = Float64(y * Float64(x * Float64(-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 * y) <= -Inf)
tmp = z * (x * -y);
elseif ((z * y) <= 5e+119)
tmp = x * (1.0 - (z * y));
else
tmp = y * (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[N[(z * y), $MachinePrecision], (-Infinity)], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * y), $MachinePrecision], 5e+119], N[(x * N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot y \leq -\infty:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{elif}\;z \cdot y \leq 5 \cdot 10^{+119}:\\
\;\;\;\;x \cdot \left(1 - z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0Initial program 63.6%
Taylor expanded in y around inf
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6463.6
Simplified63.6%
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
neg-lowering-neg.f6499.9
Applied egg-rr99.9%
if -inf.0 < (*.f64 y z) < 4.9999999999999999e119Initial program 99.9%
if 4.9999999999999999e119 < (*.f64 y z) Initial program 89.1%
Taylor expanded in y around inf
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6495.5
Simplified95.5%
Final simplification99.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (* y (* x (- z))))) (if (<= (* z y) -4000.0) t_0 (if (<= (* z y) 1e-9) x t_0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = y * (x * -z);
double tmp;
if ((z * y) <= -4000.0) {
tmp = t_0;
} else if ((z * y) <= 1e-9) {
tmp = x;
} 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 = y * (x * -z)
if ((z * y) <= (-4000.0d0)) then
tmp = t_0
else if ((z * y) <= 1d-9) then
tmp = x
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 = y * (x * -z);
double tmp;
if ((z * y) <= -4000.0) {
tmp = t_0;
} else if ((z * y) <= 1e-9) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = y * (x * -z) tmp = 0 if (z * y) <= -4000.0: tmp = t_0 elif (z * y) <= 1e-9: tmp = x else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(y * Float64(x * Float64(-z))) tmp = 0.0 if (Float64(z * y) <= -4000.0) tmp = t_0; elseif (Float64(z * y) <= 1e-9) tmp = x; 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 = y * (x * -z);
tmp = 0.0;
if ((z * y) <= -4000.0)
tmp = t_0;
elseif ((z * y) <= 1e-9)
tmp = x;
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[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * y), $MachinePrecision], -4000.0], t$95$0, If[LessEqual[N[(z * y), $MachinePrecision], 1e-9], x, t$95$0]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{if}\;z \cdot y \leq -4000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \cdot y \leq 10^{-9}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -4e3 or 1.00000000000000006e-9 < (*.f64 y z) Initial program 90.6%
Taylor expanded in y around inf
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6491.7
Simplified91.7%
if -4e3 < (*.f64 y z) < 1.00000000000000006e-9Initial program 100.0%
Taylor expanded in y around 0
Simplified97.5%
Final simplification94.3%
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 y))))) (if (<= (* z y) -4000.0) t_0 (if (<= (* z y) 1e-9) x t_0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = -(x * (z * y));
double tmp;
if ((z * y) <= -4000.0) {
tmp = t_0;
} else if ((z * y) <= 1e-9) {
tmp = x;
} 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 = -(x * (z * y))
if ((z * y) <= (-4000.0d0)) then
tmp = t_0
else if ((z * y) <= 1d-9) then
tmp = x
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 = -(x * (z * y));
double tmp;
if ((z * y) <= -4000.0) {
tmp = t_0;
} else if ((z * y) <= 1e-9) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = -(x * (z * y)) tmp = 0 if (z * y) <= -4000.0: tmp = t_0 elif (z * y) <= 1e-9: tmp = x else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(-Float64(x * Float64(z * y))) tmp = 0.0 if (Float64(z * y) <= -4000.0) tmp = t_0; elseif (Float64(z * y) <= 1e-9) tmp = x; 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 * y));
tmp = 0.0;
if ((z * y) <= -4000.0)
tmp = t_0;
elseif ((z * y) <= 1e-9)
tmp = x;
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 * y), $MachinePrecision]), $MachinePrecision])}, If[LessEqual[N[(z * y), $MachinePrecision], -4000.0], t$95$0, If[LessEqual[N[(z * y), $MachinePrecision], 1e-9], x, t$95$0]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := -x \cdot \left(z \cdot y\right)\\
\mathbf{if}\;z \cdot y \leq -4000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \cdot y \leq 10^{-9}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -4e3 or 1.00000000000000006e-9 < (*.f64 y z) Initial program 90.6%
Taylor expanded in y around inf
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6488.1
Simplified88.1%
if -4e3 < (*.f64 y z) < 1.00000000000000006e-9Initial program 100.0%
Taylor expanded in y around 0
Simplified97.5%
Final simplification92.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x 100.0) (fma (* x (- z)) y x) (* x (- 1.0 (* z y)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 100.0) {
tmp = fma((x * -z), y, x);
} 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 <= 100.0) tmp = fma(Float64(x * Float64(-z)), y, x); else tmp = Float64(x * Float64(1.0 - Float64(z * y))); 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[x, 100.0], N[(N[(x * (-z)), $MachinePrecision] * y + x), $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 100:\\
\;\;\;\;\mathsf{fma}\left(x \cdot \left(-z\right), y, x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z \cdot y\right)\\
\end{array}
\end{array}
if x < 100Initial program 93.0%
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-*r*N/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
neg-lowering-neg.f6494.9
Applied egg-rr94.9%
if 100 < x Initial program 100.0%
Final simplification96.2%
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.8%
Taylor expanded in y around 0
Simplified45.7%
herbie shell --seed 2024205
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))