<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Formal Methods on Hillel Wayne</title>
    <link>https://www.hillelwayne.com/tags/formal-methods/</link>
    <description>Recent content in Formal Methods on Hillel Wayne</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 17 Jun 2024 00:00:00 +0000</lastBuildDate>
    
	<atom:link href="https://www.hillelwayne.com/tags/formal-methods/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Composing TLA&#43; Specifications with State Machines</title>
      <link>https://www.hillelwayne.com/post/composing-tla/</link>
      <pubDate>Mon, 17 Jun 2024 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/composing-tla/</guid>
      <description>Last year a client asked me to solve a problem: they wanted to be able to compose two large TLA+ specs as part of a larger system. Normally you&amp;rsquo;re not supposed to do this and instead write one large spec with both systems hardcoded in, but these specs were enormous and had many internal invariants of their own. They needed a way to develop the two specs independently and then integrate them with minimal overhead.</description>
    </item>
    
    <item>
      <title>Don&#39;t let Alloy facts make your specs a fiction</title>
      <link>https://www.hillelwayne.com/post/alloy-facts/</link>
      <pubDate>Wed, 10 Apr 2024 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/alloy-facts/</guid>
      <description>I&amp;rsquo;ve recently done a lot of work in Alloy and it&amp;rsquo;s got me thinking about a common specification pitfall. Everything in the main post applies to all formal specifications, everything in dropdowns is for experienced Alloy users.
Consider a simple model of a dependency tree. We have a set of top-level dependencies for our program, which have their own dependencies, etc. We can model it this way in Alloy:</description>
    </item>
    
    <item>
      <title>The World and the Machine</title>
      <link>https://www.hillelwayne.com/post/world-vs-machine/</link>
      <pubDate>Thu, 04 Jan 2024 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/world-vs-machine/</guid>
      <description>This is just a way of thinking about formal specification that I find really useful. The terms originally come from Michael Jackson&amp;rsquo;s Software Requirements and Specifications.
