
(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}
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) 5e+203) (+ x (/ x (/ (/ -1.0 y) z))) (* z (* y (- x)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 5e+203) {
tmp = x + (x / ((-1.0 / y) / z));
} else {
tmp = z * (y * -x);
}
return tmp;
}
NOTE: y and z should be sorted in increasing order before calling this function.
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+203) then
tmp = x + (x / (((-1.0d0) / y) / z))
else
tmp = z * (y * -x)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 5e+203) {
tmp = x + (x / ((-1.0 / y) / z));
} else {
tmp = z * (y * -x);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 5e+203: tmp = x + (x / ((-1.0 / y) / z)) else: tmp = z * (y * -x) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 5e+203) tmp = Float64(x + Float64(x / Float64(Float64(-1.0 / y) / z))); else tmp = Float64(z * Float64(y * Float64(-x))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= 5e+203)
tmp = x + (x / ((-1.0 / y) / z));
else
tmp = z * (y * -x);
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], 5e+203], N[(x + N[(x / N[(N[(-1.0 / y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 5 \cdot 10^{+203}:\\
\;\;\;\;x + \frac{x}{\frac{\frac{-1}{y}}{z}}\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 4.99999999999999994e203Initial program 98.7%
Taylor expanded in y around 0 98.7%
mul-1-neg98.7%
associate-*r*94.0%
Simplified94.0%
unsub-neg94.0%
associate-*l*98.7%
Applied egg-rr98.7%
add-sqr-sqrt55.7%
sqrt-unprod71.2%
sqr-neg71.2%
sqrt-unprod25.4%
add-sqr-sqrt62.5%
distribute-lft-neg-in62.5%
neg-mul-162.5%
metadata-eval62.5%
associate-/r/62.5%
div-inv62.5%
frac-2neg62.5%
distribute-neg-frac62.5%
metadata-eval62.5%
associate-/r*62.5%
metadata-eval62.5%
add-sqr-sqrt37.0%
sqrt-unprod72.1%
sqr-neg72.1%
sqrt-unprod42.8%
add-sqr-sqrt99.0%
frac-2neg99.0%
Applied egg-rr99.0%
if 4.99999999999999994e203 < (*.f64 y z) Initial program 82.4%
Taylor expanded in y around inf 82.4%
mul-1-neg82.4%
associate-*r*99.9%
Simplified99.9%
Final simplification99.1%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) 5e+203) (* x (- 1.0 (* y z))) (* z (* y (- x)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 5e+203) {
tmp = x * (1.0 - (y * z));
} else {
tmp = z * (y * -x);
}
return tmp;
}
NOTE: y and z should be sorted in increasing order before calling this function.
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+203) then
tmp = x * (1.0d0 - (y * z))
else
tmp = z * (y * -x)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 5e+203) {
tmp = x * (1.0 - (y * z));
} else {
tmp = z * (y * -x);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 5e+203: tmp = x * (1.0 - (y * z)) else: tmp = z * (y * -x) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 5e+203) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(z * Float64(y * Float64(-x))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= 5e+203)
tmp = x * (1.0 - (y * z));
else
tmp = z * (y * -x);
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], 5e+203], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 5 \cdot 10^{+203}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 4.99999999999999994e203Initial program 98.7%
if 4.99999999999999994e203 < (*.f64 y z) Initial program 82.4%
Taylor expanded in y around inf 82.4%
mul-1-neg82.4%
associate-*r*99.9%
Simplified99.9%
Final simplification98.8%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) 5e+203) (- x (* (* y z) x)) (* z (* y (- x)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 5e+203) {
tmp = x - ((y * z) * x);
} else {
tmp = z * (y * -x);
}
return tmp;
}
NOTE: y and z should be sorted in increasing order before calling this function.
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+203) then
tmp = x - ((y * z) * x)
else
tmp = z * (y * -x)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 5e+203) {
tmp = x - ((y * z) * x);
} else {
tmp = z * (y * -x);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 5e+203: tmp = x - ((y * z) * x) else: tmp = z * (y * -x) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 5e+203) tmp = Float64(x - Float64(Float64(y * z) * x)); else tmp = Float64(z * Float64(y * Float64(-x))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= 5e+203)
tmp = x - ((y * z) * x);
else
tmp = z * (y * -x);
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], 5e+203], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 5 \cdot 10^{+203}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 4.99999999999999994e203Initial program 98.7%
Taylor expanded in y around 0 98.7%
mul-1-neg98.7%
associate-*r*94.0%
Simplified94.0%
unsub-neg94.0%
associate-*l*98.7%
Applied egg-rr98.7%
if 4.99999999999999994e203 < (*.f64 y z) Initial program 82.4%
Taylor expanded in y around inf 82.4%
mul-1-neg82.4%
associate-*r*99.9%
Simplified99.9%
Final simplification98.8%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -2.3e-71) (not (<= z 2.25e+151))) (* z (* y (- x))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.3e-71) || !(z <= 2.25e+151)) {
tmp = z * (y * -x);
} else {
tmp = x;
}
return tmp;
}
NOTE: y and z should be sorted in increasing order before calling this function.
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 <= (-2.3d-71)) .or. (.not. (z <= 2.25d+151))) then
tmp = z * (y * -x)
else
tmp = x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.3e-71) || !(z <= 2.25e+151)) {
tmp = z * (y * -x);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (z <= -2.3e-71) or not (z <= 2.25e+151): tmp = z * (y * -x) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -2.3e-71) || !(z <= 2.25e+151)) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -2.3e-71) || ~((z <= 2.25e+151)))
tmp = z * (y * -x);
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[z, -2.3e-71], N[Not[LessEqual[z, 2.25e+151]], $MachinePrecision]], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.3 \cdot 10^{-71} \lor \neg \left(z \leq 2.25 \cdot 10^{+151}\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.2999999999999998e-71 or 2.2499999999999999e151 < z Initial program 93.7%
Taylor expanded in y around inf 72.0%
mul-1-neg72.0%
associate-*r*74.6%
Simplified74.6%
if -2.2999999999999998e-71 < z < 2.2499999999999999e151Initial program 98.7%
Taylor expanded in y around 0 78.5%
Final simplification76.9%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z -2.4e-71) (* z (* y (- x))) (if (<= z 5e+91) x (* y (* z (- x))))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= -2.4e-71) {
tmp = z * (y * -x);
} else if (z <= 5e+91) {
tmp = x;
} else {
tmp = y * (z * -x);
}
return tmp;
}
NOTE: y and z should be sorted in increasing order before calling this function.
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 <= (-2.4d-71)) then
tmp = z * (y * -x)
else if (z <= 5d+91) then
tmp = x
else
tmp = y * (z * -x)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.4e-71) {
tmp = z * (y * -x);
} else if (z <= 5e+91) {
tmp = x;
} else {
tmp = y * (z * -x);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if z <= -2.4e-71: tmp = z * (y * -x) elif z <= 5e+91: tmp = x else: tmp = y * (z * -x) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (z <= -2.4e-71) tmp = Float64(z * Float64(y * Float64(-x))); elseif (z <= 5e+91) tmp = x; else tmp = Float64(y * Float64(z * Float64(-x))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= -2.4e-71)
tmp = z * (y * -x);
elseif (z <= 5e+91)
tmp = x;
else
tmp = y * (z * -x);
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[z, -2.4e-71], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 5e+91], x, N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{-71}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{elif}\;z \leq 5 \cdot 10^{+91}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if z < -2.4e-71Initial program 97.3%
Taylor expanded in y around inf 70.3%
mul-1-neg70.3%
associate-*r*69.2%
Simplified69.2%
if -2.4e-71 < z < 5.0000000000000002e91Initial program 98.6%
Taylor expanded in y around 0 79.8%
if 5.0000000000000002e91 < z Initial program 88.7%
Taylor expanded in y around inf 67.8%
mul-1-neg67.8%
associate-*r*72.0%
distribute-rgt-neg-in72.0%
*-commutative72.0%
associate-*r*76.7%
distribute-rgt-neg-out76.7%
Simplified76.7%
Final simplification76.2%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(y < z);
double code(double x, double y, double z) {
return x;
}
NOTE: y and z should be sorted in increasing order before calling this function.
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
assert y < z;
public static double code(double x, double y, double z) {
return x;
}
[y, z] = sort([y, z]) def code(x, y, z): return x
y, z = sort([y, z]) function code(x, y, z) return x end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x
\end{array}
Initial program 96.6%
Taylor expanded in y around 0 55.8%
Final simplification55.8%
herbie shell --seed 2023298
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))