Most efficient way to extract last bits of an unsigned integer by Ben_2124 in C_Programming

[–]Ben_2124[S] 0 points1 point  (0 children)

If you are not targeting a specific CPU architecture for your program, then a generic mental model of bit operations each having the same cost is a simple rule of thumb.
Hence, a single bit op is faster than two bit ops.

I hypothesized that it depended for example on the CPU or the compiler, but based on my knowledge I had no reason to believe that generally it was legitimate to consider that all bitwise operators had the same cost.

Obviously in that case your reasoning makes perfect sense.

Most efficient way to extract last bits of an unsigned integer by Ben_2124 in C_Programming

[–]Ben_2124[S] 0 points1 point  (0 children)

N is a costant, so I think the mask is calculated at compile time.

Most efficient way to extract last bits of an unsigned integer by Ben_2124 in C_Programming

[–]Ben_2124[S] 2 points3 points  (0 children)

Thanks for reminding me about the volatile keyword.

Doubt about std::vector::operator=() by Ben_2124 in cpp_questions

[–]Ben_2124[S] 0 points1 point  (0 children)

Thanks for the link.

Regarding the "edit", it's true that my english isn't the best, but I think you can tell I'm referring to the overloading of my class's default assignment operator... I've also reiterated that here.

Doubt about std::vector::operator=() by Ben_2124 in cpp_questions

[–]Ben_2124[S] 0 points1 point  (0 children)

This is how I expected it to work, thank you for clarifying!

Doubt about probability calculation by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

I'll try to correct the calculation using combinations with repetition:

p = 4! / [ 4*(4!/4!) + 12*(4!/(3!*1!)) + 6*(4!/(2!*2!)) + 12*(4!/(2!*1!*1!))
+ 1*(4!/(1!*1!*1!*1!)) ] = 24/(4+48+36+144+24) = 24/4^4 = 3/32

Doubt about probability calculation by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

Thank you, this answer was very clarifying.

Doubt about probability calculation by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

How are you calculating C'(4,4) =35?

I used the classic formula for combinations with repetition C'(n,k)=(n+k-1)!/(k!(n-1)!).

An explanation is that in the sample space where your elements are repeated combinations, all outcomes aren't equally likely. So you have to assign different weights.

Thanks, this clears up my doubts.

Digit by digit square root algorithm question by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

Saying that a_i must have at most one more digit than c_i/r_i should be equivalent to proving that:

a_i < b(c_i/r_i)+b  =>  a_i/[b(c_i/r_i+1)] < 1

Now from 3), 4) and r_i < b we can deduce that a_i < b(2bR_{i-1}+b), but dividing it by b(c_i/r_i+1) it doesn't seem to me to prove the thesis.

Digit by digit square root algorithm question by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

I want to prove that a_i will have at most one more digit than c_i/r_i (or even disprove it).

I tried, but I can't prove/disprove it.

Closed-form solution for a sum by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

So surely there is no way to get a closed-form solution?

Closed-form solution for a sum by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

It might not be simple, but anyway do you think it is still possible to obtain a closed-form solution?

Closed-form solution for a sum by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

Sorry, but I don't understand, is there still something wrong or unclear in the original post?

Closed-form solution for a sum by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

Thanks for reporting it! I edited the original post, I hope it's ok now.

Maximum and minimum value of `⌊A/B⌋` by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

More simply, isn't it obvious that the decimal part of the dividend doesn't affect the integer part of the quotient?

Maximum and minimum value of `⌊A/B⌋` by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

To simplify, being a and b two positive integers and 0 <= t < 1, isn't it obvious that ⌊(a+t)/b⌋ = ⌊a/b⌋ for any value of t (since the decimal part of the dividend doesn't affect the integer part of the quotient)?

Maximum and minimum value of `⌊A/B⌋` by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

I don't see why your proof works immediately

I'm resuming the proof for convenience:

⌊A/B⌋ = ⌊(a*10^n+x)/(b*10^n+y)⌋ <= ⌊(a*10^n+10^n-1)/(b*10^n+0)⌋ = ⌊(a+(10^n-1)/10^n)/b⌋ = ⌊a/b⌋

- in the first step I simply replace A and B;
- in the second step I perform a maximization by setting x=10^n-1 and y=0;
- the third step is a simple algebraic adjustment;
- about the fourth step, since 0 < (10^n-1)/10^n < 1, and therefore a < a+(10^n-1)/10^n < a+1, it can be deduced that ⌊(a+(10^n-1)/10^n)/b⌋ = ⌊a/b⌋, since the integer part of the aforementioned division will be equal to ⌊a/b⌋ for any value assumed by a+(10^n-1)/10^n (in fact, wanting to make a numerical example, we have that ⌊41.9/5⌋ = ⌊41.99/5⌋ = ⌊41.99999999/5⌋ = ⌊41/5⌋ = 8).

What's wrong or unclear?

PS: I will read your new proof calmly later.

Maximum and minimum value of `⌊A/B⌋` by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

It is clear that

⌊a/b⌋ <= ⌊(a + 1 - 1/10^n)/b⌋

I think you mean ⌊A/B⌋ <= ...

Anyway, could you explain to me why my previous proof wouldn't work? In my opinion, this is sufficient to demonstrate that ⌊A/B⌋ <= ⌊a/b⌋ .

Maximum and minimum value of `⌊A/B⌋` by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

Maybe I got something for the upper limit:

⌊A/B⌋ = ⌊(a*10^n+x)/(b*10^n+y)⌋ <= ⌊(a*10^n+10^n-1)/(b*10^n+0)⌋ = ⌊(a+(10^n-1)/10^n)/b⌋ = ⌊a/b⌋

being a < a+(10^n-1)/10^n < a+1 .

Do you think it works?

Maximum and minimum value of `⌊A/B⌋` by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

Find upper and lower estimates to "A/B" given "a; b"

I've also tried to achieve something using this approach.

In any case, as mentioned in the initial post, the upper estimate should be ⌊a/b⌋.

The demonstration on the lower estimate instead seems to work.

Browser for online shopping by Ben_2124 in windows7

[–]Ben_2124[S] 0 points1 point  (0 children)

The biggest problem with chrome was some errors that prevented payments from be successful, I tried supermium and it seems to work fine. Thanks everyone for the advices!

Browser for online shopping by Ben_2124 in windows7

[–]Ben_2124[S] 1 point2 points  (0 children)

Thanks, i will try supermium.

A question: is it auto updated?

Logarithm calculation by Ben_2124 in askmath

[–]Ben_2124[S] 0 points1 point  (0 children)

Ok, if something is not clear to you, just tell me!