
(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}
(FPCore (x y z) :precision binary64 (if (<= (* y z) -5e+259) (* y (* x (- z))) (- x (* (* y z) x))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+259) {
tmp = y * (x * -z);
} else {
tmp = x - ((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) <= (-5d+259)) then
tmp = y * (x * -z)
else
tmp = x - ((y * z) * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+259) {
tmp = y * (x * -z);
} else {
tmp = x - ((y * z) * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -5e+259: tmp = y * (x * -z) else: tmp = x - ((y * z) * x) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -5e+259) tmp = Float64(y * Float64(x * Float64(-z))); 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) <= -5e+259) tmp = y * (x * -z); else tmp = x - ((y * z) * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -5e+259], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+259}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 y z) < -5.00000000000000033e259Initial program 77.5%
Taylor expanded in y around inf 77.5%
mul-1-neg77.5%
associate-*r*99.6%
distribute-rgt-neg-in99.6%
*-commutative99.6%
associate-*r*99.9%
distribute-rgt-neg-out99.9%
Simplified99.9%
if -5.00000000000000033e259 < (*.f64 y z) Initial program 98.6%
flip--82.4%
associate-*r/79.6%
metadata-eval79.6%
pow279.6%
+-commutative79.6%
fma-def79.6%
Applied egg-rr79.6%
associate-*l/79.4%
Simplified79.4%
Taylor expanded in y around 0 98.6%
associate-*r*98.6%
neg-mul-198.6%
cancel-sign-sub-inv98.6%
*-commutative98.6%
*-commutative98.6%
associate-*l*93.5%
*-commutative93.5%
Simplified93.5%
Taylor expanded in z around 0 98.6%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= (* y z) -2e+219) (* z (* x (- y))) (if (or (<= (* y z) -1000.0) (not (<= (* y z) 0.2))) (* x (* y (- z))) x)))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2e+219) {
tmp = z * (x * -y);
} else if (((y * z) <= -1000.0) || !((y * z) <= 0.2)) {
tmp = x * (y * -z);
} 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) <= (-2d+219)) then
tmp = z * (x * -y)
else if (((y * z) <= (-1000.0d0)) .or. (.not. ((y * z) <= 0.2d0))) then
tmp = x * (y * -z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2e+219) {
tmp = z * (x * -y);
} else if (((y * z) <= -1000.0) || !((y * z) <= 0.2)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -2e+219: tmp = z * (x * -y) elif ((y * z) <= -1000.0) or not ((y * z) <= 0.2): tmp = x * (y * -z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -2e+219) tmp = Float64(z * Float64(x * Float64(-y))); elseif ((Float64(y * z) <= -1000.0) || !(Float64(y * z) <= 0.2)) tmp = Float64(x * Float64(y * Float64(-z))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= -2e+219) tmp = z * (x * -y); elseif (((y * z) <= -1000.0) || ~(((y * z) <= 0.2))) tmp = x * (y * -z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -2e+219], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[(y * z), $MachinePrecision], -1000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.2]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -2 \cdot 10^{+219}:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{elif}\;y \cdot z \leq -1000 \lor \neg \left(y \cdot z \leq 0.2\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -1.99999999999999993e219Initial program 83.1%
Taylor expanded in y around inf 83.1%
mul-1-neg83.1%
associate-*r*99.7%
Simplified99.7%
if -1.99999999999999993e219 < (*.f64 y z) < -1e3 or 0.20000000000000001 < (*.f64 y z) Initial program 97.1%
Taylor expanded in y around inf 95.0%
mul-1-neg95.0%
distribute-rgt-neg-in95.0%
distribute-rgt-neg-out95.0%
Simplified95.0%
if -1e3 < (*.f64 y z) < 0.20000000000000001Initial program 100.0%
Taylor expanded in y around 0 97.1%
Final simplification96.5%
(FPCore (x y z) :precision binary64 (if (<= (* y z) -5e+259) (* y (* x (- z))) (if (or (<= (* y z) -1000.0) (not (<= (* y z) 0.2))) (* x (* y (- z))) x)))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+259) {
tmp = y * (x * -z);
} else if (((y * z) <= -1000.0) || !((y * z) <= 0.2)) {
tmp = x * (y * -z);
} 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) <= (-5d+259)) then
tmp = y * (x * -z)
else if (((y * z) <= (-1000.0d0)) .or. (.not. ((y * z) <= 0.2d0))) then
tmp = x * (y * -z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+259) {
tmp = y * (x * -z);
} else if (((y * z) <= -1000.0) || !((y * z) <= 0.2)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -5e+259: tmp = y * (x * -z) elif ((y * z) <= -1000.0) or not ((y * z) <= 0.2): tmp = x * (y * -z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -5e+259) tmp = Float64(y * Float64(x * Float64(-z))); elseif ((Float64(y * z) <= -1000.0) || !(Float64(y * z) <= 0.2)) tmp = Float64(x * Float64(y * Float64(-z))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= -5e+259) tmp = y * (x * -z); elseif (((y * z) <= -1000.0) || ~(((y * z) <= 0.2))) tmp = x * (y * -z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -5e+259], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[(y * z), $MachinePrecision], -1000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.2]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+259}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{elif}\;y \cdot z \leq -1000 \lor \neg \left(y \cdot z \leq 0.2\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -5.00000000000000033e259Initial program 77.5%
Taylor expanded in y around inf 77.5%
mul-1-neg77.5%
associate-*r*99.6%
distribute-rgt-neg-in99.6%
*-commutative99.6%
associate-*r*99.9%
distribute-rgt-neg-out99.9%
Simplified99.9%
if -5.00000000000000033e259 < (*.f64 y z) < -1e3 or 0.20000000000000001 < (*.f64 y z) Initial program 97.2%
Taylor expanded in y around inf 95.3%
mul-1-neg95.3%
distribute-rgt-neg-in95.3%
distribute-rgt-neg-out95.3%
Simplified95.3%
if -1e3 < (*.f64 y z) < 0.20000000000000001Initial program 100.0%
Taylor expanded in y around 0 97.1%
Final simplification96.5%
(FPCore (x y z) :precision binary64 (if (or (<= (* y z) -1000.0) (not (<= (* y z) 0.2))) (* z (* x (- y))) x))
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -1000.0) || !((y * z) <= 0.2)) {
tmp = z * (x * -y);
} 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) <= (-1000.0d0)) .or. (.not. ((y * z) <= 0.2d0))) then
tmp = z * (x * -y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -1000.0) || !((y * z) <= 0.2)) {
tmp = z * (x * -y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((y * z) <= -1000.0) or not ((y * z) <= 0.2): tmp = z * (x * -y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -1000.0) || !(Float64(y * z) <= 0.2)) tmp = Float64(z * Float64(x * Float64(-y))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((y * z) <= -1000.0) || ~(((y * z) <= 0.2))) tmp = z * (x * -y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -1000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.2]], $MachinePrecision]], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1000 \lor \neg \left(y \cdot z \leq 0.2\right):\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -1e3 or 0.20000000000000001 < (*.f64 y z) Initial program 94.2%
Taylor expanded in y around inf 92.6%
mul-1-neg92.6%
associate-*r*89.7%
Simplified89.7%
if -1e3 < (*.f64 y z) < 0.20000000000000001Initial program 100.0%
Taylor expanded in y around 0 97.1%
Final simplification93.1%
(FPCore (x y z) :precision binary64 (if (<= (* y z) -5e+259) (* y (* x (- z))) (* x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+259) {
tmp = y * (x * -z);
} else {
tmp = x * (1.0 - (y * z));
}
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) <= (-5d+259)) then
tmp = y * (x * -z)
else
tmp = x * (1.0d0 - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+259) {
tmp = y * (x * -z);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -5e+259: tmp = y * (x * -z) else: tmp = x * (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -5e+259) tmp = Float64(y * Float64(x * Float64(-z))); 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) <= -5e+259) tmp = y * (x * -z); else tmp = x * (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -5e+259], N[(y * N[(x * (-z)), $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 -5 \cdot 10^{+259}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -5.00000000000000033e259Initial program 77.5%
Taylor expanded in y around inf 77.5%
mul-1-neg77.5%
associate-*r*99.6%
distribute-rgt-neg-in99.6%
*-commutative99.6%
associate-*r*99.9%
distribute-rgt-neg-out99.9%
Simplified99.9%
if -5.00000000000000033e259 < (*.f64 y z) Initial program 98.6%
Final simplification98.7%
(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.9%
Taylor expanded in y around 0 46.9%
Final simplification46.9%
herbie shell --seed 2024010
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))