In specification, the machine is the part of the system you have direct control over and the world is all the parts that you don&amp;rsquo;t. Take a simple transfer spec:
---- MODULE transfer ---- EXTENDS TLC, Integers CONSTANTS People, Money, NumTransfers (* --algorithm transfer variables acct \in [People -&amp;gt; Money]; define \* Invariant NoOverdrafts == \A p \in People: acct[p] &amp;gt;= 0 end define; process cheque \in 1.</description>
    </item>
    
    <item>
      <title>Let&#39;s Prove Leftpad</title>
      <link>https://www.hillelwayne.com/post/lpl/</link>
      <pubDate>Wed, 16 Nov 2022 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/lpl/</guid>
      <description>img {border-style: groove;} Someone recently told me a project isn&amp;rsquo;t real until you do a retrospective, so I think it&amp;rsquo;s time to do one for Let&amp;rsquo;s Prove Leftpad. Short explanation: it&amp;rsquo;s a repository of proofs of leftpad, in different proof systems.
Long explanation: the rest of this post.
Background I&amp;rsquo;m into formal methods, the discipline of proving software correct. Consider the following contrived code:
def add(x: int, y: int): int { if(x == 12976 &amp;amp;&amp;amp; y == 14867) { return x - y; } return x + y; }  This typechecks, and any black-box unit test would find that add(x, y) == x + y.</description>
    </item>
    
    <item>
      <title>Safety and Liveness Properties</title>
      <link>https://www.hillelwayne.com/post/safety-and-liveness/</link>
      <pubDate>Tue, 06 Sep 2022 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/safety-and-liveness/</guid>
      <description>img {border-style: groove; border-width: 1px; padding: 5px; } 
Sounds like I should write a post on safety and liveness!
First, some definitions. A system is anything that has changing state. This is an incredibly broad definition that covers a wide variety of situations, like:
 Two threads in a thread scheduler Five servers behind a load balancer A reader and writer communicating on a FIFO queue A business workflow being manually followed A person waiting for the bus Etc.</description>
    </item>
    
    <item>
      <title>Specification Refinement</title>
      <link>https://www.hillelwayne.com/post/refinement/</link>
      <pubDate>Tue, 13 Jul 2021 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/refinement/</guid>
      <description>When teaching formal methods, I often get asked how we can connect the specifications we write to the code we produce. One way we do this is with refinement. All examples are in TLA+.1
Imagine we&amp;rsquo;re designing a multithreaded counter. We don&amp;rsquo;t know how we&amp;rsquo;re going to implement it yet, so we start by specifying the abstract behavior.2
---- MODULE abstract ---- EXTENDS Integers, Sequences VARIABLES pc, counter vars == &amp;lt;&amp;lt;pc, counter&amp;gt;&amp;gt; \* Two threads Threads == 1.</description>
    </item>
    
    <item>
      <title>Why Specifications Don&#39;t Compose</title>
      <link>https://www.hillelwayne.com/post/spec-composition/</link>
      <pubDate>Sun, 18 Apr 2021 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/spec-composition/</guid>
      <description>Recently my friend Lars Hupel and I had a discussion on why formal methods don&amp;rsquo;t compose well. You can read the conversation here. We focused mostly on composing formally-verified code. I want to talk a little more about the difficulties in composing specifications. This is half because it&amp;rsquo;s difficult for interesting reasons and half because it&amp;rsquo;s a common question from beginners.
Beginners to formal specification expect specifications should be organized like programs: multiple independent modules that interact through public interfaces, where the modules don&amp;rsquo;t know about each others&amp;rsquo; private implementations.</description>
    </item>
    
    <item>
      <title>TLA&#43; Action Properties</title>
      <link>https://www.hillelwayne.com/post/action-properties/</link>
      <pubDate>Thu, 25 Feb 2021 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/action-properties/</guid>
      <description>There&amp;rsquo;s not a whole lot on TLA+ technique out there: all the resources are either introductions or case studies. Good for people starting out, bad for people past that. I think we need to write more intermediate-level stuff, what Ben Kuhn calls Blub studies. Here&amp;rsquo;s an attempt at that.
Most TLA+ properties are invariants, properties that must be true for every state in the behavior. If we have a simple counter:</description>
    </item>
    
    <item>
      <title>Two workers are quadratically better than one</title>
      <link>https://www.hillelwayne.com/post/queueing-prism/</link>
      <pubDate>Mon, 02 Nov 2020 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/queueing-prism/</guid>
      <description>For latency, anyway.
A common architecture pattern is the &amp;ldquo;task queue&amp;rdquo;: tasks enter an ordered queue, workers pop tasks and process them. This pattern is used everywhere from distributed systems to thread pools. It applies just as well to human systems, like waiting in line at a supermarket or a bank. Task queues are popular because they are simple, easy to understand, and scale well.
There are two primary performance metrics for a task queue.</description>
    </item>
    
    <item>
      <title>Software correctness is a lot like flossing</title>
      <link>https://www.hillelwayne.com/post/flossing/</link>
      <pubDate>Wed, 28 Oct 2020 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/flossing/</guid>
      <description>My work brings me though a lot of software correctness techniques, things like type theory, test-driven development (TDD), and formal methods. The surrounding communities all have the same problem: they can&amp;rsquo;t get people using these techniques. They all ask &amp;ldquo;Don&amp;rsquo;t people care about correct software?&amp;rdquo; To which the insiders usually answer &amp;ldquo;programmers don&amp;rsquo;t care about correctness, they just care about shoveling out garbage to make money!&amp;rdquo;
I&amp;rsquo;ve heard this from every single community I&amp;rsquo;ve explored, many of which are in direct conflict with each other.</description>
    </item>
    
    <item>
      <title>Finding Goroutine Bugs with TLA&#43;</title>
      <link>https://www.hillelwayne.com/post/tla-golang/</link>
      <pubDate>Fri, 25 Sep 2020 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/tla-golang/</guid>
      <description>My job these days is teaching TLA+ and formal methods: specifying designs to find bugs in them. But just knowing the syntax isn&amp;rsquo;t enough to write specs, and it helps to have examples to draw from. I recently read Chris Siebenmann&amp;rsquo;s Even in Go, concurrency is still not easy and thought it would make a good case study for writing a spec. In it, he gives an example of Go code which deadlocks:</description>
    </item>
    
    <item>
      <title>Decision Table Patterns</title>
      <link>https://www.hillelwayne.com/post/decision-table-patterns/</link>
      <pubDate>Wed, 09 Sep 2020 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/decision-table-patterns/</guid>
      <description>Decision tables are easy, simple, and powerful. You can teach them in five minutes and write one in half that time. You can look at a table and understand what it&amp;rsquo;s saying, see if it matches your problem, and check for design flaws. So it&amp;rsquo;s kinda weird that there&amp;rsquo;s basically nothing about them online. I wrote an introduction a while back, but I want something a little more formal. So this post will reintroduce the core ideas in a more formal way and then talk about some of the techniques you can apply to make better tables.</description>
    </item>
    
    <item>
      <title>Weak and Strong Fairness</title>
      <link>https://www.hillelwayne.com/post/fairness/</link>
      <pubDate>Fri, 03 Jul 2020 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/fairness/</guid>
      <description>I&amp;rsquo;m in the process of revising some of my workshops. I realized that one particular important aspect of TLA+, fairness, is something that I&amp;rsquo;ve struggled to explain well. Then again, everybody struggles to explain it well! It&amp;rsquo;s also a great example of how messy concurrent systems can get, so I figured it would make a good post for the blog.
Stuttering Take the following spec of a clock. I used TLA+ but it should mostly be clear from context:</description>
    </item>
    
    <item>
      <title>Announcing: Alloydocs</title>
      <link>https://www.hillelwayne.com/post/alloydocs/</link>
      <pubDate>Mon, 13 Apr 2020 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/alloydocs/</guid>
      <description>tl;dr: online Alloy reference here.
If you&amp;rsquo;ve read this blog at all you probably know I&amp;rsquo;m a big fan of Alloy. It&amp;rsquo;s a simple, powerful formal method whose entire syntax fits in just two pages. You can learn it in a day and be productive in two. And it can be used to model everything from package management to database migrations to authorization systems.
Two years ago I was invited to the Workshop on the Future of Alloy.</description>
    </item>
    
    <item>
      <title>Feature Interaction Bugs</title>
      <link>https://www.hillelwayne.com/post/feature-interaction/</link>
      <pubDate>Wed, 05 Feb 2020 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/feature-interaction/</guid>
      <description>In most testing frameworks, you&amp;rsquo;re expected to write a lot of low-level tests and few high-level tests. The reasoning is that end-to-end tests are slow and expensive and only cover a tiny amount of the program&amp;rsquo;s state space. It&amp;rsquo;s better to focus on testing all the parts in isolation versus testing that they all work together.
In practice, global correctness does not follow from local correctness. It&amp;rsquo;s possible for every part to be individually rock-solid but the system to be broken as a whole.</description>
    </item>
    
    <item>
      <title>The Business Case for Formal Methods</title>
      <link>https://www.hillelwayne.com/post/business-case-formal-methods/</link>
      <pubDate>Wed, 22 Jan 2020 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/business-case-formal-methods/</guid>
      <description>This is an &amp;ldquo;intro packet&amp;rdquo; you can use to argue for the benefits of formal methods (FM) to your boss. It&amp;rsquo;s a short explanation, a list of benefits and case studies, and a demo. Everything&amp;rsquo;s in TLA+, but the arguments apply equally well to Alloy, B, statecharts, etc. Adapt the material to your specific needs.
Quick notational note: I&amp;rsquo;m leaving out the code verification side of formal methods, mostly because design verification is a much easier sell.</description>
    </item>
    
    <item>
      <title>Hypermodeling Hyperproperties</title>
      <link>https://www.hillelwayne.com/post/hyperproperties/</link>
      <pubDate>Mon, 13 Jan 2020 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/hyperproperties/</guid>
      <description>When we design programs, we usually look for two kinds of properties: that &amp;ldquo;bad things&amp;rdquo; never happen and that &amp;ldquo;good things&amp;rdquo; are guaranteed to happen. These are called safety and liveness properties, respectively. These are properties that we want to hold true for every possible program behavior. &amp;ldquo;We always complete every request&amp;rdquo; is a liveness property. If our system has it, every program trace will complete every request. If it doesn&amp;rsquo;t hold, I can give you a example behavior where the server never responds.</description>
    </item>
    
    <item>
      <title>Formally Modeling Database Migrations</title>
      <link>https://www.hillelwayne.com/post/formally-modeling-migrations/</link>
      <pubDate>Wed, 09 Oct 2019 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/formally-modeling-migrations/</guid>
      <description>Most of my formal methods examples deal with concurrency, because time is evil and I hate it. While FM is very effective for that, it gives people a limited sense of how flexible these tools are. One of the most common questions I get from people is
 Formal methods looks really useful for distributed systems, but I&amp;rsquo;m not making a distributed system. Is FM still useful for me?</description>
    </item>
    
    <item>
      <title>Probabilistic Modeling with PRISM</title>
      <link>https://www.hillelwayne.com/post/prism/</link>
      <pubDate>Mon, 17 Jun 2019 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/prism/</guid>
      <description>In my job I dig up a lot of obscure techniques. Some of them are broadly useful: formal specification, design-by-contract, etc. These I specialize in. Some of them are useful, but for a smaller group of programmers. That&amp;rsquo;s stuff like metamorphic testing, theorem proving, constraint solving. These I write articles about.
Then there&amp;rsquo;s the stuff where I have no idea how to make it useful. Either they&amp;rsquo;re so incredibly specialist or they could be useful if it weren&amp;rsquo;t for some deep problems.</description>
    </item>
    
    <item>
      <title>Modeling Adversaries with TLA&#43;</title>
      <link>https://www.hillelwayne.com/post/adversaries/</link>
      <pubDate>Sun, 05 May 2019 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/adversaries/</guid>
      <description>A common question I get about specs is how to model bad actors. Usually this is one of two contexts:
 The spec involves several interacting agents sharing a protocol, but some of the nodes are faulty or malicious: they will intentionally try to subvert the system. The spec involves an agent subject to outside forces, like someone can throw a rock at your sensor.  These &amp;ldquo;open world&amp;rdquo; situations are a great place to use formal methods.</description>
    </item>
    
    <item>
      <title>Using Formal Methods at Work</title>
      <link>https://www.hillelwayne.com/post/using-formal-methods/</link>
      <pubDate>Mon, 11 Mar 2019 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/using-formal-methods/</guid>
      <description>A few people have told me that they&amp;rsquo;ve enjoyed learning formal methods but aren&amp;rsquo;t sure how to actually use it. They&amp;rsquo;re mostly doing short sprints at work and aren&amp;rsquo;t building new systems from scratch. This tells me there&amp;rsquo;s some confusion about what makes specifications useful, and that we need a resource on applying them in practice. This is a short guide to using specifications at work in a way that&amp;rsquo;s accessible to beginners, applicable in many contexts, and provides solid business value.</description>
    </item>
    
    <item>
      <title>Why Don&#39;t People Use Formal Methods?</title>
      <link>https://www.hillelwayne.com/post/why-dont-people-use-formal-methods/</link>
      <pubDate>Mon, 21 Jan 2019 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/why-dont-people-use-formal-methods/</guid>
      <description>I saw this question on the Software Engineering Stack Exchange: What are the barriers that prevent widespread adoption of formal methods? The question was closed as opinion-based, and most of the answers were things like &amp;ldquo;its too expensive!!!&amp;rdquo; or &amp;ldquo;website isn&amp;rsquo;t airplane!!!&amp;rdquo; These are sorta kinda true but don&amp;rsquo;t explain very much. I wrote this to provide a larger historical picture of formal methods, why they&amp;rsquo;re actually so unused, and what we&amp;rsquo;re doing to make them used.</description>
    </item>
    
    <item>
      <title>Modeling Message Queues in TLA&#43;</title>
      <link>https://www.hillelwayne.com/post/tla-messages/</link>
      <pubDate>Wed, 31 Oct 2018 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/tla-messages/</guid>
      <description>I recently did a corporate TLA+ workshop and some people asked what TLA+ specs look like in practice. If you looked at the most common public examples, you&amp;rsquo;d probably come away thinking that people only used it for critical consensus algorithms. This is a problem for two reasons: first, it makes it harder to learn TLA+, as there aren&amp;rsquo;t simpler examples to experiment with. Second, it makes it hard for people to see how TLA+ is useful for them.</description>
    </item>
    
    <item>
      <title>Practical TLA&#43; Now Available</title>
      <link>https://www.hillelwayne.com/post/practical-tla/</link>
      <pubDate>Thu, 18 Oct 2018 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/practical-tla/</guid>
      <description>I am delighted to announce that my book, Practical TLA+, is now available! When I stumbled into TLA+ in 2016 I had no idea it would so define my passions, my values, and my career. I definitely didn&amp;rsquo;t think I&amp;rsquo;d be writing a book. But 11 months and 220 pages later, here we are! This is the largest project I&amp;rsquo;ve ever done and I&amp;rsquo;m incredibly excited to share it with you all.</description>
    </item>
    
    <item>
      <title>Augmenting Agile with Formal Methods</title>
      <link>https://www.hillelwayne.com/post/augmenting-agile/</link>
      <pubDate>Mon, 30 Jul 2018 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/augmenting-agile/</guid>
      <description>I really like the c2 wiki as a historical artifact: a lot of big names in Agile and Extreme Programming argued with each other there.1 One thing they did was the Extreme Programming Challenge, where people tried to test the limits of these approaches. They&amp;rsquo;d find edge problems (designing databases, remote teams, etc) and see if Agile/XP still worked in that context. In almost every case they quickly decided that yes, it works just fine.</description>
    </item>
    
    <item>
      <title>Formally Specifying UIs</title>
      <link>https://www.hillelwayne.com/formally-specifying-uis/</link>
      <pubDate>Mon, 11 Jun 2018 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/formally-specifying-uis/</guid>
      <description>Good UI is necessary to making correct software. If people have trouble using the product, they&amp;rsquo;re more likely to do the wrong thing. Personally, though, I can&amp;rsquo;t stand UI work. I don&amp;rsquo;t think it&amp;rsquo;s &amp;ldquo;beneath me&amp;rdquo; or anything, it just doesn&amp;rsquo;t quite mesh with my brain. Visuals and interfaces give me anxiety. Mad respect for the people who can handle it.
I love formal methods. Recently my friend Kevin Lynagh released Sketch.</description>
    </item>
    
    <item>
      <title>Raw Materials</title>
      <link>https://www.hillelwayne.com/post/raw-materials/</link>
      <pubDate>Sun, 27 May 2018 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/raw-materials/</guid>
      <description>This is an excerpt from Michael Jackson (not the singer)&amp;rsquo;s book Software Requirements and Specifications, in his discussion of &amp;ldquo;Raw Materials&amp;rdquo;. It&amp;rsquo;s worth letting stand on its own.
 First, make a list of all the languages you use in all your development activities. Be honest: don&amp;rsquo;t list all of the languages you have ever heard of; include only languages you have used for real work at least once&amp;hellip;
Now, ask yourself which of the languages on your list you would choose to say these things, and how easily you could say them:</description>
    </item>
    
    <item>
      <title>The Great Theorem Prover Showdown</title>
      <link>https://www.hillelwayne.com/post/theorem-prover-showdown/</link>
      <pubDate>Wed, 25 Apr 2018 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/theorem-prover-showdown/</guid>
      <description>Functional programming and immutability are hot right now. On one hand, this is pretty great as there&amp;rsquo;s lots of nice things about functional programming. On the other hand, people get a little overzealous and start claiming that imperative code is unnatural or that purity is always preferable to mutation.
I think that the appropriate paradigm is heavily dependent on context, but a lot of people speak in universals. I keep hearing that it&amp;rsquo;s easier to analyze pure functional code than mutable imperative code.</description>
    </item>
    
    <item>
      <title>Formally Specifying a Package Manager</title>
      <link>https://www.hillelwayne.com/post/nix/</link>
      <pubDate>Fri, 16 Mar 2018 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/post/nix/</guid>
      <description>This post was commissioned by Graham Christensen as part of the Great Slate fundraiser. Thank you!
I wanted to help out the Great Slate fundraiser and donated two technical essays of the purchaser&amp;rsquo;s choice. Graham bought one and asked for
 Something that has to do with Nix or NixOS
 This was a bit of a challenge, given that I didn&amp;rsquo;t even know what Nix was. I had never used it and still haven&amp;rsquo;t, nor can I use it for the near future, because my only computer right now is a Windows box.</description>
    </item>
    
    <item>
      <title>Proving Games are Winnable with Alloy</title>
      <link>https://www.hillelwayne.com/alloy-randomizer/</link>
      <pubDate>Mon, 15 Jan 2018 00:00:00 +0000</pubDate>
      
      <guid>https://www.hillelwayne.com/alloy-randomizer/</guid>
      <description>One of my vices is watching Link to the Past Randomizer games. This gist is it&amp;rsquo;s a regular Zelda game except all of the items in chests are randomized. A chest that normally has bombs might have a critical item, while the chest that&amp;rsquo;s supposed to have the moon pearl might only have 10 rupees. People use randomizers to run races, since you can&amp;rsquo;t just memorize the &amp;ldquo;correct&amp;rdquo; path through the game.</description>
    </item>
    
    <item>
      <title>Modeling Zero-Downtime Deployments with TLA&#43;</title>
      <link>https://www.hillelwayne.com/post/modeling-deployments/</link>
      <pubDate>Tue, 30 May 2017 11:48:17 -0500</pubDate>
      
      <guid>https://www.hillelwayne.com/post/modeling-deployments/</guid>
      <description>I&amp;rsquo;m working on some examples for my TLA+ guide and realized this one would be a good introduction to specification in general, so I simplified it a little to make it more accessible. Enjoy!
The problem Deploying code to a set of servers is tricky. You can turn them off, migrate the code, and turn them back on, but that&amp;rsquo;ll piss off the customers. You could also update them live, but different servers update are different rates and customers could get inconsistent results.</description>
    </item>
    
  </channel>
</rss>