
(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 4 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: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) 2e+40) (- x (* (* y z) x)) (* z (- (* y x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 2e+40) {
tmp = x - ((y * z) * x);
} else {
tmp = z * -(y * x);
}
return tmp;
}
NOTE: x, 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) <= 2d+40) then
tmp = x - ((y * z) * x)
else
tmp = z * -(y * x)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 2e+40) {
tmp = x - ((y * z) * x);
} else {
tmp = z * -(y * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 2e+40: tmp = x - ((y * z) * x) else: tmp = z * -(y * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 2e+40) tmp = Float64(x - Float64(Float64(y * z) * x)); else tmp = Float64(z * Float64(-Float64(y * x))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= 2e+40)
tmp = x - ((y * z) * x);
else
tmp = z * -(y * x);
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], 2e+40], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(z * (-N[(y * x), $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 2 \cdot 10^{+40}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 2.00000000000000006e40Initial program 98.1%
sub-neg98.1%
distribute-rgt-in98.1%
*-un-lft-identity98.1%
distribute-rgt-neg-in98.1%
Applied egg-rr98.1%
*-commutative98.1%
associate-*l*90.2%
add-sqr-sqrt49.7%
sqrt-unprod67.1%
sqr-neg67.1%
sqrt-unprod26.7%
add-sqr-sqrt56.2%
associate-*r*59.7%
*-commutative59.7%
cancel-sign-sub59.7%
distribute-rgt-neg-out59.7%
*-commutative59.7%
associate-*r*56.2%
add-sqr-sqrt29.5%
sqrt-unprod62.0%
sqr-neg62.0%
sqrt-unprod40.3%
add-sqr-sqrt90.2%
associate-*l*98.1%
Applied egg-rr98.1%
if 2.00000000000000006e40 < (*.f64 y z) Initial program 86.3%
Taylor expanded in y around inf 86.3%
mul-1-neg86.3%
associate-*r*97.8%
Simplified97.8%
Final simplification98.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -1.8e+83) (not (<= y 4.2e-103))) (* z (- (* y x))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.8e+83) || !(y <= 4.2e-103)) {
tmp = z * -(y * x);
} else {
tmp = x;
}
return tmp;
}
NOTE: x, 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 <= (-1.8d+83)) .or. (.not. (y <= 4.2d-103))) then
tmp = z * -(y * x)
else
tmp = x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.8e+83) || !(y <= 4.2e-103)) {
tmp = z * -(y * x);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y <= -1.8e+83) or not (y <= 4.2e-103): tmp = z * -(y * x) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -1.8e+83) || !(y <= 4.2e-103)) tmp = Float64(z * Float64(-Float64(y * x))); else tmp = x; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= -1.8e+83) || ~((y <= 4.2e-103)))
tmp = z * -(y * x);
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[y, -1.8e+83], N[Not[LessEqual[y, 4.2e-103]], $MachinePrecision]], N[(z * (-N[(y * x), $MachinePrecision])), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{+83} \lor \neg \left(y \leq 4.2 \cdot 10^{-103}\right):\\
\;\;\;\;z \cdot \left(-y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.7999999999999999e83 or 4.20000000000000009e-103 < y Initial program 91.8%
Taylor expanded in y around inf 67.4%
mul-1-neg67.4%
associate-*r*70.5%
Simplified70.5%
if -1.7999999999999999e83 < y < 4.20000000000000009e-103Initial program 99.9%
Taylor expanded in y around 0 72.5%
Final simplification71.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) 2e+40) (* x (- 1.0 (* y z))) (* z (- (* y x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 2e+40) {
tmp = x * (1.0 - (y * z));
} else {
tmp = z * -(y * x);
}
return tmp;
}
NOTE: x, 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) <= 2d+40) then
tmp = x * (1.0d0 - (y * z))
else
tmp = z * -(y * x)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 2e+40) {
tmp = x * (1.0 - (y * z));
} else {
tmp = z * -(y * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 2e+40: tmp = x * (1.0 - (y * z)) else: tmp = z * -(y * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 2e+40) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(z * Float64(-Float64(y * x))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= 2e+40)
tmp = x * (1.0 - (y * z));
else
tmp = z * -(y * x);
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], 2e+40], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * (-N[(y * x), $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 2 \cdot 10^{+40}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 2.00000000000000006e40Initial program 98.1%
if 2.00000000000000006e40 < (*.f64 y z) Initial program 86.3%
Taylor expanded in y around inf 86.3%
mul-1-neg86.3%
associate-*r*97.8%
Simplified97.8%
Final simplification98.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(x < y && y < z);
double code(double x, double y, double z) {
return x;
}
NOTE: x, 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 x < y && y < z;
public static double code(double x, double y, double z) {
return x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x
x, y, z = sort([x, y, z]) function code(x, y, z) return x end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x
\end{array}
Initial program 95.9%
Taylor expanded in y around 0 50.0%
herbie shell --seed 2024087
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))