algebraic distance of an element of a ring from an ideal Let $A$ be a commutative ring and $I$ an ideal. Does there exist a notion of "distance" of an element $x \in A$ from the ideal $I$? This "distance", need not be of the form $A\rightarrow \mathbb{R}$; it could be an algebraic construction, perhaps in terms of exact sequences and resolutions or even a topological construction.
Any ideas?
Are there any related theories?
Edit: Lets consider the more specific case where $A=\mathbb{R}[x_1,\cdots,x_n]$ and $I$ is an ideal of $A$. Let $f(x) \in A$ be a polynomial. Then i am interested in a mechanism that would allow me to determine how close $f(x)$ is to $I$ and then possibly find the element of $I$ that is closest to $f(x)$.
 A: Here are two ideas off the top of my head.  Is there something specific you want to do with such a construction?  (EDIT: I just saw your edit.  I'm not sure how well any of what I said applies, but maybe it'll help inspire you.  I'll think more about your question and get back to you.)
First, you can form the ideal $(I:x) = \{y \in A: xy \in I\}$.  A larger colon ideal seems to suggest that $x$ is multiplicatively 'closer to $I$'.  If $x \in I$, this is all of $A$; if $I$ is prime and $x \not\in I$, it's equal to $I$.  My favorite application of this is the Lam-Reyes Prime Ideal Principle, which lets you conclude that ideals maximal with respect to certain properties are always prime.
Second, there's a natural topology on $A$ called the $I$-adic topology.  This has a basis given by the sets $x + I^n$ for $x \in A$ and $n \ge 0$.  This is Hausdorff iff $\bigcap I^n = 0$, and in this case it's metrizable, with metric given by (for example) $d(x,y) = 2^{-n}$ if $x \in y + I^n$ but not $y + I^{n+1}$.  The thing people most commonly do with this (particularly when $A$ is local with maximal ideal $I$) is to form the completion, which actually carries a ring structure: it's just $\varprojlim A/I^n$.  
In case that's too abstract, here's a good example: take $A = \mathbb{Z}$ and $I$  a prime ideal $(p)$.  Then the distance of $x$ from $0$ (its '$p$-adic absolute value') measures how many factors of $p$ are in $x$, with numbers that are highly divisible by $p$ being very close to zero.  The completion is the limit of the inverse system $\dotsb \to \mathbb{Z}/p^3\mathbb{Z} \to \mathbb{Z}/p^2\mathbb{Z} \to \mathbb{Z}/p\mathbb{Z}$.  That is, to give an element of this ring, you first pick an integer $a_1$ mod $p$; then an integer $a_2$ mod $p^2$ that reduces to $a_1$ mod $p$; and so on.  Since high powers of $p$ are small, the successive $a_i$ are like increasingly close approximations to the element you want.  (This completion is called the '$p$-adic integers' $\mathbb{Z}_p$.)
The Zariski topology, as Frank McGovern mentioned in his comment, is actually a topology on the set of prime ideals of the ring $A$, though it's still the best way to think about $A$ as a topological space.  This topological space carries a natural 'structure sheaf,' and elements of $A$ are best thought of in this context as global sections of this sheaf.  (Depending on your background, that last sentence will either be obvious or make no sense.  If the latter, look at an introductory book on algebraic geometry, like Ravi Vakil's notes.)
