
(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) -1e+223) (* z (* x (- y))) (- x (* (* y z) x))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -1e+223) {
tmp = z * (x * -y);
} else {
tmp = x - ((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) <= (-1d+223)) then
tmp = z * (x * -y)
else
tmp = x - ((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) <= -1e+223) {
tmp = z * (x * -y);
} else {
tmp = x - ((y * z) * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -1e+223: tmp = z * (x * -y) else: tmp = x - ((y * z) * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -1e+223) tmp = Float64(z * Float64(x * Float64(-y))); else tmp = Float64(x - Float64(Float64(y * z) * 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) <= -1e+223)
tmp = z * (x * -y);
else
tmp = x - ((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], -1e+223], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(y * z), $MachinePrecision] * x), $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^{+223}:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 y z) < -1.00000000000000005e223Initial program 62.4%
Taylor expanded in y around inf 62.4%
mul-1-neg62.4%
associate-*r*99.5%
Simplified99.5%
if -1.00000000000000005e223 < (*.f64 y z) Initial program 99.0%
flip--88.2%
associate-*r/86.2%
metadata-eval86.2%
pow286.2%
+-commutative86.2%
fma-define86.2%
Applied egg-rr86.2%
*-commutative86.2%
associate-/l*85.6%
Simplified85.6%
Taylor expanded in y around 0 99.0%
*-commutative99.0%
associate-*r*94.5%
neg-mul-194.5%
unsub-neg94.5%
*-commutative94.5%
Simplified94.5%
Taylor expanded in y around 0 99.0%
Final simplification99.1%
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) -1000000000000.0) (not (<= (* y z) 2e-9))) (* z (* x (- y))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -1000000000000.0) || !((y * z) <= 2e-9)) {
tmp = z * (x * -y);
} 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 * z) <= (-1000000000000.0d0)) .or. (.not. ((y * z) <= 2d-9))) then
tmp = z * (x * -y)
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 * z) <= -1000000000000.0) || !((y * z) <= 2e-9)) {
tmp = z * (x * -y);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -1000000000000.0) or not ((y * z) <= 2e-9): tmp = z * (x * -y) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -1000000000000.0) || !(Float64(y * z) <= 2e-9)) tmp = Float64(z * Float64(x * Float64(-y))); 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 * z) <= -1000000000000.0) || ~(((y * z) <= 2e-9)))
tmp = z * (x * -y);
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[N[(y * z), $MachinePrecision], -1000000000000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 2e-9]], $MachinePrecision]], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1000000000000 \lor \neg \left(y \cdot z \leq 2 \cdot 10^{-9}\right):\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -1e12 or 2.00000000000000012e-9 < (*.f64 y z) Initial program 88.7%
Taylor expanded in y around inf 87.8%
mul-1-neg87.8%
associate-*r*88.5%
Simplified88.5%
if -1e12 < (*.f64 y z) < 2.00000000000000012e-9Initial program 100.0%
Taylor expanded in y around 0 98.9%
Final simplification94.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -1000000000000.0) (* z (* x (- y))) (if (<= (* y z) 2e-9) x (* y (* x (- z))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -1000000000000.0) {
tmp = z * (x * -y);
} else if ((y * z) <= 2e-9) {
tmp = x;
} else {
tmp = y * (x * -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) <= (-1000000000000.0d0)) then
tmp = z * (x * -y)
else if ((y * z) <= 2d-9) then
tmp = x
else
tmp = y * (x * -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) <= -1000000000000.0) {
tmp = z * (x * -y);
} else if ((y * z) <= 2e-9) {
tmp = x;
} else {
tmp = y * (x * -z);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -1000000000000.0: tmp = z * (x * -y) elif (y * z) <= 2e-9: tmp = x else: tmp = y * (x * -z) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -1000000000000.0) tmp = Float64(z * Float64(x * Float64(-y))); elseif (Float64(y * z) <= 2e-9) tmp = x; else tmp = Float64(y * Float64(x * Float64(-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) <= -1000000000000.0)
tmp = z * (x * -y);
elseif ((y * z) <= 2e-9)
tmp = x;
else
tmp = y * (x * -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[N[(y * z), $MachinePrecision], -1000000000000.0], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 2e-9], x, N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1000000000000:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{-9}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -1e12Initial program 82.4%
Taylor expanded in y around inf 81.9%
mul-1-neg81.9%
associate-*r*89.2%
Simplified89.2%
if -1e12 < (*.f64 y z) < 2.00000000000000012e-9Initial program 100.0%
Taylor expanded in y around 0 98.9%
if 2.00000000000000012e-9 < (*.f64 y z) Initial program 96.2%
Taylor expanded in y around inf 94.9%
mul-1-neg94.9%
associate-*r*87.6%
distribute-rgt-neg-in87.6%
*-commutative87.6%
associate-*l*88.2%
Simplified88.2%
Final simplification94.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -1000000000000.0) (* z (* x (- y))) (if (<= (* y z) 2e-9) x (* (* y z) (- x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -1000000000000.0) {
tmp = z * (x * -y);
} else if ((y * z) <= 2e-9) {
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 ((y * z) <= (-1000000000000.0d0)) then
tmp = z * (x * -y)
else if ((y * z) <= 2d-9) 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 ((y * z) <= -1000000000000.0) {
tmp = z * (x * -y);
} else if ((y * z) <= 2e-9) {
tmp = x;
} else {
tmp = (y * z) * -x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -1000000000000.0: tmp = z * (x * -y) elif (y * z) <= 2e-9: 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 (Float64(y * z) <= -1000000000000.0) tmp = Float64(z * Float64(x * Float64(-y))); elseif (Float64(y * z) <= 2e-9) tmp = x; else tmp = Float64(Float64(y * 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) <= -1000000000000.0)
tmp = z * (x * -y);
elseif ((y * z) <= 2e-9)
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[N[(y * z), $MachinePrecision], -1000000000000.0], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 2e-9], x, N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1000000000000:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{-9}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -1e12Initial program 82.4%
Taylor expanded in y around inf 81.9%
mul-1-neg81.9%
associate-*r*89.2%
Simplified89.2%
if -1e12 < (*.f64 y z) < 2.00000000000000012e-9Initial program 100.0%
Taylor expanded in y around 0 98.9%
if 2.00000000000000012e-9 < (*.f64 y z) Initial program 96.2%
flip--58.1%
associate-*r/53.2%
metadata-eval53.2%
pow253.2%
+-commutative53.2%
fma-define53.2%
Applied egg-rr53.2%
*-commutative53.2%
associate-/l*50.9%
Simplified50.9%
Taylor expanded in y around inf 49.6%
Taylor expanded in y around inf 94.9%
associate-*r*94.9%
neg-mul-194.9%
Simplified94.9%
Final simplification95.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -1e+223) (* z (* x (- y))) (* x (- 1.0 (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -1e+223) {
tmp = z * (x * -y);
} 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+223)) then
tmp = z * (x * -y)
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+223) {
tmp = z * (x * -y);
} 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+223: tmp = z * (x * -y) 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+223) tmp = Float64(z * Float64(x * Float64(-y))); 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+223)
tmp = z * (x * -y);
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[N[(y * z), $MachinePrecision], -1e+223], N[(z * N[(x * (-y)), $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^{+223}:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -1.00000000000000005e223Initial program 62.4%
Taylor expanded in y around inf 62.4%
mul-1-neg62.4%
associate-*r*99.5%
Simplified99.5%
if -1.00000000000000005e223 < (*.f64 y z) Initial program 99.0%
Final simplification99.1%
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.7%
Taylor expanded in y around 0 54.7%
Final simplification54.7%
herbie shell --seed 2024066
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))