Thursday, July 24, 2014

Floating Point Benchmark: Lua Language Added

I have posted an update to my trigonometry-intense floating point benchmark which adds Lua to the list of languages in which the benchmark is implemented. A new release of the benchmark collection including Lua is now available for downloading.

Lua was developed with the intention of being a small-footprint scripting language which could be easily embedded in applications. Despite this design goal, which it has achieved superbly, being widely adopted as the means of extensibility for numerous games and applications, it is a remarkably sophisticated language, with support for floating point, complex data structures, object oriented programming, and functional programming. It is a modern realisation of what I attempted to achieve with Atlast in 1990, but with a syntax which most programmers will find familiar and a completely memory-safe architecture (unless compromised by user extensions). If I were developing an application for which I needed scripting or user extensibility, Lua would be my tool of choice, and in porting the benchmark to the language I encountered no problems whatsoever—indeed, it worked the first time.

The relative performance of the various language implementations (with C taken as 1) is as follows. All language implementations of the benchmark listed below produced identical results to the last (11th) decimal place.

Language Relative
Time
Details
C 1 GCC 3.2.3 -O3, Linux
Visual Basic .NET 0.866 All optimisations, Windows XP
FORTRAN 1.008 GNU Fortran (g77) 3.2.3 -O3, Linux
Pascal 1.027
1.077
Free Pascal 2.2.0 -O3, Linux
GNU Pascal 2.1 (GCC 2.95.2) -O3, Linux
Java 1.121 Sun JDK 1.5.0_04-b05, Linux
Visual Basic 6 1.132 All optimisations, Windows XP
Haskell 1.223 GHC 7.4.1-O2 -funbox-strict-fields, Linux
Ada 1.401 GNAT/GCC 3.4.4 -O3, Linux
Go 1.481 Go version go1.1.1 linux/amd64, Linux
Simula 2.099 GNU Cim 5.1, GCC 4.8.1 -O2, Linux
Erlang 3.663
9.335
Erlang/OTP 17, emulator 6.0, HiPE [native, {hipe, [o3]}]
Byte code (BEAM), Linux
ALGOL 60 3.951 MARST 2.7, GCC 4.8.1 -O3, Linux
Lisp 7.41
19.8
GNU Common Lisp 2.6.7, Compiled, Linux
GNU Common Lisp 2.6.7, Interpreted
Smalltalk 7.59 GNU Smalltalk 2.3.5, Linux
Forth 9.92 Gforth 0.7.0, Linux
COBOL 12.5
46.3
Micro Focus Visual COBOL 2010, Windows 7
Fixed decimal instead of computational-2
Algol 68 15.2 Algol 68 Genie 2.4.1 -O3, Linux
Python 17.6 Python 2.3.3 -OO, Linux
Lua 22.7 Lua 5.2.3, Linux
Perl 23.6 Perl v5.8.0, Linux
Ruby 26.1 Ruby 1.8.3, Linux
JavaScript 27.6
39.1
46.9
Opera 8.0, Linux
Internet Explorer 6.0.2900, Windows XP
Mozilla Firefox 1.0.6, Linux
QBasic 148.3 MS-DOS QBasic 1.1, Windows XP Console

The performance of Lua is comparable to other scripting languages which compile to and execute byte-codes, such as Perl, Python, and Ruby. Raw CPU performance is rarely important in a scripting language, as it is mostly used as “glue” to invoke facilities of the host application which run at native code speed.

Posted at 22:32 Permalink

Wednesday, July 16, 2014

Atlast 2.0 (64-bit) Released

I have just posted the first update to Atlast since 2007. Atlast is a FORTH-like language toolkit intended to make it easy to open the internal facilities of applications to users, especially on embedded platforms with limited computing and memory resources.

Like FORTH, Atlast provides low-level access to the memory architecture of the machine on which it runs, and is sensitive to the length of data objects. The 1.x releases of Atlast assume integers and pointers are 32 bit quantities and floating point numbers are 64 bit, occupying two stack items. This assumption is no longer the case when building programs in native mode on 64-bit systems: integers, pointers, and floating point values are all 64 bits.

Release 2.0 of Atlast is a dedicated 64-bit implementation of the language. If you are developing on a 64-bit platform and are confident you will only target such platforms, it provides a simpler architecture (no need for double word operations for floating point) and a larger address space and integers. This comes at the cost of loss of source code compatibility with the 32-bit 1.x releases, particularly for floating point code. If your target platform is a 32-bit system and your development machine is 64-bit, it's best to use version 1.2 (which is functionally identical to 2.0), cross-compiled as 32-bit code. If you don't use floating point or do low-level memory twiddling, it's likely your programs will work on both 32- and 64-bit versions.

Although Atlast includes comprehensive pointer and stack limit checking, it is not memory-safe, and consequently I do not encourage its use in modern applications. When it was originally developed in the late 1980s, its ability to fit in a small memory footprint was of surpassing importance. With the extravagant memory and compute power of contemporary machines, this is less important and other scripting languages which are both entirely safe and less obscure in syntax will usually be preferable. Still, some people working with embedded systems very close to the hardware continue to find Atlast useful, and this release updates it for 64-bit architectures.

The distribution archive has been re-organised in 2.0, collecting the regression test, examples from the user manual, and benchmarks in subdirectories. An implementation of my floating point benchmark is included among the examples.

Posted at 23:56 Permalink

Saturday, June 28, 2014

Reading List: The Case for Space Solar Power

Mankins, John C. The Case for Space Solar Power. Houston: Virginia Edition, 2014. ISBN 978-0-9913370-0-2.
As world population continues to grow and people in the developing world improve their standard of living toward the level of residents of industrialised nations, demand for energy will increase enormously. Even taking into account anticipated progress in energy conservation and forecasts that world population will reach a mid-century peak and then stabilise, the demand for electricity alone is forecasted to quadruple in the century from 2000 to 2100. If electric vehicles shift a substantial part of the energy consumed for transportation from hydrocarbon fuels to electricity, the demand for electric power will be greater still.

