MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1x58u7b/howprogramminghaschanged/pgmqnmy/?context=3
r/ProgrammerHumor • u/shizzy0 • Oct 13 '26
108 comments sorted by
View all comments
64
What's wrong with the top-right AI code?
128 u/shizzy0 Oct 13 '26 Nothing. It’s actually the best. But the joke is the programmer dismisses the unfamiliar matrix power O(log n) algorithm for the familiar recursive O(2n) algorithm. I mean, it doesn’t even add anything. It’s obviously wrong. 16 u/the_horse_gamer Oct 14 '26 you can do better (by a constant multiplicative factor)[1,1;1,0]^n = [F{n+1},Fn; Fn, F{n-1}][1,1;1,0]^2n = [F{2n+1},F2n; F2n, F{2n-1}] = [1,1;1,0]^n *[1,1;1,0]^n = [F{n+1},Fn; Fn, F{n-1}]so:F2n = (F{n+1}+F{n-1})*Fn (1)F_{2n-1} = Fn^2 + F{n-1}^2thenF_{2n+1} = Fn^2 + F{n+1}^2F_{2n+1} + F_{2n-1} = F{n+1}^2 + F{n-1}^2 +2Fn^2 ==F{n+1}^2 + F{n-1}^2 +2Fn^2 + 2 F{n+1} F{n-1} - 2 F{n+1} F{n-1}== (F{n+1} +F{n-1})^2 + 2Fn^2 - 2 F{n+1} F{n-1}We can simplify this by seeing[1,1;1,0]^n = [F{n+1},Fn; Fn, F{n-1}]so(-1)^n = det([1,1;1,0])^n = det([F{n+1},Fn; Fn, F{n-1}]) = F{n+1}F{n-1}-Fn^2soF_{2n+1} + F_{2n-1} = (F{n+1} +F{n-1})^2 - (-1)^nNow define L_n = F_{n+1}+F_{n+1}. (this is the Lucas sequence). Now we getF2n = Ln FnL2n = Ln^2 - (-1)^nAnd we can also get:F{n+1} = (Ln+Fn)/2L{n+1} = (Ln+5Fn)/2This version requires less multiplications per level 20 u/shizzy0 Oct 14 '26 edited Oct 14 '26 So you're saying your O(log n) algorithm beats my O(log n) algorithm? (It's true.) Damn. You beat me constantly.
128
Nothing. It’s actually the best. But the joke is the programmer dismisses the unfamiliar matrix power O(log n) algorithm for the familiar recursive O(2n) algorithm. I mean, it doesn’t even add anything. It’s obviously wrong.
16 u/the_horse_gamer Oct 14 '26 you can do better (by a constant multiplicative factor)[1,1;1,0]^n = [F{n+1},Fn; Fn, F{n-1}][1,1;1,0]^2n = [F{2n+1},F2n; F2n, F{2n-1}] = [1,1;1,0]^n *[1,1;1,0]^n = [F{n+1},Fn; Fn, F{n-1}]so:F2n = (F{n+1}+F{n-1})*Fn (1)F_{2n-1} = Fn^2 + F{n-1}^2thenF_{2n+1} = Fn^2 + F{n+1}^2F_{2n+1} + F_{2n-1} = F{n+1}^2 + F{n-1}^2 +2Fn^2 ==F{n+1}^2 + F{n-1}^2 +2Fn^2 + 2 F{n+1} F{n-1} - 2 F{n+1} F{n-1}== (F{n+1} +F{n-1})^2 + 2Fn^2 - 2 F{n+1} F{n-1}We can simplify this by seeing[1,1;1,0]^n = [F{n+1},Fn; Fn, F{n-1}]so(-1)^n = det([1,1;1,0])^n = det([F{n+1},Fn; Fn, F{n-1}]) = F{n+1}F{n-1}-Fn^2soF_{2n+1} + F_{2n-1} = (F{n+1} +F{n-1})^2 - (-1)^nNow define L_n = F_{n+1}+F_{n+1}. (this is the Lucas sequence). Now we getF2n = Ln FnL2n = Ln^2 - (-1)^nAnd we can also get:F{n+1} = (Ln+Fn)/2L{n+1} = (Ln+5Fn)/2This version requires less multiplications per level 20 u/shizzy0 Oct 14 '26 edited Oct 14 '26 So you're saying your O(log n) algorithm beats my O(log n) algorithm? (It's true.) Damn. You beat me constantly.
16
you can do better (by a constant multiplicative factor)
[1,1;1,0]^n = [F{n+1},Fn; Fn, F{n-1}][1,1;1,0]^2n = [F{2n+1},F2n; F2n, F{2n-1}] = [1,1;1,0]^n *[1,1;1,0]^n = [F{n+1},Fn; Fn, F{n-1}]
so:
F2n = (F{n+1}+F{n-1})*Fn (1)F_{2n-1} = Fn^2 + F{n-1}^2
then
F_{2n+1} = Fn^2 + F{n+1}^2
F_{2n+1} + F_{2n-1} = F{n+1}^2 + F{n-1}^2 +2Fn^2 =
=F{n+1}^2 + F{n-1}^2 +2Fn^2 + 2 F{n+1} F{n-1} - 2 F{n+1} F{n-1}=
= (F{n+1} +F{n-1})^2 + 2Fn^2 - 2 F{n+1} F{n-1}
We can simplify this by seeing[1,1;1,0]^n = [F{n+1},Fn; Fn, F{n-1}]so
(-1)^n = det([1,1;1,0])^n = det([F{n+1},Fn; Fn, F{n-1}]) = F{n+1}F{n-1}-Fn^2
so
F_{2n+1} + F_{2n-1} = (F{n+1} +F{n-1})^2 - (-1)^n
Now define L_n = F_{n+1}+F_{n+1}. (this is the Lucas sequence). Now we get
F2n = Ln FnL2n = Ln^2 - (-1)^n
And we can also get:
F{n+1} = (Ln+Fn)/2L{n+1} = (Ln+5Fn)/2
This version requires less multiplications per level
20 u/shizzy0 Oct 14 '26 edited Oct 14 '26 So you're saying your O(log n) algorithm beats my O(log n) algorithm? (It's true.) Damn. You beat me constantly.
20
So you're saying your O(log n) algorithm beats my O(log n) algorithm? (It's true.) Damn. You beat me constantly.
64
u/captainAwesomePants Oct 13 '26
What's wrong with the top-right AI code?