Finding the Separate RHS of a/b when b = b' + c

  • Thread starter jobyts
  • Start date
In summary: I'm not exactly sure how it is done in the PARI/GP code, but the basic idea is that you can keep shifting the bits to the right to divide by 2^i in the code, and you can also shift to the left (with padding zeros) to multiply by 2^i, and then you can use integer truncate to round to the nearest integer. So for each value of i, you are keeping track of how many bits you need to shift right so that the multiplication by m will be as close to K as possible. It's not a perfect algorithm, but it's an iterative way
  • #1
jobyts
227
64
let's say a/b = a/(b'+c)
where b = b'+c.
I need to separate the RHS into a/b' + something. What's that something?
 
Mathematics news on Phys.org
  • #2
jobyts said:
let's say a/b = a/(b'+c)
where b = b'+c.
I need to separate the RHS into a/b' + something. What's that something?

What's the context? Is it just algebraic manipulation?

Something = a/(b'+c) - a/b'

and put over a common denominator?
 
  • #3
I need to convert x (ranging between 0 - 1,000,000) to y (ranging between 0 - (2^32)-1).

so y = (x * 2^32)/1M => (x << 32)/ 1M

We, the software guys have no problem doing it. But the microcode group says they don't have division operation.
I was trying to provide a solution by converting (x << 32)/ 1M to (x <<32) / ((2^20) + a)
(2^20 is the closest approximation to 1M)

I need to measure the error I'm introducing if I assume a=0.
If possible, I want to come up with a calculation as
(x<<32) /((2^20) + a) => (x << 12) + b.
What is b?
 
  • #4
jobyts said:
I need to convert x (ranging between 0 - 1,000,000) to y (ranging between 0 - (2^32)-1).

so y = (x * 2^32)/1M => (x << 32)/ 1M

We, the software guys have no problem doing it. But the microcode group says they don't have division operation.
I was trying to provide a solution by converting (x << 32)/ 1M to (x <<32) / ((2^20) + a)
(2^20 is the closest approximation to 1M)

I need to measure the error I'm introducing if I assume a=0.
If possible, I want to come up with a calculation as
(x<<32) /((2^20) + a) => (x << 12) + b.
What is b?

Do they have a multiply? Just multiply x * 4295

Will that work?
 
  • #5
berkeman said:
Do they have a multiply? Just multiply x * 4295

Will that work?

They have multiply operation for integers. Is it possible to make the approximation independent of x? We can use if-then-else.
 
  • #6
jobyts said:
They have multiply operation for integers. Is it possible to make the approximation independent of x? We can use if-then-else.

Not sure what you mean by approximation. That multiplicative factor is pretty exact for doing the scaling that you asked about. Nice integer multiplication...
 
  • #7
1000000*4295 = 0x1 0000 7FC0
1000000*4294 = 0x0 FFF1 3D80
1000000*1125899906 >> 18 = 4294967292 (0x0 FFFF FFFC)
1000000*2251799813 >> 19 = 4294967294 (0x0 FFFF FFFE)
 
Last edited:
  • #8
berkeman said:
Not sure what you mean by approximation. That multiplicative factor is pretty exact for doing the scaling that you asked about. Nice integer multiplication...

2^32 / 1M = 4,294.967296
We rounded 4,294.967296... to 4295.

So, for higher values of x, the deviation would be high.
 
  • #9
Thanks Berkeman and Xitami for your answers. Xitami's equation gives pretty accurate results.

Xitami, can you tell how you derived that equation?
 
  • #10
Code:
PARI/GP >[B]{
K=2^32-1;
T=1000000;
m=K/T;
for(i=0,20,
        n=T*truncate(m*2^i)>>i;
        print(i" "K-n))}[/B]
0 967295
1 467295
2 217295
3 92295
4 29795
5 29795
6 14170
7 6358
8 2452
9 499
10 499
11 10
12 10
13 10
14 10
15 10
16 10
17 3
18 3
19 1
20 1
PARI/GP > [B]truncate(m*2^19)[/B]
%2 = 2251799813
PARI/GP > [B]#binary(truncate(m*2^19)*1000000)[/B]
%3 = 51
51 bits of intermediate result
 
Last edited:

1. What is the separate right-hand side (RHS) of a/b?

The separate RHS of a/b refers to the value on the right side of the division symbol ("/"). It is the result of dividing a by b.

2. Can b' and c be any numbers?

Yes, b' and c can be any real numbers. It does not matter if they are integers or decimals.

3. How do I find the separate RHS of a/b when b = b' + c?

To find the separate RHS of a/b when b = b' + c, you can use the formula: a / (b' + c). Simply substitute the values of a, b', and c into the formula and solve for the separate RHS.

4. What if b' and c are both negative?

If b' and c are both negative, the result of dividing a by (b' + c) will still be positive. This is because a negative number divided by a negative number results in a positive number.

5. Why is it important to find the separate RHS of a/b?

Knowing the separate RHS of a/b is important because it allows you to understand the relationship between the numerator (a) and denominator (b) in a division problem. It also helps in simplifying fractions and solving equations involving fractions.

Similar threads

Replies
5
Views
1K
Replies
9
Views
395
  • General Math
Replies
4
Views
778
  • General Math
Replies
1
Views
820
  • General Math
Replies
1
Views
672
Replies
3
Views
789
Replies
19
Views
2K
  • General Math
Replies
7
Views
872
Replies
1
Views
763
Back
Top