
(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 6 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) -4e+275) (* y (* z (- x))) (if (<= (* y z) 2e+258) (* x (- 1.0 (* y z))) (* z (* y (- x))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -4e+275) {
tmp = y * (z * -x);
} else if ((y * z) <= 2e+258) {
tmp = x * (1.0 - (y * z));
} else {
tmp = z * (y * -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) <= (-4d+275)) then
tmp = y * (z * -x)
else if ((y * z) <= 2d+258) then
tmp = x * (1.0d0 - (y * z))
else
tmp = z * (y * -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) <= -4e+275) {
tmp = y * (z * -x);
} else if ((y * z) <= 2e+258) {
tmp = x * (1.0 - (y * z));
} else {
tmp = z * (y * -x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -4e+275: tmp = y * (z * -x) elif (y * z) <= 2e+258: tmp = x * (1.0 - (y * z)) else: tmp = z * (y * -x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -4e+275) tmp = Float64(y * Float64(z * Float64(-x))); elseif (Float64(y * z) <= 2e+258) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(z * Float64(y * Float64(-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) <= -4e+275)
tmp = y * (z * -x);
elseif ((y * z) <= 2e+258)
tmp = x * (1.0 - (y * z));
else
tmp = z * (y * -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], -4e+275], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 2e+258], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -4 \cdot 10^{+275}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{+258}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -3.99999999999999984e275Initial program 72.0%
Taylor expanded in y around inf 72.0%
mul-1-neg72.0%
*-commutative72.0%
associate-*r*99.5%
distribute-rgt-neg-in99.5%
Simplified99.5%
if -3.99999999999999984e275 < (*.f64 y z) < 2.00000000000000011e258Initial program 99.9%
if 2.00000000000000011e258 < (*.f64 y z) Initial program 55.2%
Taylor expanded in z around inf 99.9%
Taylor expanded in y around inf 99.9%
neg-mul-199.9%
*-commutative99.9%
distribute-rgt-neg-in99.9%
Simplified99.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 -1.8e+62) (not (<= y 1.4e-88))) (* z (* y (- x))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.8e+62) || !(y <= 1.4e-88)) {
tmp = z * (y * -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 <= (-1.8d+62)) .or. (.not. (y <= 1.4d-88))) then
tmp = z * (y * -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 <= -1.8e+62) || !(y <= 1.4e-88)) {
tmp = z * (y * -x);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y <= -1.8e+62) or not (y <= 1.4e-88): tmp = z * (y * -x) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -1.8e+62) || !(y <= 1.4e-88)) tmp = Float64(z * Float64(y * 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 <= -1.8e+62) || ~((y <= 1.4e-88)))
tmp = z * (y * -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[y, -1.8e+62], N[Not[LessEqual[y, 1.4e-88]], $MachinePrecision]], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{+62} \lor \neg \left(y \leq 1.4 \cdot 10^{-88}\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.8e62 or 1.39999999999999988e-88 < y Initial program 90.3%
Taylor expanded in z around inf 83.2%
Taylor expanded in y around inf 65.3%
neg-mul-165.3%
*-commutative65.3%
distribute-rgt-neg-in65.3%
Simplified65.3%
if -1.8e62 < y < 1.39999999999999988e-88Initial program 100.0%
Taylor expanded in y around 0 74.5%
Final simplification69.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 -1.85e+62) (not (<= y 1.3e-88))) (* x (* y (- z))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.85e+62) || !(y <= 1.3e-88)) {
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 <= (-1.85d+62)) .or. (.not. (y <= 1.3d-88))) 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 <= -1.85e+62) || !(y <= 1.3e-88)) {
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 <= -1.85e+62) or not (y <= 1.3e-88): 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 ((y <= -1.85e+62) || !(y <= 1.3e-88)) 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 <= -1.85e+62) || ~((y <= 1.3e-88)))
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[y, -1.85e+62], N[Not[LessEqual[y, 1.3e-88]], $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 \leq -1.85 \cdot 10^{+62} \lor \neg \left(y \leq 1.3 \cdot 10^{-88}\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.85000000000000007e62 or 1.30000000000000007e-88 < y Initial program 90.3%
Taylor expanded in y around inf 59.8%
mul-1-neg59.8%
distribute-rgt-neg-out59.8%
Simplified59.8%
if -1.85000000000000007e62 < y < 1.30000000000000007e-88Initial program 100.0%
Taylor expanded in y around 0 74.5%
Final simplification66.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -1.86e+62) (* y (* z (- x))) (if (<= y 1.4e-88) x (* z (* y (- x))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -1.86e+62) {
tmp = y * (z * -x);
} else if (y <= 1.4e-88) {
tmp = x;
} else {
tmp = z * (y * -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.86d+62)) then
tmp = y * (z * -x)
else if (y <= 1.4d-88) then
tmp = x
else
tmp = z * (y * -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.86e+62) {
tmp = y * (z * -x);
} else if (y <= 1.4e-88) {
tmp = x;
} else {
tmp = z * (y * -x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -1.86e+62: tmp = y * (z * -x) elif y <= 1.4e-88: tmp = x else: tmp = z * (y * -x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -1.86e+62) tmp = Float64(y * Float64(z * Float64(-x))); elseif (y <= 1.4e-88) tmp = x; else tmp = Float64(z * Float64(y * Float64(-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.86e+62)
tmp = y * (z * -x);
elseif (y <= 1.4e-88)
tmp = x;
else
tmp = z * (y * -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.86e+62], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.4e-88], x, N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.86 \cdot 10^{+62}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-88}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if y < -1.85999999999999995e62Initial program 91.0%
Taylor expanded in y around inf 70.3%
mul-1-neg70.3%
*-commutative70.3%
associate-*r*79.1%
distribute-rgt-neg-in79.1%
Simplified79.1%
if -1.85999999999999995e62 < y < 1.39999999999999988e-88Initial program 100.0%
Taylor expanded in y around 0 74.5%
if 1.39999999999999988e-88 < y Initial program 89.9%
Taylor expanded in z around inf 81.9%
Taylor expanded in y around inf 62.0%
neg-mul-162.0%
*-commutative62.0%
distribute-rgt-neg-in62.0%
Simplified62.0%
Final simplification70.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z 8e+177) x (/ (* z x) z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= 8e+177) {
tmp = x;
} else {
tmp = (z * x) / 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 (z <= 8d+177) then
tmp = x
else
tmp = (z * x) / 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 (z <= 8e+177) {
tmp = x;
} else {
tmp = (z * x) / z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if z <= 8e+177: tmp = x else: tmp = (z * x) / z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (z <= 8e+177) tmp = x; else tmp = Float64(Float64(z * x) / z); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= 8e+177)
tmp = x;
else
tmp = (z * x) / 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[z, 8e+177], x, N[(N[(z * x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 8 \cdot 10^{+177}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{z \cdot x}{z}\\
\end{array}
\end{array}
if z < 8.0000000000000001e177Initial program 96.3%
Taylor expanded in y around 0 56.8%
if 8.0000000000000001e177 < z Initial program 79.3%
Taylor expanded in z around inf 99.9%
Taylor expanded in y around 0 6.9%
associate-*r/31.5%
*-commutative31.5%
Applied egg-rr31.5%
Final simplification54.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 94.7%
Taylor expanded in y around 0 52.3%
herbie shell --seed 2024144
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))