6 ms·
What I've Learned About Formal Methods in Half a Year
- rqtwteye 4y agoI wonder if AI systems like ChatGPT will be helpful in this area. Something that’s able to track all requirements of a system and understands the code enough to validate it against the requirements.
- stfutechbros 4y agoChatGPT is basically the opposite of formal verification... It itself is not verified, and its results are so inaccurate that you need to verify them anyway.
- cartoonfoxes 4y agoMost definitely. I've been playing with using ChatGPT to generate proof texts in Isabelle/HOL, since it lets me verify the correctness of the output before code generation.
- Taikonerd 4y agoI've had the same thought. Formally proven code can give powerful security assurances (cf. Project Everest[1]), but it's also very, very labor-intensive. I've heard rules of thumb like, "100x as much time to prove the software correct as to write it in the first place." If LLM systems are going to give us a virtual army of programmers, I think formally proving more systems software (device drivers, browser engines, etc.) would be a great use of their time. [1]: https://www.microsoft.com/en-us/research/blog/project-everest-advancing-the-science-of-program-proof/ https://www.microsoft.com/en-us/research/blog/project-everes...
- deterministic 4y agoCompCert is a proven correct C compiler proven correct by a very small team in a few years. Used by Airbus for avionics software. GCC after 25 years of work still has bugs.
- AlotOfReading 4y agoI've had extremely poor results attempting to get current LLMs to generate proofs, for code or otherwise.
- ogogmad 4y agoCombining it with AutoGPT (or the ideas it's based on) and a formal prover like Lean might be the answer. Have you tried? Basically, if you don't allow GPT to iteratively write, execute, criticise and then correct its code, you won't get good results.
- rqtwteye 4y agoI think it probably needs to be a specialized combination of LLM and hardcoded knowledge.
- markusde 4y agoYeah, I'm cautiously excited about how AI and FM might work together. I don't think LLM's can ever be trusted to verify programs itself, but anything which can reduce the annotation overhead for programmers is a super useful thing!
- rqtwteye 4y agoI don't think a pure LLM approach will work (or maybe it will, who knows?). I am more thinking of a hybrid that combines LLM or other AI with some hardcoded knowledge for this domain
- prisonguard 4y agoI've always thought theorem proving to be about proving equality of the function and the result. Lean to me is not only obscure but unapproachable by someone from a non-mathematical background. Take this snippet for instance theorem nat.add_comm : ∀ (n m : ℕ), n + m = m + n := λ (n m : ℕ), nat.brec_on m (λ (m : ℕ) (_F : nat.below (λ (m : ℕ), ∀ (n : ℕ), n + m = m + n) m) (n : ℕ), nat.cases_on m (λ (_F : nat.below (λ (m : ℕ), ∀ (n : ℕ), n + m = m + n) 0), id_rhs (n + 0 = 0 + n) (eq.symm (nat.zero_add n))) (λ (m : ℕ) (_F : nat.below (λ (m : ℕ), ∀ (n : ℕ), n + m = m + n) (nat.succ m)), id_rhs (n + (m + 1) = nat.succ m + n) (eq.symm (nat.succ_add m n) ▸ congr_arg nat.succ (_F.fst.fst n))) _F) n If we want to democratise formal methods and theorem proving, we should lean towards natural language expressions of proof and not mathematical expressions and greek characters. This is the path that languages such as Idris https://www.idris-lang.org/ https://www.idris-lang.org/ have taken
- tsimionescu 4y agoI don't think you have any chance of approaching formal methods if the notation is a stumbling block. The difficulty and verbosity of formal proofs is huge even with the very concise mathematical notation. And learning the notation itself is a very small stumbling block compared to learning the actual theorems and logic that you need to use. So while I am not a fan of mathematical notation for general programming (which is often quite un-mathematical in fact) formal proofs are a place where this notation absolutely shines. I can't even imagine how much uglier the proof above would become if you had to replace `∀ (n : ℕ)` with something like `for any natural number n`.
- sirwhinesalot 4y agoForall (n: Nat) Is perfectly reasonable. If conciseness was that important theorem provers would have syntax like APL.
- tsimionescu 4y agoWhy is forall any less formal than ∀? Or Nat less formal than ℕ? Especially when these are symbols that most will have learned in high school?
- jgeada 4y agoIf I had complete enough specifications for any interesting program that formal methods would be interesting, I think I would just be easier to hit compile on that spec. Yes, there are a subset of interesting bugs related to edge cases, but the real problematic bugs are when what the software does does not match what was expected, even if nobody really could articulate what was expected in the first place. The art of software engineering isn't the coding, it is asking enough questions to know what the actual problem to be solved is.
- drewcoo 4y agoI think the interesting part isn't in a single component's edge cases at all, but in how complex webs of many, many things interact. I've yet to see a hard debugging problem that didn't boil down to something like, in the best of possible worlds: "component A expected something to meet promise FOO when it calls component B, because that's obvious, right?" combined with "component B just passes requests and routes results, dude, component C is messed up" combined with "component C never promised that behavior and if you look at our spec it even says so!" That's an example of your "does not match what was expected" case. I think most of formal methods is an academic waste of time. Whether they take a more formal or a more practical approach, I see high value in contract tests and data flow analysis because they're more likely to catch the bugs that cross Conway's code/org boundaries.
- im_down_w_otp 4y agoThis kind of, “Just what the heck in this pile of parts is impacting the other stuff and how is the other stuff impacting this part?” was precisely the angle we took with our V&V tools.
- jgeada 4y agoYes, this! What would be helpful is if formal methods were powerful enough to be able to prove contracts and assertions about expectations and invariants; however, all formal systems I've experienced are not powerful enough to do this at scale in any interesting program, not without spending way more time reconstructing the entire system in the formal world, with the attendant likelihood of introducing spec bugs in that reconstruction. It is entirely different in the world of hardware, where the specification in many cases is the RTL and the thing being proved is the, supposedly identical, physical implementation.
- whatever1 4y agoI like there is us who like formal methods and guarantees of correctness for our code. And then there are the others who now generate approximately code with large language models that mostly runs. They are winning.
- cgio 4y agoIt’s a repeat of search & hope/trust (Google) vs define and query (semantic web) and yes they are winning and will win. Fine tuning your scope for extreme accuracy might be less efficient a strategy than fine tuning your loader for extreme speed
- mcguire 4y agoIn most situations, a half-assed answer quickly will a beat a good answer slowly. Most. ""Software should be reliable."" Reliability is not usually worth the effort. Most software is not used enough, or not important enough, to make any effort worthwhile. In almost all systems, errors are created at every step and propagate through the system routinely without causing problems.
- specialist 4y agoShip early, ship often. First to ship wins. Flood the zone. Often phrased as "worse is better." Like, hypothetically, imagine you spent two whole weeks designing and implementing a new programming language, which was guaranteed to be installed on millions of computers overnight. Any language which took three weeks to finish, like wasting a week testing, would be DOA. Like how the (brood parasite) cuckoo chick hatches early and then murders all the other chicks.
- intrepidhero 4y agoBut when the robot uprising comes our killbots will be unstoppable terminators and their killbots will explode the first time they encounter a set of stairs.
- nextos 4y agoWhen the latest incarnation of ChatGPT was out, I had the same thought. However, I then became convinced there might be some synergy between both. Imagine a programming system where you can specify little components using Hoare or Separation Logic, i.e. pre/postconditions. An engineer could spend his effort specifying little components, but code and proof generation can be handled by GPT. Actually, many tasks can be offloaded to a SAT/SMT solver. Lots of verification and synthesis efforts already do the last bit, offloading to SAT/SMT solver. This would be a win-win. Formal methods would become cheaper to use, and software would become built using rigorous engineering.
- jderick 4y agoWe use formal at Apple to verify hardware. We are always looking for good people in this area.
- rsrsrs86 4y agoDo you have more to share? I use Alloy at work and research and would love to learn about how Apple uses FM.
- ta1748 4y agoThis is the easiest way to get an idea for what is happening and what experience is needed: https://jobs.apple.com/en-us/search?search=formal&sort=relevance&location=united-states-USA https://jobs.apple.com/en-us/search?search=formal&sort=relev... There are several different niches, and HW formal is likely using different tools and methods than SW formal, though there is overlap. Anyways there is room for a wide range of experience/skills/background in a variety of different areas.
- jderick 4y agoApple is pretty tight lipped about revealing the details of our work. Formal is a bit of a niche area, but you can find some info online. Here is a course taught at UT with some slides from guest lecturers from industry that looks like a decent overview: https://www.cerc.utexas.edu/~jaa/verification/ https://www.cerc.utexas.edu/~jaa/verification/ Also, the main conference in the area is FMCAD, you can find a lot of related work there. More recently the conference has moved more towards software, but if you look at some of the older proceedings you can find a lot of hardware related stuff. https://www.fmcad.org/ https://www.fmcad.org/ There is decent amount of overlap between formal for hardware and software, so if you study one you will likely have enough background to get started in the other.
- ajb 4y agoNot at apple: The following is about 10 years out of date, would be interesting to know what's changed: 10 years ago formal had just started to be viable in run of the mill semiconductor verification (as opposed to throwing a bunch of specialist PhD grads at the problem); Jasper Gold was the first tool I heard of that worked well enough. pre-formal, the approach was to write a bunch of tests with input stimulators and validity checkers and/or assertions, and then work on the stimulators until you reached 100%coverage (signing off the cases that couldn't happen). That's not just line coverage, but each branch of an if, each component of a boolean expression must toggle, each bit of a signal must toggle, etc. Reaching 100% coverage was a tedious exercise so the first use of formal was as a sumplement, to find the last,most difficult test cases that completed your coverage (or prove that the cases were impossible). The next use was to try and prove directly that assertions or test failures could not occur, or provide a counterexample. this is all based on the tool being able to read low level verilog or systemC code. What it couldn't do at the time, which would be interesting to know if it can now, is as follows: Often, you actually have a higher level model of the behavior of your system. The RTL code is written to have the same behavior (manually, because it takes expertise to choose RTL code that will work efficiently). Ideally, provers would simply prove that your RTL has the same behavior.
- deleted 4y ago[deleted]
- mcguire 4y agoI'm not sure if the author is here, or if my comment attempt was successful. So, can I suggest you take a look at a third leg of the formal methods stool? If you are familiar with C, check out Frama-C (https://frama-c.com/ https://frama-c.com/) and the WP and RTE plugins. The approach is based on Tony Hoare and EWD's axiomatic semantics (https://en.wikipedia.org/wiki/Hoare_logic https://en.wikipedia.org/wiki/Hoare_logic). It does not have a good memory management story, as far as I know, but is very good for demonstrating value correctness (RTE automatically generates assertions for numeric runtime errors, for example) and many memory errors. If you are familiar with Ada, check out SPARK (https://www.adacore.com/about-spark https://www.adacore.com/about-spark), which is similar to Frama-C but has a much better interface in the AdaCore GNAT toolkit and IDE. Both work similarly: Assertions in normal Ada or C code as well as the code itself are translated into SMT statements and fed to a SMT solver to find counterexamples---errors. I have some blog posts from several years ago about Frama-C:https://maniagnosis.crsr.net/tags/applied%20formal%20logic.html https://maniagnosis.crsr.net/tags/applied%20formal%20logic.h... (And I really should get back into it; it's a lot of fun.) If you are not familiar with Ada or C, Dafny (https://dafny.org/ https://dafny.org/) is another option based on .NET and devoleped at Microsoft. It seems nigh-on perfect for this approach. (The language uses a garbage collector.) At the time I was looking, there was little documentation on Dafny, but that seems to have improved.
- tsarfox 4y agoSorry to hear you had issues with my comment system. Comments are invisible until I manually approve them, but I'm not seeing anything new in the database right now. Did you get any sort of error code? The system should let you know if e.g., the answer to the captcha was wrong. I do mention SPARK at the end of the article. I'm not familiar with Frama-C so I'll check that and your blog posts out. Thanks for sharing!
- mcguire 4y agoGot a blank page. Sorry I missed the mention of SPARK. TLA+, although I haven't fiddled with it as much, is more similar to Alloy than anything else. SPARK actually works on Ada code.
- SamvitJ 4y agoWhen writing about a new topic (e.g., formal methods), it's generally better to keep other aspects of the presentation (e.g., code samples) simple and familiar to the reader. Would have preferred the code samples to not be in Lisp (ostensibly also new to the reader, if formal methods are), and also more sparingly used.
- scscsc 4y agoTo those wondering if there will be a successful "marriage" between popular incarnations of AI, like ChatGPT, and FM: no, at least not in the sense you would expect. Sure, ChatGPT will successfully manage to find formal proofs that have been done before. But synthesising proofs from scratch is NP-complete for the simplest proofs (or worse for more interesting cases), and LLMs are simply not clever enough to do it (except in cases where the proof has been seen before). It could be possible to integrate an SMT solver with a LLM to make this work, but the core difficulty of the FM task will then be solved by the SMT solver.
- trenchgun 4y agoThere is ongoing work trying to get that marriage to work