this post was submitted on 22 Oct 2023
601 points (95.6% liked)

Programmer Humor

32375 readers
529 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

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

Guess only work with integers, specially for the floor function that is going to give you an integer at the end everytime.

Not my idea, learned it somewhere while doing college in an statistics class. The idea is that the exponential function grow really fast, so small difference on variables become extreme difference on the exponential, then the log function reverse the exponential, but because it grew more for the biggest variable it reverts to the max variable making the other variables the decimal part (this is why you need the floor function). I think is cool because works for any number of variables, unlike mathematician 2 who only work for 2 variables (maybe it can be generalized for more variables but I don't think can be done).

For a min fuction it can be use ceiling(-ln(e^-x + e^-y))

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago) (5 children)

to be fair it does seem to work for any two numbers where one is >1. As lim x,y--> inf ln(e^x+e^y) <= lim x,y --> inf ln(2 e^(max(x,y))) = max(x,y) + ln(2).

I think is cool because works for any number of variables

using the same proof as before we can see that: lim,x_i -->inf ln(sum_{i/in I} e^(x_i)) <= ln(|I|) +max{x_i | i /in I}.

So it would only work for at most [base of your log, so e<3 for ln] variables.

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

After searching a little, I found the name of the function and it's proof: https://en.wikipedia.org/wiki/LogSumExp

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago) (1 children)

thanks for looking it up:).

I do think the upper bound on that page is wrong thought. Incedentally in the article itself only the lower bound is prooven, but in its sources this paper prooves what I did in my comment before as well:

for the upper bound it has max +log(n) . (Section 2, eq 4) This lets us construct an example (see reply to your other comment) to disproove the notion about beeing able to calculate the max for many integers.

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

I just remembered where I learned about that function, in this course on convex optimization that unfortunately I never had the opportunity to finishing it but is really good.

load more comments (2 replies)
load more comments (2 replies)