this post was submitted on 02 Aug 2024
226 points (96.3% liked)

Programmer Humor

19171 readers
1180 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 7 points 1 month ago* (last edited 1 month ago) (2 children)

Umm, AKCTSHUALLY it gets more like O(n^2^) in parallel, assuming you're using a physically achievable memory. There's just a lot of criss-crossing the entries have to do.

Strassen's algorithm gets O(n^2.8^) in serial by being terrible, and the weird experimental ones get O(n^2.3^), but the asymptotic benefits of Coppersmith-Winograd and friends only kick in if you're a Kardashev III civilisation computing a single big product on a Dyson sphere.

[–] [email protected] 3 points 1 month ago (1 children)

I can't decide whether this sentence is a joke or not. It has the same tone that triggers my PTSD from my CS degree classes and I also do recognize some of the terms, but it also sounds like it's just throwing random science terms around as if you asked a LLM to talk about math.

I love it.

Also, it's apparently also real and correct.

[–] [email protected] 1 points 1 month ago

Thank you, I'm glad to share the pain of numerical linear algebra with anyone who will listen.

[–] [email protected] 2 points 1 month ago (1 children)

Yeah, in fact, I somehow calculated in assumption of n being the amount of elements in matrix, not (assuming square matrix)

But I am impressed to know that there are serial algorithms that approach O(n²), thank you for sharing that info

[–] [email protected] 3 points 1 month ago* (last edited 1 month ago)

Yeah, they work by turning the problem into some crazy kind of group theory and attacking it that way. Every once in a while someone shaves the decimal down slightly, just by implementing the deep math in a more efficient way. A new approach will be needed if it is in fact possible to get down to O(n^2^), though. Strassen's is a divide and conquer algorithm, and each step of the iteration looks like this:

    S[1] = B[1, 2] - B[2, 2]
    S[2] = A[1, 1] + A[1, 2]
    S[3] = A[2, 1] + A[2, 2]
    S[4] = B[2, 1] - B[1, 1]
    S[5] = A[1, 1] + A[2, 2]
    S[6] = B[1, 1] + B[2, 2]
    S[7] = A[1, 2] - A[2, 2]
    S[8] = B[2, 1] + B[2, 2]
    S[9] = A[1, 1] - A[2, 1]
    S[10] = B[1, 1] + B[1, 2]
    P[1] = STRASSEN(A[1, 1], S[1])
    P[2] = STRASSEN(S[2], B[2, 2])
    P[3] = STRASSEN(S[3], B[1, 1])
    P[4] = STRASSEN(A[2, 2], S[4])
    P[5] = STRASSEN(S[5], S[6])
    P[6] = STRASSEN(S[7], S[8])
    P[7] = STRASSEN(S[9], S[10])
    C[1..n / 2][1..n / 2] = P[5] + P[4] - P[2] + P[6]
    C[1..n / 2][n / 2 + 1..n] = P[1] + P[2]
    C[n / 2 + 1..n][1..n / 2] = P[3] + P[4]
    C[n / 2 + 1..n][n / 2 + 1..n] = P[5] + P[1] - P[3] - P[7]
    return C

In my copy of Introduction to Algorithms, it says something like "this is the most bullshit algorithm in the book and it's not close" underneath. You can make it a bit neater by representing the multiplication operation as a 3-dimensional tensor, but at the end of the day it's still just a stupid arithmetic trick. One that's built into your GPU.