
(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: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -3.8e+207) (- x (* y (* x z))) (* x (- 1.0 (* y z)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e+207) {
tmp = x - (y * (x * z));
} else {
tmp = x * (1.0 - (y * z));
}
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 <= (-3.8d+207)) then
tmp = x - (y * (x * z))
else
tmp = x * (1.0d0 - (y * z))
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e+207) {
tmp = x - (y * (x * z));
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if y <= -3.8e+207: tmp = x - (y * (x * z)) else: tmp = x * (1.0 - (y * z)) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (y <= -3.8e+207) tmp = Float64(x - Float64(y * Float64(x * z))); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -3.8e+207)
tmp = x - (y * (x * z));
else
tmp = x * (1.0 - (y * z));
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[y, -3.8e+207], N[(x - N[(y * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+207}:\\
\;\;\;\;x - y \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if y < -3.79999999999999986e207Initial program 85.8%
Taylor expanded in x around 0 85.8%
*-commutative85.8%
distribute-rgt-out--85.8%
associate-*r*96.1%
*-lft-identity96.1%
Simplified96.1%
if -3.79999999999999986e207 < y Initial program 97.9%
Final simplification97.7%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) (- INFINITY)) (* z (* y (- x))) (* x (- 1.0 (* y z)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -((double) INFINITY)) {
tmp = z * (y * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -Double.POSITIVE_INFINITY) {
tmp = z * (y * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -math.inf: tmp = z * (y * -x) else: tmp = x * (1.0 - (y * z)) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= Float64(-Inf)) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= -Inf)
tmp = z * (y * -x);
else
tmp = x * (1.0 - (y * z));
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], (-Infinity)], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -\infty:\\
\;\;\;\;z \cdot \left(y \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 79.9%
add-cbrt-cube79.9%
pow379.9%
Applied egg-rr79.9%
Taylor expanded in y around inf 84.1%
mul-1-neg100.0%
associate-*r*79.9%
distribute-lft-neg-in79.9%
distribute-rgt-neg-out79.9%
*-commutative79.9%
Simplified79.9%
add-sqr-sqrt31.5%
sqrt-unprod31.5%
pow-prod-up31.5%
add-sqr-sqrt17.6%
sqrt-unprod31.5%
sqr-neg31.5%
sqrt-unprod13.9%
add-sqr-sqrt31.5%
metadata-eval31.5%
Applied egg-rr31.5%
*-commutative31.5%
Simplified31.5%
Taylor expanded in y around -inf 100.0%
mul-1-neg100.0%
*-commutative100.0%
associate-*l*99.9%
*-commutative99.9%
distribute-rgt-neg-in99.9%
Simplified99.9%
if -inf.0 < (*.f64 y z) Initial program 98.3%
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 (<= y -6.8e+118) (not (<= y 2.2e-85))) (* x (* y (- z))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.8e+118) || !(y <= 2.2e-85)) {
tmp = x * (y * -z);
} 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 ((y <= (-6.8d+118)) .or. (.not. (y <= 2.2d-85))) then
tmp = x * (y * -z)
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 ((y <= -6.8e+118) || !(y <= 2.2e-85)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y <= -6.8e+118) or not (y <= 2.2e-85): tmp = x * (y * -z) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -6.8e+118) || !(y <= 2.2e-85)) tmp = Float64(x * Float64(y * Float64(-z))); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= -6.8e+118) || ~((y <= 2.2e-85)))
tmp = x * (y * -z);
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[y, -6.8e+118], N[Not[LessEqual[y, 2.2e-85]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+118} \lor \neg \left(y \leq 2.2 \cdot 10^{-85}\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.79999999999999973e118 or 2.2e-85 < y Initial program 94.3%
Taylor expanded in y around inf 69.4%
mul-1-neg69.4%
associate-*r*67.2%
distribute-lft-neg-in67.2%
distribute-rgt-neg-out67.2%
*-commutative67.2%
Simplified67.2%
if -6.79999999999999973e118 < y < 2.2e-85Initial program 99.1%
Taylor expanded in y around 0 70.3%
Final simplification68.7%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -2.7e+118) (* y (* x (- z))) (if (<= y 1.95e-85) x (* x (* y (- z))))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -2.7e+118) {
tmp = y * (x * -z);
} else if (y <= 1.95e-85) {
tmp = x;
} else {
tmp = x * (y * -z);
}
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 <= (-2.7d+118)) then
tmp = y * (x * -z)
else if (y <= 1.95d-85) then
tmp = x
else
tmp = x * (y * -z)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.7e+118) {
tmp = y * (x * -z);
} else if (y <= 1.95e-85) {
tmp = x;
} else {
tmp = x * (y * -z);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if y <= -2.7e+118: tmp = y * (x * -z) elif y <= 1.95e-85: tmp = x else: tmp = x * (y * -z) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (y <= -2.7e+118) tmp = Float64(y * Float64(x * Float64(-z))); elseif (y <= 1.95e-85) tmp = x; else tmp = Float64(x * Float64(y * Float64(-z))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -2.7e+118)
tmp = y * (x * -z);
elseif (y <= 1.95e-85)
tmp = x;
else
tmp = x * (y * -z);
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[y, -2.7e+118], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.95e-85], x, N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{+118}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{-85}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\end{array}
\end{array}
if y < -2.7e118Initial program 88.7%
Taylor expanded in y around inf 81.5%
mul-1-neg81.5%
distribute-rgt-neg-in81.5%
distribute-lft-neg-out81.5%
*-commutative81.5%
Simplified81.5%
if -2.7e118 < y < 1.94999999999999994e-85Initial program 99.1%
Taylor expanded in y around 0 70.3%
if 1.94999999999999994e-85 < y Initial program 97.6%
Taylor expanded in y around inf 62.2%
mul-1-neg62.2%
associate-*r*63.2%
distribute-lft-neg-in63.2%
distribute-rgt-neg-out63.2%
*-commutative63.2%
Simplified63.2%
Final simplification70.1%
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.6%
Taylor expanded in y around 0 49.6%
Final simplification49.6%
herbie shell --seed 2023242
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))