Poojeets btfo

>poojeets btfo

Attached: 1533491948366.png (581x678, 73K)

niggah what?

wait doesn't a+b take as long to compute as b-a

(5+5)/2=5
+(5-5)/2=+0

Attached: 1521027939598.jpg (300x299, 11K)

(a + b) >>> 2?

>requires less computation
wut

Though it does reduce the risk of overflow if you're dealing with non-negative integers.

5 + ((5 - 5) / 2)
Is what you're supposed to be doing

fuck I meant 1

>1 add, 1 mul (0.5)
>vs
>1 add, 1 sub, 1 mul
that guy probably has some kind of mental disability. the point in that is not optimization but rather avoiding overflows, but even on that you should be using a buffer larger than the inputs anyway

All a+(b-a)/2 does is avoid overflow, it does not "require less computation". It requires *more*.

It's not taught in schools because you are taught how to average two numbers in the way you said wasn't the right way.

Why?

TIL 3 computations is less than 2 computations

I'm not 100% positive, but isn't float calculations after a certain point where the number is really really small or large, IS slower? Even then, wouldn't that defeat the purpose since he'll actually be creating really small numbers with (b-a) if they're usually really close together.

I'm very confused.

>what is IEEE 754?
Brainlet, pls.
Just give up. Don't even bother.

In the OP's example it would be 45 / 2 instead of 934525 / 2.

Whether that's faster or not to compute on a computer I don't know

Yes, but a halving a small number is much easier than halving a big one. The average of 123456 and 123000 is [half of 456] more than 123000, which I can immediately figure in my head as 123228. Easier than trying to divide 246456 by two in my head.

>not doing (a+b) >> 1

>all these people who didn't read "What Every Computer Scientist Should Know About Floating-Point Arithmetic"
As expected from youtube-tutorial generation.
Kids these days just don't read. *sips monster*

>dividing by two takes long
lol. this is what street shitters believe

As I expected all the autists here think he is referring to a programming context when he is talking about mental calculations.

WOW THAT "OPTIMIZATION" IS REALLY GOING TO HELP ME. YEP LETS DISCUSS SHIT SOLVED A DECADE AGO.

mathlet

Only autists do mental calculations

That one is kind of a stupid example because all the digits are even numbers.
Dividing a binary number by two is trivial, of course, so a computer doesn't care about this.

The tweet is not about computers though. Vitalik is using "compute" to refer to "calculating" by hand. When you are trying to quickly come up with the average of two large decimal numbers, you probably already use the technique described unless you have a bad relationship with math. Quick, what's the average of 100 and 150? You instantly know this is 125, because 25 is halfway between 0 and 50, and the 100s place doesn't matter.

If you're the OP, you are stupid for posting this to Jow Forums. Obviously in a Jow Forums context people will misinterpret the meaning of "compute" here. If you posted it to /sci/, no one would care and would just say "Duh, this is obvious."

Next you'll tell me that I can calculate products by multiplying their digits.

Just because i said compute and posted on a board about computers and technology doesn't mean I referred to computers. Now comes the part where I call anonymous people online autistic!

Multiplying by 0.5 is faster than dividing by 2
Can I get a job at doom now?

I really don't understand, considering a and b are floating point numbers, why it's suboptimal unless for very special cases

the former needs 2 operations while the latter needs 3, the more operations, the more rounding and bigger the error


for very special cases like a and b are very big so that their addition can be inf and then the latter would be the correct answer, but this is a very special case

what you really want to do is that
a >>= 1;
b >>= 1;
a += b;

>the average of 1 and 1 is 0
congrats

integer division my dude

The second () is redundant.

just use a calculator lol

I keep a calculator within reach and use it all the time, but I still know some answers in my head faster than I can get them typed into a calculator.

(1 + 1) / 2 = 1

But 1/2 + 1/2 = 0

And how is this relevant to the thread?

Eh. Regardless of the context, the "algorithm" only works when you're using two numbers. Indeed, if you've ever just eyeballed two numbers and try to gauge their average, you probably implicitly use the algorithm rather than doing add-then-half.

Indian/Asian obsession with arithmetic shortcuts is always so bizarre to me.

It's not, because the thread is actually about "calculating averages quickly in your head" and not about integer division in CPUs.

(a+b)/2 might be easier for mental calculation for many people. Fewer steps, plus for me at least it's easier to add in my head than subtract in my head.

>Indeed, if you've ever just eyeballed two numbers and try to gauge their average, you probably implicitly use the algorithm rather than doing add-then-half.
Yes, exactly. People who are comfortable with numbers naturally do this. But the "bad at math" meme leads a lot of people to give up and assume that there's no way they can ever intuitively understand even the simplest things like averages. So there is some value in reminding those people "I'm not smarter than you, I'm just thinking more clearly, and you can do it too."

Of course, it backfires if you don't get them to think about why it works and lead them to believe "LOL it's like a magic trick, it just werks!" as this stupid twitter post does. It's a shame that so many clever people see no value in learning to teach properly.

I've never thought of it as subtraction, just "what number is halfway between these two numbers," chopping off some digits when applicable.

Wow you must be top of the class

>averaging only integer values

>>poojeets btfo
Sorry but we were taught that in our Numerical Methods course here in India. Now kill yourself Jow Forumstard.

Do they just give checkmarks to anyone on twitter now? Who the fuck even is this?

>not just decreasing the exponent by 1, literally one cycle

Blue checkmarks on twitter: Jews or close friends of the Jews.

first comes new math, now new computer science

Attached: 1533345326.png (464x99, 50K)

