The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Division-free LCM

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Oliver Steele

Posts: 112
Nickname: ows
Registered: Aug, 2003

Oliver Steele is Chief Software Architect at Laszlo Systems, Inc.
Division-free LCM Posted: Jul 8, 2007 7:19 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by Oliver Steele.
Original Post: Division-free LCM
Feed Title: Oliver Steele on Software
Feed URL: http://feeds.feedburner.com/osteele
Feed Description: Languages of the real and artificial.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by Oliver Steele
Latest Posts From Oliver Steele on Software

Advertisement

Division-free GCD

A few years ago I described an algorithm for computing the greatest common denominator without division. (Euclid’s algorithm requires division, in order to compute the remainder.) Although less efficient than the standard algorithm, I found it easier to teach to my children when they were learning to add fractions.

I’ve made a movie of the steps involved here.

Division-free LCM

Yesterday Paula Feynman asked me if there was a similar algorithm for finding the least common multiple. I came up with this one on the drive home. It can be used at grade school level — my children learned it in about half an hour — and I used their help (and the influence of Edwin Hutchins) to figure out the most teachable presentation.

The movie is here.

Steps Towards Linear Algebra, or, Gauss Meets Euclid

Although the notation obscures it, this is a great warm-up for teaching Gaussian elimination. The numbers in the second and third columns are the factors of the two inputs that sum to the number in the first column. (This is why the first two rows are filled with the identity.) From here on out, it’s Gaussian elimination: replace a row by a linear combination of rows, until the leading term in one of them has been annihilated. Since there are only two rows, we can work in place (by extending one table), instead of copying the matrices to a new location each time.

The difference from standard Gaussian elimination is in the set of row coefficients. Since the algorithm doesn’t allow you to divide a row by a scalar (or multiply by non-integer) in order to produce unity, you’re limited to operations within the ring of integers. This ensures that the operations preserve the number-theoretic properties of the inputs, which is what lets you recover the GCD and its co-factors at the end.

Sure enough, after I showed my son how the algorithm worked, I was able to easily show him how to invert a matrix in order to solve a family of systems of equations. (He had already worked with systems of equations in school, and I had shown him how to represent a system as a matrix last week.)

Nothing New Under the Sun

While writing this posting, I discovered that the division-free technique for computing the GCD was actually Euclid’s original algorithm.

Similarly, I belatedly found that most of the technique for computing the LCM of two numbers was also previously known (probably as of a century ago?). It’s the “table method” of the “extended Euclidean algorithm”. However, that method, at least as described at Wikipedia, stops short of actually computing the LCM: it terminates with the co-factors of the inputs. So maybe I’m bringing something to the table, so to speak.

Read: Division-free LCM

Topic: An Oversized, expensive Nano? Previous Topic   Next Topic Topic: TeamCity 2.1.1 Released

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use