Providing this electricity in an affordable, sustainable way is a tremendous challenge. Most electricity today is produced by burning fuels such as coal, natural gas, and petroleum; by nuclear fission reactors; and by hydroelectric power generated by dams. Quadrupling electric power generation by any of these means poses serious problems. Fossil fuels may be subject to depletion, pose environmental consequences both in extraction and release of combustion products into the atmosphere, and are distributed unevenly around the world, leading to geopolitical tensions between have and have-not countries. Uranium fission is a technology with few environmental drawbacks, but operating it in a safe manner is very demanding and requires continuous vigilance over the decades-long lifespan of a power station. Further, the risk exists that nuclear material can be diverted for weapons use, especially if nuclear power stations proliferate into areas which are politically unstable. Hydroelectric power is clean, generally reliable (except in the case of extreme droughts), and inexhaustible, but unfortunately most rivers which are suitable for its generation have already been dammed, and potential projects which might be developed are insufficient to meet the demand.

Well, what about those “sustainable energy” projects the environmentalists are always babbling about: solar panels, eagle shredders (wind turbines), and the like? They do generate energy without fuel, but they are not the solution to the problem. In order to understand why, we need to look into the nature of the market for electricity, which is segmented into two components, even though the current flows through the same wires. The first is “base load” power. The demand for electricity varies during the day, from day to day, and seasonally (for example, electricity for air conditioning peaks during the mid-day hours of summer). The base load is the electricity demand which is always present, regardless of these changes in demand. If you look at a long-term plot of electricity demand and draw a line through the troughs in the curve, everything below that line is base load power and everything above it is “peak” power. Base load power is typically provided by the sources discussed in the previous paragraph: hydrocarbon, nuclear, and hydroelectric. Because there is a continuous demand for the power they generate, these plants are designed to run non-stop (with excess capacity to cover stand-downs for maintenance), and may be complicated to start up or shut down. In Switzerland, for example, 56% of base load power is produced from hydroelectric plants and 39% from nuclear fission reactors.

The balance of electrical demand, peak power, is usually generated by smaller power plants which can be brought on-line and shut down quickly as demand varies. Peaking plants sell their power onto the grid at prices substantially higher than base load plants, which compensates for their less efficient operation and higher capital costs for intermittent operation. In Switzerland, most peak energy is generated by thermal plants which can burn either natural gas or oil.

Now the problem with “alternative energy” sources such as solar panels and windmills becomes apparent: they produce neither base load nor peak power. Solar panels produce electricity only during the day, and when the Sun is not obscured by clouds. Windmills, obviously, only generate when the wind is blowing. Since there is no way to efficiently store large quantities of energy (all existing storage technologies raise the cost of electricity to uneconomic levels), these technologies cannot be used for base load power, since they cannot be relied upon to continuously furnish power to the grid. Neither can they be used for peak power generation, since the times at which they are producing power may not coincide with times of peak demand. That isn't to say these energy sources cannot be useful. For example, solar panels on the roofs of buildings in the American southwest make a tremendous amount of sense since they tend to produce power at precisely the times the demand for air conditioning is greatest. This can smooth out, but not replace, the need for peak power generation on the grid.

If we wish to dramatically expand electricity generation without relying on fossil fuels for base load power, there are remarkably few potential technologies. Geothermal power is reliable and inexpensive, but is only available in a limited number of areas and cannot come close to meeting the demand. Nuclear fission, especially modern, modular designs is feasible, but faces formidable opposition from the fear-based community. If nuclear fusion ever becomes practical, we will have a limitless, mostly clean energy source, but after sixty years of research we are still decades away from an operational power plant, and it is entirely possible the entire effort may fail. The liquid fluoride thorium reactor, a technology demonstrated in the 1960s, could provide centuries of energy without the nuclear waste or weapons diversion risks of uranium-based nuclear power, but even if it were developed to industrial scale it's still a “nuclear reactor” and can be expected to stimulate the same hysteria as existing nuclear technology.

