
(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 (<= (* y z) 2e+157) (- x (* (* y z) x)) (* y (* z (- x)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 2e+157) {
tmp = x - ((y * z) * x);
} else {
tmp = y * (z * -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) <= 2d+157) then
tmp = x - ((y * z) * x)
else
tmp = y * (z * -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) <= 2e+157) {
tmp = x - ((y * z) * x);
} else {
tmp = y * (z * -x);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 2e+157: tmp = x - ((y * z) * x) else: tmp = y * (z * -x) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 2e+157) tmp = Float64(x - Float64(Float64(y * z) * x)); else tmp = Float64(y * Float64(z * 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) <= 2e+157)
tmp = x - ((y * z) * x);
else
tmp = y * (z * -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], 2e+157], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 2 \cdot 10^{+157}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 1.99999999999999997e157Initial program 98.6%
Taylor expanded in y around 0 98.6%
mul-1-neg98.6%
Simplified98.6%
unsub-neg98.6%
associate-*r*90.8%
*-commutative90.8%
Applied egg-rr90.8%
Taylor expanded in z around 0 98.6%
if 1.99999999999999997e157 < (*.f64 y z) Initial program 74.3%
Taylor expanded in y around 0 74.3%
mul-1-neg74.3%
Simplified74.3%
Taylor expanded in y around inf 74.3%
mul-1-neg74.3%
associate-*r*97.1%
*-commutative97.1%
distribute-lft-neg-in97.1%
Simplified97.1%
Taylor expanded in z around 0 74.3%
mul-1-neg74.3%
*-commutative74.3%
associate-*r*97.5%
distribute-rgt-neg-in97.5%
*-commutative97.5%
Simplified97.5%
Final simplification98.5%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) 2e+157) (* x (- 1.0 (* y z))) (* y (* z (- x)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 2e+157) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (z * -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) <= 2d+157) then
tmp = x * (1.0d0 - (y * z))
else
tmp = y * (z * -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) <= 2e+157) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (z * -x);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 2e+157: tmp = x * (1.0 - (y * z)) else: tmp = y * (z * -x) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 2e+157) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(y * Float64(z * 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) <= 2e+157)
tmp = x * (1.0 - (y * z));
else
tmp = y * (z * -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], 2e+157], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 2 \cdot 10^{+157}:\\
\;\;\;\;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.99999999999999997e157Initial program 98.6%
if 1.99999999999999997e157 < (*.f64 y z) Initial program 74.3%
Taylor expanded in y around 0 74.3%
mul-1-neg74.3%
Simplified74.3%
Taylor expanded in y around inf 74.3%
mul-1-neg74.3%
associate-*r*97.1%
*-commutative97.1%
distribute-lft-neg-in97.1%
Simplified97.1%
Taylor expanded in z around 0 74.3%
mul-1-neg74.3%
*-commutative74.3%
associate-*r*97.5%
distribute-rgt-neg-in97.5%
*-commutative97.5%
Simplified97.5%
Final simplification98.5%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -4.5e-86) (not (<= z 2.9e+30))) (* (* y z) (- x)) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.5e-86) || !(z <= 2.9e+30)) {
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 ((z <= (-4.5d-86)) .or. (.not. (z <= 2.9d+30))) 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 ((z <= -4.5e-86) || !(z <= 2.9e+30)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (z <= -4.5e-86) or not (z <= 2.9e+30): tmp = (y * z) * -x else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -4.5e-86) || !(z <= 2.9e+30)) 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 ((z <= -4.5e-86) || ~((z <= 2.9e+30)))
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[z, -4.5e-86], N[Not[LessEqual[z, 2.9e+30]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{-86} \lor \neg \left(z \leq 2.9 \cdot 10^{+30}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.4999999999999998e-86 or 2.8999999999999998e30 < z Initial program 90.6%
Taylor expanded in y around inf 67.7%
mul-1-neg67.7%
distribute-rgt-neg-in67.7%
distribute-rgt-neg-in67.7%
Simplified67.7%
if -4.4999999999999998e-86 < z < 2.8999999999999998e30Initial program 99.9%
Taylor expanded in y around 0 73.0%
Final simplification70.3%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -1.7e-86) (not (<= z 6.2e+29))) (* y (* z (- x))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.7e-86) || !(z <= 6.2e+29)) {
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 ((z <= (-1.7d-86)) .or. (.not. (z <= 6.2d+29))) 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 ((z <= -1.7e-86) || !(z <= 6.2e+29)) {
tmp = y * (z * -x);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (z <= -1.7e-86) or not (z <= 6.2e+29): tmp = y * (z * -x) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -1.7e-86) || !(z <= 6.2e+29)) tmp = Float64(y * Float64(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 ((z <= -1.7e-86) || ~((z <= 6.2e+29)))
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[z, -1.7e-86], N[Not[LessEqual[z, 6.2e+29]], $MachinePrecision]], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{-86} \lor \neg \left(z \leq 6.2 \cdot 10^{+29}\right):\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.7e-86 or 6.1999999999999998e29 < z Initial program 90.6%
Taylor expanded in y around 0 90.6%
mul-1-neg90.6%
Simplified90.6%
Taylor expanded in y around inf 67.7%
mul-1-neg67.7%
associate-*r*71.2%
*-commutative71.2%
distribute-lft-neg-in71.2%
Simplified71.2%
Taylor expanded in z around 0 67.7%
mul-1-neg67.7%
*-commutative67.7%
associate-*r*71.3%
distribute-rgt-neg-in71.3%
*-commutative71.3%
Simplified71.3%
if -1.7e-86 < z < 6.1999999999999998e29Initial program 99.9%
Taylor expanded in y around 0 73.0%
Final simplification72.1%
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.1%
Taylor expanded in y around 0 48.3%
Final simplification48.3%
herbie shell --seed 2023310
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))