[Edu-sig] Radical Math: debugging help?

kirby urner kirby.urner at gmail.com
Tue Apr 13 06:35:32 CEST 2010


On Mon, Apr 12, 2010 at 9:16 PM, kirby urner <kirby.urner at gmail.com> wrote:

<< snip >>

OK, a couple replies to this one:

> (a) I found the bug:  I'd neglected to subclass 'object' as my root object,
> so was not getting new-style classes, just classic classes -- we still
> have that distinction in 2.6.

I was also mistakenly passing 'self' as a first parameter to
super(Type, self).__init__.

> (b) I made numerous enhancements for this new improved deluxe
> edition, appended herewith:
>

Here's the output you get if you run it as is, except the alignment
here is messed up (not a fixed width font for me here):


Volumes Table
=============
Tetrahedron (edge = 1)                                             1
Cube (any face diagonal = 1)                                       3
Octahedron (any edge = 1)                                          4
Rhombic Triacontahedron (any long face diagonal = 0.6177)          5
Rhombic Dodecahedron (any long face diagonal = 1)                  6
Rhombic Triacontahedron (any long face diagonal = 0.7071)        7.5
Pentagonal Dodecahedron (any edge = 0.618)                     15.35
Icosahedron (any edge = 1)                                     18.51
Cuboctahedron (any edge = 1)                                      20


Duals Table
==========
Tetrahedron*                  Tetrahedron
Cube*                         Octahedron
Octahedron*                   Cube
Rhombic Dodecahedron          Cuboctahedron
Rhombic Triacontahedron       Icosidodecahedron
Pentagonal Dodecahedron*      Icosahedron
Icosahedron*                  Pentagonal Dodecahedron
Cuboctahedron                 Rhombic Dodecahedron

* = Platonic


>    def scale(self, scalefactor):
>        edge = self.edge * scalefactor  # edge unbound to self
>        volume = self.volume * pow(scalefactor, 3)  # likewise volume
>        # print("DEBUG:  a star is born: a new %s" % self.__class__.__name__)
>        return self.__class__(edge = edge, edge_name = self.edge_name,
>                              volume = volume, greekname = self.greekname)

Found a bug already:  the scale method had yet to pass on its full complement
of parameters when giving birth to a scaled version of itself.  Here's what
I changed it to:

    def scale(self, scalefactor):
        edge = self.edge * scalefactor  # edge unbound to self
        volume = self.volume * pow(scalefactor, 3)  # likewise volume
        # print("DEBUG:  a star is born: a new %s" % self.__class__.__name__)
        return self.__class__(*(edge, self.edge_name, volume, self.greekname,
                              self.platonic, self.dual))


Testing (old code):

>>> t = Tetra()
>>> t.dual
'Tetrahedron'
>>> t.volume
1
>>> newt = t.volume * 3
>>> newt.dual

Traceback (most recent call last):
  File "<pyshell#43>", line 1, in <module>
    newt.dual
AttributeError: 'int' object has no attribute 'dual'
>>> newt.platonic

Traceback (most recent call last):
  File "<pyshell#44>", line 1, in <module>
    newt.platonic
AttributeError: 'int' object has no attribute 'platonic'


Testing (new code):

>>> reload(ch)
<module 'ch' from 'C:\Python26\Lib\site-packages\ch.pyc'>
>>> t = Tetra()
>>> t = 3 * t
>>> t.volume
27
>>> t.dual
'Tetrahedron'
>>> t.platonic
True
>>> c = Cube()
>>> c = c * 3
>>> c.volume
81
>>> c.platonic
True
>>> d = ch.R_Dodeca()
>>> d.platonic
False
>>> e = d * 5
>>> e.volume
750
>>> e.platonic
False
>>> e.dual
'Cuboctahedron'


More information about the Edu-sig mailing list