Using the Decimal type in Martian Math

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using the Decimal type in Martian Math

kirby urner-4
I'm including the script below, using Python as a calculator, showing
off the relatively new Decimal type, mainly to solicit feedback as to
whether I'm doing anything really dorky (or that could easily be
improved dramatically if I just knew what I was doing more).

I don't use this type every day.

In lobbying to displace calculators in at least some high school math
courses, I need to make it evident to teachers that the bigger more
colorful displays are well worth it, even though an advanced TI will
do extended precision they tell me.

It's still not so easy to take screen prints or to compare (as strings
perhaps) with published digit sets (e.g. for pi, e, phi, sqrt(2) --
numbers we care about).[1]

However, many math teachers are already converts to the bigger
screens, i.e. once they have them, would never go back.  Even just
having the one up front, thanks to the computer projector, is enough
in some classrooms (the 1:1 ratio may be what homework is all about,
even in OLPC-ville).

So if we're this far along the decision tree (in a computerized math
lab, say a TuxLab, running free/libre stuff on commodity hardware)
then the next challenge is to tout Python, a scripting language, over
say Excel or OpenOffice or that IronPython spreadsheet with Python for
cell coding.

In Windows world, where Python also runs (on Tk in IDLE if you want
the GUI, or on ActiveState's or Wing's for scholars...), Excel is a
gravity well for many math teachers, or should I say black hole (they
never re-emerge)?  Does Excel harness IEEE extended precision?  I know
Mathematica does.

For context:

The appended script is a fragment of Martian Math where we take a
tetrahedral pizza slice out of a spherical pizza (messy analogy) and
weigh it (compute its volume).  The 120 slices have identical angles,
so all have the same volume for a given h (height), the scale factor
built in to all the six linear dimensions (the six edges of each pizza
slice).

I'm changing the value of h from phi/root2 -- where the pizza weighs
in at 7.5 -- to a different value (or vice versa), where the pizza
weighs in at volume 5.

Given this is Martian Math, there's the little matter of needing a
conversion factor (syn3) to escape the Earthlings' worshipful fixation
on unit-volume cubes (what keeps 'em retarded -- Martian Math is
somewhat counter-culture (= counter-intelligence)).

Our canonical Martian Math rhombic dodecahedron has a volume of six
and has radius 1 i.e. inscribes each ball in a CCP ball packing (same
as FCC, the ~0.74 maximum density possible in ordinary space).

The volume 5 rhombic triacontahedron (investigated below) is a
different animal (different zonohedron) but there's a bridge in that
our T, A and B modules all have the same easy volume of 1/24.

The latter two (A&B) build the primitive space-filler (i.e. the Mite,
pg. 71 Regular Polytopes by Coxeter)) as well as said rhombic
dodecahedron (also canonical cube (vol 3), octahedron (vol 4),
tetrahedron (vol 1), cuboctahedron (vol 20) etc.).

Probably more than you wanted to know, the kind of stuff I've encoded
in my rbf.py for those wishing to explore our digital math track in
more depth.[2]

Kirby Urner
Oregon Curriculum Network
4dsolutions.net

isepp.org (board)
python.org (voting member)
wikieducator (wikibuddy)

[1] http://mail.geneseo.edu/pipermail/math-thinking-l/2009-November/001329.html
(suggesting high precision explorations, ala fractals, as integral to
digital math track (DM))

[2] http://www.4dsolutions.net/ocn/cp4e.html

--
>>> from mars import math
http://www.wikieducator.org/Martian_Math

=== Python v. 2.6 ===

from decimal import Decimal, getcontext
getcontext().prec = 31

# whole numbers
d1,d2,d3,d4,d5,d6 = [Decimal(i) for i in range(1,7)]

# fractions
dthird = d1/d3
dhalf = d1/d2

# surds
droot2 = d2.sqrt()
droot5 = d5.sqrt()

# constants
# http://www.rwgrayprojects.com/synergetics/s09/figs/f86210.html
syn3 = d3/pow(droot2, d3)  # tetravolume:cubevolume

phi = (d1 + droot5)/d2  # golden ratio

