MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Why is y a local variable here?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63085] Why is y a local variable here?
  • From: "Steven T. Hatton" <hattons at globalsymmetry.com>
  • Date: Tue, 13 Dec 2005 03:41:40 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

This is based on an example in _Programming In Mathematica_.  You can find
the original example in this file file:
AddOns/ExtraPackages/ProgrammingInMathematica/SwinnertonDyer.m

y = "The value of y";
SDP[0, x_] := x
SDP[n_Integer?Positive, x_] := Module[{sd, srp = Sqrt[Prime[n]], py},
    py[y_] = Print["y = ", y];
    Print["x = ", x];
    sd[y_] = SDP[n - 1, y];
    Expand[sd[x + srp] sd[x - srp]]]

SDP[5, x]

This is the output:

y = The value of y
x = x
y = The value of y
x = y$
y = The value of y
x = y$
y = The value of y
x = y$
y = The value of y
x = y$

                                              2                       4
Out[4]= 2000989041197056 - 44660812492570624 x  + 183876928237731840 x  - 
 
                         6                       8                      10
>    255690851718529024 x  + 172580952324702208 x  - 65892492886671360 x   + 
 
                        12                     14                    16
>    15459151516270592 x   - 2349014746136576 x   + 239210760462336 x   - 
 
                     18                 20                22
>    16665641517056 x   + 801918722048 x   - 26625650688 x   + 
 
                24            26          28        30    32
>    602397952 x   - 9028096 x   + 84864 x   - 448 x   + x

I do not understand why y is not "contaminated" by the global value when it
appears in sd[y_] = SDP[n - 1, y];. Can someone explain this?

-- 
The Mathematica Wiki: http://www.mathematica-users.org/
Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html
Math for the WWW: http://www.w3.org/Math/


  • Prev by Date: Re: Turning on numerical computation
  • Next by Date: Re: Pattern matching question and answer
  • Previous by thread: Re: Re: Mathematica Programmer vs. Programming in Mathematica
  • Next by thread: Re: Why is y a local variable here?