This book explores an entirely different alternative. Think about it: once you get above the Earth's atmosphere and sufficiently far from the Earth to avoid its shadow, the Sun provides a steady 1.368 kilowatts per square metre, and will continue to do so, non-stop, for billions of years into the future (actually, the Sun is gradually brightening, so on the scale of hundreds of millions of years this figure will increase). If this energy could be harvested and delivered efficiently to Earth, the electricity needs of a global technological civilisation could be met with a negligible impact on the Earth's environment. With present-day photovoltaic cells, we can convert 40% of incident sunlight to electricity, and wireless power transmission in the microwave band (to which the Earth's atmosphere is transparent, even in the presence of clouds and precipitation) has been demonstrated at 40% efficiency, with 60% end-to-end efficiency expected for future systems.

Thus, no scientific breakthrough of any kind is required to harvest abundant solar energy which presently streams past the Earth and deliver it to receiving stations on the ground which feed it into the power grid. Since the solar power satellites would generate energy 99.5% of the time (with short outages when passing through the Earth's shadow near the equinoxes, at which time another satellite at a different longitude could pick up the load), this would be base load power, with no fuel source required. It's “just a matter of engineering” to calculate what would be required to build the collector satellite, launch it into geostationary orbit (where it would stay above the same point on Earth), and build the receiver station on the ground to collect the energy beamed down by the satellite. Then, given a proposed design, one can calculate the capital cost to bring such a system into production, its operating cost, the price of power it would deliver to the grid, and the time to recover the investment in the system.

Solar power satellites are not a new idea. In 1968, Peter Glaser published a description of a system with photovoltaic electricity generation and microwave power transmission to an antenna on Earth; in 1973 he was granted U.S. patent 3,781,647 for the system. In the 1970s NASA and the Department of Energy conducted a detailed study of the concept, publishing a reference design in 1979 which envisioned a platform in geostationary orbit with solar arrays measuring 5 by 25 kilometres and requiring a monstrous space shuttle with payload of 250 metric tons and space factories to assemble the platforms. Design was entirely conventional, using much the same technologies as were later used in the International Space Station (ISS) (but for a structure twenty times its size). Given that the ISS has a cost estimated at US$ 150 billion, NASA's 1979 estimate that a complete, operational solar power satellite system comprising 60 power generation platforms and Earth-based infrastructure would cost (in 2014 dollars) between 2.9 and 8.7 trillion might be considered optimistic. Back then, a trillion dollars was a lot of money, and this study pretty much put an end to serious consideration of solar power satellites in the U.S.for almost two decades. In the late 1990s, NASA, realising that much progress has been made in many of the enabling technologies for space solar power, commissioned a “Fresh Look Study”, which concluded that the state of the art was still insufficiently advanced to make power satellites economically feasible.

In this book, the author, after a 25-year career at NASA, recounts the history of solar power satellites to date and presents a radically new design, SPS-ALPHA (Solar Power Satellite by means of Arbitrarily Large Phased Array), which he argues is congruent with 21st century manufacturing technology. There are two fundamental reasons previous cost estimates for solar power satellites have come up with such forbidding figures. First, space hardware is hideously expensive to develop and manufacture. Measured in US$ per kilogram, a laptop computer is around $200/kg, a Boeing 747 $1400/kg, and a smart phone $1800/kg. By comparison, the Space Shuttle Orbiter cost $86,000/kg and the International Space Station around $110,000/kg. Most of the exorbitant cost of space hardware has little to do with the space environment, but is due to its being essentially hand-built in small numbers, and thus never having the benefit of moving down the learning curve as a product is put into mass production nor of automation in manufacturing (which isn't cost-effective when you're only making a few of a product). Second, once you've paid that enormous cost per kilogram for the space hardware, you have launch it from the Earth into space and transport it to the orbit in which it will operate. For communication satellites which, like solar power satellites, operate in geostationary orbit, current launchers cost around US$ 50,000 per kilogram delivered there. New entrants into the market may substantially reduce this cost, but without a breakthrough such as full reusability of the launcher, it will stay at an elevated level.

SPS-ALPHA tackles the high cost of space hardware by adopting a “hyper modular” design, in which the power satellite is composed of huge numbers of identical modules of just eight different types. Each of these modules is on a scale which permits prototypes to be fabricated in facilities no more sophisticated than university laboratories and light enough they fall into the “smallsat” category, permitting inexpensive tests in the space environment as required. A production power satellite, designed to deliver 2 gigawatts of electricity to Earth, will have almost four hundred thousand of each of three types of these modules, assembled in space by 4,888 robot arm modules, using more than two million interconnect modules. These are numbers where mass production economies kick in: once the module design has been tested and certified you can put it out for bids for serial production. And a factory which invests in making these modules inexpensively can be assured of follow-on business if the initial power satellite is a success, since there will a demand for dozens or hundreds more once its practicality is demonstrated. None of these modules is remotely as complicated as an iPhone, and once they are made in comparable quantities shouldn't cost any more. What would an iPhone cost if they only made five of them?

Modularity also requires the design to be distributed and redundant. There is no single-point failure mode in the system. The propulsion and attitude control module is replicated 200 times in the full design. As modules fail, for whatever cause, they will have minimal impact on the performance of the satellite and can be swapped out as part of routine maintenance. The author estimates than on an ongoing basis, around 3% of modules will be replaced per year.

The problem of launch cost is addressed indirectly by the modular design. Since no module masses more than 600 kg (the propulsion module) and none of the others exceed 100 kg, they do not require a heavy lift launcher. Modules can simply be apportioned out among a large number of flights of the most economical launchers available. Construction of a full scale solar power satellite will require between 500 and 1000 launches per year of a launcher with a capacity in the 10 to 20 metric ton range. This dwarfs the entire global launch industry, and will provide motivation to fund the development of new, reusable, launcher designs and the volume of business to push their cost down the learning curve, with a goal of reducing cost for launch to low Earth orbit to US$ 300–500 per kilogram. Note that the SpaceX Falcon Heavy, under development with a projected first flight in 2015, already is priced around US$ 1000/kg without reusability of the three core stages which is expected to be introduced in the future.

The author lays out five “Design Reference Missions” which progress from small-scale tests of a few modules in low Earth orbit to a full production power satellite delivering 2 gigawatts to the electrical grid. He estimates a cost of around US$ 5 billion to the pilot plant demonstrator and 20 billion to the first full scale power satellite. This is not a small sum of money, but is comparable to the approximately US$ 26 billion cost of the Three Gorges Dam in China. Once power satellites start to come on line, each feeding power into the grid with no cost for fuel and modest maintenance expenses (comparable to those for a hydroelectric dam), the initial investment does not take long to be recovered. Further, the power satellite effort will bootstrap the infrastructure for routine, inexpensive access to space, and the power satellite modules can also be used in other space applications (for example, very high power communication satellites).

The most frequently raised objection when power satellites are mentioned is fear that they could be used as a “death ray”. This is, quite simply, nonsense. The microwave power beam arriving at the Earth's surface will have an intensity between 10–20% of summer sunlight, so a mirror reflecting the Sun would be a more effective death ray. Extensive tests were done to determine if the beam would affect birds, insects, and aircraft flying through it and all concluded there was no risk. A power satellite which beamed down its power with a laser could be weaponised, but nobody is proposing that, since it would have problems with atmospheric conditions and cost more than microwave transmission.

This book provides a comprehensive examination of the history of the concept of solar power from space, the various designs proposed over the years and studies conducted of them, and an in-depth presentation of the technology and economic rationale for the SPS-ALPHA system. It presents an energy future which is very different from that which most people envision, provides a way to bring the benefits of electrification to developing regions without any environmental consequences whatever, and ensure a secure supply of electricity for the foreseeable future.

This is a rewarding, but rather tedious read. Perhaps it's due to the author's 25 years at NASA, but the text is cluttered with acronyms—there are fourteen pages of them defined in a glossary at the end of the book—and busy charts, some of which are difficult to read as reproduced in the Kindle edition. Copy editing is so-so: I noted 28 errors, and I wasn't especially looking for them. The index in the Kindle edition lists page numbers in the print edition which are useless because the electronic edition does not contain page numbers.

Posted at 18:24 Permalink

Thursday, June 26, 2014

Reading List: The Death of Money

Rickards, James. The Death of Money. New York: Portfolio / Penguin, 2014. ISBN 978-1-591-84670-3.
In his 2011 book Currency Wars (November 2011), the author discusses what he sees as an inevitable conflict among fiat currencies for dominance in international trade as the dollar, debased as a result of profligate spending and assumption of debt by the government that issues it, is displaced as the world's preeminent trading and reserve currency. With all currencies backed by nothing more than promises made by those who issue them, the stage is set for a race to the bottom: one government weakens its currency to obtain short-term advantage in international trade, only to have its competitors devalue, setting off a chain of competitive devaluations which disrupt trade, cause investment to be deferred due to uncertainty, and destroy the savings of those holding the currencies in question. In 2011, Rickards wrote that it was still possible to avert an era of currency war, although that was not the way to bet. In this volume, three years later, he surveys the scene and concludes that we are now in the early stages of a collapse of the global monetary system, which will be replaced by something very different from the status quo, but whose details we cannot, at this time, confidently predict. Investors and companies involved in international commerce need to understand what is happening and take steps to protect themselves in the era of turbulence which is ahead.

We often speak of “globalisation” as if it were something new, emerging only in recent years, but in fact it is an ongoing trend which dates from the age of wooden ships and sail. Once ocean commerce became practical in the 18th century, comparative advantage caused production and processing of goods to be concentrated in locations where they could be done most efficiently, linked by the sea lanes. This commerce was enormously facilitated by a global currency—if trading partners all used their own currencies, a plantation owner in the West Indies shipping sugar to Great Britain might see his profit wiped out if the exchange rate between his currency and the British pound changed by the time the ship arrived and he was paid. From the dawn of global trade to the present there has been a global currency. Initially, it was the British pound, backed by gold in the vaults of the Bank of England. Even commerce between, say, Argentina and Italy, was usually denominated in pounds and cleared through banks in London. The impoverishment of Britain in World War I began a shift of the centre of financial power from London to New York, and after World War II the Bretton Woods conference established the U.S. dollar, backed by gold, as the world's reserve and trade currency. The world continued to have a global currency, but now it was issued in Washington, not London. (The communist bloc did not use dollars for trade within itself, but conducted its trade with nations outside the bloc in dollars.) In 1971, the U.S. suspended the convertibility of the dollar to gold, and ever since the dollar has been entirely a fiat currency, backed only by the confidence of those who hold it that they will be able to exchange it for goods in the future.

The international monetary system is now in a most unusual period. The dollar remains the nominal reserve and trade currency, but the fraction of reserves held and trade conducted in dollars continues to fall. All of the major currencies: the dollar, euro, yen, pound, yuan, rouble—are pure fiat currencies unbacked by any tangible asset, and valued only against one another in ever-shifting foreign exchange markets. Most of these currencies are issued by central banks of governments which have taken on vast amounts of debt which nobody in their right mind believes can ever be paid off, and is approaching levels at which even a modest rise in interest rates to historical mean levels would make the interest on the debt impossible to service. There is every reason for countries holding large reserves of dollars to be worried, but there isn't any other currency which looks substantially better as an alternative. The dollar is, essentially, the best horse in the glue factory.

The author argues that we are on the threshold of a collapse of the international monetary system, and that the outlines of what will replace it are not yet clear. The phrase “collapse of the international monetary system” sounds apocalyptic, but we're not talking about some kind of Mad Max societal cataclysm. As the author observes, the international monetary system collapsed three times in the last century: in 1914, 1939, and 1971, and life went on (albeit in the first two cases, with disastrous and sanguinary wars), and eventually the financial system was reconstructed. There were, in each case, winners and losers, and investors who failed to protect themselves against these turbulent changes paid dearly for their complacency.

In this book, the author surveys the evolving international financial scene. He comes to conclusions which may surprise observers from a variety of perspectives. He believes the Euro is here to stay, and that its advantages to Germany coupled with Germany's economic power will carry it through its current problems. Ultimately, the countries on the periphery will consider the Euro, whatever its costs to them in unemployment and austerity, better than the instability of their national currencies before joining the Eurozone. China is seen as the victim of its own success, with financial warlords skimming off the prosperity of its rapid growth, aided by an opaque and deeply corrupt political class. The developing world is increasingly forging bilateral agreements which bypass the dollar and trade in their own currencies.

What is an investor to do faced with such uncertainty? Well, that's far from clear. The one thing one shouldn't do is assume the present system will persist until you're ready to retire, and invest your retirement savings entirely on the assumption nothing will change. Fortunately, there are alternative investments (for example, gold and silver, farm land, fine art, funds investing in natural resources, and, yes, cash in a variety of currencies [to enable you to pick up bargains when other assets crater]) which will appreciate enormously when the monetary system collapses. You don't have to (and shouldn't) bet everything on a collapse: a relatively small hedge against it will protect you should it happen.

This is an extensively researched and deep investigation of the present state of the international monetary system. As the author notes, ever since all currencies were severed from gold in 1971 and began to float against one another, the complexity of the system has increased enormously. What were once fixed exchange rates, adjusted only when countries faced financial crisis, have been replaced by exchange rates which change in milliseconds, with a huge superstructure of futures, options, currency swaps, and other derivatives whose notional value dwarfs the actual currencies in circulation. This is an immensely fragile system which even a small perturbation can cause to collapse. Faced with a risk whose probability and consequences are impossible to quantify, the prudent investor takes steps to mitigate it. This book provides background for developing such a plan.

Posted at 23:44 Permalink

Sunday, June 22, 2014

Tom Swift and His Airship updated, EPUB added

All 25 of the public domain Tom Swift novels have been posted in the Tom Swift and His Pocket Library collection. I am now returning to the earlier novels, upgrading them to use the more modern typography of those I've done in the last few years. The third novel in the series, Tom Swift and His Airship, has now been updated. Several typographical errors in the original edition have been corrected, and Unicode text entities are used for special characters such as single and double quotes and dashes.

An EPUB edition of this novel is now available which may be downloaded to compatible reader devices; the details of how to do this differ from device to device—please consult the documentation for your reader for details.

For additional details about this novel, see the review I wrote when it was originally posted in 2005.

Posted at 14:02 Permalink

Monday, June 16, 2014

Floating Point Benchmark: Erlang Language Added

I have posted an update to my trigonometry-intense floating point benchmark which adds Erlang to the list of languages in which the benchmark is implemented. A new release of the benchmark collection including Erlang is now available for downloading.

The Erlang programming language was originally developed by the Swedish telecommunication equipment manufacturer Ericsson. Its name is simultaneously a reference to the unit of circuit load used in circuit-switched communication systems, the Danish engineer after whom the unit is named, and an abbreviation for “Ericsson Language”. While originally a proprietary Ericsson product for in-house use, in 1998 the language and software was released as an open source product and is now distributed by erlang.org.

Erlang is intended to facilitate the implementation of concurrent, scalable, distributed, and high-availability systems of the kinds needed to support large telecommunication networks. Concurrency, based upon a message-passing architecture, is built into the language at a low level, as is support for symmetric multiprocessing, allowing Erlang programs to easily exploit modern multi-core microprocessors. A general port architecture allows moving components of a system among physical hardware without reprogramming, and fault tolerance allows the detection of errors and restarting modules which have failed. It is possible to “hot swap” components in running systems without taking the entire system down for the update.

The language adopts the functional programming model, although it is not as strict in enforcing this paradigm as Haskell. The language is dynamically typed, does not use lazy evaluation, allows input/output within functions not specially marked as having side effects, and has ways a sneaky programmer can store global state or create side effects. While these may seem to be (indeed, they are) compromises with a strict reading of functional programming, Erlang is clearly a tool created by practical programmers intended to be used to build very large production systems which have to keep running no matter what. It is not an academic project made to prove a point. (But then Haskell is very pure, and yet that has not kept large systems from being built using it.)

One advantage of choosing Erlang when building a system which may need to grow at a vertiginous rate from its original implementation is that it's “been there; done that”. Companies such as WhatsApp (messaging service), Facebook (chat service), and Goldman Sachs (high-frequency trading) all use Erlang. You may not be dealing with the most philosophically pure functional language, but one which has earned its chops in the real world.

The relative performance of the various language implementations (with C taken as 1) is as follows. All language implementations of the benchmark listed below produced identical results to the last (11th) decimal place.

Language Relative
Time
Details
C 1 GCC 3.2.3 -O3, Linux
Visual Basic .NET 0.866 All optimisations, Windows XP
FORTRAN 1.008 GNU Fortran (g77) 3.2.3 -O3, Linux
Pascal 1.027
1.077
Free Pascal 2.2.0 -O3, Linux
GNU Pascal 2.1 (GCC 2.95.2) -O3, Linux
Java 1.121 Sun JDK 1.5.0_04-b05, Linux
Visual Basic 6 1.132 All optimisations, Windows XP
Haskell 1.223 GHC 7.4.1-O2 -funbox-strict-fields, Linux
Ada 1.401 GNAT/GCC 3.4.4 -O3, Linux
Go 1.481 Go version go1.1.1 linux/amd64, Linux
Simula 2.099 GNU Cim 5.1, GCC 4.8.1 -O2, Linux
Erlang 3.663
9.335
Erlang/OTP 17, emulator 6.0, HiPE [native, {hipe, [o3]}]
Byte code (BEAM), Linux
ALGOL 60 3.951 MARST 2.7, GCC 4.8.1 -O3, Linux
Lisp 7.41
19.8
GNU Common Lisp 2.6.7, Compiled, Linux
GNU Common Lisp 2.6.7, Interpreted
Smalltalk 7.59 GNU Smalltalk 2.3.5, Linux
Forth 9.92 Gforth 0.7.0, Linux
COBOL 12.5
46.3
Micro Focus Visual COBOL 2010, Windows 7
Fixed decimal instead of computational-2
Algol 68 15.2 Algol 68 Genie 2.4.1 -O3, Linux
Python 17.6 Python 2.3.3 -OO, Linux
Perl 23.6 Perl v5.8.0, Linux
Ruby 26.1 Ruby 1.8.3, Linux
JavaScript 27.6
39.1
46.9
Opera 8.0, Linux
Internet Explorer 6.0.2900, Windows XP
Mozilla Firefox 1.0.6, Linux
QBasic 148.3 MS-DOS QBasic 1.1, Windows XP Console

By default, Erlang compiles to a machine-independent byte code which is executed by the runtime system. The developers say this is typically about ten times slower than C compiled to native code for computationally intense numeric and text processing work. My test confirmed this, with the byte code compiled benchmark running 9.3 times slower than C. On some platforms, including the GNU/Linux x86_64 machine on which I ran the benchmark, Erlang supports HiPE (High Performance Erlang), which allows compilation to native machine code. Using this option and specifying the highest level of optimisation produces a program which runs just 3.7 times slower than C. While this may seem a substantial penalty, it's worth noting that telecommunication systems rarely do serious number crunching or text shuffling: they're all about database accesses and intercommunication, and what is paramount is reliability, scalability, and the ability to distribute the application across multiple hardware platforms. Erlang's strengths in these areas may outweigh its greater CPU usage for large-scale distributed systems.

Posted at 23:37 Permalink

Friday, June 13, 2014

Floating Point Benchmark: Simula Language Added

I have posted an update to my trigonometry-intense floating point benchmark which adds Simula to the list of languages in which the benchmark is implemented. A new release of the benchmark collection including Simula is now available for downloading.

Simula may be the most significant computer language of which you've never heard. In the 1960s, it introduced almost all of the essential concepts of object oriented programming: classes, inheritance, virtual procedures, and included facilities for discrete event simulation. Memory management includes dynamic storage allocation and garbage collection. When programming in Simula, one has the sense of using a computer language of the 1990s which somehow dropped into the 1960s, retaining some of the archaic syntax of that epoch. (What was it about academic language designers of the era that they did not appreciate the value of initialising variables and declaring symbolic constants? COBOL had both from inception.) In fact, although few programmers were aware of Simula, it was well known among the computer science community and language designers and was the direct inspiration for languages such as C++, Objective C, Smalltalk, and Java. Had it not been relegated to the niche of a “simulation language”, we might have been writing object oriented code since the early 1970s. So it goes.

The relative performance of the various language implementations (with C taken as 1) is as follows. All language implementations of the benchmark listed below produced identical results to the last (11th) decimal place.

Language Relative
Time
Details
C 1 GCC 3.2.3 -O3, Linux
Visual Basic .NET 0.866 All optimisations, Windows XP
FORTRAN 1.008 GNU Fortran (g77) 3.2.3 -O3, Linux
Pascal 1.027
1.077
Free Pascal 2.2.0 -O3, Linux
GNU Pascal 2.1 (GCC 2.95.2) -O3, Linux
Java 1.121 Sun JDK 1.5.0_04-b05, Linux
Visual Basic 6 1.132 All optimisations, Windows XP
Haskell 1.223 GHC 7.4.1-O2 -funbox-strict-fields, Linux
Ada 1.401 GNAT/GCC 3.4.4 -O3, Linux
Go 1.481 Go version go1.1.1 linux/amd64, Linux
Simula 2.099 GNU Cim 5.1, GCC 4.8.1 -O2, Linux
ALGOL 60 3.951 MARST 2.7, GCC 4.8.1 -O3, Linux
Lisp 7.41
19.8
GNU Common Lisp 2.6.7, Compiled, Linux
GNU Common Lisp 2.6.7, Interpreted
Smalltalk 7.59 GNU Smalltalk 2.3.5, Linux
Forth 9.92 Gforth 0.7.0, Linux
COBOL 12.5
46.3
Micro Focus Visual COBOL 2010, Windows 7
Fixed decimal instead of computational-2
Algol 68 15.2 Algol 68 Genie 2.4.1 -O3, Linux
Python 17.6 Python 2.3.3 -OO, Linux
Perl 23.6 Perl v5.8.0, Linux
Ruby 26.1 Ruby 1.8.3, Linux
JavaScript 27.6
39.1
46.9
Opera 8.0, Linux
Internet Explorer 6.0.2900, Windows XP
Mozilla Firefox 1.0.6, Linux
QBasic 148.3 MS-DOS QBasic 1.1, Windows XP Console

The Simula benchmark was developed and run under the GNU Cim 5.1 Simula to C translator. C code was compiled with GCC 4.8.1 with -O2 for the x86_64 architecture. There is no reason to believe a purpose-built optimising Simula compiler could not perform as well as a present-day C++ compiler.

Posted at 14:26 Permalink

Tuesday, June 10, 2014

Reading List: The Weed Agency

Geraghty, Jim. The Weed Agency. New York: Crown Forum, 2014. ISBN 978-0-7704-3652-0.
During the Carter administration, the peanut farmer become president, a man very well acquainted with weeds, created the Agency of Invasive Species (AIS) within the Department of Agriculture to cope with the menace. Well, not really—the agency which occupies centre stage in this farce is fictional but, as the author notes in the preface, the Federal Interagency Committee for the Management of Noxious and Exotic Weeds, the Aquatic Nuisance Species Task Force, the Federal Interagency Committee on Invasive Terrestrial Animals and Pathogens, and the National Invasive Species Council of which they are members along with a list of other agencies, all do exist. So while it may seem amusing that a bankrupt and over-extended government would have an agency devoted to weeds, in fact that real government has an entire portfolio of such agencies, along with, naturally, a council to co-ordinate their activities.

The AIS has a politically appointed director, but the agency had been run since inception by Administrative Director Adam Humphrey, career civil service, who is training his deputy, Jack Wilkins, new to the civil service after a frustrating low-level post in the Carter White House, in the ways of the permanent bureaucracy and how to deal with political appointees, members of congress, and rival agencies. Humphrey has an instinct for how to position the agency's mission as political winds shift over the decades: during the Reagan years as American agriculture's first line of defence against the threat of devastation by Soviet weeds, at the cutting edge of information technology revolutionising citizens' interaction with government in the Gingrich era, and essential to avert even more disastrous attacks on the nation after the terrorist attacks in 2001.

Humphrey and Wilkins are masters of the care and feeding of congressional allies, who are rewarded with agency facilities in their districts, and neutralising the occasional idealistic budget cutter who wishes to limit the growth of the agency's budget or, horror of horrors, abolish it.

We also see the agency through the eyes of three young women who arrived at the agency in 1993 suffused with optimism for “reinventing government” and “building a bridge to the twenty-first century”. While each of them—Lisa, hired in the communications office; Jamie, an event co-ordinator; and Ava, a technology systems analyst—were well aware that their positions in the federal bureaucracy were deep in the weeds, they believed they had the energy and ambition to excel and rise to positions where they would have the power to effect change for the better.

Then they began to actually work within the structure of the agency and realise what the civil service actually was. Thomas Sowell has remarked that the experience in his life which transformed him from being a leftist (actually, a Marxist) to a champion of free markets and individual liberty was working as a summer intern in 1960 in a federal agency. He says that after experiencing the civil service first-hand, he realised that whatever were the problems of society that concerned him, government bureaucracy was not the solution. Lisa, Jamie, and Ava all have similar experiences, and react in different ways. Ava decides she just can't take it any more and is tempted by a job in the middle of the dot com boom. Her experience is both entertaining and enlightening.

Even the most obscure federal agency has the power to mess up on a colossal scale and wind up on the front page of the Washington Post and the focus of a congressional inquest. So it was to be for the AIS, when an ill wind brought a threat to agriculture in the highly-visible districts of powerful members of congress. All the bureaucratic and political wiles of the agency had to be summoned to counter the threat and allow the agency to continue to do what such organisations do best: nothing.

Jim Geraghty is a veteran reporter, contributing editor, and blogger at National Review; his work has appeared in a long list of other publications. His reportage has always been characterised by a dry wit, but for a first foray into satire and farce, this is a masterful accomplishment. It is as funny as some of the best work of Christopher Buckley, and that's about as good as contemporary political humour gets. Geraghty's plot is not as zany as most of Buckley's, but it is more grounded in the political reality of Washington. One of the most effective devices in the book is to describe this or that absurdity and then add a footnote documenting that what you've just read actually exists, or that an outrageous statement uttered by a character was said on the record by a politician or bureaucrat.

Much of this novel reads like an American version of the British sitcom Yes Minister (Margaret Thatcher's favourite television programme), and although the author doesn't mention it in the author's note or acknowledgements, I suspect that the master civil servant's being named “Humphrey” is an homage to that series. Sharp-eyed readers will discover another oblique reference to Yes Minister in the entry for November 2012 in the final chapter.

Posted at 17:04 Permalink

Wednesday, June 4, 2014

Reading List: Tales From Our Near Future

Coppley, Jackson. Tales From Our Near Future. Seattle: CreateSpace, 2014. ISBN 978-1-4961-2851-5.
I am increasingly convinced that the 2020s will be a very interesting decade. As computing power continues its inexorable exponential growth (and there is no reason to believe this growth will abate, except in the aftermath of economic and/or societal collapse), more and more things which seemed absurd just a few years before will become commonplace—consider self-driving cars. This slim book (142 pages in the print edition) collects three unrelated stories set in this era. In each, the author envisions a “soft take-off” scenario rather than the sudden onset of a technological singularity which rapidly renders the world incomprehensible.

These are all “puzzle stories” in the tradition of Isaac Asimov's early short stories. You'll enjoy them best if you just immerse yourself in the world the characters inhabit, get to know them, and then discover what is really going on, which may not be at all what it appears on the surface. By the nature of puzzle stories, almost anything I say about them would be a spoiler, so I'll refrain from getting into details other than asking, “What would it be like to know everything?”, which is the premise of the first story, stated on its first page.

Two of the three stories contain explicit sexual scenes and are not suitable for younger readers. This book was recommended (scroll down a few paragraphs) by Jerry Pournelle.

Posted at 22:12 Permalink

Saturday, May 31, 2014

Reading List: Miss Leavitt's Stars

Johnson, George. Miss Leavitt's Stars. New York: W. W. Norton, 2005. ISBN 978-0-393-32856-1.
Henrietta Swan Leavitt was a computer. No, this is not a tale of artificial intelligence, but rather of the key discovery which allowed astronomers to grasp the enormity of the universe. In the late 19th century it became increasingly common for daughters of modestly prosperous families to attend college. Henrietta Leavitt's father was a Congregational church minister in Ohio whose income allowed him to send his daughter to Oberlin College in 1885. In 1888 she transferred to the Society for the Collegiate Instruction of Women (later Radcliffe College) in Cambridge Massachusetts where she earned a bachelor's degree in 1892. In her senior year, she took a course in astronomy which sparked a lifetime fascination with the stars. After graduation, she remained in Cambridge and the next year was volunteering at the Harvard College Observatory and was later put on salary.

The director of the observatory, Edward Pickering, realised that while at the time it was considered inappropriate for women to sit up all night operating a telescope, much of the work of astronomy consisted of tedious tasks such as measuring the position and brightness of stars on photographic plates, compiling catalogues, and performing analyses based upon their data. Pickering realised that there was a pool of college educated women (especially in the Boston area) who were unlikely to find work as scientists but who were perfectly capable of doing this office work so essential to the progress of astronomy. Further, they would work for a fraction of the salary of a professional astronomer and Pickering, a shrewd administrator as well as a scientist, reasoned he could boost the output of his observatory by a substantial factor within the available budget. So it was that Leavitt was hired to work full-time at the observatory with a job title of “computer” and a salary of US$ 0.25 per hour (she later got a raise to 0.30, which is comparable to the U.S. federal minimum wage in 2013).

There was no shortage of work for Leavitt and her fellow computers (nicknamed “Pickering's Harem”) to do. The major project underway at the observatory was the creation of a catalogue of the position, magnitude, and colour of all stars visible from the northern hemisphere to the limiting magnitude of the telescope available. This was done by exposing glass photographic plates in long time exposures while keeping the telescope precisely aimed at a given patch of the sky (although telescopes of era had “clock drives” which approximately tracked the apparent motion of the sky, imprecision in the mechanism required a human observer [all men!] to track a guide star through an eyepiece during the long exposure and manually keep the star centred on the crosshairs with fine adjustment controls). Since each plate covered only a small fraction of the sky, the work of surveying the entire hemisphere was long, tedious, and often frustrating, as a cloud might drift across the field of view and ruin the exposure.

But if the work at the telescope was seemingly endless, analysing the plates it produced was far more arduous. Each plate would contain images of thousands of stars, the position and brightness (inferred from the size of the star's image on the plate) of which had to be measured and recorded. Further, plates taken through different colour filters had to be compared, with the difference in brightness used to estimate each star's colour and hence temperature. And if that weren't enough, plates taken of the same field at different times were compared to discover stars whose brightness varied from one time to another.

There are two kinds of these variable stars. The first consist of multiple star systems where one star periodically eclipses another, with the simplest case being an “eclipsing binary”: two stars which eclipse one another. Intrinsic variable stars are individual stars whose brightness varies over time, often accompanied by a change in the star's colour. Both kinds of variable stars were important to astronomers, with intrinsic variables offering clues to astrophysics and the evolution of stars.

Leavitt was called a “variable star ‘fiend’ ” by a Princeton astronomer in a letter to Pickering, commenting on the flood of discoveries she published in the Harvard Observatory's journals. For the ambitious Pickering, one hemisphere did not suffice. He arranged for an observatory to be established in Arequipa Peru, which would allow stars visible only from the southern hemisphere to be observed and catalogued. A 24 inch telescope and its accessories were shipped around Cape Horn from Boston, and before long the southern sky was being photographed, with the plates sent to Harvard for measurement and cataloguing. When the news had come to Harvard, it was the computers, not the astronomers, who scrutinised them to see what had been discovered.

Now, star catalogues of the kind Pickering was preparing, however useful they were to astronomers, were essentially two-dimensional. They give the position of the star on the sky, but no information about how distant it is from the solar system. Indeed, only the distances of few dozen of the very closest stars had been measured by the end of the 19th century by stellar parallax, but for all the rest of the stars their distances were a complete mystery and consequently also the scale of the visible universe was utterly unknown. Because the intrinsic brightness of stars varies over an enormous range (some stars are a million times more luminous than the Sun, which is itself ten thousand times brighter than some dwarf stars), a star of a given magnitude (brightness as observed from Earth) may either be a nearby star of modest brightness or an brilliant supergiant star far away.

One of the first intrinsic variable stars to be studied in depth was Delta Cephei, found to be variable in 1784. It is the prototype Cepheid variable, many more of which were discovered by Leavitt. Cepheids are old, massive stars, which have burnt up most of their hydrogen fuel and vary with a characteristic sawtooth-shaped light curve with periods ranging from days to months. In Leavitt's time the mechanism for this variability was unknown, but it is now understood to be due to oscillations in the star's radius as the ionisation state of helium in the star's outer layer cycles between opaque and transparent states, repeatedly trapping the star's energy and causing it to expand, then releasing it, making the star contract.

When examining the plates from the telescope in Peru, Leavitt was fascinated by the Magellanic clouds, which look like little bits of the Milky Way which broke off and migrated to distant parts of the sky (we now know them to be dwarf galaxies which may be in orbit around the Milky Way). Leavitt became fascinated by the clouds, and by assiduous searches on multiple plates showing them, eventually published in 1908 a list of 1,777 variable stars she had discovered in them. While astronomers did not know the exact nature of the Magellanic clouds, they were confident of two things: they were very distant (since stars within them of spectral types which are inherently bright were much dimmer than those seen elsewhere in the sky), and all of the stars in them were about the same distance from the solar system, since it was evident the clouds must be gravitationally bound to persist over time.

Leavitt's 1908 paper contained one of the greatest understatements in all of the scientific literature: “It is worthy of notice that the brightest variables have the longer periods.” She had discovered a measuring stick for the universe. In examining Cepheids among the variables in her list, she observed that there was a simple linear relationship between the period of pulsation and how bright the star appeared. But since all of the Cepheids in the clouds must be at about the same distance, that meant their absolute brightness could be determined from their periods. This made the Cepheids “standard candles” which could be used to chart the galaxy and beyond. Since they are so bright, they could be observed at great distances.

To take a simple case, suppose you observe a Cepheid in a star cluster, and another in a different part of the sky. The two have about the same period of oscillation, but the one in the cluster has one quarter the brightness at Earth of the other. Since the periods are the same, you know the inherent luminosities of the two stars are alike, so according to the inverse-square law the cluster must be twice as distant as the other star. If the Cepheids have different periods, the relationship Leavitt discovered can be used to compute the relative difference in their luminosity, again allowing their distances to be compared.

This method provides a relative distance scale to as far as you can identify and measure the periods of Cepheids, but it does not give their absolute distances. However, if you can measure the distance to any single Cepheid by other means, you can now compute the absolute distance to all of them. Not without controversy, this was accomplished, and for the first time astronomers beheld just how enormous the galaxy was, that the solar system was far from its centre, and that the mysterious “spiral neublæ” many had argued were clouds of gas or solar systems in formation were entire other galaxies among a myriad in a universe of breathtaking size. This was the work of others, but all of it was founded on Leavitt's discovery.

Henrietta Leavitt would not live to see all of these consequences of her work. She died of cancer in 1921 at the age of 53, while the debate was still raging over whether the Milky Way was the entire universe or just one of a vast number of “island universes”. Both sides in this controversy based their arguments in large part upon her work.

She was paid just ten cents more per hour than a cotton mill worker, and never given the title “astronomer”, never made an observation with a telescope, and yet working endless hours at her desk made one of the most profound discoveries of 20th century astronomy, one which is still being refined by precision measurements from the Earth and space today. While the public hardly ever heard her name, she published her work in professional journals and eminent astronomers were well aware of its significance and her part in creating it. A 66 kilometre crater on the Moon bears her name (the one named after that Armstrong fellow is just 4.6 km, albeit on the near side).

This short book is only in part a biography of Leavitt. Apart from her work, she left few traces of her life. It is as much a story of how astronomy was done in her days and how she and others made the giant leap in establishing what we now call the cosmic distance ladder. This was a complicated process, with many missteps and controversies along the way, which are well described here.

In the Kindle edition (as viewed on the iPad) the quotations at the start of each chapter are mis-formatted so each character appears on its own line. The index contains references to page numbers in the print edition and is useless because the Kindle edition contains no page numbers.

Posted at 21:54 Permalink