
(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+226) (- x (* (* y z) x)) (/ 1.0 (+ (/ -1.0 (* (* y y) (* x (* z z)))) (/ (/ -1.0 y) (* z x))))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 5e+226) {
tmp = x - ((y * z) * x);
} else {
tmp = 1.0 / ((-1.0 / ((y * y) * (x * (z * z)))) + ((-1.0 / 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+226) then
tmp = x - ((y * z) * x)
else
tmp = 1.0d0 / (((-1.0d0) / ((y * y) * (x * (z * z)))) + (((-1.0d0) / 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+226) {
tmp = x - ((y * z) * x);
} else {
tmp = 1.0 / ((-1.0 / ((y * y) * (x * (z * z)))) + ((-1.0 / y) / (z * x)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= 5e+226: tmp = x - ((y * z) * x) else: tmp = 1.0 / ((-1.0 / ((y * y) * (x * (z * z)))) + ((-1.0 / y) / (z * x))) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 5e+226) tmp = Float64(x - Float64(Float64(y * z) * x)); else tmp = Float64(1.0 / Float64(Float64(-1.0 / Float64(Float64(y * y) * Float64(x * Float64(z * z)))) + Float64(Float64(-1.0 / y) / Float64(z * x)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= 5e+226) tmp = x - ((y * z) * x); else tmp = 1.0 / ((-1.0 / ((y * y) * (x * (z * z)))) + ((-1.0 / y) / (z * x))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], 5e+226], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(-1.0 / N[(N[(y * y), $MachinePrecision] * N[(x * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 / y), $MachinePrecision] / N[(z * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 5 \cdot 10^{+226}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{-1}{\left(y \cdot y\right) \cdot \left(x \cdot \left(z \cdot z\right)\right)} + \frac{\frac{-1}{y}}{z \cdot x}}\\
\end{array}
\end{array}
if (*.f64 y z) < 5.0000000000000005e226Initial program 98.3%
sub-neg98.3%
distribute-rgt-in98.3%
*-un-lft-identity98.3%
distribute-rgt-neg-in98.3%
Applied egg-rr98.3%
if 5.0000000000000005e226 < (*.f64 y z) Initial program 77.4%
add-cube-cbrt77.3%
pow377.3%
Applied egg-rr77.3%
rem-cube-cbrt77.4%
*-commutative77.4%
flip--16.7%
metadata-eval16.7%
unpow216.7%
associate-/r/16.5%
clear-num16.5%
clear-num16.5%
associate-/r/16.7%
metadata-eval16.7%
unpow216.7%
flip--77.4%
*-commutative77.4%
Applied egg-rr77.4%
Taylor expanded in y around inf 99.9%
unpow299.9%
*-commutative99.9%
unpow299.9%
associate-/r*99.9%
Simplified99.9%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (<= (* y z) 5e+226) (* x (- 1.0 (* y z))) (* y (* z (- x)))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 5e+226) {
tmp = x * (1.0 - (y * z));
} 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) <= 5d+226) then
tmp = x * (1.0d0 - (y * z))
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) <= 5e+226) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (z * -x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= 5e+226: tmp = x * (1.0 - (y * z)) else: tmp = y * (z * -x) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 5e+226) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(y * Float64(z * Float64(-x))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= 5e+226) tmp = x * (1.0 - (y * z)); else tmp = y * (z * -x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], 5e+226], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 5 \cdot 10^{+226}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 5.0000000000000005e226Initial program 98.3%
if 5.0000000000000005e226 < (*.f64 y z) Initial program 77.4%
Taylor expanded in y around inf 99.9%
mul-1-neg99.9%
distribute-rgt-neg-in99.9%
distribute-rgt-neg-in99.9%
Simplified99.9%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (<= (* y z) 5e+226) (- x (* (* y z) x)) (* y (* z (- x)))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 5e+226) {
tmp = x - ((y * z) * 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) <= 5d+226) then
tmp = x - ((y * z) * 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) <= 5e+226) {
tmp = x - ((y * z) * x);
} else {
tmp = y * (z * -x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= 5e+226: tmp = x - ((y * z) * x) else: tmp = y * (z * -x) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 5e+226) tmp = Float64(x - Float64(Float64(y * z) * x)); else tmp = Float64(y * Float64(z * Float64(-x))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= 5e+226) tmp = x - ((y * z) * x); else tmp = y * (z * -x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], 5e+226], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 5 \cdot 10^{+226}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 5.0000000000000005e226Initial program 98.3%
sub-neg98.3%
distribute-rgt-in98.3%
*-un-lft-identity98.3%
distribute-rgt-neg-in98.3%
Applied egg-rr98.3%
if 5.0000000000000005e226 < (*.f64 y z) Initial program 77.4%
Taylor expanded in y around inf 99.9%
mul-1-neg99.9%
distribute-rgt-neg-in99.9%
distribute-rgt-neg-in99.9%
Simplified99.9%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.3e-115) (not (<= z 7e+100))) (* (* y z) (- x)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.3e-115) || !(z <= 7e+100)) {
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 <= (-3.3d-115)) .or. (.not. (z <= 7d+100))) 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 <= -3.3e-115) || !(z <= 7e+100)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.3e-115) or not (z <= 7e+100): tmp = (y * z) * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.3e-115) || !(z <= 7e+100)) 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 <= -3.3e-115) || ~((z <= 7e+100))) tmp = (y * z) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.3e-115], N[Not[LessEqual[z, 7e+100]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{-115} \lor \neg \left(z \leq 7 \cdot 10^{+100}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.2999999999999999e-115 or 6.99999999999999953e100 < z Initial program 94.8%
Taylor expanded in y around inf 68.4%
mul-1-neg68.4%
distribute-rgt-neg-out68.4%
Simplified68.4%
if -3.2999999999999999e-115 < z < 6.99999999999999953e100Initial program 97.7%
Taylor expanded in y around 0 77.7%
Final simplification73.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.3e-115) (not (<= z 8.5e+100))) (* y (* z (- x))) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.3e-115) || !(z <= 8.5e+100)) {
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 <= (-3.3d-115)) .or. (.not. (z <= 8.5d+100))) 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 <= -3.3e-115) || !(z <= 8.5e+100)) {
tmp = y * (z * -x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.3e-115) or not (z <= 8.5e+100): tmp = y * (z * -x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.3e-115) || !(z <= 8.5e+100)) tmp = Float64(y * Float64(z * Float64(-x))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.3e-115) || ~((z <= 8.5e+100))) tmp = y * (z * -x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.3e-115], N[Not[LessEqual[z, 8.5e+100]], $MachinePrecision]], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{-115} \lor \neg \left(z \leq 8.5 \cdot 10^{+100}\right):\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.2999999999999999e-115 or 8.50000000000000043e100 < z Initial program 94.8%
Taylor expanded in y around inf 68.8%
mul-1-neg68.8%
distribute-rgt-neg-in68.8%
distribute-rgt-neg-in68.8%
Simplified68.8%
if -3.2999999999999999e-115 < z < 8.50000000000000043e100Initial program 97.7%
Taylor expanded in y around 0 77.7%
Final simplification73.2%
(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 53.1%
Final simplification53.1%
herbie shell --seed 2023240
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))