
(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 (fma z (- y) 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -((double) INFINITY)) {
tmp = z * (x * -y);
} else {
tmp = x * fma(z, -y, 1.0);
}
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 * fma(z, Float64(-y), 1.0)); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], N[(x * N[(z * (-y) + 1.0), $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 \mathsf{fma}\left(z, -y, 1\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0Initial program 49.4%
Taylor expanded in y around inf 49.4%
Taylor expanded in y around inf 49.4%
neg-mul-149.4%
distribute-lft-neg-in49.4%
Simplified49.4%
Taylor expanded in x around 0 49.4%
associate-*r*99.8%
associate-*r*99.8%
*-commutative99.8%
mul-1-neg99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
if -inf.0 < (*.f64 y z) Initial program 98.7%
cancel-sign-sub-inv98.7%
+-commutative98.7%
*-commutative98.7%
fma-define98.7%
Simplified98.7%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= (* y z) -20000.0) (* y (* x (- z))) (if (<= (* y z) 1.0) x (* (* y z) (- x)))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -20000.0) {
tmp = y * (x * -z);
} else if ((y * z) <= 1.0) {
tmp = x;
} else {
tmp = (y * z) * -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) <= (-20000.0d0)) then
tmp = y * (x * -z)
else if ((y * z) <= 1.0d0) then
tmp = x
else
tmp = (y * z) * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -20000.0) {
tmp = y * (x * -z);
} else if ((y * z) <= 1.0) {
tmp = x;
} else {
tmp = (y * z) * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -20000.0: tmp = y * (x * -z) elif (y * z) <= 1.0: tmp = x else: tmp = (y * z) * -x return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -20000.0) tmp = Float64(y * Float64(x * Float64(-z))); elseif (Float64(y * z) <= 1.0) tmp = x; else tmp = Float64(Float64(y * z) * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= -20000.0) tmp = y * (x * -z); elseif ((y * z) <= 1.0) tmp = x; else tmp = (y * z) * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -20000.0], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 1.0], x, N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -20000:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -2e4Initial program 89.0%
Taylor expanded in y around inf 87.2%
mul-1-neg87.2%
*-commutative87.2%
associate-*l*91.1%
*-commutative91.1%
distribute-rgt-neg-in91.1%
distribute-rgt-neg-in91.1%
Simplified91.1%
if -2e4 < (*.f64 y z) < 1Initial program 100.0%
Taylor expanded in y around 0 95.8%
if 1 < (*.f64 y z) Initial program 95.0%
Taylor expanded in y around inf 93.1%
associate-*r*93.1%
mul-1-neg93.1%
Simplified93.1%
Final simplification94.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.4e-141) (not (<= z 16500.0))) (* (* y z) (- x)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.4e-141) || !(z <= 16500.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 ((z <= (-4.4d-141)) .or. (.not. (z <= 16500.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 ((z <= -4.4e-141) || !(z <= 16500.0)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.4e-141) or not (z <= 16500.0): tmp = (y * z) * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.4e-141) || !(z <= 16500.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 ((z <= -4.4e-141) || ~((z <= 16500.0))) tmp = (y * z) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.4e-141], N[Not[LessEqual[z, 16500.0]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.4 \cdot 10^{-141} \lor \neg \left(z \leq 16500\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.40000000000000018e-141 or 16500 < z Initial program 93.9%
Taylor expanded in y around inf 59.2%
associate-*r*59.2%
mul-1-neg59.2%
Simplified59.2%
if -4.40000000000000018e-141 < z < 16500Initial program 99.9%
Taylor expanded in y around 0 79.8%
Final simplification67.2%
(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 49.4%
Taylor expanded in y around inf 49.4%
Taylor expanded in y around inf 49.4%
neg-mul-149.4%
distribute-lft-neg-in49.4%
Simplified49.4%
Taylor expanded in x around 0 49.4%
associate-*r*99.8%
associate-*r*99.8%
*-commutative99.8%
mul-1-neg99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
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 96.2%
Taylor expanded in y around 0 52.5%
Final simplification52.5%
herbie shell --seed 2024067
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))