
(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 (<= (* y z) 1e+242) (- x (* (* y z) x)) (* y (* z (- x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 1e+242) {
tmp = x - ((y * z) * x);
} else {
tmp = y * (z * -x);
}
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 ((y * z) <= 1d+242) then
tmp = x - ((y * z) * x)
else
tmp = y * (z * -x)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 1e+242) {
tmp = x - ((y * z) * x);
} else {
tmp = y * (z * -x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 1e+242: tmp = x - ((y * z) * x) else: tmp = y * (z * -x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 1e+242) tmp = Float64(x - Float64(Float64(y * z) * x)); else tmp = Float64(y * Float64(z * Float64(-x))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= 1e+242)
tmp = x - ((y * z) * x);
else
tmp = y * (z * -x);
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[(y * z), $MachinePrecision], 1e+242], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 10^{+242}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 1.00000000000000005e242Initial program 98.7%
sub-neg98.7%
+-commutative98.7%
add-sqr-sqrt52.9%
distribute-rgt-neg-in52.9%
fma-define52.9%
Applied egg-rr52.9%
*-commutative52.9%
fma-undefine52.9%
distribute-rgt-neg-in52.9%
add-sqr-sqrt98.7%
distribute-rgt-neg-out98.7%
distribute-rgt1-in98.7%
distribute-rgt-neg-out98.7%
cancel-sign-sub-inv98.7%
*-commutative98.7%
Applied egg-rr98.7%
if 1.00000000000000005e242 < (*.f64 y z) Initial program 72.9%
sub-neg72.9%
+-commutative72.9%
add-sqr-sqrt72.8%
distribute-rgt-neg-in72.8%
fma-define72.8%
Applied egg-rr72.8%
Applied egg-rr8.2%
Taylor expanded in y around inf 62.2%
Taylor expanded in x around 0 99.7%
distribute-rgt1-in99.7%
metadata-eval99.7%
neg-mul-199.7%
Simplified99.7%
Final simplification98.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -6.8e+87) (not (<= y 1.25e-82))) (* (* y z) (- x)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.8e+87) || !(y <= 1.25e-82)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
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 ((y <= (-6.8d+87)) .or. (.not. (y <= 1.25d-82))) then
tmp = (y * z) * -x
else
tmp = x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.8e+87) || !(y <= 1.25e-82)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y <= -6.8e+87) or not (y <= 1.25e-82): tmp = (y * z) * -x else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -6.8e+87) || !(y <= 1.25e-82)) tmp = Float64(Float64(y * z) * Float64(-x)); else tmp = x; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= -6.8e+87) || ~((y <= 1.25e-82)))
tmp = (y * z) * -x;
else
tmp = x;
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[Or[LessEqual[y, -6.8e+87], N[Not[LessEqual[y, 1.25e-82]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+87} \lor \neg \left(y \leq 1.25 \cdot 10^{-82}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.8000000000000004e87 or 1.25e-82 < y Initial program 93.0%
Taylor expanded in y around inf 58.0%
mul-1-neg58.0%
distribute-rgt-neg-in58.0%
distribute-rgt-neg-in58.0%
Simplified58.0%
if -6.8000000000000004e87 < y < 1.25e-82Initial program 99.9%
Taylor expanded in y around 0 77.7%
Final simplification67.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -2.5e+87) (* (* y z) (- x)) (if (<= y 2.1e-51) x (* y (* z (- x))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -2.5e+87) {
tmp = (y * z) * -x;
} else if (y <= 2.1e-51) {
tmp = x;
} else {
tmp = y * (z * -x);
}
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 (y <= (-2.5d+87)) then
tmp = (y * z) * -x
else if (y <= 2.1d-51) then
tmp = x
else
tmp = y * (z * -x)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.5e+87) {
tmp = (y * z) * -x;
} else if (y <= 2.1e-51) {
tmp = x;
} else {
tmp = y * (z * -x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -2.5e+87: tmp = (y * z) * -x elif y <= 2.1e-51: tmp = x else: tmp = y * (z * -x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -2.5e+87) tmp = Float64(Float64(y * z) * Float64(-x)); elseif (y <= 2.1e-51) tmp = x; else tmp = Float64(y * Float64(z * Float64(-x))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -2.5e+87)
tmp = (y * z) * -x;
elseif (y <= 2.1e-51)
tmp = x;
else
tmp = y * (z * -x);
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[y, -2.5e+87], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], If[LessEqual[y, 2.1e-51], x, N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+87}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{-51}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if y < -2.4999999999999999e87Initial program 95.6%
Taylor expanded in y around inf 68.9%
mul-1-neg68.9%
distribute-rgt-neg-in68.9%
distribute-rgt-neg-in68.9%
Simplified68.9%
if -2.4999999999999999e87 < y < 2.10000000000000002e-51Initial program 99.9%
Taylor expanded in y around 0 77.8%
if 2.10000000000000002e-51 < y Initial program 90.9%
sub-neg90.9%
+-commutative90.9%
add-sqr-sqrt43.1%
distribute-rgt-neg-in43.1%
fma-define43.1%
Applied egg-rr43.1%
Applied egg-rr62.9%
Taylor expanded in y around inf 48.8%
Taylor expanded in x around 0 63.1%
distribute-rgt1-in63.1%
metadata-eval63.1%
neg-mul-163.1%
Simplified63.1%
Final simplification71.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) 1e+242) (* x (- 1.0 (* y z))) (* y (* z (- x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 1e+242) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (z * -x);
}
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 ((y * z) <= 1d+242) then
tmp = x * (1.0d0 - (y * z))
else
tmp = y * (z * -x)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 1e+242) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (z * -x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 1e+242: tmp = x * (1.0 - (y * z)) else: tmp = y * (z * -x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 1e+242) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(y * Float64(z * Float64(-x))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= 1e+242)
tmp = x * (1.0 - (y * z));
else
tmp = y * (z * -x);
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[(y * z), $MachinePrecision], 1e+242], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 10^{+242}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 1.00000000000000005e242Initial program 98.7%
if 1.00000000000000005e242 < (*.f64 y z) Initial program 72.9%
sub-neg72.9%
+-commutative72.9%
add-sqr-sqrt72.8%
distribute-rgt-neg-in72.8%
fma-define72.8%
Applied egg-rr72.8%
Applied egg-rr8.2%
Taylor expanded in y around inf 62.2%
Taylor expanded in x around 0 99.7%
distribute-rgt1-in99.7%
metadata-eval99.7%
neg-mul-199.7%
Simplified99.7%
Final simplification98.8%
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.2%
Taylor expanded in y around 0 55.7%
Final simplification55.7%
herbie shell --seed 2024053
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))