Archive

Posts Tagged ‘testing’

Variations in the literal representation of Pi

March 12th, 2010 Derek-Jones No comments

The numbers system I am developing attempts to match numeric literals contained in a file against a database of interesting numbers. One of the things I did to quickly build a reasonably sized database of reliable values was to extract numeric literals from a few well known programs that I thought I could trust.

R is a widely used statistical package and Maxima is a computer algebra system with a long history. Both contain a great deal of functionality and are actively maintained.

To my surprise the source code of both packages contain a large variety of different literal values for pi, or to be exact the number of digits contained in the literals varied by more than I expected. In the following table the value to the left of the pi representation is the number of occurrences; values listed in increasing literal order:

     Maxima                              R
   2 3.14159
                                      14 3.141592
   1 3.1415926
   1 3.14159265                        2 3.14159265
   3 3.1415926535
   4 3.14159265358979
  14 3.141592653589793
   3 3.1415926535897932385             3 3.1415926535897932385
   9 3.14159265358979324
                                       1 3.14159265359
                                       1 3.1415927
                                       1 3.141593

The comments in the Maxima source led me to believe that some thought had gone into ensuring that the numerical routines were robust. Over 3/4 of the literal representations of pi have a precision comparable to at least that of 64-bit floating-point (I’m assuming an IEEE 754 representation in this post).

In the R source approximately 2/3 of the literal representations of pi have a precision comparable to that of 32-bit floating-point.

Closer examination of the source suggests one reason for this difference. Both packages make heavy use of existing code (translated from Fortran to Lisp for Maxima and from Fortran to C for R); using existing code makes good sense and because of its use in scientific and engineering applications many numerical libraries have been written in Fortran. Maxima has adapted the slatec library, whereas the R developers have used a variety of different libraries (e.g., specfun).

How important is variation in the representation of Pi?

  • A calculation based on a literal that is only accurate to 32-bits is likely to be limited to that level of accuracy (unless errors cancel out somewhere).
  • Inconsistencies in the value used to represent Pi are a source of error. These inconsistencies may be implicit, for instance literals used to denote a value derived from pi such as pi^0.5 often seem to be be based on more precise values of Pi than appear in the code.

The obvious solution to this representation issue of creating a file containing definitions of all of the frequently used literal values has possible drawbacks. For instance, numerical accuracy is a strange beast and increasing the precision of one literal without doing the same for other literals appearing in a calculation can sometimes reduce the accuracy of the final result.

Pulling together existing libraries to build a package is often very cost effective, but numerical accuracy is a slippery beast and this inconsistent usage of literals suggests that developers from these two communities have not addressed the system level consequences of software reuse.

Distribution of numeric values (additive)

December 16th, 2008 Derek-Jones No comments

Developers and testers rarely put any thought into working out the likely distribution of numeric values (final or intermediate) computed during the execution of the code they write.

The likely value of a variable is useful to know in a number of situations, including optimizing code (should it prove to be necessary) for the common case and testing (what distribution of input values are needed to be confident that all paths through a program are exercised?)

The answer for the ’simple’ distributions is actually more complicated to work with than the more ‘complicated’ distributions. For instance, the sum of two independent values having a normal distributions is a normal distribution and the sum of two Poisson distributions is also a Poisson distribution.

What if the values are uniformly distributed? If two independent, randomly chosen, uniformly distributed, variables, are added what is the distribution of the result? For instance, if the values of X and Y are independent of each other and take on any value between 0 and 9, with equal likelihood, what is the most (and least) likely value of X+Y?

Warning: Information spoilers follow.

You are probably thinking that the result will also be uniformly distributed and indeed it would be if the range of values taken by X and Y did not overlap. When the possible range of values overlap exactly the answer is the triangular distribution, with the mostly likely result being 9 and the least likely results being 0 and 18.

The variance of the actual result distribution is approximately six times smaller than the original distribution, meaning that the common cases occupy a much narrower value range. This value range ‘narrowing’ goes someway towards helping to explain the surprising discovery that during program execution a small set of (integer and floating) values often occur with such regularity that it might be worth cpu arithmetic units remembering previous operands and their results (i.e., to save time by returning the result rather than recalculating it).

FireStats icon Powered by FireStatsbuy cheap propecia

cheap levitra online

best way to use cialis

cheapest overnight cialis

how much cialis

buy cialis usa

online pharmacy propecia

cialis pfizer

best levitra price

canadian viagra 50mg

cheapest prices on viagra

buy branded viagra online

cheap propecia order online

buying viagra with no prescription

cheap viagra pills

buying propecia online

cheap propecia uk

buy cialis without a prescription

cheap cialis soft

canadian pharmacy viagra

buy cheap levitra online

buying viagra in the us

cheap levitra uk

buy cialis online uk

cheap propecia 5mg

canada viagra pharmacies scam

cialis brand name

buy real cialis

buy daily cialis

