The purpose of this separate answer is to address the other part of the question, when does equality happen? (also, my first answer is getting too long).
I. As FC pointed out, equality happens if $J$ is principal (this can be proved using Fact 1 in my other answer). When $R$ is a complete intersection, consider Consider the following:
- $J$ is principal.
- $R/I$ is Gorenstein.
- $R/I$ is a complete intersection.
Then $(3)\Rightarrow (2) \Leftrightarrow (1)$. If $R$ is a complete intersection, then $(2)\Rightarrow (3)$.
Sketch of proof: equivalent of (1) and (2) can be proved using the Facts of my other answer. For example, since $J$ is isomorphic to the canonical module of $R/I$, $R/I$ is Gorenstein forces $J$ to be principal. The last statement follows from a cute result by Kunz that an almost complete intersection is never Gorenstein! (E. Kunz, Almost complete intersections are not Gorenstein, J. Alg. 28(1974), 111–-115)
II. By my 10/04/10 update in the answer above, if $R$ has SLP (for example when $R$ is a monomial complete intersection, and conjecturally for all complete intersections), $k$ has char. $0$ and the socle degree is odd, then equality occurs for $I$ generated by a general linear form (it may or may not happen when the socle degree is even).
For example, equality happens $I=(x+y+u+v)$ in $R=\mathbb Q[x,y,u,v]/(x^6,y^7,u^7,v^7)$ (socle degree $23$) but not for $R=\mathbb Q[x,y,u,v]/(x^7,y^7,u^7,v^7)$ (socle degree $24$). Note that for such $I$, $J$ will typically not be principal unless if the number of variables is $2$, see part (III) below.
III. Here are some examples in positive characteristic, with the help of Macaulay 2 (thanks to Branden Stone for helping me with programming). Numerical evidences suggested:
Conjecture: Let $R=\mathbb Z/(p)[x,y]/(x^N,y^N)$ and $I=(x^n+y^n)$ with $N\geq n$. Then equality happens if and only if there is an integer $k$ such that $N/n=k$ or $kp-1\leq N/n \leq kp+1$.
Remark: the first condition is not surprising. In $2$ variables, if $n$ divides $N$ then $R/I$ is a complete intersection, so by part (I), equality happens. I think this one can be proved but did not have enough motivation to go through the details. The point is that $R/J$ is Gorenstein (Fact 3 above). In $2$ variables, this is the same as complete intersection, so $R/J$ is $k[x,y]/(f,g)$ so everything can be written down explicitly. Note that the length of $R/J$ is the product of degrees of $f,g$ by Bezout theorem.
I did not see any clear pattern when you have more variables. For example, when $R=\mathbb Z/(3)[x,y,z]/(x^N,y^N,z^N)$ and $I=(x^2+y^2+z^2)$, the values of $N$ between $2$ and $100$ such that equality fails to occur is $3,9,27,33,75,81,99$. If you set the field to be $\mathbb Z/(5)$, those values will be $3,5,15,17,23,25,75,77,83,85,95,97$!