Thursday, April 7, 2011

Numerical Derivatives Comparison of Scheme and Fortran

This short note compares numerical derivative performance for Scheme and Fortran. In my profession, I compute numerical derivatives daily. Often, the numerical derivatives are part of a simulation routine, so computational time is critically important. The apparent gold standard for numerical performance is Fortran. It is said that if you have a numerical task to solve, Fortran will do the job and keep you in the top 80% tier, if not the top spot, of performance. On the other end of the spectrum, Scheme is known to do the job with 20% of the effort but with no guarantees for performance (some might say "guaranteed to be slow", but that's cruel).

Well, here's a case where Scheme is way faster than Fortran. The example comes from computational fluid dynamics. Given a function u(x), let a 2nd function be defined as t(x)=du/dx and a 3rd function be defined as f(x)=dt/dx. The function u(x) is defined as x*x + x + 1. I've normalized the speed with ifort Fortran's time (greater than 1.0 is faster than Intel's "ifort" Fortran).

  • stalin with gcc: 0.065
  • stalin with icc: 2.2 
  • ifort: 1
  • chicken scheme with gcc:  0.017
As a comparison, I defined the function u(x)=sin(x) for a comparison with a library sin(x) function. The results are as I would expect with multiple calls to a library routine.
  • stalin with gcc: 0.70
  • stalin with icc: 1.1
  • ifort: 1

Performance with the Stalin ("Stalin brutally optimizes") scheme compiler with Intel's C compiler is more than twice as fast as Intel's Fortran compiler. I've heard rumors of this issue, but this is the first time I've done it myself.

Is anyone interested in the codes? Let me know.

Update:
Hand coding the routine with Fortran (rather than passing a function) gives an order of magnitude improvement. Hand coding the Scheme routine decreased performance by about 25%. Changing from (set!) to recursion increased Scheme's performance by about 10%.

Conclusion:
My best Fortran version is about 3 times faster than my best Scheme version.

Thursday, March 17, 2011

Chicken Scheme

Hello Chicken Scheme and Goodbye Python. More later...

The Chicken Scheme egg for qt-light on Windows is malfunctioning. You will need to copy the proper .dll to qt-light.so. I can confirm that qt-light is functional on Windows XP with Chicken Scheme 4.5.0. Contact me if more information is needed.

Monday, March 14, 2011

Cross of Paper Redux

“We could not maintain the gold standard nor the silver standard. We could not maintain the copper standard, and now we cannot even maintain the zinc standard." Ron Paul referring to U.S. pennies.

This is an update of last year's Cross of Paper note. Bold emphasis is mine.

WASHINGTON - The United States Mint today announced that it is requesting public comment from all interested persons on factors to be considered in conducting research for alternative metallic coinage materials for the production of all circulating coins.
...
The United States Mint is not soliciting suggestions or recommendations on specific metallic coinage materials, and any such suggestions or recommendations will not be considered at this time.  The United States Mint seeks public comment only on the factors to be considered in the research and evaluation of potential new metallic coinage materials.
The recently enacted Coin Modernization, Oversight, and Continuity Act of 2010 (Public Law 111-302) gives the United States Mint research and development authority to conduct studies for alternative metallic coinage materials.  Additionally, the new law requires the United States Mint to consider certain factors in the conduct of research, development, and solicitation of input or work in conjunction with Federal and nonfederal entities, including factors that the public believes the United States Mint should consider to be appropriate and in the public interest.
See the official document here. The language is clear. The Mint is "not soliciting suggestions ... on specific metallic coinage materials". So, don't bother asking for actual honest money with gold, silver, nickel and copper.

One specific currently-minted US coin is the target: 5c nickels. See here.

Conclusion:
The Federal Reserve working with the US Mint is debasing US money: paper and coins alike. Certain current US coins containing semi-valuable metal (5c pieces) will change composition soon. These legacy coins will picked out of circulation.

Saturday, March 12, 2011

ObamaCare's Hidden Tax on Health Savings Accounts (HSA)

ObamaCare stealthily increases taxes on HSA (Heath Savings Accounts). The HSA requires a high-deductible health insurance plan. Here's the IRS Guideline:
The Affordable Care Act, enacted in March, established a new uniform standard that, effective Jan. 1, 2011, applies to FSAs and health reimbursement arrangements (HRAs). Under the new standard, the cost of an over-the-counter medicine or drug cannot be reimbursed from the account unless a prescription is obtained.
The previous advantage was that health products were paid with pre-tax dollars. Thus, ObamaCare increased taxes on non-prescription items by about 20%. But wait, there's more!

This guideline also taxes doctors. From now on, doctors will be asked to provide prescriptions for over-the-counter medicine. So an (economically flawed and anti-liberty  by the way) effort to control health-care costs now increases either taxes or the mindless duties of doctors.

Who benefits? Let's follow the money to find out:
  1. Federal Revenue increases.
  2. Subsidizes doctors writing "over-the-counter" prescriptions. But why would a sane person pay for a doctor's office visit just to save 20% on otc products? "Doc, write me a prescription for aspirin... and band-aids."
  3. HSA accounts now draw down more slowly, so the HSA custodians have the benefit of a larger "float" balance.  Given that HSA custodians are typically large banks, this could be a carefully planned but hidden back-room deal for the banks.
Conclusion:
ObamaCare distorts the market. Get ready for unintended consequences.

Monday, March 7, 2011

Two wings of the Republican party: Fascism versus Libertarian

Here the difference between the two wings of the Republican party: Corporatist versus Libertarian.



That's right folks: "Drug test every high school student in America." Crazy socialists.

Wednesday, February 9, 2011

Mini-review of WHY AMERICAN HISTORY IS NOT WHAT THEY SAY: AN INTRODUCTION TO REVISIONISM by Jeff Riggenbach

Do you know which U.S. President said this?
I accuse the present Administration of being the greatest spending
Administration in peace time in all American history—one which
piled bureau on bureau, commission on commission, and has failed
to anticipate the dire needs or reduced earning power of the people.
Bureaus and bureaucrats have been retained at the expense of the
taxpayer. . . . We are spending altogether too much money for govern-
ment services which are neither practical nor necessary. In addition to
this, we are attempting too many functions and we need a simplifica-
tion of what the Federal government is giving to the people.

After reading WHY AMERICAN HISTORY IS NOT WHAT THEY SAY: AN INTRODUCTION TO REVISIONISM by Jeff Riggenbach, I know who said it and, more importantly, why he said it. It's not who you might expect. One hint: He ended up following his despised predecessor’s policies rather than the above policy.

This is a new favorite and is now on my list of recommended books. Get a pdf copy here or in physical form here.

Answer below: