1
$\begingroup$

I'm new to Mathematica and trying to better understand the syntax. In the documentation, the function Limit has the signature:

Limit[f[x], x -> x0] 

whereas FixedPoint has:

FixedPoint[f, expr] 

What is the difference between arguments of the form f and f[x]? I seem to be unable to pass pure functions in the case of Limit.

$\endgroup$
2
  • $\begingroup$ A pure function does not involve any variable names, so as you vary x, it will not change, and the limiting value will just be the pure function. $\endgroup$ Commented May 24, 2018 at 15:08
  • $\begingroup$ @Alan Is that the only difference between these cases? $\endgroup$ Commented May 24, 2018 at 15:17

1 Answer 1

5
$\begingroup$

The difference here is that f in FixedPoint is a function that (in the first iteration) gets applied to expr to form f[expr]. Then in the second iteration it gets applied again to form f[f[expr]] and FixedPoint checks if f[f[expr]] is the same as f[expr].

You couldn't apply f[x] to expr, because you'd get f[x][expr] rather than f[expr]. In the second iteration you'd get f[x][f[x][expr]]. In most cases this would be meaningless. Technically, though, f[x] CAN be a function if you do something like:

f[x_] := Function[{y}, x + y] 

In this case f[1] would be the "add one" operator that you can apply to other values:

f[1][2] (* 3 *) 

Now Limit on the other hand uses a substitution rule (or at least: the syntax of one). The best function to illustrate this with is ReplaceAll (or /. for short), which is a function that inspects an expression and replaces bits based on replacement rules you give. For example:

Clear[x]; {1, 2, 3, x} /. x -> 4 

results in {1, 2, 3, 4}. The reason I first do Clear[x] is that this wouldn't work correctly if x had a value, so you have to be a bit careful when you use them. For example:

x = 1; {1, 2, 3, x} /. x -> 4 

which gives you {4, 2, 3, 4}. If you use TracePrint[{1, 2, 3, x} /. x -> 4], you can see what happens: first x gets evaluated to 1 in the list; then x evaluates to 1 in the replacement rule and you end up with:

 {1,2,3,1} /. 1 -> 4 

Hence the result.

There are other functions that do replacements like this (such as Table), except they use a slightly different mechanism and syntax. Table localizes its iterator, which you can spot from the syntax highlighting of i in the following example.

i = 2 Table[i^2, {i, 1, 4}] 

So I hope that these examples help you understand the differences between function application and value substitution.

$\endgroup$
2
  • $\begingroup$ Your examples made it a lot more clear. Could you summarize in one sentence what can be passed on as "f" and what as "f[x]"? I'm not sure I understand in general, even though you explained this particular case. $\endgroup$ Commented May 24, 2018 at 16:13
  • $\begingroup$ You use f whenever you need to pass on a function that gets applied repeatedly to arguments (e.g., Map, Nest, Fold, Select). In these cases you can use pure functions (i.e., Function). You use f[x] to pass on an expression into which x will be substituted with some other value. In this case, pure functions generally don't work. $\endgroup$ Commented May 24, 2018 at 18:18

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.