Superior Highly Composite Numbers for fractional representation

12 views
Skip to first unread message

Logan Streondj

unread,
Feb 26, 2015, 7:20:11 AM2/26/15
to libfi...@googlegroups.com
Hey,
did you know you can get most accurate representation of numeric fractions by using superior highly composite numbers (SHCN)?

Can accurately represent numbers divisible by 3, 5, with a 7bit SHCN,
 7, 11, with a 16bit SHCN,  13, 17 with a 29 bit SHCN.
and of course all the non prime numbers also.

goes without saying, much better than binary fixed fractions.

here is demonstration:

note :
120 is 7bit SHCN
55440 is 16 bit SHCN
21621600 is 25bit SHCN
367567200 is 29bit SHCN

first value is fraction, second is precision, third is the SHCN fraction.

 2-limit
0.5
0.5 perfect 60/120
0.5 perfect 27720/55440
0.5 perfect 10810800/21621600
0.5 perfect 183783600/367567200
3-limit
0.3333333333333333
0.3333333333333333 perfect 40/120
0.3333333333333333 perfect 18480/55440
0.3333333333333333 perfect 7207200/21621600
0.3333333333333333 perfect 122522400/367567200
5-limit
0.2
0.2 perfect 24/120
0.2 perfect 11088/55440
0.2 perfect 4324320/21621600
0.2 perfect 73513440/367567200
7-limit
0.14285714285714285
0.14166666666666666 0.0011904761904761862 17/120
0.14285714285714285 perfect 7920/55440
0.14285714285714285 perfect 3088800/21621600
0.14285714285714285 perfect 52509600/367567200
11-limit
0.09090909090909091
0.09166666666666666 0.0007575757575757486 11/120
0.09090909090909091 perfect 5040/55440
0.09090909090909091 perfect 1965600/21621600
0.09090909090909091 perfect 33415200/367567200
13-limit
0.07692307692307693
0.075 0.0019230769230769301 9/120
0.07693001443001443 0.00000693750693750439 4265/55440
0.07692307692307693 perfect 1663200/21621600
0.07692307692307693 perfect 28274400/367567200
17-limit
0.058823529411764705
0.058333333333333334 0.0004901960784313708 7/120
0.05882034632034632 0.0000031830914183836323 3261/55440
0.058823537573537574 8.161772868664485e-9 1271859/21621600
0.058823529411764705 perfect 21621600/367567200
pi
0.3141592653589793
0.31666666666666665 0.0025074013076873403 38/120
0.31415945165945164 1.863004723268169e-7 17417/55440
0.31415926665926663 1.3002873222589528e-9 6792626/21621600
0.31415926665926663 1.3002873222589528e-9 115474642/367567200
phi
0.16180339887498948
0.15833333333333333 0.0034700655416561588 19/120
0.1617965367965368 0.000006862078452685161 8970/55440
0.1618033818033818 1.707160768305016e-8 3498448/21621600
0.16180339812692754 7.480619457211901e-10 59473622/367567200
e
0.27182818284590454
0.275 0.00317181715409548 33/120
0.2718253968253968 0.0000027860205077390177 15070/55440
0.2718281718281718 1.101773272615958e-8 5877360/21621600
0.27182818271053566 1.353688827698818e-10 99915124/367567200

Yep,
I think it should be easy enough to implement.
What do you think?

--
Logan

Petteri Aimonen

unread,
Feb 26, 2015, 7:26:19 AM2/26/15
to libfi...@googlegroups.com
Hi,

> I think it should be easy enough to implement.
> What do you think?

The main advantage of binary fractions is that
dividing by the denominator is fast, as it is only shifts.
For example in multiplications you need to divide by the
denominator.

Also if you allow varying denominators, you have to store
that with every value, which basically means every 32 bit
value becomes 64 bit instead.

--
Petteri

Logan Streondj

unread,
Feb 26, 2015, 11:27:47 AM2/26/15
to libfi...@googlegroups.com
On Thu, Feb 26, 2015 at 02:26:18PM +0200, Petteri Aimonen wrote:
> Hi,
>
> > I think it should be easy enough to implement.
> > What do you think?
>
> The main advantage of binary fractions is that
> dividing by the denominator is fast, as it is only shifts.
> For example in multiplications you need to divide by the
> denominator.

hmm, yes binary is certainly faster. I was more thinking of it as a
high-precision alternative for finance and scientific calculations.
for instance some use decimal fixed points,
I guess you don't have those,
but SHCN's are better than them.

> Also if you allow varying denominators, you have to store
> that with every value, which basically means every 32 bit
> value becomes 64 bit instead.
>
> --
> Petteri

The denominator would always be the same for a given type.
the maximum SHCN that fits in the alloted bits.
if C is used to show SHCN: CQ16.16 would always be 16bit SHCN

adding, subtracting, multiplying and dividing with whole numbers
for the SHCN fixed-points numbers I've tried is fairly trivial.
i.e. 8bit unisigned SHCN (base 12) little-endian
0011 0010 (3+2/12) ~pi
*2 =
0110 0100 (6+4/12) ~2pi

simply apply to each, and carry overflow.
(3+2/12)+(2+10/12) =
(6+0/12)


though multiplying and dividing by fractions would certainly be more
difficult.
(3+2/12)*(2+9/12) =
(8+9/12)
not sure how to easily accomplish that.

though for high precision it may be very useful.
If precision is outside the scope of libfixmath,
please direct me to a more suitable libre software project.

--
Logan


>
> --
> You received this message because you are subscribed to the Google Groups "libfixmath" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to libfixmath+...@googlegroups.com.
> To post to this group, send email to libfi...@googlegroups.com.
> Visit this group at http://groups.google.com/group/libfixmath.
> For more options, visit https://groups.google.com/d/optout.

Vincent

unread,
Feb 26, 2015, 3:36:09 PM2/26/15
to libfi...@googlegroups.com
Hi,

For me, the goal of libfixmath is to provide fast fixed point math operations.

Your representation is interesting, but the most simple mathematical operation, the addition, is complicated :
(3+2/12)+(2+10/12)
Additionning 0x32 to 0x2A gives 0x3C, and it should give 0x40. It means this representation needs conditionning computing = bad performances

In the end ... the only way to have easy maths with your SHCN, is having a base 16 SHCN .. which is finally libfixmath !

Best regards,
Vincent.
Reply all
Reply to author
Forward
0 new messages