def tvolume(h):
    # http://www.rwgrayprojects.com/synergetics/s09/figs/f86411a.html
    # http://www.rwgrayprojects.com/synergetics/s09/figs/f86411b.html
    AC, BC, OC = ((h/d2) * (droot5 - d1), (h/d2) * (d3 - droot5), h)
    base = dhalf * (AC * OC)
    return dthird * base * BC

# T module (1/120th of volume 5 rhombic triacontahedron)
h = (phi/droot2) * pow(d2/d3, d1/d3)
tvol = tvolume(h)

print "T Module"
print "T in tetravolumes: ", tvol * syn3
print "Rh Triacontrahedron: ", 120 * tvol * syn3

# E module (1/120th of rhombic triacontahedron with radius 1)
h = d1
evol = tvolume(h)

print "E Module"
print "E in tetravolumes: ", evol * syn3
print "Rh Triacontrahedron: ", 120 * evol * syn3

# K module (1/120th of volume 7.5 rhombic triacontahedron)
h = phi/droot2
kvol = tvolume(h)

print "K Module"
print "K in tetravolumes: ", kvol * syn3
print "Rh Triacontrahedron: ", 120 * kvol * syn3
_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig
Reply | Threaded
Open this post in threaded view
|

Re: Using the Decimal type in Martian Math

kirby urner-4
On Sun, Nov 29, 2009 at 10:58 AM, kirby urner <[hidden email]> wrote:

<< SNIP >>

> print "K Module"
> print "K in tetravolumes: ", kvol * syn3
> print "Rh Triacontrahedron: ", 120 * kvol * syn3
>

I'm now comparing output from this script on Ubuntu netbook Python 2.6
and WinXP HP desktop Python 3.1.

Here's Python 3.1rc1 (r31rc1:73069, May 31 2009, 08:57:10):

getcontext().prec = 31

T Module
T in tetravolumes:  0.04166666666666666666666666666670
Rh Triacontrahedron:  5.000000000000000000000000000005
E Module
E in tetravolumes:  0.04173131692777365429943951200165
Rh Triacontrahedron:  5.007758031332838515932741440198
K Module
K in tetravolumes:  0.06250000000000000000000000000008
Rh Triacontrahedron:  7.500000000000000000000000000009


getcontext().prec = 50

T Module
T in tetravolumes:  0.041666666666666666666666666666666666666666666666678
Rh Triacontrahedron:  5.0000000000000000000000000000000000000000000000013
E Module
E in tetravolumes:  0.041731316927773654299439512001665297072526423571419
Rh Triacontrahedron:  5.0077580313328385159327414401998356487031708285702
K Module
K in tetravolumes:  0.062500000000000000000000000000000000000000000000014
Rh Triacontrahedron:  7.5000000000000000000000000000000000000000000000018

Here's from Python 2.6 on Ubuntu Starling-1:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2

getcontext().prec = 31

T Module
T in tetravolumes:  0.04166666666666666666666666666670
Rh Triacontrahedron:  5.000000000000000000000000000005
E Module
E in tetravolumes:  0.04173131692777365429943951200165
Rh Triacontrahedron:  5.007758031332838515932741440198
K Module
K in tetravolumes:  0.06250000000000000000000000000008
Rh Triacontrahedron:  7.500000000000000000000000000009

getcontext().prec = 50

T Module
T in tetravolumes:  0.041666666666666666666666666666666666666666666666678
Rh Triacontrahedron:  5.0000000000000000000000000000000000000000000000013
E Module
E in tetravolumes:  0.041731316927773654299439512001665297072526423571419
Rh Triacontrahedron:  5.0077580313328385159327414401998356487031708285702
K Module
K in tetravolumes:  0.062500000000000000000000000000000000000000000000014
Rh Triacontrahedron:  7.5000000000000000000000000000000000000000000000018

Note that 0.041666666... is our 1/24, the volume of T,A and B slices
(tetrahedra) in Martian Math.

Kirby

--
>>> from mars import math
http://www.wikieducator.org/Martian_Math
_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig