9 ms·
I once published a method for finding the closest distance between an ellipse and a point on SO: https://stackoverflow.com/questions/22959698/distance-from-give
by 0xfaded 9mo ago
I once published a method for finding the closest distance between an ellipse and a point on SO: https://stackoverflow.com/questions/22959698/distance-from-given-point-to-given-ellipse#answer-46007540 https://stackoverflow.com/questions/22959698/distance-from-g...
I consider it the most beautiful piece of code I've ever written and perhaps my one minor contribution to human knowledge. It uses a method I invented, is just a few lines, and converges in very few iterations.
People used to reach out to me all the time with uses they had found for it, it was cited in a PhD and apparently lives in some collision plugin for unity. Haven't heard from anyone in a long time.
It's also my test question for LLMs, and I've yet to see my solution regurgitated. Instead they generate some variant of Newtons method, ChatGPT 5.2 gave me an LM implementation and acknowledged that Newtons method is unstable (it is, which is why I went down the rabbit hole in the first place.)
Today I don't know where I would publish such a gem. It's not something I'd bother writing up in a paper, and SO was the obvious place were people who wanted an answer to this question would look. Now there is no central repository, instead everyone individually summons the ghosts of those passed in loneliness.
- emmelaich 9mo agoYou should write it up and submit it to some journal officially. Doesn't matter if it mostly duplicates your own (technically unpublished) work.
- jvanderbot 9mo agoYou can write a paper, submit the arxiv, and you can also make a blog post. At any rate, I agree - SO was (is?) a wonderful place for this kind of thing. I once had a professor mention that they knew me from SO because I posted a few underhanded tricks to prevent an EKF from "going singular" in production. That kind of community is going to be hard to replace, but SO isnt going anywhere, you can still ask a question and answer your own question for permanent, searchable archive.
- paulgerhardt 9mo agoI would imagine the endorsement requirement reduces submissions by a few orders of magnitude.
- marcosdumay 9mo agoAt this point SO seems harder to publish into than arxiv.
- DrewADesign 9mo agoIf you had used the search feature you’d realize that many similar comments have already been posted on HN. Vote to close.
- rerdavies 9mo agoIf only those who voted to close would bother to check whether the dup/close issue was ACTUALLY a duplicate. If only there were (substantial) penalties for incorrectly dup/closing. The vast majority of dup/closes seem to not actually be dup/closes. I really wish they would get rid of that feature. Would also prevent code rot (references to ancient versions of the software or compiler you're interested in that are no longer relevant, or solutions that have much easier fixes in modern versions of the software). Not missing StackOverflow in the least. It did not age well. (And the whole copyright thing was just toxically stupid).
- DrewADesign 9mo agoI think they should have had some mechanism that encouraged people to help everybody, including POSITIVELY posting links to previously answered questions, and then only making meaningfully unique ones publicly discoverable (even in the site search by default), afterwards. Instead, they provided an incentive structure and collection of rationales that cultivated a culture of hall monitors with martyr complexes far more interested in punitively enforcing the rules than being a positive educational resource.
- zellyn 9mo agoPlease, start a blog! Hugo + GitHub hosting makes it laughably simple. (Or pick a different stack; that’s just mine.) Even if you’re worried it’ll be sparse and crappy, isn’t an Internet full of idiosyncratic personal blogs what we all want? If you want help or encouragement, reach out: zellyn@ most places
- 0xfaded 9mo agoIt's been a long time, but here is the writeup https://blog.chatfield.io/simple-method-for-distance-to-ellipse/ https://blog.chatfield.io/simple-method-for-distance-to-elli...
- Aurornis 9mo ago> Please, start a blog! The second sentence of the SO post is a link to their blog where it was posted originally. The blog is not a replacement for the function SO served.
- erikig 9mo agoThe various admonitions to publish to a personal blog, while encouraging, don't really get at the 0xfaded's request which I'd summarize as follows: With no one asking questions these technical questions publicly, where, how and on what public platform will technical people find the problems that need solving so they can exercise their creativity for the benefit of all?
- Forgeties79 9mo agoSeriously where will we get this info anymore? I’ve depended on it for decades. No matter how obscure, I could always find a community that was talking about something I needed solved. I feel like that’s getting harder and harder every year. The balkanization of the Internet + garbage AI slop blogs overwhelming the clearly declining Google is a huge problem.
- HumblyTossed 9mo agoUsenet?
- Forgeties79 9mo agoI guess? I feel like it’s too small now. It can’t cover all my interests
- seb1204 9mo agoKeep using SO?
- Forgeties79 9mo agoWhen I grew up shakes fist at clouds I had a half dozen totally independent forums/sites to pull on for any interest or hobby no matter how obscure. I want it back!
- wiether 9mo agoThe discoverability, both from the outside and within is absolute trash, but the closest I find of those old forums nowadays are Discord servers.
- davchana 9mo agoI too, around 2012 was too much active on so, in fact, it had that counter thing continuously xyz days most of my one liners, or snippets for php are still the highest voted answers. Even now when sometimes I google something, and an answer comes up, I realize its me who asked the same question and answered it too.
- banku_brougham 9mo agoI have had this experience -- twice with the same answer. There is nothing so amusing in quite this way.
- googlehater 9mo agoI often forget just how much smaller and less siloed the internet was just ~13 years ago.
- jmux 9mo agoThis is a really method for solving that problem! I wouldn’t have thought to use the tangents but that makes perfect sense
- qwertox 9mo agoWhy did SO decide to do that to us? to not invest in ai and then, iirc, claim our contributions their ownership. i sometimes go back to answers i gave, even when answered my own questions.
- socalgal2 9mo agoDecide to do what? SO didn't claim contributions. They're still CC-BY-SA https://stackoverflow.com/help/licensing https://stackoverflow.com/help/licensing AFAICT all they did is stop providing dumps. That doesn't change the license. I was very active, In fact I'm actually upset at myself for spending so much time there. That said, I always thought I was getting fair value. They provided free hosting, I got answers and got to contribute answers for others.
- sky2224 9mo agoThis is a perfect example of an element of Q&A forums that is being lost. Another thing that I don't think we'll see as much of anymore is interaction from developers that have extensive internal knowledge on products. An example I can think of was when Eric Lippert, a developer on the C# compiler at the time, responded to a question about a "gotcha" in the language: https://stackoverflow.com/a/8899347/10470363 https://stackoverflow.com/a/8899347/10470363 Developer interaction like that is going to be completely lost.
- Philpax 9mo agoThe second answer cites Lippert's pre-existing blog post on the subject: https://ericlippert.com/2009/11/12/closing-over-the-loop-variable-considered-harmful-part-one/ https://ericlippert.com/2009/11/12/closing-over-the-loop-var... I agree that there will be some degradation here, but I also think that the developers inclined to do this kind of outreach will still find ways to do it.
- tempest_ 9mo agoThis type of thing often lives in the issues / discussion tab of a github repo now a days, for better and worse.
- dimator 9mo agoYuck. I don't know if it's just me, but something feels completely off about the GH issue tracker. I don't know if it's the spacing, the formatting, or what, but each time it feels like it's actively trying to shoo me away. It's whatever the visual language equivalent of "low signal" is.
- NitpickLawyer 9mo agoStill gh issues are better than some random discord server. The fact that forums got replaced by discord for "support" is a net loss for humanity, as discord is not searchable (to my knowledge). So instead of a forum where someone asks a question and you get n answers, you have to visit the discord, and talk to the discord people, and join a wave channel first, hope the people are there, hope the person that knows is online, and so on.
- Neywiny 9mo agoLooks like solid code. My only gripe is the shadowing of x. I would prefer to see `for _ in range`. You do redefine it immediately so it's not the most confusing, but it could trip people up especially as it's x and not i or something.
- 0xfaded 9mo agoHahaha thanks, I never noticed that. If I ever print it out and frame it I'll be sure to fix it
- userbinator 9mo agoThat algorithm reminds me of raymarching signed distance functions.
- mmaaz 9mo agoVery cool!
- namanyayg 9mo agoI had a similar beautiful experience where an experienced programmer answered one of my elementary JavaScript typing questions when I was just starting to learn programming. He didn't need to, but he gave the most comprehensive answer possible attacking the question from various angles. He taught me the value of deeply understanding theoretical and historical aspects of computing to understand why some parts of programming exist the way they are. I'm still thankful. If this was repeated today, an LLM would have given a surface level answer, or worse yet would've done the thinking for me obliviating the question in the first place. I wrote a blog post about my experience at https://nmn.gl/blog/ai-and-learning https://nmn.gl/blog/ai-and-learning
- cinntaile 9mo agoYou can prompt the LLM to not just give you the answer. Possibly even ask it to consider the problem from different angles but that may not be helpful when you don't know what you don't know.
- matsemann 9mo agoHad a similar experience. Asked a question about a new language feature in java 8 (parallell streams), and one of the language designers (Goetz) answered my question about the intention of how to use it. An LLM couldn't have done the same. Someone would have to ask the question and someone answer it for indexing by the LLM. If we all just ask questions in closed chats, lots of new questions will go unanswered as those with the knowledge have simply not been asked to write the answers down anywhere.
- achille 9mo agothanks for sharing that, it was simple, neat, elegant. this sent me down a rabbit hole -- I asked a few models to solve that same problem, then followed up with a request to optimize it so it runs more efficiently. chatgpt & gemini's solutions were buggy, but claude solved it, and actually found a solution that is even more efficient. It only needs to compute sqrt once per iteration. It's more complex however. yours claude ------------------------------ Time (ns/call) 40.5 38.3 sqrt per iter 3 1 Accuracy 4.8e-7 4.8e-7 Claude's trick: instead of calling sin/cos each iteration, it rotates the existing (cos,sin) pair by the small Newton step and renormalizes: // Rotate (c,s) by angle dt, then renormalize to unit circle float nc = c + dt*s, ns = s - dt*c; float len = sqrt(nc*nc + ns*ns); c = nc/len; s = ns/len; See: https://gist.github.com/achille/d1eadf82aa54056b9ded7706e8f56760 https://gist.github.com/achille/d1eadf82aa54056b9ded7706e8f5... p.s: it seems like Gemini has disabled the ability to share chats can anyone else confirm this?
- 0xfaded 9mo agoThanks for pushing this, I've never gone beyond "zero" shotting the prompt (is it still called zero shot with search?) As a curiosity, it looks like r and q are only ever used as r/q, and therefore a sqrt could be saved by computing rq = sqrt((rxrx + ryry) / (qxqx + qyqy)). The if q < 1e-10 is also perhaps not necessary, since this would imply that the ellipse is degenerate. My method won't work in that case anyway. For the other sqrt, maybe try std::hypot Finally, for your test set, could you had some highly eccentric cases such as a=1 and b=100 Thanks for the investigation:) Edit: BTW, the sin/cos renormalize trick is the same as what tx,ty are doing. It was pointed out to me by another SO member. My original implementation used trig functions
- achille 9mo agoNice, that worked. It's even faster. yours yours+opt claude --------------------------------------- Time (ns) 40.9 36.4 38.7 sqrt/iter 3 2 1 Instructions 207 187 241 Edit: it looks like the claude algorithm fails at high eccentricities. Gave chatgpt pro more context and it worked for 30min and only made marginal improvement on yours, by doing 2 steps then taking a third local step. https://gist.github.com/achille/23680e9100db87565a8e67038797b27d https://gist.github.com/achille/23680e9100db87565a8e67038797...
- eviks 9mo ago> Today I don't know where I would publish such a gem. In the same blog you published it originally, then mentioning it on whatever social media site you use? So same?
- techsystems 9mo agoAmazing work!
- mightybyte 9mo agoSounds like this should live in Wikipedia somewhere on https://en.wikipedia.org/wiki/Ellipse...or https://en.wikipedia.org/wiki/Ellipse...or maybe a related but more CS focused related page.
- weatherlite 9mo agoI can relate. I used to have a decent SO profile (10k+ reputation, I know this isnt crazy but it was mostly on non low hanging fruit answers...it was a grind getting there). I used to be proud of my profile and even put it in my resume like people put their Github. Now - who cares? It would make look like a dinosaur sharing that profile, and I never go to SO anymore.
- rerdavies 9mo agoReddit is my current go-to for human-sourced info. Search for "reddit your question here". Where on reddit? Not sure. I don't post, tbh, but I do search. Has the added benefit of NOT returning stackoverflow answers, since StackOverflow seems to have rotted out these days, and been taken over by the "rejection police".
- lbj 9mo agoReally great write-up, thanks for sharing it again!
- RustyRussell 9mo agoOn the other hand, I once implemented something to be told later it was novel and probably the optimal solution in the space. An AI might be more likely to find it...
- eru 9mo agoI have a similar story about an interesting little advance in computing that I haven't formally published anywhere, but it's at https://cs.stackexchange.com/a/171695/50292 https://cs.stackexchange.com/a/171695/50292 The question boils down to: can you simulate the bulk outcome of a sequence of priority queue operations (insert and delete-minimum) in linear time, or is O(n log n) necessary. Surprisingly, linear time is possible.
- PeterStuer 9mo agoSO in 2013 was a different world from the SO of the 2020's. In the latter world your post would have been moderator classified as 'duplicate' of some basic textbook copy/pasted method posted by a karma grinding CS student and closed.
- eitland 9mo agoMy experience as well: Stack Overflow used to (in practice) be a place to ask questions and get help and also help others. At some point it became all about some mission and not only was it not as useful anymore but it also became a whole lot less fun.
- kwakubiney 9mo agoNaive question maybe but how haven’t the models been trained on your answer if it’s on SO?
- wesammikhail 9mo agoModels are NOT search engines. Even if LLMs were trained on the answer, that doesn't mean they'll ever recommend it. Regardless of how accurate it may be. LLMs are black box next token predictors and that's part of the issue.
- scirob 9mo agoHas anyone tried building a modern Stack Overflow that's actually designed for AI-first developers? The core idea: question gets asked → immediately shows answers from 3 different AI models. Users get instant value. Then humans show up to verify, break it down, or add production context. But flip the reputation system: instead of reputation for answers, you get it for catching what's wrong or verifying what works. "This breaks with X" or "verified in production" becomes the valuable contribution. Keep federation in mind from day one (did:web, did:plc) so it's not another closed platform. Stack Overflow's magic was making experts feel needed. They still do—just differently now.
- cpa 9mo agoAm I reading an AI trying to trick me into becoming its subordinate?
- imcritic 9mo agoYeah, they didn't even bother to suggest paying you with tokens for the job well done! The audacity!
- scirob 9mo agohehe yea this existing of course. like these guys https://yupp.ai/ https://yupp.ai/ they have not announced the tokens but there are points and they got all their VC money from web3 VC. I'm sure there are others trying
- dataviz1000 9mo agoIn 2014, one benefit of Stack Overflow / Exchange is a user searching for work can include that they are a top 10% contributor. It actually had real world value. The equivalent today is users with extensive examples of completed projects on Github that can be cloned and run. OP's solution if contained in Github repositories will eventually get included in a training model. Moreover, the solution will definitely be used for training because it now exists on Hacker News.
- baq 9mo agoIf you ask me your blog post is basically a paper, I’d publish to arxiv.
- OJFord 9mo agoI don't disagree completely by any means, it's an interesting point, but in your SO answer you already point to your blog post explaining it in more detail, so isn't that the answer, you'd just blog about it and not bother with SO? Then AI finding it (as opposed to already trained well enough on it, I suppose) will still point to it as did your SO answer.
- noduerme 9mo agoThat's pretty nice ;) I once wrote this humdinger, that's still on my mostly dead personal website from 2010... one of my proudest bits of code besides my poker hand evaluator ;) The question was, how do you generate a unique number for any two positive integers, where x!=y, such that f(x,y) = f(y,x) but the resulting combined id would not be generated by any other pair of integers. What I came up with was a way to generate a unique key from any set of positive integers which is valid no matter the order, but which doesn't key to any other set. My idea was to take the radius of a circle that intersected the integer pair in cartesian space. That alone doesn't guarantee the circle won't intersect any other integer pairs... so I had to add to it the phase multiple of sine and cosine which is the same at those two points on the arc. That works out to: (x^2+y^2)+(sin(atan(x/y))*cos(atan(x/y))) And means that it doesn't matter which order you feed x and y in, it will generate a unique float for the pair. It reduces to: x^2+y^2+( (x/y) / (x^2+y^2) ) To add another dimension, just add it to the process and key it to one of the first... x^2+y^2+z^2+( (x/y) / (x^2+y^2) )+( (x/z) / (x^2+z^2) )
- bazzargh 9mo agoIt looks like you have typos? (x^2+y^2)+(sin(atan(x/y))*cos(atan(x/y))) reduces to x^2+y^2+( (x/y) / (x^2/y^2 + 1) ) - not the equation given? Tho it's easier to see that this would be symmetrical if you rearrange it to: x^2+y^2+( (xy) / (x^2+y^2) ) Also, if f(x,y) = x^2+y^2+( (x/y) / (x^2+y^2) ) then f(2,1) is 5.2 and f(1,2) is 5.1? - this is how I noticed the mistake. (the other reduction gives the same answer, 5.4, for both, by symmetry, as you suggest) There's a simpler solution which produces integer ids (though they are large): 2^x & 2^y. Another solution is to multiply the xth and yth primes. I only looked because I was curious how you proved it unique!
- noduerme 9mo agoHhhhmm. Ok. So I invented this solution in 2009 at what you might call a "peak mental moment", by a pool in Palm Springs, CA, after about 6 hours of writing on napkins. I'm not a mathematician. I don't think I'm even a great programmer, since there are probably much better ways of solving the thing I was trying to solve. And also, I'm not sure how I even came up with the reduction; I probably was wrong or made a typo (missing the +1?), and I'm not even certain how I could come up with it again. 2^x & 2^y ...is the & a bitwise operator...???? That would produce a unique ID? That would be very interesting, is that provable? Primes take too much time. The thing I was trying to solve was: I had written a bitcoin poker site from scratch, and I wanted to determine whether any players were colluding with each other. There were too many combinations of players on tables to analyze all their hands versus each other rapidly, so I needed to write a nightly cron job that collated their betting patterns 1 vs 1, 1 vs 2, 1 vs 3... any time 2 or 3 or 4 players were at the same table, I wanted to have a unique signature for that combination of players, regardless of which order they sat in at the table or which order they played their hands in. All the data for each player's action was in a SQL table of hand histories, indexed by playerID and tableID, with all the other playerIDs in the hand in a separate table. At the time, at least, I needed a faster way to query that data so that I could get a unique id from a set of playerIDs that would pull just the data from this massive table where all the same players were in a hand, without having to check the primary playerID column for each one. That was the motivation behind it. It did work. I'm glad you were curious. I think I kept it as the original algorithm, not the reduced version. But I was much smarter 15 years ago... I haven't had an epiphany like that in awhile (mostly have not needed to, unfortunately).
- fho 9mo agoThen let me quickly say: thank you! I used that algorithm three times in different projects during my academic "career" :-)