
(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 (or (<= (* y z) -2e+307) (not (<= (* y z) 1e+137))) (* 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) <= -2e+307) || !((y * z) <= 1e+137)) {
tmp = y * (z * -x);
} 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+307)) .or. (.not. ((y * z) <= 1d+137))) then
tmp = y * (z * -x)
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+307) || !((y * z) <= 1e+137)) {
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) <= -2e+307) or not ((y * z) <= 1e+137): 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) <= -2e+307) || !(Float64(y * z) <= 1e+137)) 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) <= -2e+307) || ~(((y * z) <= 1e+137)))
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[Or[LessEqual[N[(y * z), $MachinePrecision], -2e+307], N[Not[LessEqual[N[(y * z), $MachinePrecision], 1e+137]], $MachinePrecision]], 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 -2 \cdot 10^{+307} \lor \neg \left(y \cdot z \leq 10^{+137}\right):\\
\;\;\;\;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) < -1.99999999999999997e307 or 1e137 < (*.f64 y z) Initial program 74.4%
Taylor expanded in y around inf 74.4%
mul-1-neg74.4%
*-commutative74.4%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
if -1.99999999999999997e307 < (*.f64 y z) < 1e137Initial program 99.9%
sub-neg99.9%
distribute-rgt-in99.9%
*-un-lft-identity99.9%
distribute-rgt-neg-in99.9%
Applied egg-rr99.9%
associate-*l*96.3%
add-sqr-sqrt42.8%
sqrt-unprod70.4%
sqr-neg70.4%
sqrt-unprod33.2%
add-sqr-sqrt59.1%
cancel-sign-sub-inv59.1%
associate-*l*60.1%
*-commutative60.1%
*-commutative60.1%
distribute-lft-neg-out60.1%
distribute-rgt-neg-out60.1%
associate-*l*59.1%
add-sqr-sqrt33.2%
sqrt-unprod70.4%
sqr-neg70.4%
sqrt-unprod42.8%
add-sqr-sqrt96.3%
associate-*l*99.9%
*-commutative99.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
(let* ((t_0 (* z (* y (- x)))))
(if (<= (* y z) (- INFINITY))
t_0
(if (<= (* y z) -10000000.0)
(* x (* y (- z)))
(if (<= (* y z) 0.5) x t_0)))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = z * (y * -x);
double tmp;
if ((y * z) <= -((double) INFINITY)) {
tmp = t_0;
} else if ((y * z) <= -10000000.0) {
tmp = x * (y * -z);
} else if ((y * z) <= 0.5) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = z * (y * -x);
double tmp;
if ((y * z) <= -Double.POSITIVE_INFINITY) {
tmp = t_0;
} else if ((y * z) <= -10000000.0) {
tmp = x * (y * -z);
} else if ((y * z) <= 0.5) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = z * (y * -x) tmp = 0 if (y * z) <= -math.inf: tmp = t_0 elif (y * z) <= -10000000.0: tmp = x * (y * -z) elif (y * z) <= 0.5: tmp = x else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(z * Float64(y * Float64(-x))) tmp = 0.0 if (Float64(y * z) <= Float64(-Inf)) tmp = t_0; elseif (Float64(y * z) <= -10000000.0) tmp = Float64(x * Float64(y * Float64(-z))); elseif (Float64(y * z) <= 0.5) tmp = x; else tmp = t_0; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = z * (y * -x);
tmp = 0.0;
if ((y * z) <= -Inf)
tmp = t_0;
elseif ((y * z) <= -10000000.0)
tmp = x * (y * -z);
elseif ((y * z) <= 0.5)
tmp = x;
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], -10000000.0], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.5], x, t$95$0]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{if}\;y \cdot z \leq -\infty:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq -10000000:\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 0.5:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 0.5 < (*.f64 y z) Initial program 80.0%
Taylor expanded in z around inf 99.8%
Taylor expanded in y around inf 98.6%
neg-mul-198.6%
*-commutative98.6%
distribute-rgt-neg-in98.6%
Simplified98.6%
if -inf.0 < (*.f64 y z) < -1e7Initial program 99.8%
Taylor expanded in y around inf 98.3%
mul-1-neg98.3%
distribute-rgt-neg-out98.3%
Simplified98.3%
if -1e7 < (*.f64 y z) < 0.5Initial program 100.0%
Taylor expanded in y around 0 96.5%
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+307) (not (<= (* y z) 1e+137))) (* 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) <= -2e+307) || !((y * z) <= 1e+137)) {
tmp = y * (z * -x);
} 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+307)) .or. (.not. ((y * z) <= 1d+137))) then
tmp = y * (z * -x)
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+307) || !((y * z) <= 1e+137)) {
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) <= -2e+307) or not ((y * z) <= 1e+137): 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) <= -2e+307) || !(Float64(y * z) <= 1e+137)) 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) <= -2e+307) || ~(((y * z) <= 1e+137)))
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[Or[LessEqual[N[(y * z), $MachinePrecision], -2e+307], N[Not[LessEqual[N[(y * z), $MachinePrecision], 1e+137]], $MachinePrecision]], 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 -2 \cdot 10^{+307} \lor \neg \left(y \cdot z \leq 10^{+137}\right):\\
\;\;\;\;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) < -1.99999999999999997e307 or 1e137 < (*.f64 y z) Initial program 74.4%
Taylor expanded in y around inf 74.4%
mul-1-neg74.4%
*-commutative74.4%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
if -1.99999999999999997e307 < (*.f64 y z) < 1e137Initial 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 (<= (* y z) -10000000.0) (not (<= (* y z) 0.5))) (* y (* z (- x))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -10000000.0) || !((y * z) <= 0.5)) {
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 * z) <= (-10000000.0d0)) .or. (.not. ((y * z) <= 0.5d0))) 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 * z) <= -10000000.0) || !((y * z) <= 0.5)) {
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 * z) <= -10000000.0) or not ((y * z) <= 0.5): 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 ((Float64(y * z) <= -10000000.0) || !(Float64(y * z) <= 0.5)) 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 (((y * z) <= -10000000.0) || ~(((y * z) <= 0.5)))
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[N[(y * z), $MachinePrecision], -10000000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.5]], $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}\;y \cdot z \leq -10000000 \lor \neg \left(y \cdot z \leq 0.5\right):\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -1e7 or 0.5 < (*.f64 y z) Initial program 87.6%
Taylor expanded in y around inf 86.3%
mul-1-neg86.3%
*-commutative86.3%
associate-*r*96.0%
distribute-rgt-neg-in96.0%
Simplified96.0%
if -1e7 < (*.f64 y z) < 0.5Initial program 100.0%
Taylor expanded in y around 0 96.5%
Final simplification96.2%
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) -10000000.0) (not (<= (* y z) 0.5))) (* x (* y (- z))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -10000000.0) || !((y * z) <= 0.5)) {
tmp = x * (y * -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 (((y * z) <= (-10000000.0d0)) .or. (.not. ((y * z) <= 0.5d0))) then
tmp = x * (y * -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 (((y * z) <= -10000000.0) || !((y * z) <= 0.5)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -10000000.0) or not ((y * z) <= 0.5): tmp = x * (y * -z) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -10000000.0) || !(Float64(y * z) <= 0.5)) tmp = Float64(x * Float64(y * 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 (((y * z) <= -10000000.0) || ~(((y * z) <= 0.5)))
tmp = x * (y * -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[N[(y * z), $MachinePrecision], -10000000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.5]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -10000000 \lor \neg \left(y \cdot z \leq 0.5\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -1e7 or 0.5 < (*.f64 y z) Initial program 87.6%
Taylor expanded in y around inf 86.3%
mul-1-neg86.3%
distribute-rgt-neg-out86.3%
Simplified86.3%
if -1e7 < (*.f64 y z) < 0.5Initial program 100.0%
Taylor expanded in y around 0 96.5%
Final simplification91.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -5e+37) (/ (* z x) z) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+37) {
tmp = (z * 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 ((y * z) <= (-5d+37)) then
tmp = (z * 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 ((y * z) <= -5e+37) {
tmp = (z * x) / z;
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -5e+37: tmp = (z * x) / z else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -5e+37) tmp = Float64(Float64(z * x) / 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 ((y * z) <= -5e+37)
tmp = (z * 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[LessEqual[N[(y * z), $MachinePrecision], -5e+37], N[(N[(z * x), $MachinePrecision] / z), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+37}:\\
\;\;\;\;\frac{z \cdot x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -4.99999999999999989e37Initial program 87.7%
Taylor expanded in z around inf 94.4%
Taylor expanded in y around 0 4.6%
associate-*r/27.6%
*-commutative27.6%
Applied egg-rr27.6%
if -4.99999999999999989e37 < (*.f64 y z) Initial program 95.6%
Taylor expanded in y around 0 64.2%
Final simplification53.0%
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 93.2%
Taylor expanded in y around 0 46.1%
herbie shell --seed 2024157
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))