
(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) -500000.0) (not (<= (* y z) 0.2))) (* y (* x (- z))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -500000.0) || !((y * z) <= 0.2)) {
tmp = y * (x * -z);
} 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) <= (-500000.0d0)) .or. (.not. ((y * z) <= 0.2d0))) then
tmp = y * (x * -z)
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) <= -500000.0) || !((y * z) <= 0.2)) {
tmp = y * (x * -z);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -500000.0) or not ((y * z) <= 0.2): tmp = y * (x * -z) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -500000.0) || !(Float64(y * z) <= 0.2)) tmp = Float64(y * Float64(x * Float64(-z))); 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) <= -500000.0) || ~(((y * z) <= 0.2)))
tmp = y * (x * -z);
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], -500000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.2]], $MachinePrecision]], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -500000 \lor \neg \left(y \cdot z \leq 0.2\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -5e5 or 0.20000000000000001 < (*.f64 y z) Initial program 91.7%
remove-double-neg91.7%
distribute-lft-neg-out91.7%
neg-mul-191.7%
*-commutative91.7%
associate-*r*91.7%
distribute-lft-neg-in91.7%
distribute-rgt-neg-out91.7%
*-commutative91.7%
neg-mul-191.7%
remove-double-neg91.7%
cancel-sign-sub-inv91.7%
+-commutative91.7%
distribute-lft-neg-out91.7%
metadata-eval91.7%
distribute-neg-in91.7%
fma-def91.7%
Simplified91.7%
Taylor expanded in y around inf 91.6%
mul-1-neg91.6%
distribute-rgt-neg-in91.6%
distribute-rgt-neg-in91.6%
Simplified91.6%
if -5e5 < (*.f64 y z) < 0.20000000000000001Initial program 100.0%
remove-double-neg100.0%
distribute-lft-neg-out100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
metadata-eval100.0%
distribute-neg-in100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 98.7%
Final simplification94.8%
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) (* x (- (fma y z -1.0))) (* y (* x (- z)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((x * (1.0 - (y * z))) <= ((double) INFINITY)) {
tmp = x * -fma(y, z, -1.0);
} else {
tmp = y * (x * -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))) <= Inf) tmp = Float64(x * Float64(-fma(y, z, -1.0))); else tmp = Float64(y * Float64(x * Float64(-z))); end return 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[(x * (-N[(y * z + -1.0), $MachinePrecision])), $MachinePrecision], N[(y * N[(x * (-z)), $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:\\
\;\;\;\;x \cdot \left(-\mathsf{fma}\left(y, z, -1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < +inf.0Initial program 95.4%
remove-double-neg95.4%
distribute-lft-neg-out95.4%
neg-mul-195.4%
*-commutative95.4%
associate-*r*95.4%
distribute-lft-neg-in95.4%
distribute-rgt-neg-out95.4%
*-commutative95.4%
neg-mul-195.4%
remove-double-neg95.4%
cancel-sign-sub-inv95.4%
+-commutative95.4%
distribute-lft-neg-out95.4%
metadata-eval95.4%
distribute-neg-in95.4%
fma-def95.4%
Simplified95.4%
if +inf.0 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 95.4%
remove-double-neg95.4%
distribute-lft-neg-out95.4%
neg-mul-195.4%
*-commutative95.4%
associate-*r*95.4%
distribute-lft-neg-in95.4%
distribute-rgt-neg-out95.4%
*-commutative95.4%
neg-mul-195.4%
remove-double-neg95.4%
cancel-sign-sub-inv95.4%
+-commutative95.4%
distribute-lft-neg-out95.4%
metadata-eval95.4%
distribute-neg-in95.4%
fma-def95.4%
Simplified95.4%
Taylor expanded in y around inf 52.5%
mul-1-neg52.5%
distribute-rgt-neg-in52.5%
distribute-rgt-neg-in52.5%
Simplified52.5%
Final simplification95.4%
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) t_0 (* y (* x (- z))))))
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 = t_0;
} else {
tmp = y * (x * -z);
}
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 = t_0;
} else {
tmp = y * (x * -z);
}
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 = t_0 else: tmp = y * (x * -z) 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 <= Inf) tmp = t_0; else tmp = Float64(y * Float64(x * Float64(-z))); 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 = t_0;
else
tmp = y * (x * -z);
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], t$95$0, N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]]]
\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:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < +inf.0Initial program 95.4%
if +inf.0 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 95.4%
remove-double-neg95.4%
distribute-lft-neg-out95.4%
neg-mul-195.4%
*-commutative95.4%
associate-*r*95.4%
distribute-lft-neg-in95.4%
distribute-rgt-neg-out95.4%
*-commutative95.4%
neg-mul-195.4%
remove-double-neg95.4%
cancel-sign-sub-inv95.4%
+-commutative95.4%
distribute-lft-neg-out95.4%
metadata-eval95.4%
distribute-neg-in95.4%
fma-def95.4%
Simplified95.4%
Taylor expanded in y around inf 52.5%
mul-1-neg52.5%
distribute-rgt-neg-in52.5%
distribute-rgt-neg-in52.5%
Simplified52.5%
Final simplification95.4%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= (* y z) -500000.0) (not (<= (* y z) 0.2))) (* x (* y (- z))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -500000.0) || !((y * z) <= 0.2)) {
tmp = x * (y * -z);
} 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) <= (-500000.0d0)) .or. (.not. ((y * z) <= 0.2d0))) then
tmp = x * (y * -z)
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) <= -500000.0) || !((y * z) <= 0.2)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -500000.0) or not ((y * z) <= 0.2): tmp = x * (y * -z) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -500000.0) || !(Float64(y * z) <= 0.2)) tmp = Float64(x * Float64(y * Float64(-z))); 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) <= -500000.0) || ~(((y * z) <= 0.2)))
tmp = x * (y * -z);
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], -500000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.2]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -500000 \lor \neg \left(y \cdot z \leq 0.2\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -5e5 or 0.20000000000000001 < (*.f64 y z) Initial program 91.7%
Taylor expanded in y around inf 90.7%
associate-*r*90.7%
neg-mul-190.7%
*-commutative90.7%
Simplified90.7%
if -5e5 < (*.f64 y z) < 0.20000000000000001Initial program 100.0%
remove-double-neg100.0%
distribute-lft-neg-out100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
metadata-eval100.0%
distribute-neg-in100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 98.7%
Final simplification94.3%
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.4%
remove-double-neg95.4%
distribute-lft-neg-out95.4%
neg-mul-195.4%
*-commutative95.4%
associate-*r*95.4%
distribute-lft-neg-in95.4%
distribute-rgt-neg-out95.4%
*-commutative95.4%
neg-mul-195.4%
remove-double-neg95.4%
cancel-sign-sub-inv95.4%
+-commutative95.4%
distribute-lft-neg-out95.4%
metadata-eval95.4%
distribute-neg-in95.4%
fma-def95.4%
Simplified95.4%
Taylor expanded in y around 0 46.3%
Final simplification46.3%
herbie shell --seed 2023274
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))