
(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}
(FPCore (x y z) :precision binary64 (if (or (<= (* z y) (- INFINITY)) (not (<= (* z y) 5e+161))) (* z (* y (- x))) (- x (* x (* z y)))))
double code(double x, double y, double z) {
double tmp;
if (((z * y) <= -((double) INFINITY)) || !((z * y) <= 5e+161)) {
tmp = z * (y * -x);
} else {
tmp = x - (x * (z * y));
}
return tmp;
}
public static double code(double x, double y, double z) {
double tmp;
if (((z * y) <= -Double.POSITIVE_INFINITY) || !((z * y) <= 5e+161)) {
tmp = z * (y * -x);
} else {
tmp = x - (x * (z * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((z * y) <= -math.inf) or not ((z * y) <= 5e+161): tmp = z * (y * -x) else: tmp = x - (x * (z * y)) return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(z * y) <= Float64(-Inf)) || !(Float64(z * y) <= 5e+161)) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = Float64(x - Float64(x * Float64(z * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((z * y) <= -Inf) || ~(((z * y) <= 5e+161))) tmp = z * (y * -x); else tmp = x - (x * (z * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(z * y), $MachinePrecision], (-Infinity)], N[Not[LessEqual[N[(z * y), $MachinePrecision], 5e+161]], $MachinePrecision]], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot y \leq -\infty \lor \neg \left(z \cdot y \leq 5 \cdot 10^{+161}\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot \left(z \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 4.9999999999999997e161 < (*.f64 y z) Initial program 74.4%
flip--12.8%
clear-num12.8%
+-commutative12.8%
fma-def12.8%
metadata-eval12.8%
pow212.8%
Applied egg-rr12.8%
Taylor expanded in y around inf 74.4%
mul-1-neg74.4%
*-commutative74.4%
distribute-rgt-neg-in74.4%
*-commutative74.4%
associate-*l*99.8%
Simplified99.8%
if -inf.0 < (*.f64 y z) < 4.9999999999999997e161Initial program 99.8%
remove-double-neg99.8%
distribute-lft-neg-out99.8%
neg-mul-199.8%
*-commutative99.8%
associate-*r*99.8%
distribute-lft-neg-in99.8%
distribute-rgt-neg-out99.8%
*-commutative99.8%
neg-mul-199.8%
remove-double-neg99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
metadata-eval99.8%
distribute-neg-in99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
distribute-lft-out--99.9%
*-rgt-identity99.9%
unsub-neg99.9%
mul-1-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
unsub-neg99.9%
mul-1-neg99.9%
remove-double-neg99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (* z (- y)))) (t_1 (* z (* y (- x)))))
(if (<= (* z y) (- INFINITY))
t_1
(if (<= (* z y) -400000.0)
t_0
(if (<= (* z y) 0.5) x (if (<= (* z y) 5e+161) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = x * (z * -y);
double t_1 = z * (y * -x);
double tmp;
if ((z * y) <= -((double) INFINITY)) {
tmp = t_1;
} else if ((z * y) <= -400000.0) {
tmp = t_0;
} else if ((z * y) <= 0.5) {
tmp = x;
} else if ((z * y) <= 5e+161) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = x * (z * -y);
double t_1 = z * (y * -x);
double tmp;
if ((z * y) <= -Double.POSITIVE_INFINITY) {
tmp = t_1;
} else if ((z * y) <= -400000.0) {
tmp = t_0;
} else if ((z * y) <= 0.5) {
tmp = x;
} else if ((z * y) <= 5e+161) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z * -y) t_1 = z * (y * -x) tmp = 0 if (z * y) <= -math.inf: tmp = t_1 elif (z * y) <= -400000.0: tmp = t_0 elif (z * y) <= 0.5: tmp = x elif (z * y) <= 5e+161: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z * Float64(-y))) t_1 = Float64(z * Float64(y * Float64(-x))) tmp = 0.0 if (Float64(z * y) <= Float64(-Inf)) tmp = t_1; elseif (Float64(z * y) <= -400000.0) tmp = t_0; elseif (Float64(z * y) <= 0.5) tmp = x; elseif (Float64(z * y) <= 5e+161) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z * -y); t_1 = z * (y * -x); tmp = 0.0; if ((z * y) <= -Inf) tmp = t_1; elseif ((z * y) <= -400000.0) tmp = t_0; elseif ((z * y) <= 0.5) tmp = x; elseif ((z * y) <= 5e+161) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z * (-y)), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * y), $MachinePrecision], (-Infinity)], t$95$1, If[LessEqual[N[(z * y), $MachinePrecision], -400000.0], t$95$0, If[LessEqual[N[(z * y), $MachinePrecision], 0.5], x, If[LessEqual[N[(z * y), $MachinePrecision], 5e+161], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z \cdot \left(-y\right)\right)\\
t_1 := z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{if}\;z \cdot y \leq -\infty:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \cdot y \leq -400000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \cdot y \leq 0.5:\\
\;\;\;\;x\\
\mathbf{elif}\;z \cdot y \leq 5 \cdot 10^{+161}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 4.9999999999999997e161 < (*.f64 y z) Initial program 74.4%
flip--12.8%
clear-num12.8%
+-commutative12.8%
fma-def12.8%
metadata-eval12.8%
pow212.8%
Applied egg-rr12.8%
Taylor expanded in y around inf 74.4%
mul-1-neg74.4%
*-commutative74.4%
distribute-rgt-neg-in74.4%
*-commutative74.4%
associate-*l*99.8%
Simplified99.8%
if -inf.0 < (*.f64 y z) < -4e5 or 0.5 < (*.f64 y z) < 4.9999999999999997e161Initial program 99.7%
remove-double-neg99.7%
distribute-lft-neg-out99.7%
neg-mul-199.7%
*-commutative99.7%
associate-*r*99.7%
distribute-lft-neg-in99.7%
distribute-rgt-neg-out99.7%
*-commutative99.7%
neg-mul-199.7%
remove-double-neg99.7%
cancel-sign-sub-inv99.7%
+-commutative99.7%
distribute-lft-neg-out99.7%
metadata-eval99.7%
distribute-neg-in99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around inf 96.2%
mul-1-neg96.2%
*-commutative96.2%
distribute-rgt-neg-in96.2%
Simplified96.2%
if -4e5 < (*.f64 y z) < 0.5Initial 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 97.4%
Final simplification97.6%
(FPCore (x y z) :precision binary64 (if (or (<= (* z y) (- INFINITY)) (not (<= (* z y) 5e+161))) (* z (* y (- x))) (* x (- 1.0 (* z y)))))
double code(double x, double y, double z) {
double tmp;
if (((z * y) <= -((double) INFINITY)) || !((z * y) <= 5e+161)) {
tmp = z * (y * -x);
} else {
tmp = x * (1.0 - (z * y));
}
return tmp;
}
public static double code(double x, double y, double z) {
double tmp;
if (((z * y) <= -Double.POSITIVE_INFINITY) || !((z * y) <= 5e+161)) {
tmp = z * (y * -x);
} else {
tmp = x * (1.0 - (z * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((z * y) <= -math.inf) or not ((z * y) <= 5e+161): tmp = z * (y * -x) else: tmp = x * (1.0 - (z * y)) return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(z * y) <= Float64(-Inf)) || !(Float64(z * y) <= 5e+161)) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = Float64(x * Float64(1.0 - Float64(z * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((z * y) <= -Inf) || ~(((z * y) <= 5e+161))) tmp = z * (y * -x); else tmp = x * (1.0 - (z * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(z * y), $MachinePrecision], (-Infinity)], N[Not[LessEqual[N[(z * y), $MachinePrecision], 5e+161]], $MachinePrecision]], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot y \leq -\infty \lor \neg \left(z \cdot y \leq 5 \cdot 10^{+161}\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 4.9999999999999997e161 < (*.f64 y z) Initial program 74.4%
flip--12.8%
clear-num12.8%
+-commutative12.8%
fma-def12.8%
metadata-eval12.8%
pow212.8%
Applied egg-rr12.8%
Taylor expanded in y around inf 74.4%
mul-1-neg74.4%
*-commutative74.4%
distribute-rgt-neg-in74.4%
*-commutative74.4%
associate-*l*99.8%
Simplified99.8%
if -inf.0 < (*.f64 y z) < 4.9999999999999997e161Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.9e+45) (not (<= y 1.4e-160))) (* z (* y (- x))) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.9e+45) || !(y <= 1.4e-160)) {
tmp = z * (y * -x);
} else {
tmp = x;
}
return tmp;
}
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.9d+45)) .or. (.not. (y <= 1.4d-160))) then
tmp = z * (y * -x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.9e+45) || !(y <= 1.4e-160)) {
tmp = z * (y * -x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.9e+45) or not (y <= 1.4e-160): tmp = z * (y * -x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.9e+45) || !(y <= 1.4e-160)) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.9e+45) || ~((y <= 1.4e-160))) tmp = z * (y * -x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.9e+45], N[Not[LessEqual[y, 1.4e-160]], $MachinePrecision]], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+45} \lor \neg \left(y \leq 1.4 \cdot 10^{-160}\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.9000000000000001e45 or 1.40000000000000008e-160 < y Initial program 91.1%
flip--64.4%
clear-num64.4%
+-commutative64.4%
fma-def64.4%
metadata-eval64.4%
pow264.4%
Applied egg-rr64.4%
Taylor expanded in y around inf 62.6%
mul-1-neg62.6%
*-commutative62.6%
distribute-rgt-neg-in62.6%
*-commutative62.6%
associate-*l*64.4%
Simplified64.4%
if -1.9000000000000001e45 < y < 1.40000000000000008e-160Initial program 98.9%
remove-double-neg98.9%
distribute-lft-neg-out98.9%
neg-mul-198.9%
*-commutative98.9%
associate-*r*98.9%
distribute-lft-neg-in98.9%
distribute-rgt-neg-out98.9%
*-commutative98.9%
neg-mul-198.9%
remove-double-neg98.9%
cancel-sign-sub-inv98.9%
+-commutative98.9%
distribute-lft-neg-out98.9%
metadata-eval98.9%
distribute-neg-in98.9%
fma-def98.9%
Simplified98.9%
Taylor expanded in y around 0 74.4%
Final simplification68.1%
(FPCore (x y z) :precision binary64 (if (<= z 8.8e+229) (- x (* x (* z y))) (- x (* z (* x y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= 8.8e+229) {
tmp = x - (x * (z * y));
} else {
tmp = x - (z * (x * y));
}
return tmp;
}
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 <= 8.8d+229) then
tmp = x - (x * (z * y))
else
tmp = x - (z * (x * y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 8.8e+229) {
tmp = x - (x * (z * y));
} else {
tmp = x - (z * (x * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 8.8e+229: tmp = x - (x * (z * y)) else: tmp = x - (z * (x * y)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 8.8e+229) tmp = Float64(x - Float64(x * Float64(z * y))); else tmp = Float64(x - Float64(z * Float64(x * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 8.8e+229) tmp = x - (x * (z * y)); else tmp = x - (z * (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 8.8e+229], N[(x - N[(x * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 8.8 \cdot 10^{+229}:\\
\;\;\;\;x - x \cdot \left(z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < 8.80000000000000014e229Initial program 95.0%
remove-double-neg95.0%
distribute-lft-neg-out95.0%
neg-mul-195.0%
*-commutative95.0%
associate-*r*95.0%
distribute-lft-neg-in95.0%
distribute-rgt-neg-out95.0%
*-commutative95.0%
neg-mul-195.0%
remove-double-neg95.0%
cancel-sign-sub-inv95.0%
+-commutative95.0%
distribute-lft-neg-out95.0%
metadata-eval95.0%
distribute-neg-in95.0%
fma-def95.0%
Simplified95.0%
Taylor expanded in x around 0 95.0%
mul-1-neg95.0%
distribute-lft-out--95.0%
*-rgt-identity95.0%
unsub-neg95.0%
mul-1-neg95.0%
+-commutative95.0%
distribute-neg-in95.0%
unsub-neg95.0%
mul-1-neg95.0%
remove-double-neg95.0%
Simplified95.0%
if 8.80000000000000014e229 < z Initial program 82.2%
flip--24.5%
clear-num24.4%
+-commutative24.4%
fma-def24.4%
metadata-eval24.4%
pow224.4%
Applied egg-rr24.4%
Taylor expanded in y around 0 82.3%
mul-1-neg82.3%
*-commutative82.3%
unsub-neg82.3%
*-commutative82.3%
associate-*l*99.8%
Simplified99.8%
Final simplification95.4%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
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
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 94.0%
remove-double-neg94.0%
distribute-lft-neg-out94.0%
neg-mul-194.0%
*-commutative94.0%
associate-*r*94.0%
distribute-lft-neg-in94.0%
distribute-rgt-neg-out94.0%
*-commutative94.0%
neg-mul-194.0%
remove-double-neg94.0%
cancel-sign-sub-inv94.0%
+-commutative94.0%
distribute-lft-neg-out94.0%
metadata-eval94.0%
distribute-neg-in94.0%
fma-def94.0%
Simplified94.0%
Taylor expanded in y around 0 46.9%
Final simplification46.9%
herbie shell --seed 2023290
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))