
(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 5 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) -2e+158) (* y (* z (- x))) (if (<= (* y z) 4e+192) (* x (- 1.0 (* y z))) (- x (* z (* y x))))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2e+158) {
tmp = y * (z * -x);
} else if ((y * z) <= 4e+192) {
tmp = x * (1.0 - (y * z));
} else {
tmp = x - (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) <= (-2d+158)) then
tmp = y * (z * -x)
else if ((y * z) <= 4d+192) then
tmp = x * (1.0d0 - (y * z))
else
tmp = x - (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) <= -2e+158) {
tmp = y * (z * -x);
} else if ((y * z) <= 4e+192) {
tmp = x * (1.0 - (y * z));
} else {
tmp = x - (z * (y * x));
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -2e+158: tmp = y * (z * -x) elif (y * z) <= 4e+192: tmp = x * (1.0 - (y * z)) else: tmp = x - (z * (y * x)) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -2e+158) tmp = Float64(y * Float64(z * Float64(-x))); elseif (Float64(y * z) <= 4e+192) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(x - Float64(z * Float64(y * x))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= -2e+158)
tmp = y * (z * -x);
elseif ((y * z) <= 4e+192)
tmp = x * (1.0 - (y * z));
else
tmp = x - (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], -2e+158], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 4e+192], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -2 \cdot 10^{+158}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 4 \cdot 10^{+192}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -1.99999999999999991e158Initial program 77.6%
Taylor expanded in y around inf 99.8%
mul-1-neg99.8%
distribute-rgt-neg-in99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
if -1.99999999999999991e158 < (*.f64 y z) < 4.00000000000000016e192Initial program 99.9%
if 4.00000000000000016e192 < (*.f64 y z) Initial program 72.8%
Taylor expanded in x around 0 72.8%
sub-neg72.8%
distribute-rgt-neg-out72.8%
+-commutative72.8%
distribute-lft1-in72.8%
associate-*l*99.9%
fma-def99.9%
*-commutative99.9%
Simplified99.9%
fma-udef99.9%
*-commutative99.9%
associate-*l*72.8%
+-commutative72.8%
distribute-rgt-neg-out72.8%
distribute-lft-neg-out72.8%
distribute-rgt-neg-out72.8%
add-sqr-sqrt48.3%
sqrt-unprod42.4%
sqr-neg42.4%
sqrt-unprod0.0%
add-sqr-sqrt0.2%
cancel-sign-sub0.2%
distribute-rgt-neg-out0.2%
*-commutative0.2%
associate-*r*0.3%
cancel-sign-sub-inv0.3%
*-commutative0.3%
add-sqr-sqrt0.1%
sqrt-unprod35.3%
sqr-neg35.3%
sqrt-unprod49.8%
add-sqr-sqrt99.9%
Applied egg-rr99.9%
Final simplification99.9%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= (* y z) -2e+158) (not (<= (* y z) 4e+276))) (* y (* z (- x))) (* x (- 1.0 (* y z)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -2e+158) || !((y * z) <= 4e+276)) {
tmp = y * (z * -x);
} else {
tmp = x * (1.0 - (y * z));
}
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) <= (-2d+158)) .or. (.not. ((y * z) <= 4d+276))) then
tmp = y * (z * -x)
else
tmp = x * (1.0d0 - (y * z))
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -2e+158) || !((y * z) <= 4e+276)) {
tmp = y * (z * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -2e+158) or not ((y * z) <= 4e+276): tmp = y * (z * -x) else: tmp = x * (1.0 - (y * z)) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -2e+158) || !(Float64(y * z) <= 4e+276)) tmp = Float64(y * Float64(z * Float64(-x))); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (((y * z) <= -2e+158) || ~(((y * z) <= 4e+276)))
tmp = y * (z * -x);
else
tmp = x * (1.0 - (y * z));
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[N[(y * z), $MachinePrecision], -2e+158], N[Not[LessEqual[N[(y * z), $MachinePrecision], 4e+276]], $MachinePrecision]], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -2 \cdot 10^{+158} \lor \neg \left(y \cdot z \leq 4 \cdot 10^{+276}\right):\\
\;\;\;\;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) < -1.99999999999999991e158 or 4.0000000000000002e276 < (*.f64 y z) Initial program 69.2%
Taylor expanded in y around inf 99.8%
mul-1-neg99.8%
distribute-rgt-neg-in99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
if -1.99999999999999991e158 < (*.f64 y z) < 4.0000000000000002e276Initial program 99.9%
Final simplification99.9%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -1.55e+76) (not (<= y 1.15e-124))) (* (* y z) (- x)) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.55e+76) || !(y <= 1.15e-124)) {
tmp = (y * z) * -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 ((y <= (-1.55d+76)) .or. (.not. (y <= 1.15d-124))) then
tmp = (y * z) * -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 ((y <= -1.55e+76) || !(y <= 1.15e-124)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y <= -1.55e+76) or not (y <= 1.15e-124): tmp = (y * z) * -x else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -1.55e+76) || !(y <= 1.15e-124)) tmp = Float64(Float64(y * z) * 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 ((y <= -1.55e+76) || ~((y <= 1.15e-124)))
tmp = (y * z) * -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[y, -1.55e+76], N[Not[LessEqual[y, 1.15e-124]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{+76} \lor \neg \left(y \leq 1.15 \cdot 10^{-124}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.55000000000000006e76 or 1.15000000000000006e-124 < y Initial program 86.5%
Taylor expanded in y around inf 63.6%
mul-1-neg63.6%
distribute-rgt-neg-out63.6%
Simplified63.6%
if -1.55000000000000006e76 < y < 1.15000000000000006e-124Initial program 99.2%
Taylor expanded in y around 0 76.6%
Final simplification69.9%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -2.15e+76) (not (<= y 1.15e-124))) (* y (* z (- x))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.15e+76) || !(y <= 1.15e-124)) {
tmp = y * (z * -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 ((y <= (-2.15d+76)) .or. (.not. (y <= 1.15d-124))) then
tmp = y * (z * -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 ((y <= -2.15e+76) || !(y <= 1.15e-124)) {
tmp = y * (z * -x);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y <= -2.15e+76) or not (y <= 1.15e-124): tmp = y * (z * -x) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -2.15e+76) || !(y <= 1.15e-124)) tmp = Float64(y * Float64(z * 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 ((y <= -2.15e+76) || ~((y <= 1.15e-124)))
tmp = y * (z * -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[y, -2.15e+76], N[Not[LessEqual[y, 1.15e-124]], $MachinePrecision]], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.15 \cdot 10^{+76} \lor \neg \left(y \leq 1.15 \cdot 10^{-124}\right):\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.14999999999999989e76 or 1.15000000000000006e-124 < y Initial program 86.5%
Taylor expanded in y around inf 74.1%
mul-1-neg74.1%
distribute-rgt-neg-in74.1%
distribute-rgt-neg-in74.1%
Simplified74.1%
if -2.14999999999999989e76 < y < 1.15000000000000006e-124Initial program 99.2%
Taylor expanded in y around 0 76.6%
Final simplification75.3%
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 92.6%
Taylor expanded in y around 0 48.9%
Final simplification48.9%
herbie shell --seed 2023202
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))