Suppose that you write something like this for your students. This is just the beginning of something I would like to write to help them with the formal definition of a limit, but I am puzzled by the first output.
formalLimit[expr_, a_, L_, ϵ_] := Module[{f},
f[x_] := expr;
f[2]
]
So, my first question is, when I enter
formalLimit[x^2, 2, 4, .1]
Why do I get the output $x^2$?
Once I get past this problem, my next question is, suppose a student enters an expression $\sqrt{4-t^2}$, not using my choice of $x$ as the independent variable. How can I identify their choice of independent variable in the expr_, then change it to $x$ when using f[x_]:=expr
?
Update: I'd like to thank all of my colleagues for their kind responses. Here is what I was able to do thanks to your help. Students will get a question (yes, it can be answered much more quickly using Mathematica techniques such as Reduce, etc, but I want a visual introduction to the formal definition of a limit) such as "Use a graph to find a number $\delta$ such that
$$|f(x)-L|<\epsilon\qquad\text{whenever}\qquad0<|x-a|<\delta.$$
As an example, find a $\delta$ such that
$$|\sqrt{x}-1|<0.5\qquad\text{whenever}\qquad0<|x-1|<\delta$$
I've written this function:
formalLimit[expr_, var_, a_, L_, ϵ_] :=
DynamicModule[{f, δ},
f = (expr /. var -> #) &;
Manipulate[
δ = Min[Abs[p[[1]] - a], Abs[q[[1]] - a]];
Show[
Plot[f[x], {x, a - zoom, a + zoom},
PlotRange -> {{a - zoom, a + zoom}, {L - 2 ϵ, L + 2 ϵ}},
Epilog ->
{Arrowheads[0.02],
Arrow[{{a, L - 2 ϵ}, {a, f[a]}, {a - 1.5 δ, L}}],
{Red, Dashed,
InfiniteLine[{{p[[1]], L - ϵ}, {p[[1]], L + ϵ}}],
InfiniteLine[{{q[[1]], L - ϵ}, {q[[1]], L + ϵ}}]}},
AxesLabel -> {ToString[var], "y"},
PlotLabel -> "δ = " <> ToString[δ],
AxesOrigin -> {a - 1.5 δ, L - 2 ϵ},
Ticks -> {{p[[1]], a, q[[1]]}, {L - ϵ, L, L + ϵ}}],
Plot[{L - ϵ, L + ϵ}, {x, a - zoom, a + zoom},
PlotStyle -> Directive[Dashed, GrayLevel[0.8]],
Filling -> {1 -> {2}}]],
{{zoom, 3}, 0.0001, 3, Appearance -> "Labeled"},
{{p, {a - 1, L - ϵ}}, Locator, Appearance -> None},
{{q, {a + 1, L + ϵ}}, Locator, Appearance -> None}]]
Then the students can enter:
formalLimit[Sqrt[x], x, 1, 1, .5]
And they get this image, where they can use their mouse to drag the dashed vertical lines to help determine $\delta$. There is also a slider for some zooming to adjust the horizontal size of the window.
This function has only been slightly tested, so I wouldn't mind hearing warnings and suggestions.
x
inexpr
is not the same as the locally scoped pattern variable inf[x_]
. The result fromTrace[formalLimit[x^2, 2, 4, .1]]
should help in understanding this. $\endgroup$Module[{f$}, f$[x$_] := x^2
, which I think you are referring to. $\endgroup$