
(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 6 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 (fma (- 0.0 y) (* x z) x)))
(if (<= (* z y) (- INFINITY))
t_0
(if (<= (* z y) 1e+141) (- x (* x (* z y))) t_0))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = fma((0.0 - y), (x * z), x);
double tmp;
if ((z * y) <= -((double) INFINITY)) {
tmp = t_0;
} else if ((z * y) <= 1e+141) {
tmp = x - (x * (z * y));
} else {
tmp = t_0;
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = fma(Float64(0.0 - y), Float64(x * z), x) tmp = 0.0 if (Float64(z * y) <= Float64(-Inf)) tmp = t_0; elseif (Float64(z * y) <= 1e+141) tmp = Float64(x - Float64(x * Float64(z * y))); else tmp = t_0; end return 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[(N[(0.0 - y), $MachinePrecision] * N[(x * z), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[N[(z * y), $MachinePrecision], (-Infinity)], t$95$0, If[LessEqual[N[(z * y), $MachinePrecision], 1e+141], N[(x - N[(x * 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 := \mathsf{fma}\left(0 - y, x \cdot z, x\right)\\
\mathbf{if}\;z \cdot y \leq -\infty:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \cdot y \leq 10^{+141}:\\
\;\;\;\;x - x \cdot \left(z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 1.00000000000000002e141 < (*.f64 y z) Initial program 84.6%
sub-negN/A
+-commutativeN/A
distribute-rgt-inN/A
distribute-lft-neg-inN/A
associate-*l*N/A
*-lft-identityN/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f6498.3
Applied egg-rr98.3%
sub0-negN/A
neg-lowering-neg.f6498.3
Applied egg-rr98.3%
if -inf.0 < (*.f64 y z) < 1.00000000000000002e141Initial program 99.8%
sub-negN/A
distribute-rgt-inN/A
*-lft-identityN/A
distribute-lft-neg-outN/A
unsub-negN/A
--lowering--.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.8
Applied egg-rr99.8%
Final simplification99.5%
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) -1.0) t_0 (if (<= (* z y) 1.0) x 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) <= -1.0) {
tmp = t_0;
} else if ((z * y) <= 1.0) {
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 = 0.0d0 - (x * (z * y))
if ((z * y) <= (-1.0d0)) then
tmp = t_0
else if ((z * y) <= 1.0d0) 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 = 0.0 - (x * (z * y));
double tmp;
if ((z * y) <= -1.0) {
tmp = t_0;
} else if ((z * y) <= 1.0) {
tmp = x;
} 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) <= -1.0: tmp = t_0 elif (z * y) <= 1.0: tmp = x else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(0.0 - Float64(x * Float64(z * y))) tmp = 0.0 if (Float64(z * y) <= -1.0) tmp = t_0; elseif (Float64(z * y) <= 1.0) 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 = 0.0 - (x * (z * y));
tmp = 0.0;
if ((z * y) <= -1.0)
tmp = t_0;
elseif ((z * y) <= 1.0)
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[(0.0 - N[(x * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * y), $MachinePrecision], -1.0], t$95$0, If[LessEqual[N[(z * y), $MachinePrecision], 1.0], x, t$95$0]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 0 - x \cdot \left(z \cdot y\right)\\
\mathbf{if}\;z \cdot y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \cdot y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -1 or 1 < (*.f64 y z) Initial program 92.7%
sub-negN/A
distribute-rgt-inN/A
*-lft-identityN/A
distribute-lft-neg-outN/A
unsub-negN/A
--lowering--.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6492.7
Applied egg-rr92.7%
associate-*l*N/A
cancel-sign-sub-invN/A
sub0-negN/A
associate-*r*N/A
distribute-rgt1-inN/A
sub0-negN/A
distribute-lft-neg-inN/A
neg-sub0N/A
associate-+l-N/A
flip--N/A
metadata-evalN/A
sub-negN/A
swap-sqrN/A
metadata-evalN/A
associate-*r*N/A
neg-sub0N/A
distribute-frac-negN/A
Applied egg-rr92.6%
Taylor expanded in y around inf
/-lowering-/.f64N/A
*-lowering-*.f6489.9
Simplified89.9%
clear-numN/A
associate-/l/N/A
frac-2negN/A
metadata-evalN/A
div-invN/A
neg-mul-1N/A
neg-lowering-neg.f64N/A
distribute-frac-neg2N/A
associate-/r/N/A
metadata-evalN/A
neg-mul-1N/A
remove-double-negN/A
*-lowering-*.f64N/A
*-lowering-*.f6490.0
Applied egg-rr90.0%
if -1 < (*.f64 y z) < 1Initial program 100.0%
Taylor expanded in y around 0
Simplified97.4%
Final simplification93.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x 20000000000.0) (fma (- 0.0 z) (* x y) x) (- x (* x (* z y)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 20000000000.0) {
tmp = fma((0.0 - z), (x * y), x);
} else {
tmp = x - (x * (z * y));
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= 20000000000.0) tmp = fma(Float64(0.0 - z), Float64(x * y), x); else tmp = Float64(x - Float64(x * 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, 20000000000.0], N[(N[(0.0 - z), $MachinePrecision] * N[(x * y), $MachinePrecision] + x), $MachinePrecision], N[(x - N[(x * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 20000000000:\\
\;\;\;\;\mathsf{fma}\left(0 - z, x \cdot y, x\right)\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot \left(z \cdot y\right)\\
\end{array}
\end{array}
if x < 2e10Initial program 94.7%
sub-negN/A
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-*l*N/A
*-lft-identityN/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f6495.7
Applied egg-rr95.7%
sub0-negN/A
neg-lowering-neg.f6495.7
Applied egg-rr95.7%
if 2e10 < x Initial program 99.8%
sub-negN/A
distribute-rgt-inN/A
*-lft-identityN/A
distribute-lft-neg-outN/A
unsub-negN/A
--lowering--.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.8
Applied egg-rr99.8%
Final simplification96.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- x (* x (* z y))))
assert(x < y && y < z);
double code(double x, double y, double z) {
return x - (x * (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 - (x * (z * y))
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x - (x * (z * y));
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x - (x * (z * y))
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(x - Float64(x * Float64(z * y))) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x - (x * (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[(x * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x - x \cdot \left(z \cdot y\right)
\end{array}
Initial program 96.1%
sub-negN/A
distribute-rgt-inN/A
*-lft-identityN/A
distribute-lft-neg-outN/A
unsub-negN/A
--lowering--.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6496.1
Applied egg-rr96.1%
Final simplification96.1%
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 96.1%
Final simplification96.1%
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 96.1%
Taylor expanded in y around 0
Simplified47.8%
herbie shell --seed 2024198
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))