
(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) -2e+232) (* y (* z (- x))) (- x (* (* y z) x))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2e+232) {
tmp = y * (z * -x);
} 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) <= (-2d+232)) then
tmp = y * (z * -x)
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) <= -2e+232) {
tmp = y * (z * -x);
} else {
tmp = x - ((y * z) * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -2e+232: tmp = y * (z * -x) else: tmp = x - ((y * z) * x) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -2e+232) tmp = Float64(y * Float64(z * Float64(-x))); 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) <= -2e+232) tmp = y * (z * -x); else tmp = x - ((y * z) * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -2e+232], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -2 \cdot 10^{+232}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 y z) < -2.00000000000000011e232Initial program 73.4%
Taylor expanded in y around inf 73.4%
mul-1-neg73.4%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
*-commutative99.8%
associate-*l*99.9%
Simplified99.9%
if -2.00000000000000011e232 < (*.f64 y z) Initial program 99.5%
sub-neg99.5%
distribute-rgt-in99.5%
*-un-lft-identity99.5%
distribute-rgt-neg-in99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (<= (* y z) -2e+232) (* y (* z (- x))) (if (or (<= (* y z) -20.0) (not (<= (* y z) 0.005))) (* (* y z) (- x)) x)))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2e+232) {
tmp = y * (z * -x);
} else if (((y * z) <= -20.0) || !((y * z) <= 0.005)) {
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) <= (-2d+232)) then
tmp = y * (z * -x)
else if (((y * z) <= (-20.0d0)) .or. (.not. ((y * z) <= 0.005d0))) 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) <= -2e+232) {
tmp = y * (z * -x);
} else if (((y * z) <= -20.0) || !((y * z) <= 0.005)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -2e+232: tmp = y * (z * -x) elif ((y * z) <= -20.0) or not ((y * z) <= 0.005): tmp = (y * z) * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -2e+232) tmp = Float64(y * Float64(z * Float64(-x))); elseif ((Float64(y * z) <= -20.0) || !(Float64(y * z) <= 0.005)) 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) <= -2e+232) tmp = y * (z * -x); elseif (((y * z) <= -20.0) || ~(((y * z) <= 0.005))) tmp = (y * z) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -2e+232], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[(y * z), $MachinePrecision], -20.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.005]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -2 \cdot 10^{+232}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \cdot z \leq -20 \lor \neg \left(y \cdot z \leq 0.005\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -2.00000000000000011e232Initial program 73.4%
Taylor expanded in y around inf 73.4%
mul-1-neg73.4%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
*-commutative99.8%
associate-*l*99.9%
Simplified99.9%
if -2.00000000000000011e232 < (*.f64 y z) < -20 or 0.0050000000000000001 < (*.f64 y z) Initial program 98.7%
Taylor expanded in y around inf 97.0%
mul-1-neg97.0%
associate-*r*85.1%
Simplified85.1%
Taylor expanded in x around 0 97.0%
if -20 < (*.f64 y z) < 0.0050000000000000001Initial program 100.0%
Taylor expanded in y around 0 97.7%
Final simplification97.7%
(FPCore (x y z) :precision binary64 (if (<= (* y z) -2e+232) (* z (* y (- x))) (if (or (<= (* y z) -20.0) (not (<= (* y z) 0.005))) (* (* y z) (- x)) x)))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2e+232) {
tmp = z * (y * -x);
} else if (((y * z) <= -20.0) || !((y * z) <= 0.005)) {
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) <= (-2d+232)) then
tmp = z * (y * -x)
else if (((y * z) <= (-20.0d0)) .or. (.not. ((y * z) <= 0.005d0))) 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) <= -2e+232) {
tmp = z * (y * -x);
} else if (((y * z) <= -20.0) || !((y * z) <= 0.005)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -2e+232: tmp = z * (y * -x) elif ((y * z) <= -20.0) or not ((y * z) <= 0.005): tmp = (y * z) * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -2e+232) tmp = Float64(z * Float64(y * Float64(-x))); elseif ((Float64(y * z) <= -20.0) || !(Float64(y * z) <= 0.005)) 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) <= -2e+232) tmp = z * (y * -x); elseif (((y * z) <= -20.0) || ~(((y * z) <= 0.005))) tmp = (y * z) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -2e+232], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[(y * z), $MachinePrecision], -20.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.005]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -2 \cdot 10^{+232}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \cdot z \leq -20 \lor \neg \left(y \cdot z \leq 0.005\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -2.00000000000000011e232Initial program 73.4%
Taylor expanded in y around inf 73.4%
mul-1-neg73.4%
associate-*r*99.8%
Simplified99.8%
if -2.00000000000000011e232 < (*.f64 y z) < -20 or 0.0050000000000000001 < (*.f64 y z) Initial program 98.7%
Taylor expanded in y around inf 97.0%
mul-1-neg97.0%
associate-*r*85.1%
Simplified85.1%
Taylor expanded in x around 0 97.0%
if -20 < (*.f64 y z) < 0.0050000000000000001Initial program 100.0%
Taylor expanded in y around 0 97.7%
Final simplification97.7%
(FPCore (x y z) :precision binary64 (if (or (<= (* y z) -20.0) (not (<= (* y z) 0.005))) (* (* y z) (- x)) x))
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -20.0) || !((y * z) <= 0.005)) {
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) <= (-20.0d0)) .or. (.not. ((y * z) <= 0.005d0))) 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) <= -20.0) || !((y * z) <= 0.005)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((y * z) <= -20.0) or not ((y * z) <= 0.005): tmp = (y * z) * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -20.0) || !(Float64(y * z) <= 0.005)) 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) <= -20.0) || ~(((y * z) <= 0.005))) tmp = (y * z) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -20.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.005]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -20 \lor \neg \left(y \cdot z \leq 0.005\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -20 or 0.0050000000000000001 < (*.f64 y z) Initial program 93.4%
Taylor expanded in y around inf 92.0%
mul-1-neg92.0%
associate-*r*88.2%
Simplified88.2%
Taylor expanded in x around 0 92.0%
if -20 < (*.f64 y z) < 0.0050000000000000001Initial program 100.0%
Taylor expanded in y around 0 97.7%
Final simplification95.1%
(FPCore (x y z) :precision binary64 (if (<= (* y z) -2e+232) (* y (* z (- x))) (* x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2e+232) {
tmp = y * (z * -x);
} 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) <= (-2d+232)) then
tmp = y * (z * -x)
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) <= -2e+232) {
tmp = y * (z * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -2e+232: tmp = y * (z * -x) else: tmp = x * (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -2e+232) tmp = Float64(y * Float64(z * Float64(-x))); 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) <= -2e+232) tmp = y * (z * -x); else tmp = x * (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -2e+232], N[(y * N[(z * (-x)), $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 -2 \cdot 10^{+232}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -2.00000000000000011e232Initial program 73.4%
Taylor expanded in y around inf 73.4%
mul-1-neg73.4%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
*-commutative99.8%
associate-*l*99.9%
Simplified99.9%
if -2.00000000000000011e232 < (*.f64 y z) Initial program 99.5%
Final simplification99.5%
(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 53.8%
herbie shell --seed 2024101
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))