首页›Hillel Wayne›文章

A Crash Course in Predicate Logic

2026年9月1日

AI 摘要 AI 生成,可能有误

本文改编自《Logic for Programmers》(程序员逻辑学)一书的第二章,是一堂面向程序员的形式逻辑速成课。文章将谓词解释为返回布尔值的函数,既可以是具体的,也可以是抽象的;通过 CanRunProgram 示例和真值表展示了形式逻辑如何消除自然语言需求中的歧义,并介绍了蕴含运算符 (=>) 以及用于约束谓词输入的集合。

I started writing Logic for Programmers because there weren’t any good resources on logic for, uh, programmers. Now that the book’s out, the new problem is that there aren’t any good free resources on logic for programmers.

So, to solve that problem (and maybe hype the book a little), I converted the second chapter of LfP into a blog post. All footnotes are editorial comments not present in the book.1 Enjoy!

Chapter 2: A Crash Course in Logic

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Hillel Wayne

Logic for Programmers is Now Available

AI 摘要The author announces the release of their book, Logic for Programmers, which took five years to write and teaches working developers the basics of formal logic and its applications, including property-based testing, domain modeling, and logic programming. The book was created because no programmer-focused resources existed for learning these fundamentals, and it requires no math background. Early access buyers can get version 1.0 for free on Leanpub.

Chicago vs New York Pizza is the Wrong Argument

AI 摘要The author, writing for April Cools, argues that the classic 'Chicago vs New York pizza' debate is meaningless because deep dish is a special-occasion food while New York-style pizza is an everyday food, making them poor points of comparison. Instead, they propose comparing New York pizza to the Chicago-style hot dog as role-equivalent iconic local foods, ultimately conceding that NYP wins for ease of home preparation while praising the Chicago dog as a superior hot dog. The piece closes as a celebration of other Chicago specialties like Italian beef, the jibarito, and flaming saganaki.

Some Silly Z3 Scripts I Wrote

AI 摘要The author shares a collection of discarded Z3 example scripts (written with Python bindings) produced while working on their book 'Logic for Programmers', explaining that Z3 is an SMT solver that finds values satisfying mathematical and programming constraints. The examples range from solving equation systems and math puzzles about equal sums and products, to optimizing annual bank deposits, reverse engineering a pseudorandom number generator's parameters, proving theorems by checking for counterexamples, and maximizing stock trade profit. Along the way, the article demonstrates Z3 features like the Optimize solver, the theory of arrays, and constraint checking with additional temporary constraints.

A Very Early History of Algebraic Data Types

AI 摘要The article traces the earliest history of algebraic data types back to John McCarthy's 1961 paper 'A Basis for a Mathematical Theory of Computation,' which introduced Cartesian products and 'direct unions' along with their algebraic properties like isomorphism and distributivity. The author then follows how these ideas spread through Tony Hoare's work on data structuring in imperative languages, where 'discriminated union' was coined, and through Rod Burstall's structural induction work that influenced functional programming. Finally, the author disputes the common claim that Landin's ISWIM was the first language with algebraic data types, arguing it was merely a proposal and likely never actually defined sum types.

Gamer Games for Non-Gamers

AI 摘要Written as part of the 'April Cools' tradition, this article recommends video games that are accessible to non-gamers, using criteria such as running on ordinary hardware, requiring no prior gaming knowledge, being culturally meaningful, and being games the author has personally seen non-gamers enjoy. The author details four picks—Baba is You, Stardew Valley, The Case of the Golden Idol, and Balatro—explaining each game's mechanics, appeal, and historical context within its genre. The piece aims to lower the barrier to entry into gaming, which despite being a half-trillion-dollar industry remains surprisingly niche compared to movies or music.