<div>Creating Top-Level names root0, root1, root2... rootN</div><div><br></div><div>Setting the stage:</div><div><br></div><div>We&#39;ve come across an ethnicity, in our voyages</div><div>of the starship whatever, that doesn&#39;t share our</div>
<div>fascination with squares and cubes.  For example,</div><div>when multiplying n * n, it never occurred to them</div><div>to picture n * n squares in a checkerboard pattern.</div><div>Rather, they have a more Chinese Checkers bias</div>
<div>towards triangles and hexagons, and their picture</div><div>of n * n is an equilateral triangle subdivided into</div><div>n ** 2 similar sub-triangles.  </div><div><br></div><div>Likewise, their picture of n * n * n, or n**3 is a </div>
<div>tetrahedron, though here the subdividing process </div><div>results in a matrix known to Earthlings (&quot;terra-ists&quot;) </div><div>as the FCC and/or CCP and/or... whatever Earthling</div><div>terminology.</div><div>
<br></div><div>The Challenge:</div><div><br></div><div>The anthropologist-astronauts we&#39;ve left behind</div><div>to work and study with these people (to be </div><div>collected on a next pass a year from now, unless</div>
<div>they plan on staying longer), are using Python, and</div><div>find that saying &#39;sqrt&#39; just gets in the way (keeps </div><div>them habituated to patterns of thought they&#39;re trying</div><div>to snap out of).  </div>
<div><br></div><div>What they&#39;d like to do is this:  for 2nd, 3rd, 4th, </div><div>5th etc. root of a number, have the functions </div><div>root2, root3, root4... up to root10 routinely available, </div><div>perhaps in a module called roots or radicals.</div>
<div><br></div><div>&gt;&gt;&gt; import radicals as r</div><div>&gt;&gt;&gt; r.root3 ( 2.0 / 3.0 )</div><div>0.8735804647362989</div><div><br></div><div>So how might we generate root0... root10 in a </div><div>factory function, such that these function names</div>
<div>become top level within their generating and/or </div><div>defining module?  </div><div><br></div><div>True, we could individually define these functions </div><div>per the example below, but what is a clever way </div>
<div>of generating rootN in principle, such as root2012,</div><div>taking 2012 as an argument.</div><div><br></div><div>Hints:</div><div><br></div><div>For root2, you might take an obvious shortcut:</div><div><br></div><div>
from math import sqrt as root2</div><div><br></div><div>For root3, consider the following:</div><div><br></div><div>def root3 (x):  return pow( x, 1.0/3.0 )</div><div><br></div><div>In general:</div><div><br></div><div>def rootN (x):  return pow( x, 1.0/N)</div>
<div><br></div><div>Rationale for this exercise:</div><div><br></div><div>Students often want a way to factory-produce</div><div>new names at the top level, from within a contained</div><div>scope (such as from within a function).  </div>
<div><br></div><div>These top level names may be of data, functions or </div><div>whatever arbitrary objects.  The production process </div><div>often involves synthesizing new names on the fly, </div><div>as strings.  Strings are &quot;right side&quot; objects, usually </div>
<div>assigned names, but not themselves names of </div><div>anything.</div><div><br></div><div>By what magic might we turn a string object into </div><div>a top-level name:  that is the question this lesson </div><div>addresses.</div>
<div><br></div>