
(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: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) 4e+278) (- x (* (* y z) x)) (* z (* y (- x)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 4e+278) {
tmp = x - ((y * z) * x);
} else {
tmp = z * (y * -x);
}
return tmp;
}
NOTE: 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) <= 4d+278) then
tmp = x - ((y * z) * x)
else
tmp = z * (y * -x)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 4e+278) {
tmp = x - ((y * z) * x);
} else {
tmp = z * (y * -x);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 4e+278: tmp = x - ((y * z) * x) else: tmp = z * (y * -x) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 4e+278) tmp = Float64(x - Float64(Float64(y * z) * x)); else tmp = Float64(z * Float64(y * Float64(-x))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= 4e+278)
tmp = x - ((y * z) * x);
else
tmp = z * (y * -x);
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], 4e+278], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 4 \cdot 10^{+278}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 3.99999999999999985e278Initial program 98.3%
sub-neg98.3%
distribute-rgt-in98.3%
*-un-lft-identity98.3%
distribute-rgt-neg-in98.3%
Applied egg-rr98.3%
if 3.99999999999999985e278 < (*.f64 y z) Initial program 75.8%
add-sqr-sqrt40.5%
pow240.5%
Applied egg-rr40.5%
Taylor expanded in y around inf 54.8%
mul-1-neg54.8%
distribute-rgt-neg-in54.8%
distribute-rgt-neg-in54.8%
Simplified54.8%
unpow254.8%
add-sqr-sqrt99.8%
*-commutative99.8%
associate-*r*99.6%
distribute-lft-neg-in99.6%
neg-mul-199.6%
associate-*r*99.6%
Applied egg-rr99.6%
Final simplification98.4%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) 4e+239) (* x (- 1.0 (* y z))) (* y (* z (- x)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 4e+239) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (z * -x);
}
return tmp;
}
NOTE: 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) <= 4d+239) then
tmp = x * (1.0d0 - (y * z))
else
tmp = y * (z * -x)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 4e+239) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (z * -x);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 4e+239: tmp = x * (1.0 - (y * z)) else: tmp = y * (z * -x) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 4e+239) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(y * Float64(z * Float64(-x))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= 4e+239)
tmp = x * (1.0 - (y * z));
else
tmp = y * (z * -x);
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], 4e+239], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 4 \cdot 10^{+239}:\\
\;\;\;\;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) < 3.99999999999999996e239Initial program 98.2%
if 3.99999999999999996e239 < (*.f64 y z) Initial program 83.3%
Taylor expanded in y around inf 99.8%
mul-1-neg44.6%
distribute-rgt-neg-in44.6%
distribute-rgt-neg-in44.6%
Simplified99.8%
Final simplification98.4%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) 4e+278) (* x (- 1.0 (* y z))) (* z (* y (- x)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 4e+278) {
tmp = x * (1.0 - (y * z));
} else {
tmp = z * (y * -x);
}
return tmp;
}
NOTE: 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) <= 4d+278) then
tmp = x * (1.0d0 - (y * z))
else
tmp = z * (y * -x)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 4e+278) {
tmp = x * (1.0 - (y * z));
} else {
tmp = z * (y * -x);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 4e+278: tmp = x * (1.0 - (y * z)) else: tmp = z * (y * -x) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 4e+278) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(z * Float64(y * Float64(-x))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= 4e+278)
tmp = x * (1.0 - (y * z));
else
tmp = z * (y * -x);
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], 4e+278], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 4 \cdot 10^{+278}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 3.99999999999999985e278Initial program 98.3%
if 3.99999999999999985e278 < (*.f64 y z) Initial program 75.8%
add-sqr-sqrt40.5%
pow240.5%
Applied egg-rr40.5%
Taylor expanded in y around inf 54.8%
mul-1-neg54.8%
distribute-rgt-neg-in54.8%
distribute-rgt-neg-in54.8%
Simplified54.8%
unpow254.8%
add-sqr-sqrt99.8%
*-commutative99.8%
associate-*r*99.6%
distribute-lft-neg-in99.6%
neg-mul-199.6%
associate-*r*99.6%
Applied egg-rr99.6%
Final simplification98.4%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -1.35e-95) (not (<= z 3.2e-19))) (* x (* z (- y))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.35e-95) || !(z <= 3.2e-19)) {
tmp = x * (z * -y);
} else {
tmp = x;
}
return tmp;
}
NOTE: 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 ((z <= (-1.35d-95)) .or. (.not. (z <= 3.2d-19))) then
tmp = x * (z * -y)
else
tmp = x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.35e-95) || !(z <= 3.2e-19)) {
tmp = x * (z * -y);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (z <= -1.35e-95) or not (z <= 3.2e-19): tmp = x * (z * -y) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -1.35e-95) || !(z <= 3.2e-19)) tmp = Float64(x * Float64(z * Float64(-y))); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -1.35e-95) || ~((z <= 3.2e-19)))
tmp = x * (z * -y);
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[z, -1.35e-95], N[Not[LessEqual[z, 3.2e-19]], $MachinePrecision]], N[(x * N[(z * (-y)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.35 \cdot 10^{-95} \lor \neg \left(z \leq 3.2 \cdot 10^{-19}\right):\\
\;\;\;\;x \cdot \left(z \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.35e-95 or 3.19999999999999982e-19 < z Initial program 94.3%
Taylor expanded in y around inf 72.3%
mul-1-neg72.3%
distribute-rgt-neg-out72.3%
Simplified72.3%
if -1.35e-95 < z < 3.19999999999999982e-19Initial program 100.0%
Taylor expanded in y around 0 82.3%
Final simplification76.2%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -1.1e-96) (not (<= z 4.3e-18))) (* y (* z (- x))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.1e-96) || !(z <= 4.3e-18)) {
tmp = y * (z * -x);
} else {
tmp = x;
}
return tmp;
}
NOTE: 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 ((z <= (-1.1d-96)) .or. (.not. (z <= 4.3d-18))) then
tmp = y * (z * -x)
else
tmp = x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.1e-96) || !(z <= 4.3e-18)) {
tmp = y * (z * -x);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (z <= -1.1e-96) or not (z <= 4.3e-18): tmp = y * (z * -x) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -1.1e-96) || !(z <= 4.3e-18)) tmp = Float64(y * Float64(z * Float64(-x))); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -1.1e-96) || ~((z <= 4.3e-18)))
tmp = y * (z * -x);
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[z, -1.1e-96], N[Not[LessEqual[z, 4.3e-18]], $MachinePrecision]], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1 \cdot 10^{-96} \lor \neg \left(z \leq 4.3 \cdot 10^{-18}\right):\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.0999999999999999e-96 or 4.3000000000000002e-18 < z Initial program 94.3%
Taylor expanded in y around inf 73.0%
mul-1-neg30.1%
distribute-rgt-neg-in30.1%
distribute-rgt-neg-in30.1%
Simplified73.0%
if -1.0999999999999999e-96 < z < 4.3000000000000002e-18Initial program 100.0%
Taylor expanded in y around 0 82.3%
Final simplification76.6%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(y < z);
double code(double x, double y, double z) {
return x;
}
NOTE: 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 y < z;
public static double code(double x, double y, double z) {
return x;
}
[y, z] = sort([y, z]) def code(x, y, z): return x
y, z = sort([y, z]) function code(x, y, z) return x end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x
\end{array}
Initial program 96.5%
Taylor expanded in y around 0 46.7%
Final simplification46.7%
herbie shell --seed 2023229
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))