Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

18
  • $\begingroup$ Another strange-looking pattern that doesn't require altering Plus might be e.g. (a_Integer)[b, x_] ^:= x + a. Anyway, I think this answer is very good and should really help the OP; +1. $\endgroup$ Commented Jul 4, 2014 at 12:32
  • $\begingroup$ Good answer, also maybe this is useful (although I think using TreeForm, as you suggested, and thinking hard is probably the way to go). $\endgroup$ Commented Jul 4, 2014 at 12:58
  • $\begingroup$ @acl: The documentation is great once you get the computational model. But I must admit that I had a lot of trouble understanding it at first, when I started with all the (mis)conceptions about what expressions, functions and values are, coming from C++. $\endgroup$ Commented Jul 4, 2014 at 13:09
  • $\begingroup$ I completely agree, however, the part of the docs I linked to tries to explain how everything is an expression in mma. It even shows trees like you did, etc. Of course one needs to also realise that you can mentally model what mma does as transforming tree-like objects according to user- or system-specified patterns. $\endgroup$ Commented Jul 4, 2014 at 13:26
  • $\begingroup$ Thanks for replying. I think I can smoothly parse the tree form of some expression like a^2+b^c*d-(x+y)^k. However, I still can't figure out why people always say "there is no distinction between function and data?" I think it is reasonable to say that "the definition of a function is (via) an expression", but when we want to define a function in MMA, we need to type f[x_]:=..., and calling it using f[4]. An expression(take "x^2+2 x+1" or "a=x^2+2 x+1"for example) is an expression; whereas a function(take "f[x_]:=x^2+2 x+1") is a function, their "essence" seem not same. $\endgroup$ Commented Jul 4, 2014 at 13:28