views:

391

answers:

5

Might anyone be famiiar with tricks and techniques to coerce the set of valid floating point numbers to be a group under a multiplication based operation?

That is, given any two floating point numbers ("double a,b"), what sequence of operations, including multiply, will turn this into another valid floating point number? (A valid floating point number is anything 1-normalized, excluding NaN, denormals and -0.0).

To put this rough code:

double a = drand();
while ( forever ) 
{
    double b = drand();
    a = GROUP_OPERATION(a,b); 
    //invariant - a is a valid floating point number
}

Just multiply by itself doesn't work, because of NaNs. Ideally this would be a straight-line approach (avoiding "if above X, divide by Y" formulations).

If this can't work for all valid floating point numbers, is there a subset for which such an operation is available?

(The model I'm looking for is akin to integer multiplication in C - no matter what two integers get multiplied together, you always get an integer back).

+1  A: 
Charlie Martin
Since I start with floating point (instead of "real" numbers), can't I avoid any of the 0.1 representational issues?The "x = x*x" problem is why additional operations are needed to keep the result in the valid range.
A: 

Floating point numbers are backed by bits. That means that you can use the integer arithmetic on the integer representation of your floating point values and you will get a group.

Not sure this is very usefull though.

/* You have to find the integer type whose size correspond to your double */
typedef double float_t;
typedef long long int_t;

float_t group_operation(float_t a, float_t b)
{
  int_t *ia, *ib, c;
  assert(sizeof(float_t) == sizeof(int_t));
  ia = &a;
  ib = &b;
  c = *ia * *ib;
  return (float_t)c;
}
kmkaplan
A: 

If group operation is multiplication then if n is the highest bit, then r1=1/power(2,n-1) is the least decimal that you can operate and the set [r1,2 * r1,4 * r1,8 * r1...1] union [-r1, -2 * r1, -4 * r1,....-1] union [0] will be the group that you are expecting. For integer [1,0,-1] is the group.

if Group operation can be any thing else, then to form n set of valid groups,

A(r)=cos(2*Pi*r/n) from r=0 to n-1

and group operation is

COS(COSINV(A1)+COSINV(A2))

I don't know whether you want this.....

or if you want INFINITY set as a valid group then

simple answer : GROUP OPERATION = AVG(A1,A2) = (A1+A2)/2

or some functions exists F which has FINV as it's inverse and then FINV(F(A1)+F(A2)/2) Example of F is Log, inverse, square etc ..

 double a = drand();
while ( forever ) 
{
    double b = drand();
    a = (a+b)/2
  //invariant - a is a valid floating point number
}

or if you want INFINITY set of DIGITAL format as a valid group then Let L be the lowest float number and H be highest float number

then GROUP OPERATION = AVG(A1,A2, L, H) = (A1+A2+L+H)/4

this operation will always be within L & H for all Positive numbers.

You can take L as four times the lowest decimal number and H as the (highest decimal number /4) for practical purpose.

double l = (0.0000000000000000000000000//1) * 4
double h = (0xFFFFFFFFFFFFFFFFFFFFFF///F) / 4
double a = abs(drand()) / 4;

while ( forever ) 
{
    double b = abs(drand()) / 4;
    a = (a+b+l+h)/4
//invariant - a is a valid floating point number
}

this has a subset of all possitive float number / 4.

lakshmanaraj
+2  A: 

(The model I'm looking for is akin to integer multiplication in C - no matter what two integers get multiplied together, you always get an integer back).

Integers modulo 2^N do not form a group - what integer multiplied by 2 gives 1? For integers to be a group under multiplication, you have to be modulo a prime number. (eg Z mod 7, 2*4 = 1, so 2 and 4 are each other's inverses)

For floating point values, simple multiplication or addition saturates to +/- Infinity, and there are no values which are the inverses of infinity, so either the set is not closed, or it lacks invertibility.

If on the other hand you want something similar to integer multiplication modulo a power of 2, then multiplication will do - there are elements without an inverse, so it's not a group, but it is closed - you always get a floating point value back. For subsets of floats which are a true group, see lakshmanaraj's answer.

Pete Kirkham
A: 

The integers don't form a group under multiplication -- 0 doesn't have an inverse.