# Function to make values close to zero, zero leaving others as is

I have a 2D vector $v$, where each component is in the range -1 to +1.

I'd like a function $f(v, x)$, where x is a real number, and the result is a vector, such that each $component$ of the result is zero if abs($component$) < $x$ where $abs(x) < 1$.

-
Do you mean each component of $f$? Is the output of $f$ also a two-dimensional vector? And $x$ seems to be real number? –  joriki Jul 27 '11 at 8:56
Sorry for not being clear. The output of $f$ should be a 2d vector. x is a real number that defines the range of values of each component of $v$ that will become zero. –  George Duckett Jul 27 '11 at 9:12
If you're working in a C-ish language, you could either exploit the fact that Booleans are represented as 0 and 1 (mathematically, you're using an Iverson bracket), or you can use the inline conditional (condition) ? (if-true) : (if-false)... –  J. M. is back. Jul 27 '11 at 9:24
@J.M.: On a slight tangent, I've occasionally found myself using $(P\ \;?\ a : b)$ in a mathematical formula. It's a convenient notation in situations where $\scriptstyle \begin{cases}a & \text{if }P \\ b & \text{if not }P\end{cases}$ would be too bulky and Iverson brackets or $b + \mathbf 1_P\;(a-b)$ too obfuscatory. Of course, not being commonly used notation, one needs to explain what it means, but generally I've found that true for Iverson brackets too. –  Ilmari Karonen Jul 27 '11 at 11:54
@Ilmari: Hah, yes. :) Sadly, Knuth's evangelizing for the Iverson brackets hasn't been spectacularly successful, but oh well... I guess whichever of piecewise notation, Iverson brackets, or C-ish constructs should you use depends on the audience. –  J. M. is back. Jul 27 '11 at 12:02

I wouldn't bother formalizing it further, but if you must, you can define $f(u,v) = (g_x(u),g_x(v))$ where $g_x(t) = \begin{cases} 0 & t < |x| \\ t & \mbox{otherwise} \end{cases}$
...or in Iverson bracket form: $t[t\geq|x|]$. That can be rewritten as $t(1+|t-|x||/(t-|x|))/2$, but I see no advantage in rewriting it that way, except if for some reason you abhor the use of Iverson brackets... –  J. M. is back. Jul 27 '11 at 9:53