
(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 7 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) (- INFINITY)) (* y (* z (- x))) (- x (* (* y z) x))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -((double) INFINITY)) {
tmp = y * (z * -x);
} else {
tmp = x - ((y * z) * x);
}
return tmp;
}
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -Double.POSITIVE_INFINITY) {
tmp = y * (z * -x);
} else {
tmp = x - ((y * z) * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -math.inf: tmp = y * (z * -x) else: tmp = x - ((y * z) * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= Float64(-Inf)) tmp = Float64(y * Float64(z * Float64(-x))); else tmp = Float64(x - Float64(Float64(y * z) * 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) <= -Inf)
tmp = y * (z * -x);
else
tmp = x - ((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], (-Infinity)], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -\infty:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0Initial program 42.6%
Taylor expanded in y around inf 42.6%
mul-1-neg42.6%
*-commutative42.6%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
if -inf.0 < (*.f64 y z) Initial program 98.3%
sub-neg98.3%
distribute-rgt-in98.3%
*-un-lft-identity98.3%
distribute-rgt-neg-in98.3%
Applied egg-rr98.3%
associate-*l*91.9%
add-sqr-sqrt39.0%
sqrt-unprod57.1%
sqr-neg57.1%
sqrt-unprod26.6%
add-sqr-sqrt47.8%
cancel-sign-sub-inv47.8%
associate-*l*49.4%
*-commutative49.4%
*-commutative49.4%
distribute-lft-neg-out49.4%
distribute-rgt-neg-out49.4%
associate-*l*47.8%
add-sqr-sqrt26.6%
sqrt-unprod57.1%
sqr-neg57.1%
sqrt-unprod39.0%
add-sqr-sqrt91.9%
associate-*l*98.3%
*-commutative98.3%
Applied egg-rr98.3%
Final simplification98.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -7.5e-100) (not (<= z 7e+53))) (* y (* z (- x))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.5e-100) || !(z <= 7e+53)) {
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 ((z <= (-7.5d-100)) .or. (.not. (z <= 7d+53))) 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 ((z <= -7.5e-100) || !(z <= 7e+53)) {
tmp = y * (z * -x);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -7.5e-100) or not (z <= 7e+53): 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 ((z <= -7.5e-100) || !(z <= 7e+53)) tmp = Float64(y * Float64(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 ((z <= -7.5e-100) || ~((z <= 7e+53)))
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[z, -7.5e-100], N[Not[LessEqual[z, 7e+53]], $MachinePrecision]], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.5 \cdot 10^{-100} \lor \neg \left(z \leq 7 \cdot 10^{+53}\right):\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.50000000000000015e-100 or 7.00000000000000038e53 < z Initial program 91.7%
Taylor expanded in y around inf 66.6%
mul-1-neg66.6%
*-commutative66.6%
associate-*r*69.9%
distribute-rgt-neg-in69.9%
Simplified69.9%
if -7.50000000000000015e-100 < z < 7.00000000000000038e53Initial program 99.9%
Taylor expanded in y around 0 74.9%
Final simplification72.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -7e-100) (not (<= z 7e+53))) (* z (* y (- x))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -7e-100) || !(z <= 7e+53)) {
tmp = z * (y * -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 ((z <= (-7d-100)) .or. (.not. (z <= 7d+53))) then
tmp = z * (y * -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 ((z <= -7e-100) || !(z <= 7e+53)) {
tmp = z * (y * -x);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -7e-100) or not (z <= 7e+53): tmp = z * (y * -x) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -7e-100) || !(z <= 7e+53)) tmp = Float64(z * Float64(y * 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 ((z <= -7e-100) || ~((z <= 7e+53)))
tmp = z * (y * -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[z, -7e-100], N[Not[LessEqual[z, 7e+53]], $MachinePrecision]], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7 \cdot 10^{-100} \lor \neg \left(z \leq 7 \cdot 10^{+53}\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.0000000000000001e-100 or 7.00000000000000038e53 < z Initial program 91.7%
Taylor expanded in z around inf 91.8%
Taylor expanded in y around inf 69.9%
neg-mul-169.9%
distribute-rgt-neg-in69.9%
Simplified69.9%
if -7.0000000000000001e-100 < z < 7.00000000000000038e53Initial program 99.9%
Taylor expanded in y around 0 74.9%
Final simplification72.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -4.8e-101) (not (<= z 7.2e+53))) (* (* y z) (- x)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8e-101) || !(z <= 7.2e+53)) {
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 ((z <= (-4.8d-101)) .or. (.not. (z <= 7.2d+53))) 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 ((z <= -4.8e-101) || !(z <= 7.2e+53)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -4.8e-101) or not (z <= 7.2e+53): 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 ((z <= -4.8e-101) || !(z <= 7.2e+53)) 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 ((z <= -4.8e-101) || ~((z <= 7.2e+53)))
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[z, -4.8e-101], N[Not[LessEqual[z, 7.2e+53]], $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}\;z \leq -4.8 \cdot 10^{-101} \lor \neg \left(z \leq 7.2 \cdot 10^{+53}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.8e-101 or 7.2e53 < z Initial program 91.7%
Taylor expanded in y around inf 66.6%
mul-1-neg66.6%
distribute-rgt-neg-out66.6%
Simplified66.6%
if -4.8e-101 < z < 7.2e53Initial program 99.9%
Taylor expanded in y around 0 74.9%
Final simplification70.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) (- INFINITY)) (* y (* z (- x))) (* x (- 1.0 (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -((double) INFINITY)) {
tmp = y * (z * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -Double.POSITIVE_INFINITY) {
tmp = y * (z * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -math.inf: tmp = y * (z * -x) else: tmp = x * (1.0 - (y * z)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= Float64(-Inf)) tmp = Float64(y * Float64(z * Float64(-x))); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); 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) <= -Inf)
tmp = y * (z * -x);
else
tmp = x * (1.0 - (y * 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[(y * z), $MachinePrecision], (-Infinity)], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -\infty:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0Initial program 42.6%
Taylor expanded in y around inf 42.6%
mul-1-neg42.6%
*-commutative42.6%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
if -inf.0 < (*.f64 y z) Initial program 98.3%
Final simplification98.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z 2.4e+155) x (/ (* z x) z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= 2.4e+155) {
tmp = x;
} else {
tmp = (z * x) / z;
}
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 (z <= 2.4d+155) then
tmp = x
else
tmp = (z * x) / z
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (z <= 2.4e+155) {
tmp = x;
} else {
tmp = (z * x) / z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if z <= 2.4e+155: tmp = x else: tmp = (z * x) / z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (z <= 2.4e+155) tmp = x; else tmp = Float64(Float64(z * x) / 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 <= 2.4e+155)
tmp = x;
else
tmp = (z * 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[z, 2.4e+155], x, N[(N[(z * x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.4 \cdot 10^{+155}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{z \cdot x}{z}\\
\end{array}
\end{array}
if z < 2.40000000000000021e155Initial program 96.1%
Taylor expanded in y around 0 52.9%
if 2.40000000000000021e155 < z Initial program 90.7%
Taylor expanded in z around inf 88.0%
Taylor expanded in y around 0 11.9%
associate-*r/30.2%
*-commutative30.2%
Applied egg-rr30.2%
Final simplification50.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 95.5%
Taylor expanded in y around 0 48.3%
herbie shell --seed 2024172
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))