Farey Sequence - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: Farey Sequence (/thread-145512.html) |
Farey Sequence - Thomas Klemm - 01-09-2009 Farey SequenceI was given this book: "An Introduction to the Theory of Numbers" by Hardy & Wright and there's this chapter about Farey Series I've never heard before. Of course I wanted to calculate them writing a program for one of my HP-calculators. Let's have a look at what I came out with:
F001 LBL F F013 ENTER Example:
5 XEQ F ENTER 0
E001 LBL E
Please note that #> stands for the black triangle that indicates STO-ring in a variable.
\<< DUP 1 DUP 0 Here we get a list of vectors [ p q ] indicating the fraction: p/q:
{
DEFINE a 1GETLAM Now we get a list of algebraic expressions:
{ '0/1' '1/5' '1/4' ... '3/4' '4/5' '1/1' } Looking at the different solutions I wondered whether I can still understand what I've done in a few weeks or months from now. Why do I have to burry the algorithm in a bunch of cryptic mnemonics when all I want to say is:
def farey( n ):
However this is not the International Obfuscated C Code Contest. Quiet the contrary: I tried to stay as close to the original program (Python) as possible. And it's not a complicated algorithm neither. Just be honest: which solution do you understand best at a first glimpse? Then why is it so much more fun to write a program using cryptic mnemonics?
Best regards
Re: Farey Sequence - Egan Ford - 01-10-2009 Hello Thomas, I first read about this series in Recreations in the Theory of Numbers by Beiler. One of my favorite books.
Quote:Python. I was programming computers before calculators.
Quote:The challenge. Being closer to the action, almost like writing machine code. Since this is the year of the 41, here is my version with word-wrapped output (printer required). i41CXp output:
RAW file: http://sense.net/~egan/41cx/FAREY.RAW Barcode: http://sense.net/~egan/41cx/farey.pdf
Source: 01 LBL "FAREY" 18 RCL 00 35 CF 00 52 RCL 05 Update: Reduced code size by 25%. Improved word-wrap output to use column 24. Fixed F(1). Edited: 10 Jan 2009, 1:03 p.m.
Re: Farey Sequence - Thomas Klemm - 01-12-2009 On the Teeth of Wheels, an article on the use of the related Stern-Brocot tree in the design of gears.
Quote:
I've started with an HP-41.
Thanks for providing your solution with barcode and the book recommendation. Just had a look at it: seems promising.
|