Re: Converting decimal number to carpenter's fractions

new topic     » goto parent     » topic index » view thread      » older message » newer message

Derek,

In answer to your questions:

There is no reasoning from {U,0,base} to {U,N,base}. So let me repeat myself ... \\ 
when the numerator is zero ... the value of the denominator is not really required; \\ 
it could be anything, so I may as well return something that could be useful.  
Useful to the caller, that is. To always return {U, 0, 1} when there is no  
fractional part is perfectly fine, except that its a waste of information bandwidth.  
This is not a mathematics environment; the function is trying to be useful to the  
caller by communicating information that may be gainfully employed by the application. 
problem: compare for equality:  
   {0, 0, 1, -1} {0, 0, 64, -1} {0, 0, 64, 1} 
   they all equal zero yet they are all different. 
 
waste of bandwidth: 
   another view on is: not providing misleading or spurious data. 
Bill 
 
And as a consequence of that you get {U, 1, 64} = {U, 2, 128} = ... 
And (as stated) GCD(0,64) = 64. Normalised {U, 0, 64} = [U, 0, 1}. 
 
Comparing sizes you will see normalisation is a GOOD IDEA. 
Im a bit confused by this. You seem to be suggesting that normalization is the  
process of presenting a fraction such that the numerator and divisor are the  
smallest integers possible to represent the value. And that such normalization is  
useful for comparison of values. If Ive got this wrong, please improve my  
understanding. 
OK: 
 
1. 72/99 * 63/87 * 255/2436 is going to produce a rather large fraction unless  
   normalised.  
 
2 there are an infinite number of unnormalised representations of 1/2 
  ... -1/-2,1/2 ... 
  comparing a normalised fraction for equality is 
  a/b = c/d if a=c and b=c 
  comparing an unnormalised fraction is 
  a/b = c/d if a*d = c*b 
  the first is the less expensive operation (and particularly so for people) 
  255/2436 = 85/812? 
If this is so, I beg to differ. 
 
Using this function 72/99 normalizes to {0,8,11,1} and 77/99 normalizes to {0,7,9,1}.  
But if we did a comparison of these normal forms, we find that 77/99 is less than 72/99! 
 
A = carp(72/99, 1, 99)  --> {0,8,11,1}  
B = carp(77/99, 1, 99)  --> {0,7,9,1}  
compare(A,B) --> 1  

Well yes comparing them as sequences is silly.

whereas some better ways to compare them is ... 
 
A = carp(72/99, 1, 99)  --> {0,8,11,1}  
B = carp(77/99, 1, 99)  --> {0,7,9,1}  
compare(A[2] * B[3],B[2] * A[3]) --> -1  
compare(A[2] / A[3],B[2] / B[3]) --> -1  

Yes

  function eq(rat a, rat b) 
     return a[1]=b[1] and a[2]=b[2] 
 
  end function 
  function lt(rat a, rat b) 
     return a[i]*b[2] = b[1]*a[2] 
  end function 

BTW as your function stands it still could be improved.

You do not require the denominator to be positive.
If it is 0 the function will blow up when it tries to do a remainder(0,0).
If it is negative it will return peculiar results.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu