
(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 (or (<= (* y z) -1e+185) (not (<= (* y z) 2e+182))) (* y (- (* x z))) (* x (- 1.0 (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -1e+185) || !((y * z) <= 2e+182)) {
tmp = y * -(x * z);
} else {
tmp = x * (1.0 - (y * z));
}
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) <= (-1d+185)) .or. (.not. ((y * z) <= 2d+182))) then
tmp = y * -(x * z)
else
tmp = x * (1.0d0 - (y * z))
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) <= -1e+185) || !((y * z) <= 2e+182)) {
tmp = y * -(x * z);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -1e+185) or not ((y * z) <= 2e+182): tmp = y * -(x * z) else: tmp = x * (1.0 - (y * z)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -1e+185) || !(Float64(y * z) <= 2e+182)) tmp = Float64(y * Float64(-Float64(x * z))); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); 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) <= -1e+185) || ~(((y * z) <= 2e+182)))
tmp = y * -(x * z);
else
tmp = x * (1.0 - (y * z));
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[N[(y * z), $MachinePrecision], -1e+185], N[Not[LessEqual[N[(y * z), $MachinePrecision], 2e+182]], $MachinePrecision]], N[(y * (-N[(x * z), $MachinePrecision])), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+185} \lor \neg \left(y \cdot z \leq 2 \cdot 10^{+182}\right):\\
\;\;\;\;y \cdot \left(-x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -9.9999999999999998e184 or 2.0000000000000001e182 < (*.f64 y z) Initial program 81.4%
Taylor expanded in y around inf 81.4%
mul-1-neg81.4%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
*-commutative99.8%
associate-*r*99.7%
distribute-rgt-neg-out99.7%
Simplified99.7%
if -9.9999999999999998e184 < (*.f64 y z) < 2.0000000000000001e182Initial program 99.9%
Final simplification99.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -1.38e+42) (not (<= y 1.5e-88))) (* (* y z) (- x)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.38e+42) || !(y <= 1.5e-88)) {
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 ((y <= (-1.38d+42)) .or. (.not. (y <= 1.5d-88))) 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 ((y <= -1.38e+42) || !(y <= 1.5e-88)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y <= -1.38e+42) or not (y <= 1.5e-88): 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 ((y <= -1.38e+42) || !(y <= 1.5e-88)) 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 ((y <= -1.38e+42) || ~((y <= 1.5e-88)))
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[y, -1.38e+42], N[Not[LessEqual[y, 1.5e-88]], $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}\;y \leq -1.38 \cdot 10^{+42} \lor \neg \left(y \leq 1.5 \cdot 10^{-88}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.3800000000000001e42 or 1.5e-88 < y Initial program 90.2%
Taylor expanded in y around inf 66.0%
mul-1-neg66.0%
distribute-rgt-neg-in66.0%
distribute-rgt-neg-out66.0%
Simplified66.0%
if -1.3800000000000001e42 < y < 1.5e-88Initial program 100.0%
Taylor expanded in y around 0 75.0%
Final simplification69.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -1.18e+42) (not (<= y 1.25e-86))) (* y (- (* x z))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.18e+42) || !(y <= 1.25e-86)) {
tmp = y * -(x * z);
} 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 ((y <= (-1.18d+42)) .or. (.not. (y <= 1.25d-86))) then
tmp = y * -(x * z)
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 ((y <= -1.18e+42) || !(y <= 1.25e-86)) {
tmp = y * -(x * z);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y <= -1.18e+42) or not (y <= 1.25e-86): tmp = y * -(x * z) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -1.18e+42) || !(y <= 1.25e-86)) tmp = Float64(y * Float64(-Float64(x * z))); 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 ((y <= -1.18e+42) || ~((y <= 1.25e-86)))
tmp = y * -(x * z);
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[y, -1.18e+42], N[Not[LessEqual[y, 1.25e-86]], $MachinePrecision]], N[(y * (-N[(x * z), $MachinePrecision])), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.18 \cdot 10^{+42} \lor \neg \left(y \leq 1.25 \cdot 10^{-86}\right):\\
\;\;\;\;y \cdot \left(-x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.18e42 or 1.25e-86 < y Initial program 90.2%
Taylor expanded in y around inf 66.0%
mul-1-neg66.0%
associate-*r*75.0%
distribute-rgt-neg-in75.0%
*-commutative75.0%
associate-*r*72.5%
distribute-rgt-neg-out72.5%
Simplified72.5%
if -1.18e42 < y < 1.25e-86Initial program 100.0%
Taylor expanded in y around 0 75.0%
Final simplification73.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x 8e+107) (- x (* y (* x z))) (- x (* x (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 8e+107) {
tmp = x - (y * (x * z));
} else {
tmp = x - (x * (y * z));
}
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 (x <= 8d+107) then
tmp = x - (y * (x * z))
else
tmp = x - (x * (y * z))
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (x <= 8e+107) {
tmp = x - (y * (x * z));
} else {
tmp = x - (x * (y * z));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= 8e+107: tmp = x - (y * (x * z)) else: tmp = x - (x * (y * z)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= 8e+107) tmp = Float64(x - Float64(y * Float64(x * z))); else tmp = Float64(x - Float64(x * Float64(y * z))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= 8e+107)
tmp = x - (y * (x * z));
else
tmp = x - (x * (y * z));
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[x, 8e+107], N[(x - N[(y * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8 \cdot 10^{+107}:\\
\;\;\;\;x - y \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if x < 7.9999999999999998e107Initial program 93.3%
sub-neg93.3%
distribute-rgt-in93.3%
*-un-lft-identity93.3%
distribute-rgt-neg-in93.3%
Applied egg-rr93.3%
distribute-rgt-neg-out93.3%
distribute-lft-neg-out93.3%
associate-*r*93.8%
*-commutative93.8%
distribute-lft-neg-in93.8%
add-sqr-sqrt51.9%
sqrt-unprod58.7%
sqr-neg58.7%
sqrt-unprod27.2%
add-sqr-sqrt45.2%
*-commutative45.2%
distribute-lft-neg-in45.2%
cancel-sign-sub-inv45.2%
associate-*l*47.6%
*-commutative47.6%
*-commutative47.6%
associate-*r*45.2%
Applied egg-rr93.8%
if 7.9999999999999998e107 < x Initial program 100.0%
sub-neg100.0%
distribute-rgt-in100.0%
*-un-lft-identity100.0%
distribute-rgt-neg-in100.0%
Applied egg-rr100.0%
Final simplification94.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x 5e+83) (- x (* y (* x z))) (* x (- 1.0 (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 5e+83) {
tmp = x - (y * (x * z));
} else {
tmp = x * (1.0 - (y * z));
}
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 (x <= 5d+83) then
tmp = x - (y * (x * z))
else
tmp = x * (1.0d0 - (y * z))
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (x <= 5e+83) {
tmp = x - (y * (x * z));
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= 5e+83: tmp = x - (y * (x * z)) else: tmp = x * (1.0 - (y * z)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= 5e+83) tmp = Float64(x - Float64(y * Float64(x * z))); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= 5e+83)
tmp = x - (y * (x * z));
else
tmp = x * (1.0 - (y * z));
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[x, 5e+83], N[(x - N[(y * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{+83}:\\
\;\;\;\;x - y \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if x < 5.00000000000000029e83Initial program 93.0%
sub-neg93.0%
distribute-rgt-in93.0%
*-un-lft-identity93.0%
distribute-rgt-neg-in93.0%
Applied egg-rr93.0%
distribute-rgt-neg-out93.0%
distribute-lft-neg-out93.0%
associate-*r*93.5%
*-commutative93.5%
distribute-lft-neg-in93.5%
add-sqr-sqrt51.7%
sqrt-unprod56.9%
sqr-neg56.9%
sqrt-unprod26.5%
add-sqr-sqrt43.7%
*-commutative43.7%
distribute-lft-neg-in43.7%
cancel-sign-sub-inv43.7%
associate-*l*46.3%
*-commutative46.3%
*-commutative46.3%
associate-*r*43.7%
Applied egg-rr93.5%
if 5.00000000000000029e83 < x Initial program 100.0%
Final simplification94.8%
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 94.4%
Taylor expanded in y around 0 46.8%
Final simplification46.8%
herbie shell --seed 2024029
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))