NYCJUG/2013-09-10
Rabbit constant, golden ratio, Haskell, JDB, JD, database, generalized inverses of probability distributions, JHS (J HTTP Server), file renaming app, Iverson College report, terse code versus verbose code, performance doesn't matter, language matters
Location:: ThomasNet
Meeting Agenda for NYCJUG 20130910
1. Beginner's regatta: how to understand a line of J: see "Golden strings and the rabbit constant.doc". 2. Show-and-tell: what's new in J8? Chris Burke will tell us. Generalized inverses using Newton iteration: see "Generalized Inverse of Cumulative Probability Distributions.doc". 3. Advanced topics: Availability of a J server? What do we need to produce retail-level J-apps? See "Better File Renaming App.doc". 4. Learning, teaching and promoting J, et al.: impressions of an outsider - see "Report on Iverson College - Coding Is Like Cooking by Emily Bache.doc". The value of terse code: how much code is too much? See "Cost of Code Conversion.doc". Losing a negative of interpreters: see "The Day Performance Didnt Matter Anymore.doc" Generally, language matters - see "Study shows language can cause the invisible to be seen.doc"
Proceedings
We looked at a little J code and saw how one might break down a J phrase to better understand it. Then Chris Burke of J Software talked about version 8 of J and how the company is promoting a high-powered database called JD. This is a successor to the free database JDB offered with J but represents a big break from that codebase in terms of functionality and performance.
We then looked at how we might use a J version of the Newton-Raphson solver to calculate inverse values of probability distributions. We also talked about how J is available over the web, especially with recent updates to JHS - the J HTTP Server. This led to discussion of what J needs to offer to allow J programmers to offer retail-level applications, especially those deliverable in a browser. The example application we looked at is a simple file-renaming utility that is simple to assemble in J but is apparently fairly popular.
We next looked an essay about the most recent Iverson College, written by someone new to the array-language world who evidently is intrigued by the notion of terseness lending clarity to the expression of an algorithm. We continued on this theme of the value of minimal code by examining a report of the huge amount of money proposed to update a major benefits system for the state of New Zealand. Much of the cost is due simply to the enormous size of the code-base.
Finally, we talked about a trio of essays. One postulated that we have reached a point of such widely-available, powerful computing machines that long-past considerations of performance are becomingly increasingly irrelevant. The other two addressed broader issues of language and how it affects perception.
Beginner's Regatta
. Golden strings and the rabbit constant [from http://www.johndcook.com/blog/2013/07/23/golden-strings/] Posted on 23 July 2013 by John — 2 Comments ↓ Golden strings are analogous to Fibonacci numbers, except one uses concatenation rather than addition. Start with s,,1,, = “1″ and s,,2,, = “10″. Then define s,,n,, = s,,n-1,, + s,,n-2,, where “+” means string concatenation. The first few golden strings are
- “1″
- “10″
- “101″
- “10110″
- “10110101″
- …
. The length of s,,n,, is F,,n,,,,+1,,, the n+1st Fibonacci number. Also, s,,n,, contains F,,n,, 1′s and F,,n,,,,-1,, 0′s. (Source: The Glorious Golden Ratio). If we interpret the s,,n,, as the fractional part of a binary number, the sequence converges to the rabbit constant R = 0.7098034428612913… It turns out that R is related to the golden ratio φ by where ⌊i φ⌋ is the largest integer no greater than iφ. Here’s a little Python code to print out the first few golden strings and an approximation to the rabbit constant.
from sympy.mpmath import mp, fraction a = "1" b = "10" for i in range(10): b, a = b+a, b print(b) n = len(b) mp.dps = n denom = 2**n num = int(b, 2) rabbit = fraction(num, denom) print(rabbit)
. Note that the code sets the number of decimal places, mp.dps, to the length of the string b. That’s because it takes up to n decimal places to exactly represent a rational number with denominator 2^n^.
2 comments on “Golden strings and the rabbit constant”
1. Skip Cave says, on 23 July 2013 at 13:34 :
. The rabbit constant calculation in the J language:
0.5#.|.0,;(;;{.)^:(6) 1;0 0.709803
. written by Raul Miller @ forums.jsoftware.com
1. Edward Kmett says, on 5 August 2013 at 22:24 : In Haskell:
gold = “1″:”10″:zipWith (++) (tail gold) gold
Understanding the J Code
0.5#.|.0,;(;;{.)^:(6) 1;0 NB. Run it as presented. 0.709803 |.0,;(;;{.)^:(6) 1;0 NB. Pare it down to see penultimate result. 0 1 1 0 1 1 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 0 (;;{.)^:(6) 1;0 NB. Pare it down further. +-----------------------------------------+-------------------------+ |1 0 1 1 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 0 1|1 0 1 1 0 1 0 1 1 0 1 1 0| +-----------------------------------------+-------------------------+ (;;{.)^:(0) 1;0 NB. See initial value on which fork ;;{. Runs. +-+-+ |1|0| +-+-+ (;;{.)^:(1) 1;0 NB. First iteration… +---+-+ |1 0|1| +---+-+ (;;{.)^:(2) 1;0 NB. Next iteration… +-----+---+ |1 0 1|1 0| +-----+---+
Learning, teaching and promoting J
A Report on Iverson College
The blogger Emily Bache, who asserts that "Coding is like Cooking," reported on her experience at Iverson College this past Autumn. Her major conclusions were as follows.
. My main discoveries are that Array Programming is different again from Object Oriented Programming and Functional Programming, (although it has a lot in common with functional programming), and that this community contains some exceptional programmers. The total number of array language programmers is however extremely small and their work seems to be pretty much unknown to the wider programming community.
Interestingly, even though she found APL to look intimidating, she eventually came to be more comfortable with its notation in preference to that of J. It seems she also came to appreciate the previously foreign notion of terseness as an aid to clarity.
In all, it's interesting to see the APL community from the point of view of an outsider who's open to what it has to offer.
Cost of Code Conversion
In contrast to the economy of terse code, we might consider a contemporary example of the cost of verbose code in this report about a proposal for a major overhaul of New Zealand's code base supporting its tax system.
Date: Fri, 23 Aug 2013 17:00:45 +1200 From: "Richard A. O'Keefe" <ok@cs.otago.ac.nz> Subject: NZ Inland Revenue system: Watch this space
The current New Zealand Inland Revenue Department is 40 million lines of COBOL and DMSII and who-knows-what which has been stretched far past its original design. I am by background and inclination in roughly the same political camp as say I. F. Stone, but in the case of a computer system like this it is hard to argue with small-government conservatives who claim that the tax system should be simplified. A simpler system is not necessarily one that is unfair to workers, after all.
[The] system has been transformed over the years from a tax system collecting only income and company tax, to one which covers child support, ... student loans, ... Kiwisaver [a retirement scheme], and Working for Families.
http://www.stuff.co.nz/national/politics/8619006/IRD-computer-systems-1-5b-overhaul
The Cabinet approved what has been described as a "major overhaul" but sounds more like a total rewrite. The project is supposed to take 10 years, and to cost a milliard dollars, although they're allowing for one and a half milliard. To put this in perspective, the population of the country is about 4.5 million, so the annual spend will be 22 to 34 [sic] dollars per man, woman, and child per year.
Several people are freaking out about the big number, but
40,000,000 lines of code
- 20 lines of tested working documented code/day
= 2,000,000 programmer-days
- 200 work-days per year
= 10,000 programmer work-years
- $100,000 salary and overheads per programmer year
= $1,000,000,000 (one milliard)
equivalent must have been spent building the old system -- using some very crude estimates I don't care to justify -- so the expected cost of the new system is not out of line.
Nonetheless, slouching your way to Bedlam one new feature request at a time is one thing, *intending* to go there is quite another. It would make a huge amount of sense spending a full year of design trying to reduce the size of the planned system (whatever they think the size will be), but it will take a special miracle from St Thomas More to make _that_ happen.
Expect to hear interesting things about this.
An Effect of Language on Thought
We discussed an interesting piece of research in which researchers have conducted experiments demonstrating that, in some instances, language can cause objects obscured from view to come into focus.
We also looked at another piece of research about "differences in the way 4 year old children process geometric concepts." This was an attempt to explore questions about how much of knowledge about geometric concepts is "in-born" as opposed to learned.
Materials
- File:Golden strings and the rabbit constant.pdf
- File:Generalized Inverse of Cumulative Probability Distributions.pdf
- File:Better File Renaming App.pdf
- File:Report on Iverson College - Coding Is Like Cooking by Emily Bache.pdf
- File:Cost of Code Conversion.pdf
- File:The Day Performance Didnt Matter Anymore.pdf
- File:Study shows language can cause the invisible to be seen.pdf