Live data from Hacker News

Show HN: Formally verified polygon intersection – Opus 4.8 oneshots, prev failed

github.com

21–26 of 26 posts

Re: Show HN: Formally verified polygon intersection – Opus 4.8 oneshots, prev failed

#22
post #21

I'm not sure if the feature is intersection or the use of AI to write it... Polygon intersection is a well known thing. Video games and geographic information systems (topology) do that for decades. Tell me more, what should I look at ?

Sure, what the program does is not interesting by itself, neither is that you can use AI to create programs to do polygon intersection.

The main feature, that I hope is interesting in this submission, is that the program is formally verified and how I used formal verification together with AI to create it.

Formal verification means that a mathematical proof is provided that the program satisfies a specification. And that proof is checked automatically by a deterministic system, the lean checker, which we can trust, in constrast to error prone LLMs.

I gave the agent a formal specification m1.interior ∩ m2.interior = result.interior and it produced an implementation together with such a formal proof. With this approach we can treat much of the work of the agent as a black box, which we don't have to review to judge correctness.

I think the project shows that as AI agents get more capable, an approach like this is starting to get practical for certain problems like polygon intersection for which there is a concise way to specify the problem.

Re: Show HN: Formally verified polygon intersection – Opus 4.8 oneshots, prev failed

#23
post #22
post #21

I'm not sure if the feature is intersection or the use of AI to write it... Polygon intersection is a well known thing. Video games and geographic information systems (topology) do that for decades. Tell me more, what should I look at ?

Sure, what the program does is not interesting by itself, neither is that you can use AI to create programs to do polygon intersection. The main feature, that I hope is interesting in this submission, is that the program is formally verified and how I used formal verification together with AI to create it. Formal verification means that a mathematical proof is provided that the program satisfies a specification. And…

Nice I get it now. And from your usage, a natural question is how much effort was put by the AI to find the verified answer ? Did it need to run significantly longer or less that without these constraints ?

Re: Show HN: Formally verified polygon intersection – Opus 4.8 oneshots, prev failed

#24
How hard would it be to extend this proof to real coordinates? Is that ‘just’ a matter of formalizing some known, tedious math, or would it require new work?

For example, if one allows one coordinate of one corner to be non rational, I think the set of potential output coordinates used would be a subset of the reals (depending on the value of that coordinate), and to my (possibly very bad) intuition, formalizing that subset doesn’t feel like a hard problem.

Allowing two of such real points would make things more tedious, potentially way more tedious, but again, doesn’t feel like it would be impossible to handle.

Re: Show HN: Formally verified polygon intersection – Opus 4.8 oneshots, prev failed

#25
post #23
post #22

Earlier quoted context omitted.

Sure, what the program does is not interesting by itself, neither is that you can use AI to create programs to do polygon intersection. The main feature, that I hope is interesting in this submission, is that the program is formally verified and how I used formal verification together with AI to create it. Formal verification means that a mathematical proof is provided that the program satisfies a specification. And…

Nice I get it now. And from your usage, a natural question is how much effort was put by the AI to find the verified answer ? Did it need to run significantly longer or less that without these constraints ?

Yes, it runs significantly longer.

Opus 4.8 ran autonomously for about 8 hours to provide program and proof of correctness, given the formal specification. And in previous experiments, Opus 4.7 failed and I was only able to do it using that model when I cut the work for the agents in smaller steps.

Much of the work the agent is to provide the proof of correctness. The upside is that less time is needed for human review and we can guarantee the absence of bugs that might be expensive when they come up in production.

Historically formal verification was only worth it for very critical software. In the readme I reference related work from NASA, that implemented and verified a different algorithm concerned with polygons, with the intended application to compute keep out zones for autonomous vehicles. This was 2021 before capable LLMs and in the paper they mention that they manually wrote 700 lemmas to produce such a formal proof manually. I hope that as it gets cheaper now, formal verification is used more widely.

Re: Show HN: Formally verified polygon intersection – Opus 4.8 oneshots, prev failed

#26
post #24

How hard would it be to extend this proof to real coordinates? Is that ‘just’ a matter of formalizing some known, tedious math, or would it require new work? For example, if one allows one coordinate of one corner to be non rational, I think the set of potential output coordinates used would be a subset of the reals (depending on the value of that coordinate), and to my (possibly very bad) intuition, formalizing that…

There are two things here: The proof and how you would represent that in a program that you actually can run.

From the math side, I am confident that the construction and proof can be extended to the real numbers and that can be formalized in lean with minimal changes in the existing proof. (Mathematically speaking, we can replace the rationals with any ordered field and the proof should run through.)

I chose to model the problem with rational numbers because the intersections of polygons with rational coordinates have rational coordinates and rational numbers can easily be represented in the computer.

To have a computable implementation with real numbers, you have to make some choice about which part of the real numbers you want to be able to represent in the computer. For example if sqrt(2) and sqrt(3) is important to you, I think you can have a program that can represent them if they occur in any input coordinates and can represent any resulting coordinates exactly symbolically besides the rational numbers (I think this requires minimal changes in the code, the required lean machinery to work with such numbers can be separated from the geometrical code), but a program can’t be able to represent all real numbers exactly since there are too many of them.

Another interesting direction to take this would be to allow spline segments instead of line segments, since intersections of splines with rational coordinates can have non rational coordinates, but I think can still be represented exactly in the computer. This would require a bigger change and would be interesting geometrically.

Post reply on HN