
(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}
(FPCore (x y z) :precision binary64 (if (<= (* y z) (- INFINITY)) (* z (* x (- y))) (- x (* (* y z) x))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -((double) INFINITY)) {
tmp = z * (x * -y);
} else {
tmp = x - ((y * z) * x);
}
return tmp;
}
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -Double.POSITIVE_INFINITY) {
tmp = z * (x * -y);
} else {
tmp = x - ((y * z) * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -math.inf: tmp = z * (x * -y) else: tmp = x - ((y * z) * x) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= Float64(-Inf)) tmp = Float64(z * Float64(x * Float64(-y))); else tmp = Float64(x - Float64(Float64(y * z) * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= -Inf) tmp = z * (x * -y); else tmp = x - ((y * z) * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -\infty:\\
\;\;\;\;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) < -inf.0Initial program 36.9%
Taylor expanded in y around inf 36.9%
mul-1-neg36.9%
associate-*r*99.9%
Simplified99.9%
if -inf.0 < (*.f64 y z) Initial program 98.7%
sub-neg98.7%
distribute-rgt-in98.7%
*-un-lft-identity98.7%
distribute-rgt-neg-in98.7%
Applied egg-rr98.7%
*-commutative98.7%
associate-*l*89.0%
add-sqr-sqrt43.4%
sqrt-unprod61.9%
sqr-neg61.9%
sqrt-unprod24.1%
add-sqr-sqrt49.0%
associate-*r*52.2%
*-commutative52.2%
cancel-sign-sub52.2%
distribute-rgt-neg-out52.2%
add-sqr-sqrt37.1%
add-sqr-sqrt52.2%
associate-*l*50.6%
add-sqr-sqrt26.1%
sqrt-unprod65.8%
sqr-neg65.8%
sqrt-unprod48.5%
add-sqr-sqrt95.1%
Applied egg-rr95.1%
Taylor expanded in y around 0 98.7%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= (* y z) (- INFINITY)) (* z (* x (- y))) (if (or (<= (* y z) -5.0) (not (<= (* y z) 4e-15))) (* (* y z) (- x)) x)))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -((double) INFINITY)) {
tmp = z * (x * -y);
} else if (((y * z) <= -5.0) || !((y * z) <= 4e-15)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -Double.POSITIVE_INFINITY) {
tmp = z * (x * -y);
} else if (((y * z) <= -5.0) || !((y * z) <= 4e-15)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -math.inf: tmp = z * (x * -y) elif ((y * z) <= -5.0) or not ((y * z) <= 4e-15): tmp = (y * z) * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= Float64(-Inf)) tmp = Float64(z * Float64(x * Float64(-y))); elseif ((Float64(y * z) <= -5.0) || !(Float64(y * z) <= 4e-15)) tmp = Float64(Float64(y * z) * Float64(-x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= -Inf) tmp = z * (x * -y); elseif (((y * z) <= -5.0) || ~(((y * z) <= 4e-15))) tmp = (y * z) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[(y * z), $MachinePrecision], -5.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 4e-15]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -\infty:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{elif}\;y \cdot z \leq -5 \lor \neg \left(y \cdot z \leq 4 \cdot 10^{-15}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0Initial program 36.9%
Taylor expanded in y around inf 36.9%
mul-1-neg36.9%
associate-*r*99.9%
Simplified99.9%
if -inf.0 < (*.f64 y z) < -5 or 4.0000000000000003e-15 < (*.f64 y z) Initial program 97.3%
Taylor expanded in y around inf 94.7%
mul-1-neg94.7%
associate-*r*82.3%
Simplified82.3%
Taylor expanded in x around 0 94.7%
if -5 < (*.f64 y z) < 4.0000000000000003e-15Initial program 100.0%
Taylor expanded in y around 0 98.9%
Final simplification97.1%
(FPCore (x y z) :precision binary64 (if (or (<= (* y z) -1.0) (not (<= (* y z) 1.0))) (* (* y z) (- x)) x))
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -1.0) || !((y * z) <= 1.0)) {
tmp = (y * z) * -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 * z) <= (-1.0d0)) .or. (.not. ((y * z) <= 1.0d0))) then
tmp = (y * z) * -x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -1.0) || !((y * z) <= 1.0)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((y * z) <= -1.0) or not ((y * z) <= 1.0): tmp = (y * z) * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -1.0) || !(Float64(y * z) <= 1.0)) tmp = Float64(Float64(y * z) * Float64(-x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((y * z) <= -1.0) || ~(((y * z) <= 1.0))) tmp = (y * z) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -1.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 1.0]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1 \lor \neg \left(y \cdot z \leq 1\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -1 or 1 < (*.f64 y z) Initial program 90.4%
Taylor expanded in y around inf 88.0%
mul-1-neg88.0%
associate-*r*84.3%
Simplified84.3%
Taylor expanded in x around 0 88.0%
if -1 < (*.f64 y z) < 1Initial program 100.0%
Taylor expanded in y around 0 98.9%
Final simplification93.4%
(FPCore (x y z) :precision binary64 (if (<= (* y z) (- INFINITY)) (* z (* x (- y))) (* x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -((double) INFINITY)) {
tmp = z * (x * -y);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -Double.POSITIVE_INFINITY) {
tmp = z * (x * -y);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -math.inf: tmp = z * (x * -y) else: tmp = x * (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= Float64(-Inf)) tmp = Float64(z * Float64(x * Float64(-y))); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= -Inf) tmp = z * (x * -y); else tmp = x * (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -\infty:\\
\;\;\;\;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) < -inf.0Initial program 36.9%
Taylor expanded in y around inf 36.9%
mul-1-neg36.9%
associate-*r*99.9%
Simplified99.9%
if -inf.0 < (*.f64 y z) Initial program 98.7%
Final simplification98.8%
(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 95.1%
Taylor expanded in y around 0 50.7%
Final simplification50.7%
herbie shell --seed 2024076
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))