
(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 5 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: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* x (- 1.0 (* y z))) (- INFINITY)) (* y (* z (- x))) (- x (* x (* y z)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((x * (1.0 - (y * z))) <= -((double) INFINITY)) {
tmp = y * (z * -x);
} else {
tmp = x - (x * (y * z));
}
return tmp;
}
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((x * (1.0 - (y * z))) <= -Double.POSITIVE_INFINITY) {
tmp = y * (z * -x);
} else {
tmp = x - (x * (y * z));
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (x * (1.0 - (y * z))) <= -math.inf: tmp = y * (z * -x) else: tmp = x - (x * (y * z)) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x * Float64(1.0 - Float64(y * z))) <= Float64(-Inf)) tmp = Float64(y * Float64(z * Float64(-x))); else tmp = Float64(x - Float64(x * Float64(y * z))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x * (1.0 - (y * z))) <= -Inf)
tmp = y * (z * -x);
else
tmp = x - (x * (y * z));
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-Infinity)], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot \left(1 - y \cdot z\right) \leq -\infty:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < -inf.0Initial program 66.4%
Taylor expanded in y around inf 66.4%
mul-1-neg66.4%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
*-commutative99.8%
associate-*r*99.9%
distribute-rgt-neg-out99.9%
Simplified99.9%
if -inf.0 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 98.6%
sub-neg98.6%
distribute-rgt-in98.7%
*-un-lft-identity98.7%
distribute-rgt-neg-in98.7%
Applied egg-rr98.7%
Final simplification98.8%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- 1.0 (* y z))))) (if (<= t_0 (- INFINITY)) (* y (* z (- x))) t_0)))
assert(y < z);
double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = y * (z * -x);
} else {
tmp = t_0;
}
return tmp;
}
assert y < z;
public static double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = y * (z * -x);
} else {
tmp = t_0;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): t_0 = x * (1.0 - (y * z)) tmp = 0 if t_0 <= -math.inf: tmp = y * (z * -x) else: tmp = t_0 return tmp
y, z = sort([y, z]) function code(x, y, z) t_0 = Float64(x * Float64(1.0 - Float64(y * z))) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(y * Float64(z * Float64(-x))); else tmp = t_0; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = x * (1.0 - (y * z));
tmp = 0.0;
if (t_0 <= -Inf)
tmp = y * (z * -x);
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - y \cdot z\right)\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < -inf.0Initial program 66.4%
Taylor expanded in y around inf 66.4%
mul-1-neg66.4%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
*-commutative99.8%
associate-*r*99.9%
distribute-rgt-neg-out99.9%
Simplified99.9%
if -inf.0 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 98.6%
Final simplification98.8%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -4e+84) (not (<= y 6.4e-24))) (* z (* x (- y))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -4e+84) || !(y <= 6.4e-24)) {
tmp = z * (x * -y);
} else {
tmp = x;
}
return tmp;
}
NOTE: 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 <= (-4d+84)) .or. (.not. (y <= 6.4d-24))) then
tmp = z * (x * -y)
else
tmp = x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4e+84) || !(y <= 6.4e-24)) {
tmp = z * (x * -y);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y <= -4e+84) or not (y <= 6.4e-24): tmp = z * (x * -y) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -4e+84) || !(y <= 6.4e-24)) tmp = Float64(z * Float64(x * Float64(-y))); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= -4e+84) || ~((y <= 6.4e-24)))
tmp = z * (x * -y);
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[y, -4e+84], N[Not[LessEqual[y, 6.4e-24]], $MachinePrecision]], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+84} \lor \neg \left(y \leq 6.4 \cdot 10^{-24}\right):\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.00000000000000023e84 or 6.40000000000000025e-24 < y Initial program 90.2%
Taylor expanded in y around inf 59.2%
mul-1-neg59.2%
associate-*r*64.6%
Simplified64.6%
if -4.00000000000000023e84 < y < 6.40000000000000025e-24Initial program 99.9%
Taylor expanded in y around 0 78.0%
Final simplification71.4%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -7e+84) (* y (* z (- x))) (if (<= y 4.5e-25) x (* z (* x (- y))))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -7e+84) {
tmp = y * (z * -x);
} else if (y <= 4.5e-25) {
tmp = x;
} else {
tmp = z * (x * -y);
}
return tmp;
}
NOTE: 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 <= (-7d+84)) then
tmp = y * (z * -x)
else if (y <= 4.5d-25) then
tmp = x
else
tmp = z * (x * -y)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if (y <= -7e+84) {
tmp = y * (z * -x);
} else if (y <= 4.5e-25) {
tmp = x;
} else {
tmp = z * (x * -y);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if y <= -7e+84: tmp = y * (z * -x) elif y <= 4.5e-25: tmp = x else: tmp = z * (x * -y) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (y <= -7e+84) tmp = Float64(y * Float64(z * Float64(-x))); elseif (y <= 4.5e-25) tmp = x; else tmp = Float64(z * Float64(x * Float64(-y))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -7e+84)
tmp = y * (z * -x);
elseif (y <= 4.5e-25)
tmp = x;
else
tmp = z * (x * -y);
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, -7e+84], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.5e-25], x, N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{+84}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{-25}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\end{array}
\end{array}
if y < -6.9999999999999998e84Initial program 91.6%
Taylor expanded in y around inf 69.4%
mul-1-neg69.4%
associate-*r*71.3%
distribute-rgt-neg-in71.3%
*-commutative71.3%
associate-*r*72.7%
distribute-rgt-neg-out72.7%
Simplified72.7%
if -6.9999999999999998e84 < y < 4.5000000000000001e-25Initial program 99.9%
Taylor expanded in y around 0 78.0%
if 4.5000000000000001e-25 < y Initial program 89.1%
Taylor expanded in y around inf 50.8%
mul-1-neg50.8%
associate-*r*59.1%
Simplified59.1%
Final simplification71.6%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(y < z);
double code(double x, double y, double z) {
return x;
}
NOTE: 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 y < z;
public static double code(double x, double y, double z) {
return x;
}
[y, z] = sort([y, z]) def code(x, y, z): return x
y, z = sort([y, z]) function code(x, y, z) return x end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x
\end{array}
Initial program 95.1%
Taylor expanded in y around 0 55.9%
Final simplification55.9%
herbie shell --seed 2023318
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))