
(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: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* z y) 4e+107) (* (- 1.0 (* z y)) x) (fma (* (- y) x) z x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z * y) <= 4e+107) {
tmp = (1.0 - (z * y)) * x;
} else {
tmp = fma((-y * x), z, x);
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(z * y) <= 4e+107) tmp = Float64(Float64(1.0 - Float64(z * y)) * x); else tmp = fma(Float64(Float64(-y) * x), z, x); 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[N[(z * y), $MachinePrecision], 4e+107], N[(N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], N[(N[((-y) * x), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot y \leq 4 \cdot 10^{+107}:\\
\;\;\;\;\left(1 - z \cdot y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(-y\right) \cdot x, z, x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 3.9999999999999999e107Initial program 98.5%
if 3.9999999999999999e107 < (*.f64 y z) Initial program 81.4%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6499.8
Applied rewrites99.8%
Final simplification98.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (- 1.0 (* z y))) (t_1 (* (* (- y) z) x))) (if (<= t_0 -5000.0) t_1 (if (<= t_0 2.0) (* 1.0 x) t_1))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 1.0 - (z * y);
double t_1 = (-y * z) * x;
double tmp;
if (t_0 <= -5000.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = 1.0 * x;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - (z * y)
t_1 = (-y * z) * x
if (t_0 <= (-5000.0d0)) then
tmp = t_1
else if (t_0 <= 2.0d0) then
tmp = 1.0d0 * x
else
tmp = t_1
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (z * y);
double t_1 = (-y * z) * x;
double tmp;
if (t_0 <= -5000.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = 1.0 * x;
} else {
tmp = t_1;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = 1.0 - (z * y) t_1 = (-y * z) * x tmp = 0 if t_0 <= -5000.0: tmp = t_1 elif t_0 <= 2.0: tmp = 1.0 * x else: tmp = t_1 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(1.0 - Float64(z * y)) t_1 = Float64(Float64(Float64(-y) * z) * x) tmp = 0.0 if (t_0 <= -5000.0) tmp = t_1; elseif (t_0 <= 2.0) tmp = Float64(1.0 * x); else tmp = t_1; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = 1.0 - (z * y);
t_1 = (-y * z) * x;
tmp = 0.0;
if (t_0 <= -5000.0)
tmp = t_1;
elseif (t_0 <= 2.0)
tmp = 1.0 * x;
else
tmp = t_1;
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[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-y) * z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[t$95$0, -5000.0], t$95$1, If[LessEqual[t$95$0, 2.0], N[(1.0 * x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - z \cdot y\\
t_1 := \left(\left(-y\right) \cdot z\right) \cdot x\\
\mathbf{if}\;t\_0 \leq -5000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -5e3 or 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 90.9%
Taylor expanded in y around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6488.2
Applied rewrites88.2%
if -5e3 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites97.7%
Final simplification92.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* (- 1.0 (* z y)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (1.0 - (z * y)) * 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 = (1.0d0 - (z * y)) * x
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (1.0 - (z * y)) * x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (1.0 - (z * y)) * x
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(1.0 - Float64(z * y)) * x) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (1.0 - (z * y)) * x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\left(1 - z \cdot y\right) \cdot x
\end{array}
Initial program 95.1%
Final simplification95.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* 1.0 x))
assert(x < y && y < z);
double code(double x, double y, double z) {
return 1.0 * 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 = 1.0d0 * x
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return 1.0 * x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return 1.0 * x
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(1.0 * x) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = 1.0 * x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
1 \cdot x
\end{array}
Initial program 95.1%
Taylor expanded in y around 0
Applied rewrites46.8%
Final simplification46.8%
herbie shell --seed 2024294
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))