levitra viagra online

generic cialis sale

cheap cialis from india

can i order viagra from the chemist

cialis iop

best propecia prices

cialis on women

lowest price propecia best

canada viagra generic

healthcare of canada pharmacy

low price propecia

generic viagra made in usa

buying viagra with no prescription

cialis canadian cost

online viagra

canada levitra

buy prescription propecia without

cheap levitra online us

levitra online order

buy mg propecia

buy propecia in the uk

mexico viagra

cialis brand name

cialis from canada

cheap canadian viagra

buy propecia without prescription

growth hair propecia

brand viagra over the net

buy levitra online viagra

buy cialis canada

cialis women

buy propecia pills

buy cheapest propecia

canada online pharmacy propecia

buy cialis in canada

brand name cialis overnight

cheap viagra or cialis

levitra cheap canadian pharmacy

buy levitra overnight

cialis professional no prescription

canadain viagra india

ordering viagra overnight delivery

brand cialis for sale

discount generic propecia

buying cialis in canada

combine cialis and levitra

buy cheap generic propecia

canadian viagra india

generic propecia canada

gel viagra

buying viagra in canada

50 mg cialis

buy propecia without a prescription

buy propecia online pharmacy

generic propecia for sale

buy levitra online no prescription

for sale levitra

cialis cheap

cialis and women

buy cheapest cialis

discount levitra online viagra

discount brand name cialis

buy cialis

next day delivery cialis

cialis 50 mg dose

cialis uk

buy levitra low price

discount propecia propecia

best levitra prices

cialis samples in canada

buy levitra uk

buy propecia prescriptions online

female viagra

cialis no prescription

buy cialis without prescription

discount cialis levitra viagra

canada propecia prescription

buy pfizer viagra online

buy viagra pills

cost of cialis

buy viagra on line

levitra low price

about cialis

buy viagra germany canadian meds

cialis on sale

buy prescription propecia

online pharmacy propecia sale

cialis canada illegal buy

cialis cost

best prices for propecia

levitra online

cialis 5 mg buy

cialis medication

order propecia propecia

generic levitra canada

canada levitra

cialis tablets

cheapest online propecia

mail order propecia

order cheap levitra

canadian viagra india

cialis overnight delivery

canadian drugs propecia

buy propecia online from usa pharmacy

dose cialis

canada cheap propecia

generic cialis canada

levitra tablet

buy cialis

buy levitra online from canada

buy cheap levitra

cialis professional 100 mg

levitra sex pill

buy pfizer viagra in canada

levitra buying

cialis canadian

canadian viagra 50mg

cialis canada

cialis cheap us pharmacy

cialis 50 mg

once daily cialis

discount real viagra

canadian pharmacy discount code viagra

buying viagra without prescription

cialis india

cheapest propecia pharmacy online

buy viagra online cheap us

brand viagra

buy pfizer viagra in canada

overnight delivery cialis

cialis soft canada

generic propecia alternative

buy propecia canada

how you get pfizer viagra

canadian healthcare cialis

generic propecia effective

cialis discounts

buy levitra by mail

levitra without prescription

cialis samples

bying viagra online cheap us

buy prescription propecia without

levitra cheap

canada online pharmacy levitra

how to get cialis

cialis india

cialis alternatives

generic cialis next day shipping

lowest propecia 1 mg

chip cialis

buy fast propecia

cialis canadian

low price levitra

cialis arterial fibrillation

cialis generic 100 mg

cheap order prescription propecia

buy cheapest cialis

5 mg cialis

cheap viagra canada or india

generic cialis in india

cheapest viagra usa

buy viagra without prescription

best online generic levitra

best doses for propecia

cialis 20 mg

buying cialis

cheap levitra prescription

online ordering propecia

buy propecia online without prescription

bying viagra online cheap us

levitra prescription

cialis for women

cheap propecia no prescription

buying real viagra without prescription

online propecia sales

cheap propecia canada

buy propecia where

buy viagra without prescription

buy cheap generic propecia

non pescription cialis

cheapest prices on propecia

getting cialis from canada

buy generic cialis

buy levitra lowest prices

canadian propecia rx

buy cialis online

cialis cost canada

cialis buy

buy levitra uk

discount cialis india

buy 5 mg cialis

how to get cialis in canada

buy cheap online propecia

genuine cialis pills

online pharmacy propecia viagra

levitra online overnight delivery

buy now propecia

herbal alternative to cialis

best price propecia

buy viagra

cheap levitra online

buy propecia online usa

cheap levitra without prescription

buy dosages levitra

canadian healthcare viagra

canada viagra generic

cialis soft tablets

cialis canadian pharmacy

how can i get some cialis

lowest cost levitra

buy fast propecia

cialis prescription

cheap viagra generic

canada meds viagra

cialis headaches

cialis once daily

brand cialis

best price for propecia

order propecia pill

beta blockers and viagra

cheapest prices for viagra