
(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 (or (<= (* y z) -2e+211) (not (<= (* y z) 4e+236))) (* (* y x) (- z)) (- x (* (* y z) x))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -2e+211) || !((y * z) <= 4e+236)) {
tmp = (y * x) * -z;
} else {
tmp = x - ((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) <= (-2d+211)) .or. (.not. ((y * z) <= 4d+236))) then
tmp = (y * x) * -z
else
tmp = x - ((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) <= -2e+211) || !((y * z) <= 4e+236)) {
tmp = (y * x) * -z;
} 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) <= -2e+211) or not ((y * z) <= 4e+236): tmp = (y * x) * -z 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) <= -2e+211) || !(Float64(y * z) <= 4e+236)) tmp = Float64(Float64(y * x) * Float64(-z)); 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) <= -2e+211) || ~(((y * z) <= 4e+236)))
tmp = (y * x) * -z;
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[Or[LessEqual[N[(y * z), $MachinePrecision], -2e+211], N[Not[LessEqual[N[(y * z), $MachinePrecision], 4e+236]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] * (-z)), $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 -2 \cdot 10^{+211} \lor \neg \left(y \cdot z \leq 4 \cdot 10^{+236}\right):\\
\;\;\;\;\left(y \cdot x\right) \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 y z) < -1.9999999999999999e211 or 4.00000000000000021e236 < (*.f64 y z) Initial program 72.8%
Taylor expanded in y around inf 72.8%
mul-1-neg72.8%
associate-*r*99.9%
Simplified99.9%
if -1.9999999999999999e211 < (*.f64 y z) < 4.00000000000000021e236Initial program 99.9%
sub-neg99.9%
distribute-rgt-in99.9%
*-un-lft-identity99.9%
distribute-rgt-neg-in99.9%
Applied egg-rr99.9%
*-commutative99.9%
associate-*l*91.9%
add-sqr-sqrt42.9%
sqrt-unprod66.6%
sqr-neg66.6%
sqrt-unprod30.6%
add-sqr-sqrt58.5%
associate-*r*61.2%
*-commutative61.2%
cancel-sign-sub61.2%
distribute-rgt-neg-out61.2%
*-commutative61.2%
associate-*r*58.5%
add-sqr-sqrt27.9%
sqrt-unprod68.5%
sqr-neg68.5%
sqrt-unprod48.9%
add-sqr-sqrt91.9%
associate-*l*99.9%
Applied egg-rr99.9%
Final simplification99.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= (* y z) -2e+211) (not (<= (* y z) 4e+236))) (* (* y x) (- z)) (* x (- 1.0 (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -2e+211) || !((y * z) <= 4e+236)) {
tmp = (y * x) * -z;
} else {
tmp = x * (1.0 - (y * 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 (((y * z) <= (-2d+211)) .or. (.not. ((y * z) <= 4d+236))) then
tmp = (y * x) * -z
else
tmp = x * (1.0d0 - (y * 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 (((y * z) <= -2e+211) || !((y * z) <= 4e+236)) {
tmp = (y * x) * -z;
} 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) <= -2e+211) or not ((y * z) <= 4e+236): tmp = (y * x) * -z 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) <= -2e+211) || !(Float64(y * z) <= 4e+236)) tmp = Float64(Float64(y * x) * Float64(-z)); 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) <= -2e+211) || ~(((y * z) <= 4e+236)))
tmp = (y * x) * -z;
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[Or[LessEqual[N[(y * z), $MachinePrecision], -2e+211], N[Not[LessEqual[N[(y * z), $MachinePrecision], 4e+236]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] * (-z)), $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 -2 \cdot 10^{+211} \lor \neg \left(y \cdot z \leq 4 \cdot 10^{+236}\right):\\
\;\;\;\;\left(y \cdot x\right) \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -1.9999999999999999e211 or 4.00000000000000021e236 < (*.f64 y z) Initial program 72.8%
Taylor expanded in y around inf 72.8%
mul-1-neg72.8%
associate-*r*99.9%
Simplified99.9%
if -1.9999999999999999e211 < (*.f64 y z) < 4.00000000000000021e236Initial program 99.9%
Final simplification99.9%
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-138) (not (<= z 1.75e+87))) (* (* y x) (- z)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -7e-138) || !(z <= 1.75e+87)) {
tmp = (y * x) * -z;
} 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-138)) .or. (.not. (z <= 1.75d+87))) then
tmp = (y * x) * -z
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-138) || !(z <= 1.75e+87)) {
tmp = (y * x) * -z;
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -7e-138) or not (z <= 1.75e+87): tmp = (y * x) * -z else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -7e-138) || !(z <= 1.75e+87)) tmp = Float64(Float64(y * x) * Float64(-z)); 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-138) || ~((z <= 1.75e+87)))
tmp = (y * x) * -z;
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-138], N[Not[LessEqual[z, 1.75e+87]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] * (-z)), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7 \cdot 10^{-138} \lor \neg \left(z \leq 1.75 \cdot 10^{+87}\right):\\
\;\;\;\;\left(y \cdot x\right) \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.9999999999999997e-138 or 1.74999999999999993e87 < z Initial program 91.9%
Taylor expanded in y around inf 67.0%
mul-1-neg67.0%
associate-*r*68.3%
Simplified68.3%
if -6.9999999999999997e-138 < z < 1.74999999999999993e87Initial program 99.1%
Taylor expanded in y around 0 82.4%
Final simplification74.6%
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.2%
Taylor expanded in y around 0 51.9%
Final simplification51.9%
herbie shell --seed 2024081
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))