r/ProgrammerHumor • • 3d ago

Meme dontYouDareToDeceive

Post image
1.4k Upvotes

51 comments sorted by

432

u/IHeartBadCode 3d ago

Before you know it, they'll have O(1) time method for factoring all even primes.

126

u/dangderr 3d ago

We’ve actually been able to factor all primes in O(1) for a while now.

41

u/Murphy_Slaw_ 2d ago

Erm, actually it can't get under O(n) because just outputting n is O(n).

47

u/prumf 2d ago

What no you changed n from the number to its size.

Printing n is O(log(n))

8

u/Bartodziejj 2d ago

O(log(n)) is a subset of O(n)

10

u/Vivid_Dot_6405 2d ago

Correct and this is why I dislike the use of Big O in non-academic discourse because when people use Big O they usually really mean Big Theta, which is a tight bound and not an upper bound like Big O.

7

u/soussang 2d ago

Ahem. Yes, it's true for integers which prints in O(log_b(n)).

But have you consider printing those in binary? O(1) for all fixed sized integer types (__int128 go brrrr). Is it slower than the integer printing? Maybe. Does it falls appart if you need more bytes? Maybe. Are you willing to make a template/macro which can unwrap a N sized loop to maintain O(1) for any arbitrary fixed size? I'll let you decide.

5

u/dangderr 2d ago

I didn't say anything about outputting?

You must be an amateur haxor if you're outputting all your factored primes in the middle of an attack smh

If you just have to pass back a pointer to the result, it's O(1).

1

u/hary627 2d ago

"are any of these even numbers prime?" Always has the same answer

7

u/Frodojj 2d ago

Two is prime.

3

u/evorm 2d ago

That's still just 1 iteration.

2 ? yes : no

0

u/48panda 2d ago

Quantum algorithms exist with complexity smaller than its input

8

u/Willinton06 2d ago

O(0), all primes already exist in the abstract plan of math, good enough for me

15

u/Front_Committee4993 3d ago

print("2,1")

5

u/overclockedslinky 3d ago

SoURcE?!??!

3

u/Neon297 2d ago

print("2")

14

u/BenTheHokie 2d ago

You can factor any integer in O(1) as long as you guess it right on the first try

2

u/vuurheer_ozai 10h ago

That would be Ω(1); O is an upper bound

-1

u/onepiecefreak2 2d ago

That's not how Big O notation works

4

u/Rainb0_0 1d ago

Best case should be O(1) right?

6

u/onepiecefreak2 1d ago

Big O notation represents the worst case runtime. Sorting algorithms also aren't O(1) just because there is a chance that the list is already sorted.

2

u/argument_inverted 1d ago

What kind of programmers we have here? 🙄

1

u/onepiecefreak2 22h ago

That's just how it works.

2

u/Rainb0_0 13h ago

Big O just represents the upper bound, not the worst case. The best/avg/worst case each can have big/small O, theta and big/small omega assigned to them

2

u/Unupgradable 2d ago

But it is how smol o notation works... Sort-of

1

u/Vivid_Dot_6405 2d ago

Easy.

Suppose there exists a memory storage device with infinite capacity and that the maximum speed of causality can be safely ignored because the device is extremely small. Also suppose that infinite time is available. Now assume all prime numbers have been calculated and stored on the memory storage device. Thus, an algorithm for calculating an n-th prime merely reduces to retrieval of data from the memory storage device, which has time complexity O(1).

55

u/djonoy 3d ago • Bravo

ERROR: expected comparison but found expression instead

106

u/seba07 2d ago

The algorithm "wait a million years; answer 42" is O(1) but wouldn't be usable for anything. P=NP does not mean that there is a way to solve problems in NP fast.

21

u/Ksevio 2d ago

It's been a while since I took algorithms, but I recall you can break down any NP problem to the simplest form and then if you could prove that could be solved in polynomial time, you'd be able to solve NP problems fast

30

u/seba07 2d ago

There is a difference between computation theory and practical implementation. As I was trying to highlight, an polynomial algorithm does not mean that it is is fast. It just meant the complexity doesn't grow that fast.

4

u/TldrDev 1d ago

