Archive

Posts Tagged ‘testing’

Variations in the literal representation of Pi

March 12th, 2010 (16 hours ago) 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 FireStatscheapest prices for viagra

best price cialis

cialis generic

cheap online levitra

buy 5 mg cialis

best viagra

cialis usa

generic propecia cheap

cialis price in canada

buy pfizer viagra online

canadian pharmacy cialis

canada online pharmacy propecia

low price cialis

cialis generic 100 mg

cost of propecia

cialis samples in canada

buy prescription propecia

is pfizer viagra available in india

canada levitra

order propecia pill

cialis quick shipment

levitra lowest price

cialisis in canada

cialis samples

buy cheapest propecia

cialis prescription

cheepest cialis

get viagra fast

buy viagra in canada

cheap cialis

generic viagra propecia

buy viagra on line

cialis 5 mg italia

buy propecia on line

generic levitra pill

buy cheap propecia

generic viagra online

cialis refractory

cheap propecia no prescription

cialis 50 mg

canada cheap propecia

for sale levitra

generic viagra from china

canadian pharmacy viagra

buy cialis without prescription

cheap viagra generic

best price for propecia

cialis brand only

cialis fast delivery

cialis by mail

buy cialis fedex shipping

buy viagra online canada

best online levitra

healthcare canadian pharmacy

cialis by mail

canadian viagra 50mg

discount us propecia

about cialis

bio viagra herbal

cheap levitra

cialis professional no prescription

cialis 5 mg

buy real viagra online

cialis 100 mg generic

buy generic levitra online

lowest price propecia best

cialis discount prices

buy propecia online pharmacy

no prescription viagra

cialis daily dosage pharmacy

lowest price for levitra

cheap viagra on line

mail online order propecia

online order propecia

buying viagra in canada

buy levitra low price

how much does cialis cost

buy prescription propecia

buy cheapest cialis

canadian levitra

canadian healthcare

buying online propecia

how much to buy viagra in pounds

best way to take cialis

cialis daily price

buy cialis cannada

cialis by mail

how to get cialis in canada

online propecia cheap

buying cialis next day delivery

cialis 5 mg italia

generic levitra canada

cialis low price

cialis angioplasty

natural viagra

brand name cialis

levitra canadian pharmacy

online pharmacy propecia sale

about cialis

canadian pharmacy cialis

cialis order

cialis kanada

best price for propecia online

cialis alternitives

daily cialis

buy propecia pills

online propecia sales

mail order levitra

buy discount viagra

best price cialis

buy cialis without a prescription

buy propecia online without prescription

low cost viagra

brand viagra over the net

canadian viagra india

generic cialis sale

order propecia now

cialis canada online pharmacy

cheap price propecia

buy cialis without a prescription

cialis buy overnight

cialis canada

healthcare of canada pharmacy

cialis daily

buy cialis in canada

lowest propecia 1 mg

generic viagra made in usa

buy propecia generic

gele viagra

cialis usa

buy viagra mexico

cheap online propecia

order viagra or levitra

canadian levitra

5 mg cialis canada

cialis soft canada

buy pfizer viagra in canada

levitra low price

cialis canadian cost

brand name cialis overnight

cialis en mexico

cialis next day

cialis 20 mg

cheapest propecia sale uk

canadian generic viagra online

buy levitra online from canada

best price levitra

lowest cost levitra

generic cialis india

buy levitra overnight

buy viagra germany canadian meds

get cialis online

cialis arterial fibrillation

buy generic levitra

cialis price

low cost canadian viagra

cheap viagra online

buy branded viagra online

buy propecia in canada

canada propecia prescription

cialis headaches

order propecia

generic propecia canada

online viagra

cialis for women

canadian healthcare viagra

cialis iop

generic cialis next day delivery

buying generic cialis mexico rx

buy levitra lowest prices

discount brand name cialis

buy cialis online without prescription

buying cialis

cialis for woman

is pfizer viagra available in india

buy propecia cheap

best levitra price

best cialis price

buy generic viagra india rx

cialis en mexico

cialis professional

canada online pharmacy levitra

buy levitra american pharmacy

buy cialis usa

buy viagra on line

best deal for propecia

cheapest propecia online

natural viagra

next day viagra

buy xenical propecia

cialis kanada

buy cialis in usa

cialis india

buying viagra in canada

mail order propecia

cialis tablets vs viagra

canadian healthcare cialis

diuretics and viagra

canada viagra generic

canadian generic cialis

cheap canadian viagra

cheap cialis soft

cialis levitra

canadian viagra

cialis

cheapest online propecia

female viagra pills

low price propecia

indian cialis canada

buy now online propecia

canadian pharmacy discount code viagra

original brand cialis

brand viagra without prescription buy

cheapest propecia online

buy propecia no prescription

bestellen levitra

best levitra prices

cialis trazodone

discount cialis levitra viagra

cialis brand name

levitra cheapest

cialis next day

get viagra

original levitra

buy propecia without prescription

cialis c 50

generic viagra india

cialis and women

cialis and women

canadian generic viagra online

buy cialis next day delivery

canada online pharmacy propecia

levitra cost

online order viagra overnight delivery

cheap viagra on line

get propecia prescription

cheapest viagra usa

cialis express delivery

buy can from i propecia who

female viagra

online levitra us

buy levitra us

order cheapest propecia online

cialis online without prescription

buy pfizer viagra

levitra price

cialis alternative

levitra sex pill

cialis price

best way to take cialis