Wednesday, March 12, 2008

Fractions R Us

:: congrats to anna ::
[first posted to Math Forum, earlier today (typos fixed for this version, code colorized)]

I'm noticing with our novel approach to teaching fractions, that we're discounting the importance of the LCM in connection with adding them. The reason for that is our use of Euclid's Algorithm for the GCD upon instantiation, meaning when we create a fraction object, we automatically convert to the canonical delegate in each equivalence class, namely that for which the numerator and denominator are relatively prime.

The background context is "building fractions" (yes, this is constructionism) from the ground up, in some computer language facilitating operator overloading. That's right, we're doing some programming as a part of our standard mathematics curriculum, what of it? TIs have been programmable for years, and we've heard no one fussing ("more features!" has always been the battle cry, no?).

As I've posted about numerous times here (math-teach), irrespective of whether programming's involved, it's interesting to see if a curriculum dodges Euclid's Method for finding the GCD, escaping into "factor trees" (which I have nothing against -- very important for teaching the meaning of the Fundamental Theorem of Arithmetic).

I'd call that a kind of litmus test, to see if your proposal meets minimum standards -- let's apply it to the states first and foremost, see which state legislatures are being lobbied intelligently, vs. getting fed a lot of mumbo jumbo. Good project for a PhD candidate.

So how do we add fractions then? Of course the old fashioned way: a/b + c/d == (a/b)(d/d) + (c/d)(b/b) == (ad + cb)/bd as justified by using multiplicative identity, other axioms (I'm sure Paul could help out here).

Then you get gcd((ad + cb), bd)), call it thegcd (could be 1), so your new (reduced) numerator, denominator (p,q) become p/thegcd, q/thegcd (multiplying by x/x is to multiply by 1, the multiplicative identity -- this came up earlier, in justifying (a/b)==(a/b)(d/d).

How does this look in actual Python? Here's a fraction class (rational number class) developed to the point of enabling its instances (p/q) to multiply and add (p,q integers, q <> 0). Click for larger views.