I believe this a question that most of us have encountered when we were beginners but forgot when we got more familiar with Mathematica.

We know the notation $y=y(x)$ for functions, where $y$ here simultaneously represents the functional relation and the dependent variable, isn't rare. We also know it's trouble in Mathematica because it'll cause infinite recursion:

y = y[x]

$RecursionLimit::reclim: Recursion depth of 256 exceeded. >>


This behavior makes the language strict, of course. But recently, when I found myself in a situation with some justification for using a lot of $y=y(x)$ style notation, the question in the title came to my mind: what if this notation were well behaved in Mathematica?

Needless to say, though quite similar, there're many differences between Mathematica syntax and traditional math notation. For most cases we can easily see the advantages of such deviations. For example, the strict distinctions of [],(),{},[[]]. However, the advantage of the currently built-in behavior of y = y[x] seems not to be obvious. In other words, I can't see what kind of problems will arise if a symbol were allowed to have OwnValues and DownValues at the same time. In such case, OwnValues of a symbol would only be evaluated when the symbol is not the head of any expressions.

Can I achieve this feature in Mathematica?

  • 4
    $\begingroup$ You can, but using Stack, which makes it inefficient, and won't work if inside StackInhibit. Otherwise, I think we have to wait until they create the attribute OnlyEvaluateIfNotHead, or create the OnlyIfNotHeadOwnValues $\endgroup$
    – Rojo
    Jun 13, 2014 at 15:23
  • 1
    $\begingroup$ Otherwise, you have to get hacky, such as creating a lexical environment. As to the advantages of how it is, there are many, and they will come up more often soon in v10, with all the new "operator versions" of functions like Map, Apply, etc $\endgroup$
    – Rojo
    Jun 13, 2014 at 15:28
  • 2
    $\begingroup$ If you care more about close-to-math notation more than debating language features, this would be a solution: 'With[{y = y[x]}, y]'. $\endgroup$
    – Yi Wang
    Jun 15, 2014 at 7:06

1 Answer 1


Your question does not make sense to me since the infinite recursive pattern that troubles you has nothing to do with down-values. It is strictly an effect of the way own-values are evaluated.


Block[{$RecursionLimit = 20}, y = y[x]]

$RecursionLimit::reclim: Recursion depth of 20 exceeded. >>

Column[{OwnValues @ y, DownValues @ y}]
{HoldPattern[y] :> y[x]}

As you can see, y has no down-values.

It is my belief that only re-coding the Mathematica kernel could fix the problem you discuss. I hope I'm wrong and that someone smarter than me with post a solution. However, this has come up before and no magic solution was conjured up.

  • 1
    $\begingroup$ I think he just means that he would like for y to be evaluated to something, but y[sth] be treated as something different. In other words, have some kind of ownvalues that won't evaluate if the symbol is a head $\endgroup$
    – Rojo
    Jun 13, 2014 at 16:40
  • 1
    $\begingroup$ @Rojo. You may be right. But the OP spends considerable time talking about a symbol having down-values and own-values at the same time as if that would somehow fix the problem. It was even mentioned in the title until you edited it :). I want the OP to know down-values are neither part of the problem nor the solution to the question he raises. $\endgroup$
    – m_goldberg
    Jun 13, 2014 at 22:37
  • $\begingroup$ Sorry to my late reply. I did intend to wait for an hour after posting this question but was beaten by sandman within 10 minutes 囧. @Rojo Yeah, you're right, thanks for editing the title, also, thanks for m_goldberg's polishing :D $\endgroup$
    – xzczd
    Jun 14, 2014 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.