Wednesday, November 21, 2012

Pearl of Wisdom

Just came across this gem of wisdom in this month's Harpers:

"Whatever you do, is bound to be a giant, annoying and irrevocable mistake. So make the best mistake you can."

Saturday, November 10, 2012

Loop and Do, and number theory

Well, I don't know when it started, but I always seem to be more comfortable writing a complicated do statement than trying to find the right combination of loop keywords to accomplish any non-trivial task in common lisp. "do" really is the more powerful tool, at the cost of having less builtin bells and whistles. I am uploading a bunch of functions I wrote for a number-theory class to github, since I have started to feel I won't add to many more things to it. It's far from polished, unpackaged, perhaps broken, and inelegant, but I want to have it someplace it won't crash. github repo. I will update it as appropriate, it's mainly a product of fooling around and never meant to be production quality. There are a ton of clumsy choices, and cruft resulting from them.

Tuesday, September 25, 2012

Fixing Emacs and Latex on Mac OS

So I bought a shiny new macbook, and immediately set about installing emacs and latex. A few hiccups. First, emacs couldn't find the latex executables. This was remedied with

(setenv "PATH" (concat "/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/texbin:/usr/bin:" (getenv "PATH")))
(setq exec-path (append '("/opt/local/bin" "/opt/local/sbin" "/usr/local/bin" "/usr/local/sbin" "/usr/texbin" "/usr/bin") exec-path))

Next, I typically want pdf rather than dvi output, and I'd like to use Preview to view these. Emacs defaults to Evince, which is unhelpful in a gnome-less world.

(setq TeX-PDF-mode t)

This can be set in Customize, but trying to do these next two was problematic, since there were drop-down menus in customize defaulting to the builtin list.

(setq TeX-view-program-list '(("Preview" "open %o")))
(setq TeX-view-program-selection '((output-pdf "Preview")))

Now I'm a latex compiling machine!

Tuesday, September 18, 2012

Data

Anyone ever tried to use excel to view a large csv file and gotten really sad? Like frustratingly sad?

Here's how this came about. Rahm Emmanuel in all his wisdom opened up the city of chicago's data as much as possible. One dataset is crime 2001 to present here. Well, if you go to this, and export to csv, you get ~1.08 GB of information. Loading this into Excel was were the fun began. First, my Excel for Mac 2011 seems to have a limit on worksheet sizes of about one million. Second, the helpful dialog pops up saying that the import failed, but that I'll get as many rows as can fit, and that I should import the remainder using "start import at row: n" in the csv dialog. Which makes a lot of sense. However, the most positive integer which is allowed in the dialog box for row number is 37677, 2^15 - 1. A signed 16 bit integer is still in a modern excel running on a 64 bit host? I'm awestruck by the quality.

I will try this same experiment later on in windows using excel 2010 to see what gives.

In defense of excel, bringing up eshell in emacs 24, then typing `cat Crimes... | grep NARCOTICS` gave me three lines before it froze the program. There should have been over 511,000 lines for that.

This is going to be fun.

Saturday, September 08, 2012

A Small Experiment

One proof of the infinitude of prime numbers goes as follows:

Assume there were k primes, and we had them all in a list. Now consider the number one more than the product of all these primes. None of the primes in our list divides this number. Either it is prime, or it has a prime divisor not in our list. So there is no such k, that is, the primes are without number.

I started to think, which primes would we discover if this was our only method? I fiddled around for a few minutes with a piece of lisp code to generate these "euclidean" primes (Euclid included this proof long ago in the Elements).


(defun factor (n)
  "return a list of factors of n"
  (let ((test 3)
(limit (+ 1 (floor (sqrt n)))))
    (cond
      ((eq n 1) nil)
      ((evenp n) (cons 2 (factor (/ n 2))))
      (t (do()
 ((or (zerop (mod n test)) (> test limit)))
  (incf test 2))
(if (> test limit)
    (list n)
    (cons test  (factor (/ n test))))))))



(defun euclidean-primes (n)
  "generate the n primes generated by euclids proof"
  (let ((primes (list 1)))
    (do ((count 0 (1+ count)))
        ((= count n) (remove 1 primes))
      (let ((eprimorial (1+ (reduce #'* primes))))
        (setf primes (union primes (factor eprimorial)))))))

So I ran this, an up to (euclidean-primes 8) there is no issue, with a nice result:

(31051 1033 607 547 139 13 7 2 3 43 3263443 29881 67003 9119521 6212157481)

But running this for 9 proved time consuming, as the value to be factored was an unwieldy 
(FACTOR 12864938683278671740537145998360961546653259485195807)
which I found in the debugger when I was wondering why my CPU had pegged at 100% for several minutes. The overhead of bignum-truncate and bignum-normalize were swamping the process.

Now, I bet that my factorization is unnecessarily complicated, and that it's not the most efficient program for doing this, but it was an interesting thought experiment. Also, it appears union does some funny thing to element ordering, while I was expecting these to be ascending or descending, it looks like the smallest values tend to propagate to the center.

Just for a full picture:

(loop for i from 1 upto 8 do (print (euclidean-primes i)))
(2) 
(2 3) 
(3 2 7) 
(7 2 3 43) 
(43 3 2 7 13 139) 
(139 13 7 2 3 43 3263443) 
(3263443 43 3 2 7 13 139 547 607 1033 31051) 
(31051 1033 607 547 139 13 7 2 3 43 3263443 29881 67003 9119521 6212157481) 

Saturday, June 09, 2012

Announcements

Yesterday I added an intended feature to the ODESolver. Now, the system announces each calculated state/time pair, so any interested observers can handle this information. Very simple observers include a state recorder, that just stores all incoming data in a sorted collection, and transcript recorder, that just writes information to the transcript (smalltalk's output stream). Practical extensions include curve fitting the data after the capture (take the set of points, and find a function that fits them).

One simple side-effect of being able to inspect the output is that I'm nearly certain I'm returning the wrong value in explicit steps, I noticed that I'm probably taking one step too many due to (initialTime to: endTime by: dt) do: [interesting parts here], which steps forward once to many times.

Is there a standard idiom to exclude the last item in a sequence? I would change to (initialTime to: endTime - dt by: dt), but I'm concerned about edge cases where delta-t isn't evenly divisible by dt, where does it stop?

Tuesday, June 05, 2012

Almost There

I redid the metacello configuration for SciSmalltalk this afternoon to split the Math-All package, since the current version of FileTree seems to be failing to handle this properly in the git repo (local directory copy). My intent is to remove the Math-All package as an option, use ConfigurationOfSciSmalltalk as a current target, and keep ss3/github synched much more simply.

I seem to have resolved the issue I was having where clean images are able to inspect the github local repo (all of them could write, but reading from it was not possible), which appears to have been triggered by some 2.0 update. Reloading Dale's package manually did the trick.

I tested the loaded packages from fresh 2.0 and 1.4 images, and it looks good. Only the test I need to fail to remind me to get to work is failing, and apart from a dependency loop in DHB-Numerical I think it's a clean load.


Github page
SqueakSource3 Site

Monday, June 04, 2012

ODE part 2

At present I have the following set up and tested:

an Euler Method explicit stepper and solver.
a Runge Kutte non-adaptive stepper and solver.

My obvious next step is adaptive step size control. My other big milestone is to implement an announcements based observer model to capture the data as a series and present the intermediate results.

I wish (and probably am only ignorant about it) that there was a straightforward 2d function plotter in Pharo.

Tuesday, May 22, 2012

Ordinary Differential Equations Solver

I've started the translation of the odeint-v2 boost library to SciSmalltalk. So far, I have defined the basic portions, a Stepper base class, an ExplicitStepper subclass which is for the time being masquerading as an Euler Stepper, an ExplicitSystem class which is a thin wrapper over a block, and some test cases for it.

Things should ramp up as I get into the flow of things. I'm not committing any of these to public repositories until I have something looking moderately useable. I may use this as an opportunity to make a branch on github (have been working straight to master so far).

Sunday, May 20, 2012

SciSmalltalk Updates

I updated SciSmalltalk's Metacello configuration to version 1.01. This version incorporates new bugfixes in the GeneticOptimizer submitted by Werner Kassens, and includes 200 unit tests. Test coverage is about 65-68% right now. This number is difficult to gauge as TestRunner and Monticello are having some confusion about which package some methods reside in, so the coverage is registered once, but the methods are shown twice. Though I have an internal guess about which these are, I have a hard time justifying the firm numbers. Once I have 100% test coverage, it will likely still show several methods in the list. C'est la vie. The broad majority of uncovered methods are in DHB-Numerics (a little over 400 methods need tests.)

I'm tempted to look into incorporating Nicolas Cellier's Arbitrary Precision Floating Point package (already included his Quaternion, Complex, and Number Extensions). I'm a little sad that there are no Doubles in Pharo/Squeak.

I need to start in on the ODE system solvers. I'm looking into odeint-v2 as a source of inspiration. Un-templating the C++ code into a dynamic language looks to be a fun time for me! I'm not certain I need to involve the generality of arbitrary algebras that they did, a good portion of this looks like it was built in to add support for CUDA operations.

I had a fun time this morning, as I did a pull merge in the wrong order and had to play some games to get my work from last night brought back into line. All the code from the commit was still visible, and all the packages were in the cache, so it wasn't more than a well learned lesson for the future. At least my own commits are visible in the timeline on my github person page.

Wednesday, May 16, 2012

Shared Experience

A real talk about smalltalk

This is a great post. I completely understand the revulsion when loading Squeak for the first time (esp. if you get Squeak 3.9 from your Linux distro). Like the author here, I feel that seeing Squeak 4.3+ or any Pharo image is a huge relief after using the coloring book releases of Squeak 3, with the drag and drop scripting tools everywhere.

And like the author, I have to say a dozen nice things about the debugger. Really the power tool that separates Smalltalk from any other language. Why doesn't gdb have an editor, compiler, and on-demand dynamic linker built in as a standard feature? I can think why.

He links also to 10 reasons why I'm using smalltalk as a starting point for his investigations, and points to James Robertson's screencasts at Smalltalk for you as being a useful jumpstart into using the system. I really hate screencasts, since I want to click on the 'desktop' but only end up pausing the video! But Robertson's continuing efforts at education are a treasure, and deserve a wide audience.

Sunday, May 13, 2012

Bug Fix

I think I may have submitted my first bug fix. Or I just added to the noise level.
In Pharo, the TestRunner tool allows for determining how much coverage your test suite has over some package. Basically, it records all the messages sent during execution of the tests, and compares this against all the messages implemented in that package. My personal goal is 100% test coverage, though that sometimes leads to a few seemingly meaningless tests.

Development on Pharo-2.0 is moving to restructure the basic tools and frameworks in the system, which has the unfortunate side effect of sometimes breaking the tools you are using. Something happened in the past week that broke the Run Coverage tool in TestRunner. I noticed that I could patch around it by undoing a few small changes that the developers made in the system dictionary (basically, the method for finding which tool handles which class of tasks). This worked for a few days, until the tool I moved it back to was removed from the system by another patch.

I spent a couple days working in Pharo-1.4 because of this, which is stable and unlikely to have more new problems. Today, I updated a clean 2.0 image and just let the debugger show me what was wrong. Four new methods later, I was able to get a coverage list running. The Smalltalk debugger is such a useful tool!

Rather than simply emitting a message, it gives you the entire call stack. Each stack frame is live, that is, you can look at all the passed arguments, change them, inspect them, send methods to them, etc. All of the errors I received were ultimately of the form X does not understand Y (trying to call a function on an object that doesn't implement it). Rewinding 2 stack frames showed me the call site in TestRunner's collectResultsFor method, and in the debugger, I could click on the does not understand error, click create, tell it which class in the hierarchy of X to implement the message in, choose a protocol, write the (very short) code to handle the method, and restart the stack frame where the call failed, and try over.

Honestly, as a very inexperienced programmer, to have a system so immediately supportive as to allow fixing a problem with the system tools in a few button clicks, test it, confirm that it's working, and move on with my life, is a huge relief. Having a system so understandable that it takes about 10 minutes and 10 lines of code to fix a problem in the IDE is exhilarating.

The next process involved feeding this back to the developer team. In Pharo, issues are tracked on google code, and if you've opened a ticket, you can automatically document your patch. In Nautilus, I clicked create a slice, which asked me for an issue number (mine was 5839), then automatically inserted the issue description in the slice. Submitting to PharoInbox was one more click away, and if what I did was useful, that's a bug fix!


Wednesday, May 09, 2012

Milestones for this week

Well, it's already Wednesday. I plan to get as much test coverage and documentation sorted out by Friday as possible. Then on to building/reconstructing/thinking about ODE's and their solutions.


SciSmalltalk Progress and github concerns

Today, I've been working on getting better test coverage for the packages in Math for SciSmalltalk. I have documented and completed coverage for DhbFloatingPointMachine. It looks like (following Didier Besset's Book) DhbPolynomial will be next, in chapter 2.2.

I added the complex class, and it looks like there are a lot of failing tests for Trigonometric/Circular functions.

Werner Kassens is interested in adding a KDTree implementation, and I'm excited to incorporate this when it materializes.

Does anyone know how to refork/synch a fork with upstream master on git/github? I've made the mistake of committing directly to upstream, and want to catch up with the changes I've made, but don't see the way to refresh a fork once upstream has gotten ahead of me. I think in the future what I want to do is push to my fork, then pull into master.

Also, has anyone had an issue with github deciding to use korean text in button images? The hover text is english, but all the graphics are now Hangul. Though I'm open to learning new powerful magics, I'm more of a Roman/Cyrillic/Hellenic reader, and Asian scripts always strike me as too foreign.

Lastly, I created a dummy-repo to test inline images in markdown. This is nowhere as easy as it should be! Dummy Repo

Tuesday, May 08, 2012

Ubuntu woes

Urgh, once again I struggled through the semiannual fight to bring a new ubuntu release onto my machines. It looks like my laptop adapted just fine, no loss of data or functionality, and apparently multiscreen display started working again.

My desktop had an issue where the soundcard module wasn't loaded into the kernel at boot. lsmod and modprobe showed tons of good things, but sound preferences was sending all my output to dummy device... well, reinstall from disk and thank heaven I partition /home far from /bin and /boot, and a fresh install is never more than a few hours of synaptic from yesterdays machine.

Since I've moved well away from Unity, I sometimes forget how little I like it, it's like a cute little jail, with a non-configurable dock, stupid invisible scrollbars, and garish colors. Gnome 2 on the laptop and WindowMaker on the desktop are the winners, still.

Only thing left is to set static ip on boot, not sure why the 'friendly' installer doesn't ask these questions anymore. Time was, installation was full of more questions than an income tax form.

Monday, April 23, 2012

Summer of Code

I just received my congratulatory email from Google. It looks like I am set to get a lot done this summer. I will be working on Sci-Smalltalk, implementing mathematical software in Pharo.

I am very excited to move forward on this. I expect to have the best summer ever.

Sunday, April 08, 2012

Ubuntu Tour

Alright, normally the Ubuntu folks have been aggravating more each release. especially when it comes to UI divergence and pesky 'features', like the removal of locatable scrollbars.

However, in fairness, I thought this was a rather clever test-drive page:
Ubuntu Tour

The most surprising thing (besides how attractive it looks), is that they just render off-site content in firefox if you use it. The back button doesn't work, but is this a free web page proxy?

Thursday, March 08, 2012

Smalltalk First Impressions

For the past two weeks I have been experimenting with Smalltalk. I was having a conversation perhaps a month ago with a classmate, who was taking a programming languages survey, and she was mentioning smalltalk, and how weird it was. I tried to explain that it wasn't so foreign, but I may have been tainted by exposure to common lisp, so much of the dynamic nature of smalltalk seemed like a natural thing to expect from a programming system.

I started to look into squeak, and a little reading lead me to Pharo, which if you are an adult looking to write programs and learn smalltalk, offers a much cleaner UI, is compatible with the squeak vm, and has excellent development tools, and no toy like features which provide a funny first impression of Squeak.

It turns out much of what I thought I knew about smalltalk was either incomplete or just plain wrong, borrowing from things I remembered about Objective C from a furtive attempt to start using it years ago. I have been repeatedly blown away by the depth of the object metaphor in smalltalk. The inspector and explorer are leagues above the tools I had become used to (either gdb+emacs or slime+emacs). The additional scratchpads at the bottom of the inspector allowing modification of the object at runtime are well planned and very useful. The debugger at first glance looks like the slime debugger, a variety of restarts are available, a somewhat terse message regarding the offending condition, and a partial stack trace / message history are presented. But the immediate usability of the system comes in the ability to browse the offending code site, modify the code definitions, restart or proceed and fix on the spot the problem.

In two weeks, I worked through the "Pharo By Example" LightsOut program (which was Quinto in Squeak by Example), get a quick feel for SUnit and the test runner, where the tests are only a keystroke away, and can be automatically created, blindly find my way through a currency converter gui program (a la Learning Cocoa), and have created a small DFA simulator. The learning curve is a little steep, but having seen the example application, and learned the short syntax of the language (really fits on a single sheet of paper, possibly a 4x6 card), the remainder of programming seems to have been selecting the appropriate classes, browsing their sanely named selectors, putting the pieces together, and running the tests.

My DFA simulation took about 45 minutes to piece together in between classes one morning, and I am a complete novice in Smalltalk.

Things I don't understand, certainly include monticello/metacello, how to install software, which pieces are loadable but will break your system, and have certainly had my share of frozen images. I recommend to anyone starting to keep a pristine image, and if you ever start it, to immediately save your working copy as an alternate name. Monticello is very useful in packaging versioned bundles, and seems to beat fileOut handily.

The Pharo developers have a very active community, their mailing list is busy, the community is experimenting in several directions at once, and what's most important, the system is discoverable. The browsers and finders are beautiful, the debugger is amazing, the Morphic Hierarchy is easy to browse, and finding the right tool for the job is simply a matter of finding the right pieces to put together.

One thing I haven't discovered in Morphic is how to specify relative position of submorphs, so I simply give explicit locations in the bounds, and hope the user doesn't alter the initial size too much. VisualWorks' GUI Painter seems to have simple checkboxes to control this behavior (if you've used Interface Builder in XCode you will be familiar with Springies...), and perhaps it's present in Morphic as well.

I have to say a few nice things about Stephane Ducasse's well kept links to available books, and his personal efforts in pushing Pharo forward.

Sunday, February 26, 2012

Ongoing Elsevier Boycott

Several mathematicians recently started taking action to boycott all Elsevier journals, following comments by Mr Gower of Cambridge. This has been a large enough embarrassment for them, and has gained international news coverage (I read about it in the economist less than 10 days after seeing the initial statements on Gower's Weblog.)

Mr Gower adds a rebuttal to an open letter from Elsevier to the research community here.

Saturday, February 25, 2012

Inventing on Principle

Now I see what everyone was so excited about. Brett Victor - Inventing on Principle. is perhaps the most intriguing video I've seen in over a year. This is the future coming at you fast. It looks like dynamic languages are finally coming back to the future.

Thursday, February 02, 2012

A Simple Example

Occasionally, people make far fetched claims about the flexibility offered by lisp. Here is a simple example: editing the source code of a running program.

(defun foo () t) ;; foo returns true when called
(loop (when (not (foo)) (return))) ;; call foo repeatedly, until it is false.

This is of course a simple while true do nothing loop. But then we evaluate this little bit on the same system in a separate interaction session/slime buffer.

(defun foo () nil) ;; foo returns nil/false when called.

Amazingly, our loop exits, returns nil, and we are back in business. This is of course a contrived example, but not so far from the mark in expressing the simple idea that editing a program at runtime can yield a lot of power.

Saturday, January 07, 2012

Friday, January 06, 2012

Busy Week

We wanted to see "The Artist" on New Years Day, but the showing we planned on was sold out. Our second choice, "A Dangerous Method", left us with one hour of free time. The theater in Evanston has a Cost Plus next door, so we decided to while away the time in there. My wife found these very attractive blue leather chairs, and launched on a mission to replace our used Ikea chairs with the white slipcovers with these 'more adult' chairs. We placed a hold that day and borrowed a truck from someone who owed us a small favor for moving their things on New Years Eve. We were able to find a home for the other chairs with a friend the same day, and now we are back to a normal set of two chairs in the living room.


While at the friends apartment delivering chairs, I picked up her copy of "The Winter of Our Discontent" by Steinbeck and have since devoured it. I look forward to returning it with positive reviews.

Lately I've been reading through some of the published ACL2 'books' for inspiration. The system looks quite readable, and after wrestling for some time with Cyc, it's a pleasure to find something so aesthically pleasant. The modifications and extensions to the main CL functions are mostly removable from the axioms file, and implementing and testing some of the methods has been a relaxing pastime. Having the full source in /usr/share is a wonderful benefit to the curious. Anyone looking for hints on how to bootstrap lisp in lisp is encouraged to read through the beautifully documented acl2.lisp file, which sets up all packages and handles masking  out the existing language while preserving the system's symbols in another area.

School starts Monday. I picked up my bus pass and last book yesterday. I look forward to the interaction and stimulation that a group effort to understand some thorny subjects will bring.

I've recently started using github. Somehow, within 24 hours, a friend from school had found me and followed me. Amazing how quickly information spreads. Nothing I've put there is particularly interesting, but it's useful to think I can have an additional backup, and starting to use vc is enlightening. I think I hear sourceforge slowly collapsing.

Beth left town tonight for the weekend. That leaves me to indulge in stuffed green peppers and Sabado Gigante. I can't wait to watch el Chacal de la trompeta eliminate some more contestants.

Thursday, January 05, 2012

Branding

xkcd: Brand Identity

In an unrelated note, I added "No Logo" to my wishlist yesterday.