The implications of P=NP are currently unknown. It could be that all NP problems are NP fast. It could be we have to compute infinitely. It could be just walking a tree to the answer. It depends on if P=NP, and what type of solution we find. You are talking in certain terms, but in my opinion, probably shouldnt be.

5

u/seba07 1d ago

It also depends on the type of proof. Maybe someone shows that P≠NP can't be true (not likely but could be). That would solve the problem but doesn't give an algorithm.

11

u/emptyArray_79 1d ago

An algorithm that has a time complexity of Θ(n^1000) is technically still in P, yet still impractically slow (probably slower than most NP-hard algorithms on realistic input sizes). Being in P doesnt mean the algorithm is practically fast. Just that their time complexity is some polynomial instead of the exponential time complexity of NP complete problems.

9

u/bender3600 2d ago edited 2d ago

Yeah, but just because its considered asymptotically fast does not necessarily mean it's actually fast to execute.

An example is integer multiplication. The asymptotically fastest known algorithm is O(n log n) but the hidden constant is so big that it only becomes faster for integers with trillions of digits.

And of course a Θ(ngoogol ) algorithm would also be considered fast because it's still polynomial but it would not be practical

-1

u/TldrDev 1d ago

This is only one possible outcome.

NP problems are often a family of problems where if you solve one, you solve them all. The same algorithmic solution can be applied across a huge range of disciplines. In the past, we have solved such problems where the solution is literally trivial. For example, computing some digit of pi or checking subsets of prime numbers.

Instead of calculating permutations we are essentially able to walk to the answer directly.

That would make things completely calculatable in essentially arbitrary time frames.

You are assuming its impossible, but id disagree.

Imagine the traveling salesman problem, where we make a tree of all possible states of that problem.

Right now, iterating the permutations and checking each possibility makes it computationally prohibitive & expensive.

However, there might be a solution to the problem such that you can walk down the tree of possibilities directly to the answer. This would be a solution such that P=NP, and you do not need permutation at all.

If you solved that problem, you can apply that same solution to literally tens of thousands of adjacent math and computer science problems.

We do not currently have that solution, and it is unclear if it will be something as easy as walking the tree, or using permutations which are incalculable.

The implications of this question remains to be seen. We will know if we ever get an answer.

3

u/bender3600 1d ago

I'm not assuming anything. I simply stated that just because something can be solved in polynomial time it doesn't necessarily mean that it's practical to solve, not that it can't be.

1

u/mirhagk 1d ago

Just need a million processing units to each wait a year!

Yes your point is true, but the concern is when n gets large, and we deal with very large n these days. It only gets larger, as computers get faster.

My understanding is that quantum-proof algorithms still rely on P!=NP, since that's a fundamental need. As n keeps growing, it needs to always be true that it's faster to verify than to solve, and that's only the case if P!=NP.

Fortunately we can be pretty sure they didn't solve it, because the rumours are widespread enough that a claim wouldn't do any damage, and these companies love to make claims that are unproven. Plus it's easy enough to prove, it's not like they don't have the computing power to solve it.

30

u/AkrinorNoname 1d ago

P=NP only for N=1 or P=0. No idea why everyone is so worked up about this.

6

u/Visible_Comment6433 1d ago

I'm going to trust you on this.

6

u/henrikhakan 1d ago

Bro

3

u/Visible_Comment6433 1d ago

In bro we trust

4

u/henrikhakan 1d ago

Bro saved my marriage

3

u/Visible_Comment6433 1d ago

Bro saved me a bundle on my car's extended warranty.

14

u/Alzusand 2d ago

Please let it be true it would be so funny.

2

u/Jersey_2019 2d ago

Then Quantum computing field would go away in an instant 😭

28

u/Front_Committee4993 3d ago

Let N=1

14

u/differentiallity 2d ago

Or P=0. See? Not so easy.

4

u/Substantial_Top5312 2d ago

n=1 or p = 0

3

u/Benjam438 1d ago

If P=NP I'm skeptical of the letter N

2

u/Wiseon321 1d ago

I refuse to believe this thought experiment is even important.

1

u/username_6916 2d ago

Show all your work for full credit.