
(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) 1e+179) (- x (* (* y z) x)) (* (- y) (* z x))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 1e+179) {
tmp = x - ((y * z) * x);
} else {
tmp = -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) <= 1d+179) then
tmp = x - ((y * z) * x)
else
tmp = -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) <= 1e+179) {
tmp = x - ((y * z) * x);
} else {
tmp = -y * (z * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 1e+179: tmp = x - ((y * z) * x) else: tmp = -y * (z * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 1e+179) tmp = Float64(x - Float64(Float64(y * z) * x)); else tmp = Float64(Float64(-y) * Float64(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) <= 1e+179)
tmp = x - ((y * z) * x);
else
tmp = -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], 1e+179], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[((-y) * N[(z * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 10^{+179}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot \left(z \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 9.9999999999999998e178Initial program 98.6%
sub-neg98.6%
distribute-rgt-in98.6%
*-un-lft-identity98.6%
distribute-rgt-neg-in98.6%
Applied egg-rr98.6%
*-commutative98.6%
associate-*r*92.9%
distribute-rgt-neg-out92.9%
distribute-lft-neg-out92.9%
add-sqr-sqrt49.5%
sqrt-unprod63.3%
sqr-neg63.3%
sqrt-unprod22.6%
add-sqr-sqrt53.8%
cancel-sign-sub-inv53.8%
associate-*r*55.0%
*-commutative55.0%
associate-*l*53.3%
add-sqr-sqrt21.7%
sqrt-unprod63.5%
sqr-neg63.5%
sqrt-unprod49.2%
add-sqr-sqrt94.6%
Applied egg-rr94.6%
Taylor expanded in y around 0 98.6%
if 9.9999999999999998e178 < (*.f64 y z) Initial program 73.2%
Taylor expanded in y around inf 96.3%
Taylor expanded in z around inf 96.3%
mul-1-neg96.3%
*-commutative96.3%
distribute-rgt-neg-in96.3%
Simplified96.3%
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) -20000000.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) <= -20000000.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) <= (-20000000.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) <= -20000000.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) <= -20000000.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) <= -20000000.0) || !(Float64(y * z) <= 0.5)) 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 (((y * z) <= -20000000.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], -20000000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.5]], $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}\;y \cdot z \leq -20000000 \lor \neg \left(y \cdot z \leq 0.5\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -2e7 or 0.5 < (*.f64 y z) Initial program 91.6%
Taylor expanded in y around inf 89.5%
mul-1-neg89.5%
distribute-rgt-neg-in89.5%
distribute-rgt-neg-out89.5%
Simplified89.5%
if -2e7 < (*.f64 y z) < 0.5Initial program 100.0%
Taylor expanded in y around 0 97.3%
Final simplification93.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) -20000000.0) (* z (* y (- x))) (if (<= (* 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) <= -20000000.0) {
tmp = z * (y * -x);
} else if ((y * z) <= 0.5) {
tmp = x;
} else {
tmp = -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) <= (-20000000.0d0)) then
tmp = z * (y * -x)
else if ((y * z) <= 0.5d0) then
tmp = x
else
tmp = -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) <= -20000000.0) {
tmp = z * (y * -x);
} else if ((y * z) <= 0.5) {
tmp = x;
} else {
tmp = -y * (z * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -20000000.0: tmp = z * (y * -x) elif (y * z) <= 0.5: tmp = x else: tmp = -y * (z * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -20000000.0) tmp = Float64(z * Float64(y * Float64(-x))); elseif (Float64(y * z) <= 0.5) tmp = x; else tmp = Float64(Float64(-y) * Float64(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) <= -20000000.0)
tmp = z * (y * -x);
elseif ((y * z) <= 0.5)
tmp = x;
else
tmp = -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], -20000000.0], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.5], x, N[((-y) * N[(z * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -20000000:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 0.5:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot \left(z \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -2e7Initial program 96.0%
Taylor expanded in z around inf 91.0%
Taylor expanded in y around inf 89.8%
mul-1-neg89.8%
distribute-rgt-neg-in89.8%
Simplified89.8%
if -2e7 < (*.f64 y z) < 0.5Initial program 100.0%
Taylor expanded in y around 0 97.3%
if 0.5 < (*.f64 y z) Initial program 85.3%
Taylor expanded in y around inf 88.2%
Taylor expanded in z around inf 91.3%
mul-1-neg91.3%
*-commutative91.3%
distribute-rgt-neg-in91.3%
Simplified91.3%
Final simplification93.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -20000000.0) (* (* y z) (- x)) (if (<= (* 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) <= -20000000.0) {
tmp = (y * z) * -x;
} else if ((y * z) <= 0.5) {
tmp = x;
} else {
tmp = -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) <= (-20000000.0d0)) then
tmp = (y * z) * -x
else if ((y * z) <= 0.5d0) then
tmp = x
else
tmp = -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) <= -20000000.0) {
tmp = (y * z) * -x;
} else if ((y * z) <= 0.5) {
tmp = x;
} else {
tmp = -y * (z * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -20000000.0: tmp = (y * z) * -x elif (y * z) <= 0.5: tmp = x else: tmp = -y * (z * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -20000000.0) tmp = Float64(Float64(y * z) * Float64(-x)); elseif (Float64(y * z) <= 0.5) tmp = x; else tmp = Float64(Float64(-y) * Float64(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) <= -20000000.0)
tmp = (y * z) * -x;
elseif ((y * z) <= 0.5)
tmp = x;
else
tmp = -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], -20000000.0], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.5], x, N[((-y) * N[(z * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -20000000:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{elif}\;y \cdot z \leq 0.5:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot \left(z \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -2e7Initial program 96.0%
Taylor expanded in y around inf 94.8%
mul-1-neg94.8%
distribute-rgt-neg-in94.8%
distribute-rgt-neg-out94.8%
Simplified94.8%
if -2e7 < (*.f64 y z) < 0.5Initial program 100.0%
Taylor expanded in y around 0 97.3%
if 0.5 < (*.f64 y z) Initial program 85.3%
Taylor expanded in y around inf 88.2%
Taylor expanded in z around inf 91.3%
mul-1-neg91.3%
*-commutative91.3%
distribute-rgt-neg-in91.3%
Simplified91.3%
Final simplification95.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) 1e+179) (* x (- 1.0 (* y z))) (* (- y) (* z x))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 1e+179) {
tmp = x * (1.0 - (y * z));
} else {
tmp = -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) <= 1d+179) then
tmp = x * (1.0d0 - (y * z))
else
tmp = -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) <= 1e+179) {
tmp = x * (1.0 - (y * z));
} else {
tmp = -y * (z * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 1e+179: tmp = x * (1.0 - (y * z)) else: tmp = -y * (z * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 1e+179) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(Float64(-y) * Float64(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) <= 1e+179)
tmp = x * (1.0 - (y * z));
else
tmp = -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], 1e+179], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-y) * N[(z * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 10^{+179}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot \left(z \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 9.9999999999999998e178Initial program 98.6%
if 9.9999999999999998e178 < (*.f64 y z) Initial program 73.2%
Taylor expanded in y around inf 96.3%
Taylor expanded in z around inf 96.3%
mul-1-neg96.3%
*-commutative96.3%
distribute-rgt-neg-in96.3%
Simplified96.3%
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 (<= (* y z) -5e+63) (/ (* y x) y) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+63) {
tmp = (y * x) / 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 * z) <= (-5d+63)) then
tmp = (y * x) / 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 * z) <= -5e+63) {
tmp = (y * x) / y;
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -5e+63: tmp = (y * x) / y 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+63) tmp = Float64(Float64(y * x) / 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 * z) <= -5e+63)
tmp = (y * x) / 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[N[(y * z), $MachinePrecision], -5e+63], N[(N[(y * x), $MachinePrecision] / y), $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^{+63}:\\
\;\;\;\;\frac{y \cdot x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -5.00000000000000011e63Initial program 95.3%
Taylor expanded in y around inf 92.8%
Taylor expanded in z around 0 8.1%
*-commutative8.1%
associate-*l/26.7%
Applied egg-rr26.7%
if -5.00000000000000011e63 < (*.f64 y z) Initial program 96.0%
Taylor expanded in y around 0 66.0%
Final simplification56.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 95.8%
Taylor expanded in y around 0 50.5%
herbie shell --seed 2024096
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))