To implement "Hero's Method" for approximating $\sqrt{c}$, one iterates the function (x + c/x)/2 for a given number c (e.g., 2) starting with some initial value of x. This can be implemented by defining first the function
g[c_, x_] := (x + c/x)/2
of two variables, next fixing the first variable to get the pure function g[2, #]&, and finally iterating with Nest (or NestList, etc.):
Nest[g[2, #]&, 1.0, 5]
Another way is to define
h[c_][x_] := (x + c/x)/2
and then iterate h[2], as in:
Nest[h[2], 1.0, 5]
Yet h[2] evaluates to nothing more than itself:
h[2]
(* h[2] *)
Technical question: What kind of creature is the expression h[2]? It acts as if it were a function. Can one say something more to describe or characterize it? (Yes, I realize that currying is involved here.)
Subsidiary pedagogical question (which may be unsuitable for this forum): For a Mathematica beginner, which approach to iterating (for a fixed c) is likely to be easier to understand — fixing the first argument to g and making a pure function, on the one hand, or defining h as shown, on the other hand? How does the answer to the technical question affect the answer to this pedagogical question?
h[2][y]... – ciao Aug 30 '15 at 20:03h[2][y]orh[2][x], etc. But how can one characterizeh[2]itself? That was my question. – murray Aug 30 '15 at 20:15SubValues. This allows you to pass the "arguments" collected inh(like2in this case), to the body of the "function" (r.h.s. of the rule). This is useful, since it allows you to separate parameters which are fixed externally (behaves like constants,2here), from those which are passed dynamically. – Leonid Shifrin Aug 30 '15 at 20:22h[c_]:=Function[x, (x + c/x)/2]. This reveals that you create a closure, closed over the value ofc. So, this is one way to think also abouth[c][x]construct when defined with rules, from the functional programming (operational) viewpoint - although the mechanism is technically very different. – Leonid Shifrin Aug 30 '15 at 20:25SubValues[h]gives what I expect. But it still doesn't say anything about whath[2]is. – murray Aug 30 '15 at 20:47h[2]is?" – murray Aug 30 '15 at 20:48ha parametrized function, where2inh[2]is the parameter value. That has explanatory value to the extent that it allows you to remember when it's used, even if it doesn't describe the technical subtleties. – Jens Aug 30 '15 at 21:23ha "parameterized function", with the2inh[2]a value of the parameter. I'm beginning to sense that it makes little sense to ask whath[2]is other than to say it's a function and look ath[2][x]orh[2][1], etc. -- no more sense than to ask what, say,Sin"is". – murray Aug 30 '15 at 21:29has a parameterized function, i.e., a family of functions, then one might as well use a subscript definition:Subscript[h, c_][x_] := (x + c/x)/2, so that StandardForm notation such as $h_2$ resembles a traditional mathematical notation for one of a family of functions. – murray Sep 02 '15 at 19:31