
(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) 1.4e+242) (* x (fma z (- y) 1.0)) (* y (* z (- x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 1.4e+242) {
tmp = x * fma(z, -y, 1.0);
} else {
tmp = y * (z * -x);
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 1.4e+242) tmp = Float64(x * fma(z, Float64(-y), 1.0)); else tmp = Float64(y * Float64(z * Float64(-x))); end return 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], 1.4e+242], N[(x * N[(z * (-y) + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 1.4 \cdot 10^{+242}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(z, -y, 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 1.4e242Initial program 98.2%
cancel-sign-sub-inv98.2%
+-commutative98.2%
*-commutative98.2%
fma-def98.2%
Simplified98.2%
if 1.4e242 < (*.f64 y z) Initial program 75.0%
Taylor expanded in y around inf 75.0%
mul-1-neg75.0%
distribute-rgt-neg-in75.0%
distribute-rgt-neg-in75.0%
Simplified75.0%
distribute-rgt-neg-out75.0%
distribute-rgt-neg-in75.0%
neg-sub075.0%
flip--9.1%
metadata-eval9.1%
pow29.1%
add-sqr-sqrt9.0%
sqrt-unprod9.1%
sqr-neg9.1%
sqrt-unprod0.0%
add-sqr-sqrt0.1%
sub-neg0.1%
neg-sub00.1%
add-sqr-sqrt0.0%
sqrt-unprod9.1%
sqr-neg9.1%
sqrt-unprod9.0%
add-sqr-sqrt9.1%
Applied egg-rr9.1%
sub0-neg9.1%
associate-*r*9.2%
associate-*r*15.7%
Simplified15.7%
distribute-frac-neg15.7%
pow115.7%
pow-div99.9%
metadata-eval99.9%
pow199.9%
associate-*r*75.0%
distribute-lft-neg-in75.0%
*-commutative75.0%
associate-*r*99.8%
Applied egg-rr99.8%
Final simplification98.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -2.7e-72) (not (<= z 2.05e+61))) (* (* y z) (- x)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.7e-72) || !(z <= 2.05e+61)) {
tmp = (y * z) * -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 ((z <= (-2.7d-72)) .or. (.not. (z <= 2.05d+61))) then
tmp = (y * z) * -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 ((z <= -2.7e-72) || !(z <= 2.05e+61)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -2.7e-72) or not (z <= 2.05e+61): tmp = (y * z) * -x else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -2.7e-72) || !(z <= 2.05e+61)) tmp = Float64(Float64(y * z) * 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 ((z <= -2.7e-72) || ~((z <= 2.05e+61)))
tmp = (y * z) * -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[z, -2.7e-72], N[Not[LessEqual[z, 2.05e+61]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{-72} \lor \neg \left(z \leq 2.05 \cdot 10^{+61}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.7e-72 or 2.04999999999999986e61 < z Initial program 92.8%
Taylor expanded in y around inf 61.7%
mul-1-neg61.7%
distribute-rgt-neg-in61.7%
distribute-rgt-neg-in61.7%
Simplified61.7%
if -2.7e-72 < z < 2.04999999999999986e61Initial program 99.9%
Taylor expanded in y around 0 75.0%
Final simplification68.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -2.15e-72) (not (<= z 1.82e+59))) (* z (* y (- x))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.15e-72) || !(z <= 1.82e+59)) {
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 ((z <= (-2.15d-72)) .or. (.not. (z <= 1.82d+59))) 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 ((z <= -2.15e-72) || !(z <= 1.82e+59)) {
tmp = z * (y * -x);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -2.15e-72) or not (z <= 1.82e+59): 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 ((z <= -2.15e-72) || !(z <= 1.82e+59)) 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 ((z <= -2.15e-72) || ~((z <= 1.82e+59)))
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[z, -2.15e-72], N[Not[LessEqual[z, 1.82e+59]], $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}\;z \leq -2.15 \cdot 10^{-72} \lor \neg \left(z \leq 1.82 \cdot 10^{+59}\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.1499999999999999e-72 or 1.82000000000000008e59 < z Initial program 92.8%
Taylor expanded in y around inf 61.7%
mul-1-neg61.7%
distribute-rgt-neg-in61.7%
distribute-rgt-neg-in61.7%
Simplified61.7%
distribute-rgt-neg-out61.7%
distribute-rgt-neg-in61.7%
neg-sub061.7%
flip--18.3%
metadata-eval18.3%
pow218.3%
add-sqr-sqrt5.9%
sqrt-unprod5.5%
sqr-neg5.5%
sqrt-unprod0.8%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.8%
sqrt-unprod5.5%
sqr-neg5.5%
sqrt-unprod5.9%
add-sqr-sqrt18.3%
Applied egg-rr18.3%
sub0-neg18.3%
associate-*r*16.1%
associate-*r*18.4%
Simplified18.4%
distribute-frac-neg18.4%
pow118.4%
pow-div63.8%
metadata-eval63.8%
pow163.8%
associate-*r*61.7%
distribute-lft-neg-in61.7%
associate-*r*63.8%
Applied egg-rr63.8%
if -2.1499999999999999e-72 < z < 1.82000000000000008e59Initial program 99.9%
Taylor expanded in y around 0 75.0%
Final simplification69.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z -3.1e-73) (* z (* y (- x))) (if (<= z 3.6e+58) x (* y (* z (- x))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= -3.1e-73) {
tmp = z * (y * -x);
} else if (z <= 3.6e+58) {
tmp = x;
} else {
tmp = y * (z * -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 (z <= (-3.1d-73)) then
tmp = z * (y * -x)
else if (z <= 3.6d+58) then
tmp = x
else
tmp = y * (z * -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 (z <= -3.1e-73) {
tmp = z * (y * -x);
} else if (z <= 3.6e+58) {
tmp = x;
} else {
tmp = y * (z * -x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if z <= -3.1e-73: tmp = z * (y * -x) elif z <= 3.6e+58: tmp = x else: tmp = y * (z * -x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (z <= -3.1e-73) tmp = Float64(z * Float64(y * Float64(-x))); elseif (z <= 3.6e+58) tmp = x; else tmp = Float64(y * Float64(z * 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 (z <= -3.1e-73)
tmp = z * (y * -x);
elseif (z <= 3.6e+58)
tmp = x;
else
tmp = y * (z * -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[z, -3.1e-73], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 3.6e+58], x, N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{-73}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{+58}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if z < -3.09999999999999969e-73Initial program 95.2%
Taylor expanded in y around inf 55.7%
mul-1-neg55.7%
distribute-rgt-neg-in55.7%
distribute-rgt-neg-in55.7%
Simplified55.7%
distribute-rgt-neg-out55.7%
distribute-rgt-neg-in55.7%
neg-sub055.7%
flip--15.1%
metadata-eval15.1%
pow215.1%
add-sqr-sqrt4.1%
sqrt-unprod3.5%
sqr-neg3.5%
sqrt-unprod0.8%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.8%
sqrt-unprod3.5%
sqr-neg3.5%
sqrt-unprod4.1%
add-sqr-sqrt15.1%
Applied egg-rr15.1%
sub0-neg15.1%
associate-*r*15.1%
associate-*r*16.2%
Simplified16.2%
distribute-frac-neg16.2%
pow116.2%
pow-div58.1%
metadata-eval58.1%
pow158.1%
associate-*r*55.7%
distribute-lft-neg-in55.7%
associate-*r*58.1%
Applied egg-rr58.1%
if -3.09999999999999969e-73 < z < 3.59999999999999996e58Initial program 99.9%
Taylor expanded in y around 0 75.0%
if 3.59999999999999996e58 < z Initial program 89.4%
Taylor expanded in y around inf 70.5%
mul-1-neg70.5%
distribute-rgt-neg-in70.5%
distribute-rgt-neg-in70.5%
Simplified70.5%
distribute-rgt-neg-out70.5%
distribute-rgt-neg-in70.5%
neg-sub070.5%
flip--23.0%
metadata-eval23.0%
pow223.0%
add-sqr-sqrt8.5%
sqrt-unprod8.4%
sqr-neg8.4%
sqrt-unprod0.9%
add-sqr-sqrt1.5%
sub-neg1.5%
neg-sub01.5%
add-sqr-sqrt0.9%
sqrt-unprod8.4%
sqr-neg8.4%
sqrt-unprod8.5%
add-sqr-sqrt23.0%
Applied egg-rr23.0%
sub0-neg23.0%
associate-*r*17.6%
associate-*r*21.5%
Simplified21.5%
distribute-frac-neg21.5%
pow121.5%
pow-div72.0%
metadata-eval72.0%
pow172.0%
associate-*r*70.5%
distribute-lft-neg-in70.5%
*-commutative70.5%
associate-*r*75.9%
Applied egg-rr75.9%
Final simplification69.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) 1.4e+242) (* x (- 1.0 (* y z))) (* y (* z (- x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 1.4e+242) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (z * -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) <= 1.4d+242) then
tmp = x * (1.0d0 - (y * z))
else
tmp = y * (z * -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) <= 1.4e+242) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (z * -x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 1.4e+242: tmp = x * (1.0 - (y * z)) else: tmp = y * (z * -x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 1.4e+242) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(y * Float64(z * 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) <= 1.4e+242)
tmp = x * (1.0 - (y * z));
else
tmp = y * (z * -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], 1.4e+242], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 1.4 \cdot 10^{+242}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 1.4e242Initial program 98.2%
if 1.4e242 < (*.f64 y z) Initial program 75.0%
Taylor expanded in y around inf 75.0%
mul-1-neg75.0%
distribute-rgt-neg-in75.0%
distribute-rgt-neg-in75.0%
Simplified75.0%
distribute-rgt-neg-out75.0%
distribute-rgt-neg-in75.0%
neg-sub075.0%
flip--9.1%
metadata-eval9.1%
pow29.1%
add-sqr-sqrt9.0%
sqrt-unprod9.1%
sqr-neg9.1%
sqrt-unprod0.0%
add-sqr-sqrt0.1%
sub-neg0.1%
neg-sub00.1%
add-sqr-sqrt0.0%
sqrt-unprod9.1%
sqr-neg9.1%
sqrt-unprod9.0%
add-sqr-sqrt9.1%
Applied egg-rr9.1%
sub0-neg9.1%
associate-*r*9.2%
associate-*r*15.7%
Simplified15.7%
distribute-frac-neg15.7%
pow115.7%
pow-div99.9%
metadata-eval99.9%
pow199.9%
associate-*r*75.0%
distribute-lft-neg-in75.0%
*-commutative75.0%
associate-*r*99.8%
Applied egg-rr99.8%
Final simplification98.3%
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 96.2%
Taylor expanded in y around 0 53.0%
Final simplification53.0%
herbie shell --seed 2024024
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))