
(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 (or (<= (* y z) (- INFINITY)) (not (<= (* y z) 2e+198))) (* z (* y (- x))) (* x (- 1.0 (* y z)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -((double) INFINITY)) || !((y * z) <= 2e+198)) {
tmp = z * (y * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -Double.POSITIVE_INFINITY) || !((y * z) <= 2e+198)) {
tmp = z * (y * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -math.inf) or not ((y * z) <= 2e+198): tmp = z * (y * -x) else: tmp = x * (1.0 - (y * z)) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= Float64(-Inf)) || !(Float64(y * z) <= 2e+198)) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (((y * z) <= -Inf) || ~(((y * z) <= 2e+198)))
tmp = z * (y * -x);
else
tmp = x * (1.0 - (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[Or[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], N[Not[LessEqual[N[(y * z), $MachinePrecision], 2e+198]], $MachinePrecision]], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -\infty \lor \neg \left(y \cdot z \leq 2 \cdot 10^{+198}\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 2.00000000000000004e198 < (*.f64 y z) Initial program 71.8%
Taylor expanded in y around inf 71.8%
associate-*r*71.8%
associate-*r*99.9%
mul-1-neg99.9%
*-commutative99.9%
*-commutative99.9%
Simplified99.9%
if -inf.0 < (*.f64 y z) < 2.00000000000000004e198Initial program 99.8%
Final simplification99.8%
NOTE: y and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (* z (- x)))))
(if (<= (* y z) -5000000.0)
t_0
(if (<= (* y z) 0.05) x (if (<= (* y z) 2e+177) (* (* y z) (- x)) t_0)))))assert(y < z);
double code(double x, double y, double z) {
double t_0 = y * (z * -x);
double tmp;
if ((y * z) <= -5000000.0) {
tmp = t_0;
} else if ((y * z) <= 0.05) {
tmp = x;
} else if ((y * z) <= 2e+177) {
tmp = (y * z) * -x;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = y * (z * -x)
if ((y * z) <= (-5000000.0d0)) then
tmp = t_0
else if ((y * z) <= 0.05d0) then
tmp = x
else if ((y * z) <= 2d+177) then
tmp = (y * z) * -x
else
tmp = t_0
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double t_0 = y * (z * -x);
double tmp;
if ((y * z) <= -5000000.0) {
tmp = t_0;
} else if ((y * z) <= 0.05) {
tmp = x;
} else if ((y * z) <= 2e+177) {
tmp = (y * z) * -x;
} else {
tmp = t_0;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): t_0 = y * (z * -x) tmp = 0 if (y * z) <= -5000000.0: tmp = t_0 elif (y * z) <= 0.05: tmp = x elif (y * z) <= 2e+177: tmp = (y * z) * -x else: tmp = t_0 return tmp
y, z = sort([y, z]) function code(x, y, z) t_0 = Float64(y * Float64(z * Float64(-x))) tmp = 0.0 if (Float64(y * z) <= -5000000.0) tmp = t_0; elseif (Float64(y * z) <= 0.05) tmp = x; elseif (Float64(y * z) <= 2e+177) tmp = Float64(Float64(y * 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 = y * (z * -x);
tmp = 0.0;
if ((y * z) <= -5000000.0)
tmp = t_0;
elseif ((y * z) <= 0.05)
tmp = x;
elseif ((y * z) <= 2e+177)
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[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], -5000000.0], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 0.05], x, If[LessEqual[N[(y * z), $MachinePrecision], 2e+177], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
t_0 := y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{if}\;y \cdot z \leq -5000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \cdot z \leq 0.05:\\
\;\;\;\;x\\
\mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{+177}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (*.f64 y z) < -5e6 or 2e177 < (*.f64 y z) Initial program 86.2%
sub-neg86.2%
distribute-rgt-in86.2%
*-un-lft-identity86.2%
*-commutative86.2%
+-commutative86.2%
distribute-rgt-neg-in86.2%
Applied egg-rr86.2%
+-commutative86.2%
*-commutative86.2%
distribute-rgt-neg-out86.2%
cancel-sign-sub-inv86.2%
*-commutative86.2%
Applied egg-rr86.2%
Taylor expanded in y around inf 84.5%
*-commutative84.5%
associate-*r*93.0%
mul-1-neg93.0%
distribute-rgt-neg-in93.0%
*-commutative93.0%
Simplified93.0%
if -5e6 < (*.f64 y z) < 0.050000000000000003Initial program 100.0%
Taylor expanded in y around 0 96.7%
if 0.050000000000000003 < (*.f64 y z) < 2e177Initial program 99.7%
Taylor expanded in y around inf 92.1%
mul-1-neg92.1%
distribute-rgt-neg-in92.1%
distribute-rgt-neg-out92.1%
Simplified92.1%
Final simplification94.9%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= (* y z) -5000000.0) (not (<= (* y z) 0.05))) (* (* y z) (- x)) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -5000000.0) || !((y * z) <= 0.05)) {
tmp = (y * z) * -x;
} 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 * z) <= (-5000000.0d0)) .or. (.not. ((y * z) <= 0.05d0))) then
tmp = (y * z) * -x
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 * z) <= -5000000.0) || !((y * z) <= 0.05)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -5000000.0) or not ((y * z) <= 0.05): tmp = (y * z) * -x else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -5000000.0) || !(Float64(y * z) <= 0.05)) tmp = Float64(Float64(y * z) * Float64(-x)); 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 * z) <= -5000000.0) || ~(((y * z) <= 0.05)))
tmp = (y * z) * -x;
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[N[(y * z), $MachinePrecision], -5000000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.05]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5000000 \lor \neg \left(y \cdot z \leq 0.05\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -5e6 or 0.050000000000000003 < (*.f64 y z) Initial program 90.0%
Taylor expanded in y around inf 86.7%
mul-1-neg86.7%
distribute-rgt-neg-in86.7%
distribute-rgt-neg-out86.7%
Simplified86.7%
if -5e6 < (*.f64 y z) < 0.050000000000000003Initial program 100.0%
Taylor expanded in y around 0 96.7%
Final simplification92.2%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -5000000.0) (* y (* z (- x))) (if (<= (* y z) 0.05) x (* z (* y (- x))))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5000000.0) {
tmp = y * (z * -x);
} else if ((y * z) <= 0.05) {
tmp = x;
} else {
tmp = z * (y * -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 * z) <= (-5000000.0d0)) then
tmp = y * (z * -x)
else if ((y * z) <= 0.05d0) then
tmp = x
else
tmp = z * (y * -x)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5000000.0) {
tmp = y * (z * -x);
} else if ((y * z) <= 0.05) {
tmp = x;
} else {
tmp = z * (y * -x);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -5000000.0: tmp = y * (z * -x) elif (y * z) <= 0.05: tmp = x else: tmp = z * (y * -x) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -5000000.0) tmp = Float64(y * Float64(z * Float64(-x))); elseif (Float64(y * z) <= 0.05) tmp = x; else tmp = Float64(z * Float64(y * Float64(-x))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= -5000000.0)
tmp = y * (z * -x);
elseif ((y * z) <= 0.05)
tmp = x;
else
tmp = z * (y * -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[LessEqual[N[(y * z), $MachinePrecision], -5000000.0], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.05], x, N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5000000:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 0.05:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -5e6Initial program 89.3%
sub-neg89.3%
distribute-rgt-in89.3%
*-un-lft-identity89.3%
*-commutative89.3%
+-commutative89.3%
distribute-rgt-neg-in89.3%
Applied egg-rr89.3%
+-commutative89.3%
*-commutative89.3%
distribute-rgt-neg-out89.3%
cancel-sign-sub-inv89.3%
*-commutative89.3%
Applied egg-rr89.3%
Taylor expanded in y around inf 86.8%
*-commutative86.8%
associate-*r*89.4%
mul-1-neg89.4%
distribute-rgt-neg-in89.4%
*-commutative89.4%
Simplified89.4%
if -5e6 < (*.f64 y z) < 0.050000000000000003Initial program 100.0%
Taylor expanded in y around 0 96.7%
if 0.050000000000000003 < (*.f64 y z) Initial program 90.6%
Taylor expanded in y around inf 86.6%
associate-*r*86.6%
associate-*r*89.5%
mul-1-neg89.5%
*-commutative89.5%
*-commutative89.5%
Simplified89.5%
Final simplification93.4%
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.5%
Taylor expanded in y around 0 54.4%
Final simplification54.4%
herbie shell --seed 2023301
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))