[Edu-sig] Math through programming: sample challenge

kirby urner kirby.urner at gmail.com
Fri Apr 21 23:29:34 CEST 2006

```In math world we have these things called "almost integers" which are
weird expressions with transcendentals, usually, that evaluate to
within a very tiny percent of wholesome whole  numberhood.

Probably the most famous example, owing to Ramanujan, is math.e **
(math.pi * math.sqrt(163)), which works out to an "almost integer" of
262537412640768744.

http://www.research.att.com/%7Enjas/sequences/A060295

Challenge:

Write a generator of Python expressions (up to you if you use an
actual generator) with a filter to keep only those that evaluate to
within epsilon of an integer.

Proposed look (just an idea):

>>> almosts = GenExps(1e-4)
>>> almosts.next()
('e** (pi * sqrt(58))',  24591257751.999931)

http://mathworld.wolfram.com/AlmostInteger.html

Kirby

Author's note:  I haven't tested this for feasibility yet.  I've got a
new Pythonic Mathematics class starting tomorrow c/o Saturday Academy,
so might run it by my students, some of whom already know Python
pretty well.  It's a good exercise in building valid expressions that
evaluate to floats, coupled with some objective (to get "almost
integers").
```