thanks 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;
Thanks 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
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.
I ran some analysis on the source image — this is almost certainly AI-generated. In addition to the visual markers others noted (no photography in federal court, nonsensical positioning), here's what comes up in the original image:
Filename: ..._simple_compose_01kdcxamjmekery2m9tay43szn.png
- "simple_compose" + LSB common (e.g ideogram) output
Resolution: 1536x1024
- Exact native output of GPT-image-1, Gemini/Imagen, Flux models
PNG encoder fingerprint: 0x78 0xDA | single IDAT | 94.7% Average filter
- Matches PIL/Pillow with optimize=True
Steganographic watermark:
- LSB entropy: 3.0/3.0 (maximum)
- Bits 0-3 of RGB channels filled with encrypted payload
- ~1.77 MB of pseudorandom data embedded
The analysis and tools were most definitely ai-aided, but this was done with homegrown forensics tooling, and about an hour of labor that involved cc, gemini (to check for synthid), chatgpt + a lot more. I also signed up for ideogram and generated more images to try and replicate the output:
- e.g: https://ideogram.ai/g/fcqp-qTlQV-moS-OuhebhQ/1 (although I refused to pay for ideogram so I could not get a png output, only jpg)
The paper describes a split Alvarez (Lohmann) lens [1,2] with a phase modulator between them. I didn't do the math, but it looks like the phase modulator is optically equivalent to a mechanical shift of the Alvarez lenses over regions of the field of view. Alvarez lenses have higher aberrations, and are relatively bulky, compared to normal lenses. AR was referenced in the paper, but this lens will be hard to make compact, and have great image quality, over large fields of view.
What's the point of building skills like this?
reply