
(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) (- INFINITY)) (not (<= (* y z) 2e+236))) (- (* z (* x y))) (* 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)) || !((y * z) <= 2e+236)) {
tmp = -(z * (x * y));
} 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) || !((y * z) <= 2e+236)) {
tmp = -(z * (x * y));
} 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) or not ((y * z) <= 2e+236): tmp = -(z * (x * y)) 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)) || !(Float64(y * z) <= 2e+236)) tmp = Float64(-Float64(z * Float64(x * y))); 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) || ~(((y * z) <= 2e+236)))
tmp = -(z * (x * y));
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], (-Infinity)], N[Not[LessEqual[N[(y * z), $MachinePrecision], 2e+236]], $MachinePrecision]], (-N[(z * N[(x * y), $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 \lor \neg \left(y \cdot z \leq 2 \cdot 10^{+236}\right):\\
\;\;\;\;-z \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 2.00000000000000011e236 < (*.f64 y z) Initial program 74.3%
Taylor expanded in y around inf 74.3%
mul-1-neg74.3%
associate-*r*99.8%
Simplified99.8%
if -inf.0 < (*.f64 y z) < 2.00000000000000011e236Initial program 99.8%
Final simplification99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (* y (- z)))) (t_1 (- (* z (* x y)))))
(if (<= (* y z) (- INFINITY))
t_1
(if (<= (* y z) -200000000.0)
t_0
(if (<= (* y z) 0.0001) x (if (<= (* y z) 2e+236) t_0 t_1))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = x * (y * -z);
double t_1 = -(z * (x * y));
double tmp;
if ((y * z) <= -((double) INFINITY)) {
tmp = t_1;
} else if ((y * z) <= -200000000.0) {
tmp = t_0;
} else if ((y * z) <= 0.0001) {
tmp = x;
} else if ((y * z) <= 2e+236) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = x * (y * -z);
double t_1 = -(z * (x * y));
double tmp;
if ((y * z) <= -Double.POSITIVE_INFINITY) {
tmp = t_1;
} else if ((y * z) <= -200000000.0) {
tmp = t_0;
} else if ((y * z) <= 0.0001) {
tmp = x;
} else if ((y * z) <= 2e+236) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = x * (y * -z) t_1 = -(z * (x * y)) tmp = 0 if (y * z) <= -math.inf: tmp = t_1 elif (y * z) <= -200000000.0: tmp = t_0 elif (y * z) <= 0.0001: tmp = x elif (y * z) <= 2e+236: tmp = t_0 else: tmp = t_1 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(x * Float64(y * Float64(-z))) t_1 = Float64(-Float64(z * Float64(x * y))) tmp = 0.0 if (Float64(y * z) <= Float64(-Inf)) tmp = t_1; elseif (Float64(y * z) <= -200000000.0) tmp = t_0; elseif (Float64(y * z) <= 0.0001) tmp = x; elseif (Float64(y * z) <= 2e+236) tmp = t_0; else tmp = t_1; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = x * (y * -z);
t_1 = -(z * (x * y));
tmp = 0.0;
if ((y * z) <= -Inf)
tmp = t_1;
elseif ((y * z) <= -200000000.0)
tmp = t_0;
elseif ((y * z) <= 0.0001)
tmp = x;
elseif ((y * z) <= 2e+236)
tmp = t_0;
else
tmp = t_1;
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[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = (-N[(z * N[(x * y), $MachinePrecision]), $MachinePrecision])}, If[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], t$95$1, If[LessEqual[N[(y * z), $MachinePrecision], -200000000.0], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 0.0001], x, If[LessEqual[N[(y * z), $MachinePrecision], 2e+236], t$95$0, t$95$1]]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := x \cdot \left(y \cdot \left(-z\right)\right)\\
t_1 := -z \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \cdot z \leq -\infty:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \cdot z \leq -200000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq 0.0001:\\
\;\;\;\;x\\
\mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{+236}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 2.00000000000000011e236 < (*.f64 y z) Initial program 74.3%
Taylor expanded in y around inf 74.3%
mul-1-neg74.3%
associate-*r*99.8%
Simplified99.8%
if -inf.0 < (*.f64 y z) < -2e8 or 1.00000000000000005e-4 < (*.f64 y z) < 2.00000000000000011e236Initial program 99.7%
Taylor expanded in y around inf 97.9%
mul-1-neg97.9%
associate-*r*90.1%
Simplified90.1%
Taylor expanded in x around 0 97.9%
if -2e8 < (*.f64 y z) < 1.00000000000000005e-4Initial program 100.0%
Taylor expanded in y around 0 98.2%
Final simplification98.3%
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) -200000000.0) (not (<= (* y z) 0.0001))) (* x (* y (- z))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -200000000.0) || !((y * z) <= 0.0001)) {
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) <= (-200000000.0d0)) .or. (.not. ((y * z) <= 0.0001d0))) 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) <= -200000000.0) || !((y * z) <= 0.0001)) {
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) <= -200000000.0) or not ((y * z) <= 0.0001): 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) <= -200000000.0) || !(Float64(y * z) <= 0.0001)) 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) <= -200000000.0) || ~(((y * z) <= 0.0001)))
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], -200000000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.0001]], $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 -200000000 \lor \neg \left(y \cdot z \leq 0.0001\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -2e8 or 1.00000000000000005e-4 < (*.f64 y z) Initial program 92.8%
Taylor expanded in y around inf 91.5%
mul-1-neg91.5%
associate-*r*92.8%
Simplified92.8%
Taylor expanded in x around 0 91.5%
if -2e8 < (*.f64 y z) < 1.00000000000000005e-4Initial program 100.0%
Taylor expanded in y around 0 98.2%
Final simplification94.4%
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) -200000000.0) (not (<= (* y z) 0.0001))) (* y (* x (- z))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -200000000.0) || !((y * z) <= 0.0001)) {
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 (((y * z) <= (-200000000.0d0)) .or. (.not. ((y * z) <= 0.0001d0))) 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 (((y * z) <= -200000000.0) || !((y * z) <= 0.0001)) {
tmp = y * (x * -z);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -200000000.0) or not ((y * z) <= 0.0001): 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 ((Float64(y * z) <= -200000000.0) || !(Float64(y * z) <= 0.0001)) tmp = Float64(y * Float64(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 (((y * z) <= -200000000.0) || ~(((y * z) <= 0.0001)))
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[N[(y * z), $MachinePrecision], -200000000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.0001]], $MachinePrecision]], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -200000000 \lor \neg \left(y \cdot z \leq 0.0001\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -2e8 or 1.00000000000000005e-4 < (*.f64 y z) Initial program 92.8%
Taylor expanded in y around inf 91.5%
mul-1-neg91.5%
associate-*r*92.8%
distribute-rgt-neg-in92.8%
*-commutative92.8%
associate-*l*91.4%
Simplified91.4%
if -2e8 < (*.f64 y z) < 1.00000000000000005e-4Initial program 100.0%
Taylor expanded in y around 0 98.2%
Final simplification94.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x 4.2e-101) (- x (* y (* x z))) (* x (- 1.0 (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 4.2e-101) {
tmp = x - (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 (x <= 4.2d-101) then
tmp = x - (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 (x <= 4.2e-101) {
tmp = x - (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 x <= 4.2e-101: tmp = x - (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 (x <= 4.2e-101) tmp = Float64(x - Float64(y * Float64(x * 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 (x <= 4.2e-101)
tmp = x - (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[LessEqual[x, 4.2e-101], N[(x - N[(y * N[(x * z), $MachinePrecision]), $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}\;x \leq 4.2 \cdot 10^{-101}:\\
\;\;\;\;x - y \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if x < 4.20000000000000031e-101Initial program 93.6%
sub-neg93.6%
distribute-rgt-in93.6%
*-un-lft-identity93.6%
distribute-rgt-neg-in93.6%
Applied egg-rr93.6%
*-commutative93.6%
*-commutative93.6%
associate-*r*94.5%
distribute-rgt-neg-out94.5%
distribute-lft-neg-in94.5%
associate-*l*93.6%
*-commutative93.6%
add-sqr-sqrt43.4%
sqrt-unprod61.2%
sqr-neg61.2%
sqrt-unprod25.1%
add-sqr-sqrt42.4%
cancel-sign-sub-inv42.4%
*-commutative42.4%
*-commutative42.4%
associate-*r*39.4%
add-sqr-sqrt22.1%
sqrt-unprod58.3%
sqr-neg58.3%
sqrt-unprod45.3%
add-sqr-sqrt93.5%
Applied egg-rr94.5%
if 4.20000000000000031e-101 < x Initial program 99.8%
Final simplification96.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -1.58e+165) (/ (* x y) y) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -1.58e+165) {
tmp = (x * y) / y;
} 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 <= (-1.58d+165)) then
tmp = (x * y) / y
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 <= -1.58e+165) {
tmp = (x * y) / y;
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -1.58e+165: tmp = (x * y) / y else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -1.58e+165) tmp = Float64(Float64(x * y) / y); 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 <= -1.58e+165)
tmp = (x * y) / y;
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[y, -1.58e+165], N[(N[(x * y), $MachinePrecision] / y), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.58 \cdot 10^{+165}:\\
\;\;\;\;\frac{x \cdot y}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.58000000000000007e165Initial program 89.5%
Taylor expanded in y around inf 85.6%
Taylor expanded in z around 0 6.3%
*-commutative6.3%
associate-*l/20.3%
Applied egg-rr20.3%
if -1.58000000000000007e165 < y Initial program 96.6%
Taylor expanded in y around 0 48.2%
Final simplification45.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.9%
Taylor expanded in y around 0 43.7%
Final simplification43.7%
herbie shell --seed 2024071
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))