You're the mental one kiddo, he was talking about mental calculation

You're just a retard.

>has to go through small number
vs.
>has to go through a large number
well obviously it's a BIT faster but it may be trivial unless we're talking performing literally trillions of these calculations

he's pretty known actually, he invented ethereum or something similar

He's talking about mental calculations, retards.

is this a joke?

of course they do (you fucking idiot)

Yes, it's a very subtle troll. Ignore it.

where do I learn software optimization

Who are the authors that teach how to reduce cycles

It got me too user, but I realized what I did wrong before posting. That makes me smarter than you.

>i posted non-technology related shit on a technology board
>and that is ok
you need to go back, summer

>three computations is less than two computations

You say that like im supposed to know what an etherum is

2+2=4-1=3

> he invented ethereum or something
faggot why are you acting like you dont know?

Explanation for dummys:

unsigned char a = 255;
unsigned char b = 255;
unsigned char c = (a+b)/2;


will overflow, but

unsigned char a = 255;
unsigned char b = 255;
unsigned char c = b+(a-b)/2;


will do ok.

Attached: a68.jpg (600x813, 58K)

>unsigned char to store a potential float
Idiot.

It's about mental math you retard

A S C E N D E D

You could probably blow this guys mind by telling him that a^2 = (a-b)(a+b) + b^2.

>You instantly know this is 125, because 25 is halfway between 0 and 50, and the 100s place doesn't matter.
Not really, I just "remember" same way I remember the multiplication table.

But I absolutely suck at math.

>a = 255
>b = 0
Oh noes

No problem fampai, got a dedicated ALU in pci

Attached: 1504701136910.jpg (347x102, 6K)

ok but what is IEEE754? referencing it while only being condescending doesn't further the conversation

on x86 division is much more expensive than addition
his point is it's likely that b-a is a smaller divisor than a+b making the division operation less expensive
It assumes a, b are close to each other

because I'm not sure of what he really did in the project, I just know he's related to ethereum

Only for floats (?), I think integer division is in constant time

This, it's the only reason (or extremelly high numbers which will involve more that 2 registers) why you should calculate it like that.

>less computation
>not "less thinking"

Vitalik confirmed for robot

Wouldn't it lead to potential loss of precision though?

float a = ........
float b = .........
float c = a + (b - a) / 2

so he's become an e-celeb huh. time to unfollow

Vitalik is dumb as fuck - if the result is still a 6 digit number, it will take just as long to calculate (by hand) the result.

If I were trying to average 75,000 and 100,000 I would use his method. If I were trying to average 100,000 and 125,000 I would not waste my time turning a two step process into a three (before dividing).

Logic, bitch nigga. Figure it out.

a+b results in a large number which is hard to divide in your head, b-a is a smaller number easier to divide, division is IMO the hardest basic operation to do in your head

The argument is time taken and the correct operation as presented is
> A + (( A - B ) / 2 ) = X
Turning
>(A + B) / 2 = X
From a two-step to a three-step operation.

It's a joke.

>a + (b-a)/2

doesn't he mean a + ((b-a)/2)?

Equivalent of you use the standard rules of arithmetic.

pls halp i fail highschool maths

Attached: Untitled.png (734x338, 9K)

>Redundant
Lel no it isn't.
Order of operations without it would be 5-5=0, then 0/2=0, then 5+0, Division comes before addition.

>2+2=3
This sort of shit is why you failed math, you can't just go around writing it like that.

its just quick maffs user

import datetime

numOne = 4859285828
numTwo = 4859492729

times = 1000000

def normal():
return (numOne+numTwo)/2

def better():
return numOne+(numTwo-numOne)/2

bNormal = datetime.datetime.now()
for i in range(0, times):
avgN = normal()
eNormal = datetime.datetime.now()
dNormal = eNormal - bNormal

bBetter = datetime.datetime.now()
for i in range(0, times):
avgB = better()
eBetter = datetime.datetime.now()
dBetter = eBetter - bBetter

print("Normal: ")
print(dNormal)
print("Average Normal: ")
print(avgN)
print("")
print("Better:")
print(dBetter)
print("Average Better: ")
print(avgB)

"""""""""""better"""""""""""

Attached: image.jpg (319x346, 50K)

Attached: 1533090101099.jpg (477x565, 34K)

you are an idiot... it's = 1

Vitali is taking about mental math. Also you don't need to be taught how to do this. You should just naturally see that it's faster this way.

Is this bait? a+(b-a)/2 means that only b-a is divided by 2. If you want it to be clearer you can think of it as "a+(b-a)*1/2. It should be pretty obvious that only b-a is divided by 2 in that form.

>mental math
I get that, I do.
>See that it's faster this way
Explain to me how adding an operation to an equation is faster when the example is still computing a 6 figure sum.
As I explained above, there may be a speedup (in the division only) IF, if the a+(b-a) method yields a number with less figures.
For example (the numbers aren't real):
Dividing 112520 by hand takes 6 operations. Dividing 97832 by hand takes 5
But you had to perform an extra step to get the 5 digit number, negating any benefit.

It's technically correct to say the division is faster, but incorrect to say the problem is solved faster.

Objectively and and incredibly, wrong.

Attached: chrome_2018-08-06_07-42-24.png (1552x705, 102K)

Saving 1 picosecond of processing power.

Cool I guess, but it only works for two numbers, and I can't think of any times when I would need to do a shit ton of two number averages.

Maybe if you were visually simulating some kind of value that had to be exactly in the middle of two floats it could be useful, but I can't imagine this would speed up the calculation by any appreciable amount.

How far did you get into your education?